:root {
  --ink: #17233b;
  --ink-soft: #465067;
  --paper: #f4f1e8;
  --paper-deep: #e8e1d2;
  --card: #fffefa;
  --line: #d8d0bd;
  --seal: #b13a32;
  --seal-dark: #842821;
  --gold: #a68542;
  --shadow: 0 14px 40px rgba(23, 35, 59, 0.09);
  --radius: 24px;
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", sans-serif;
  color: var(--ink);
  background: var(--paper);
  font-synthesis: none;
}

* { box-sizing: border-box; }

html {
  min-height: 100%;
  background: var(--paper);
  -webkit-text-size-adjust: 100%;
}

body {
  min-width: 320px;
  min-height: 100dvh;
  margin: 0;
  background:
    radial-gradient(circle at 15% 0%, rgba(255,255,255,.78), transparent 26rem),
    linear-gradient(135deg, rgba(133, 106, 56, .045) 25%, transparent 25%) 0 0 / 8px 8px,
    var(--paper);
  color: var(--ink);
  overscroll-behavior-y: none;
}

button, input { font: inherit; }

button {
  color: inherit;
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible, [tabindex]:focus-visible {
  outline: 3px solid rgba(177, 58, 50, .32);
  outline-offset: 3px;
}

.app-shell {
  width: min(100%, 760px);
  min-height: 100dvh;
  margin: 0 auto;
  padding: max(14px, env(safe-area-inset-top)) 18px calc(92px + env(safe-area-inset-bottom));
}

.app-shell.study-shell { padding-bottom: calc(18px + env(safe-area-inset-bottom)); }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 52px;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 13px;
  background: var(--ink);
  color: var(--card);
  font: 700 1.35rem/1 "Noto Serif CJK KR", "Noto Serif KR", "Batang", serif;
  box-shadow: 0 6px 16px rgba(23, 35, 59, .16);
}

.brand h1 { margin: 0; font-size: 1.35rem; letter-spacing: -.03em; }
.brand small { display: block; margin-top: 2px; color: var(--ink-soft); font-size: .78rem; }

.icon-btn, .soft-btn, .install-btn, .back-btn {
  display: inline-flex;
  min-width: 46px;
  min-height: 46px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: rgba(255, 254, 250, .78);
  cursor: pointer;
}

.install-btn { padding: 0 15px; gap: 7px; font-weight: 750; }
.install-btn[hidden] { display: none; }

.eyebrow {
  margin: 30px 0 8px;
  color: var(--seal);
  font-size: .88rem;
  font-weight: 800;
  letter-spacing: .08em;
}

.home-title {
  margin: 0;
  font: 700 clamp(1.75rem, 7vw, 2.6rem)/1.28 "Noto Serif CJK KR", "Noto Serif KR", "Batang", serif;
  letter-spacing: -.055em;
}

.home-title .today-char, .home-title .today-phrase { color: var(--seal); }
.home-title .today-phrase { letter-spacing: .03em; white-space: nowrap; }
.home-reading { margin: 7px 0 0; color: var(--ink-soft); font-size: 1rem; letter-spacing: .12em; }

.today-panel {
  position: relative;
  overflow: hidden;
  margin-top: 22px;
  padding: 22px;
  border: 1px solid rgba(23, 35, 59, .09);
  border-radius: 28px;
  background: var(--ink);
  color: var(--card);
  box-shadow: var(--shadow);
}

.today-panel::after {
  position: absolute;
  right: -22px;
  bottom: -62px;
  content: "字";
  color: rgba(255,255,255,.055);
  font: 700 11rem/1 serif;
  pointer-events: none;
}

