/* Dedilhado — só branco, preto e cinzas */
*, *::before, *::after { box-sizing: border-box; }

:root {
  --font-ui: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", sans-serif;
  --font-mono: "Cascadia Mono", "JetBrains Mono", Consolas, "Courier New", monospace;
  --radius: 14px;
  --fs: 25px;
  --lh: 46px;
  --kh: clamp(30px, 4.4vw, 52px);
}

:root, [data-theme="light"] {
  --bg: #e7e7e7;
  --surface: #efefef;
  --surface-2: #f9f9f9;
  --ink: #111111;
  --ink-2: #474747;
  --muted: #8c8c8c;
  --line: #d0d0d0;
  --line-strong: #a9a9a9;
  --inset: rgba(0, 0, 0, .08);
  --board: #d6d6d6;
  --board-hi: rgba(255, 255, 255, .7);
  --key-top: #ffffff;
  --key-bot: #e9e9e9;
  --key-top2: #f0f0f0;
  --key-bot2: #d9d9d9;
  --key-line: #c4c4c4;
  --key-edge: #a6a6a6;
  --key-hi: rgba(255, 255, 255, .9);
  --key-shadow: rgba(0, 0, 0, .18);
  --key-ink: #1d1d1d;
  --accent: #141414;
  --accent-ink: #ffffff;
  --ring: rgba(0, 0, 0, .18);
  --f5: #1c1c1c; --f4: #565656; --f3: #8e8e8e; --f2: #bdbdbd; --ft: #d8d8d8;
  --heat-c: #000000;
  --miss-bg: #dcdcdc;
  color-scheme: light;
}

[data-theme="dark"] {
  --bg: #121212;
  --surface: #1a1a1a;
  --surface-2: #202020;
  --ink: #f1f1f1;
  --ink-2: #bdbdbd;
  --muted: #6e6e6e;
  --line: #2f2f2f;
  --line-strong: #4b4b4b;
  --inset: rgba(0, 0, 0, .5);
  --board: #0b0b0b;
  --board-hi: rgba(255, 255, 255, .05);
  --key-top: #3b3b3b;
  --key-bot: #2b2b2b;
  --key-top2: #2e2e2e;
  --key-bot2: #222222;
  --key-line: #191919;
  --key-edge: #000000;
  --key-hi: rgba(255, 255, 255, .09);
  --key-shadow: rgba(0, 0, 0, .6);
  --key-ink: #e9e9e9;
  --accent: #f1f1f1;
  --accent-ink: #111111;
  --ring: rgba(255, 255, 255, .22);
  --f5: #f2f2f2; --f4: #b3b3b3; --f3: #7a7a7a; --f2: #505050; --ft: #3a3a3a;
  --heat-c: #ffffff;
  --miss-bg: #333333;
  color-scheme: dark;
}

html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 15px;
  min-height: 100vh;
  transition: background .2s, color .2s;
}
button, select, input, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
kbd {
  font-family: var(--font-mono); font-size: .82em; padding: 1px 6px; border-radius: 5px;
  border: 1px solid var(--line-strong); border-bottom-width: 2px; background: var(--surface-2);
}

/* ---------- Topo ---------- */
.topbar {
  display: flex; align-items: center; gap: 16px; padding: 12px 24px;
  border-bottom: 1px solid var(--line); background: var(--surface);
  position: sticky; top: 0; z-index: 10;
}
.brand {
  background: none; border: 0; cursor: pointer; font-weight: 700; font-size: 18px;
  display: flex; align-items: center; gap: 8px; letter-spacing: .2px; padding: 0;
}
.brand-mark { font-size: 22px; }
.nav { display: flex; gap: 4px; margin-left: 12px; }
.nav button {
  background: none; border: 0; padding: 8px 12px; border-radius: 9px; cursor: pointer; color: var(--ink-2);
}
.nav button:hover { background: var(--bg); }
.nav button.active { color: var(--ink); font-weight: 600; background: var(--bg); }
.top-tools { margin-left: auto; display: flex; gap: 8px; align-items: center; }

