/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ── Scrollbars ── */
* { scrollbar-width: thin; scrollbar-color: var(--bg3) transparent; }
*::-webkit-scrollbar { width: 3px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: var(--bg3); border-radius: 2px; }

/* ── CSS Variables ── */
:root {
  --bg:      #0c0a08;
  --bg2:     #17130f;
  --bg3:     #221c15;
  --text:    #e8dcc4;
  --muted:   #7a6a52;
  --gold:    #c8963c;
  --gold-lt: #e8c060;
  --line-h:  10px;
  --r:       16px;
}

:root.light {
  --bg:      #f5f0e8;
  --bg2:     #ece5d8;
  --bg3:     #e0d8c8;
  --text:    #2a2018;
  --muted:   #8a7860;
  --gold:    #a07020;
  --gold-lt: #c8900a;
}

/* ── Fonts ── */
@font-face {
  font-family: 'Hidetoshy';
  src: url('../fonts/Hidetoshy/Hidetoshy.ttf') format('truetype');
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Noto Serif';
  src: url('../fonts/noto-serif/noto-serif-latin-400-normal.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Noto Serif';
  src: url('../fonts/noto-serif/noto-serif-latin-400-italic.woff2') format('woff2');
  font-weight: 400;
  font-style: italic;
  font-display: swap;
}
@font-face {
  font-family: 'Noto Serif';
  src: url('../fonts/noto-serif/noto-serif-latin-600-normal.woff2') format('woff2');
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Noto Sans SC';
  src: url('../fonts/noto-sans-sc/noto-sans-sc-chinese-simplified-400-normal.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

/* ── Base ── */
html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  height: var(--app-h, 100dvh);
  font-family: 'Noto Serif', Georgia, serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
}

/* ── App container ── */
#app {
  width: 100%;
  max-width: 720px;
  flex: 1;
  min-height: 0;
  position: relative;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  overflow: hidden;
}

/* ── Header ── */
.hdr {
  width: 100%;
  max-width: 720px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 52px 16px 12px;
  flex-shrink: 0;
  background: var(--bg2);
  position: relative;
  z-index: 20;
  box-shadow: 0 0 0 100vmax var(--bg2);
  clip-path: inset(0 -100vmax);
}

.hdr-left { display: flex; align-items: center; gap: 6px; }
.hdr-right { display: flex; align-items: center; gap: 6px; flex-wrap: nowrap; }

.hdr-btn, .hdr-home {
  border: 1px solid #3a2e22;
  background: var(--bg2);
  color: var(--muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: border-color .2s, color .2s, background .2s;
  user-select: none;
  font-family: 'Noto Sans SC', sans-serif;
  font-weight: 400;
  font-size: 12px;
  letter-spacing: .05em;
  flex-shrink: 0;
}

.hdr-btn { width: 34px; height: 34px; }
.hdr-home { width: 40px; height: 40px; color: var(--gold); }
.hdr-btn svg, .hdr-home svg { width: 16px; height: 16px; pointer-events: none; }
.hdr-home svg { width: 18px; height: 18px; }

.hdr-btn:active, .hdr-home:active { border-color: var(--gold); color: var(--gold); }
.hdr-btn.active { border-color: var(--gold); color: var(--gold); }
.hdr-home.hidden { opacity: 0; pointer-events: none; }

/* ── Screens container ── */
#screens {
  flex: 1;
  position: relative;
  overflow: hidden;
}

/* ── Screen transitions ── */
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  opacity: 0;
  pointer-events: none;
  transform: translateX(30px);
  transition: opacity .35s ease, transform .35s ease;
  background: var(--bg);
}

.screen.active {
  opacity: 1;
  pointer-events: all;
  transform: translateX(0);
}

.screen.leaving {
  opacity: 0;
  transform: translateX(-30px);
  pointer-events: none;
}

/* ── Separator ── */
.sep {
  width: 40px;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--gold), transparent);
  margin: 0 auto;
  opacity: .5;
  flex-shrink: 0;
}

/* ── Common buttons ── */
.btn-start {
  margin-top: 40px;
  padding: 14px 44px;
  border-radius: 40px;
  border: 1.5px solid var(--gold);
  background: transparent;
  color: var(--gold-lt);
  font-family: 'Noto Sans SC', sans-serif;
  font-weight: 400;
  letter-spacing: .2em;
  font-size: 13px;
  cursor: pointer;
  text-transform: uppercase;
  transition: background .2s, color .2s;
}
.btn-start:active { background: var(--gold); color: var(--bg); }

