/* tt: interface. One type scale, flat surfaces, hairline borders, and no
 * decoration that competes with the text you are trying to read. */


/* ---- info dot ---------------------------------------------------------- */
.info {
  display: inline-grid;
  place-items: center;
  width: 15px; height: 15px;
  flex: none;
  border-radius: 50%;
  border: 1px solid var(--sub);
  color: var(--dim);
  font-size: 9.5px;
  font-weight: 700;
  font-style: normal;
  cursor: help;
  position: relative;
  vertical-align: -2px;
  transition: color var(--t), border-color var(--t);
}
.info:hover, .info:focus-visible { color: var(--text); border-color: var(--dim); outline: none; }
.tip {
  position: fixed;
  z-index: 300;
  max-width: min(300px, calc(100vw - 24px));
  padding: 9px 12px;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--sub);
  border-radius: var(--r);
  font-size: var(--fs-sm);
  line-height: 1.55;
  text-align: left;
  pointer-events: none;
  box-shadow: var(--shadow-lift);
  opacity: 0;
  transform: translateY(3px);
  transition: opacity 110ms ease, transform 110ms ease;
}
.tip.is-on { opacity: 1; transform: none; }

/* ---- config bar -------------------------------------------------------- */
.configbar {
  background: transparent;
  border: none;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: var(--sp-1);
  padding: 6px var(--sp-3);
  margin: var(--sp-2) auto 0;
  max-width: 100%;
  user-select: none;
}
.cfg-group { display: flex; align-items: center; gap: 1px; }
.cfg-sep { width: 1px; height: 18px; background: var(--sub); margin: 0 var(--sp-2); }
.cfg-label {
  font-size: var(--fs-xs);
  letter-spacing: var(--track);
  text-transform: uppercase;
  color: var(--dim);
  padding: 0 var(--sp-1);
}
.cfg-btn { padding: 5px 10px; }

.cfg-input {
  padding: 5px 8px;
  border-radius: var(--r-sm);
  background: var(--bg);
  border: 1px solid var(--sub);
  color: var(--text);
  font-size: var(--fs-sm);
  transition: border-color var(--t);
}
.cfg-input { width: 84px; font-family: var(--font); }
.cfg-input::placeholder { color: var(--dim); }
.cfg-input:focus { border-color: var(--accent); }

/* ---- typing surface ---------------------------------------------------- */
.typing {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: var(--sp-3);
  position: relative;
  padding: var(--sp-2) 0 var(--sp-6);
}

.hud {
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  min-height: 32px;
  font-variant-numeric: tabular-nums;
}
.hud-main {
  font-family: var(--font);
  font-size: 28px;
  line-height: 1;
  letter-spacing: -.02em;
  color: var(--accent);
}
.hud-item { font-size: var(--fs-sm); color: var(--dim); display: flex; gap: 5px; align-items: baseline; }
.hud-item b { color: var(--text); font-weight: 500; font-family: var(--font); }
.hud-bar {
  flex: 1; height: 3px; max-width: 260px; margin-left: auto;
  background: var(--sub); border-radius: 2px; overflow: hidden;
}
.hud-bar > i { display: block; height: 100%; background: var(--accent); width: 0; transition: width 90ms linear; }

.words-wrap {
  position: relative;
  overflow: hidden;
  max-height: calc(var(--row) * 3);
  min-height: calc(var(--row) * 3);
  cursor: text;
}
.words {
  font-family: var(--font);
  font-size: var(--size);
  line-height: var(--line);
  color: var(--untyped);
  display: flex;
  flex-wrap: wrap;
  will-change: transform;
  transition: transform 140ms cubic-bezier(.4, 0, .2, 1);
  user-select: none;
}
.words.no-anim { transition: none; }

.w { display: inline-flex; border-bottom: 2px solid transparent; margin: 0 .32em 0 0; }
.w.bad { border-bottom-color: color-mix(in srgb, var(--error) 62%, transparent); }
.c { display: inline-block; white-space: pre; }
.c.ok { color: var(--accent); }
.c.no { color: var(--error); }
.c.extra { color: var(--error-extra); }