select, input[type="number"] {
  background: var(--surface-2); border: 1px solid var(--line-strong); border-radius: 9px; padding: 6px 10px;
}
.icon-btn {
  width: 36px; height: 36px; border-radius: 10px; border: 1px solid var(--key-line); cursor: pointer;
  background: linear-gradient(var(--key-top), var(--key-bot)); box-shadow: 0 3px 0 var(--key-edge);
  font-size: 16px; transition: transform .05s, box-shadow .05s;
}
.icon-btn:active { transform: translateY(3px); box-shadow: none; }
.icon-btn.off { color: var(--muted); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 15px; border-radius: 10px; border: 1px solid var(--key-line); cursor: pointer;
  background: linear-gradient(var(--key-top), var(--key-bot)); box-shadow: 0 3px 0 var(--key-edge), 0 4px 8px var(--key-shadow);
  transition: transform .05s, box-shadow .05s; white-space: nowrap;
}
.btn:active { transform: translateY(3px); box-shadow: 0 0 0 var(--key-edge); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary kbd { background: transparent; color: inherit; border-color: currentColor; }
.btn.danger { border-style: dashed; }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 10px; }

main { max-width: 1080px; margin: 0 auto; padding: 22px 20px 50px; }
.view { display: none; }
.view.active { display: block; animation: fade .2s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } }

.panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px;
}
.panel h3 { margin: 0 0 12px; font-size: 15px; }
.panel-label { font-size: 12px; text-transform: uppercase; letter-spacing: .8px; color: var(--muted); margin-bottom: 8px; }
.panel-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.panel-head h3 { margin: 0; }
.pill {
  display: inline-flex; align-items: center; gap: 4px; font-size: 12px; padding: 3px 10px;
  border-radius: 999px; border: 1px solid var(--line-strong); color: var(--ink-2); white-space: nowrap;
}
.bar { height: 8px; border-radius: 99px; background: var(--bg); border: 1px solid var(--line); overflow: hidden; margin-top: 10px; }
.bar > div { height: 100%; width: 0; background: var(--ink); border-radius: 99px; transition: width .3s; }
.bar.thin { height: 4px; margin: 10px 0 0; border: 0; background: var(--line); }

/* ---------- Início ---------- */
.home-top { display: grid; grid-template-columns: 1fr 1fr 1.2fr; gap: 14px; }
.metric-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.metric-row b { font-size: 18px; }
.quick-row { display: flex; gap: 8px; margin-top: 8px; }
.quick-row .btn { flex: 1; }
.section-title { font-size: 16px; margin: 28px 0 12px; }
.phase-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; }
.phase {
  text-align: left; cursor: pointer; padding: 14px 15px 13px; border-radius: var(--radius);
  border: 1px solid var(--key-line); background: linear-gradient(var(--key-top), var(--key-bot));
  box-shadow: 0 4px 0 var(--key-edge), 0 6px 12px var(--key-shadow);
  display: flex; flex-direction: column; gap: 6px; transition: transform .06s, box-shadow .06s;
}
.phase:hover:not(:disabled) { transform: translateY(-1px); }
.phase:active:not(:disabled) { transform: translateY(4px); box-shadow: 0 0 0 var(--key-edge), 0 1px 2px var(--key-shadow); }
.phase.locked { opacity: .45; cursor: not-allowed; box-shadow: 0 2px 0 var(--key-edge); }
.phase.current { outline: 2px solid var(--ink); outline-offset: 2px; }
.ph-top { display: flex; justify-content: space-between; align-items: center; }
.ph-num { font-family: var(--font-mono); font-weight: 700; font-size: 20px; }
.ph-stars { font-size: 14px; letter-spacing: 1px; color: var(--ink-2); display: inline-flex; align-items: center; gap: 4px; }
.phase.locked .ph-stars { font-size: 12px; letter-spacing: 0; }
.ph-name { font-weight: 650; font-size: 15px; }
.ph-desc { font-size: 13px; color: var(--ink-2); line-height: 1.35; flex: 1; }
.ph-meta { display: flex; justify-content: space-between; gap: 6px; font-size: 11.5px; color: var(--muted); flex-wrap: wrap; }

