:root {
  --paper: #f4efe5;
  --surface: #fffdf8;
  --ink: #1f211f;
  --muted: #6f716c;
  --line: #d8d0c3;
  --red: #bf4938;
  --green: #247562;
  --blue: #315f89;
  --gold: #a87318;
  --purple: #71577e;
  --coral: #c8644e;
  --shadow: 0 16px 42px rgba(51, 43, 31, 0.12);
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--paper);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, input, select { font: inherit; }
button { cursor: pointer; }

.app-shell {
  width: min(100%, 480px);
  min-height: 100vh;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 16px max(30px, env(safe-area-inset-bottom));
}

.app-version {
  margin-top: 28px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 750;
  text-align: center;
}

.topbar, .section-heading, .detail-heading, .card-tags {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.topbar { padding: 4px 0 14px; }
.section-heading { align-items: flex-end; margin-bottom: 12px; }
.detail-heading { justify-content: flex-start; align-items: flex-start; margin: 16px 0; }

h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(1.9rem, 9vw, 2.5rem); line-height: 1; letter-spacing: 0; }
h2 { margin-bottom: 0; font-size: 1.25rem; line-height: 1.2; letter-spacing: 0; }
h3 { margin-bottom: 0; font-size: 1rem; letter-spacing: 0; }

.eyebrow, .section-label {
  margin: 0 0 4px;
  color: var(--red);
  font-size: 0.74rem;
  font-weight: 850;
  letter-spacing: 0;
  text-transform: uppercase;
}

.icon-button, .save-button {
  display: grid;
  place-items: center;
  flex: 0 0 44px;
  width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font-size: 1.08rem;
}

.save-button.saved { border-color: #cfaa52; background: #f6dfa4; color: #73500e; }

.tabbar {
  position: sticky;
  top: 0;
  z-index: 3;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 4px;
  margin-bottom: 16px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(244, 239, 229, 0.95);
  backdrop-filter: blur(14px);
}

.tab {
  min-width: 0;
  min-height: 42px;
  padding: 0 4px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: clamp(0.68rem, 3.5vw, 0.82rem);
  font-weight: 800;
}

.tab.active { background: var(--ink); color: white; }
.view { display: none; }
.view.active { display: block; }

.mission-panel {
  position: relative;
  display: grid;
  grid-template-columns: 112px minmax(0, 1fr);
  min-height: 224px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(135deg, #e2ebef, #f8e6d4);
  box-shadow: var(--shadow);
}

.mission-copy { z-index: 1; padding: 22px 18px 20px 8px; }
.mission-copy h2 { margin-bottom: 8px; font-size: clamp(1.65rem, 8vw, 2.25rem); line-height: 1.05; }
.mission-copy > p:not(.section-label) { margin-bottom: 17px; color: #59615f; line-height: 1.4; }
.mission-art { position: relative; min-height: 100%; }
.building { position: absolute; left: 18px; bottom: 0; display: grid; place-items: start center; width: 84px; height: 176px; padding-top: 23px; border: 5px solid #2b5275; border-bottom: 0; border-radius: 8px 8px 0 0; background: #f8f4e9; color: #2b5275; font-size: 2.2rem; font-weight: 900; }
.door { position: absolute; left: 45px; bottom: 0; z-index: 1; width: 32px; height: 60px; border-radius: 5px 5px 0 0; background: var(--red); }
.pin { position: absolute; left: 76px; top: 20px; z-index: 2; display: grid; place-items: center; width: 34px; height: 34px; border-radius: 50% 50% 50% 0; transform: rotate(-45deg); background: var(--green); color: white; font-size: 0.5rem; }
.pin::first-letter { transform: rotate(45deg); }

.primary-button, .ghost-button, .back-button, .text-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 15px;
  border-radius: 8px;
  font-weight: 800;
}

.primary-button { border: 1px solid var(--green); background: var(--green); color: white; }
.ghost-button { border: 1px solid var(--line); background: var(--surface); color: var(--ink); }
.back-button, .text-button { padding: 0; border: 0; background: transparent; color: var(--blue); }
.wide-button { width: 100%; }

.stats-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px; margin: 14px 0 20px; }
.stat { min-width: 0; padding: 12px; border: 1px solid var(--line); border-radius: 8px; background: rgba(255, 253, 248, 0.76); }
.stat span { display: block; font-size: 1.22rem; font-weight: 900; }
.stat p { margin: 2px 0 0; color: var(--muted); font-size: 0.74rem; }
.content-section { margin-top: 22px; }

.quick-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 9px; }
.quick-action { display: grid; place-items: center; gap: 8px; min-width: 0; min-height: 92px; padding: 10px 5px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--ink); }
.quick-action span { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 50%; background: rgba(49, 95, 137, 0.12); color: var(--blue); font-size: 1rem; font-weight: 900; }
.quick-action strong { font-size: 0.8rem; }

.compact-phrase, .mini-phrase, .phrasebook-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 44px;
  align-items: center;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.mini-phrase { grid-template-columns: minmax(0, 1fr) 94px; align-items: start; }
