/* ===== Lách kách — style ===== */
:root {
  color-scheme: light;
  --bg: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --line: #e1e0d9;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --good: #0ca30c;
  --bad: #d03b3b;
  --key-bg: #ffffff;
  --key-shadow: rgba(11, 11, 11, 0.12);
  --series: #2a78d6;
  --grid: #e1e0d9;
  --finger-0: rgba(232, 123, 164, 0.28);
  --finger-1: rgba(237, 161, 0, 0.26);
  --finger-2: rgba(27, 175, 122, 0.26);
  --finger-3: rgba(42, 120, 214, 0.22);
  --finger-4: rgba(42, 120, 214, 0.22);
  --finger-5: rgba(27, 175, 122, 0.26);
  --finger-6: rgba(237, 161, 0, 0.26);
  --finger-7: rgba(232, 123, 164, 0.28);
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #242423;
  --ink: #ffffff;
  --ink-2: #c3c2b7;
  --muted: #898781;
  --line: #2c2c2a;
  --accent: #3987e5;
  --accent-ink: #ffffff;
  --good: #0ca30c;
  --bad: #e66767;
  --key-bg: #242423;
  --key-shadow: rgba(0, 0, 0, 0.5);
  --series: #3987e5;
  --grid: #2c2c2a;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { height: 100%; }
body {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  line-height: 1.5;
}
main { flex: 1; width: min(920px, 100% - 2rem); margin: 0 auto; padding: 1rem 0 2rem; }
.hidden { display: none !important; }

/* ===== Header ===== */
.topbar {
  display: flex; align-items: center; gap: 1rem;
  width: min(920px, 100% - 2rem); margin: 0 auto; padding: 0.8rem 0;
}
.brand {
  display: flex; align-items: center; gap: 0.5rem;
  background: none; border: none; cursor: pointer; color: var(--ink);
  font-size: 1.25rem; font-weight: 700; font-family: inherit;
}
.brand-icon { font-size: 1.5rem; }
.topnav { display: flex; gap: 0.25rem; margin-left: auto; }
.nav-btn, .icon-btn, .seg-btn, .ghost-btn, .primary-btn, .danger-btn {
  font-family: inherit; font-size: 0.95rem; cursor: pointer;
  border: 1px solid transparent; border-radius: 10px;
  background: none; color: var(--ink-2); padding: 0.45rem 0.9rem;
  transition: background 0.15s, color 0.15s;
}
.nav-btn:hover, .icon-btn:hover { background: var(--surface-2); }
.nav-btn.active { background: var(--surface-2); color: var(--ink); font-weight: 600; }
.icon-btn { font-size: 1.1rem; padding: 0.4rem 0.6rem; }
.topactions { display: flex; gap: 0.25rem; }

/* ===== Menu ===== */
.hero { text-align: center; padding: 1.5rem 0 1rem; }
.hero h1 {
  font-size: clamp(2.2rem, 6vw, 3.4rem); font-weight: 800; letter-spacing: -0.02em;
  background: linear-gradient(120deg, var(--accent), #1baf7a);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.tagline { color: var(--ink-2); margin-top: 0.3rem; }

.lang-row { display: flex; align-items: center; justify-content: center; gap: 0.75rem; margin: 1rem 0 0.5rem; }
.lang-label { color: var(--ink-2); font-size: 0.95rem; }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 12px; padding: 3px; }
.seg-btn { border-radius: 9px; padding: 0.35rem 1rem; }
.seg-btn.active { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: 0 1px 3px var(--key-shadow); }

.ime-note {
  text-align: center; font-size: 0.9rem; color: var(--ink-2);
  background: var(--surface-2); border-radius: 10px;
  padding: 0.6rem 1rem; margin: 0.5rem auto 1.2rem; max-width: 620px;
}

.mode-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 1rem; }
.mode-card {
  display: flex; flex-direction: column; align-items: flex-start; gap: 0.35rem;
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px;
  padding: 1.2rem; cursor: pointer; text-align: left; font-family: inherit; color: var(--ink);
  transition: transform 0.12s, box-shadow 0.12s, border-color 0.12s;
}
.mode-card:hover { transform: translateY(-2px); box-shadow: 0 6px 18px var(--key-shadow); border-color: var(--accent); }
.mode-icon { font-size: 1.8rem; }
.mode-title { font-size: 1.1rem; font-weight: 700; }
.mode-desc { color: var(--ink-2); font-size: 0.9rem; }
.mode-extra { color: var(--accent); font-size: 0.85rem; font-weight: 600; margin-top: 0.25rem; }

/* ===== Chọn chủ đề kiến thức ===== */
.topics-title { margin: 1rem 0 0.25rem; }
.topics-note { color: var(--ink-2); font-size: 0.9rem; margin-bottom: 1rem; }
#screen-topics .result-actions { justify-content: flex-start; margin-top: 1.2rem; }

/* ===== Luyện tập ===== */
.live-stats { display: flex; align-items: center; gap: 1.5rem; padding: 0.5rem 0 1rem; }
.stat { display: flex; flex-direction: column; align-items: center; min-width: 70px; }
.stat-value { font-size: 1.5rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-label { font-size: 0.75rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
#btn-quit { margin-left: auto; }
.ghost-btn { border-color: var(--line); }
.ghost-btn:hover { background: var(--surface-2); color: var(--ink); }

.typing-box {
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px;
  padding: 1.4rem 1.6rem; outline: none; cursor: text;
}
.typing-box:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent); }
.typing-text {
  font-size: 1.6rem; line-height: 2.2; letter-spacing: 0.02em;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  word-break: break-word; user-select: none;
}
.typing-text .done { color: var(--muted); }
.typing-text .cur {
  background: var(--accent); color: var(--accent-ink); border-radius: 4px;
  animation: pulse 1s ease-in-out infinite;
}
.typing-text .cur.err { background: var(--bad); animation: shake 0.15s; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.75; } }
@keyframes shake { 25% { transform: translateX(-2px); } 75% { transform: translateX(2px); } }
.hint-row { text-align: center; color: var(--ink-2); font-size: 0.95rem; min-height: 1.6em; margin-top: 0.6rem; }

