:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-2: #f0eee8;
  --border: #dedbd2;
  --text: #1d1c1a;
  --muted: #6b6860;
  --accent: #2f5bd3;
  --accent-soft: #e6ecfb;
  --accent-text: #ffffff;
  --ok: #1f7a4d;
  --ok-soft: #e2f3ea;
  --warn: #9a6200;
  --warn-soft: #fbf0d9;
  --bad: #b3261e;
  --bad-soft: #fbe5e3;
  --hl: #ffe08a;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.04);
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #161614; --surface: #1f1f1c; --surface-2: #282824; --border: #3a3934;
    --text: #ecebe6; --muted: #a09d94; --accent: #7a9cff; --accent-soft: #232e4d; --accent-text: #0e1220;
    --ok: #5fcf95; --ok-soft: #1b3428; --warn: #f0b955; --warn-soft: #3a2f17;
    --bad: #ff8a80; --bad-soft: #3d1f1d; --hl: #6b5512;
    --shadow: 0 1px 2px rgba(0,0,0,.3); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #161614; --surface: #1f1f1c; --surface-2: #282824; --border: #3a3934;
  --text: #ecebe6; --muted: #a09d94; --accent: #7a9cff; --accent-soft: #232e4d; --accent-text: #0e1220;
  --ok: #5fcf95; --ok-soft: #1b3428; --warn: #f0b955; --warn-soft: #3a2f17;
  --bad: #ff8a80; --bad-soft: #3d1f1d; --hl: #6b5512;
  --shadow: 0 1px 2px rgba(0,0,0,.3); color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.55 "Be Vietnam Pro", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, textarea, select { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px 20px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; letter-spacing: -.01em; }
.brand span { color: var(--muted); font-weight: 500; }
.topbar .spacer { flex: 1; }
.who { color: var(--muted); font-size: 14px; }

.progress { display: flex; align-items: center; gap: 10px; min-width: 220px; }
.bar { flex: 1; height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--ok); border-radius: 99px; transition: width .3s; }
.progress b { font-variant-numeric: tabular-nums; font-size: 14px; white-space: nowrap; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); cursor: pointer; font-weight: 500; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { color: var(--bad); }
kbd {
  font: 11px/1 ui-monospace, monospace; padding: 2px 5px; border-radius: 4px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--muted);
}
.btn.primary kbd { background: transparent; color: inherit; border-color: currentColor; opacity: .7; }