.btn-action {
  flex: 1;
  padding: 13px;
  border-radius: 40px;
  border: 1.5px solid #3a2e22;
  background: var(--bg2);
  color: var(--text);
  font-family: 'Noto Sans SC', sans-serif;
  font-weight: 400;
  font-size: 12px;
  letter-spacing: .15em;
  text-transform: uppercase;
  cursor: pointer;
  transition: border-color .2s, color .2s, background .2s;
}
.btn-action.primary { border-color: var(--gold); color: var(--gold-lt); background: var(--bg3); }
.btn-action:active { border-color: var(--gold); color: var(--gold-lt); }

.btn-reset {
  background: none;
  border: 1.5px solid #3a2e22;
  border-radius: 40px;
  color: var(--text);
  font-size: 12px;
  letter-spacing: .2em;
  text-transform: uppercase;
  font-family: 'Noto Sans SC', sans-serif;
  font-weight: 400;
  cursor: pointer;
  padding: 10px 24px;
  transition: border-color .2s, color .2s;
}
.btn-reset:active { border-color: var(--gold); color: var(--gold-lt); }

.bottom-nav {
  display: flex;
  gap: 12px;
  padding: 12px 20px 24px;
  flex-shrink: 0;
}

/* ═══════════════════════════════
   SCREEN 0 — HOME
═══════════════════════════════ */
#s-home {
  background: radial-gradient(ellipse 70% 55% at 50% 35%, #1e1508 0%, var(--bg) 70%);
}
:root.light #s-home {
  background: radial-gradient(ellipse 70% 55% at 50% 35%, #d8ccb4 0%, var(--bg) 70%);
}

.home-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding-bottom: 24px;
}

.home-chinese {
  font-family: 'Hidetoshy', serif;
  font-size: clamp(36px, 9vw, 54px);
  color: var(--gold-lt);
  line-height: 1;
  text-shadow: 0 0 40px rgba(200,150,60,.4);
  letter-spacing: .1em;
}

.home-latin {
  font-family: 'Hidetoshy', serif;
  font-size: clamp(32px, 8vw, 44px);
  color: var(--text);
  margin-top: 4px;
  opacity: .9;
}

.home-logo {
  margin: 24px 0;
  width: clamp(140px, 35vw, 190px);
  height: clamp(140px, 35vw, 190px);
  object-fit: contain;
  opacity: .85;
  filter: drop-shadow(0 0 20px rgba(200,150,60,.2));
}

.home-sub {
  font-size: 13px;
  color: var(--muted);
  letter-spacing: .18em;
  text-transform: uppercase;
  font-family: 'Noto Sans SC', sans-serif;
  font-weight: 400;
  text-align: center;
  line-height: 1.6;
}

/* ═══════════════════════════════
   SCREEN 1 — INSTRUCTIONS
═══════════════════════════════ */
#s-inst { overflow: hidden; }

.inst-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 24px 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.inst-title {
  font-family: 'Hidetoshy', serif;
  font-size: 26px;
  color: var(--text);
  text-align: center;
}

.inst-text {
  font-size: 14px;
  color: var(--muted);
  line-height: 1.8;
  text-align: center;
  font-style: italic;
}

.inst-text strong { color: var(--gold); font-style: normal; }

.inst-coins-label {
  font-family: 'Noto Sans SC', sans-serif;
  font-weight: 400;
  font-size: 10px;
  letter-spacing: .25em;
  color: var(--muted);
  text-transform: uppercase;
  text-align: center;
  margin-bottom: 10px;
}

.inst-coins {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.coin-card {
  background: var(--bg2);
  border: 1px solid #2a2018;
  border-radius: var(--r);
  padding: 14px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.coin-cluster-tri {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 3px;
  width: 54px;
  align-items: center;
  justify-items: center;
}
.coin-cluster-tri .cc:nth-child(3) { grid-column: 1 / 3; }

.cc {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 8px;
  font-family: 'Noto Sans SC', sans-serif;
  font-weight: 400;
  flex-shrink: 0;
}
.cc-face { background: var(--gold); color: var(--bg); }
.cc-pile { background: var(--bg3); border: 1.5px solid var(--muted); color: var(--muted); }

.coin-line-demo {
  width: 100%;
  height: 22px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.bar-full { flex: 1; height: 8px; background: var(--gold); border-radius: 4px; position: relative; }
.bar-half { flex: 1; height: 8px; background: var(--gold); border-radius: 4px; }
.bar-gap  { width: 10px; flex-shrink: 0; }
.bar-dot  {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--bg2);
  border: 2px solid var(--gold);
}

.coin-label {
  font-family: 'Noto Sans SC', sans-serif;
  font-weight: 400;
  font-size: 10px;
  letter-spacing: .1em;
  color: var(--muted);
  text-transform: uppercase;
  text-align: center;
}

.inst-note {
  font-size: 12px;
  color: var(--muted);
  text-align: center;
  line-height: 1.7;
  font-style: italic;
  opacity: .7;
}

/* ═══════════════════════════════
   SCREEN 2 — CASTING
═══════════════════════════════ */
#s-cast { overflow: hidden; }

.cast-progress {
  text-align: center;
  padding: 8px 24px 12px;
  flex-shrink: 0;
}

.cast-progress-label {
  font-family: 'Noto Sans SC', sans-serif;
  font-weight: 400;
  font-size: 11px;
  letter-spacing: .22em;
  color: var(--muted);
  text-transform: uppercase;
  margin-bottom: 8px;
  min-height: 1.4em;
}

.cast-dots { display: flex; gap: 6px; justify-content: center; }

.cast-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: #2a2018;
  border: 1px solid #3a2e22;
  transition: background .3s, border-color .3s;
}
.cast-dot.done    { background: var(--gold); border-color: var(--gold); }
.cast-dot.current { background: transparent; border-color: var(--gold-lt); box-shadow: 0 0 6px rgba(232,192,96,.4); }

.hex-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 60px;
}

