/* ===== Design tokens ===== */
:root {
  --bg: #f6f5fb;
  --bg-2: #eceaf7;
  --surface: #ffffff;
  --surface-2: #f8f7fd;
  --text: #1d1b2f;
  --muted: #6b6886;
  --line: #e3e0f0;
  --primary: #6c4cf5;
  --primary-2: #8f6bff;
  --primary-soft: #ece7ff;
  --accent: #ff8a3d;
  --good: #22b26b;
  --good-soft: #dcf7e8;
  --bad: #ef4766;
  --bad-soft: #ffe1e7;
  --warn: #f5b400;
  --warn-soft: #fff4cc;
  --blue: #2f8cff;
  --blue-soft: #e0eeff;
  --shadow: 0 2px 0 rgba(40, 30, 90, .06), 0 8px 24px rgba(40, 30, 90, .08);
  --shadow-lg: 0 20px 60px rgba(30, 20, 80, .25);
  --radius: 18px;
  --radius-sm: 12px;
  --font: "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12111c; --bg-2: #1a1828; --surface: #1e1c2e; --surface-2: #252338;
    --text: #f1effa; --muted: #a29fbe; --line: #322f4a;
    --primary: #8f73ff; --primary-2: #a98fff; --primary-soft: #2c2650;
    --good-soft: #143a28; --bad-soft: #43182a; --warn-soft: #3d3310; --blue-soft: #15294a;
    --shadow: 0 2px 0 rgba(0,0,0,.25), 0 8px 24px rgba(0,0,0,.3);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #12111c; --bg-2: #1a1828; --surface: #1e1c2e; --surface-2: #252338;
  --text: #f1effa; --muted: #a29fbe; --line: #322f4a;
  --primary: #8f73ff; --primary-2: #a98fff; --primary-soft: #2c2650;
  --good-soft: #143a28; --bad-soft: #43182a; --warn-soft: #3d3310; --blue-soft: #15294a;
  --shadow: 0 2px 0 rgba(0,0,0,.25), 0 8px 24px rgba(0,0,0,.3);
  color-scheme: dark;
}

