:root {
  --bg: #17120e; --bg2: #1f1913; --surf: #261f18; --line: #3a3128; --ink: #f6efe2; --mute: #a99c88;
  --acc: #ffb703; --acc-ink: #1a1208; --teal: #2ec4b6; --bad: #ff5a4f; --ok: #9be37a; --heat: 255, 90, 79;
  --font: 'Noto Sans Arabic', 'Segoe UI', Tahoma, system-ui, -apple-system, sans-serif;
  --text-font: 'Noto Naskh Arabic', 'Amiri', 'Traditional Arabic', 'Segoe UI', serif;
  --r: 16px; color-scheme: dark;
}
:root[data-theme=light] { --bg: #f6efe2; --bg2: #efe5d2; --surf: #fffaf0; --line: #d9ccb4; --ink: #1d1a16; --mute: #6d6354; --acc: #f59e0b; --teal: #0f8f84; --bad: #d63a2f; --ok: #3e8e22; color-scheme: light; }
@media (prefers-color-scheme: light) {
  :root:not([data-theme]) { --bg: #f6efe2; --bg2: #efe5d2; --surf: #fffaf0; --line: #d9ccb4; --ink: #1d1a16; --mute: #6d6354; --acc: #f59e0b; --teal: #0f8f84; --bad: #d63a2f; --ok: #3e8e22; color-scheme: light; }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { background: var(--bg); }
body { margin: 0; font-family: var(--font); background: var(--bg); color: var(--ink); line-height: 1.5; min-height: 100vh; padding-bottom: calc(76px + env(safe-area-inset-bottom)); }
button, select, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--acc); outline-offset: 2px; }
h2 { font-size: 1.5rem; margin: .2rem 0 .4rem; }
h3 { font-size: 1.05rem; margin: 0 0 .6rem; }
.lead, .hint { color: var(--mute); font-size: .92rem; margin: .4rem 0 .8rem; }
.hint.err { color: var(--bad); min-height: 1.2em; }
.hint.err.okmsg { color: var(--ok); }

.top { padding-inline: max(16px, calc((100vw - 760px) / 2)) !important; position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between; padding: 10px 16px; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; }
.brand-name { font-weight: 800; font-size: 1.35rem; line-height: 1; display: flex; flex-direction: column; }
.brand-name small { font-size: .62rem; letter-spacing: .22em; color: var(--acc); font-weight: 600; margin-top: 3px; text-transform: uppercase; }
.top-actions { display: flex; gap: 8px; }
.icon-btn { width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--line); background: var(--surf); font-weight: 700; font-size: .95rem; }
.icon-btn:hover { border-color: var(--acc); }

