/* Kymmensormi – styles */

:root {
  color-scheme: light;
  --bg: #f5f4ef;
  --surface: #ffffff;
  --surface-2: #f0efe9;
  --surface-3: #e7e5dc;
  --ink: #1c1e1b;
  --ink-2: #4c504a;
  --muted: #62655e;
  --border: rgba(28, 30, 20, 0.11);
  --shadow: 0 1px 2px rgba(20, 20, 10, 0.05), 0 4px 18px rgba(20, 20, 10, 0.05);

  --accent: #2f6b4f;
  --accent-ink: #ffffff;
  --accent-soft: #e2eee6;

  --pending: #3f443d;
  --ok: #1d8045;
  --bad: #c8322a;
  --bad-bg: #fbdcd8;
  --caret-bg: #dcebe1;

  /* finger zones (symmetric: same finger type, same colour) */
  --f-pinky: #f6d3cf;
  --f-ring: #fbe3bd;
  --f-middle: #f7efb6;
  --f-index: #cfe8d5;
  --f-index-r: #cfe4f0;
  --f-thumb: #e6e5df;
  --key-locked: #ecebe5;
  --key-ink: #2a2d28;

  /* charts (dataviz reference palette, light) */
  --chart-surface: #ffffff;
  --series-1: #2a78d6;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --chart-muted: #6b6d67;

  --text-size: 30px;
  --radius: 14px;
  font-family: system-ui, -apple-system, "SF Pro Text", "Segoe UI", sans-serif;
}

:root[data-size="large"] { --text-size: 36px; }
:root[data-size="xl"] { --text-size: 44px; }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #151614;
    --surface: #1f201e;
    --surface-2: #272926;
    --surface-3: #31332f;
    --ink: #eeede8;
    --ink-2: #c2c3bb;
    --muted: #a2a49c;
    --border: rgba(255, 255, 255, 0.10);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
    --accent: #6fbf94;
    --accent-ink: #10231a;
    --accent-soft: #23362b;
    --pending: #d6d7d0;
    --ok: #5fcf8a;
    --bad: #ff7a70;
    --bad-bg: #4a2422;
    --caret-bg: #2b4134;
    --f-pinky: #4a3432;
    --f-ring: #4a3f2c;
    --f-middle: #46432a;
    --f-index: #2f4535;
    --f-index-r: #2c4150;
    --f-thumb: #343632;
    --key-locked: #262825;
    --key-ink: #ecebe5;
    --chart-surface: #1f201e;
    --series-1: #3987e5;
    --grid: #2c2c2a;
    --axis: #383835;
    --chart-muted: #898781;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #151614;
  --surface: #1f201e;
  --surface-2: #272926;
  --surface-3: #31332f;
  --ink: #eeede8;
  --ink-2: #c2c3bb;
  --muted: #a2a49c;
  --border: rgba(255, 255, 255, 0.10);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
  --accent: #6fbf94;
  --accent-ink: #10231a;
  --accent-soft: #23362b;
  --pending: #d6d7d0;
  --ok: #5fcf8a;
  --bad: #ff7a70;
  --bad-bg: #4a2422;
  --caret-bg: #2b4134;
  --f-pinky: #4a3432;
  --f-ring: #4a3f2c;
  --f-middle: #46432a;
  --f-index: #2f4535;
  --f-index-r: #2c4150;
  --f-thumb: #343632;
  --key-locked: #262825;
  --key-ink: #ecebe5;
  --chart-surface: #1f201e;
  --series-1: #3987e5;
  --grid: #2c2c2a;
  --axis: #383835;
  --chart-muted: #898781;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
button { font: inherit; color: inherit; cursor: pointer; }
h1 { font-size: 26px; margin: 0 0 6px; font-weight: 650; letter-spacing: -0.01em; }
h2 { font-size: 17px; margin: 0; font-weight: 620; }
.muted { color: var(--muted); }
kbd {
  display: inline-block;
  min-width: 1.6em;
  padding: 0 0.35em;
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 6px;
  background: var(--surface);
  font: inherit;
  font-weight: 600;
  text-align: center;
  line-height: 1.5;
}

