/* Lamplight whitewood shell. Phone first: a dark page, the table in the middle, a thin HUD on top. */

:root {
  color-scheme: dark;
  --bg: #0a0c11;
  --ink: #ece8dd;
  --dim: #a2a8b6;
  --line: rgba(255, 255, 255, 0.22);
  --chip: rgba(13, 16, 23, 0.58);
  --sheet: rgba(15, 18, 26, 0.93);
  --amber: #ffbf5e;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  /* Set by main.js on every layout. */
  --panel-left: 8px;
  --panel-top: 96px;
  --panel-width: 300px;
  --panel-max-height: 60vh;
}

*,
*::before,
*::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

[hidden] { display: none !important; }

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
  color: var(--ink);
  font: 13px/1.35 var(--font);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  touch-action: none;
}

/* A fixed body cannot rubber-band or pull to refresh. */
body { position: fixed; inset: 0; }

/* ---------------------------------------------------------------- table */

#stage {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px)
           env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
}

#fit {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

#column {
  position: relative;
  flex: none;
  width: 0;
  height: 0;
  background: #0d1017;
  container-type: inline-size;   /* main.js gives it its width; the practice line sizes its type by it */
}

#table {
  display: block;
  width: 100%;
  height: 100%;
}

/* Plunger power: a thin bar on the right edge, above where the thumb is. */
#meter {
  position: absolute;
  right: 2px;
  top: 44%;
  width: 6px;
  height: 30%;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.12);
  overflow: hidden;
  opacity: 0;
  transition: opacity 0.18s;
  pointer-events: none;
}
#meter.on { opacity: 1; transition-duration: 0.05s; }
#meter > i {
  position: absolute;
  inset: 0;
  background: var(--amber);
  transform: scaleY(0);
  transform-origin: 50% 100%;
}
#meter.full > i { background: #fff3d6; }

/* Messages sit on the apron: under the flippers, centred between them (main.js sets --toast-x),
   where the only thing to hide is a ball that has already drained. */
#toast {
  position: absolute;
  left: var(--toast-x, 50%);
  bottom: 1%;
  transform: translateX(-50%);
  max-width: var(--toast-max, 92%);
  padding: 5px 11px;
  border-radius: 999px;
  background: var(--chip);
  border: 1px solid var(--line);
  font-weight: 600;
  font-size: clamp(11px, 3.1vw, 12px);
  white-space: pre;              /* one line, and the spaces in it are kept */
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: 0;
  transition: opacity 0.35s;
  pointer-events: none;
}
#toast.show { opacity: 1; transition-duration: 0.06s; }
/* A message too long for the space under the flippers steps down in size (main.js measures). */
#toast[data-fit="small"] { font-size: 10px; padding: 5px 8px; letter-spacing: -0.01em; }
#toast[data-fit="smaller"] { font-size: 9px; padding: 5px 5px; letter-spacing: -0.02em; }
/* A small table (a short phone with Thumb room, a phone on its side) has an apron lower than the
   toast: there it is set flatter and at the very bottom, clear of the resting flipper tips
   (main.js measures the apron on every layout). */
#column[data-apron="low"] #toast { bottom: 1px; padding-top: 1px; padding-bottom: 1px; line-height: 1.2; }

/* Aim practice: which gate and flipper are lit, and how far along the run is. It stands in the
   upper playfield, inside the arch, where an aim practice table has nothing: far from the flippers
   and from the row of gates. Takes no touches. */
#drill {
  position: absolute;
  left: var(--toast-x, 50%);
  top: 12.5%;
  transform: translateX(-50%);
  width: max-content;
  max-width: 84%;
  text-align: center;
  font-size: clamp(10px, 3.3vw, 13px);
  font-size: clamp(10px, 5cqw, 13px);    /* by the table's own width, where the browser can (a phone on its side has a narrow table) */
  line-height: 1.45;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 1px 2px #000, 0 0 7px #000;
  pointer-events: none;
}
#drill > b { display: block; font-weight: 700; color: #ffe2ad; }
#drill > span { display: block; color: var(--dim); }
#drill > i { display: block; font-style: normal; color: var(--ink); }
#drill > i:empty { display: none; }
/* The whitewood's score and ball times mean nothing in a drill. */
#hud[data-drill] #score,
#hud[data-drill] #ballline,
#hud[data-drill] #times { display: none; }
/* On an aim practice the sheets are for reading figures: nothing shows through them (the results
   card can lie under the Stats panel, and words under either). */
#hud[data-drill] ~ .panel,
#hud[data-drill] ~ #results { background: #0f121a; }

/* Thumb room: where the thumbs go when the strip under the table is switched on. The whole
   screen takes touches as before; the pads only show the two halves. */