.phrase-actions { display: grid; gap: 6px; }
.phrase-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 0 7px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: white;
  color: var(--ink);
  font-size: 0.72rem;
  font-weight: 800;
  text-decoration: none;
}
.google-link { color: var(--blue); }

.compact-phrase strong, .mini-phrase strong { display: block; margin-bottom: 4px; font-size: 1.18rem; }
.compact-phrase span, .mini-phrase span { display: block; color: var(--muted); font-size: 0.88rem; line-height: 1.35; }

.situation-grid { display: grid; gap: 9px; }
.situation-card { display: grid; grid-template-columns: 48px minmax(0, 1fr) 20px; align-items: center; gap: 12px; width: 100%; min-height: 96px; padding: 13px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--ink); text-align: left; }
.situation-icon, .detail-icon { display: grid; place-items: center; width: 48px; height: 48px; border-radius: 8px; background: #eee; color: white; font-size: 1rem; font-weight: 900; }
.situation-copy { min-width: 0; }
.situation-copy strong, .situation-copy small, .situation-copy em { display: block; }
.situation-copy strong { margin-bottom: 3px; font-size: 1rem; }
.situation-copy small { overflow: hidden; color: var(--muted); font-size: 0.8rem; line-height: 1.3; text-overflow: ellipsis; white-space: nowrap; }
.situation-copy em { margin-top: 7px; color: var(--blue); font-size: 0.72rem; font-style: normal; font-weight: 800; }
.chevron { color: var(--muted); font-size: 1.4rem; }
.red { background: var(--red); } .blue { background: var(--blue); } .green { background: var(--green); } .gold { background: var(--gold); } .purple { background: var(--purple); } .teal { background: #1f7f8b; } .coral { background: var(--coral); } .dark { background: var(--ink); }
.detail-heading p:not(.section-label) { margin: 6px 0 0; color: var(--muted); line-height: 1.4; }
.lesson-progress { width: 100%; height: 6px; overflow: hidden; border-radius: 999px; background: #ded8cd; }
.lesson-progress span { display: block; width: 0; height: 100%; border-radius: inherit; background: var(--green); transition: width 180ms ease; }
.phrase-strip { display: grid; gap: 8px; }
.word-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.word-item { display: grid; gap: 12px; min-width: 0; padding: 13px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.word-item strong, .word-item span { display: block; }
.word-item strong { margin-bottom: 3px; font-size: 1.28rem; }
.word-item span { overflow-wrap: anywhere; color: var(--muted); font-size: 0.78rem; line-height: 1.35; }
.word-item .phrase-actions { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.word-item .phrase-action { padding: 0 3px; font-size: 0.65rem; }
.word-item.known-word { border-color: #b8d1c6; background: #edf7f2; }
.word-item.known-word strong::after { content: " Known"; color: var(--green); font-size: 0.64rem; font-weight: 850; }

.order-builder { display: grid; gap: 8px; }
.order-builder label, .control-label { color: var(--muted); font-size: 0.76rem; font-weight: 800; }
.order-builder select { width: 100%; min-height: 48px; padding: 0 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--ink); }
.quantity-control { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; padding: 5px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.quantity-control button { min-height: 40px; border: 0; border-radius: 6px; background: transparent; color: var(--muted); font-weight: 900; }
.quantity-control button.active { background: var(--ink); color: white; }
.order-result { margin-top: 4px; padding: 16px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); box-shadow: 0 8px 24px rgba(51, 43, 31, 0.07); }
.order-result > strong, .order-result > span { display: block; }
.order-result > strong { margin: 8px 0; font-size: clamp(1.65rem, 8vw, 2.3rem); line-height: 1.12; word-break: keep-all; }
.order-result > span { color: var(--muted); line-height: 1.4; }
.order-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-top: 16px; }
.order-actions a { text-decoration: none; }

.conversation-panel, .flashcard, .vocab-flashcard {
  margin-top: 22px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 8px 24px rgba(51, 43, 31, 0.07);
}

.vocab-flashcard { display: grid; gap: 14px; margin: 0 0 12px; }
.flashcard-face {
  display: grid;
  align-content: center;
  width: 100%;
  min-height: 238px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffaf0;
  color: var(--ink);
  text-align: left;
}
.flashcard-face .korean { margin-bottom: 10px; }
.flashcard-face .meaning-large { min-height: 0; margin-bottom: 0; }
.flashcard-actions { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 7px; }
.flashcard-actions .primary-button, .flashcard-actions .ghost-button { min-width: 0; padding: 0 8px; font-size: 0.76rem; text-align: center; text-decoration: none; }
.secondary-actions { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.flashcard-actions button:disabled { cursor: default; opacity: 0.45; }

.chat-log { display: grid; gap: 10px; }
.chat-bubble { width: 88%; padding: 11px 12px; border-radius: 8px 8px 8px 2px; background: #e7edf0; }
.chat-bubble.user { justify-self: end; border-radius: 8px 8px 2px 8px; background: #e1efe9; }
.chat-bubble small { display: block; margin-bottom: 4px; color: var(--muted); font-size: 0.7rem; font-weight: 800; }
.chat-bubble button { width: 100%; padding: 0; border: 0; background: transparent; color: var(--ink); font-weight: 850; text-align: left; }
.chat-bubble button span { float: right; color: var(--green); }
.chat-bubble p { margin: 4px 0 0; color: var(--muted); font-size: 0.8rem; }
.google-inline { display: inline-block; margin-top: 8px; color: var(--blue); font-size: 0.72rem; font-weight: 800; text-decoration: none; }
.conversation-choices { display: grid; gap: 8px; margin-top: 12px; }
.conversation-choice { min-height: 62px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: white; color: var(--ink); text-align: left; }
.conversation-choice strong, .conversation-choice span { display: block; }
.conversation-choice span { margin-top: 3px; color: var(--muted); font-size: 0.8rem; }

.queue-count { flex: 0 0 auto; color: var(--muted); font-size: 0.78rem; font-weight: 800; }
.flashcard { min-height: 410px; margin-top: 0; }
.card-tags { margin-bottom: 28px; }
.card-tags > span { display: inline-flex; align-items: center; min-height: 32px; padding: 0 10px; border-radius: 999px; background: rgba(49, 95, 137, 0.12); color: var(--blue); font-size: 0.75rem; font-weight: 850; }
.prompt-label { margin-bottom: 8px; color: var(--muted); font-size: 0.76rem; font-weight: 800; text-transform: uppercase; }
.meaning { color: var(--muted); line-height: 1.45; }
.meaning-large { min-height: 74px; margin-bottom: 22px; color: var(--ink); font-size: 1.5rem; font-weight: 850; line-height: 1.2; }
.answer-block { margin: 0 0 18px; padding-top: 18px; border-top: 1px solid var(--line); }
.korean { margin-bottom: 7px; font-size: clamp(2rem, 11vw, 3rem); font-weight: 900; line-height: 1.06; word-break: keep-all; }
.roman { margin-bottom: 12px; color: var(--blue); font-weight: 750; }
.review-actions { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 7px; }
.review-actions button { min-width: 0; min-height: 62px; padding: 7px 3px; border: 1px solid var(--line); border-radius: 8px; background: white; color: var(--ink); }
.review-actions strong, .review-actions span { display: block; }
.review-actions strong { font-size: 0.76rem; }
.review-actions span { margin-top: 3px; color: var(--muted); font-size: 0.66rem; }

.toggle-label { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 0.78rem; font-weight: 800; }
.toggle-label input { width: 18px; height: 18px; accent-color: var(--green); }
.search-box { display: flex; align-items: center; gap: 9px; min-height: 48px; padding: 0 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.search-box input { width: 100%; border: 0; outline: 0; background: transparent; color: var(--ink); }
.category-chips { display: flex; gap: 7px; overflow-x: auto; padding: 12px 0; scrollbar-width: none; }
.chip { flex: 0 0 auto; min-height: 36px; padding: 0 12px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); color: var(--muted); font-weight: 800; }
.chip.active { border-color: var(--gold); background: #f6dfa4; color: #67480f; }
.phrasebook-list { display: grid; gap: 8px; }
.phrasebook-item { padding: 8px 9px 8px 13px; }
.phrase-main { min-width: 0; padding: 5px 0; border: 0; background: transparent; color: var(--ink); text-align: left; }
.phrase-main small, .phrase-main strong, .phrase-main span { display: block; }
.phrase-main small { margin-bottom: 2px; color: var(--red); font-size: 0.68rem; font-weight: 850; text-transform: uppercase; }
.phrase-main strong { margin-bottom: 3px; font-size: 1.15rem; }
.phrase-main span { overflow: hidden; color: var(--muted); font-size: 0.82rem; text-overflow: ellipsis; white-space: nowrap; }

.feedback { min-height: 20px; margin: 10px 0 0; color: var(--muted); font-size: 0.82rem; font-weight: 750; }
.empty-state { padding: 20px; border: 1px solid var(--line); border-radius: 8px; background: rgba(255, 253, 248, 0.78); color: var(--muted); text-align: center; }
.empty-state p { margin-bottom: 4px; color: var(--ink); font-weight: 900; }
.empty-state span { display: block; margin-bottom: 14px; font-size: 0.86rem; }

.travel-dialog { width: min(calc(100% - 28px), 440px); padding: 24px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.travel-dialog::backdrop { background: rgba(21, 23, 22, 0.66); backdrop-filter: blur(3px); }
.dialog-close { position: absolute; top: 10px; right: 10px; display: grid; place-items: center; width: 40px; height: 40px; border: 0; background: transparent; color: var(--muted); font-size: 1.7rem; }
.travel-korean { margin: 30px 0 8px; font-size: clamp(2.4rem, 13vw, 3.7rem); font-weight: 900; line-height: 1.06; word-break: keep-all; }

@media (min-width: 720px) {
  body { background: linear-gradient(90deg, rgba(49, 95, 137, 0.07) 1px, transparent 1px), var(--paper); background-size: 48px 48px; }
  .app-shell { padding-top: 28px; padding-bottom: 40px; }
}