.caret {
  position: absolute;
  width: 2.5px;
  border-radius: 2px;
  background: var(--caret);
  top: 0; left: 0;
  transform: translate(0, 0);
  transition: transform 70ms cubic-bezier(.4, 0, .2, 1);
  will-change: transform;
  pointer-events: none;
}
.caret.blink { animation: caretBlink 1s steps(1) infinite; }
.caret.block { opacity: .4; }
@keyframes caretBlink { 0%, 49% { opacity: 1; } 50%, 100% { opacity: 0; } }

.typing.shake .words-wrap { animation: nudge 110ms ease-out; }
@keyframes nudge { 0% { transform: translateX(0); } 33% { transform: translateX(-4px); } 66% { transform: translateX(3px); } 100% { transform: translateX(0); } }

.stage-foot {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-4);
  min-height: 26px;
  flex-wrap: wrap;
  font-size: var(--fs-sm);
  color: var(--dim);
}
.chip { display: inline-flex; align-items: center; gap: 6px; }
.chip .k { color: var(--dim); }
.chip b { color: var(--text); font-family: var(--font); font-weight: 500; }
.chip.accent b { color: var(--accent); }
.key-hint {
  font-family: var(--font);
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--sub);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: var(--fs-xs);
}
.text-btn { padding: 6px 13px; }

/* ---- results ----------------------------------------------------------- */
.results {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: var(--sp-2) 2px var(--sp-6);
  animation: fadeUp 180ms ease-out;
}
@keyframes fadeUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.res-top { display: flex; align-items: flex-start; gap: var(--sp-5); flex-wrap: wrap; }
.res-headline { display: flex; gap: var(--sp-6); align-items: flex-start; flex-wrap: wrap; }
.res-big { min-width: 96px; }
.res-big .k {
  font-size: var(--fs-xs); letter-spacing: var(--track);
  text-transform: uppercase; color: var(--dim); font-weight: 600;
}
.res-big .v {
  font-family: var(--font);
  font-size: clamp(36px, 5.6vw, 52px);
  line-height: 1.08;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  letter-spacing: -.03em;
}
.res-big .v small { font-size: .40em; color: var(--dim); margin-left: 3px; letter-spacing: 0; }
.res-big.muted .v { color: var(--text); font-size: clamp(28px, 4.2vw, 40px); }

.res-grade {
  display: grid; place-items: center;
  width: 66px; height: 66px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  font-family: var(--font); font-size: 24px; font-weight: 700;
  color: var(--accent);
}
.res-score { font-size: var(--fs-sm); color: var(--dim); text-align: center; margin-top: 7px; }
.res-score b { color: var(--text); font-size: var(--fs-lg); font-family: var(--font); }

.res-chartwrap { margin: var(--sp-5) 0 var(--sp-3); padding: var(--sp-4) var(--sp-4) var(--sp-2); }

.res-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: var(--sp-2);
}
.res-cell { padding: 10px 12px; }
.res-cell .k {
  font-size: var(--fs-xs); letter-spacing: .04em; color: var(--dim);
  display: flex; align-items: center; gap: 5px; justify-content: space-between;
}
.res-cell .v {
  font-family: var(--font); font-size: var(--fs-lg); color: var(--text);
  font-variant-numeric: tabular-nums; margin-top: 3px;
}

.res-section-title {
  font-size: var(--fs-xs); letter-spacing: var(--track); text-transform: uppercase;
  color: var(--dim); font-weight: 600;
  margin: var(--sp-6) 0 var(--sp-3);
  padding-bottom: var(--sp-2);
  border-bottom: 1px solid var(--sub);
  display: flex; align-items: center; gap: 7px;
}
.res-flags { display: flex; gap: 7px; flex-wrap: wrap; margin-top: var(--sp-3); }
.flag {
  font-size: var(--fs-sm); padding: 3px 10px; border-radius: 20px;
  border: 1px solid var(--sub); color: var(--dim);
}
.flag.bad { border-color: color-mix(in srgb, var(--error) 45%, transparent); color: var(--error); }
.flag.good { border-color: color-mix(in srgb, var(--accent) 45%, transparent); color: var(--accent); }