/* ===== Base ===== */
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font-family: var(--font); font-size: 16px; line-height: 1.5; -webkit-font-smoothing: antialiased; }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; cursor: pointer; }
input, textarea, select { font: inherit; color: var(--text); }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5em; }
h1 { font-size: 1.9rem; font-weight: 900; }
h2 { font-size: 1.4rem; font-weight: 800; }
h3 { font-size: 1.1rem; font-weight: 800; }
p { margin: 0 0 .8em; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.center { text-align: center; }
[hidden] { display: none !important; }

/* ===== Layout ===== */
#app { display: flex; min-height: 100vh; }
.sidebar { width: 240px; flex-shrink: 0; background: var(--surface); border-right: 1px solid var(--line); padding: 20px 14px; display: flex; flex-direction: column; gap: 8px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 900; font-size: 1.25rem; padding: 6px 10px 18px; }
.logo { font-size: 2rem; display: inline-block; animation: bob 3s ease-in-out infinite; }
.brand-name { background: linear-gradient(90deg, var(--primary), var(--accent)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.nav { display: flex; flex-direction: column; gap: 4px; }
.nav a, .nav-settings { display: flex; align-items: center; gap: 12px; padding: 11px 14px; border-radius: 14px; font-weight: 800; color: var(--muted); border: 2px solid transparent; background: none; text-align: left; transition: background .15s, color .15s; }
.nav a:hover, .nav-settings:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { background: var(--primary-soft); color: var(--primary); border-color: color-mix(in srgb, var(--primary) 35%, transparent); }
.ni { font-size: 1.35rem; width: 28px; text-align: center; }
.nav-settings { margin-top: auto; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 10; background: var(--bg); }
.topbar { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 28px; background: color-mix(in srgb, var(--bg) 85%, transparent); backdrop-filter: blur(10px); }
.topbar-title { font-weight: 900; font-size: 1.1rem; }
.stats { display: flex; gap: 8px; flex-wrap: wrap; }
.stat { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); font-weight: 800; font-size: .95rem; }
button.stat:hover { border-color: var(--primary); }
.stat.lvl { background: var(--primary); color: #fff; border-color: transparent; }
.view { padding: 8px 28px 60px; max-width: 1100px; width: 100%; margin: 0 auto; animation: fadeUp .35s ease; }

@media (max-width: 820px) {
  .sidebar { position: fixed; bottom: 0; top: auto; left: 0; right: 0; width: 100%; height: auto; flex-direction: row; padding: 6px 6px calc(6px + env(safe-area-inset-bottom)); z-index: 20; border-right: 0; border-top: 1px solid var(--line); }
  .brand, .nav-settings { display: none; }
  .nav { flex-direction: row; flex: 1; justify-content: space-around; gap: 0; }
  .nav a { flex-direction: column; gap: 0; padding: 6px 4px; font-size: .68rem; flex: 1; align-items: center; }
  .ni { font-size: 1.4rem; }
  .topbar { padding: 10px 16px; }
  .topbar-title { display: none; }
  .stats { width: 100%; justify-content: space-between; }
  .view { padding: 4px 16px 100px; }
  h1 { font-size: 1.5rem; }
}

/* ===== Components ===== */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.card.click { cursor: pointer; transition: transform .15s, box-shadow .15s, border-color .15s; }
.card.click:hover { transform: translateY(-3px); border-color: var(--primary); }
.card.locked { opacity: .55; filter: grayscale(.7); cursor: not-allowed; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.g3 { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.g4 { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.section { margin: 28px 0 14px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 12px 22px; border-radius: 14px; border: 2px solid var(--line); background: var(--surface); font-weight: 800; letter-spacing: .02em; box-shadow: 0 4px 0 var(--line); transition: transform .08s, box-shadow .08s, filter .15s; user-select: none; }
.btn:hover { filter: brightness(1.04); }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--line); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; box-shadow: 0 4px 0 color-mix(in srgb, var(--primary) 60%, #000); }
.btn.good { background: var(--good); border-color: var(--good); color: #fff; box-shadow: 0 4px 0 color-mix(in srgb, var(--good) 60%, #000); }
.btn.bad { background: var(--bad); border-color: var(--bad); color: #fff; box-shadow: 0 4px 0 color-mix(in srgb, var(--bad) 60%, #000); }
.btn.ghost { background: transparent; box-shadow: none; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.btn.big { padding: 15px 30px; font-size: 1.08rem; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; filter: grayscale(.5); }
.btn.sm { padding: 7px 12px; font-size: .88rem; border-radius: 10px; box-shadow: 0 3px 0 var(--line); }
.icon-btn { width: 44px; height: 44px; border-radius: 50%; border: 2px solid var(--line); background: var(--surface); display: inline-grid; place-items: center; font-size: 1.2rem; box-shadow: 0 3px 0 var(--line); flex-shrink: 0; }
.icon-btn:active { transform: translateY(2px); box-shadow: none; }
.icon-btn.speak { background: var(--blue); border-color: var(--blue); color: #fff; box-shadow: 0 3px 0 color-mix(in srgb, var(--blue) 60%, #000); }

.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 11px; border-radius: 999px; font-size: .8rem; font-weight: 800; background: var(--surface-2); border: 1px solid var(--line); color: var(--muted); }
.chip.p { background: var(--primary-soft); color: var(--primary); border-color: transparent; }
.chip.g { background: var(--good-soft); color: var(--good); border-color: transparent; }
.chip.w { background: var(--warn-soft); color: #b07d00; border-color: transparent; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 16px; }
.tab { padding: 8px 14px; border-radius: 999px; border: 2px solid var(--line); background: var(--surface); font-weight: 800; color: var(--muted); }
.tab.active { border-color: var(--primary); color: var(--primary); background: var(--primary-soft); }
.input { width: 100%; padding: 14px 16px; border-radius: 14px; border: 2px solid var(--line); background: var(--surface-2); font-size: 1.1rem; outline: none; transition: border-color .15s; }
.input:focus { border-color: var(--primary); background: var(--surface); }
textarea.input { min-height: 150px; resize: vertical; line-height: 1.6; }
.progress { height: 14px; border-radius: 999px; background: var(--bg-2); overflow: hidden; }
.progress > i { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--good), #5ee39e); transition: width .4s ease; position: relative; }
.progress > i::after { content: ""; position: absolute; left: 8px; right: 8px; top: 3px; height: 3px; border-radius: 3px; background: rgba(255,255,255,.4); }
.big-emoji { font-size: 4.5rem; line-height: 1; }
.emoji-xl { font-size: 7rem; line-height: 1; filter: drop-shadow(0 8px 12px rgba(0,0,0,.12)); }
.kbd { font-family: ui-monospace, monospace; background: var(--surface-2); border: 1px solid var(--line); border-radius: 6px; padding: 1px 6px; }

/* ===== Toast & modal ===== */
.toast { position: fixed; left: 50%; bottom: 30px; transform: translateX(-50%) translateY(120px); background: var(--text); color: var(--bg); padding: 12px 20px; border-radius: 14px; font-weight: 800; z-index: 100; transition: transform .3s cubic-bezier(.2,1.4,.4,1); pointer-events: none; max-width: 90vw; }
.toast.show { transform: translateX(-50%) translateY(0); }
.modal { position: fixed; inset: 0; z-index: 60; background: rgba(15, 10, 40, .55); display: grid; place-items: center; padding: 16px; animation: fade .2s; }
.modal-box { background: var(--surface); border-radius: 24px; padding: 26px; width: min(520px, 100%); max-height: 90vh; overflow: auto; box-shadow: var(--shadow-lg); animation: pop .3s cubic-bezier(.2,1.4,.4,1); position: relative; }
.modal-close { position: absolute; top: 14px; right: 14px; }

/* ===== Animations ===== */
@keyframes fade { from { opacity: 0; } }
@keyframes fadeUp { from { opacity: 0; transform: translateY(10px); } }
@keyframes pop { from { opacity: 0; transform: scale(.85); } }
@keyframes bob { 0%,100% { transform: translateY(0) rotate(-3deg); } 50% { transform: translateY(-4px) rotate(3deg); } }
@keyframes shake { 0%,100% { transform: translateX(0); } 20%,60% { transform: translateX(-8px); } 40%,80% { transform: translateX(8px); } }
@keyframes bounceIn { 0% { transform: scale(.3); opacity: 0; } 60% { transform: scale(1.1); opacity: 1; } 100% { transform: scale(1); } }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--primary) 50%, transparent); } 50% { box-shadow: 0 0 0 14px transparent; } }
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); } }
.shake { animation: shake .4s; }
.bounce-in { animation: bounceIn .5s cubic-bezier(.2,1.4,.4,1); }
.confetti { position: fixed; top: -20px; width: 10px; height: 16px; z-index: 90; border-radius: 3px; animation: fall linear forwards; pointer-events: none; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; } }