#thumbs {
  position: fixed;
  pointer-events: none;
}
#thumbs > i {
  position: absolute;
  top: 6px;
  bottom: 6px;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.11);
  background: rgba(255, 255, 255, 0.035);
}
#thumbs > i:first-child { left: 6px; width: calc(var(--split, 50%) - 9px); }
#thumbs > i:last-child { left: calc(var(--split, 50%) + 3px); right: 6px; }

/* ---------------------------------------------------------------- input */

#input {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  z-index: 1;
  touch-action: none;
  cursor: default;
}

/* ---------------------------------------------------------------- HUD */

/* main.js places the HUD and picks its mode on every layout. Nothing in it may cover play. */
#hud {
  position: fixed;
  z-index: 2;
  top: 0;
  left: 0;
  width: 100%;
  pointer-events: none;
}

#score,
#ballline,
#times {
  text-shadow: 0 1px 2px #000, 0 0 7px #000;
}

.score {
  font-weight: 700;
  font-size: clamp(18px, 5.6vw, 24px);
  line-height: 1.05;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
  white-space: nowrap;
}

.sub {
  font-size: 11px;
  line-height: 1.3;
  color: var(--dim);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.sub.strong { color: var(--ink); font-weight: 600; }

/* Phones: the buttons are one row above the table. The score (left) and the ball times (right)
   are plain text in the table's top corners, outside the arch, each line short enough to stay
   there. main.js fits the table under the bar (BAR_H there) and sets the --col-* offsets. */
#hud[data-mode="bar"] .hud-bar {
  display: flex;
  flex-wrap: nowrap;
  justify-content: space-between;
  align-items: center;
  height: 42px;
  padding: 0 2px;
}
#hud[data-mode="bar"] .btn { flex: none; }      /* never squeezed: main.js picks a size that fits */
#hud[data-mode="bar"] #score {
  position: absolute;
  left: calc(var(--col-x, 0px) + 8px);
  top: calc(var(--col-y, 42px) + 6px);
}
#hud[data-mode="bar"] #ballline,
#hud[data-mode="bar"] #times {
  position: absolute;
  right: calc(var(--col-r, 0px) + 8px);
  text-align: right;
}
#hud[data-mode="bar"] #ballline { top: calc(var(--col-y, 42px) + 6px); }
#hud[data-mode="bar"] #times { top: calc(var(--col-y, 42px) + 21px); }
#hud[data-mode="bar"] #times > span { display: block; }
#hud[data-mode="bar"] #times > .dot { display: none; }

/* Narrow phones: the two-word labels stack, so all seven buttons still share the row and every
   one of them stays at least 40 px wide (main.js steps down through these until the row fits). */
#hud[data-fit="snug"] .btn,
#hud[data-fit="tight"] .btn { padding: 0 1px; font-size: 10.5px; }
#hud[data-fit="snug"] .btn > span,
#hud[data-fit="tight"] .btn > span { flex-direction: column; gap: 1px; min-width: 38px; padding: 0 5px; line-height: 1; }
#hud[data-fit="tight"] .btn { padding: 0; font-size: 10px; }
#hud[data-fit="tight"] .btn > span { min-width: 40px; padding: 0 3px; border-radius: 7px; }
#hud[data-fit="tight"] .sub { font-size: 10px; }
#hud[data-fit="tight"] #times { top: calc(var(--col-y, 42px) + 19px); }

/* Room at the sides (landscape, tablets, desktop): the table keeps the full height, with the score
   to its left and the buttons to its right. */
#hud[data-mode="side"] {
  display: grid;
  grid-template-columns: var(--side-w, 204px) var(--col-w, 300px) var(--side-w, 204px);
  grid-template-rows: auto auto auto 1fr;
  column-gap: 6px;
}
#hud[data-mode="side"] #score { grid-column: 1; grid-row: 1; padding-top: 7px; text-align: right; }
#hud[data-mode="side"] #ballline { grid-column: 1; grid-row: 2; text-align: right; }
#hud[data-mode="side"] #times { grid-column: 1; grid-row: 3; text-align: right; }
#hud[data-mode="side"] .hud-bar {
  grid-column: 3;
  grid-row: 1 / span 4;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-start;
  align-content: flex-start;
  padding-top: 1px;
}