/* ---------- Layout ---------- */
.wrap { max-width: 880px; margin: 0 auto; padding: 20px 16px 80px; }
.blocks { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.block-chip {
  padding: 6px 12px; border-radius: 99px; border: 1px solid var(--border); background: var(--surface);
  font-size: 13px; cursor: pointer;
}
.block-chip.active { border-color: var(--accent); background: var(--accent-soft); }
.block-chip b { font-variant-numeric: tabular-nums; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px 22px; margin-bottom: 16px;
}
.card h3 { margin: 0 0 12px; font-size: 15px; }
.meta { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; font-size: 14px; }
.sid { font: 600 14px ui-monospace, "SF Mono", monospace; }
.badge {
  display: inline-block; padding: 2px 10px; border-radius: 99px; font-size: 12.5px; font-weight: 600;
  background: var(--surface-2); color: var(--text);
}
.badge.v-text { background: #e7efe2; color: #2c5a1e; }
.badge.v-emoji { background: #f6e6f3; color: #7a2a6b; }
.badge.v-full { background: #e5ecfa; color: #24448f; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .badge.v-text { background: #24341e; color: #b6dca4; }
  :root:not([data-theme="light"]) .badge.v-emoji { background: #3a2236; color: #eab2de; }
  :root:not([data-theme="light"]) .badge.v-full { background: #22304f; color: #b1c5f5; }
}
:root[data-theme="dark"] .badge.v-text { background: #24341e; color: #b6dca4; }
:root[data-theme="dark"] .badge.v-emoji { background: #3a2236; color: #eab2de; }
:root[data-theme="dark"] .badge.v-full { background: #22304f; color: #b1c5f5; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }

.content {
  font-size: 20px; line-height: 1.6; padding: 18px 20px; border-radius: 8px;
  background: var(--surface-2); white-space: pre-wrap; word-break: break-word; margin-bottom: 18px;
}
.content.emoji-only { font-size: 34px; letter-spacing: .08em; text-align: center; }
mark { background: var(--hl); color: inherit; border-radius: 4px; padding: 0 2px; outline: 2px solid var(--hl); }

.field { margin-bottom: 16px; }
.field > label, .field > .label { display: block; font-weight: 600; margin-bottom: 8px; font-size: 14px; }
.hint { font-size: 13px; color: var(--muted); margin-top: 6px; }
.hint.warn { color: var(--warn); }

.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.seg.four { grid-template-columns: repeat(4, 1fr); }
.seg.three { grid-template-columns: repeat(3, 1fr); }
.opt {
  text-align: left; padding: 10px 12px; border: 1.5px solid var(--border); border-radius: 8px;
  background: var(--surface); cursor: pointer; line-height: 1.3;
}
.opt b { display: block; font-size: 15px; }
.opt span { font-size: 12.5px; color: var(--muted); }
.opt:hover:not(:disabled) { border-color: var(--accent); }
.opt.on { border-color: var(--accent); background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent); }
.opt:disabled { cursor: default; }
.opt.act-KEEP.on { border-color: var(--ok); background: var(--ok-soft); box-shadow: inset 0 0 0 1px var(--ok); }
.opt.act-DROP.on { border-color: var(--bad); background: var(--bad-soft); box-shadow: inset 0 0 0 1px var(--bad); }
.opt.act-UNCERTAIN.on { border-color: var(--warn); background: var(--warn-soft); box-shadow: inset 0 0 0 1px var(--warn); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 6px 12px; border-radius: 99px; border: 1.5px solid var(--border); background: var(--surface);
  cursor: pointer; font-size: 14px;
}
.chip small { color: var(--muted); }
.chip:hover:not(:disabled) { border-color: var(--accent); }
.chip.on { border-color: var(--accent); background: var(--accent); color: var(--accent-text); }
.chip.on small { color: inherit; opacity: .8; }
.chip:disabled { cursor: default; }

textarea {
  width: 100%; min-height: 80px; resize: vertical; padding: 10px 12px; border-radius: 8px;
  border: 1.5px solid var(--border); background: var(--surface); line-height: 1.5;
}
textarea:focus, input:focus { outline: none; border-color: var(--accent); }
textarea:disabled { background: var(--surface-2); }
input[type=text], input[type=password], select {
  padding: 9px 12px; border-radius: 8px; border: 1.5px solid var(--border); background: var(--surface);
}

.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 8px; }
.actions .spacer { flex: 1; }
.errors {
  background: var(--bad-soft); color: var(--bad); border-radius: 8px; padding: 10px 14px;
  font-size: 14px; margin: 8px 0;
}
.errors ul { margin: 0; padding-left: 18px; }
.saved { font-size: 13px; color: var(--muted); }

.locked-note {
  display: flex; gap: 8px; align-items: center; font-size: 13.5px;
  background: var(--ok-soft); color: var(--ok); padding: 8px 12px; border-radius: 8px; margin-bottom: 14px;
}
.pending-etc {
  border: 1.5px dashed var(--border); border-radius: var(--radius); padding: 16px 20px;
  color: var(--muted); font-size: 14px; margin-bottom: 16px;
}

/* ETC target cards */
.target { border: 1px solid var(--border); border-radius: 8px; padding: 14px 16px; margin-bottom: 14px; }
.target-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.target-head .emo { font-size: 26px; }
.sent { font-size: 16px; padding: 8px 12px; background: var(--surface-2); border-radius: 6px; white-space: pre-wrap; word-break: break-word; }
.sent-label { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 8px 0 4px; font-weight: 600; }

/* ---------- Drawer ---------- */
.drawer-back { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 40; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(720px, 100vw); z-index: 41;
  background: var(--surface); border-left: 1px solid var(--border); display: flex; flex-direction: column;
}
.drawer-head { display: flex; align-items: center; gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.drawer-head h2 { margin: 0; font-size: 16px; flex: 1; }
.drawer-body { overflow: auto; padding: 16px 20px 40px; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; padding: 8px 16px 0; border-bottom: 1px solid var(--border); }
.tab { padding: 8px 12px; border: none; background: none; cursor: pointer; border-bottom: 2px solid transparent; color: var(--muted); font-weight: 500; }
.tab.on { color: var(--text); border-bottom-color: var(--accent); }

.guide h3 { font-size: 16px; margin: 4px 0 10px; }
.guide p { margin: 8px 0; }
.guide table { width: 100%; border-collapse: collapse; margin: 10px 0 16px; font-size: 13.5px; }
.guide th, .guide td { border: 1px solid var(--border); padding: 8px 10px; vertical-align: top; text-align: left; }
.guide th { background: var(--surface-2); }
.guide td:first-child { font-weight: 600; white-space: nowrap; }
.guide dl { margin: 0; }
.guide dt { font-weight: 700; margin-top: 12px; }
.guide dd { margin: 4px 0 0; }

.grid-list h4 { margin: 16px 0 8px; font-size: 14px; }
.cells { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 6px; }
.cell {
  font: 12px ui-monospace, monospace; padding: 6px 0; text-align: center; border-radius: 6px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface);
}
.cell.draft { background: var(--warn-soft); border-color: var(--warn); }
.cell.done { background: var(--ok-soft); border-color: var(--ok); color: var(--ok); }
.cell.cur { outline: 2px solid var(--accent); outline-offset: 1px; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13px; color: var(--muted); }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -2px; margin-right: 4px; border: 1px solid var(--border); }

/* ---------- Login ---------- */
.login { max-width: 420px; margin: 12vh auto; padding: 0 16px; }
.login .card { padding: 28px; }
.login h1 { font-size: 22px; margin: 0 0 4px; }
.login input { width: 100%; margin: 14px 0 12px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 60;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 8px; font-size: 14px;
  box-shadow: var(--shadow);
}

/* ---------- Admin ---------- */
.wrap.wide { max-width: 1180px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat h4 { margin: 0 0 4px; font-size: 15px; }
.stat .num { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .row { display: flex; justify-content: space-between; font-size: 13.5px; margin-top: 6px; gap: 8px; }
.stat .row .bar { max-width: 120px; margin-left: auto; align-self: center; }
table.data { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.data th, table.data td { border-bottom: 1px solid var(--border); padding: 8px; text-align: left; vertical-align: top; }
table.data th { font-weight: 600; color: var(--muted); font-size: 12.5px; text-transform: uppercase; letter-spacing: .03em; }
.tbl-scroll { overflow-x: auto; }

@media (max-width: 640px) {
  .topbar { padding: 10px 16px; }
  .progress { min-width: 0; width: 100%; order: 5; }
  .card { padding: 16px; }
  .seg, .seg.four, .seg.three { grid-template-columns: 1fr; }
  .content { font-size: 18px; }
}

/* ---------- 4 phần mở dần trong một câu ---------- */
.steps { display: inline-flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.step { font-size: 12.5px; padding: 2px 8px; border-radius: 99px; border: 1px solid var(--border); color: var(--muted); }
.step.done { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.step.active { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); font-weight: 600; }
.stage-head { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.stage-num {
  width: 24px; height: 24px; border-radius: 50%; display: inline-grid; place-items: center;
  font-size: 13px; font-weight: 700; background: var(--surface-2); color: var(--muted);
}
.stage-num.active { background: var(--accent); color: var(--accent-text); }
.stage-num.done { background: var(--ok-soft); color: var(--ok); }
.card.stage.active { border-color: var(--accent); }
.card.stage.done { padding: 14px 18px; box-shadow: none; }
.card.stage.done .stage-head { margin-bottom: 8px; }
.content.small-content { font-size: 15.5px; padding: 10px 14px; margin-bottom: 8px; }
.content.small-content.emoji-only { font-size: 22px; text-align: left; }
.badge.v-etc { background: var(--warn-soft); color: var(--warn); }
