/* Layout: một cột 640px kiểu sổ học từ, thẻ trung tâm, thanh tab dưới cho iPhone. */
:root {
  --bg: #f4f6f1;
  --surface: #ffffff;
  --surface-2: #e9eee5;
  --ink: #17251c;
  --muted: #5c6b60;
  --line: #d3dbcf;
  --brand: #14532d;
  --brand-ink: #ffffff;
  --hl: #fde68a;
  --hl-ink: #3b2f05;
  --ok: #15803d;
  --ok-bg: #dcfce7;
  --bad: #b91c1c;
  --bad-bg: #fee2e2;
  --warn: #a16207;
  --font-ui: "Be Vietnam Pro", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-ipa: "Noto Sans", "Lucida Sans Unicode", "Arial Unicode MS", sans-serif;
  --r: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1511; --surface: #16201a; --surface-2: #1f2b23; --ink: #e6efe7; --muted: #9aab9e; --line: #2c3a30;
    --brand: #4ade80; --brand-ink: #062b14; --hl: #facc15; --hl-ink: #1f1800;
    --ok: #4ade80; --ok-bg: #12301d; --bad: #f87171; --bad-bg: #3a1515; --warn: #facc15; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e1511; --surface: #16201a; --surface-2: #1f2b23; --ink: #e6efe7; --muted: #9aab9e; --line: #2c3a30;
  --brand: #4ade80; --brand-ink: #062b14; --hl: #facc15; --hl-ink: #1f1800;
  --ok: #4ade80; --ok-bg: #12301d; --bad: #f87171; --bad-bg: #3a1515; --warn: #facc15; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink); font: 16px/1.5 var(--font-ui);
  -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent;
  padding-bottom: calc(72px + env(safe-area-inset-bottom, 0px));
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--hl); outline-offset: 2px; }
[hidden] { display: none !important; }

.top { position: sticky; top: 0; z-index: 5; background: var(--brand); color: var(--brand-ink);
  padding-top: env(safe-area-inset-top, 0px); }
.top-in { max-width: 640px; margin: 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding-block: 10px; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: .01em; }
.brand-mark { background: var(--hl); color: var(--hl-ink); border-radius: 8px; padding: 2px 7px; font-size: 14px; }
.top-stat { font-size: 13px; opacity: .9; font-variant-numeric: tabular-nums; text-align: right; }

.wrap { max-width: 640px; margin: 0 auto; padding-block: 18px 24px;
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
  display: flex; flex-direction: column; gap: 16px; }

.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 5; display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom, 0px); padding-left: env(safe-area-inset-left, 0px); padding-right: env(safe-area-inset-right, 0px); }
.tab { background: none; border: 0; padding: 8px 4px 10px; display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 12px; color: var(--muted); }
.tab .ti { font-size: 18px; line-height: 1; }
.tab.on { color: var(--brand); font-weight: 600; }