/* A button is a 40 px tall touch target with a smaller visible chip inside it. */
.btn {
  pointer-events: auto;
  appearance: none;
  -webkit-appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 40px;
  height: 40px;
  margin: 0;
  padding: 0 2px;
  border: 0;
  background: none;
  color: var(--ink);
  font: 600 11px/1 var(--font);
  cursor: pointer;
  touch-action: none;
}
.btn > span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  height: 32px;
  gap: 0.28em;
  padding: 0 7px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--chip);
  white-space: nowrap;
}
.btn > span > i { font-style: normal; }
.btn.down > span,
.btn:active > span { background: rgba(255, 191, 94, 0.3); }
.btn[aria-pressed="true"] > span { border-color: var(--amber); color: var(--amber); }
.btn.toggle[aria-pressed="false"] > span { color: #7d8492; border-style: dashed; }
.btn:focus-visible { outline: none; }
.btn:focus-visible > span { outline: 2px solid var(--amber); outline-offset: 1px; }
.btn[disabled] { opacity: 0.45; cursor: default; }

#btn-sound[aria-pressed="true"] .when-off,
#btn-sound[aria-pressed="false"] .when-on { display: none; }

.btn.big { width: 100%; height: 52px; font-size: 16px; }
.btn.big > span {
  width: 100%;
  height: 46px;
  border-color: var(--amber);
  background: rgba(255, 191, 94, 0.16);
  color: #ffe2ad;
}

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

.panel {
  position: fixed;
  z-index: 5;            /* above the start card, so Tune and Stats are usable before Start */
  left: var(--panel-left);
  top: var(--panel-top);
  width: var(--panel-width);
  max-height: var(--panel-max-height);
  padding: 2px 12px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--sheet);
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
}
.panel * { touch-action: pan-y; }

.panel header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-right: -8px;
}
.panel h2 {
  margin: 0;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--dim);
}

.presets { display: flex; flex-wrap: wrap; margin: 0 -6px 0 -2px; }
.presets .btn { flex: 1 1 0; }
.presets .btn > span { width: 100%; }
.presets .btn.close { flex: none; margin-left: 4px; }
#panel-tune { padding-top: 4px; padding-bottom: 4px; }

/* A slider is a 40 px tall touch target. It reaches up under its own caption (which takes no
   touches), so four of them still leave the flippers in view on a phone. */
.slider { display: block; margin: 1px 0 0; }
.slider .head { display: flex; justify-content: space-between; align-items: baseline; pointer-events: none; }
.slider .name { font-weight: 600; }
.slider output { font-variant-numeric: tabular-nums; color: var(--amber); }
.slider input[type="range"] {
  display: block;
  position: relative;
  width: 100%;
  height: 40px;
  margin: -7px 0 -3px;
  accent-color: var(--amber);
  cursor: pointer;
}

.row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  min-height: 40px;
  column-gap: 10px;
}
.code {
  font: 600 14px/1.2 var(--mono);
  color: var(--amber);
  -webkit-user-select: text;
  user-select: text;
}
.buzz,
.opt { display: inline-flex; align-items: center; gap: 4px; margin-right: -4px; color: var(--dim); font-size: 12px; }
.opt .btn > span { min-width: 46px; }

#stats-body { display: grid; grid-template-columns: 1fr auto; column-gap: 14px; row-gap: 3px; }
#stats-body .k { color: var(--dim); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#stats-body .v { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
#stats-body .h {
  grid-column: 1 / -1;
  margin-top: 7px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--dim);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}
#stats-body .h:first-child { margin-top: 0; }
#stats-body .wide { grid-column: 1 / -1; color: var(--dim); font-size: 11px; white-space: normal; }

/* ---------------------------------------------------------------- start card */

.card {
  position: fixed;
  z-index: 4;
  left: 50%;
  top: 44%;
  transform: translate(-50%, -50%);
  width: min(300px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  overflow: auto;
  padding: 16px 16px 12px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--sheet);
  box-shadow: 0 12px 50px rgba(0, 0, 0, 0.6);
  text-align: center;
}
.card,
.card * { touch-action: pan-y; }
.card h1 { margin: 0; font-size: 26px; font-weight: 700; letter-spacing: 0.02em; color: #ffe2ad; }
.card .tag { margin: 1px 0 10px; color: var(--dim); font-size: 12px; letter-spacing: 0.06em; }
.card ul { margin: 0 0 10px; padding: 0; list-style: none; font-size: 13.5px; line-height: 1.55; }
.card li.dim { color: var(--dim); font-size: 12px; }
.card .keys { display: none; margin: 0 0 10px; color: var(--dim); font-size: 12px; }
.card .other { margin: 8px 0 0; font-size: 12.5px; }
.card .other a { display: inline-block; padding: 6px 12px; color: var(--amber); text-underline-offset: 3px; }
#start-practice { font-size: 13px; }

/* ---------------------------------------------------------------- aim practice results */

/* The same report in the results card and in the Stats panel: the figures in plain words, a row
   for each pair, and the line to send back. */
.report { text-align: left; }
.report .words { margin: 0 0 8px; font-size: 13px; line-height: 1.4; }
/* How far to trust it: the other ways of taking the scatter, what was set aside, and the like. */
.report .small { margin: 0 0 8px; color: var(--dim); font-size: 11.5px; line-height: 1.4; }
/* Runs that were closed (Run again, a tuning change, a reload), each with its own code. */
.report .earlier .h {
  margin: 8px 0 4px;
  padding-top: 6px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--dim);
  font-size: 11.5px;
}
.report .pairs {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr) minmax(0, 0.6fr) minmax(0, 1.05fr) minmax(0, 1.1fr);
  column-gap: 6px;
  row-gap: 2px;
  margin: 0 0 8px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.report .pairs > div { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.report .pairs > .h {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--dim);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}
