/* ==========================================================================
   십이신살 트레이닝 — 스타일
   색은 화투 고유색에서 가져왔다. 먹·홍(붉은 시문)·청(청단)·금(광)·지(종이).
   모든 색은 토큰으로만 쓴다. 하드코딩 금지.
   ========================================================================== */

:root {
  --paper: #ede5d7;
  --paper-raised: #f7f2e7;
  --paper-sunken: #e3d9c7;
  --ink: #17161b;
  --ink-soft: #55504a;
  --ink-faint: #837c72;
  --hong: #b33a2b;
  --hong-wash: rgba(179, 58, 43, 0.1);
  --cheong: #2f5d62;
  --cheong-wash: rgba(47, 93, 98, 0.1);
  --geum: #b8912f;
  --line: rgba(23, 22, 27, 0.14);
  --line-strong: rgba(23, 22, 27, 0.3);
  --shadow: 0 1px 2px rgba(23, 22, 27, 0.06), 0 8px 24px rgba(23, 22, 27, 0.07);

  --font-display: 'Gowun Batang', 'Nanum Myeongjo', serif;
  --font-body: 'IBM Plex Sans KR', -apple-system, BlinkMacSystemFont, 'Apple SD Gothic Neo', sans-serif;

  --col: 40rem;
  --radius: 4px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --paper: #15141a;
    --paper-raised: #1f1d25;
    --paper-sunken: #100f14;
    --ink: #ece4d6;
    --ink-soft: #b0a89b;
    --ink-faint: #857e73;
    --hong: #d9695a;
    --hong-wash: rgba(217, 105, 90, 0.14);
    --cheong: #7fb0ae;
    --cheong-wash: rgba(127, 176, 174, 0.13);
    --geum: #d5ae5e;
    --line: rgba(236, 228, 214, 0.16);
    --line-strong: rgba(236, 228, 214, 0.34);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 10px 28px rgba(0, 0, 0, 0.35);
  }
}

