:root {
  --bg: #06080b;
  --surface: #0d1116;
  --surface-2: #151b22;
  --surface-3: #1d252e;
  --line: rgba(255, 255, 255, 0.09);
  --text: #eef3f7;
  --muted: #8d99a8;
  --accent: #1ee6c4;
  --accent-dim: rgba(30, 230, 196, 0.14);
  --accent-ink: #02201b;
  --danger: #ff4d6d;
  --danger-dim: rgba(255, 77, 109, 0.14);
  --radius: 18px;
  --tabbar-h: 62px;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Noto Sans KR", "Noto Sans TC", "Noto Sans JP",
    "Noto Sans Thai", "Apple SD Gothic Neo", "PingFang TC", "Hiragino Sans", "Malgun Gothic", "Microsoft JhengHei", sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; width: 100%; margin: 0; overflow: hidden; }
html { touch-action: manipulation; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  background: #020304;
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  overflow: hidden;
  position: fixed; inset: 0; /* lock the page to the visible screen: no rubber-band, no sideways drift */
}
[hidden] { display: none !important; }
:lang(ko) { word-break: keep-all; overflow-wrap: anywhere; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; touch-action: manipulation; }
button:focus-visible, [tabindex]:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
h1, h2, p { margin: 0; }
img { display: block; }
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.ic { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

#app {
  position: relative;
  width: 100%;
  height: 100%;
  max-width: 480px;
  margin: 0 auto;
  background: var(--bg);
  overflow: hidden;
}
@media (min-width: 481px) {
  #app { border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
}

