/* monkeystyping - a dark, warm, terminal-ish palette that matches the colour
   ramp the Rust renderer uses for the troop. */

:root {
  --bg: #100e0c;
  --panel: #191614;
  --panel-2: #211d1a;
  --line: #332c26;
  --ink: #efe6dc;
  --ink-dim: #a2948a;
  --ink-faint: #6f645c;
  --amber: #e8922c;
  --amber-bright: #ffc861;
  --hot: #fff4dd;
  --good: #7fc98a;
  --bad: #d9695f;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--amber-bright); }

/* ---- masthead ---------------------------------------------------- */

.masthead {
  text-align: center;
  padding: 2.6rem 1rem 1.4rem;
  border-bottom: 1px solid var(--line);
  background: radial-gradient(ellipse at 50% -40%, #2b211a 0%, var(--bg) 65%);
}
.masthead h1 {
  margin: 0;
  font-family: var(--mono);
  font-size: clamp(2rem, 6vw, 3.2rem);
  letter-spacing: -0.04em;
  font-weight: 700;
  color: var(--hot);
}
.masthead h1 span { color: var(--amber); }
.tagline { margin: .4rem 0 0; color: var(--ink-dim); }

.boot { text-align: center; padding: 4rem 1rem; color: var(--ink-dim); font-family: var(--mono); }

main {
  max-width: 1180px;
  margin: 0 auto;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

/* ---- panels ------------------------------------------------------ */

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1.25rem 1.4rem 1.5rem;
}
.panel h2 {
  margin: 0 0 .2rem;
  font-size: 1.15rem;
  font-weight: 650;
  letter-spacing: -0.01em;
}
.panel h3 {
  margin: 1.4rem 0 .3rem;
  font-size: .82rem;
  text-transform: uppercase;
  letter-spacing: .09em;
  color: var(--ink-dim);
  font-weight: 600;
}
.hint { margin: .25rem 0 .9rem; color: var(--ink-dim); font-size: .88rem; max-width: 62ch; }
.note { color: var(--amber); font-size: .84rem; font-family: var(--mono); }
.error {
  background: #3a1d1a; border: 1px solid #6d3129; color: #ffd8d2;
  padding: .7rem 1rem; border-radius: 9px; font-size: .9rem; margin: 0;
}

/* ---- the verdict ------------------------------------------------- */

.verdict {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr);
  gap: 1.5rem;
  align-items: center;
  background: linear-gradient(160deg, #241b14, var(--panel) 60%);
}
.verdict-label {
  margin: 0; font-size: .75rem; letter-spacing: .12em;
  text-transform: uppercase; color: var(--ink-faint);
}
.verdict-number {
  margin: .15rem 0 .1rem;
  font-family: var(--mono);
  font-size: clamp(1.5rem, 4.2vw, 2.5rem);
  line-height: 1.15;
  color: var(--amber-bright);
  font-weight: 600;
  overflow-wrap: anywhere;
}
.verdict-sub { margin: 0; color: var(--ink-dim); font-size: .9rem; }
.verdict-side {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .8rem 1rem;
}
.stat span {
  display: block; font-family: var(--mono); font-size: 1.05rem; color: var(--ink);
  overflow-wrap: anywhere;
}
.stat label {
  display: block; font-size: .7rem; letter-spacing: .07em;
  text-transform: uppercase; color: var(--ink-faint);
}

/* ---- controls ---------------------------------------------------- */

.controls { display: flex; flex-direction: column; gap: 1.1rem; }
.phrase-group > label {
  display: block; font-size: .75rem; letter-spacing: .1em;
  text-transform: uppercase; color: var(--ink-faint); margin-bottom: .4rem;
}
#phrase {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--hot);
  font-family: var(--mono);
  font-size: 1.05rem;
  padding: .65rem .8rem;
}
#phrase:focus { outline: 2px solid var(--amber); border-color: transparent; }

.presets { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .6rem; }
.presets button {
  background: var(--panel-2); border: 1px solid var(--line); color: var(--ink-dim);
  border-radius: 999px; padding: .28rem .7rem; font-size: .8rem;
  font-family: var(--mono); cursor: pointer;
}
.presets button:hover { border-color: var(--amber); color: var(--amber-bright); }

.control-columns {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 1rem;
}
fieldset {
  border: 1px solid var(--line); border-radius: 10px;
  padding: .6rem .9rem 1rem; margin: 0; min-width: 0;
}
legend {
  font-size: .7rem; letter-spacing: .12em; text-transform: uppercase;
  color: var(--ink-faint); padding: 0 .4rem;
}
.slider, .select { display: block; margin: .65rem 0; }
.slider > span, .select > span {
  display: flex; justify-content: space-between; gap: .5rem;
  font-size: .82rem; color: var(--ink-dim); margin-bottom: .25rem;
}
.slider output { font-family: var(--mono); color: var(--amber-bright); }
input[type=range] { width: 100%; accent-color: var(--amber); }
select {
  width: 100%; background: var(--bg); color: var(--ink);
  border: 1px solid var(--line); border-radius: 7px; padding: .4rem .5rem;
  font-family: var(--mono); font-size: .85rem;
}
.two-handed-only { display: none; }
.strike-params.two-handed .two-handed-only { display: block; }
.check { display: flex; align-items: center; gap: .5rem; font-size: .85rem; color: var(--ink-dim); margin-top: .8rem; }
.buttons { display: flex; gap: .5rem; margin: .5rem 0 .9rem; }
button.primary, #restart {
  flex: 1; padding: .5rem .8rem; border-radius: 8px; cursor: pointer;
  font-family: var(--mono); font-size: .88rem;
  background: var(--panel-2); border: 1px solid var(--line); color: var(--ink);
}
button.primary { background: var(--amber); border-color: var(--amber); color: #241704; font-weight: 600; }
button:hover { filter: brightness(1.12); }

.readout { display: grid; grid-template-columns: auto 1fr; gap: .18rem .8rem; margin: 0; font-size: .84rem; }
.readout dt { color: var(--ink-faint); }
.readout dd { margin: 0; font-family: var(--mono); color: var(--ink); text-align: right; overflow-wrap: anywhere; }
.readout.inline { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); margin-top: 1rem; }
.readout.inline dt { grid-column: auto; }