/* ===== Bàn phím ảo ===== */
.keyboard { display: flex; flex-direction: column; gap: 6px; margin-top: 0.8rem; user-select: none; }
.kb-row { display: flex; gap: 6px; justify-content: center; }
.key {
  position: relative;
  display: flex; align-items: center; justify-content: center;
  height: 46px; min-width: 46px; flex: 0 0 46px;
  background: var(--key-bg); border: 1px solid var(--line); border-radius: 8px;
  box-shadow: 0 2px 0 var(--key-shadow);
  font-family: ui-monospace, Menlo, monospace; font-size: 0.95rem; color: var(--ink);
  transition: background 0.08s, transform 0.05s;
}
.key.wide { flex: 0 0 72px; }
.key.space { flex: 1 1 auto; max-width: 300px; }
.key.f0 { background: color-mix(in srgb, var(--key-bg) 100%, transparent); }
.key.next {
  background: var(--accent); color: var(--accent-ink); border-color: var(--accent);
  transform: translateY(1px); box-shadow: 0 1px 0 var(--key-shadow);
}
.key.flash-err { background: var(--bad); color: #fff; border-color: var(--bad); }
.key.locked { opacity: 0.3; }
.key .bump { position: absolute; bottom: 6px; width: 10px; height: 2px; border-radius: 2px; background: currentColor; opacity: 0.5; }
.keyboard.small .key { height: 34px; min-width: 34px; flex: 0 0 34px; font-size: 0.8rem; }
.keyboard.small .key.wide { flex: 0 0 54px; }

/* Màu ngón tay */
.key[data-finger="0"] { background: linear-gradient(var(--finger-0), var(--finger-0)), var(--key-bg); }
.key[data-finger="1"] { background: linear-gradient(var(--finger-1), var(--finger-1)), var(--key-bg); }
.key[data-finger="2"] { background: linear-gradient(var(--finger-2), var(--finger-2)), var(--key-bg); }
.key[data-finger="3"] { background: linear-gradient(var(--finger-3), var(--finger-3)), var(--key-bg); }
.key[data-finger="4"] { background: linear-gradient(var(--finger-4), var(--finger-4)), var(--key-bg); }
.key[data-finger="5"] { background: linear-gradient(var(--finger-5), var(--finger-5)), var(--key-bg); }
.key[data-finger="6"] { background: linear-gradient(var(--finger-6), var(--finger-6)), var(--key-bg); }
.key[data-finger="7"] { background: linear-gradient(var(--finger-7), var(--finger-7)), var(--key-bg); }
.key.next[data-finger] { background: var(--accent); }
.key.flash-err[data-finger] { background: var(--bad); }
/* Heatmap ghi đè màu ngón */
.keyboard.small .key[data-heat] { color: var(--ink); }

/* ===== Bàn tay gợi ý ===== */
.hands { display: flex; justify-content: center; gap: 3rem; margin-top: 1rem; user-select: none; }
.hand { height: 106px; width: auto; }
.hf {
  stroke: var(--line); stroke-width: 1.5;
  transform-box: fill-box;
  transition: fill 0.12s, transform 0.12s;
}
.hf[data-f="0"] { fill: var(--finger-0); }
.hf[data-f="1"] { fill: var(--finger-1); }
.hf[data-f="2"] { fill: var(--finger-2); }
.hf[data-f="3"] { fill: var(--finger-3); }
.hf[data-f="4"] { fill: var(--finger-4); }
.hf[data-f="5"] { fill: var(--finger-5); }
.hf[data-f="6"] { fill: var(--finger-6); }
.hf[data-f="7"] { fill: var(--finger-7); }
.hf.thumb { fill: var(--surface-2); }
.hp { fill: var(--surface-2); stroke: var(--line); stroke-width: 1.5; }
.hf.on { fill: var(--accent); transform: translateY(5px); }

/* ===== Kết quả ===== */
#screen-result { text-align: center; padding-top: 2rem; }
#screen-result h2 { font-size: 2rem; margin-bottom: 0.5rem; }
.levelup { color: var(--good); font-weight: 700; font-size: 1.1rem; margin-bottom: 0.5rem; }
.result-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 1rem; margin: 1.5rem 0; }
.tile {
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  padding: 1.1rem; display: flex; flex-direction: column; align-items: center;
}
.tile-value { font-size: 2rem; font-weight: 800; }
.tile-label { color: var(--muted); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em; }
.result-actions, .stats-actions { display: flex; gap: 0.75rem; justify-content: center; margin-top: 1rem; }
.primary-btn { background: var(--accent); color: var(--accent-ink); font-weight: 600; padding: 0.6rem 1.4rem; }
.primary-btn:hover { filter: brightness(1.1); }
.danger-btn { border-color: var(--bad); color: var(--bad); }
.danger-btn:hover { background: var(--bad); color: #fff; }

/* ===== Thống kê ===== */
#screen-stats h2 { margin: 1rem 0; }
.chart-block { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 1.2rem; margin-bottom: 1.2rem; }
.chart-block h3 { font-size: 1rem; font-weight: 600; margin-bottom: 0.8rem; color: var(--ink-2); }
.chart { width: 100%; overflow-x: auto; }
.chart svg { display: block; width: 100%; height: auto; }
.chart-note { font-size: 0.85rem; color: var(--muted); margin-bottom: 0.8rem; }
.heat-legend { display: inline-flex; gap: 2px; vertical-align: middle; margin-left: 0.5rem; }
.heat-legend i { width: 16px; height: 10px; border-radius: 2px; display: inline-block; }
.empty-note { color: var(--muted); text-align: center; padding: 1rem; }

/* Tooltip biểu đồ */
.viz-tip {
  position: fixed; pointer-events: none; z-index: 30;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--line); border-radius: 8px;
  padding: 0.35rem 0.6rem; font-size: 0.85rem;
  box-shadow: 0 4px 14px var(--key-shadow);
  font-variant-numeric: tabular-nums;
}

/* ===== Khác ===== */
.foot { text-align: center; color: var(--muted); font-size: 0.85rem; padding: 1rem; }
.toast {
  position: fixed; bottom: 1.5rem; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: var(--bg);
  border-radius: 12px; padding: 0.7rem 1.2rem; font-size: 0.95rem;
  box-shadow: 0 6px 20px var(--key-shadow); z-index: 50;
  animation: rise 0.25s ease-out;
}
@keyframes rise { from { opacity: 0; transform: translate(-50%, 8px); } }

@media (max-width: 720px) {
  .key { height: 34px; min-width: 26px; flex: 1 1 26px; font-size: 0.8rem; }
  .key.wide { flex: 1.6 1 40px; }
  .typing-text { font-size: 1.25rem; }
  .brand-name { display: none; }
  .hand { height: 76px; }
  .hands { gap: 1.5rem; }
}