/* ---------- brand ---------- */
.brand { display: inline-flex; align-items: center; gap: 9px; font-weight: 700; letter-spacing: -0.01em; font-size: 17px; }
.brand-mark {
  position: relative; width: 22px; height: 22px; border-radius: 7px; flex: none;
  border: 2px solid var(--accent);
}
.brand-mark i { position: absolute; inset: 5px; border-radius: 50%; background: var(--accent); }
.brand-lg { font-size: 22px; gap: 11px; }
.brand-lg .brand-mark { width: 30px; height: 30px; border-radius: 9px; border-width: 2.5px; }
.brand-lg .brand-mark i { inset: 7px; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 9px;
  min-height: 52px; padding: 0 22px; border-radius: 15px;
  font-weight: 650; font-size: 16.5px; letter-spacing: -0.005em;
  transition: transform 0.08s ease, background 0.15s ease, opacity 0.15s ease;
}
.btn:active { transform: scale(0.98); }
.btn-block { display: flex; width: 100%; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary[disabled] { opacity: 0.45; }
.btn-primary.is-done { background: var(--accent-dim); color: var(--accent); }
.btn-ghost { color: var(--muted); min-height: 44px; }
.btn-danger { background: var(--danger-dim); color: var(--danger); }
.btn-danger.is-armed { background: var(--danger); color: #fff; }
.icon-btn {
  display: inline-grid; place-items: center; width: 44px; height: 44px; border-radius: 50%;
  background: var(--surface-3); color: var(--text); flex: none;
}
.icon-btn.speak { background: var(--accent-dim); color: var(--accent); width: 48px; height: 48px; }
.icon-btn.speak.is-speaking { background: var(--accent); color: var(--accent-ink); }
.pill-btn {
  display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 12px 0 15px;
  border-radius: 22px; background: rgba(6, 8, 11, 0.55); border: 1px solid var(--line);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  font-weight: 600; font-size: 14px;
}
.pill-btn .ic { width: 19px; height: 19px; color: var(--muted); }

/* ---------- onboarding ---------- */
.onboarding {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  padding: calc(var(--sat) + 28px) calc(var(--sar) + 22px) calc(var(--sab) + 20px) calc(var(--sal) + 22px);
  overflow-y: auto;
  background:
    radial-gradient(120% 60% at 100% 0%, rgba(30, 230, 196, 0.13), transparent 60%),
    var(--bg);
}
.ob-inner { flex: 1; }
.ob-title { margin: 26px 0 30px; font-size: 31px; line-height: 1.16; letter-spacing: -0.025em; font-weight: 750; text-wrap: balance; }
.field { margin-bottom: 24px; }
.field-label { font-size: 13px; font-weight: 650; color: var(--muted); letter-spacing: 0.04em; text-transform: uppercase; margin-bottom: 11px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  min-height: 44px; padding: 0 15px; border-radius: 13px;
  background: var(--surface-2); border: 1.5px solid transparent;
  font-size: 15.5px; font-weight: 550; color: var(--text);
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}
.chip[aria-checked="true"] { background: var(--accent-dim); border-color: var(--accent); color: var(--accent); }
.ob-foot { padding-top: 10px; }
.ob-note { margin-top: 13px; font-size: 13px; color: var(--muted); text-align: center; line-height: 1.5; text-wrap: pretty; }

/* ---------- views ---------- */
#main { position: absolute; inset: 0; }
.view { position: absolute; inset: 0 0 calc(var(--tabbar-h) + var(--sab)) 0; }
.view-page {
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: calc(var(--sat) + 18px) calc(var(--sar) + 18px) 28px calc(var(--sal) + 18px);
}
.page-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.page-head h1 { font-size: 29px; letter-spacing: -0.025em; font-weight: 750; }
.count { color: var(--muted); font-size: 14.5px; font-weight: 550; white-space: nowrap; font-variant-numeric: tabular-nums; }

/* ---------- camera ---------- */
.view-camera { background: #000; overflow: hidden; touch-action: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
#video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: #05070a; }
/* A picked photo is shown whole, in the space the result card leaves free. */
.still { position: absolute; left: 0; right: 0; top: 0; width: 100%; height: 56%; padding: calc(var(--sat) + 70px) 18px 14px; object-fit: contain; z-index: 5; }
.still:not([hidden]) ~ .cam-shade { background: var(--bg); z-index: 4; }
.cam-shade {
  position: absolute; inset: 0; pointer-events: none;
  background:
    linear-gradient(to bottom, rgba(3, 5, 7, 0.72), transparent 22%),
    linear-gradient(to top, rgba(3, 5, 7, 0.82), transparent 34%);
}
.cam-top {
  position: absolute; top: 0; left: 0; right: 0; z-index: 6;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(var(--sat) + 12px) calc(var(--sar) + 14px) 0 calc(var(--sal) + 16px);
}
.reticle {
  position: absolute; left: 50%; top: 43%; width: min(68%, 300px); aspect-ratio: 1;
  transform: translate(-50%, -50%); pointer-events: none; z-index: 2;
  transition: transform 0.25s ease, opacity 0.2s ease;
}
.reticle .c { position: absolute; width: 30px; height: 30px; border: 3px solid rgba(255, 255, 255, 0.9); transition: border-color 0.2s ease; }
.reticle .tl { top: 0; left: 0; border-right: 0; border-bottom: 0; border-top-left-radius: 14px; }
.reticle .tr { top: 0; right: 0; border-left: 0; border-bottom: 0; border-top-right-radius: 14px; }
.reticle .bl { bottom: 0; left: 0; border-right: 0; border-top: 0; border-bottom-left-radius: 14px; }
.reticle .br { bottom: 0; right: 0; border-left: 0; border-top: 0; border-bottom-right-radius: 14px; }
.reticle .sweep {
  position: absolute; left: 8%; right: 8%; top: 8%; height: 2px; border-radius: 2px; opacity: 0;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  box-shadow: 0 0 16px 2px rgba(30, 230, 196, 0.5);
}
.reticle[data-state="steady"] { transform: translate(-50%, -50%) scale(0.96); }
.reticle[data-state="scanning"] { transform: translate(-50%, -50%) scale(0.96); }
.reticle[data-state="scanning"] .c { border-color: var(--accent); }
.reticle[data-state="scanning"] .sweep { opacity: 1; animation: sweep 1.3s ease-in-out infinite alternate; }
.reticle[data-state="off"] { opacity: 0; }
@keyframes sweep { from { top: 8%; } to { top: 92%; } }

.status {
  position: absolute; left: 50%; top: calc(43% + min(34%, 150px) + 26px); transform: translateX(-50%); z-index: 3;
  max-width: calc(100% - 40px); padding: 8px 15px; border-radius: 20px;
  background: rgba(6, 8, 11, 0.6); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  font-size: 14px; font-weight: 600; text-align: center; white-space: nowrap;
  transition: opacity 0.2s ease, color 0.2s ease;
}
.status:empty { opacity: 0; }
.status.is-accent { color: var(--accent); }

.cam-controls {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 3;
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; justify-items: center;
  padding: 0 calc(var(--sar) + 18px) 20px calc(var(--sal) + 18px);
}
.ctl { display: flex; flex-direction: column; align-items: center; gap: 5px; min-width: 76px; min-height: 60px; font-size: 12px; font-weight: 600; color: var(--text); }
.ctl-ic {
  display: grid; place-items: center; width: 46px; height: 46px; border-radius: 50%;
  background: rgba(6, 8, 11, 0.55); border: 1px solid var(--line);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
.ctl[aria-pressed="true"] .ctl-ic { background: var(--accent-dim); border-color: rgba(30, 230, 196, 0.55); color: var(--accent); }
.ctl[aria-pressed="false"] .ctl-label { color: var(--muted); }
.shutter { width: 76px; height: 76px; border-radius: 50%; border: 3px solid #fff; display: grid; place-items: center; }
.shutter span { width: 60px; height: 60px; border-radius: 50%; background: #fff; transition: transform 0.1s ease, background 0.2s ease; }
.shutter:active span { transform: scale(0.9); }
.shutter.is-busy { border-color: var(--accent); }
.shutter.is-busy span { background: var(--accent); transform: scale(0.72); }

.cam-fallback {
  position: absolute; inset: 0; z-index: 4; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 12px; padding: 24px 28px; text-align: center; background: var(--bg);
}
.cam-fallback h2 { font-size: 23px; letter-spacing: -0.02em; margin-top: 8px; }
.cam-fallback p { color: var(--muted); max-width: 300px; margin-bottom: 12px; text-wrap: pretty; }
.fb-icon, .empty-art {
  display: grid; place-items: center; width: 72px; height: 72px; border-radius: 24px;
  background: var(--surface-2); color: var(--accent);
}
.fb-icon .ic, .empty-art .ic { width: 32px; height: 32px; }
.cam-fallback.has-still { background: transparent; pointer-events: none; }
.cam-fallback.has-still > * { display: none; }

/* ---------- result card ---------- */
.card {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 6;
  padding: 10px calc(var(--sar) + 20px) 18px calc(var(--sal) + 20px);
  background: var(--surface); border-top: 1px solid var(--line);
  border-radius: 26px 26px 0 0;
  box-shadow: 0 -20px 50px rgba(0, 0, 0, 0.55);
  animation: card-in 0.28s cubic-bezier(0.2, 0.9, 0.25, 1);
}
.card.is-leaving { animation: card-out 0.2s ease forwards; }
@keyframes card-in { from { transform: translateY(100%); } to { transform: none; } }
@keyframes card-out { to { transform: translateY(105%); } }
.card-grab { width: 38px; height: 4px; border-radius: 2px; background: var(--surface-3); margin: 0 auto 14px; }
.card-close { position: absolute; top: 14px; right: 14px; width: 36px; height: 36px; background: transparent; color: var(--muted); }
.card-close::before { content: ""; position: absolute; inset: -4px; }
.card-head { display: flex; align-items: center; gap: 14px; }
.card .card-head { padding-right: 30px; }
.card-thumb { width: 60px; height: 60px; border-radius: 15px; object-fit: cover; background: var(--surface-2); flex: none; }
.card-main { flex: 1; min-width: 0; }
.word { font-size: 38px; line-height: 1.12; font-weight: 750; letter-spacing: -0.02em; overflow-wrap: anywhere; }
.word.is-long { font-size: 28px; }
.reading { margin-top: 3px; color: var(--accent); font-size: 17px; font-weight: 550; overflow-wrap: anywhere; }
.reading:empty { display: none; }
.meaning { margin-top: 14px; font-size: 20px; font-weight: 600; }
.example { margin-top: 12px; padding: 12px 14px; border-radius: 14px; background: var(--surface-2); }
.ex-src { font-size: 16.5px; font-weight: 550; }
.ex-tr { margin-top: 3px; font-size: 14.5px; color: var(--muted); }
.card .btn-block { margin-top: 16px; }
.demo-tag { margin-top: 10px; text-align: center; font-size: 12px; color: var(--muted); letter-spacing: 0.03em; }

/* ---------- wordbook ---------- */
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.tile {
  display: flex; flex-direction: column; text-align: left; border-radius: var(--radius); overflow: hidden;
  background: var(--surface); border: 1px solid var(--line);
  transition: transform 0.08s ease;
}
.tile:active { transform: scale(0.98); }
.tile img { width: 100%; aspect-ratio: 1; object-fit: cover; background: var(--surface-2); }
.tile-body { padding: 11px 13px 13px; min-width: 0; }
.tile-word { font-size: 21px; font-weight: 700; letter-spacing: -0.015em; line-height: 1.2; overflow-wrap: anywhere; }
.tile-reading { color: var(--accent); font-size: 13.5px; font-weight: 550; margin-top: 2px; overflow-wrap: anywhere; }
.tile-meaning { color: var(--muted); font-size: 14.5px; margin-top: 5px; overflow-wrap: anywhere; }
.tile-lang { float: right; margin: 3px 0 0 6px; padding: 1px 6px; border-radius: 6px; background: var(--surface-3); color: var(--muted); font-size: 10.5px; font-weight: 700; letter-spacing: 0.04em; }
.notice { margin-bottom: 16px; padding: 12px 14px; border-radius: 14px; background: var(--danger-dim); color: #ffb3c0; font-size: 14px; }

.empty { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 10px; padding: 9vh 14px 20px; }
.empty h2 { font-size: 22px; letter-spacing: -0.02em; margin-top: 10px; text-wrap: balance; }
.empty p { color: var(--muted); max-width: 290px; margin-bottom: 14px; text-wrap: pretty; }
.progress-ring {
  display: flex; align-items: baseline; justify-content: center; gap: 4px; width: 104px; height: 104px; border-radius: 50%;
  border: 3px solid var(--surface-3); padding-top: 28px; font-variant-numeric: tabular-nums;
}
.progress-ring span { font-size: 40px; font-weight: 750; color: var(--accent); line-height: 1; }
.progress-ring small { font-size: 16px; color: var(--muted); font-weight: 600; }

/* ---------- review ---------- */
.quiz-photo { border-radius: 22px; overflow: hidden; background: var(--surface); border: 1px solid var(--line); }
.quiz-photo { max-width: 330px; margin: 0 auto; }
.quiz-photo img { width: 100%; aspect-ratio: 1; object-fit: cover; }
.quiz-q { margin: 16px 2px 11px; font-size: 14px; color: var(--muted); font-weight: 650; letter-spacing: 0.04em; text-transform: uppercase; }
.quiz-options { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.opt {
  min-height: 64px; padding: 10px 12px; border-radius: 16px; background: var(--surface-2); border: 1.5px solid transparent;
  font-size: 20px; font-weight: 650; overflow-wrap: anywhere; line-height: 1.2;
  transition: background 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
}
.opt.is-right { background: var(--accent-dim); border-color: var(--accent); color: var(--accent); }
.opt.is-wrong { background: var(--danger-dim); border-color: var(--danger); color: var(--danger); }
.opt.is-dim { opacity: 0.4; }
.quiz-feedback { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-top: 16px; }
.qf-text { min-width: 0; display: flex; flex-direction: column; }
.qf-text strong { font-size: 17px; }
.qf-text.is-right strong { color: var(--accent); }
.qf-text.is-wrong strong { color: var(--danger); }
.qf-text span { color: var(--muted); font-size: 14.5px; overflow-wrap: anywhere; }
.quiz-feedback .btn { flex: none; }

/* ---------- tab bar ---------- */
.tabbar {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 8;
  height: calc(var(--tabbar-h) + var(--sab)); padding: 0 calc(var(--sar) + 6px) var(--sab) calc(var(--sal) + 6px);
  display: grid; grid-template-columns: repeat(3, 1fr);
  background: var(--bg); border-top: 1px solid var(--line);
}
.tab { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: var(--muted); font-size: 11.5px; font-weight: 600; }
.tab[aria-current="page"] { color: var(--accent); }
.tab-ic { position: relative; display: grid; }
.tab-ic b {
  position: absolute; top: -5px; left: 14px; min-width: 17px; height: 17px; padding: 0 4px; border-radius: 9px;
  background: var(--accent); color: var(--accent-ink); font-size: 10.5px; font-weight: 750; line-height: 17px; text-align: center;
}

/* ---------- sheets ---------- */
.sheet-wrap { position: absolute; inset: 0; z-index: 20; display: flex; align-items: flex-end; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.62); animation: fade-in 0.2s ease; }
.sheet {
  position: relative; width: 100%; max-height: 92%; overflow-y: auto;
  padding: 20px calc(var(--sar) + 20px) calc(var(--sab) + 20px) calc(var(--sal) + 20px);
  background: var(--surface); border-radius: 26px 26px 0 0; border-top: 1px solid var(--line);
  animation: card-in 0.28s cubic-bezier(0.2, 0.9, 0.25, 1);
}
@keyframes fade-in { from { opacity: 0; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.sheet-head h2 { font-size: 23px; letter-spacing: -0.02em; }
.detail-photo { position: relative; margin-bottom: 18px; border-radius: 20px; overflow: hidden; background: var(--surface-2); }
.detail-photo img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; }
.detail-close { position: absolute; top: 10px; right: 10px; background: rgba(6, 8, 11, 0.6); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }
.sheet .btn-block { margin-top: 18px; }

/* ---------- toast + offline ---------- */
.toast {
  position: absolute; left: 50%; bottom: calc(var(--tabbar-h) + var(--sab) + 18px); transform: translateX(-50%); z-index: 30;
  display: flex; align-items: center; gap: 9px; max-width: calc(100% - 32px); width: max-content;
  padding: 12px 17px; border-radius: 15px; background: var(--surface-3); border: 1px solid var(--line);
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.5); font-size: 15px; font-weight: 600;
  animation: toast-in 0.2s ease;
}
.toast.is-ok { color: var(--accent); }
.toast.is-err { color: #ff8fa3; }
.toast.is-top { bottom: auto; top: calc(var(--sat) + 70px); }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } }
.offline {
  position: absolute; top: calc(var(--sat) + 64px); left: 50%; transform: translateX(-50%); z-index: 25;
  display: flex; align-items: center; gap: 9px; width: max-content; max-width: calc(100% - 32px);
  padding: 10px 15px; border-radius: 14px; background: #2a1820; border: 1px solid rgba(255, 77, 109, 0.4); color: #ffb3c0;
  font-size: 14px; font-weight: 600;
}
.offline .ic { width: 19px; height: 19px; }
.offline.is-nudge { animation: nudge 0.35s ease; }
@keyframes nudge { 30% { transform: translateX(-50%) scale(1.05); } }
.is-offline .toast.is-top { top: calc(var(--sat) + 122px); }

@media (max-height: 640px) {
  .ob-title { font-size: 26px; margin: 18px 0 20px; }
  .field { margin-bottom: 16px; }
  .word { font-size: 32px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