.hex-line-slot {
  width: 100%;
  max-width: 300px;
  height: 20px;
  display: flex;
  align-items: center;
  opacity: .2;
  transition: opacity .4s;
}
.hex-line-slot.filled { opacity: 1; }

.hex-divider {
  width: 60%;
  height: 1px;
  background: linear-gradient(90deg, transparent, #3a2e22, transparent);
  margin: 4px 0;
  flex-shrink: 0;
}

.coin-btns {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1fr;
  gap: 8px;
  padding: 0 12px 12px;
  flex-shrink: 0;
}

.coin-btn {
  background: var(--bg2);
  border: 1px solid #2a2018;
  border-radius: 14px;
  padding: 10px 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  transition: border-color .15s, background .15s, transform .1s;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.coin-btn:active { border-color: var(--gold); background: var(--bg3); transform: scale(.96); }

.mini-coins {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 3px;
  width: 50px;
  justify-items: center;
}
.mini-coins .mc:nth-child(3) { grid-column: 1 / 3; }

.mc {
  width: 20px; height: 20px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 7px;
  font-family: 'Noto Sans SC', sans-serif;
  font-weight: 400;
  flex-shrink: 0;
}
.mc-face { background: var(--gold); color: var(--bg); }
.mc-pile { background: var(--bg3); border: 1px solid var(--muted); color: var(--muted); }

.mini-line {
  width: 100%;
  height: 18px;
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 0 4px;
}
.mini-bar { flex: 1; height: 6px; background: var(--gold); border-radius: 3px; position: relative; }
.mini-gap { width: 4px; flex-shrink: 0; }
.mini-dot {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--bg2);
  border: 1.5px solid var(--gold);
}

.coin-btn-label {
  font-family: 'Noto Sans SC', sans-serif;
  font-weight: 400;
  font-size: 9px;
  letter-spacing: .08em;
  color: var(--muted);
  text-align: center;
  text-transform: uppercase;
  line-height: 1.3;
}

.cast-bottom {
  display: flex;
  justify-content: center;
  padding: 0 0 20px;
  flex-shrink: 0;
}

/* ═══════════════════════════════
   SCREEN 3 — RESULT
═══════════════════════════════ */
#s-result { overflow: hidden; }

.result-title-area {
  padding: 8px 24px 12px;
  text-align: center;
  flex-shrink: 0;
}

.result-num {
  font-family: 'Noto Sans SC', sans-serif;
  font-weight: 400;
  font-size: 11px;
  letter-spacing: .3em;
  color: var(--muted);
  text-transform: uppercase;
  margin-bottom: 4px;
  min-height: 1.4em;
}

.result-zh {
  font-family: 'Hidetoshy', serif;
  font-size: clamp(20px, 5vw, 28px);
  color: var(--gold-lt);
  letter-spacing: .05em;
  line-height: 1.3;
}

.result-card-wrap {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  overflow: hidden;
}

.result-card {
  border-radius: 20px;
  overflow: hidden;
  width: 100%;
  max-width: 340px;
  max-height: 100%;
  box-shadow: 0 20px 60px rgba(0,0,0,.6), 0 0 0 1px rgba(200,150,60,.2);
  position: relative;
  transition: opacity .25s, transform .25s;
  display: flex;
  flex-direction: column;
}

.result-card-upper,
.result-card-lower {
  width: 100%;
  flex: 1 1 auto;
  min-height: 0;
  aspect-ratio: 1000 / 820;
  overflow: hidden;
}
.result-card-upper img,
.result-card-lower img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  display: block;
}

.result-card-divider {
  height: 2px;
  background: var(--bg);
  flex-shrink: 0;
}

.card-hex-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 24px;
  pointer-events: none;
}