.res-actions { display: flex; gap: var(--sp-2); flex-wrap: wrap; margin-top: var(--sp-5); align-items: center; }

.bars { display: flex; flex-direction: column; gap: 5px; }
.bar-row { display: grid; grid-template-columns: 92px 1fr 72px; gap: var(--sp-3); align-items: center; font-size: var(--fs-sm); }
.bar-row .lbl { color: var(--dim); }
.bar-row .track { height: 6px; border-radius: 3px; overflow: hidden; background: var(--sub); }
.bar-row .fill { height: 100%; background: var(--accent); border-radius: 3px; }
.bar-row .fill.bad { background: var(--error); }
.bar-row .num { font-family: var(--font); color: var(--text); text-align: right; font-variant-numeric: tabular-nums; }

.keytiles { display: flex; flex-wrap: wrap; gap: 5px; }
.keytile {
  font-family: var(--font); font-size: var(--fs-md); font-weight: 500;
  min-width: 34px; padding: 6px 8px; text-align: center;
  background: var(--panel); border: 1px solid var(--sub); border-radius: var(--r-sm);
  color: var(--text);
}
.keytile small {
  display: block; font-size: 9.5px; font-weight: 500;
  color: var(--dim); font-family: var(--ui-font); margin-top: 2px;
}

/* ---- settings dialog --------------------------------------------------- */
.panel {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  /* floors keep the dialog usable even if a host reports an odd viewport */
  width: min(600px, calc(100vw - 28px));
  min-width: min(320px, 100%);
  max-height: min(84vh, 780px);
  min-height: min(240px, 100%);
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--sub);
  border-radius: var(--r-lg);
  z-index: 60;
  overflow: hidden;
  box-shadow: var(--shadow-lift);
  animation: dialogIn 150ms cubic-bezier(.4, 0, .2, 1);
}
@keyframes dialogIn {
  from { opacity: 0; transform: translate(-50%, -50%) scale(.97); }
  to { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

.panel-head {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-3) var(--sp-3) var(--sp-3) var(--sp-5);
  border-bottom: 1px solid var(--sub);
  background: var(--panel);
}
.panel-head h2 { margin: 0; font-size: var(--fs-lg); font-weight: 600; letter-spacing: -.01em; }
.panel-close {
  width: 34px; height: 34px;
  padding: 0;
  justify-content: center;
  color: var(--text);
  background: var(--hover);
}
.panel-close:hover { background: var(--tint-strong); color: var(--text); }
.panel-close svg { display: block; }

.panel-body { flex: 1; min-height: 0; overflow-y: auto; padding-bottom: var(--sp-5); }

.panel h3 {
  font-size: var(--fs-xs); letter-spacing: var(--track); text-transform: uppercase;
  color: var(--dim); font-weight: 600;
  margin: 0;
  padding: var(--sp-5) var(--sp-5) var(--sp-2);
  display: flex; align-items: center; gap: 6px;
}

/* every setting is one row: label on the left, control on the right */
.field, .field-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-4);
  padding: 10px var(--sp-5);
  margin: 0;
  min-height: 44px;
  border-top: 1px solid color-mix(in srgb, var(--sub) 55%, transparent);
}
.field > label, .field-row .lbl {
  display: flex; align-items: center; gap: 6px;
  font-size: var(--fs-md); color: var(--text); margin: 0;
  flex: 1; min-width: 0;
}
.field > .select, .field > .range, .field > .textin { flex: 0 0 190px; }
.field.stack { flex-direction: column; align-items: stretch; gap: var(--sp-2); }
.field.stack > label { flex: none; }
.field.stack > .select, .field.stack > .segmented, .field.stack > .range { flex: none; width: 100%; }
.field-hint { font-size: var(--fs-sm); color: var(--dim); padding: 0 var(--sp-5) var(--sp-3); line-height: 1.6; }

