/* =========================================================================
 * 유진이의 한자교실 — 노자(老子) 도덕경 81장
 * 물빛 수묵(水墨) 서브테마: 청록·먹빛, 한지 바탕, 잔잔한 물결/먹번짐.
 * 한자=명조, UI=Pretendard. 천자문과 같은 브랜드, 다른 '결'.
 * ======================================================================= */

:root {
  --paper: #efe9dc;
  --paper-2: #f6f1e6;
  --surface: #fbf8f1;
  --border: #e0d8c6;
  --border-strong: #cfc6b0;

  --ink: #1f2a30;
  --ink-soft: #45565e;
  --text: #2a3338;
  --text-soft: #6b7880;
  --text-faint: #9aa6ac;

  --teal: #1f7a82;
  --teal-dark: #155a61;
  --teal-soft: #e3f0ef;
  --water: #4ea3b5;
  --jade: #4f9a7d;
  --gold: #b8893f;

  --grad-water: linear-gradient(125deg, #1f7a82 0%, #4ea3b5 55%, #7ab8a6 110%);
  --grad-ink: linear-gradient(125deg, #2a3338 0%, #45565e 100%);

  --shadow-sm: 0 1px 2px rgba(31, 42, 48, 0.06), 0 3px 8px rgba(31, 42, 48, 0.06);
  --shadow-md: 0 2px 6px rgba(31, 42, 48, 0.07), 0 10px 24px rgba(31, 42, 48, 0.1);
  --shadow-lg: 0 10px 24px rgba(20, 40, 45, 0.16), 0 28px 60px rgba(20, 40, 45, 0.18);
  --hairline: inset 0 1px 0 rgba(255, 255, 255, 0.85);

  --r-sm: 12px;
  --r-md: 18px;
  --r-lg: 26px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
:where(button, [tabindex], a):focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(31, 122, 130, 0.35); }
::selection { background: rgba(78, 163, 181, 0.28); color: var(--ink); }
html { scroll-behavior: smooth; }

body {
  font-family: 'Pretendard Variable', 'Pretendard', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color: var(--text);
  line-height: 1.58;
  letter-spacing: -0.018em;
  word-break: keep-all;
  min-height: 100vh;
  overflow-x: hidden;
  background:
    radial-gradient(1100px 600px at 85% -12%, #dfeeec 0%, transparent 55%),
    radial-gradient(900px 560px at -10% 110%, #e7eadf 0%, transparent 52%),
    var(--paper);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  font-feature-settings: 'kern' 1, 'liga' 1, 'calt' 1;
}
.serif { font-family: 'Noto Serif KR', serif; }

.wrap { width: 100%; max-width: 1200px; margin: 0 auto; padding: 0 24px; }

/* ---------- 상단 바 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  backdrop-filter: saturate(150%) blur(12px);
  background: rgba(247, 241, 230, 0.78);
  border-bottom: 1px solid var(--border);
}
.topbar .wrap { display: flex; align-items: center; gap: 14px; height: 64px; }
.brand { display: flex; align-items: center; gap: 11px; text-decoration: none; color: inherit; }
.brand .logo {
  width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center;
  font-family: 'Noto Serif KR', serif; font-weight: 700; font-size: 1.4rem; color: #fff;
  background: var(--grad-water); box-shadow: var(--shadow-sm), var(--hairline);
}
.brand .t h1 { font-size: 1.06rem; font-weight: 800; letter-spacing: -0.5px; line-height: 1.1; }
.brand .t span { font-size: 0.72rem; font-weight: 700; color: var(--teal); letter-spacing: 0.5px; }
.topbar .hud { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.progress-pill {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 999px;
  padding: 7px 14px; font-size: 0.84rem; font-weight: 800; box-shadow: var(--shadow-sm);
}
.progress-pill b { color: var(--teal); }
.sound-toggle {
  width: 38px; height: 38px; border-radius: 11px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); font-size: 1rem;
  box-shadow: var(--shadow-sm); transition: transform 0.16s var(--ease);
}
.sound-toggle:hover { transform: translateY(-1px) scale(1.05); }
.sound-toggle:active { transform: scale(0.93); }

/* ---------- 인트로 헤더 ---------- */
.intro { text-align: center; padding: 46px 20px 8px; position: relative; }
.intro .eyebrow {
  display: inline-block; font-size: 0.76rem; font-weight: 800; letter-spacing: 2px;
  color: var(--teal); background: var(--teal-soft); border: 1px solid #cfe6e3;
  padding: 6px 14px; border-radius: 999px; margin-bottom: 16px;
}
.intro h2 { font-size: clamp(1.7rem, 4vw, 2.4rem); font-weight: 900; letter-spacing: -1px; }
.intro h2 .han { font-family: 'Noto Serif KR', serif; color: var(--teal-dark); }
.intro p { color: var(--text-soft); margin-top: 10px; max-width: 540px; margin-left: auto; margin-right: auto; }

/* 진행 바 (도의 길) */
.dao-meter { max-width: 460px; margin: 22px auto 0; }
.dao-meter .bar { height: 12px; border-radius: 999px; background: var(--paper-2); border: 1px solid var(--border); overflow: hidden; box-shadow: inset 0 1px 3px rgba(31,42,48,0.08); }
.dao-meter .fill { height: 100%; width: 0; border-radius: 999px; background: var(--grad-water); box-shadow: 0 0 12px rgba(31,122,130,0.45); transition: width 0.6s var(--ease); }
.dao-meter .lab { display: flex; justify-content: space-between; font-size: 0.78rem; color: var(--text-soft); font-weight: 700; margin-top: 7px; }
.intro-actions { margin-top: 20px; }
.resume-btn {
  display: inline-flex; align-items: center; gap: 8px; cursor: pointer;
  padding: 13px 28px; border-radius: 999px; border: none;
  font-family: inherit; font-size: 0.98rem; font-weight: 800; color: #fff;
  background: var(--grad-water);
  box-shadow: 0 6px 14px rgba(31,122,130,0.3), var(--hairline);
  transition: transform 0.16s var(--ease), box-shadow 0.16s var(--ease);
}
.resume-btn:hover { transform: translateY(-2px); box-shadow: 0 10px 22px rgba(31,122,130,0.4); }
.resume-btn:active { transform: translateY(0) scale(0.98); }
.resume-btn:disabled { opacity: 0.5; pointer-events: none; box-shadow: none; background: var(--jade); }
.complete-banner {
  margin: 18px auto 0; max-width: 540px; padding: 14px 22px; border-radius: var(--r-md);
  background: linear-gradient(120deg, #fdf2dd, #eaf4f2); border: 1px solid #ecd8b4;
  color: var(--ink); font-weight: 800; box-shadow: var(--shadow-sm); animation: fadeUp 0.5s var(--ease);
}
.complete-banner.hidden { display: none; }

/* ---------- 도(道)의 길: 81 디딤돌 ---------- */
.path-section { padding: 32px 0 90px; }
.stones {
  display: grid; gap: 18px;
  grid-template-columns: repeat(auto-fill, minmax(154px, 1fr));
}
.stone {
  position: relative; aspect-ratio: 1 / 1; cursor: pointer;
  border: 1px solid var(--border); border-radius: 22px; background: var(--surface);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  box-shadow: var(--shadow-sm), var(--hairline); overflow: hidden;
  transition: transform 0.22s var(--ease), box-shadow 0.22s var(--ease), border-color 0.22s var(--ease);
  text-align: center; animation: stoneIn 0.5s var(--ease) both;
}
@keyframes stoneIn { from { opacity: 0; transform: translateY(14px) scale(0.96); } to { opacity: 1; transform: none; } }
.path-divider { grid-column: 1 / -1; display: flex; align-items: center; gap: 16px; margin: 16px 2px 2px; }
.path-divider:first-child { margin-top: 0; }
.path-divider .ln { flex: 1; height: 1px; background: linear-gradient(90deg, transparent, var(--border-strong), transparent); }
.path-divider .lbl { font-family: 'Noto Serif KR', serif; font-weight: 700; font-size: 1.05rem; color: var(--teal-dark); letter-spacing: 1px; white-space: nowrap; }
.path-divider .lbl small { color: var(--text-soft); font-weight: 600; font-size: 0.76rem; letter-spacing: 0; margin-left: 5px; }
.stone::before {
  content: ''; position: absolute; inset: 0; opacity: 0; transition: opacity 0.25s var(--ease);
  background: radial-gradient(120% 90% at 50% 120%, rgba(78,163,181,0.2), transparent 70%);
}
.stone::after {
  content: ''; position: absolute; left: 0; right: 0; top: 0; height: 3px; opacity: 0;
  background: var(--grad-water); transition: opacity 0.25s var(--ease);
}
.stone:hover { transform: translateY(-5px); box-shadow: var(--shadow-md); border-color: #bfe0dc; }
.stone:hover::before, .stone:hover::after { opacity: 1; }
.stone:hover .glyph { color: var(--teal-dark); }
.stone:active { transform: translateY(-2px) scale(0.98); }
.stone .num { font-size: 0.72rem; font-weight: 800; color: var(--text-faint); letter-spacing: 0.6px; }
.stone .glyph { font-family: 'Noto Serif KR', serif; font-weight: 700; font-size: 1.9rem; color: var(--ink); line-height: 1.08; transition: color 0.22s var(--ease); white-space: nowrap; }
.stone .glyph.long { font-size: 1.32rem; letter-spacing: -0.5px; }
.stone .s-read { font-size: 0.74rem; font-weight: 700; color: var(--teal); letter-spacing: 0.5px; line-height: 1.2; }
.stone .ko { font-size: 0.68rem; color: var(--text-soft); font-weight: 600; padding: 0 8px; line-height: 1.25; }
.stone.cleared { background: linear-gradient(165deg, #eaf4f2, #f6f1e6); border-color: #bfe0dc; }
.stone.cleared .glyph { color: var(--teal-dark); }
.stone .seal {
  position: absolute; top: 7px; right: 7px; width: 22px; height: 22px; border-radius: 6px;
  display: grid; place-items: center; font-family: 'Noto Serif KR', serif; font-size: 0.72rem; font-weight: 700;
  color: #fff; background: #b5483f; box-shadow: 0 1px 3px rgba(150,40,30,0.4);
  transform: rotate(-8deg); opacity: 0;
}
.stone.cleared .seal { opacity: 1; }

/* ---------- 오버레이 / 팝업 ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 20px;
  background: rgba(25, 38, 42, 0.5); backdrop-filter: blur(5px);
  animation: fadeIn 0.3s ease;
}
.overlay.hidden { display: none; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.popup {
  width: 100%; max-width: 660px; max-height: 90vh; overflow-y: auto;
  background:
    radial-gradient(120% 55% at 50% -10%, #eaf4f2 0%, transparent 60%),
    var(--surface);
  border: 1px solid var(--border); border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg); padding: 36px 38px 32px;
  animation: popIn 0.4s var(--ease);
}
@keyframes popIn { from { transform: translateY(18px) scale(0.97); opacity: 0; } to { transform: none; opacity: 1; } }

.popup .ph-top {
  display: flex; align-items: center; justify-content: space-between;
  padding-bottom: 14px; margin-bottom: 14px; border-bottom: 1px solid var(--border);
}
.popup .ch-tag {
  font-family: 'Noto Serif KR', serif; font-size: 0.82rem; font-weight: 700;
  color: var(--teal-dark); letter-spacing: 1.5px;
  background: var(--teal-soft); border: 1px solid #cfe6e3; padding: 5px 12px; border-radius: 999px;
}
.popup .x { background: none; border: none; cursor: pointer; font-size: 1.3rem; color: var(--text-faint); line-height: 1; padding: 4px; }
.popup .x:hover { color: var(--ink); }

/* 단계 표시 점 */
.steps-dots { display: flex; gap: 6px; justify-content: center; margin: 4px 0 22px; }
.steps-dots i { flex: 1; max-width: 40px; height: 5px; border-radius: 999px; background: var(--border-strong); transition: 0.3s var(--ease); }
.steps-dots i.on { background: var(--grad-water); box-shadow: 0 1px 4px rgba(31,122,130,0.35); }
.steps-dots i.done { background: var(--jade); }

.step { animation: fadeUp 0.45s var(--ease); }
@keyframes fadeUp { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
.step-head { text-align: center; margin-bottom: 16px; }
.step-head .kicker { font-size: 0.74rem; font-weight: 800; letter-spacing: 1.5px; color: var(--gold); text-transform: uppercase; }
.step-head h3 { font-size: 1.42rem; font-weight: 900; letter-spacing: -0.5px; margin-top: 5px; }
.step-head .ko { color: var(--text-soft); font-size: 0.95rem; margin-top: 3px; }

/* 낭독 */
.recite { display: flex; flex-direction: column; gap: 14px; }
.line {
  position: relative;
  background: var(--paper-2); border: 1px solid var(--border); border-radius: var(--r-md);
  padding: 20px 22px; text-align: center; overflow: hidden;
}
.line::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--grad-water); opacity: 0.55; }
.line .han { font-family: 'Noto Serif KR', serif; font-weight: 700; font-size: 2rem; letter-spacing: 4px; color: var(--ink); }
.line .read { font-size: 0.96rem; font-weight: 700; color: var(--teal); margin-top: 8px; letter-spacing: 1px; }
.line .ko { font-size: 0.98rem; color: var(--text-soft); margin-top: 5px; }
.line .say {
  position: absolute; top: 10px; right: 12px; width: 32px; height: 32px; border-radius: 9px;
  border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-size: 0.9rem;
  display: grid; place-items: center; transition: 0.16s var(--ease); box-shadow: var(--shadow-sm);
}
.line .say:hover { transform: scale(1.08); border-color: var(--water); }
.line .say:active { transform: scale(0.92); }

/* 빈칸 채우기 */
.blank-line { text-align: center; font-family: 'Noto Serif KR', serif; font-weight: 700; font-size: 2.15rem; letter-spacing: 4px; color: var(--ink); margin: 8px 0; }
.blank-box {
  display: inline-grid; place-items: center; width: 1.5em; height: 1.5em; vertical-align: middle;
  border-bottom: 3px solid var(--teal); border-radius: 6px; background: var(--teal-soft); color: var(--teal-dark);
  margin: 0 2px; transition: 0.2s var(--ease);
}
.blank-box.filled { background: #dff0d8; border-color: var(--jade); color: var(--jade); }
.reveal-read { text-align: center; font-size: 1.05rem; font-weight: 700; color: var(--teal); letter-spacing: 2px; margin: 2px 0 10px; animation: fadeUp 0.3s var(--ease); }
.blank-hint { text-align: center; color: var(--text-soft); font-size: 0.9rem; margin-bottom: 14px; }
.choices { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.choice {
  display: flex; flex-direction: column; align-items: center; gap: 3px; color: var(--ink);
  padding: 13px 0 11px; border: 1px solid var(--border); border-radius: var(--r-md); background: var(--surface);
  cursor: pointer; transition: 0.16s var(--ease);
}
.choice .c-han { font-family: 'Noto Serif KR', serif; font-weight: 700; font-size: 1.8rem; line-height: 1.05; }
.choice .c-read { font-size: 0.82rem; font-weight: 700; color: var(--teal); letter-spacing: 0; }
.choice.correct .c-read { color: var(--jade); }
.choice:hover { transform: translateY(-2px); box-shadow: var(--shadow-sm); border-color: var(--water); }
.choice.correct { background: #dff0d8; border-color: var(--jade); color: var(--jade); pointer-events: none; }
.choice.wrong { animation: shake 0.4s; background: #f7e0de; border-color: #d98b84; }
@keyframes shake { 0%,100%{transform:translateX(0)} 20%,60%{transform:translateX(-6px)} 40%,80%{transform:translateX(6px)} }

/* 짝 맞추기 */
.match { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.match .col { display: flex; flex-direction: column; gap: 12px; }
.tile {
  display: flex; flex-direction: column; align-items: center; gap: 3px; color: var(--ink);
  padding: 14px 10px 12px; border: 1px solid var(--border); border-radius: var(--r-md); background: var(--surface);
  cursor: pointer; text-align: center; transition: 0.16s var(--ease);
}
.tile .t-han { font-family: 'Noto Serif KR', serif; font-weight: 700; font-size: 1.5rem; letter-spacing: 2px; line-height: 1.1; }
.tile .t-read { font-size: 0.78rem; font-weight: 700; color: var(--teal); letter-spacing: 0; }
.tile.done .t-read { color: var(--jade); }
.tile:hover { border-color: var(--water); }
.tile.sel { background: var(--teal-soft); border-color: var(--teal); color: var(--teal-dark); }
.tile.done { background: #dff0d8; border-color: var(--jade); color: var(--jade); pointer-events: none; opacity: 0.75; }
.tile.miss { animation: shake 0.4s; }

/* 풀이 / 물음 */
.yujin {
  background: linear-gradient(160deg, var(--teal-soft), var(--paper-2));
  border: 1px solid #cfe6e3; border-radius: var(--r-md); padding: 18px 20px;
  font-size: 1rem; line-height: 1.7; color: var(--ink);
}
.yujin .who { display: flex; align-items: center; gap: 8px; font-weight: 800; color: var(--teal-dark); margin-bottom: 8px; font-size: 0.9rem; }
.muse {
  text-align: center; padding: 8px 6px;
}
.muse .q-mark { font-family: 'Noto Serif KR', serif; font-size: 2.4rem; color: var(--gold); line-height: 1; }
.muse .q { font-size: 1.15rem; font-weight: 800; line-height: 1.6; margin: 10px 0 6px; color: var(--ink); }
.muse .hint { font-size: 0.85rem; color: var(--text-faint); }

/* 보상 */
.reward { text-align: center; padding: 8px 0; }
.reward .seal-big {
  width: 92px; height: 92px; margin: 6px auto 14px; border-radius: 18px;
  display: grid; place-items: center; font-family: 'Noto Serif KR', serif; font-weight: 700; font-size: 2.6rem;
  color: #fff; background: #b5483f; box-shadow: 0 8px 20px rgba(150,40,30,0.4);
  transform: rotate(-7deg); animation: sealIn 0.6s var(--ease);
}
@keyframes sealIn { 0% { transform: rotate(-30deg) scale(0.2); opacity: 0; } 70% { transform: rotate(-4deg) scale(1.1); } 100% { transform: rotate(-7deg) scale(1); } }
.reward h3 { font-size: 1.4rem; font-weight: 900; }
.reward p { color: var(--text-soft); margin-top: 6px; }
.reward .r-title { font-family: 'Noto Serif KR', serif; font-weight: 700; font-size: 1.55rem; color: var(--ink); letter-spacing: 3px; margin-top: 10px; }
.reward .r-read { color: var(--teal); font-weight: 800; letter-spacing: 2px; margin-top: 2px; }
.reward .r-ko { color: var(--text-soft); margin-top: 2px; }

/* 버튼 */
.actions { display: flex; gap: 10px; margin-top: 22px; }
.btn {
  flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 14px 20px; border-radius: 999px; border: none; cursor: pointer;
  font-family: inherit; font-size: 0.98rem; font-weight: 800; color: #fff;
  background: var(--grad-water);
  box-shadow: 0 6px 14px rgba(31,122,130,0.3), var(--hairline);
  transition: transform 0.16s var(--ease), box-shadow 0.16s var(--ease);
}
.btn:hover { transform: translateY(-2px); box-shadow: 0 10px 22px rgba(31,122,130,0.4); }
.btn:active { transform: translateY(0) scale(0.98); }
.btn[disabled] { opacity: 0.45; pointer-events: none; box-shadow: none; }
.btn.ghost { background: var(--surface); color: var(--text-soft); border: 1px solid var(--border); box-shadow: none; flex: 0 0 auto; }
.btn.ghost:hover { color: var(--ink); background: var(--paper-2); transform: none; }

/* 토스트 */
.toast {
  position: fixed; left: 50%; bottom: 30px; transform: translateX(-50%) translateY(12px);
  background: var(--ink); color: #fff; padding: 12px 20px; border-radius: 999px;
  font-size: 0.9rem; font-weight: 700; box-shadow: var(--shadow-lg);
  opacity: 0; pointer-events: none; transition: 0.3s var(--ease); z-index: 200;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.footer { border-top: 1px solid var(--border); text-align: center; padding: 26px 20px; color: var(--text-faint); font-size: 0.84rem; }

/* 도장 획득 축하 연출 */
.fx-layer { position: fixed; inset: 0; pointer-events: none; z-index: 300; overflow: hidden; }
.fx-petal, .fx-ink { position: absolute; top: -8%; will-change: transform, opacity; animation-name: fxFall; animation-timing-function: cubic-bezier(0.4,0.1,0.4,1); animation-fill-mode: both; }
.fx-ink { border-radius: 50%; background: radial-gradient(circle at 35% 35%, #50626b, #1f2a30); }
@keyframes fxFall {
  0% { transform: translate(0, -12vh) rotate(0); opacity: 0; }
  12% { opacity: 1; }
  100% { transform: translate(var(--x), 108vh) rotate(var(--rot)); opacity: 0; }
}

@media (max-width: 720px) {
  .wrap { padding: 0 18px; }
  .stones { grid-template-columns: repeat(auto-fill, minmax(126px, 1fr)); gap: 14px; }
}
@media (max-width: 560px) {
  .stones { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 10px; }
  .stone .glyph { font-size: 1.6rem; }
  .stone .glyph.long { font-size: 1.04rem; }
  .popup { padding: 26px 20px 22px; }
  .choices { gap: 9px; }
  .choice { font-size: 1.55rem; padding: 15px 0; }
  .tile { font-size: 1.35rem; padding: 15px 8px; }
  .line .han { font-size: 1.6rem; letter-spacing: 3px; }
  .blank-line { font-size: 1.8rem; letter-spacing: 3px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; }
  html { scroll-behavior: auto; }
}