:root[data-theme='dark'] {
  --paper: #15141a;
  --paper-raised: #1f1d25;
  --paper-sunken: #100f14;
  --ink: #ece4d6;
  --ink-soft: #b0a89b;
  --ink-faint: #857e73;
  --hong: #d9695a;
  --hong-wash: rgba(217, 105, 90, 0.14);
  --cheong: #7fb0ae;
  --cheong-wash: rgba(127, 176, 174, 0.13);
  --geum: #d5ae5e;
  --line: rgba(236, 228, 214, 0.16);
  --line-strong: rgba(236, 228, 214, 0.34);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 10px 28px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

/* 화면이 짧아 스크롤막대가 사라져도 폭이 변하지 않게 자리를 잡아둔다. */
html { scrollbar-gutter: stable; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.7;
  word-break: keep-all;
  overflow-wrap: break-word;
  text-wrap: pretty;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { font-family: var(--font-display); font-weight: 700; text-wrap: balance; margin: 0; }

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
button:focus-visible, a:focus-visible, summary:focus-visible {
  outline: 2px solid var(--cheong);
  outline-offset: 2px;
}

/* --- 틀 ------------------------------------------------------------------ */

.shell {
  max-width: var(--col);
  margin: 0 auto;
  padding: 0 1.25rem 4rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  background: color-mix(in srgb, var(--paper) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
  margin: 0 -1.25rem;
  padding: 0.7rem 1.25rem;
  display: flex;
  align-items: center;
  gap: 0.9rem;
}

.topbar__title {
  font-family: var(--font-display);
  font-size: 0.95rem;
  letter-spacing: 0.02em;
  white-space: nowrap;
  background: none;
  border: 0;
  padding: 0;
  border-bottom: 1px solid transparent;
}
.topbar__title:hover { border-bottom-color: var(--line-strong); }

.topbar__title { margin-right: auto; }

.gnb { display: flex; gap: 0.3rem; }
.gnb__link {
  background: none;
  border: 1px solid var(--line);
  border-radius: 999px;
  min-height: 2.25rem;
  padding: 0.3rem 0.8rem;
  font-size: 0.85rem;
  color: var(--ink-soft);
  white-space: nowrap;
}
.gnb__link.is-on { color: var(--paper); background: var(--ink); border-color: var(--ink); }
@media (hover: hover) {
  .gnb__link:hover { color: var(--ink); border-color: var(--line-strong); }
  .gnb__link.is-on:hover { color: var(--paper); border-color: var(--ink); }
}

.progress { display: flex; align-items: center; gap: 0.8rem; }
.pips { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
.pip { width: 9px; height: 9px; border-radius: 50%; border: 1px solid var(--line-strong); }
.pip--hit { background: var(--cheong); border-color: var(--cheong); }
.pip--miss { background: var(--hong); border-color: var(--hong); }
.pip--now { box-shadow: 0 0 0 3px var(--cheong-wash); border-color: var(--cheong); }

.score {
  font-variant-numeric: tabular-nums;
  font-size: 0.85rem;
  color: var(--ink-soft);
  white-space: nowrap;
}
.score b { color: var(--ink); font-weight: 600; }

/* --- 표지 ---------------------------------------------------------------- */

.cover { padding-top: 2rem; display: flex; flex-direction: column; align-items: center; gap: 1rem; }
.cover h1 { font-size: clamp(2.2rem, 11vw, 3.4rem); letter-spacing: 0.06em; }
.cover .actions { margin-top: 0.5rem; }

.fan { position: relative; width: min(17rem, 70vw); height: min(19rem, 78vw); }
.fan__card {
  position: absolute;
  bottom: 0;
  left: 50%;
  width: 54%;
  aspect-ratio: 2 / 3;
  object-fit: cover;
  border: 1px solid var(--line-strong);
  border-radius: 3px;
  background: var(--paper-sunken);
  box-shadow: var(--shadow);
  transform-origin: 50% 100%;
}
.fan__card--0 { transform: translateX(-50%) rotate(-13deg) translateY(-0.4rem); }
.fan__card--1 { transform: translateX(-50%) rotate(0deg) translateY(-1.6rem); z-index: 2; }
.fan__card--2 { transform: translateX(-50%) rotate(13deg) translateY(-0.4rem); }

/* --- 문제 ---------------------------------------------------------------- */

.q { display: flex; flex-direction: column; gap: 1.1rem; }

.q__tag {
  align-self: flex-start;
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  color: var(--cheong);
  border: 1px solid var(--cheong);
  border-radius: 999px;
  padding: 0.15rem 0.7rem;
}

.q__clue {
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-left: 3px solid var(--hong);
  border-radius: var(--radius);
  padding: 1.1rem 1.2rem;
  font-family: var(--font-display);
  font-size: 1.2rem;
  line-height: 1.65;
  box-shadow: var(--shadow);
}

.q__ask { font-size: 0.95rem; color: var(--ink-soft); }

.choices { display: grid; grid-template-columns: 1fr 1fr; gap: 0.6rem; }
.choices--wide { grid-template-columns: 1fr; }
@media (max-width: 26rem) { .choices { grid-template-columns: 1fr; } }

.choice {
  position: relative;
  min-height: 3.25rem;
  text-align: left;
  background: var(--paper-raised);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  padding: 0.85rem 0.9rem 0.85rem 2.2rem;
  transition: border-color 0.12s, background 0.12s, transform 0.12s;
}
@media (hover: hover) {
  .choice:hover:not(:disabled) { border-color: var(--ink); transform: translateY(-1px); }
}
.choice:disabled { cursor: default; }
.choice__key {
  position: absolute;
  left: 0.75rem;
  top: 0.85rem;
  font-size: 0.75rem;
  color: var(--ink-faint);
  font-variant-numeric: tabular-nums;
}
.choice__name { font-family: var(--font-display); font-size: 1.05rem; }
.choice__sub { display: block; font-size: 0.82rem; color: var(--ink-soft); line-height: 1.5; }
.choice--right { border-color: var(--cheong); background: var(--cheong-wash); }
.choice--wrong { border-color: var(--hong); background: var(--hong-wash); }

/* --- 해설 ---------------------------------------------------------------- */

.reveal { display: flex; flex-direction: column; gap: 1rem; }

.verdict { font-family: var(--font-display); font-size: 1.1rem; display: flex; align-items: baseline; gap: 0.5rem; }
.verdict--right { color: var(--cheong); }
.verdict--wrong { color: var(--hong); }
.verdict small { font-family: var(--font-body); font-size: 0.82rem; color: var(--ink-soft); }

.sheet {
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.sheet__head { display: flex; gap: 1rem; padding: 1rem; border-bottom: 1px solid var(--line); }
.sheet__card {
  width: 34%;
  max-width: 140px;
  flex-shrink: 0;
  aspect-ratio: 2 / 3;
  object-fit: cover;
  border-radius: 2px;
  border: 1px solid var(--line-strong);
  background: var(--paper-sunken);
}
.sheet__name { display: flex; flex-direction: column; gap: 0.35rem; }
.sheet__name h2 { font-size: 1.8rem; line-height: 1.15; }
.sheet__name h2 span { color: var(--hong); font-size: 1.1rem; margin-left: 0.3rem; }
.sheet__hwatu { font-size: 0.82rem; color: var(--ink-soft); }
.sheet__phase {
  align-self: flex-start;
  font-size: 0.78rem;
  color: var(--geum);
  border: 1px solid var(--geum);
  border-radius: 2px;
  padding: 0.05rem 0.45rem;
}

.rows { display: flex; flex-direction: column; }
.row { display: grid; grid-template-columns: 5.5rem 1fr; gap: 0.8rem; padding: 0.7rem 1rem; border-bottom: 1px solid var(--line); }
.row:last-child { border-bottom: 0; }
.row--lit { background: var(--hong-wash); }
.row dt { font-size: 0.8rem; color: var(--ink-faint); }
.row dd { margin: 0; }
.row--lit dt { color: var(--hong); }

.block { border-top: 1px solid var(--line); padding: 0.8rem 1rem 0.9rem; }
.block--lit { background: var(--hong-wash); }
.block h4 {
  margin: 0 0 0.4rem;
  font-family: var(--font-body);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--ink-faint);
}
.block--lit h4 { color: var(--hong); }
.block ul { margin: 0; padding-left: 1.1rem; display: flex; flex-direction: column; gap: 0.35rem; }
.block li { font-size: 0.92rem; }

/* --- 버튼 ---------------------------------------------------------------- */

.actions { display: flex; gap: 0.6rem; flex-wrap: wrap; }
.btn {
  min-height: 2.75rem;
  border: 1px solid var(--ink);
  background: var(--ink);
  color: var(--paper);
  border-radius: var(--radius);
  padding: 0.65rem 1.4rem;
  font-size: 0.95rem;
  transition: opacity 0.12s;
}
.btn:hover { opacity: 0.85; }
.btn--ghost { background: transparent; color: var(--ink); border-color: var(--line-strong); }
.btn--small { padding: 0.3rem 0.9rem; font-size: 0.85rem; }
.btn--wide { flex: 1; }
.hint { font-size: 0.78rem; color: var(--ink-faint); align-self: center; }

/* --- 결과 ---------------------------------------------------------------- */

.result { display: flex; flex-direction: column; gap: 1.2rem; padding-top: 1.5rem; }
.result__score { font-family: var(--font-display); font-size: 3rem; line-height: 1; font-variant-numeric: tabular-nums; }
.result__score small { font-size: 1rem; color: var(--ink-soft); margin-left: 0.4rem; }
.tally { display: flex; flex-direction: column; gap: 0.5rem; }
.tally__row { display: flex; align-items: baseline; gap: 0.6rem; padding: 0.5rem 0; border-bottom: 1px solid var(--line); }
.tally__mark { width: 1.2rem; }
.tally__mark--hit { color: var(--cheong); }
.tally__mark--miss { color: var(--hong); }
.tally__name { font-family: var(--font-display); font-size: 1.05rem; }
.tally__basic { font-size: 0.85rem; color: var(--ink-soft); }

/* --- 도감 ---------------------------------------------------------------- */

.deck { display: grid; grid-template-columns: repeat(auto-fill, minmax(8.5rem, 1fr)); gap: 0.8rem; }
.deck__item {
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0;
  overflow: hidden;
  text-align: left;
  transition: transform 0.12s, border-color 0.12s;
}
@media (hover: hover) {
  .deck__item:hover { transform: translateY(-2px); border-color: var(--ink); }
}
.deck__item img { width: 100%; aspect-ratio: 2 / 3; object-fit: cover; display: block; background: var(--paper-sunken); }
.deck__label { display: flex; flex-direction: column; gap: 0.1rem; padding: 0.5rem 0.6rem 0.7rem; }
.deck__label b { font-family: var(--font-display); font-size: 1rem; font-weight: 400; }
.deck__label span { font-size: 0.75rem; color: var(--ink-soft); }

.foot {
  max-width: var(--col);
  margin: 0 auto;
  padding: 1.5rem 1.25rem calc(3rem + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.78rem;
  line-height: 1.6;
  color: var(--ink-faint);
}
.foot p { margin: 0; }
.foot__warn { color: var(--ink-soft); }

/* --- 겹쳐 띄운 해설 --------------------------------------------------------- */

body.locked { overflow: hidden; }

.deck__head { font-size: 1.4rem; }

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: var(--paper);
  display: flex;
  justify-content: center;
}

.modal__panel {
  width: 100%;
  height: 100dvh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--paper);
  padding-bottom: calc(2rem + env(safe-area-inset-bottom));
}

@media (min-width: 40rem) {
  .modal {
    background: color-mix(in srgb, var(--ink) 55%, transparent);
    align-items: center;
    padding: 1rem;
  }
  .modal__panel {
    width: min(34rem, 100%);
    height: auto;
    max-height: 88vh;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding-bottom: 0;
  }
}

.modal__bar {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 0.6rem;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}
.modal__nav {
  background: none;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  min-height: 2.5rem;
  padding: 0.3rem 0.9rem;
  font-size: 0.9rem;
  font-family: var(--font-display);
}
.modal__nav:hover { border-color: var(--ink); }
.modal__nav:last-of-type { margin-right: auto; }
.modal__close {
  background: none;
  border: 0;
  font-size: 1.2rem;
  color: var(--ink-soft);
  min-width: 2.75rem;
  min-height: 2.75rem;
}
.modal .sheet { border: 0; box-shadow: none; background: var(--paper); }

@media (max-width: 26rem) {
  .shell { padding: 0 0.9rem 3rem; }
  .topbar { margin: 0 -0.9rem; padding: 0.6rem 0.9rem; gap: 0.5rem; }
  .topbar__title { font-size: 0.88rem; }
  .gnb__link { padding: 0.3rem 0.6rem; font-size: 0.8rem; }
  .row { grid-template-columns: 1fr; gap: 0.15rem; padding: 0.7rem 0.9rem; }
  .sheet__head { padding: 0.9rem; }
  .foot { padding-left: 0.9rem; padding-right: 0.9rem; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