main { max-width: 760px; margin: 0 auto; padding: 18px 16px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 14px; }
.chip { padding: 8px 15px; border-radius: 999px; border: 1px solid var(--line); background: var(--surf); font-weight: 600; font-size: .93rem; min-height: 40px; }
.chip.on { background: var(--acc); color: var(--acc-ink); border-color: var(--acc); }
.field-label { font-size: .75rem; letter-spacing: .1em; text-transform: uppercase; color: var(--mute); margin: 8px 0 6px; font-weight: 700; }
.go { width: 100%; margin-top: 10px; min-height: 58px; border: 0; border-radius: var(--r); background: var(--acc); color: var(--acc-ink); font-weight: 800; font-size: 1.2rem; box-shadow: 0 6px 0 color-mix(in srgb, var(--acc) 55%, #000); transition: transform .08s, box-shadow .08s; }
.go:active { transform: translateY(4px); box-shadow: 0 2px 0 color-mix(in srgb, var(--acc) 55%, #000); }
.go.small { width: auto; min-height: 44px; padding: 0 22px; font-size: 1rem; margin: 0; box-shadow: 0 4px 0 color-mix(in srgb, var(--acc) 55%, #000); }
.ghost-btn { min-height: 44px; padding: 0 18px; border-radius: 12px; border: 1px solid var(--line); background: transparent; font-weight: 600; }
.ghost-btn:hover { border-color: var(--acc); }
.ghost-btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 50%, var(--line)); }
.row { display: flex; gap: 10px; align-items: center; justify-content: space-between; margin-top: 12px; }
.row.wrap { flex-wrap: wrap; justify-content: flex-start; }

/* arena */
.arena-top { display: flex; align-items: center; gap: 14px; margin-bottom: 8px; }
.gauge { position: relative; width: 150px; flex: none; }
.gauge-svg { width: 100%; display: block; }
.g-bg { fill: none; stroke: var(--line); stroke-width: 14; stroke-linecap: round; }
.g-fg { fill: none; stroke: var(--acc); stroke-width: 14; stroke-linecap: round; stroke-dasharray: 0 100; transition: stroke-dasharray .2s linear; }
.g-needle { stroke: var(--ink); stroke-width: 4; stroke-linecap: round; }
.g-hub { fill: var(--ink); }
.g-read { display: flex; flex-direction: column; align-items: center; line-height: 1; margin-top: 2px; }
.g-read b { font-size: 2.2rem; font-variant-numeric: tabular-nums; }
.g-read span { font-size: .7rem; color: var(--mute); letter-spacing: .1em; text-transform: uppercase; }
.stats-live { align-self: center; flex: 1; display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; text-align: center; }
.stats-live div { justify-content: center; background: var(--surf); border: 1px solid var(--line); border-radius: 12px; padding: 8px 4px; display: flex; flex-direction: column; }
.stats-live span { font-size: .68rem; color: var(--mute); }
.stats-live b { font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.lanes { margin: 12px 0; display: grid; gap: 7px; }
.lane { display: grid; grid-template-columns: 78px 1fr; align-items: center; gap: 8px; font-size: .75rem; color: var(--mute); }
.lane-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.track { position: relative; height: 12px; border-radius: 6px; background: var(--bg2); border: 1px solid var(--line); }
.runner { position: absolute; top: -4px; inset-inline-start: 0; width: 18px; height: 18px; margin-inline-start: -2px; border-radius: 50%; background: var(--acc); border: 3px solid var(--bg); transition: inset-inline-start .12s linear; }
.lane.ghost .runner { background: var(--teal); }
.lane.target .runner { background: var(--mute); }
.lane.you .track::after { content: ''; position: absolute; inset: 0; border-radius: 6px; background: repeating-linear-gradient(90deg, transparent 0 14px, color-mix(in srgb, var(--line) 80%, transparent) 14px 16px); }
.textbox { position: relative; border: 2px solid var(--line); border-radius: var(--r); background: var(--surf); padding: 22px 16px 14px; overflow: hidden; cursor: text; }
.textbox.focus { border-color: var(--acc); }
.stripes { position: absolute; top: 0; inset-inline: 0; height: 7px; background: repeating-linear-gradient(-45deg, var(--acc) 0 10px, #17120e 10px 20px); opacity: .85; }
.text { font-family: var(--text-font); font-size: 1.7rem; line-height: 2.5rem; max-height: 7.5rem; overflow: hidden; position: relative; text-align: start; word-break: keep-all; user-select: none; -webkit-user-select: none; }
.text.en { max-height: 6.9rem; font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace; font-size: 1.35rem; line-height: 2.3rem; }
.w { display: inline-block; white-space: nowrap; }
.c { color: var(--mute); border-radius: 4px; }
.c.ok { color: var(--ink); }
.c.bad { color: var(--bad); background: color-mix(in srgb, var(--bad) 22%, transparent); }
.c.cur { box-shadow: inset 0 -4px 0 var(--acc); color: var(--ink); }
.sink { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; resize: none; border: 0; font-size: 16px; }
.tap-hint { position: absolute; inset: 7px 0 0; display: flex; align-items: center; justify-content: center; text-align: center; padding: 10px 24px; background: color-mix(in srgb, var(--surf) 78%, transparent); backdrop-filter: blur(3px); font-weight: 700; pointer-events: none; }
.tap-hint[hidden] { display: none; }
.arena-actions { display: flex; gap: 10px; margin-top: 14px; }

/* keyboard */
.kb { margin: 14px auto 0; display: grid; gap: 5px; max-width: 520px; direction: ltr; }
.kb-row { display: flex; gap: 5px; justify-content: center; }
.kb-row.f2 { padding-inline: 4%; } .kb-row.f1 { padding-inline: 9%; } .kb-row.solo { justify-content: flex-start; padding-inline-start: 2%; }
.key { flex: 1 1 0; max-width: 40px; height: 38px; display: grid; place-items: center; background: var(--surf); border: 1px solid var(--line); border-bottom-width: 3px; border-radius: 8px; font-size: 1.05rem; color: var(--mute); font-family: var(--font); transition: background .1s; }
.key.space { max-width: 220px; flex: 4 1 0; }
.key.wide { max-width: 64px; flex: 1.6 1 0; font-size: .9rem; }
.key.space.next { background: color-mix(in srgb, var(--acc) 45%, var(--surf)); }
.key.next { background: var(--acc); color: var(--acc-ink); border-color: var(--acc); transform: translateY(-2px); font-weight: 800; }
.kb.heat .key.hot { background: rgba(var(--heat), var(--h)); color: #fff; border-color: rgba(var(--heat), 1); }

/* panels & cards */
.panel, .weak-card, .lesson, .lib-item { background: var(--surf); border: 1px solid var(--line); border-radius: var(--r); padding: 14px; margin: 12px 0; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(105px, 1fr)); gap: 8px; margin-bottom: 10px; }
.card { background: var(--surf); border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; display: flex; flex-direction: column; border-inline-start: 4px solid var(--acc); }
.card span { font-size: .72rem; color: var(--mute); }
.card b { font-size: 1.4rem; font-variant-numeric: tabular-nums; }
.chart-svg { width: 100%; height: auto; }
.chart-svg .grid { stroke: var(--line); stroke-width: 1; }
.chart-svg .axis { fill: var(--mute); font-size: 9px; }
.chart-svg .line { stroke: var(--acc); stroke-width: 2.5; stroke-linejoin: round; }
.chart-svg .bestline { stroke: var(--teal); stroke-dasharray: 4 3; stroke-width: 1.2; }
.chart-svg .dot { fill: var(--acc); stroke: var(--surf); stroke-width: 1.5; }
.chart-svg .dot.low { fill: var(--bad); }
.wbar { display: grid; grid-template-columns: 28px 1fr 32px; align-items: center; gap: 8px; margin: 6px 0; }
.wbar b { font-size: 1.2rem; text-align: center; }
.wb-track { height: 10px; background: var(--bg2); border-radius: 5px; overflow: hidden; }
.wb-fill { display: block; height: 100%; background: var(--bad); border-radius: 5px; }
.wbar small { color: var(--mute); text-align: end; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; font-variant-numeric: tabular-nums; }
th, td { padding: 8px 6px; text-align: start; border-bottom: 1px solid var(--line); }
th { color: var(--mute); font-size: .75rem; font-weight: 600; }
.weak-chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.wchip { display: inline-flex; align-items: baseline; gap: 6px; padding: 6px 12px; border-radius: 12px; background: color-mix(in srgb, var(--bad) 18%, transparent); border: 1px solid color-mix(in srgb, var(--bad) 50%, transparent); }
.wchip b { font-size: 1.4rem; }
.wchip small { color: var(--mute); }
.lesson-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.lesson { margin: 0; display: flex; flex-direction: column; gap: 10px; }
.lesson.done { border-color: color-mix(in srgb, var(--acc) 60%, var(--line)); }
.l-head { display: flex; justify-content: space-between; align-items: center; }
.l-stars { color: var(--acc); letter-spacing: 2px; }
.l-letters { display: flex; gap: 6px; flex-wrap: wrap; }
.l-letters span { min-width: 34px; height: 38px; display: grid; place-items: center; border-radius: 8px; background: var(--bg2); border: 1px solid var(--line); font-size: 1.2rem; font-family: var(--text-font); }
.lesson .go.small { width: 100%; margin-top: auto; }
.lesson-list .hint { grid-column: 1 / -1; }
.lib-item { display: flex; gap: 12px; align-items: center; justify-content: space-between; margin: 8px 0; }
.li-info { min-width: 0; }
.li-info small { display: block; color: var(--mute); }
.li-snip { margin: 4px 0 0; color: var(--mute); font-family: var(--text-font); font-size: 1.05rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.li-acts { display: flex; flex-direction: column; gap: 6px; flex: none; }
.add summary { cursor: pointer; font-weight: 700; }
.add label { display: block; margin-top: 12px; font-size: .85rem; color: var(--mute); }
.add input, .add textarea { width: 100%; margin-top: 4px; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg2); color: var(--ink); }

/* tabs */
.tabs { position: fixed; inset-inline: 0; bottom: 0; z-index: 6; display: grid; grid-template-columns: repeat(4, 1fr); background: var(--bg2); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.tabs a { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 9px 0 8px; text-decoration: none; color: var(--mute); font-size: .74rem; font-weight: 600; position: relative; }
.tabs a i { font-style: normal; font-size: 1.2rem; line-height: 1.2; }
.tabs a.on { color: var(--acc); }
.tabs a.on::before { content: ''; position: absolute; top: 0; width: 34px; height: 3px; border-radius: 0 0 3px 3px; background: var(--acc); }

/* dialogs */
.dlg { border: 1px solid var(--line); border-radius: 22px; background: var(--bg2); color: var(--ink); padding: 0; width: min(92vw, 440px); max-height: 90vh; }
.dlg::backdrop { background: rgba(0, 0, 0, .6); }
.dlg-body { padding: 22px; margin: 0; }
.dlg-body h3 { font-size: 1.25rem; text-align: center; }
.badge-best { text-align: center; background: var(--acc); color: var(--acc-ink); font-weight: 800; border-radius: 999px; padding: 4px 14px; width: max-content; margin: 0 auto 8px; }
.res-big { text-align: center; display: flex; flex-direction: column; line-height: 1; margin: 6px 0 14px; }
.res-big b { font-size: 4.2rem; color: var(--acc); font-variant-numeric: tabular-nums; }
.res-big span { color: var(--mute); letter-spacing: .12em; text-transform: uppercase; font-size: .8rem; margin-top: 4px; }
.res-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.res-grid div { background: var(--surf); border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px; display: flex; flex-direction: column; }
.res-grid span { font-size: .72rem; color: var(--mute); }
.res-grid b { font-size: 1.2rem; }
.res-rank { text-align: center; margin: 14px 0 4px; display: flex; flex-direction: column; gap: 4px; align-items: center; }
.rank-pill { padding: 4px 18px; border-radius: 999px; font-weight: 800; background: var(--line); }
.rank-pill.r3, .rank-pill.r4, .rank-pill.r5 { background: var(--teal); color: #06201d; }
.res-rank small { color: var(--mute); }
.res-stars { text-align: center; color: var(--acc); font-size: 1.6rem; letter-spacing: 4px; }
.set { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.set select { background: var(--surf); border: 1px solid var(--line); border-radius: 10px; padding: 6px 10px; }
.set input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--acc); }
.range { display: flex; align-items: center; gap: 8px; } .range output { min-width: 2ch; font-variant-numeric: tabular-nums; }
.range input { accent-color: var(--acc); width: 120px; }
.dlg h4 { margin: 16px 0 0; }
.about { color: var(--mute); font-size: .8rem; margin-top: 14px; }

@media (min-width: 720px) {
  .text.en { max-height: 6.9rem; }
  .text { font-size: 2rem; line-height: 3rem; max-height: 9rem; }
  .gauge { width: 220px; }
  .tabs { max-width: 560px; margin: 0 auto; border-radius: 18px 18px 0 0; border: 1px solid var(--line); border-bottom: 0; }
}
@media (max-width: 380px) { .gauge { width: 130px; } .g-read b { font-size: 1.7rem; } .lane { grid-template-columns: 62px 1fr; } }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

.hero { padding: 6px 2px 14px; }
.hero h2 { font-size: 1.75rem; line-height: 1.25; margin: 4px 0 6px; }
.hero-stats { display: flex; gap: 10px; align-items: stretch; flex-wrap: wrap; margin: 10px 0 4px; }
.hero-stats div:not(.rank-pill) { background: var(--surf); border: 1px solid var(--line); border-radius: 14px; padding: 8px 12px; display: flex; flex-direction: column; min-width: 0; flex: 1; border-inline-start: 4px solid var(--acc); }
.hero-stats b { font-size: 1.4rem; line-height: 1.2; font-variant-numeric: tabular-nums; }
.hero-stats span { font-size: .72rem; color: var(--mute); }
.hero-stats .rank-pill { align-self: center; margin-inline-start: auto; }
.dial { display: flex; flex-direction: column; }

.res-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 14px; }
.res-actions .go { grid-column: 1 / -1; width: 100%; }

.racing .tabs { display: none; }
.racing { padding-bottom: 24px; }