.card-hex-line {
  width: 75%;
  height: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-label {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  text-align: center;
  font-family: 'Noto Sans SC', sans-serif;
  font-weight: 400;
  font-size: 9px;
  letter-spacing: .15em;
  color: rgba(255,255,255,.7);
  text-transform: uppercase;
  padding: 8px 4px;
  background: linear-gradient(transparent, rgba(0,0,0,.5));
  display: none;
}

.result-nav {
  display: flex;
  justify-content: center;
  gap: 28px;
  align-items: center;
  padding: 12px 0 24px;
  flex-shrink: 0;
}

.nav-arr {
  width: 42px; height: 42px;
  border-radius: 50%;
  border: 1.5px solid #3a2e22;
  background: var(--bg2);
  color: var(--text);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: border-color .2s, color .2s;
  flex-shrink: 0;
}
.nav-arr svg { width: 20px; height: 20px; pointer-events: none; }
.nav-arr:active { border-color: var(--gold); color: var(--gold); }
.nav-arr.disabled { opacity: .25; pointer-events: none; }
#arr-next { border-color: var(--gold); color: var(--gold); }

.result-card { cursor: pointer; }

/* ═══════════════════════════════
   SCREEN 4 — ORACLE
═══════════════════════════════ */
#s-oracle { overflow: hidden; }

#oracle-content {
  flex: 1;
  overflow-y: auto;
  padding: 8px 24px 12px;
  -webkit-overflow-scrolling: touch;
  user-select: text;
  -webkit-user-select: text;
  font-size: 0.95em;
  line-height: 1.75;
  letter-spacing: 0.01em;
}


#oracle-content h1 {
  font-family: 'Noto Serif', serif;
  font-weight: 600;
  font-size: 1.5em;
  color: var(--text);
  margin-top: 1.6em;
  margin-bottom: 0.3em;
  line-height: 1.4;
}
#oracle-content h2 {
  font-family: 'Noto Serif', serif;
  font-weight: 600;
  font-size: 1.2em;
  color: var(--text);
  margin-top: 1.4em;
  margin-bottom: 0.2em;
}
#oracle-content h3 {
  font-family: 'Noto Serif', serif;
  font-weight: 600;
  font-size: 1em;
  color: var(--gold);
  margin-top: 1.3em;
  margin-bottom: 0.2em;
}
#oracle-content p {
  color: var(--text);
  opacity: .85;
  margin: 0.4em 0;
  line-height: 1.8;
}

#oracle-content blockquote {
  border-left: 2px solid var(--gold);
  margin: 0.5em 0;
  padding-left: 1em;
  color: var(--muted);
  opacity: .7;
  font-style: italic;
}
#oracle-content ul { margin: 0.3em 0; padding-left: 1.5em; }
#oracle-content li {
  color: var(--text);
  opacity: .85;
  margin-bottom: 0.4em;
  line-height: 1.7;
  font-weight: 600;
}
#oracle-content hr { margin: 2em 0; border: none; border-bottom: 1px solid #3a2e22; }

/* ═══════════════════════════════
   MODAL INFO
═══════════════════════════════ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(12,10,8,.75);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity .3s ease;
}
.modal-overlay.open { opacity: 1; pointer-events: all; }

.modal-sheet {
  width: 100%;
  max-width: 720px;
  background: var(--bg2);
  border-radius: 24px 24px 0 0;
  border-top: 1px solid #2a2018;
  padding: 12px 24px 40px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  transform: translateY(40px);
  transition: transform .35s cubic-bezier(.2,.8,.3,1);
}
.modal-overlay.open .modal-sheet { transform: translateY(0); }

.modal-handle {
  width: 36px; height: 4px;
  border-radius: 2px;
  background: #3a2e22;
  margin: 0 auto 4px;
}

.modal-title {
  font-family: 'Hidetoshy', serif;
  font-size: 30px;
  color: var(--text);
}

.modal-body {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.85;
  font-style: italic;
  overflow-y: auto;
  max-height: 280px;
  -webkit-overflow-scrolling: touch;
}
.modal-body p + p { margin-top: 10px; }
.modal-body a { color: var(--gold); }

.modal-close {
  align-self: center;
  padding: 10px 32px;
  border-radius: 40px;
  border: 1px solid #2a2018;
  background: transparent;
  color: var(--muted);
  font-family: 'Noto Sans SC', sans-serif;
  font-weight: 400;
  font-size: 11px;
  letter-spacing: .18em;
  text-transform: uppercase;
  cursor: pointer;
  transition: border-color .2s, color .2s;
}
.modal-close:active { border-color: var(--gold); color: var(--gold); }

/* ── Animation ── */
@keyframes lineAppear {
  from { opacity: 0; transform: scaleX(.4); }
  to   { opacity: 1; transform: scaleX(1); }
}
.line-anim { animation: lineAppear .35s cubic-bezier(.2,.8,.3,1) forwards; }

/* ── Desktop ── */
@media (min-width: 640px) {
  .hdr { padding-top: 20px; }
  #oracle-content { padding: 12px 40px 16px; }
}