/* ---- the troop canvas -------------------------------------------- */

.canvas-wrap {
  background: #0b0a09; border: 1px solid var(--line); border-radius: 10px;
  padding: 8px; display: flex; justify-content: center;
}
#troop-canvas {
  width: 100%; max-width: 760px; aspect-ratio: 1;
  image-rendering: pixelated;
  border-radius: 4px;
}
.best { margin-top: 1rem; }
.best-label, .best-note { margin: 0; font-size: .78rem; color: var(--ink-faint); }
.best-phrase {
  margin: .2rem 0; font-family: var(--mono); font-size: 1.25rem;
  letter-spacing: .02em; overflow-wrap: anywhere;
}
.best-phrase .got { color: var(--hot); background: rgba(232,146,44,.28); border-radius: 3px; }
.best-phrase .missing { color: var(--ink-faint); }

.histogram { display: flex; align-items: flex-end; gap: 2px; height: 54px; margin-top: 1rem; }
.histogram div { flex: 1; background: var(--amber); border-radius: 2px 2px 0 0; min-height: 1px; opacity: .85; }

.front-row { display: grid; gap: .3rem; }
.monkey {
  display: grid; grid-template-columns: 4.6rem 1fr auto; gap: .6rem;
  align-items: center; font-family: var(--mono); font-size: .78rem;
  background: var(--panel-2); border-radius: 6px; padding: .28rem .5rem;
}
.monkey .who { color: var(--ink-faint); }
.monkey .tape { color: var(--ink-dim); white-space: pre; overflow: hidden; text-overflow: clip; }
.monkey .wpm { color: var(--amber); font-size: .72rem; }

/* ---- maths ------------------------------------------------------- */