/* ---------- Prática ---------- */
.p-head { display: flex; align-items: center; gap: 14px; }
.p-title { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.p-title b { font-size: 17px; }
.p-title span { font-size: 13px; color: var(--ink-2); }
.statsbar { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-top: 16px; }
.stat {
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 8px 14px;
  display: flex; align-items: baseline; gap: 8px;
}
.stat b { font-family: var(--font-mono); font-size: 24px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; }

.textbox {
  position: relative; margin: 14px 0 8px; padding: 0 22px;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius);
  height: calc(var(--lh) * 3 + 2px); overflow: hidden; cursor: text;
  box-shadow: inset 0 2px 6px var(--inset);
}
.text-inner {
  position: relative; font-family: var(--font-mono); font-size: var(--fs); line-height: var(--lh);
  white-space: pre-wrap; word-break: normal; overflow-wrap: break-word; transition: transform .18s ease;
}
.ch { color: var(--muted); border-radius: 3px; }
.ch.ok { color: var(--ink); }
.ch.ok.fixed { text-decoration: underline dotted var(--muted); text-underline-offset: 7px; }
.ch.err { background: var(--ink); color: var(--bg); }
.ch.cur { position: relative; color: var(--ink); background: var(--miss-bg); }
.ch.cur::before {
  content: ''; position: absolute; left: 0; right: 0; bottom: 3px; height: 3px; border-radius: 2px; background: var(--ink);
  animation: blink 1.05s steps(1) infinite;
}
.textbox.running .ch.cur::before { animation: none; }
.ch.miss { outline: 2px dashed var(--ink); outline-offset: -1px; animation: shake .22s; }
.ch.ghost { position: relative; }
.ch.ghost::after {
  content: ''; position: absolute; left: 50%; top: 1px; width: 7px; height: 7px; margin-left: -3.5px;
  border-radius: 50%; background: var(--muted); box-shadow: 0 0 0 2px var(--surface-2);
}
@keyframes blink { 50% { opacity: 0; } }
@keyframes shake { 25% { transform: translateX(-2px); } 75% { transform: translateX(2px); } }

.focus-veil {
  display: none; position: absolute; inset: 0; align-items: center; justify-content: center;
  background: color-mix(in srgb, var(--surface-2) 82%, transparent); backdrop-filter: blur(3px);
  font-weight: 600; color: var(--ink-2); border-radius: inherit;
}
.textbox.blurred .focus-veil { display: flex; }

.hint-row { display: flex; justify-content: space-between; align-items: center; min-height: 26px; font-size: 14px; color: var(--ink-2); gap: 10px; }
.caps { font-weight: 700; color: var(--ink); border-color: var(--ink); }