.select, .textin {
  width: 100%;
  padding: 7px 10px;
  border-radius: var(--r-sm);
  background: var(--bg);
  border: 1px solid var(--sub);
  color: var(--text);
  font-size: var(--fs-sm);
  transition: border-color var(--t);
}
.select:focus, .textin:focus { border-color: var(--accent); }
.select option { background: var(--panel); }
.textin { font-family: var(--font); }
textarea.textin { min-height: 90px; resize: vertical; }

.swatches { display: flex; flex-wrap: wrap; gap: 7px; padding: 0 var(--sp-5) var(--sp-4); }
.swatch {
  width: 26px; height: 26px; border-radius: 50%;
  border: 2px solid transparent;
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--text) 18%, transparent);
  transition: transform var(--t), border-color var(--t);
  padding: 0;
}
.swatch:hover { transform: scale(1.1); }
.swatch.is-on { border-color: var(--text); }

.theme-list {
  display: grid; grid-template-columns: 1fr 1fr; gap: 5px;
  padding: 0 var(--sp-5) var(--sp-4);
}
.theme-item {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px;
  font-size: var(--fs-sm);
  color: var(--dim);
  background: transparent;
  border: 1px solid var(--sub);
  border-radius: var(--r-sm);
  transition: color var(--t), border-color var(--t), background var(--t);
}
.theme-item:hover { color: var(--text); background: var(--hover); }
.theme-item.is-on { color: var(--accent); border-color: var(--accent); background: var(--tint); }
.theme-dots { display: flex; gap: 3px; flex: none; }
.theme-dot { width: 9px; height: 9px; border-radius: 50%; box-shadow: inset 0 0 0 1px rgba(128,128,128,.4); }

.toggle {
  position: relative; width: 38px; height: 22px; border-radius: 11px; flex: none;
  background: var(--sub);
  transition: background var(--t);
  padding: 0;
  cursor: pointer;
}
.toggle::after {
  content: ''; position: absolute; top: 3px; left: 3px;
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--dim);
  transition: transform var(--t), background var(--t);
}
.toggle.is-on { background: var(--tint-strong); }
.toggle.is-on::after { transform: translateX(16px); background: var(--accent); }

.segmented {
  display: flex; gap: 2px; width: 100%;
  background: var(--bg); border: 1px solid var(--sub);
  border-radius: var(--r-sm); padding: 2px;
}
.segmented button { flex: 1 1 0; min-width: 0; justify-content: center; padding: 6px 6px; font-size: var(--fs-sm); }

.range { accent-color: var(--accent); width: 100%; }
.field.stack > label { justify-content: space-between; }
.lbl-value { font-family: var(--font); color: var(--dim); font-size: var(--fs-sm); }
.panel-actions {
  display: flex; gap: var(--sp-2); flex-wrap: wrap;
  padding: var(--sp-3) var(--sp-5);
  border-top: 1px solid color-mix(in srgb, var(--sub) 55%, transparent);
}

/* ---- learn view -------------------------------------------------------- */

.lesson-picker { display: grid; grid-template-columns: repeat(auto-fill, minmax(238px, 1fr)); gap: var(--sp-3); }
.unit-card { padding: var(--sp-4); }
.unit-card h4 { margin: 0 0 2px; font-size: var(--fs-md); font-weight: 600; }
.unit-card p { margin: 0 0 var(--sp-3); font-size: var(--fs-sm); color: var(--dim); line-height: 1.55; }
.lesson-row { width: 100%; text-align: left; padding: 6px 8px; margin-bottom: 2px; }
.lesson-row .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--sub); flex: none; }
.lesson-row .dot.pass { background: var(--accent); }
.lesson-row .dot.part { background: var(--dim); }
.lesson-row .meta { margin-left: auto; font-family: var(--font); font-size: var(--fs-xs); color: var(--dim); }