.two-col { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 1.6rem; }
.breakdown { display: flex; align-items: flex-end; gap: 2px; height: 96px; overflow-x: auto; padding-bottom: 1.3rem; }
.breakdown .col { display: flex; flex-direction: column; justify-content: flex-end; align-items: center; min-width: 15px; height: 100%; position: relative; }
.breakdown .bar { width: 11px; background: var(--amber); border-radius: 2px 2px 0 0; }
.breakdown .ch {
  position: absolute; bottom: -1.25rem; font-family: var(--mono);
  font-size: .7rem; color: var(--ink-dim);
}
.scale-table, .layout-table { width: 100%; border-collapse: collapse; font-size: .84rem; }
.scale-table td, .layout-table td, .layout-table th { padding: .32rem .4rem; border-bottom: 1px solid var(--line); text-align: right; }
.scale-table td:first-child, .layout-table td:first-child, .layout-table th:first-child { text-align: left; color: var(--ink-dim); }
.layout-table th { color: var(--ink-faint); font-weight: 600; font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; }
.scale-table td:last-child, .layout-table td:not(:first-child) { font-family: var(--mono); }
.layout-table tr.current { background: rgba(232,146,44,.10); }
.layout-table tr.current td:first-child { color: var(--amber-bright); }
.layout-table .win { color: var(--good); }

/* ---- keyboard heat map ------------------------------------------- */

.keyboard { width: 100%; overflow-x: auto; }
.keyboard svg { width: 100%; min-width: 560px; height: auto; display: block; }
.keyboard .cap { stroke: #0b0a09; stroke-width: .03; }
.keyboard .glyph { font-family: var(--mono); font-size: .34px; fill: var(--hot); text-anchor: middle; dominant-baseline: middle; pointer-events: none; }
.keyboard .glyph.small { font-size: .24px; fill: var(--ink-dim); }

.board { overflow-x: auto; margin: 1.1rem 0; }
.board svg { display: block; width: 100%; height: auto; min-width: 600px; border-radius: 12px; }

/* ---- the embedded paper ------------------------------------------ */

.paper {
  max-width: 74ch;
  margin: 0 auto;
  font-size: .95rem;
  line-height: 1.72;
  color: #ddd2c7;
}
.paper h1 { font-size: 1.6rem; line-height: 1.25; margin: .4rem 0 .2rem; color: var(--hot); letter-spacing: -.02em; }
.paper h2 {
  font-size: 1.12rem; margin: 2.4rem 0 .6rem; padding-top: 1.1rem;
  border-top: 1px solid var(--line); color: var(--amber-bright);
}
.paper h3 {
  font-size: .95rem; margin: 1.5rem 0 .3rem; color: var(--ink);
  text-transform: none; letter-spacing: 0;
}
.paper p { margin: .75rem 0; }
.paper strong { color: var(--hot); }
.paper em { color: var(--ink); }
.paper hr { border: 0; border-top: 1px solid var(--line); margin: 2rem 0; }
.paper ul, .paper ol { padding-left: 1.3rem; margin: .75rem 0; }
.paper li { margin: .35rem 0; }
.paper code {
  font-family: var(--mono); font-size: .87em;
  background: #0d0c0b; padding: .1em .35em; border-radius: 4px; color: var(--amber-bright);
}
.paper pre {
  background: #0d0c0b; border: 1px solid var(--line); border-radius: 8px;
  padding: .8rem 1rem; overflow-x: auto; margin: 1rem 0;
}
.paper pre code { background: none; padding: 0; color: var(--ink-dim); font-size: .82rem; line-height: 1.5; }
.paper table { width: 100%; border-collapse: collapse; font-size: .82rem; margin: 1rem 0; display: block; overflow-x: auto; }
.paper th, .paper td { padding: .3rem .55rem; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
.paper th:first-child, .paper td:first-child { text-align: left; white-space: normal; }
.paper th { color: var(--ink-faint); font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; }
.paper .byline { color: var(--ink-faint); font-size: .85rem; }

footer { color: var(--ink-faint); font-size: .82rem; text-align: center; padding: 1rem 0 2.5rem; }

@media (max-width: 720px) {
  .verdict { grid-template-columns: 1fr; }
}