.panel-row { position: relative; z-index: 1; display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; }
.today-panel h2 { margin: 0; font-size: 1.05rem; }
.today-count { margin-top: 6px; font-size: 2rem; font-weight: 850; letter-spacing: -.05em; }
.today-count span { color: #e6c985; }
.goal-edit { border: 0; background: none; color: #d8dfec; font-size: .9rem; text-decoration: underline; text-underline-offset: 4px; cursor: pointer; }

.progress-track { position: relative; z-index: 1; height: 10px; margin-top: 17px; overflow: hidden; border-radius: 999px; background: rgba(255,255,255,.16); }
.progress-fill { height: 100%; border-radius: inherit; background: linear-gradient(90deg, #dcbf7b, #f2dfaa); transition: width .35s ease; }

.primary-start {
  position: relative;
  z-index: 1;
  display: flex;
  width: 100%;
  min-height: 58px;
  margin-top: 18px;
  padding: 0 18px;
  align-items: center;
  justify-content: space-between;
  border: 0;
  border-radius: 18px;
  background: var(--card);
  color: var(--ink);
  font-size: 1.05rem;
  font-weight: 850;
  cursor: pointer;
}

.primary-start .start-char { color: var(--seal); font: 700 1.35rem/1 serif; letter-spacing: .06em; }

.action-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-top: 16px;
}

.action-card {
  display: flex;
  min-height: 112px;
  padding: 17px;
  flex-direction: column;
  align-items: flex-start;
  justify-content: space-between;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: rgba(255, 254, 250, .82);
  text-align: left;
  cursor: pointer;
  box-shadow: 0 7px 24px rgba(23, 35, 59, .045);
}

.action-card:active { transform: scale(.985); }
.action-symbol { color: var(--seal); font: 700 1.5rem/1 serif; }
.action-card strong { font-size: 1.02rem; }
.action-card small { color: var(--ink-soft); font-size: .8rem; line-height: 1.45; }

.bottom-nav {
  position: fixed;
  z-index: 30;
  right: 0;
  bottom: 0;
  left: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  width: min(100%, 760px);
  min-height: calc(70px + env(safe-area-inset-bottom));
  margin: auto;
  padding: 8px 10px env(safe-area-inset-bottom);
  border-top: 1px solid rgba(23, 35, 59, .12);
  background: rgba(250, 248, 241, .94);
  backdrop-filter: blur(16px);
}

.nav-btn {
  display: grid;
  min-height: 54px;
  place-items: center;
  align-content: center;
  gap: 3px;
  border: 0;
  border-radius: 14px;
  background: none;
  color: var(--ink-soft);
  font-size: .74rem;
  cursor: pointer;
}

.nav-btn .nav-glyph { font: 700 1.18rem/1 serif; }
.nav-btn.active { background: rgba(23, 35, 59, .07); color: var(--ink); font-weight: 800; }

.page-heading { margin: 24px 0 6px; font-size: 1.7rem; letter-spacing: -.045em; }
.page-copy { margin: 0 0 22px; color: var(--ink-soft); line-height: 1.65; }

.list-card, .record-card {
  border: 1px solid var(--line);
  border-radius: 22px;
  background: rgba(255, 254, 250, .82);
  box-shadow: 0 7px 24px rgba(23, 35, 59, .045);
}

.review-tabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 20px 0 14px; }
.tab-btn { min-height: 44px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 999px; background: var(--card); font-size: .84rem; cursor: pointer; }
.tab-btn.active { border-color: var(--ink); background: var(--ink); color: white; }

.review-list { display: grid; gap: 10px; }
.review-item { display: grid; grid-template-columns: 58px 1fr auto; min-height: 74px; padding: 8px 12px; align-items: center; border: 1px solid var(--line); border-radius: 18px; background: var(--card); cursor: pointer; }
.review-han { font: 700 2rem/1 serif; }
.review-desc strong { display: block; font-size: .95rem; }
.review-desc small { color: var(--ink-soft); }
.review-start { min-width: 72px; min-height: 42px; border: 0; border-radius: 13px; background: var(--ink); color: white; font-weight: 750; cursor: pointer; }
.phrase-review-item { grid-template-columns: minmax(92px, auto) minmax(0, 1fr) auto; gap: 10px; }
.phrase-review-han { font-size: 1.45rem; letter-spacing: .04em; white-space: nowrap; }
.review-desc { min-width: 0; }
.review-desc small { display: block; overflow: hidden; margin-top: 3px; text-overflow: ellipsis; white-space: nowrap; }
.empty-state { padding: 40px 20px; text-align: center; color: var(--ink-soft); }
.empty-state .empty-char { display: block; margin-bottom: 10px; color: var(--line); font: 700 4rem/1 serif; }

.record-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-top: 20px; }
.record-card { min-height: 124px; padding: 18px; }
.record-card.wide { grid-column: 1 / -1; }
.record-card small { color: var(--ink-soft); }
.record-number { margin-top: 8px; font-size: 1.75rem; font-weight: 850; letter-spacing: -.04em; }
.record-card .progress-track { background: var(--paper-deep); }
.record-card .progress-fill { background: var(--seal); }
.record-note { margin: 12px 0 0; color: var(--ink-soft); font-size: .9rem; line-height: 1.55; }
.source-note { margin: 20px 4px 0; color: var(--ink-soft); font-size: .78rem; line-height: 1.65; }
.source-note a { color: inherit; text-underline-offset: 3px; }

.study-topbar { display: grid; grid-template-columns: 48px 1fr 48px; align-items: center; gap: 10px; }
.study-title { min-width: 0; text-align: center; }
.study-title strong { display: block; font-size: .98rem; }
.study-title small { display: block; margin-top: 2px; overflow: hidden; color: var(--ink-soft); font-size: .77rem; text-overflow: ellipsis; white-space: nowrap; }
.star-btn.active { border-color: #c49d47; background: #fff7df; color: #8a661e; }

.stepper { display: grid; grid-template-columns: repeat(5, 1fr); gap: 7px; margin: 14px 0 10px; }
.step-dot { height: 6px; border-radius: 99px; background: var(--line); }
.step-dot.done { background: #8090a7; }
.step-dot.current { background: var(--seal); }
.stage-label { display: flex; align-items: center; justify-content: space-between; min-height: 29px; }
.stage-label strong { color: var(--seal); font-size: .9rem; }
.stage-label strong small { margin-left: 5px; color: var(--ink-soft); font-size: .76rem; font-weight: 700; }
.stage-label span { color: var(--ink-soft); font-size: .8rem; }
.stage-label .goal-edit { color: var(--ink-soft); }

.prompt-card {
  position: relative;
  display: grid;
  min-height: 142px;
  padding: 12px 18px;
  place-items: center;
  align-content: center;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--card);
}

.prompt-card.compact { min-height: 96px; grid-template-columns: auto 1fr; column-gap: 20px; }
.main-han { font: 700 clamp(5rem, 22vw, 8.5rem)/.95 "Noto Serif CJK KR", "Noto Serif KR", "Batang", serif; }
.compact .main-han { font-size: clamp(3.3rem, 15vw, 5.1rem); }
.prompt-reading { margin-top: 8px; color: var(--ink-soft); font-size: 1.08rem; }
.prompt-reading strong { color: var(--ink); font-size: 1.22rem; }
.covered-mark { color: var(--line); font: 700 4.8rem/1 serif; }

.writing-wrap { position: relative; margin-top: 10px; }
.writing-board {
  position: relative;
  width: min(100%, 520px);
  height: clamp(280px, 45vh, 440px);
  margin: 0 auto;
  overflow: hidden;
  border: 2px solid var(--ink);
  border-radius: 22px;
  background:
    linear-gradient(to right, transparent calc(50% - .5px), rgba(23,35,59,.16) 50%, transparent calc(50% + .5px)),
    linear-gradient(to bottom, transparent calc(50% - .5px), rgba(23,35,59,.16) 50%, transparent calc(50% + .5px)),
    linear-gradient(45deg, transparent calc(50% - .5px), rgba(23,35,59,.08) 50%, transparent calc(50% + .5px)),
    linear-gradient(-45deg, transparent calc(50% - .5px), rgba(23,35,59,.08) 50%, transparent calc(50% + .5px)),
    #fffefa;
  box-shadow: inset 0 0 0 6px rgba(23,35,59,.025);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.trace-char {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: rgba(23,35,59,.12);
  font: 700 min(70vw, 19rem)/1 "Noto Serif CJK KR", "Noto Serif KR", "Batang", serif;
  pointer-events: none;
}

.writing-board canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; }
.writing-board.compare-mode canvas { pointer-events: none; }
.board-hint { position: absolute; right: 0; bottom: 13px; left: 0; color: rgba(23,35,59,.44); font-size: .8rem; text-align: center; pointer-events: none; }
.has-ink .board-hint { opacity: 0; }

.tool-row { display: flex; width: min(100%, 520px); margin: 10px auto 0; gap: 9px; }
.tool-btn { flex: 1; min-height: 46px; border: 1px solid var(--line); border-radius: 14px; background: var(--card); font-weight: 750; cursor: pointer; }
.tool-btn:disabled { opacity: .45; }

.study-actions { display: grid; grid-template-columns: 1fr 1.9fr; width: min(100%, 520px); margin: 10px auto 0; gap: 9px; }
.prev-next-btn, .main-next-btn { min-height: 56px; border-radius: 17px; font-weight: 850; cursor: pointer; }
.prev-next-btn { border: 1px solid var(--line); background: var(--card); }
.main-next-btn { border: 0; background: var(--seal); color: white; box-shadow: 0 7px 18px rgba(177,58,50,.22); }
.main-next-btn:active { background: var(--seal-dark); }

.context-strip { width: min(100%, 520px); margin: 12px auto 0; text-align: center; }
.context-label { margin-bottom: 6px; color: var(--ink-soft); font-size: .76rem; }
.context-chars { display: flex; justify-content: center; gap: 6px; }
.context-char { display: grid; width: 42px; height: 42px; place-items: center; border-radius: 12px; color: var(--ink-soft); font: 700 1.35rem/1 serif; }
.context-char.active { background: var(--ink); color: white; }

.answer-banner { display: flex; width: min(100%, 520px); min-height: 68px; margin: 10px auto 0; padding: 10px 16px; align-items: center; justify-content: space-between; border-radius: 18px; background: #fff5dc; color: var(--ink); }
.answer-banner .answer-han { font: 700 2.7rem/1 serif; }
.answer-banner strong { display: block; }
.answer-banner small { color: var(--ink-soft); }

.phrase-shell { padding-bottom: calc(28px + env(safe-area-inset-bottom)); }
.phrase-seal {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border: 2px solid var(--seal);
  border-radius: 10px;
  color: var(--seal);
  font: 800 1.3rem/1 "Noto Serif CJK KR", "Batang", serif;
  transform: rotate(-3deg);
}
.phrase-hero, .batch-hero {
  margin-top: 18px;
  padding: 28px 18px 25px;
  border: 1px solid var(--line);
  border-radius: 28px;
  background:
    linear-gradient(90deg, rgba(23,35,59,.035) 1px, transparent 1px) 0 0 / 32px 32px,
    linear-gradient(rgba(23,35,59,.035) 1px, transparent 1px) 0 0 / 32px 32px,
    var(--card);
  text-align: center;
  box-shadow: var(--shadow);
}
.phrase-kicker { margin: 0 0 10px; color: var(--seal); font-size: .8rem; font-weight: 850; letter-spacing: .12em; }
.phrase-hero h2 { margin: 0; font: 750 clamp(3.2rem, 15vw, 6rem)/1.1 "Noto Serif CJK KR", "Noto Serif KR", "Batang", serif; letter-spacing: .08em; }
.phrase-reading { margin: 10px 0 0; color: var(--ink-soft); font-size: 1.12rem; font-weight: 750; letter-spacing: .18em; }
.meaning-card {
  margin-top: 12px;
  padding: 19px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: rgba(255,254,250,.88);
}
.meaning-card h3 { margin: 0 0 13px; font-size: .92rem; }
.character-meanings { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.character-meaning { display: flex; min-height: 52px; padding: 9px 11px; align-items: center; gap: 11px; border-radius: 15px; background: var(--paper); color: var(--ink-soft); font-size: .92rem; line-height: 1.4; }
.meaning-han { flex: 0 0 auto; color: var(--ink); font: 750 1.75rem/1 "Noto Serif CJK KR", "Batang", serif; }
.whole-meaning { margin: 0; color: var(--ink); font: 700 1.16rem/1.7 "Noto Serif CJK KR", "Noto Serif KR", "Batang", serif; }
.short-explanation { margin-top: 15px; padding-top: 14px; border-top: 1px solid var(--line); }
.short-explanation strong { color: var(--seal); font-size: .8rem; }
.short-explanation p { margin: 5px 0 0; color: var(--ink-soft); line-height: 1.65; }
.phrase-actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 9px; margin-top: 14px; }
.soft-wide-btn { width: 100%; min-height: 50px; margin-top: 12px; border: 1px solid var(--line); border-radius: 16px; background: var(--card); font-weight: 800; cursor: pointer; }
.batch-hero h2 { margin: 0; color: var(--ink); font: 750 clamp(2.55rem, 12vw, 4.7rem)/1.3 "Noto Serif CJK KR", "Noto Serif KR", "Batang", serif; letter-spacing: .1em; }
.batch-hero > p:last-child { margin: 10px 0 0; color: var(--ink-soft); line-height: 1.65; }
.batch-list { display: grid; gap: 9px; margin-top: 12px; }
.batch-phrase { display: grid; grid-template-columns: minmax(116px, auto) 1fr; gap: 16px; padding: 16px 18px; align-items: center; border: 1px solid var(--line); border-radius: 18px; background: var(--card); }
.batch-phrase strong { display: block; font: 750 1.45rem/1.2 "Noto Serif CJK KR", "Batang", serif; letter-spacing: .06em; }
.batch-phrase small { display: block; margin-top: 4px; color: var(--seal); font-weight: 700; letter-spacing: .08em; }
.batch-phrase p { margin: 0; color: var(--ink-soft); line-height: 1.55; }

.dialog-backdrop {
  position: fixed;
  z-index: 60;
  inset: 0;
  display: grid;
  padding: 20px;
  place-items: end center;
  background: rgba(16, 24, 39, .45);
  backdrop-filter: blur(4px);
}

.dialog-card {
  width: min(100%, 520px);
  padding: 22px;
  border-radius: 26px;
  background: var(--card);
  box-shadow: 0 28px 80px rgba(0,0,0,.25);
}

.dialog-card h2 { margin: 0; font-size: 1.35rem; }
.dialog-card p { margin: 10px 0; color: var(--ink-soft); line-height: 1.65; }
.dialog-card ol { margin: 14px 0; padding-left: 24px; color: var(--ink-soft); line-height: 1.8; }
.goal-options { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 18px 0; }
.goal-option { display: grid; min-height: 62px; place-items: center; gap: 1px; border: 1px solid var(--line); border-radius: 15px; background: white; font-weight: 800; cursor: pointer; }
.goal-option strong { font-size: 1rem; }
.goal-option small { color: var(--ink-soft); font-size: .72rem; font-weight: 650; }
.goal-option.active { border-color: var(--seal); background: #fff0ec; color: var(--seal); }
.dialog-close { width: 100%; min-height: 52px; border: 0; border-radius: 16px; background: var(--ink); color: white; font-weight: 800; cursor: pointer; }

.toast {
  position: fixed;
  z-index: 100;
  right: 18px;
  bottom: calc(90px + env(safe-area-inset-bottom));
  left: 18px;
  width: fit-content;
  max-width: min(90%, 480px);
  margin: auto;
  padding: 13px 17px;
  border-radius: 999px;
  background: rgba(23,35,59,.95);
  color: white;
  font-size: .9rem;
  text-align: center;
  box-shadow: var(--shadow);
  animation: toast-in .22s ease-out;
}

@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

@media (min-width: 700px) {
  .app-shell { padding-right: 28px; padding-left: 28px; }
  .action-grid { grid-template-columns: repeat(3, 1fr); }
  .action-card:first-child { grid-column: span 2; }
  .dialog-backdrop { place-items: center; }
}

@media (max-height: 720px) {
  .app-shell.study-shell { padding-top: max(8px, env(safe-area-inset-top)); }
  .study-topbar { min-height: 44px; }
  .prompt-card { min-height: 108px; }
  .main-han { font-size: 4.7rem; }
  .writing-board { height: clamp(260px, 42vh, 340px); }
  .context-strip { margin-top: 8px; }
}

@media (max-width: 370px) {
  .app-shell { padding-right: 12px; padding-left: 12px; }
  .today-panel { padding: 18px; }
  .action-card { padding: 14px; }
  .prompt-card.compact { column-gap: 12px; }
  .context-char { width: 38px; height: 38px; }
  .character-meaning { padding: 8px; gap: 8px; font-size: .82rem; }
  .meaning-han { font-size: 1.55rem; }
  .batch-phrase { grid-template-columns: 1fr; gap: 7px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