/* ---- stats view -------------------------------------------------------- */
.stats-row {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(146px, 1fr));
  gap: var(--sp-2); margin-bottom: var(--sp-5);
}
.hist-table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.hist-table th {
  text-align: left; font-weight: 600; color: var(--dim); font-size: var(--fs-xs);
  letter-spacing: var(--track); text-transform: uppercase;
  padding: 8px 10px; position: sticky; top: 0; background: var(--bg);
  border-bottom: 1px solid var(--sub);
}
.hist-table td {
  padding: 7px 10px; border-top: 1px solid color-mix(in srgb, var(--sub) 60%, transparent);
  font-family: var(--font); font-variant-numeric: tabular-nums; color: var(--text);
}
.hist-table tr:hover td { background: var(--hover); }
.hist-table td.dimc { color: var(--dim); font-family: var(--ui-font); }
.empty { color: var(--dim); font-size: var(--fs-md); padding: var(--sp-6) 0; text-align: center; }

.heat { display: flex; flex-wrap: wrap; gap: 4px; }
.heat-key {
  font-family: var(--font); font-size: var(--fs-md); font-weight: 500;
  width: 38px; padding: 7px 0; text-align: center;
  color: var(--text);
}
.heat-key small { display: block; font-size: 9px; color: var(--dim); font-family: var(--ui-font); }

@media (max-width: 720px) {
  :root { --size-user: 22px; --kb-height: clamp(140px, 34vh, 300px); }
  .stage { padding: 0 var(--sp-3); }
  .res-headline { gap: var(--sp-4); }
  .theme-list { grid-template-columns: 1fr; }
  .hud-bar { display: none; }
  .topbar { padding: var(--sp-2) var(--sp-3); gap: var(--sp-2); }
  .field, .field-row, .panel h3, .swatches, .theme-list, .field-hint { padding-left: var(--sp-4); padding-right: var(--sp-4); }
}

/* ---- themed select ----------------------------------------------------- */
.sel {
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-2);
  padding: 6px 9px;
  border-radius: var(--r-sm);
  background: var(--bg);
  border: 1px solid var(--sub);
  color: var(--text);
  font-size: var(--fs-sm);
  line-height: 1.4;
  cursor: pointer;
  transition: border-color var(--t), color var(--t);
  text-align: left;
}
.sel:hover { border-color: var(--dim); }
.sel:focus-visible { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px var(--tint-strong); }
.sel[aria-expanded="true"] { border-color: var(--accent); }
.sel-value { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sel-arrow { color: var(--dim); font-size: 10px; flex: none; }
.cfg-sel { max-width: 160px; }
.cfg-sel-wide { max-width: 230px; }
.field > .sel.select { flex: 0 0 190px; width: 190px; }
.field.stack > .sel.select { flex: none; width: 100%; }

.sel-menu {
  position: fixed;
  z-index: 200;
  display: flex;
  flex-direction: column;
  padding: 4px;
  gap: 1px;
  background: var(--panel);
  border: 1px solid var(--sub);
  border-radius: var(--r);
  box-shadow: var(--shadow-lift);
  overflow-y: auto;
  animation: selIn 90ms ease-out;
}
@keyframes selIn { from { opacity: 0; transform: translateY(-3px); } to { opacity: 1; transform: none; } }
.sel-opt {
  display: flex;
  align-items: center;
  padding: 7px 10px;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--text);
  font-size: var(--fs-sm);
  text-align: left;
  white-space: nowrap;
  transition: background var(--t), color var(--t);
}
.sel-opt:hover, .sel-opt:focus-visible { background: var(--hover); outline: none; }
.sel-opt.is-on { color: var(--accent); background: var(--tint); }
.sel-opt.is-on { font-weight: 600; }
.sel-opt:disabled { opacity: .4; cursor: default; }