/* ---------- Teclado em alto-relevo ---------- */
.keyboard {
  max-width: 960px; margin: 8px auto 0; padding: 12px 12px 16px; border-radius: 18px;
  background: var(--board); box-shadow: inset 0 1px 0 var(--board-hi), 0 12px 30px var(--key-shadow);
  user-select: none;
}
.kb-row { display: grid; grid-template-columns: repeat(60, minmax(0, 1fr)); }
.key { padding: 3px; min-width: 0; }
.cap {
  position: relative; height: var(--kh); border-radius: 8px;
  background: linear-gradient(180deg, var(--key-top), var(--key-bot));
  border: 1px solid var(--key-line);
  box-shadow: 0 4px 0 var(--key-edge), 0 6px 9px var(--key-shadow), inset 0 1px 0 var(--key-hi);
  color: var(--key-ink); font-size: calc(var(--kh) * .34);
  transition: transform .05s, box-shadow .05s, background .12s, color .12s;
}
.key.special .cap { background: linear-gradient(180deg, var(--key-top2), var(--key-bot2)); }
.lbl { position: absolute; line-height: 1; z-index: 1; pointer-events: none; }
.lbl-c { inset: 0; display: flex; align-items: center; justify-content: center; font-weight: 600; }
.lbl-c.small { font-size: .62em; font-weight: 500; color: var(--ink-2); }
.lbl-s { top: 17%; left: 24%; font-size: .74em; color: var(--ink-2); }
.lbl-n { bottom: 22%; left: 24%; font-size: .86em; font-weight: 600; }
.bump {
  position: absolute; bottom: 20%; left: 50%; width: 24%; height: 2px; margin-left: -12%;
  background: currentColor; opacity: .55; border-radius: 2px;
}
/* marcas dos dedos */
.cap::after {
  content: ''; position: absolute; left: 22%; right: 22%; bottom: 5px; height: 3px; border-radius: 2px;
  background: var(--fc, transparent);
}
.key[data-finger="L5"] .cap, .key[data-finger="R5"] .cap { --fc: var(--f5); }
.key[data-finger="L4"] .cap, .key[data-finger="R4"] .cap { --fc: var(--f4); }
.key[data-finger="L3"] .cap, .key[data-finger="R3"] .cap { --fc: var(--f3); }
.key[data-finger="L2"] .cap, .key[data-finger="R2"] .cap { --fc: var(--f2); }
.key[data-finger="T"] .cap { --fc: var(--ft); }
.key.special:not(.space) .cap::after { display: none; }
.keyboard.no-fingers .cap::after { display: none; }
.keyboard.hide-labels .lbl, .keyboard.hide-labels .bump { visibility: hidden; }

.key.pressed .cap {
  transform: translateY(4px);
  box-shadow: 0 0 0 var(--key-edge), 0 1px 2px var(--key-shadow), inset 0 1px 0 var(--key-hi);
}
.key.hint .cap {
  background: var(--accent); color: var(--accent-ink); border-color: var(--accent);
  animation: pulse 1.3s ease-in-out infinite;
}
.key.hint .lbl-c.small, .key.hint .lbl-s { color: var(--accent-ink); }
.key.hint .cap::after { background: var(--accent-ink); opacity: .6; }
.key.hint-shift .cap { background: var(--ink-2); color: var(--bg); border-color: var(--ink-2); }
.key.hint-shift .lbl-c.small { color: var(--bg); }
.key.wrong .cap { animation: shake .25s; outline: 2px solid var(--ink); outline-offset: 1px; }
@keyframes pulse {
  50% { box-shadow: 0 4px 0 var(--key-edge), 0 0 0 5px var(--ring), inset 0 1px 0 var(--key-hi); }
}
/* Enter em L (ABNT2) */
.key.enter-top { padding-bottom: 0; }
.key.enter-top .cap { height: calc(var(--kh) + 3px); border-bottom-right-radius: 0; box-shadow: inset 0 1px 0 var(--key-hi); }
.key.enter-bot { padding-top: 0; }
.key.enter-bot .cap { height: calc(var(--kh) + 3px); border-top: 0; border-top-left-radius: 0; border-top-right-radius: 0; }

/* mapa de calor */
.keyboard.heat { margin-top: 4px; box-shadow: inset 0 1px 0 var(--board-hi); }
.key.heated .cap::before {
  content: ''; position: absolute; inset: 0; border-radius: inherit; background: var(--heat-c);
  opacity: calc(var(--heat) * .88);
}
.key.hot .cap { color: var(--bg); }
.key.hot .lbl-s { color: var(--bg); }

/* mãos */
.hands { max-width: 380px; margin: 14px auto 0; }
.hands svg { width: 100%; display: block; }
.hands .palm, .hands .finger { fill: var(--surface-2); stroke: var(--line-strong); stroke-width: 2; }
.hands .finger { transition: fill .12s, stroke .12s; }
.hands .finger.on { fill: var(--accent); stroke: var(--accent); }
.shortcuts { text-align: center; font-size: 12.5px; color: var(--muted); margin-top: 10px; }