.report textarea.code {
  display: block;
  width: 100%;
  margin: 0;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.35);
  font: 11px/1.3 var(--mono);
  resize: none;
  overflow-wrap: anywhere;
  word-break: break-all;
  -webkit-touch-callout: default;
  touch-action: pan-y;
}
.report .copyrow { display: flex; align-items: center; gap: 8px; min-height: 40px; margin-left: -2px; }
.report .said { color: var(--dim); font-size: 12px; }
#drill-stats { margin-bottom: 6px; }
#results { top: 50%; width: min(340px, calc(100vw - 16px)); max-height: calc(100vh - 16px); max-height: calc(100dvh - 16px); padding: 12px 14px 8px; }
#results h1 { font-size: 20px; }
#results .tag { margin-bottom: 8px; }
#results .choice { display: flex; gap: 6px; margin-top: 2px; }
#results .choice .btn.big { height: 48px; font-size: 14px; }
#results .choice .btn.big > span { height: 42px; }
/* A short screen: the same card, set tighter, so that it still fits without scrolling. */
@media (max-height: 640px) {
  #results { padding: 8px 12px 4px; }
  #results h1 { font-size: 16px; }
  #results .tag { display: none; }
  #results .words { margin: 4px 0 5px; font-size: 12px; line-height: 1.3; }
  #results .small { display: none; }           /* the Stats panel has it */
  #results .pairs { margin-bottom: 5px; font-size: 11px; line-height: 1.25; row-gap: 1px; }
  #results .choice .btn.big { height: 44px; }
  #results .choice .btn.big > span { height: 38px; }
}
@media (hover: hover) and (pointer: fine) {
  .card .keys { display: block; }
  .card li.touch { display: none; }
}

/* ---------------------------------------------------------------- notices, debug, boot */

#notice {
  position: fixed;
  z-index: 7;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 10px);
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100vw - 20px);
  padding: 7px 11px;
  border-radius: 9px;
  border: 1px solid rgba(255, 120, 100, 0.6);
  background: rgba(40, 14, 12, 0.94);
  color: #ffd9d2;
  font-size: 12px;
  pointer-events: none;
}

/* ?debug timing readout. main.js places it: a two-line strip between the button bar and the
   table, or under the score when the HUD stands beside the table. Never over the table. */
#debug {
  position: fixed;
  z-index: 6;
  left: 0;
  top: 42px;
  height: 30px;
  margin: 0;
  padding: 3px 0 0;
  overflow: hidden;
  color: #b8f5c5;
  font: 9px/1.3 var(--mono);
  font-size: min(9px, 2.5vw);
  text-align: center;
  white-space: pre;
  pointer-events: none;
}
#debug[data-mode="side"] {
  height: auto;
  padding: 0;
  text-align: right;
  white-space: pre-wrap;
}

#boot {
  position: fixed;
  z-index: 9;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--bg);
  -webkit-user-select: text;
  user-select: text;
}
.boot-box { max-width: 520px; text-align: center; }
.boot-box h1 { margin: 0 0 6px; font-size: 24px; color: #ffe2ad; }
.boot-box p { margin: 0 0 8px; color: var(--dim); }
#boot.failed #boot-text { color: var(--ink); font-size: 15px; }
#boot-detail {
  margin: 0 0 8px;
  padding: 9px 11px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
  color: #ffd9d2;
  font: 12px/1.45 var(--mono);
  text-align: left;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
#boot-slow { opacity: 0; animation: boot-slow 0.4s 6s forwards; }
#boot.failed #boot-slow { display: none; }
@keyframes boot-slow { to { opacity: 1; } }

@media (max-height: 420px) {
  .card { top: 50%; padding: 10px 14px 8px; }
  .card li.dim { display: none; }
  .card ul { line-height: 1.35; margin-bottom: 6px; }
  .card .tag { margin-bottom: 5px; }
}