/* ---- toast ------------------------------------------------------------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translate(-50%, 12px);
  padding: 10px 16px;
  background: var(--panel);
  border: 1px solid var(--sub);
  border-radius: var(--r);
  color: var(--text);
  font-size: var(--fs-sm);
  box-shadow: var(--shadow-lift);
  opacity: 0;
  pointer-events: none;
  transition: opacity 140ms ease, transform 140ms ease;
  z-index: 300;
  max-width: min(520px, 90vw);
  text-align: center;
}
.toast.is-on { opacity: 1; transform: translate(-50%, 0); }
.toast.bad { border-color: var(--error); color: var(--error); }

/* the custom colour well, opened with the system eyedropper */
.swatch-custom {
  display: grid;
  place-items: center;
  position: relative;
  background: var(--bg);
  border: 1px solid var(--sub) !important;
  color: var(--dim);
  overflow: hidden;
}
.swatch-custom:hover { color: var(--text); }
.swatch-custom svg { width: 15px; height: 15px; display: block; pointer-events: none; }
.swatch-custom input {
  position: absolute; inset: 0;
  opacity: 0; cursor: pointer; padding: 0; border: 0;
}
.swatch-custom.is-on { border-color: var(--text) !important; }

.panel-field { padding: 0 var(--sp-5) var(--sp-2); }
.code-box { font-size: var(--fs-xs); line-height: 1.5; word-break: break-all; min-height: 68px; }

.stat-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: var(--sp-2);
  margin-bottom: var(--sp-4);
}
.stat-big { padding: var(--sp-3) var(--sp-4); background: var(--panel); border: 1px solid var(--sub); border-radius: var(--r); }
.stat-big .k { font-size: var(--fs-xs); letter-spacing: var(--track); text-transform: uppercase; color: var(--dim); font-weight: 600; }
.stat-big .v { font-family: var(--font); font-size: 30px; line-height: 1.15; color: var(--accent); font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.stat-big .sub { font-size: var(--fs-sm); color: var(--dim); }
.chart-caption { font-size: var(--fs-sm); color: var(--dim); margin-top: var(--sp-2); }
.stats-more { margin-top: var(--sp-4); }

/* ---- stage foot: one quiet line, everything the same size --------------- */
.stage-foot { font-size: var(--fs-sm); line-height: 1.5; }
.foot-bit { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.foot-k { color: var(--dim); font-weight: 400; }
.foot-v { color: var(--text); font-family: var(--font); font-weight: 500; }
.foot-bit.accent .foot-v { color: var(--accent); }
.foot-dot { color: var(--sub); user-select: none; }
.stage-foot .key-hint { font-size: var(--fs-sm); padding: 0 5px; }

/* ---- fitting every screen ----------------------------------------------
   Height is the scarce dimension, not width: a phone in landscape has less
   vertical room than a phone upright, so the breakpoints key off height as
   well as width. */

/* tablets and small laptops */
@media (max-width: 1000px) {
  .res-grid { grid-template-columns: repeat(auto-fit, minmax(118px, 1fr)); }
  .stat-strip { grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); }
}

/* phones upright */
@media (max-width: 560px) {
  :root { --size-user: 20px; }
  .topbar { padding: var(--sp-2) var(--sp-3); }
  .tabs { margin-left: 0; }
  .tab { padding: 6px 10px; }
  .configbar { gap: 3px; padding: 4px var(--sp-2); }
  .cfg-btn { padding: 5px 8px; }
  .cfg-sep { margin: 0 var(--sp-1); }
  .cfg-input { width: 68px; }
  .cfg-sel, .cfg-sel-wide { max-width: 128px; }
  .res-headline { gap: var(--sp-3); }
  .res-big { min-width: 78px; }
  .stage-foot { gap: var(--sp-2); font-size: var(--fs-xs); }
  .panel { width: 100vw; }
  .hist-table { font-size: var(--fs-xs); }
}

/* short viewports: two lines of text instead of three */
@media (max-height: 640px) {
  :root { --kb-height: clamp(104px, 28vh, 200px); }
  .words-wrap { max-height: calc(var(--row) * 2); min-height: calc(var(--row) * 2); }
  .topbar { padding: 6px var(--sp-4); }
  .hud { min-height: 26px; }
  .hud-main { font-size: 22px; }
  .typing { gap: var(--sp-2); padding-bottom: var(--sp-5); }
}

/* phones on their side: almost no height at all */
@media (max-height: 470px) {
  :root { --size-user: 17px; }
  .keyboard-area { display: none; }
  .brand { display: none; }
  .configbar { margin-top: 0; }
  .stage-foot { display: none; }
  .hud-main { font-size: 18px; }
  .typing { padding-bottom: var(--sp-2); }
}

/* pointer-less devices get bigger hit targets */
@media (pointer: coarse) {
  .cfg-btn, .tab, .text-btn, .sel-opt { padding-top: 9px; padding-bottom: 9px; }
  .icon-btn { width: 40px; height: 40px; }
  .swatch { width: 32px; height: 32px; }
}

/* big screens: hold the measure so the eye does not have to travel */
@media (min-width: 1500px) {
  :root { --size-user: 34px; }
  .stage { padding: 0 clamp(64px, 10vw, 220px); }
  .kb { max-width: 1320px; }
}
@media (min-width: 2200px) {
  :root { --size-user: 40px; --fs-md: 15px; --fs-sm: 13.5px; }
  .stage { padding: 0 clamp(120px, 16vw, 420px); }
}

/* explanations can run to several lines and hold their own layout */
.tip { white-space: pre-line; max-width: min(460px, calc(100vw - 24px)); font-size: var(--fs-sm); line-height: 1.6; }

/* ---- custom theme editor ----------------------------------------------- */
.custom-theme { padding: 0 var(--sp-5) var(--sp-2); }
.wells { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 6px; margin-bottom: var(--sp-3); }
.well {
  position: relative;
  display: flex; align-items: center; gap: 8px;
  padding: 7px 10px;
  border: 1px solid var(--sub);
  border-radius: var(--r-sm);
  font-size: var(--fs-sm);
  color: var(--text);
  cursor: pointer;
  transition: border-color var(--t);
}
.well:hover { border-color: var(--dim); }
.well-dot { width: 16px; height: 16px; border-radius: 4px; flex: none; box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--text) 22%, transparent); }
.well-label { color: var(--dim); }
.well input { position: absolute; inset: 0; opacity: 0; cursor: pointer; padding: 0; border: 0; }
.custom-theme .field.stack { padding-left: 0; padding-right: 0; border-top: none; }
.custom-theme .panel-actions { padding-left: 0; padding-right: 0; border-top: none; }