/* ---------- top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 24px;
  max-width: 1100px;
  margin: 0 auto;
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--bg);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 680; font-size: 19px; }
.brand-key {
  display: inline-grid; place-items: center;
  width: 32px; height: 32px;
  border-radius: 9px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 19px;
  box-shadow: inset 0 -3px 0 rgba(0,0,0,0.18);
}
.nav { display: flex; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: 12px; }
.nav-btn {
  border: 0; background: transparent;
  padding: 7px 14px; border-radius: 9px;
  font-size: 15px; font-weight: 550; color: var(--ink-2);
}
.nav-btn:hover { color: var(--ink); }
.nav-btn.active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }

main { max-width: 1100px; margin: 0 auto; padding: 4px 24px 32px; }
.view[hidden] { display: none !important; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* ---------- level strip ---------- */
.level-strip {
  display: flex; align-items: center; flex-wrap: wrap;
  gap: 8px 18px;
  margin: 6px 0 14px;
  font-size: 14px; color: var(--ink-2);
}
.level-strip .chips { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.chip {
  display: inline-grid; place-items: center;
  min-width: 26px; height: 26px; padding: 0 6px;
  border-radius: 7px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-weight: 600; font-size: 15px; color: var(--ink);
}
.chip.newest { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.learned-count { margin-right: 6px; white-space: nowrap; }
.learned-count strong { color: var(--ink); font-weight: 650; }
.chip.wide { padding: 0 8px; font-size: 13px; }
.next-letter { display: flex; align-items: center; gap: 10px; }
.next-letter .chip { border-style: dashed; color: var(--ink-2); background: transparent; }
.meter {
  width: 120px; height: 8px; border-radius: 99px;
  background: var(--accent-soft); overflow: hidden;
}
.meter > span { display: block; height: 100%; border-radius: 99px; background: var(--accent); transition: width .5s ease; }

/* ---------- exercise card ---------- */
.exercise-card { padding: 18px 26px 18px; position: relative; }
.exercise-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap;
  margin-bottom: 10px;
}
.exercise-label { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.ex-kind {
  font-size: 13px; font-weight: 650; letter-spacing: 0.04em; text-transform: uppercase;
  color: var(--accent);
}
.ex-title { font-size: 15px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.segmented { display: inline-flex; background: var(--surface-2); padding: 3px; border-radius: 10px; gap: 2px; }
.segmented button {
  border: 0; background: transparent; padding: 5px 11px; border-radius: 8px;
  font-size: 13.5px; color: var(--ink-2); font-weight: 520;
}
.segmented button:hover { color: var(--ink); }
.segmented button.active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); font-weight: 600; }
.segmented.small button { font-size: 14px; padding: 5px 12px; }

.capslock-warning {
  background: #fff3cd; color: #5c4400;
  border-radius: 10px; padding: 8px 12px; margin-bottom: 8px; font-size: 15px;
}
:root[data-theme="dark"] .capslock-warning { background: #4a3d12; color: #ffe9a8; }

.typing-area { position: relative; }
.speed-meter {
  position: absolute; right: 0; bottom: 2px;
  font-size: 15px; color: var(--ink-2);
  background: var(--surface-2); border-radius: 8px; padding: 2px 10px;
  font-variant-numeric: tabular-nums;
}

.text-box {
  font-size: var(--text-size);
  line-height: 1.7;
  letter-spacing: 0.02em;
  color: var(--pending);
  white-space: pre-wrap;
  word-break: normal;
  overflow-wrap: break-word;
  max-height: calc(var(--text-size) * 1.7 * 4 + 6px);
  overflow: hidden;
  scroll-behavior: smooth;
  padding: 2px 0 4px;
  position: relative;
  user-select: none;
  -webkit-user-select: none;
  cursor: default;
}
.text-box span { border-radius: 4px; transition: color .08s ease; }
.text-box .c-ok { color: var(--ok); }
.text-box .c-bad { color: var(--bad); background: var(--bad-bg); }
.text-box .c-cur {
  background: var(--caret-bg);
  box-shadow: inset 0 -3px 0 var(--accent);
}
/* Spaces are thin, so their caret / error mark is drawn a little wider without moving text. */
.text-box span.sp { position: relative; }
.text-box span.sp.c-cur, .text-box span.sp.c-bad { background: transparent; box-shadow: none; animation: none; }
.text-box span.sp.c-cur::before, .text-box span.sp.c-bad::before {
  content: ""; position: absolute; left: -0.1em; right: -0.1em; top: 0.18em; bottom: 0.12em;
  border-radius: 4px;
}
.text-box span.sp.c-cur::before { background: var(--caret-bg); border-bottom: 3px solid var(--accent); }
.text-box span.sp.c-bad::before { background: var(--bad-bg); border-bottom: 3px solid var(--bad); }
.text-box.idle .c-cur { animation: breathe 2.4s ease-in-out infinite; }
@keyframes breathe {
  0%, 100% { box-shadow: inset 0 -3px 0 var(--accent); }
  50% { box-shadow: inset 0 -3px 0 transparent; }
}
.text-box .story-break { display: block; height: 0.4em; }

.hint-line {
  margin-top: 10px; min-height: 30px;
  font-size: 16px; color: var(--ink-2);
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
.hint-line kbd { font-size: 17px; }
.hint-line .finger-dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; border: 1px solid var(--border); }
.hint-line .start-hint { color: var(--muted); }

/* ---------- summary ---------- */
.summary { padding: 6px 0 4px; animation: fadein .25s ease; }
@keyframes fadein { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.summary h2 { font-size: 24px; font-weight: 650; margin-bottom: 4px; }
.summary .sum-row { display: flex; gap: 28px; align-items: flex-end; flex-wrap: wrap; margin: 12px 0 8px; }
.summary .big-stat .value { font-size: 52px; font-weight: 650; line-height: 1; letter-spacing: -0.02em; }
.summary .big-stat .label { font-size: 14px; color: var(--muted); margin-top: 4px; }
.summary .small-stats { color: var(--ink-2); font-size: 16px; padding-bottom: 6px; }
.summary .small-stats div { margin: 2px 0; }
.summary .practice-keys { margin: 8px 0; color: var(--ink-2); display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.summary .unlock-box {
  display: flex; gap: 18px; align-items: center;
  background: var(--accent-soft);
  border-radius: 12px; padding: 14px 18px; margin: 12px 0 6px;
}
.summary .unlock-key {
  display: grid; place-items: center;
  width: 64px; height: 64px; border-radius: 14px;
  background: var(--accent); color: var(--accent-ink);
  font-size: 34px; font-weight: 700;
  box-shadow: inset 0 -4px 0 rgba(0,0,0,0.18);
  flex: none;
}
.summary .unlock-key.wide { width: auto; padding: 0 16px; font-size: 22px; }
.summary .unlock-text strong { font-size: 18px; }
.summary .next-progress { display: flex; align-items: center; gap: 12px; margin: 12px 0 4px; color: var(--ink-2); font-size: 15px; }
.summary .next-progress .meter { width: 200px; }
.summary .next-progress .meter > span { transition: width 1.1s cubic-bezier(.2, .7, .2, 1) .15s; }
.summary .next-progress .gain { color: var(--ok); font-weight: 650; }
.summary .milestone {
  display: flex; gap: 12px; align-items: center;
  background: var(--accent-soft); color: var(--ink);
  border-radius: 12px; padding: 10px 16px; margin: 10px 0 6px;
  font-size: 17px; font-weight: 550;
}
.summary .milestone-icon { color: var(--accent); font-size: 22px; line-height: 1; }
.summary .continue-row { display: flex; align-items: center; gap: 14px; margin-top: 16px; }
.summary .continue-row .muted { font-size: 14px; }

/* ---------- buttons ---------- */
.btn {
  border: 1px solid var(--border);
  background: var(--surface);
  padding: 8px 16px; border-radius: 10px;
  font-size: 15px; font-weight: 550;
  box-shadow: 0 1px 1px rgba(0,0,0,0.04);
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.big { font-size: 18px; padding: 12px 26px; border-radius: 12px; }
.btn.danger { color: var(--bad); }
.btn.danger.armed { background: var(--bad); color: #fff; border-color: transparent; }
.btn:disabled { opacity: .45; cursor: default; }
.ghost-btn {
  border: 0; background: transparent; color: var(--ink-2);
  padding: 6px 10px; border-radius: 8px; font-size: 14px;
}
.ghost-btn:hover { background: var(--surface-2); color: var(--ink); }
.button-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 12px; }

/* ---------- keyboard ---------- */
.keyboard-wrap { margin: 18px auto 0; max-width: 820px; }
.keyboard-wrap[hidden] { display: none; }
.keyboard {
  display: grid;
  grid-template-columns: repeat(58, 1fr);
  grid-auto-rows: 46px;
  user-select: none; -webkit-user-select: none;
}
.key {
  margin: 2.5px;
  border-radius: 8px;
  background: var(--key-locked);
  color: var(--key-ink);
  display: flex; align-items: center; justify-content: center;
  font-size: 17px; font-weight: 520;
  position: relative;
  box-shadow: inset 0 -2px 0 rgba(0,0,0,0.07);
  transition: transform .12s ease, box-shadow .12s ease, background .2s ease;
}
.key.mod { font-size: 14px; color: var(--muted); }
.key.f-lp, .key.f-rp { background: var(--f-pinky); }
.key.f-lr, .key.f-rr { background: var(--f-ring); }
.key.f-lm, .key.f-rm { background: var(--f-middle); }
.key.f-li { background: var(--f-index); }
.key.f-ri { background: var(--f-index-r); }
.key.f-th { background: var(--f-thumb); }
.key.locked { opacity: 0.38; }
.key.unlocked { font-weight: 650; }
.key.home::after {
  content: ""; position: absolute; bottom: 7px; left: 50%;
  width: 12px; height: 2px; margin-left: -6px; border-radius: 2px;
  background: currentColor; opacity: .55;
}
.key.next {
  outline: 3px solid var(--accent);
  outline-offset: 1px;
  transform: translateY(-1px);
  box-shadow: 0 4px 10px rgba(47,107,79,0.28);
  opacity: 1;
  z-index: 1;
}
.key.next-shift { outline: 3px dashed var(--accent); outline-offset: 1px; opacity: 1; }
.key.pressed-bad { animation: badflash .35s ease; }
@keyframes badflash { 0% { box-shadow: 0 0 0 3px var(--bad); } 100% { box-shadow: 0 0 0 0 transparent; } }
.key.enter-top { border-bottom-left-radius: 0; border-bottom-right-radius: 0; margin-bottom: 0; }
.key.enter-bottom { border-top-left-radius: 0; border-top-right-radius: 0; border-top-right-radius: 0; margin-top: 0; }

/* heat keyboard */
.keyboard.heat { grid-auto-rows: 50px; margin-top: 12px; max-width: 760px; }
.keyboard.heat .key { flex-direction: column; gap: 0; line-height: 1.1; }
.keyboard.heat .key small { font-size: 11px; font-weight: 500; opacity: .85; }
.heat-legend { display: flex; align-items: center; gap: 10px; margin-top: 12px; font-size: 13px; color: var(--muted); flex-wrap: wrap; }
.heat-legend .ramp { display: flex; }
.heat-legend .ramp span { width: 26px; height: 12px; }
.heat-legend .ramp span:first-child { border-radius: 4px 0 0 4px; }
.heat-legend .ramp span:last-child { border-radius: 0 4px 4px 0; }

/* ---------- practice footer ---------- */
.practice-footer {
  display: flex; justify-content: space-between; align-items: center; gap: 16px;
  margin-top: 16px; flex-wrap: wrap;
}
.tip { color: var(--muted); font-size: 14px; max-width: 640px; }
.footer-actions { display: flex; gap: 4px; }

/* ---------- progress ---------- */
.progress-intro { margin: 10px 0 16px; }
.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 14px; }
.tile { padding: 14px 16px; }
.tile .label { font-size: 13.5px; color: var(--ink-2); }
.tile .value { font-size: 30px; font-weight: 650; line-height: 1.2; margin-top: 4px; }
.tile .sub { font-size: 13px; color: var(--muted); }
.chart-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.chart-grid .chart-card:first-child { grid-column: 1 / -1; }
.chart-card, .heat-card, .table-card { padding: 16px 18px; }
.heat-card, .table-card { margin-top: 12px; }
.chart-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.chart-head .unit { font-weight: 400; color: var(--muted); font-size: 13.5px; margin-left: 4px; }
.chart-sub { font-size: 13px; color: var(--muted); }
.chart { position: relative; margin-top: 8px; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .empty { color: var(--muted); font-size: 14px; padding: 30px 0; text-align: center; }
.chart-tooltip {
  position: absolute; pointer-events: none;
  background: var(--surface); border: 1px solid var(--border);
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
  border-radius: 8px; padding: 6px 10px; font-size: 13px;
  white-space: nowrap; transform: translate(-50%, -110%);
  color: var(--ink);
}
.chart-tooltip .tt-date { color: var(--muted); font-size: 12px; }
.chart-tooltip .tt-val { font-weight: 650; }
.data-table { width: 100%; border-collapse: collapse; margin-top: 10px; font-size: 14px; }
.data-table th, .data-table td { text-align: right; padding: 6px 8px; border-bottom: 1px solid var(--border); font-variant-numeric: tabular-nums; }
.data-table th:first-child, .data-table td:first-child { text-align: left; }
.data-table th { color: var(--muted); font-weight: 550; }

/* ---------- settings ---------- */
.settings-card { padding: 18px 22px; margin-top: 12px; max-width: 760px; }
.settings-card h2 { margin-bottom: 8px; }
.settings-card p { margin: 4px 0; font-size: 15px; }
.setting-row {
  display: flex; justify-content: space-between; align-items: center; gap: 20px;
  padding: 10px 0; border-top: 1px solid var(--border);
}
.setting-row:first-of-type { border-top: 0; }
.setting-row small { color: var(--muted); font-size: 13.5px; }
.setting-row input[type="checkbox"] {
  appearance: none; -webkit-appearance: none;
  width: 44px; height: 26px; border-radius: 99px; background: var(--surface-3);
  position: relative; cursor: pointer; flex: none; transition: background .2s;
}
.setting-row input[type="checkbox"]::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 20px; height: 20px; border-radius: 50%; background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,0.25); transition: transform .2s;
}
.setting-row input[type="checkbox"]:checked { background: var(--accent); }
.setting-row input[type="checkbox"]:checked::after { transform: translateX(18px); }
.level-detail { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 10px; }
.level-detail .chip.locked { opacity: .4; border-style: dashed; }
.status-msg { font-size: 14px; color: var(--accent); min-height: 1.4em; }
.danger-zone h2 { color: var(--bad); }
.version { font-size: 12.5px; margin-top: 18px; }

/* ---------- overlay ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(20, 22, 18, 0.45);
  display: grid; place-items: center; padding: 20px; z-index: 50;
}
.overlay[hidden] { display: none; }
.welcome-card {
  background: var(--surface); border-radius: 18px; padding: 30px 34px;
  max-width: 620px; box-shadow: 0 20px 60px rgba(0,0,0,0.25);
  font-size: 17px;
}
.welcome-card ol { padding-left: 22px; }
.welcome-card li { margin: 10px 0; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 10px;
  font-size: 15px; z-index: 60; box-shadow: 0 8px 24px rgba(0,0,0,0.2);
}
.toast[hidden] { display: none; }

@media (max-width: 760px) {
  .topbar { padding: 10px 16px; flex-wrap: wrap; }
  main { padding: 4px 16px 24px; }
  .tiles { grid-template-columns: 1fr 1fr; }
  .chart-grid { grid-template-columns: 1fr; }
  .keyboard { grid-auto-rows: 34px; }
  .key { font-size: 13px; }
  .exercise-card { padding: 14px 16px; }
}

/* heatmap keys are neutral unless they carry data (no finger-zone colours here) */
.keyboard.heat .key { background: var(--surface-2); }
.keyboard.heat .key.home::after { display: none; }

/* ---------- view-only link (…&katsele) ---------- */
.view-only-banner {
  position: sticky; top: 0; z-index: 50;
  background: var(--accent); color: var(--accent-ink);
  text-align: center; font-size: 15px; font-weight: 600; padding: 8px 16px;
}