/* ---------- Estatísticas ---------- */
#view-stats .panel { margin-top: 14px; }
.stat-cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
#view-stats .stat-cards .panel { margin-top: 0; }
.stat-card { display: flex; flex-direction: column; gap: 4px; }
.stat-card span { font-size: 12px; color: var(--muted); }
.stat-card b { font-size: 22px; font-family: var(--font-mono); }
#chart { width: 100%; height: 240px; display: block; }
.legend { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink-2); }
.lg { display: inline-block; width: 22px; height: 0; border-top: 2.5px solid var(--ink); margin-left: 6px; }
.lg-acc { border-top: 2px dashed var(--muted); }
.weak-list { margin-top: 14px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.weak-list .pill { font-family: var(--font-mono); font-size: 14px; }
.weak-list small { color: var(--muted); font-size: 11px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-weight: 500; font-size: 12px; text-transform: uppercase; letter-spacing: .5px; }
td { font-variant-numeric: tabular-nums; }

/* ---------- Configurações ---------- */
.settings { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.row:last-of-type { border-bottom: 0; }
.note { font-size: 13px; color: var(--ink-2); line-height: 1.5; margin: 6px 0; }
input[type="checkbox"] {
  appearance: none; -webkit-appearance: none; width: 42px; height: 24px; border-radius: 12px; flex: none;
  background: var(--line-strong); position: relative; cursor: pointer; transition: background .15s; margin: 0;
}
input[type="checkbox"]::before {
  content: ''; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%;
  background: var(--surface-2); box-shadow: 0 1px 3px rgba(0, 0, 0, .3); transition: transform .15s;
}
input[type="checkbox"]:checked { background: var(--ink); }
input[type="checkbox"]:checked::before { transform: translateX(18px); background: var(--bg); }
input[type="range"] { accent-color: var(--ink); width: 160px; }
input[type="number"] { width: 80px; }

/* ---------- Modais ---------- */
.modal {
  position: fixed; inset: 0; background: rgba(0, 0, 0, .45); display: flex; align-items: center; justify-content: center;
  z-index: 50; padding: 16px; animation: fade .15s;
}
.modal-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 26px 28px;
  width: min(480px, 100%); box-shadow: 0 20px 60px rgba(0, 0, 0, .35); text-align: center;
}
.modal-card.wide { width: min(640px, 100%); text-align: left; }
.modal-card h2 { margin: 0 0 6px; }
.stars { font-size: 34px; letter-spacing: 6px; margin: 4px 0 8px; }
.r-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin: 14px 0; }
.r-grid div { background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 10px 4px; display: flex; flex-direction: column; }
.r-grid b { font-family: var(--font-mono); font-size: 24px; }
.r-grid span { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
#rMsg { line-height: 1.5; }
#rKeys { font-family: var(--font-mono); font-size: 13px; }
.r-actions { display: flex; gap: 10px; justify-content: center; margin-top: 18px; flex-wrap: wrap; }
.modal-card.wide .r-actions { justify-content: flex-end; }
textarea#customText {
  width: 100%; background: var(--surface-2); border: 1px solid var(--line-strong); border-radius: 10px;
  padding: 12px; font-family: var(--font-mono); font-size: 14px; resize: vertical;
}

.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); z-index: 60;
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px;
  display: flex; align-items: center; gap: 12px; box-shadow: 0 10px 30px rgba(0, 0, 0, .3); max-width: calc(100% - 32px);
}
.toast .btn.primary { background: var(--bg); color: var(--ink); border-color: var(--bg); box-shadow: none; }

.hidden-input { position: fixed; top: 0; left: 0; width: 1px; height: 1px; opacity: 0; border: 0; padding: 0; resize: none; pointer-events: none; }

/* ---------- Responsivo ---------- */
@media (max-width: 860px) {
  .home-top { grid-template-columns: 1fr; }
  .settings { grid-template-columns: 1fr; }
  .stat-cards { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 640px) {
  :root { --fs: 18px; --lh: 34px; }
  main { padding: 16px; }
  .topbar { flex-wrap: wrap; padding: 10px 16px; gap: 8px; }
  .nav { margin-left: 0; order: 3; width: 100%; }
  .statsbar { grid-template-columns: repeat(2, 1fr); }
  .r-grid { grid-template-columns: repeat(2, 1fr); }
  .keyboard { padding: 6px; }
  .key { padding: 1.5px; }
}