/* ---- config bar: a fixed anchor, then whatever the mode needs ----------- */
/* Three columns with equal outer tracks: the picker sits dead centre and
   stays there no matter how wide the mode's own options are. */
.configbar.cfg-grid {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  margin: var(--sp-2) 0 0;
  gap: 0;
}
.cfg-spacer { display: none; }
.cfg-modes { flex: none; display: flex; align-items: center; gap: 1px; }
.cfg-pipe { color: var(--sub); user-select: none; padding: 0 var(--sp-3); flex: none; }
.cfg-tail { display: flex; align-items: center; min-width: 0; }
.cfg-rest {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--sp-1) var(--sp-2);
  /* a slot of constant width: the options inside it change, the picker beside
     it does not move */
  width: 820px;
  max-width: 100%;
}

@media (max-width: 1180px) {
  .configbar.cfg-grid { flex-wrap: wrap; margin: var(--sp-2) auto 0; }
  .cfg-rest { width: auto; justify-content: center; }
  .cfg-pipe { padding: 0 var(--sp-2); }
}

/* lesson navigation reads as a pair of buttons, not bare glyphs */
.cfg-nav {
  width: 30px; height: 30px;
  padding: 0;
  justify-content: center;
  border: 1px solid var(--sub);
  color: var(--text);
}
.cfg-nav:hover { border-color: var(--dim); background: var(--hover); }
.cfg-nav svg { display: block; }
.cfg-nav.is-disabled { opacity: .35; cursor: default; }
.cfg-nav.is-disabled:hover { background: transparent; border-color: var(--sub); }

/* an outlined button, so it reads as a control rather than a link */
.cfg-outline { border: 1px solid var(--sub); color: var(--text); }
.cfg-outline:hover { border-color: var(--dim); background: var(--hover); }
.cfg-outline.is-on { border-color: var(--accent); color: var(--accent); background: var(--tint); }
.cfg-group > .cfg-nav + .sel { margin-left: 5px; }
.cfg-group > .sel + .cfg-nav { margin-left: 5px; }