h1, h2, h3 { margin: 0; text-wrap: balance; line-height: 1.25; }
h1 { font-size: 24px; } h2 { font-size: 19px; } h3 { font-size: 16px; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.eyebrow { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 600; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row > * { min-width: 0; }
.grow { flex: 1 1 0; }
.stack { display: flex; flex-direction: column; gap: 10px; }

.btn { border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 12px 16px; font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn.hl { background: var(--hl); color: var(--hl-ink); border-color: var(--hl); }
.btn.ghost { background: transparent; }
.btn.block { width: 100%; }
.btn.sm { min-height: 36px; padding: 6px 12px; font-size: 14px; border-radius: 10px; }
.btn:disabled { opacity: .45; cursor: default; }
.btn .sub { font-weight: 400; font-size: 13px; opacity: .85; }
.btn:has(.sub) { flex-direction: column; gap: 0; line-height: 1.3; }

/* Today */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 12px; display: flex; flex-direction: column; gap: 2px; }
.stat b { font-size: 26px; font-variant-numeric: tabular-nums; line-height: 1.1; }
.stat span { font-size: 12px; color: var(--muted); }
.stat.due b { color: var(--warn); }
.bar { height: 12px; background: var(--surface-2); border-radius: 99px; overflow: hidden; display: flex; }
.bar i { display: block; height: 100%; }
.bar .k { background: var(--brand); } .bar .r { background: #65a30d; } .bar .l { background: var(--hl); }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.goal { font-variant-numeric: tabular-nums; }

/* Session */
.sess-head { display: flex; align-items: center; gap: 10px; }
.sess-head .bar { flex: 1; height: 8px; }
.sess-head .bar i { background: var(--brand); }
.x { background: none; border: 0; font-size: 22px; line-height: 1; padding: 6px 8px; color: var(--muted); }
.count { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; min-width: 52px; text-align: right; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 22px 18px; display: flex; flex-direction: column; gap: 14px; }
.q-label { font-size: 13px; color: var(--muted); font-weight: 600; }
.word { font-size: 34px; font-weight: 700; letter-spacing: -.01em; line-height: 1.15; word-break: break-word; }
.ipa { font-family: var(--font-ipa); color: var(--muted); font-size: 17px; }
.pos { display: inline-block; background: var(--surface-2); border-radius: 6px; padding: 1px 8px; font-size: 13px; color: var(--muted); }
.meaning { font-size: 22px; font-weight: 600; }
.ex { border-left: 3px solid var(--hl); padding-left: 12px; display: flex; flex-direction: column; gap: 2px; }
.ex .en { font-size: 17px; }
.ex .vi { color: var(--muted); font-size: 15px; }
.ex mark { background: var(--hl); color: var(--hl-ink); border-radius: 4px; padding: 0 3px; }
.speak { border: 1px solid var(--line); background: var(--surface-2); border-radius: 99px; width: 40px; height: 40px; display: inline-flex; align-items: center; justify-content: center; font-size: 17px; flex: none; }
.speak.big { width: 72px; height: 72px; font-size: 30px; background: var(--hl); color: var(--hl-ink); border-color: var(--hl); }
.speak.sm { width: 32px; height: 32px; font-size: 14px; }
.blank { display: inline-block; min-width: 70px; border-bottom: 2px solid var(--ink); }

.opts { display: grid; gap: 10px; }
.opt { text-align: left; border: 1.5px solid var(--line); background: var(--surface); border-radius: 12px; padding: 13px 14px; min-height: 52px; display: flex; gap: 10px; align-items: center; font-size: 16px; }
.opt .k { flex: none; width: 24px; height: 24px; border-radius: 6px; background: var(--surface-2); font-size: 12px; display: inline-flex; align-items: center; justify-content: center; color: var(--muted); }
.opt.ok { border-color: var(--ok); background: var(--ok-bg); }
.opt.bad { border-color: var(--bad); background: var(--bad-bg); }
.opt:disabled { cursor: default; }

.inp { width: 100%; border: 1.5px solid var(--line); background: var(--surface); border-radius: 12px; padding: 13px 14px; font-size: 18px; }
.inp.ok { border-color: var(--ok); background: var(--ok-bg); }
.inp.bad { border-color: var(--bad); background: var(--bad-bg); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; min-height: 48px; }
.chips.target { border: 1.5px dashed var(--line); border-radius: 12px; padding: 8px; }
.chip { border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 8px 12px; font-size: 16px; }
.chip.used { visibility: hidden; }

.match { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.match .col { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.match .opt { min-height: 56px; font-size: 15px; }
.match .opt.sel { border-color: var(--brand); box-shadow: 0 0 0 2px var(--brand) inset; }
.match .opt.done { opacity: .35; border-color: var(--ok); }

.fb { border-radius: 14px; padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.fb.ok { background: var(--ok-bg); }
.fb.bad { background: var(--bad-bg); }
.fb-t { font-weight: 700; }
.fb.ok .fb-t { color: var(--ok); } .fb.bad .fb-t { color: var(--bad); }

.grades { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }

/* Dictionary */
.list { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; background: var(--surface); }
.li { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-top: 1px solid var(--line); text-align: left; background: none; border-left: 0; border-right: 0; border-bottom: 0; width: 100%; }
.li:first-child { border-top: 0; }
.li .n { width: 40px; flex: none; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.li .w { font-weight: 600; }
.li .m { color: var(--muted); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.li .t { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.pill { font-size: 11px; padding: 2px 8px; border-radius: 99px; flex: none; font-weight: 600; }
.pill.new { background: var(--surface-2); color: var(--muted); }
.pill.l { background: var(--hl); color: var(--hl-ink); }
.pill.r { background: #d9f99d; color: #365314; }
.pill.k { background: var(--brand); color: var(--brand-ink); }
.detail { padding: 14px; background: var(--surface-2); display: flex; flex-direction: column; gap: 10px; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 14px; font-weight: 600; }
.sel { border: 1.5px solid var(--line); background: var(--surface); border-radius: 10px; padding: 10px 12px; width: 100%; }
.checks { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.check { display: flex; gap: 8px; align-items: center; border: 1px solid var(--line); border-radius: 10px; padding: 9px 10px; font-size: 14px; background: var(--surface); }
.seg { display: flex; flex-wrap: wrap; gap: 8px; }
.seg button { border: 1.5px solid var(--line); background: var(--surface); border-radius: 10px; padding: 8px 12px; font-size: 14px; }
.seg button.on { border-color: var(--brand); background: var(--brand); color: var(--brand-ink); }
textarea.inp { font-size: 13px; min-height: 110px; font-family: ui-monospace, Menlo, monospace; }

.result-big { font-size: 48px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1; }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(84px + env(safe-area-inset-bottom, 0px)); background: var(--ink); color: var(--bg);
  padding: 10px 16px; border-radius: 10px; font-size: 14px; z-index: 20; max-width: calc(100% - 32px); }

@media (min-width: 560px) {
  .opts.two { grid-template-columns: 1fr 1fr; }
  .grades { grid-template-columns: repeat(4, 1fr); }
  .checks { grid-template-columns: repeat(3, 1fr); }
}
@media (prefers-reduced-motion: no-preference) {
  .card, .fb { animation: rise .18s ease-out; }
  @keyframes rise { from { transform: translateY(6px); opacity: .6; } to { transform: none; opacity: 1; } }
}