.chart-empty {
  display: grid; place-items: center;
  min-height: 180px;
  color: var(--dim);
  font-size: var(--fs-md);
  border: 1px dashed var(--sub);
  border-radius: var(--r);
}

/* the curriculum dialog is wider than settings: it holds nine unit cards */
.panel:has(.lesson-picker) { width: min(880px, calc(100vw - 28px)); }
.lesson-picker { padding: var(--sp-4) var(--sp-5) var(--sp-5); }

/* ---- credit ------------------------------------------------------------ */
.credit {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  flex-wrap: wrap;
  padding: var(--sp-4) var(--sp-5) var(--sp-2);
}
.credit-by { font-size: var(--fs-sm); color: var(--dim); margin-right: auto; }
.credit-link {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 11px;
  border: 1px solid var(--sub);
  border-radius: var(--r-sm);
  color: var(--text);
  font-size: var(--fs-sm);
  font-weight: 500;
  text-decoration: none;
  transition: border-color var(--t), background var(--t), color var(--t);
}
.credit-link:hover { border-color: var(--accent); color: var(--accent); background: var(--tint); text-decoration: none; }
.credit-link svg { display: block; flex: none; }

/* ---- posture primer ----------------------------------------------------- */
.primer { padding: var(--sp-4) var(--sp-5) var(--sp-2); display: flex; flex-direction: column; gap: var(--sp-4); }
.primer-step { display: flex; gap: var(--sp-3); align-items: flex-start; }
.primer-n {
  flex: none;
  width: 26px; height: 26px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--tint);
  color: var(--accent);
  font-family: var(--font);
  font-size: var(--fs-sm);
  font-weight: 700;
}
.primer-step h4 { margin: 2px 0 4px; font-size: var(--fs-md); font-weight: 600; }
.primer-step p { margin: 0; font-size: var(--fs-sm); color: var(--dim); line-height: 1.6; }

/* the credit links are icon only; the name lives in the tooltip */
.credit-link { width: 34px; height: 34px; padding: 0; justify-content: center; gap: 0; }
.credit-by b { color: var(--text); font-weight: 700; }

/* ---- dialog copy -------------------------------------------------------- */
.dialog-copy { padding: 0 var(--sp-5) var(--sp-3); color: var(--dim); font-size: var(--fs-sm); line-height: 1.6; margin: 0; }
.panel-field textarea.textin { min-height: 150px; }

/* ---- command palette ---------------------------------------------------- */
.palette-search {
  position: sticky;
  top: 0;
  z-index: 2;
  padding: var(--sp-3) var(--sp-5);
  background: var(--panel);
  border-bottom: 1px solid var(--sub);
}
.palette-input { font-family: var(--ui-font); font-size: var(--fs-md); }
.palette-list {
  display: flex;
  flex-direction: column;
  padding: var(--sp-2) var(--sp-3);
  gap: 1px;
  max-height: 52vh;
  overflow-y: auto;
}
.palette-row {
  display: flex;
  align-items: baseline;
  gap: var(--sp-3);
  width: 100%;
  padding: 8px 10px;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--text);
  font-size: var(--fs-sm);
  text-align: left;
  border: none;
  cursor: pointer;
}
.palette-row.is-active { background: var(--tint); color: var(--accent); }
.palette-group {
  flex: none;
  width: 104px;
  font-size: var(--fs-xs);
  letter-spacing: var(--track);
  text-transform: uppercase;
  color: var(--dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.palette-row.is-active .palette-group { color: var(--accent); }
.palette-label { flex: 1; min-width: 0; }
.palette-hint { flex: none; font-family: var(--font); font-size: var(--fs-xs); color: var(--dim); }
@media (max-width: 560px) { .palette-group { width: 66px; } }

.chart-slot { width: 100%; min-height: 40px; }
.chart-slot svg { display: block; }
