@font-face {
  font-family: "Fredoka";
  src: url("../assets/fonts/Fredoka-SemiBold.woff2") format("woff2");
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}

:root {
  --emerald-rgb: 8, 125, 88;
  --garnet-rgb: 154, 68, 88;
  --ink-rgb: 23, 33, 58;
  --bg: #f5f4f0;
  --surface: #ffffff;
  --playfield: #ffffff;
  --grid-well: #ffffff;
  --rail-surface: #fafafd;
  --text: #17213a;
  --text-strong: #17213a;
  --muted: #68738b;
  --line: #dfe3eb;
  --line-strong: #ccd2df;
  --navy: #17213a;
  --teal: #087d58;
  --teal-deep: #066348;
  --gold: #c4922a;
  --reject: #9a4458;
  --reject-bg: #f8eef1;
  --accept-bg: #e8f6f1;
  --card: #ffffff;
  /* Desktop Equation Log: one 208px column until overflow, then two equation columns. */
  --desk-side: 208px;
  --desk-log-col: 170px;
  --desk-log-gap: 10px;
  --desk-side-multi: calc(var(--desk-log-col) * 2 + var(--desk-log-gap) + 32px);
  /* Desktop Number Grid ceiling (playfield-inner). */
  --desk-grid-max: 480px;
  /* Shared so Equation Log cards line up with the top grid row. */
  --helper-row-h: 36px;
  --grid-well-pad: 10px;
  --ink: #17213a;
  --clear: #ffffff;
  --switch-off: #c5cdd8;
  --shadow: none;
  --placeholder: #f8f9fc;
  --shadow-tile: 3px 3px 0 rgba(31, 43, 75, 0.11);
  --drop-outline: 1.5px dashed rgba(var(--ink-rgb), 0.16);
  --radius-panel: 18px;
  --radius-tile: 14px;
  /* Fallback only; Number Grid cards use card-relative border via cqi. */
  --tile-border: 8px;
  --font-ui: "Nunito Sans", ui-sans-serif, system-ui, sans-serif;
  --font-math: "Atkinson Hyperlegible", "Nunito Sans", ui-sans-serif, system-ui, sans-serif;
  --font-card-number: "Fredoka", "Nunito Sans", ui-sans-serif, system-ui, sans-serif;
  --font-timer: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  --header-h: 56px;
  --type-heading-size: 1rem;
  --type-heading-weight: 700;
  --type-heading-color: var(--navy);
  --type-regular-size: 0.78rem;
  --type-regular-weight: 600;
  --type-regular-color: var(--muted);
}

:root,
[data-palette="cobalt-amethyst"] {
  --accent-0: #0848D3;
  --accent-25: #2D44CB;
  --accent-50: #5C3EC1;
  --accent-75: #8539B8;
  --accent-100: #AD34B0;
  --accent-deep: #49319A;
}

[data-palette="ember-amber"] {
  --accent-0: #EE5E13;
  --accent-25: #F06A10;
  --accent-50: #F27B0B;
  --accent-75: #F48906;
  --accent-100: #F59702;
  --accent-deep: #9A3F0B;
}

[data-palette="magenta-ruby"] {
  --accent-0: #BB33A8;
  --accent-25: #C6338F;
  --accent-50: #D4346E;
  --accent-75: #DF3452;
  --accent-100: #EB3537;
  --accent-deep: #8A245A;
}

[data-palette="lime-emerald"] {
  --accent-0: #65CB38;
  --accent-25: #50BF39;
  --accent-50: #35B03A;
  --accent-75: #1EA33B;
  --accent-100: #07973C;
  --accent-deep: #176B32;
}

[data-palette="cyan-cobalt"] {
  --accent-0: #019DE1;
  --accent-25: #018CDF;
  --accent-50: #0175DC;
  --accent-75: #0162D9;
  --accent-100: #004FD6;
  --accent-deep: #0645A8;
}

:root,
[data-palette] {
  --accent-gradient: linear-gradient(
    135deg,
    var(--accent-0) 0%,
    var(--accent-25) 25%,
    var(--accent-50) 50%,
    var(--accent-75) 75%,
    var(--accent-100) 100%
  );
  --accent-tint: color-mix(in srgb, var(--accent-50) 10%, white);
  --accent-tint-strong: color-mix(in srgb, var(--accent-50) 18%, white);
  --accent-border: color-mix(in srgb, var(--accent-deep) 38%, white);
  --accent-on-deep: #FFFFFF;
  --accent-on-bright: #17213A;
}

[data-palette="cobalt-amethyst"] .tile,
[data-palette="ember-amber"] .tile,
[data-palette="magenta-ruby"] .tile,
[data-palette="lime-emerald"] .tile,
[data-palette="cyan-cobalt"] .tile {
  border-color: var(--accent-75);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  font-family: var(--font-ui);
}

body {
  position: fixed;
  inset: 0;
  width: 100%;
  font-family: var(--font-ui);
  color: var(--text);
  background: var(--bg);
}

button, input {
  font: inherit;
}

button {
  cursor: pointer;
}

button:focus-visible,
summary:focus-visible {
  outline: 2px solid var(--accent-deep);
  outline-offset: 2px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

#app,
#app.is-playing {
  height: 100%;
  overflow: hidden;
}

#app.is-playing {
  container-type: size;
}

#app.is-menu {
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
}

.assignment {
  margin: 8px 0 0;
  font-weight: 800;
  color: var(--navy);
  font-size: 1rem;
}

.round-status.is-compact .assignment {
  flex: 1 1 100%;
  margin: 4px 0 0;
  font-size: 0.92rem;
}

.round-status.is-compact {
  flex-wrap: wrap;
}

.menu-shell {
  max-width: 540px;
  margin: 0 auto;
  padding: 10px 16px calc(24px + env(safe-area-inset-bottom, 0px));
  padding-left: calc(16px + env(safe-area-inset-left, 0px));
  padding-right: calc(16px + env(safe-area-inset-right, 0px));
}

.menu-card {
  background: var(--surface);
  border-radius: var(--radius-panel);
  border: 1px solid var(--line);
  padding: 20px 18px 18px;
}

.menu-note {
  margin: 0 0 10px;
  color: var(--muted);
  font-weight: 700;
}

.menu-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 8px;
}

.menu-actions button {
  width: 100%;
  border: 0;
  border-radius: 12px;
  padding: 0.85rem 0.7rem;
  font-weight: 800;
}

.preset-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 0 0 16px;
}

.preset-btn {
  text-align: left;
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 14px;
  padding: 0.8rem 0.9rem;
  color: var(--navy);
}

.preset-btn strong {
  display: block;
  font-size: 0.98rem;
}

.preset-btn span {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.85rem;
}

.preset-btn.is-on {
  border-color: var(--accent-deep);
  box-shadow: inset 0 0 0 1px var(--accent-deep);
  background: var(--accent-tint);
}

.result-stat {
  margin: 0 0 6px;
  font-weight: 800;
  color: var(--navy);
  font-size: 1.15rem;
}

.result-celebrate {
  margin: 12px 0;
  font-weight: 800;
  color: var(--teal-deep);
  font-size: 1.35rem;
}

.result-log {
  margin: 0 0 16px;
}

.pb-list {
  list-style: none;
  margin: 0 0 16px;
  padding: 0;
}

.pb-list li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--line);
  font-weight: 700;
  color: var(--navy);
}

.pb-list span {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.tile.is-var {
  letter-spacing: 0;
}

.number-grid .tile:not(.is-var),
.rail-tile:not(.is-var),
.drag-ghost.tile:not(.is-var) {
  font-family: var(--font-card-number);
  font-weight: 600;
}

.math {
  font-family: var(--font-math);
  font-weight: 700;
}

.lede {
  margin: 0 0 0.4rem;
  color: var(--muted);
  text-align: center;
  font-weight: 700;
}

.choice-row {
  display: flex;
  gap: 0.6rem;
  margin: 0 0 1.2rem;
}

.choice-row button {
  flex: 1;
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 12px;
  padding: 0.7rem 0.5rem;
  font-weight: 800;
  color: var(--muted);
}

.choice-row button.is-on {
  border-color: var(--accent-deep);
  color: var(--accent-deep);
  box-shadow: inset 0 0 0 1px var(--accent-deep);
  background: var(--accent-tint);
}

.choice-row button:disabled {
  opacity: 0.45;
  cursor: default;
}

.game-shell {
  width: max-content;
  max-width: 100%;
  margin: 0 auto;
  padding: 10px 16px calc(16px + env(safe-area-inset-bottom, 0px));
  padding-left: calc(16px + env(safe-area-inset-left, 0px));
  padding-right: calc(16px + env(safe-area-inset-right, 0px));
  display: grid;
  grid-template-columns: max-content var(--desk-side);
  grid-template-rows: auto auto auto;
  grid-template-areas:
    "header header"
    "playfield side"
    "stamp stamp";
  gap: 12px 16px;
  min-height: 0;
  overflow: hidden;
  height: auto;
  max-height: 100%;
  align-content: start;
}

.game-shell.is-log-only {
  grid-template-rows: auto auto auto;
  grid-template-areas:
    "header header"
    "playfield side"
    "stamp stamp";
}

.side-column {
  grid-area: side;
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: var(--desk-side);
  min-width: 0;
  height: 0;
  min-height: 100%;
  overflow: hidden;
}

/* Desktop multi log: same CSS-columns recipe as short-landscape.
   Newest stays first in the DOM → top of column 1; older rows fill down,
   then spill into column 2 (to the right). */
.game-shell.is-log-multi {
  grid-template-columns: max-content var(--desk-side-multi);
}

.game-shell.is-log-multi .side-column {
  width: var(--desk-side-multi);
}

.game-shell.is-log-multi .equation-log {
  min-height: 0;
  max-height: 100%;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.game-shell.is-log-multi .log-scroll {
  flex: 1 1 auto;
  display: block;
  min-width: 0;
  min-height: 0;
  /* Flex % height trick: same role as landscape's stretched log panel height. */
  height: 0;
  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior-x: contain;
}

.game-shell.is-log-multi .log-list {
  display: block;
  /* Prefer JS pixel height (Safari); % alone often leaves columns unpackaged. */
  height: 100%;
  width: max-content;
  max-width: none;
  min-width: calc(var(--desk-log-col) * 2 + var(--desk-log-gap));
  min-height: 0;
  margin: 0;
  padding: 0;
  list-style: none;
  flex: none;
  overflow: visible;
  gap: 0;
  contain: none;
  -webkit-column-width: var(--desk-log-col);
  -moz-column-width: var(--desk-log-col);
  column-width: var(--desk-log-col);
  -webkit-column-gap: var(--desk-log-gap);
  -moz-column-gap: var(--desk-log-gap);
  column-gap: var(--desk-log-gap);
  -webkit-column-fill: auto;
  -moz-column-fill: auto;
  column-fill: auto;
}

.game-shell.is-log-multi .log-list li {
  break-inside: avoid;
  -webkit-column-break-inside: avoid;
  page-break-inside: avoid;
  box-sizing: border-box;
  width: var(--desk-log-col);
  min-width: var(--desk-log-col);
  max-width: var(--desk-log-col);
  margin: 0 0 6px;
  touch-action: pan-x;
  cursor: default;
}

.game-header {
  grid-area: header;
  min-height: 0;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: env(safe-area-inset-top, 0px) 4px 0;
  flex-shrink: 0;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-panel);
  padding: calc(10px + env(safe-area-inset-top, 0px)) 14px 10px;
}

.game-brand {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 12px;
}

.game-mark {
  flex: 0 0 38px;
  width: 38px;
  height: 38px;
  overflow: hidden;
  background: var(--accent-gradient);
  border-radius: 11px;
}

.game-mark img {
  display: block;
  width: 100%;
  height: 100%;
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-user-drag: none;
}

.game-header h1 {
  margin: 0;
  font-family: var(--font-card-number);
  font-size: 1.9rem;
  color: var(--navy);
  letter-spacing: -0.02em;
  line-height: 1;
  font-weight: 600;
  white-space: nowrap;
}

.header-actions {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.icon-btn {
  display: grid;
  width: 38px;
  height: 38px;
  margin: 0;
  border: 1px solid var(--line-strong);
  border-radius: 11px;
  background: var(--card);
  color: #26314e;
  place-items: center;
  font-size: 1.1rem;
  line-height: 1;
}

.icon-btn:hover { background: var(--accent-tint-strong); }

.icon-btn > svg {
  width: 18px;
  height: 18px;
}

/* Co-play: grow left from the usual gear slot; gear stays in the right 38×38. */
.icon-btn.is-coplay {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  width: auto;
  min-width: 38px;
  padding: 0 0 0 8px;
  gap: 0;
}

.icon-btn.is-coplay .coplay-indicators {
  display: inline-flex;
  align-items: center;
  align-self: center;
  margin: 0 0 0 0;
  order: 0;
  color: #1a7a3c;
  line-height: 1;
}

.icon-btn.is-coplay.is-error .coplay-indicators {
  color: #b42318;
}

.icon-btn.is-coplay .icon-btn-gear {
  display: grid;
  width: 38px;
  height: 38px;
  margin: 0;
  place-items: center;
  flex: 0 0 38px;
  order: 1;
  color: #26314e;
}

.icon-btn.is-coplay .icon-btn-gear svg {
  width: 18px;
  height: 18px;
}

.coplay-chip-icon {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
}

.coplay-chip-icon svg {
  width: 18px;
  height: 18px;
  display: block;
}

.coplay-chip-status {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  min-width: 0.65em;
  margin: 0 0 0 1px;
  padding: 0;
  color: inherit;
  font-size: 0.68rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  transform: translateY(-0.35em);
}

.coplay-chip-status.is-waiting::before {
  content: '';
  display: block;
  width: 0.42em;
  height: 0.42em;
  border-radius: 50%;
  background: currentColor;
}

.coplay-chip-status.is-error {
  font-weight: 900;
}

.coplay-settings-meta {
  margin: 0 0 var(--settings-row-gap, 8px);
  font-size: var(--type-regular-size);
  font-weight: 700;
  color: var(--muted);
}

.coplay-settings-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--settings-row-gap, 8px);
  margin: 0 0 4px;
}

.settings-card .coplay-settings-actions button {
  width: 100%;
  margin-top: 0;
  min-height: var(--helper-row-h);
  padding: 0.4rem 0.45rem;
  border-radius: 10px;
  font-size: var(--settings-btn-font, 0.8rem);
  font-weight: 700;
  line-height: 1.1;
}

.settings-card .coplay-settings-actions .btn-submit {
  background: var(--teal);
  color: #fff;
  border-color: var(--teal);
}

.coplay-settings-code-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--settings-row-gap, 8px);
  margin: var(--settings-row-gap, 8px) 0 0;
}

.settings-card .coplay-settings-code-row .btn-clear {
  width: auto;
  margin-top: 0;
  min-height: var(--helper-row-h);
  padding: 0.4rem 0.7rem;
  border-radius: 10px;
  font-size: var(--settings-btn-font, 0.8rem);
  font-weight: 700;
}

.coplay-settings-code,
.coplay-settings-status,
.coplay-settings-error {
  margin: 0;
  font-size: var(--type-regular-size);
  font-weight: 700;
  color: var(--type-regular-color);
  line-height: 1.3;
}

.coplay-settings-status,
.coplay-settings-error {
  margin-top: 8px;
}

.settings-card .coplay-settings-status {
  margin-top: 6px;
  text-align: center;
}

.coplay-settings-error {
  color: #b42318;
}

.settings-card .coplay-settings-error {
  margin-top: 6px;
  text-align: center;
}

.coplay-invite-code {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  box-sizing: border-box;
  min-width: 0;
  min-height: var(--helper-row-h);
  padding: 0.4rem 0.65rem;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  text-align: center;
  color: var(--accent-deep);
  font-size: 0.9rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  line-height: 1.2;
  text-transform: uppercase;
}

.coplay-session-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 10px;
  margin: 4px 0 8px;
}

.coplay-shared-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 2px;
  color: var(--type-heading-color);
  font-size: var(--type-heading-size);
  font-weight: var(--type-heading-weight);
  line-height: 1.25;
}

.coplay-shared-dot {
  flex: 0 0 auto;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #1a7a3c;
}

.coplay-shared-dot.is-waiting {
  animation: coplay-shared-dot-pulse 1.2s ease-in-out infinite;
}

.coplay-shared-dot.is-connected {
  opacity: 1;
}

@keyframes coplay-shared-dot-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

.coplay-shared-title.is-error {
  color: #b42318;
}

.coplay-shared-text {
  min-width: 0;
}

@media (prefers-reduced-motion: reduce) {
  .coplay-shared-dot.is-waiting {
    animation: none;
  }
}

.coplay-shared-hint {
  margin: 0 0 6px;
  color: var(--type-regular-color);
  font-size: var(--type-regular-size);
  font-weight: var(--type-regular-weight);
  line-height: 1.3;
}

.coplay-session-status {
  margin: 0;
  color: #1a7a3c;
  font-size: var(--type-heading-size);
  font-weight: var(--type-heading-weight);
  line-height: 1.2;
  white-space: nowrap;
}

.coplay-session-status.is-error {
  color: #b42318;
}

.coplay-join-inline {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--settings-row-gap, 8px);
  margin: 4px 0 0;
}

.settings-card .coplay-join-inline .coplay-join-input {
  width: 100%;
  min-width: 0;
}

.settings-card .coplay-join-inline .helper-btn {
  width: auto;
  margin: 0;
  border: 0;
  background: transparent;
  padding: 0 6px;
  color: #4b5772;
  font-size: 0.78rem;
}

@media (hover: hover) and (pointer: fine) {
  .settings-card .coplay-join-inline .helper-btn:hover:not(:disabled) {
    color: var(--accent-deep);
    background: var(--accent-tint-strong);
  }
}

.coplay-join-label {
  font-size: var(--type-regular-size);
  font-weight: 800;
  color: var(--muted);
}

.coplay-join-fields {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: var(--settings-row-gap, 8px);
  align-items: stretch;
}

.coplay-join-input {
  width: 100%;
  box-sizing: border-box;
  min-height: var(--helper-row-h);
  padding: 0.4rem 0.65rem;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.settings-card .coplay-join-fields .btn-submit {
  width: auto;
  margin-top: 0;
  min-width: 3.25rem;
  min-height: var(--helper-row-h);
  padding: 0.4rem 0.75rem;
  border-radius: 10px;
  font-size: var(--settings-btn-font, 0.8rem);
  font-weight: 700;
}

html.is-short-land .icon-btn.is-coplay .coplay-indicators {
  margin: 0;
}

html.is-short-land .coplay-chip-icon svg {
  width: 16px;
  height: 16px;
}

.build-meta {
  margin: 8px 0 0;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: 0.01em;
}

.build-stamp {
  grid-area: stamp;
  margin: 2px 0 0;
  padding: 0 4px;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  opacity: 0.55;
  text-align: center;
  pointer-events: none;
  user-select: none;
}

.playfield {
  grid-area: playfield;
  min-height: 0;
  min-width: 0;
  width: max-content;
  max-width: 100%;
  justify-self: start;
  background: var(--playfield);
  border-radius: var(--radius-panel);
  border: 1px solid var(--line);
  display: flex;
  align-self: start;
  align-items: flex-start;
  justify-content: center;
  padding: 12px 14px;
  overflow: hidden;
}

.playfield-inner {
  width: min(var(--desk-grid-max), max(18rem, calc(100cqh - 23rem)));
  height: auto;
  max-height: 100%;
  min-height: 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: stretch;
  gap: clamp(6px, 1vh, 10px);
  overflow: hidden;
}

.playfield.has-panel {
  align-items: stretch;
  justify-content: stretch;
  width: min(100%, calc(var(--desk-grid-max) + 28px));
}

.playfield.has-panel .playfield-inner {
  width: 100%;
  height: 100%;
  max-width: var(--desk-grid-max);
  overflow-y: auto;
}

.playfield-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
  width: 100%;
}

.playfield-panel h2 {
  margin: 0;
  color: var(--navy);
  font-size: 1.35rem;
}

.board-column {
  position: relative;
  flex: 0 1 auto;
  min-height: 0;
  min-width: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: stretch;
}

.grid-stage {
  flex: 0 0 auto;
  min-height: 0;
  min-width: 0;
  width: 100%;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  overflow: visible;
}

.board-stack {
  position: relative;
  width: 100%;
  height: auto;
  aspect-ratio: 1 / 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.number-grid {
  flex: 0 0 auto;
  width: 100%;
  max-height: 100%;
  aspect-ratio: 1;
  min-height: 0;
  min-width: 0;
  padding: var(--grid-well-pad);
  display: grid;
  grid-template-columns: repeat(var(--grid-size, 3), minmax(0, 1fr));
  grid-template-rows: repeat(var(--grid-size, 3), minmax(0, 1fr));
  gap: clamp(8px, 1.4vh, 14px);
  background: var(--grid-well);
  border-radius: 18px;
  container-type: size;
  /* Approximate one card from the grid container (cqmin / N). */
  --card-size: calc(100cqmin / var(--grid-size, 3));
  --card-border: clamp(3px, calc(var(--card-size) * 0.07), 14px);
  --card-radius: clamp(7px, calc(var(--card-size) * 0.14), 18px);
  /* Floor only: keep readable mins; no max so numerals keep tracking card growth. */
  --card-numeral: max(1.05rem, calc(var(--card-size) * 0.46));
  --card-numeral-3: max(0.85rem, calc(var(--card-size) * 0.30));
}

.number-grid.is-shuffling .tile {
  transform: scale(0.95);
  opacity: 0.72;
}

.tile {
  position: relative;
  box-sizing: border-box;
  min-width: 0;
  min-height: 0;
  width: 100%;
  height: 100%;
  border-width: var(--tile-border);
  border-style: solid;
  border-color: var(--accent-75);
  border-radius: var(--radius-tile);
  background: var(--card);
  box-shadow: var(--shadow-tile);
  color: var(--ink);
  font-family: var(--font-math);
  font-weight: 700;
  font-size: calc(100cqmin / var(--grid-size, 3) * 0.28);
  line-height: 1;
  display: grid;
  place-items: center;
  transition: transform 0.16s ease, box-shadow 0.16s ease, opacity 0.15s ease, background 0.16s ease, border-color 0.16s ease;
  user-select: none;
  touch-action: none;
  cursor: grab;
}

/* Card-relative chrome: border / radius / numeral track the card size. */
.number-grid .tile {
  box-sizing: border-box;
  border-width: var(--card-border);
  border-radius: var(--card-radius);
  font-size: var(--card-numeral);
}

.number-grid .tile.digits-3 {
  font-size: var(--card-numeral-3);
}

.number-grid .grid-slot.is-empty {
  box-sizing: border-box;
  border-radius: var(--card-radius);
}

.tile:hover:not(:disabled) {
  transform: translateY(-1px);
}

.tile.is-dragging,
.number-grid .tile.is-vacant {
  cursor: grabbing;
}

.tile:disabled {
  opacity: 0.38;
  cursor: default;
  box-shadow: none;
}

.number-grid .tile.is-grid-restore {
  animation: grid-tile-restore 180ms ease-out both;
}

@keyframes grid-tile-restore {
  from { opacity: 0; }
  to { opacity: 1; }
}

.grid-slot.is-empty {
  min-width: 0;
  min-height: 0;
  width: 100%;
  height: 100%;
  border-radius: var(--radius-tile);
  background: var(--placeholder);
  border: 0;
  box-shadow: none;
  color: transparent;
  transform: none;
}

.number-grid .tile.is-vacant,
.grid-slot.is-empty.is-drop-target {
  background: var(--placeholder);
  border: 0;
  box-shadow: none;
  color: transparent;
  transform: none;
  outline: var(--drop-outline);
  outline-offset: -2px;
}

.tile.is-hint {
  color: var(--ink);
  background: color-mix(in srgb, var(--accent-50) 28%, white);
  animation: hint-fill-fade 5s linear forwards;
}

@keyframes hint-fill-fade {
  from { background: color-mix(in srgb, var(--accent-50) 28%, white); }
  to { background: var(--card); }
}

.number-grid .tile.is-hint {
  color: var(--ink);
}

.grid-slot.is-empty.is-hint {
  outline: none;
  box-shadow: none;
}

.helper-tools {
  display: grid;
  flex: 0 0 auto;
  width: 100%;
  max-width: 100%;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 4px;
  margin: 0;
}

.helper-btn {
  display: flex;
  height: var(--helper-row-h);
  min-height: var(--helper-row-h);
  min-width: 0;
  padding: 0 6px;
  align-items: center;
  justify-content: center;
  gap: 5px;
  color: #4b5772;
  background: transparent;
  border: 0;
  border-radius: 10px;
  font-size: 0.78rem;
  font-weight: 700;
  line-height: 1;
  white-space: nowrap;
}

@media (hover: hover) and (pointer: fine) {
  .helper-btn:hover:not(:disabled) {
    color: var(--accent-deep);
    background: var(--accent-tint-strong);
  }
}

.helper-btn.is-hover-quiet,
.helper-btn.is-hover-quiet:hover:not(:disabled) {
  color: #4b5772;
  background: transparent;
}

.helper-btn:disabled {
  opacity: 0.45;
  cursor: default;
}

/* Accept transition freezes inputs without the usual disabled fade. */
.is-accept-transition .helper-btn:disabled,
.is-accept-transition .picker button:disabled,
.is-accept-transition .picker button[aria-disabled="true"]:not(.is-on),
.is-accept-transition .rail-paren:disabled,
.is-accept-transition .btn-clear:disabled,
.is-accept-transition .btn-submit:disabled {
  opacity: 1;
}

.helper-btn.is-on {
  color: var(--accent-deep);
  background: var(--accent-tint);
}

.helper-btn svg {
  display: block;
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
}

.rail-block {
  --rail-row-min: 54px;
  position: relative;
  z-index: 60;
  /* Own compositor layer so this stays above the body-fixed message card on WebKit.
     Modal overlays (.overlay*) must stay above 60 or the rail punches through the dim. */
  transform: translateZ(0);
  overflow: hidden;
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
  width: 100%;
  max-width: 100%;
  padding: 8px 10px 10px;
  background: var(--rail-surface);
  border: 1px solid var(--line);
  border-radius: 14px;
}

.rail-scroll {
  width: 100%;
  min-width: 0;
  overflow-x: auto;
  overflow-y: hidden;
  touch-action: pan-x;
  min-height: var(--rail-row-min);
}

.rail {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  flex-wrap: nowrap;
  width: max-content;
  min-width: 100%;
  min-height: var(--rail-row-min);
  overflow: visible;
  padding: 4px 8px;
}

.rail-empty {
  width: 100%;
  min-height: var(--rail-row-min);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0;
  color: var(--type-regular-color);
  font-weight: var(--type-regular-weight);
  /* Own scale (do not reuse --type-regular-size): must shrink on short landscape. */
  font-size: clamp(0.58rem, 2.15vh, 0.78rem);
  text-align: center;
  border-radius: 12px;
  border: 0;
  outline: 1.5px dashed transparent;
  outline-offset: -2px;
  box-sizing: border-box;
}

.rail-empty-idle {
  max-width: 100%;
  line-height: 1.35;
  margin: 0;
  text-align: center;
}

.rail-empty-drop {
  display: none;
  max-width: 100%;
  line-height: 1.35;
  margin: 0;
  text-align: center;
}

.rail-empty.is-drop-target {
  outline: var(--drop-outline);
  background: var(--placeholder);
}

.rail-empty.is-drop-target .rail-empty-idle {
  display: none;
}

.rail-empty.is-drop-target .rail-empty-drop {
  display: inline;
}

.rail-scroll.is-drop-target {
  outline: var(--drop-outline);
  outline-offset: -2px;
  border-radius: 12px;
  box-sizing: border-box;
}

.rail-tile {
  flex: 0 0 auto;
  width: 46px;
  min-width: 46px;
  height: 46px;
  border-width: 1.5px;
  border-radius: 6px;
  font-size: 1.7rem;
  cursor: grab;
  touch-action: none;
  box-shadow: none;
}

.rail-tile.digits-3 { font-size: 1.02rem; }

.rail-tile.is-dragging {
  cursor: grabbing;
}

.rail-tile.is-empty {
  /* Same outer box as filled .tile.rail-tile (1.5px border in the 46px size). */
  border-style: dashed;
  border-color: rgba(var(--ink-rgb), 0.16);
  background: var(--placeholder);
  box-shadow: none;
  color: transparent;
  transform: none;
  opacity: 1;
  cursor: default;
  pointer-events: auto;
}

.rail-tile.is-empty:disabled {
  opacity: 1;
  cursor: default;
  box-shadow: none;
}

.rail-tile.is-empty.is-drop-target {
  background: var(--placeholder);
  border-color: rgba(var(--ink-rgb), 0.28);
}

.op-slot.is-scaffold {
  pointer-events: none;
  cursor: default;
  opacity: 1;
}

.op-slot.is-scaffold:disabled {
  opacity: 1;
  cursor: default;
}

.rail-tile.is-drop-before {
  box-shadow: -6px 0 0 color-mix(in srgb, var(--accent-0) 55%, transparent);
}

.rail-tile.is-drop-after {
  box-shadow: 6px 0 0 color-mix(in srgb, var(--accent-0) 55%, transparent);
}

.rail-tile:hover:not(:disabled):not(.is-vacant),
.rail-tile.is-selected:not(.is-vacant) {
  background: var(--accent-tint);
}

.rail-tile.is-vacant {
  background: transparent;
  border-color: transparent;
  box-shadow: none;
  color: transparent;
  transform: none;
  opacity: 1;
  cursor: grabbing;
  outline: var(--drop-outline);
  outline-offset: -2px;
}

.rail-tile.is-vacant.is-drop-before {
  box-shadow: -6px 0 0 color-mix(in srgb, var(--accent-0) 55%, transparent);
}

.rail-tile.is-vacant.is-drop-after {
  box-shadow: 6px 0 0 color-mix(in srgb, var(--accent-0) 55%, transparent);
}

.rail-paren {
  flex: 0 0 auto;
  box-sizing: content-box;
  width: 12px;
  height: 46px;
  padding: 0;
  margin: 0;
  border: none;
  background: transparent;
  color: var(--navy);
  font-family: var(--font-math);
  font-weight: 400;
  font-size: 2.35rem;
  line-height: 46px;
  text-align: center;
  overflow: visible;
  transform: scaleY(1.12);
  transform-origin: center;
  cursor: pointer;
}

.rail-paren:disabled {
  opacity: 0.45;
  cursor: default;
}

.rail-paren.is-preview {
  opacity: 0.38;
  pointer-events: none;
  cursor: default;
}

.drag-ghost {
  position: fixed;
  z-index: 80;
  pointer-events: none;
  margin: 0;
  cursor: grabbing;
  box-shadow: 0 8px 18px rgba(var(--ink-rgb), 0.16);
}

.op-ghost {
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 0;
  background: #f0f2f6;
  color: var(--ink);
  font-size: 1.5rem;
  font-weight: 700;
}

.op-slot {
  flex: 0 0 auto;
  width: 32px;
  min-width: 32px;
  height: 32px;
  touch-action: pan-x;
  cursor: pointer;
  border-radius: 50%;
  border: var(--drop-outline);
  background: transparent;
  color: var(--navy);
  font-size: 1.45rem;
  display: grid;
  place-items: center;
  padding: 0;
}

.op-slot.is-filled {
  border-style: solid;
  border-color: transparent;
  background: rgba(255, 255, 255, 0.7);
  cursor: grab;
  touch-action: none;
}

.op-slot.is-filled:hover:not(:disabled):not(.is-vacant),
.op-slot.is-filled:focus-visible:not(.is-vacant),
.op-slot.is-open:not(.is-vacant) {
  background: var(--accent-tint);
}

.op-slot.is-filled.is-open:not(.is-vacant),
.op-slot.is-filled:hover:not(:disabled):not(.is-vacant),
.op-slot.is-filled:focus-visible:not(.is-vacant) {
  border-color: transparent;
}

.op-slot.is-dragging,
.picker button.is-dragging {
  cursor: grabbing;
}

.picker button.is-dragging {
  opacity: 0.35;
}

.op-slot.is-vacant {
  border: var(--drop-outline);
  background: transparent;
  color: transparent;
  opacity: 1;
  cursor: grabbing;
}

.picker {
  flex: 0 0 auto;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 44px;
  min-width: 0;
  width: 100%;
}

.op-slot.is-dropzone {
  border: var(--drop-outline);
  background: transparent;
  color: transparent;
}

.op-slot.is-drop-target {
  border-color: var(--accent-deep);
  background: color-mix(in srgb, var(--accent-50) 12%, transparent);
}

.picker button {
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  border-radius: 50%;
  border: 0;
  background: #f0f2f6;
  color: #758097;
  font-family: var(--font-math);
  font-weight: 700;
  font-size: 1.5rem;
  cursor: grab;
  touch-action: none;
}

.picker button:hover:not(:disabled) {
  color: var(--accent-deep);
  background: var(--accent-tint);
}

.picker button.is-on {
  border: 0;
  background: var(--accent-deep);
  color: var(--accent-on-deep);
}

.picker button:disabled {
  opacity: 0.4;
  cursor: default;
}

.picker.has-parens button {
  width: 44px;
  height: 44px;
  flex-basis: 44px;
  font-size: 1.5rem;
}

.picker.has-parens button.is-paren {
  letter-spacing: 0.08em;
  font-size: 1.4rem;
  padding: 0 0 0 0.08em;
}

.picker button.is-muted,
.picker button[aria-disabled="true"]:not(.is-on) {
  opacity: 0.4;
}

.rail-actions {
  flex: 0 0 auto;
  width: 100%;
  min-width: 0;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 4px;
}

.btn-clear {
  color: #33405d;
  background: var(--card);
  border: 1px solid var(--line-strong);
}

.btn-submit {
  background: var(--teal);
  color: #fff;
  border: 1px solid var(--teal);
}

.btn-shuffle,
.btn-redraw,
.btn-hint {
  background: var(--card);
  color: var(--navy);
  border: 1px solid var(--line) !important;
}

.btn-clear:disabled,
.btn-submit:disabled {
  color: #9aa1b1;
  background: #eceef2;
  border-color: #eceef2;
  opacity: 1;
  cursor: default;
}

.feedback {
  position: absolute;
  left: 50%;
  bottom: 10px;
  z-index: 5;
  width: min(92%, 22rem);
  margin: 0;
  padding: 0.65rem 1rem;
  transform: translateX(-50%);
  pointer-events: none;
  text-align: center;
  font-weight: 700;
  font-size: 0.88rem;
  line-height: 1.4;
  border-radius: 14px;
  box-shadow: 0 10px 24px rgba(var(--ink-rgb), 0.2);
}

.feedback:not(.is-accepted):not(.is-rejected):not(.is-neutral):not(.is-success):not(.is-validation):not(.is-guidance):not(.is-info):not(.is-milestone) {
  visibility: hidden;
  width: 0;
  height: 0;
  padding: 0;
  overflow: hidden;
  box-shadow: none;
}

@keyframes feedback-rise {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

@keyframes feedback-sink {
  from {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
  to {
    opacity: 0;
    transform: translateX(-50%) translateY(12px);
  }
}

.feedback.is-accepted,
.feedback.is-neutral,
.feedback.is-rejected,
.feedback.is-success,
.feedback.is-validation,
.feedback.is-guidance,
.feedback.is-info,
.feedback.is-milestone {
  animation: feedback-rise 0.34s ease-out both;
}

.feedback.is-accepted.is-leaving,
.feedback.is-neutral.is-leaving,
.feedback.is-rejected.is-leaving,
.feedback.is-success.is-leaving,
.feedback.is-validation.is-leaving,
.feedback.is-guidance.is-leaving,
.feedback.is-info.is-leaving,
.feedback.is-milestone.is-leaving {
  animation: feedback-sink 0.34s ease-in both;
}

.feedback.is-accepted {
  color: var(--teal-deep);
  background: var(--accept-bg);
  box-shadow:
    0 0 0 1px rgba(var(--emerald-rgb), 0.35),
    0 8px 18px rgba(var(--ink-rgb), 0.14);
}

.feedback.is-neutral {
  color: var(--accent-on-deep);
  background: var(--accent-deep);
  font-weight: 700;
}

.feedback.is-rejected {
  color: var(--reject);
  background: var(--reject-bg);
  box-shadow:
    0 0 0 1px rgba(var(--garnet-rgb), 0.35),
    0 8px 18px rgba(var(--ink-rgb), 0.14);
}

.round-status,
.equation-log,
.how-to {
  background: var(--surface);
  border-radius: var(--radius-panel);
  border: 1px solid var(--line);
  padding: 14px 16px;
  min-height: 0;
  min-width: 0;
}

.round-status {
  flex: 0 0 auto;
}

.equation-log {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  overflow: hidden;
  min-height: 0;
  padding: 12px 16px 14px;
  position: relative;
  --log-pad-x: 16px;
  --log-pad-top: 12px;
}

.equation-log.is-progress-open {
  /* Keep overlay + veil inside the log; grow when needed (esp. mobile portrait). */
  overflow: hidden;
  min-height: calc(
    var(--log-pad-top) + var(--helper-row-h) + var(--grid-well-pad) + 9.75rem + 0.5rem
  );
}

.log-scroll {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.log-head {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: stretch;
  gap: 0;
  height: var(--helper-row-h);
  min-height: var(--helper-row-h);
  margin: 0 0 var(--grid-well-pad);
  padding: 0;
  box-sizing: border-box;
  position: relative;
  z-index: 7;
}

.log-head h2,
.side-title {
  margin: 0;
  color: var(--type-heading-color);
  font-size: var(--type-heading-size);
  font-weight: var(--type-heading-weight);
  line-height: 1;
  flex: 0 0 auto;
}

/* Full-row disclosure: heading language, not a pink chip/pill. */
.log-head-btn {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  box-sizing: border-box;
  width: 100%;
  height: 100%;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--type-heading-color);
  font: inherit;
  font-size: var(--type-heading-size);
  font-weight: var(--type-heading-weight);
  line-height: 1;
  text-align: left;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.log-head-title {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.log-head-count {
  display: inline-block;
  transform-origin: 50% 70%;
}

.log-head-suffix {
  display: inline;
}

.log-head-chevron {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 16px;
  height: 16px;
  color: #4b5772;
}

.log-head-chevron svg {
  width: 16px;
  height: 16px;
  display: block;
}

.log-head-btn.is-open .log-head-chevron svg {
  transform: rotate(180deg);
}

@media (hover: hover) and (pointer: fine) {
  .log-head-btn:hover {
    color: var(--accent-deep);
  }

  .log-head-btn:hover .log-head-chevron {
    color: var(--accent-deep);
  }
}

.log-head-btn:active {
  opacity: 0.84;
}

.log-progress {
  position: absolute;
  z-index: 6;
  left: var(--log-pad-x);
  right: var(--log-pad-x);
  top: calc(var(--log-pad-top) + var(--helper-row-h));
  max-height: calc(100% - var(--log-pad-top) - var(--helper-row-h));
  display: flex;
  flex-direction: column;
  align-items: stretch;
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  overflow: hidden;
  pointer-events: none;
  /* Overlay chrome — does not reflow equation cards underneath. */
}

.log-progress.is-open {
  pointer-events: auto;
}

/* White veil over equation cards while Progress is open (behind the panel). */
.equation-log::after {
  content: '';
  position: absolute;
  z-index: 5;
  left: 0;
  right: 0;
  top: calc(var(--log-pad-top) + var(--helper-row-h));
  bottom: 0;
  background: rgba(255, 255, 255, 0.78);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition:
    opacity 0.32s ease,
    visibility 0.32s ease;
}

.equation-log.is-progress-open::after {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

/* Vertical slide open/close (no fade). */
.log-progress-body {
  display: grid;
  grid-template-rows: 0fr;
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  background: var(--surface);
  color: var(--type-regular-color);
  font-size: var(--type-regular-size);
  font-weight: var(--type-regular-weight);
  line-height: 1.35;
  transition: grid-template-rows 0.32s ease;
}

.log-progress.is-open .log-progress-body {
  grid-template-rows: 1fr;
}

.log-progress-body-inner {
  overflow: hidden;
  min-height: 0;
  box-sizing: border-box;
  padding: 0;
}

.log-progress.is-open .log-progress-body-inner {
  padding: 0.35rem 0 0.5rem;
}

/* Collapsed: invisible under header. Open: full Equation Log client width. */
.log-edge {
  flex: 0 0 auto;
  align-self: flex-start;
  width: 100%;
  max-width: none;
  height: 1px;
  margin: 0;
  padding: 0;
  background: transparent;
  transition:
    width 0.32s ease,
    margin-left 0.32s ease,
    background-color 0.32s ease;
  pointer-events: none;
}

.log-progress.is-open .log-edge {
  width: calc(100% + (2 * var(--log-pad-x)));
  margin-left: calc(-1 * var(--log-pad-x));
  background: var(--line);
}

.log-progress-section {
  margin: 0 0 0.2rem;
  padding: 0;
  color: var(--muted);
  font-size: 0.9em;
  font-weight: var(--type-regular-weight);
  line-height: 1.2;
}

.log-progress-table {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  min-width: 0;
}

.log-progress-row {
  display: grid;
  /* Narrow: type | “N remain” (fit longest “100+ remain”). */
  grid-template-columns: minmax(0, 1fr) max-content;
  align-items: baseline;
  gap: 0.5rem;
  min-height: 1.35em;
  padding: 0.08rem 0;
}

/*
  Wide: Word-like tab stops — three content-sized columns grouped left,
  even gaps, unused space stays on the right (not full-bleed tracks).
*/
.log-progress-table.is-wide {
  display: grid;
  grid-template-columns: max-content max-content max-content;
  column-gap: 2rem;
  row-gap: 0.1rem;
  justify-content: start;
  width: max-content;
  max-width: 100%;
  /* start — not baseline: empty Bonus remain has no text baseline and
     was adding ~3px extra vertical gap under 4-number. */
  align-items: start;
}

.log-progress-table.is-wide .log-progress-row {
  display: contents;
}

.log-progress-table.is-wide .log-progress-type,
.log-progress-table.is-wide .log-progress-found,
.log-progress-table.is-wide .log-progress-remain {
  min-height: 1.35em;
  padding: 0.08rem 0;
}

.log-progress-type {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--type-heading-color);
  font-weight: var(--type-regular-weight);
  text-align: left;
}

.log-progress-found,
.log-progress-remain {
  box-sizing: border-box;
  min-width: 0;
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  color: var(--type-regular-color);
}

.log-progress-remain.is-na {
  color: var(--muted);
  font-variant-numeric: normal;
}

.log-progress-table:not(.is-wide) .log-progress-found {
  display: none;
}

@media (prefers-reduced-motion: reduce) {
  .log-progress-body,
  .log-edge,
  .equation-log::after,
  .log-head-btn.is-open .log-head-chevron svg {
    transition: none;
  }
}

.round-goal {
  margin: 0 0 10px;
  font-weight: var(--type-heading-weight);
  color: var(--type-heading-color);
  font-size: var(--type-heading-size);
  line-height: 1.3;
}

.status-label {
  color: var(--type-regular-color);
  font-size: var(--type-regular-size);
  font-weight: var(--type-regular-weight);
}

.timer {
  font-family: var(--font-timer);
  font-variant-numeric: tabular-nums;
  font-size: clamp(1.65rem, 4vw, 2.2rem);
  font-weight: 500;
  color: var(--accent-deep);
  letter-spacing: 0.045em;
  line-height: 1;
  margin: 3px 0 8px;
}

.goal-progress {
  margin: 0;
  font-weight: var(--type-heading-weight);
  color: var(--type-heading-color);
  font-size: var(--type-heading-size);
}

.round-status.is-compact .round-goal,
.round-status.is-compact .status-label {
  display: none;
}

.round-status.is-compact {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
}

.round-status.is-compact .timer {
  font-size: 1.22rem;
  margin: 0;
}

.round-status.is-compact .goal-progress {
  font-size: 0.92rem;
  color: var(--navy);
}

.round-status.is-compact:not(:has(.timer)) {
  justify-content: flex-start;
}

.log-list {
  position: relative;
  margin: 0;
  padding: 0;
  list-style: none;
  flex: 1;
  min-width: 0;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  align-content: start;
  gap: 7px;
  contain: inline-size;
}

.log-list li {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: center;
  flex: 0 0 auto;
  gap: 2px;
  min-width: 0;
  max-width: 100%;
  min-height: 45px;
  padding: 8px 10px 8px 14px;
  overflow: hidden;
  background: #f8f9fc;
  border-radius: 10px;
  border-bottom: 0;
  font-size: 0.92rem;
  color: var(--text-strong);
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-user-drag: none;
  -webkit-touch-callout: none;
}

.log-list li .log-eq {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  min-width: 0;
  width: 100%;
  max-width: 100%;
}

.log-list li .math {
  min-width: 0;
  white-space: nowrap;
}

.equation-log .math,
.result-log .math {
  font-family: var(--font-ui);
}

.log-list li * {
  user-select: none;
  -webkit-user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
}

.log-list li.is-dragging {
  cursor: grabbing;
}

.log-list li.is-vacant {
  background: transparent;
  box-shadow: none;
  color: transparent;
  border: 0;
  outline: var(--drop-outline);
  outline-offset: -2px;
  cursor: grabbing;
}

.log-list li.is-vacant::before {
  content: none;
}

.log-list li.is-vacant > * {
  visibility: hidden;
}

@keyframes log-arrive {
  from {
    opacity: 0.35;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.log-list li.is-log-arrive {
  animation: log-arrive 0.28s ease;
}

@media (prefers-reduced-motion: reduce) {
  .log-list li.is-log-arrive {
    animation: none;
  }
}

/* Accepted-equation transition: Squish → Card → Check → Transfer.
   Fixed overlays only — does not change layout geometry. */
.accept-eq-fly {
  --accept-pulse-scale: 1.05;
  --accept-pulse-ms: 220ms;
  --accept-resolve-ms: 180ms;
  --accept-flight-ms: 500ms;
  --accept-flight-ease: ease-in-out;
  --accept-receive-ms: 0ms;
  position: fixed;
  z-index: 95;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  padding: 0 0.55rem;
  border-radius: 12px;
  border: 1.5px solid var(--accent-border, rgba(30, 64, 120, 0.28));
  background: var(--playfield, #fff);
  box-shadow: none;
  pointer-events: none;
  transform-origin: center center;
  opacity: 1;
  transform: scale(1);
  transition: transform 0.32s var(--accept-flight-ease), opacity 0.32s ease;
  will-change: transform, opacity;
}

.accept-eq-fly.is-resolve {
  transition: transform var(--accept-resolve-ms) ease, opacity var(--accept-resolve-ms) ease, box-shadow var(--accept-resolve-ms) ease;
  box-shadow: 0 8px 22px rgba(20, 40, 80, 0.16);
}

.accept-eq-fly.is-pulse {
  transition: transform var(--accept-pulse-ms) ease, opacity var(--accept-pulse-ms) ease, box-shadow var(--accept-pulse-ms) ease;
  transform: scale(var(--accept-pulse-scale));
  box-shadow: 0 10px 26px rgba(20, 40, 80, 0.2);
}

.accept-eq-fly.is-flight {
  transform-origin: top left;
  transition: transform var(--accept-flight-ms) var(--accept-flight-ease), opacity var(--accept-flight-ms) ease;
}

.accept-eq-fly.is-fade {
  opacity: 0;
  transition: opacity 0.18s ease;
}

.accept-eq-fly-math {
  font-size: clamp(0.85rem, 2.4vw, 1.15rem);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  color: var(--ink, #1a2a44);
}

.log-list li.is-accept-emphasize {
  animation: accept-log-emphasize var(--accept-receive-ms, 0.28s) ease;
}

@keyframes accept-log-emphasize {
  from { opacity: 0.35; }
  to { opacity: 1; }
}

/* Squish / Card / Check overlays (production accept transition). */
#rail.accept-resolve-occlude {
  opacity: 0 !important;
}

.accept-resolve-stage {
  position: fixed;
  inset: 0;
  z-index: 90;
  pointer-events: none;
}

.accept-resolve-chrome-layer,
.accept-resolve-glyph-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.accept-resolve-chrome-layer { z-index: 1; }
.accept-resolve-glyph-layer { z-index: 4; }

.accept-resolve-chrome,
.accept-resolve-glyph,
.accept-resolve-card,
.accept-resolve-outline {
  position: fixed;
  box-sizing: border-box;
  pointer-events: none;
}

.accept-resolve-chrome {
  z-index: 1;
  opacity: 1;
  box-shadow: none !important;
}

.accept-resolve-card {
  z-index: 2;
  background: #ffffff;
  border: 1.5px solid var(--accent-border, rgba(30, 64, 120, 0.35));
  border-radius: 12px;
  box-shadow: none !important;
  transform: none;
  opacity: 0;
}

.accept-resolve-outline {
  z-index: 3;
  border: 0;
  opacity: 0;
  pointer-events: none;
}

.accept-resolve-glyph {
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  padding: 0;
  line-height: 1;
  white-space: nowrap;
  box-shadow: none !important;
  text-shadow: none !important;
  will-change: transform, left, top;
}

.accept-resolve-check {
  position: fixed;
  z-index: 96;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none !important;
  text-shadow: none !important;
  color: var(--teal, #087d58);
  font-family: var(--font-ui, "Nunito Sans", system-ui, sans-serif);
  font-weight: 800;
  line-height: 1;
  pointer-events: none;
  transform-origin: center center;
  opacity: 0;
  will-change: transform, opacity;
}

@media (prefers-reduced-motion: reduce) {
  .accept-eq-fly {
    transition: none !important;
    transform: none !important;
  }

  .log-list li.is-accept-emphasize {
    animation: none;
  }
}

.log-drop-line {
  position: absolute;
  left: 8px;
  right: 8px;
  height: 3px;
  border-radius: 999px;
  background: var(--accent-deep);
  box-shadow: 0 0 0 3px var(--accent-border);
  pointer-events: none;
  z-index: 2;
}

/* Stripe depth tracks equations in the family (data-log-count). */
.log-list li::before {
  position: absolute;
  inset: 0 auto 0 0;
  width: 4px;
  content: "";
  background: var(--accent-0);
}

.log-list li[data-log-count="2"]::before { background: var(--accent-25); }
.log-list li[data-log-count="3"]::before { background: var(--accent-50); }
.log-list li[data-log-count="4"]::before { background: var(--accent-75); }
.log-list li[data-log-count]:not([data-log-count="1"]):not([data-log-count="2"]):not([data-log-count="3"]):not([data-log-count="4"])::before {
  background: var(--accent-100);
}

.log-hint {
  display: grid;
  width: 20px;
  height: 20px;
  min-width: 20px;
  place-items: center;
  color: var(--accent-deep);
  justify-self: end;
}

.log-hint svg {
  width: 14px;
  height: 14px;
}

.log-index {
  display: none;
}

.log-empty {
  flex: 1 1 auto;
  min-height: 0;
  margin: 0;
  padding: 0 4px 2px;
  color: var(--type-regular-color);
  font-weight: var(--type-regular-weight);
  font-size: var(--type-regular-size);
  overflow-wrap: break-word;
}

.log-ghost {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  padding: 8px 12px 8px 14px;
  border-radius: 10px;
  background: #f8f9fc;
  color: var(--text-strong);
  font-size: 0.92rem;
  font-weight: 700;
  white-space: nowrap;
}

.log-ghost .log-eq {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.how-to {
  grid-area: how;
  overflow: hidden;
  padding: 0;
}

.how-to summary {
  display: flex;
  min-height: 54px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 17px;
  color: #26314e;
  cursor: pointer;
  font-weight: 700;
  list-style: none;
}

.how-to summary::-webkit-details-marker {
  display: none;
}

.how-to summary svg {
  width: 18px;
  height: 18px;
  transition: transform 0.16s ease;
}

.how-to[open] summary svg {
  transform: rotate(180deg);
}

.how-content {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  padding: 0 17px 17px;
  border-top: 1px solid #eceef3;
}

.how-step {
  padding-top: 14px;
  color: #5f6a82;
  font-size: 0.8rem;
  line-height: 1.4;
}

.how-number {
  display: grid;
  width: 24px;
  height: 24px;
  margin-bottom: 7px;
  place-items: center;
  color: var(--accent-on-deep);
  background: var(--accent-deep);
  border-radius: 50%;
  font-size: 0.7rem;
  font-weight: 700;
}

.overlay.overlay-center {
  align-items: center;
  justify-content: center;
  /* Same modal band as settings — must sit above .rail-block (60). */
  z-index: 100;
}

.overlay.overlay-over-grid .confirm-card {
  position: fixed;
  margin: 0;
}

.confirm-card {
  width: min(360px, 100%);
  background: var(--card);
  border-radius: 18px;
  border: 1px solid var(--line);
  padding: 20px 18px 16px;
  text-align: center;
}

.confirm-card h2 {
  margin: 0 0 8px;
  font-size: var(--type-heading-size);
  font-weight: var(--type-heading-weight);
  color: var(--type-heading-color);
}

.confirm-card p {
  margin: 0 0 16px;
  color: var(--type-regular-color);
  font-weight: var(--type-regular-weight);
  font-size: var(--type-regular-size);
  line-height: 1.4;
}

.confirm-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.confirm-actions button {
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--card);
  padding: 0.7rem;
  font-weight: 800;
  color: var(--navy);
}

.confirm-actions .btn-confirm {
  background: var(--navy);
  color: #fff;
  border-color: var(--navy);
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(var(--ink-rgb), 0.38);
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
  padding: 12px;
  /* Modal band: above .rail-block (60) and drag-ghost (80). */
  z-index: 100;
}

.overlay.overlay-settings {
  padding: 0;
  background: rgba(var(--ink-rgb), var(--settings-overlay, 0.28));
  /* Above .rail-block (60) so settings dims the whole play surface, including the rail. */
  z-index: 100;
}

.overlay.overlay-settings .settings-card {
  position: fixed;
  top: auto;
  right: auto;
  left: auto;
  margin: 0;
  /* Placement is set in placeSettingsCard() relative to #menuBtn. */
}

.settings-card {
  --settings-width: 312px;
  --settings-pad: 12px;
  --settings-radius: var(--radius-panel);
  --settings-head-min: 40px;
  --settings-section-gap: 14px;
  --settings-offset-x: 19px;
  --settings-offset-y: 27px;
  --settings-row-gap: 8px;
  --settings-row-pad: 8px;
  --settings-btn-font: 0.8rem;
  --settings-section-size: 0.7rem;
  --settings-close-size: 32px;
  box-sizing: border-box;
  width: min(var(--settings-width), calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  overflow-x: hidden;
  overflow-y: auto;
  padding: var(--settings-pad);
  background: var(--card);
  border-radius: var(--settings-radius);
  border: 1px solid var(--line);
  box-shadow: 0 16px 40px rgba(var(--ink-rgb), 0.18);
}

.settings-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--settings-row-gap);
  min-height: var(--settings-close-size, 32px);
  margin: 0 0 8px;
  padding: 0;
}

.settings-card .settings-head h2 {
  margin: 0;
  flex: 1 1 auto;
  min-width: 0;
  font-size: 1.12rem;
  font-weight: 800;
  line-height: 1.1;
  color: var(--type-heading-color);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.settings-card .coplay-session-row .helper-btn {
  width: auto;
  margin: 0;
  border: 0;
  background: transparent;
  padding: 0 6px;
  color: #4b5772;
  font-size: 0.78rem;
}

@media (hover: hover) and (pointer: fine) {
  .settings-card .coplay-session-row .helper-btn:hover:not(:disabled) {
    color: var(--accent-deep);
    background: var(--accent-tint-strong);
  }
}

.settings-head h2 {
  margin: 0;
}

.settings-card h2 {
  margin: 0 0 12px;
  font-size: var(--type-heading-size);
  font-weight: var(--type-heading-weight);
  color: var(--type-heading-color);
  line-height: 1;
}

.settings-section {
  margin: var(--settings-section-gap) 0 6px;
  padding: 0;
  font-size: var(--settings-section-size);
  font-weight: 800;
  color: var(--muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.settings-head + .settings-note,
.settings-head + .coplay-settings-meta,
.settings-head + .switch-row,
.settings-head + .coplay-shared-title {
  margin-top: 0;
}

.settings-head + .switch-row {
  padding-top: 0;
}

.settings-note {
  margin: 0 0 var(--settings-row-gap);
  padding: 0;
  color: var(--type-regular-color);
  font-weight: var(--type-regular-weight);
  font-size: var(--type-regular-size);
  line-height: 1.35;
}

.settings-card button {
  width: 100%;
  margin-top: var(--settings-row-gap);
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--card);
  padding: 0.4rem 0.45rem;
  font-weight: 700;
  font-size: var(--settings-btn-font);
  color: var(--navy);
}

.settings-card .settings-close {
  position: static;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: var(--settings-close-size);
  height: var(--settings-close-size);
  margin: 0;
  padding: 0;
  border-radius: 10px;
  border: 1px solid var(--line-strong);
  background: var(--card);
  color: #26314e;
}

.settings-card .settings-close svg {
  width: 16px;
  height: 16px;
}

.settings-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--settings-row-gap);
  margin: 0 0 4px;
}

.settings-actions button {
  flex: none;
  width: 100%;
  margin-top: 0;
  padding: 0.4rem 0.35rem;
  font-size: var(--settings-btn-font);
}

.switch-row {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: var(--settings-row-gap);
  padding: var(--settings-row-pad) 0;
  border-bottom: 1px solid var(--line);
}

.switch-row:last-child,
.switch-row:has(+ .coplay-join-inline) {
  border-bottom: none;
}

.switch-row.is-disabled {
  opacity: 0.55;
}

.switch-row.is-locked .switch {
  cursor: default;
}

.switch-row:has(+ .coplay-join-inline) .switch-copy span {
  white-space: normal;
}

.switch-copy {
  min-width: 0;
  flex: 1;
}

.switch-copy strong {
  display: block;
  font-size: var(--type-heading-size);
  font-weight: var(--type-heading-weight);
  color: var(--type-heading-color);
  line-height: 1.2;
}

.switch-copy span {
  display: block;
  margin-top: 0;
  font-size: var(--type-regular-size);
  font-weight: var(--type-regular-weight);
  color: var(--type-regular-color);
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.settings-card .switch {
  flex: 0 0 40px;
  width: 40px;
  height: 24px;
  margin: 0;
  padding: 0;
  border: none;
  border-radius: 999px;
  background: var(--switch-off);
  position: relative;
}

.settings-card .switch.is-on {
  background: var(--accent-deep);
}

.settings-card .switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(var(--ink-rgb), 0.28);
  transition: transform 0.15s ease;
}

.settings-card .switch.is-on::after {
  transform: translateX(16px);
}

.settings-card .choice-row button {
  width: auto;
}

.settings-card .preset-list {
  margin-bottom: 10px;
}

.settings-card .btn-submit {
  background: var(--teal);
  color: #fff;
  border-color: var(--teal);
}

.settings-dev-label {
  margin-top: 28px;
  font-weight: 700;
}

.settings-card .settings-dev-btn {
  font-weight: 600;
  color: var(--muted);
}

.tutorial-coach {
  grid-area: coach;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  column-gap: 16px;
  row-gap: 8px;
  width: 0;
  min-width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-panel);
  padding: 12px 14px;
}

.tutorial-copy {
  margin: 0;
  min-width: 0;
  overflow-wrap: break-word;
  color: var(--type-regular-color);
  font-size: 0.9rem;
  font-weight: var(--type-regular-weight);
  line-height: 1.4;
  align-self: center;
}

.tutorial-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.tutorial-next,
.tutorial-exit-text {
  margin: 0;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--card);
  padding: 0.45rem 0.8rem;
  font-weight: 800;
  color: var(--navy);
}

.tutorial-next {
  background: var(--accent-deep);
  color: #fff;
  border-color: var(--accent-deep);
}

.game-shell.is-tutorial {
  grid-template-rows: auto auto auto auto;
  grid-template-areas:
    "header header"
    "coach coach"
    "playfield side"
    "stamp stamp";
  row-gap: 4px;
}

.game-shell.is-tutorial.is-log-only {
  grid-template-areas:
    "header header"
    "coach coach"
    "playfield side"
    "stamp stamp";
}

.game-shell.is-tutorial .playfield {
  padding-top: 0;
}

.game-shell.is-tutorial .helper-tools {
  display: none;
}

.game-shell.is-tutorial .rail-msg {
  opacity: 0.55;
}

.game-shell.is-tutorial .picker button.is-tutorial-target {
  position: relative;
  z-index: 1;
  outline: 3px solid var(--accent-deep);
  outline-offset: 3px;
}

.game-shell.is-tutorial .header-actions {
  filter: grayscale(1);
  opacity: 0.55;
}

.tutorial-dim {
  position: fixed;
  inset: 0;
  /* Above .rail-block (60) so the mask actually dims the rail; below modal overlays (100). */
  z-index: 85;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.32s ease;
}

.tutorial-dim.is-on {
  opacity: 1;
}

.tutorial-dim-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.tutorial-dim-fill {
  fill: rgb(23 33 58 / 0.55);
}

@media (prefers-reduced-motion: reduce) {
  .tutorial-dim {
    transition: none;
  }
}

@media (max-width: 960px) {
  :root {
    /* Keep Clear/Undo/Submit in the first viewport; stop the grid from eating tall/wide phones. */
    --mobile-chrome: 15.75rem;
    --mobile-grid-budget: min(28rem, calc(100dvh - var(--mobile-chrome)));
    --mobile-shell-pad: 1.5rem;
    --mobile-shell-max: min(100%, calc(var(--mobile-grid-budget) + var(--mobile-shell-pad)));
  }

  .number-grid .tile {
    touch-action: pan-y;
  }

  .number-grid .tile.is-dragging {
    touch-action: none;
  }

  .log-list {
    touch-action: pan-y;
  }

  .log-list li {
    touch-action: pan-y;
    cursor: default;
  }

  .log-list li.is-log-readonly {
    cursor: default;
  }

  html, body {
    position: static;
    height: auto;
    min-height: 100dvh;
    overflow-x: hidden;
    overflow-y: auto;
    overflow-anchor: none;
    scrollbar-width: none;
    -ms-overflow-style: none;
  }

  html::-webkit-scrollbar,
  body::-webkit-scrollbar {
    display: none;
    width: 0;
    height: 0;
  }

  body {
    inset: auto;
    width: 100%;
  }

  #app,
  #app.is-playing {
    height: auto;
    min-height: 100dvh;
    overflow: visible;
    container-type: normal;
  }

  .game-shell {
    width: min(100%, var(--mobile-shell-max));
    max-width: var(--mobile-shell-max);
    margin-inline: auto;
    height: auto;
    min-height: 100dvh;
    overflow: visible;
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto auto auto;
    grid-template-areas:
      "header"
      "status"
      "playfield"
      "log"
      "stamp";
    padding: 6px 10px calc(10px + env(safe-area-inset-bottom, 0px));
    gap: 8px;
  }

  .game-shell.is-log-only {
    grid-template-rows: auto auto auto auto;
    grid-template-areas:
      "header"
      "playfield"
      "log"
      "stamp";
  }

  .game-shell.is-tutorial {
    grid-template-rows: auto auto auto auto auto auto;
    grid-template-areas:
      "header"
      "coach"
      "status"
      "playfield"
      "log"
      "stamp";
  }

  .game-shell.is-tutorial.is-log-only {
    grid-template-rows: auto auto auto auto auto;
    grid-template-areas:
      "header"
      "coach"
      "playfield"
      "log"
      "stamp";
  }

  .tutorial-coach {
    grid-template-columns: minmax(0, 1fr);
    width: auto;
    min-width: 0;
    align-items: stretch;
  }

  .tutorial-copy {
    justify-self: stretch;
    text-align: left;
  }

  .tutorial-actions {
    justify-content: center;
    width: 100%;
  }

  .side-column {
    display: contents;
    height: auto;
    min-height: 0;
    width: auto;
    overflow: visible;
  }

  .round-status {
    grid-area: status;
  }

  .equation-log {
    grid-area: log;
    flex: 0 0 auto;
  }

  .log-scroll {
    flex: 0 0 auto;
    overflow: visible;
    display: block;
    height: auto;
    min-height: 0;
  }

  .game-header {
    padding: 10px 12px;
  }

  .game-header h1 {
    font-size: 1.65rem;
  }

  .playfield {
    height: auto;
    overflow: visible;
    padding: 14px 12px;
    width: 100%;
    max-width: none;
    justify-self: stretch;
  }

  .rail-block {
    --rail-row-min: 52px;
  }

  .rail-scroll {
    overflow-x: hidden;
    touch-action: manipulation;
  }

  .rail-scroll.is-long {
    overflow-x: auto;
    touch-action: pan-x;
  }

  .rail {
    gap: 4px;
    padding: 4px 8px;
    width: 100%;
    min-width: 0;
    justify-content: center;
  }

  .rail-tile {
    width: 44px;
    min-width: 36px;
    height: 44px;
    flex: 0 1 44px;
    font-size: 1.55rem;
    border-width: 1.5px;
    border-radius: 5px;
  }

  .rail-tile.is-empty {
    width: 44px;
    min-width: 36px;
    height: 44px;
    flex: 0 1 44px;
    border-radius: 5px;
  }

  .rail-tile.digits-3 { font-size: 0.92rem; }

  .op-slot {
    width: 28px;
    min-width: 22px;
    height: 28px;
    flex: 0 1 28px;
    font-size: 1.2rem;
  }

  .rail-paren {
    width: 8px;
    min-width: 6px;
    height: 44px;
    font-size: 1.9rem;
    line-height: 44px;
    flex: 0 0 8px;
  }

  .picker {
    flex-wrap: nowrap;
    gap: 5px;
    min-height: 44px;
  }

  .picker button {
    width: 42px;
    height: 42px;
    flex: 0 0 42px;
    font-size: 1.45rem;
  }

  .playfield-inner {
    height: auto;
    overflow: visible;
    width: 100%;
    max-width: none;
  }

  .board-column {
    flex: 0 0 auto;
    width: 100%;
  }

  .helper-tools {
    width: 100%;
  }

  .grid-stage {
    flex: 0 0 auto;
    height: auto;
    width: 100%;
  }

  .board-stack {
    width: min(100%, var(--mobile-grid-budget));
    max-width: min(100%, var(--mobile-grid-budget));
    height: auto;
    margin-inline: auto;
  }

  .number-grid {
    width: 100%;
    flex: 0 0 auto;
    aspect-ratio: 1;
    --grid-well-pad: 8px;
    padding: var(--grid-well-pad);
  }

  .equation-log {
    min-height: 0;
    max-height: none;
    overflow: visible;
    padding: 14px 12px 8px;
    --log-pad-x: 12px;
    --log-pad-top: 14px;
  }

  .equation-log.is-progress-open {
    overflow: hidden;
    min-height: calc(
      var(--log-pad-top) + var(--helper-row-h) + var(--grid-well-pad) + 9.75rem + 8px
    );
  }

  .log-progress {
    top: calc(var(--log-pad-top) + var(--helper-row-h));
    max-height: calc(100% - var(--log-pad-top) - var(--helper-row-h));
  }

  .log-scroll {
    overflow: visible;
    height: auto;
  }

  .log-list {
    overflow: visible;
    flex: 0 0 auto;
    min-height: 0;
    max-height: none;
  }

  .log-empty {
    flex: 0 0 auto;
  }

  .log-list li {
    min-height: 40px;
    font-size: 0.88rem;
  }

  .round-status.is-compact {
    padding: 10px 12px;
  }

  .round-status.is-compact .timer {
    padding: 0 12px;
    border-left: 1px solid #e4e7ee;
    border-right: 1px solid #e4e7ee;
  }

  .how-content {
    grid-template-columns: 1fr;
    gap: 0;
  }

  .picker.has-parens {
    flex-wrap: nowrap;
    gap: 4px;
  }

  .picker.has-parens button {
    width: 42px;
    height: 42px;
    flex-basis: 42px;
    font-size: 1.4rem;
  }

  .picker.has-parens button.is-paren {
    font-size: 1.3rem;
  }

  .overlay.overlay-settings .settings-card {
    /* Mobile keeps the same button-anchored popover; JS clamps width/position. */
    border-radius: var(--settings-radius, var(--radius-panel));
    padding: var(--settings-pad, 12px);
  }

  .settings-card .coplay-settings-actions button,
  .settings-card .coplay-settings-code-row .btn-clear,
  .settings-card .coplay-join-fields .btn-submit {
    font-size: 0.8rem;
  }
}

/* Wide mobile / small tablet portrait: use more horizontal space, keep one content column,
   and enlarge the rail so it keeps pace with the (taller) capped grid. */
@media (min-width: 600px) and (max-width: 960px) {
  :root {
    --mobile-chrome: 18.5rem;
    /*
      One content column for header/playfield/log.
      Cap the square grid so it fills most of a tablet without dwarfing the rail.
    */
    --mobile-grid-budget: min(34rem, calc(100vw - 2.75rem), calc(100dvh - var(--mobile-chrome)));
    --mobile-shell-pad: 1.5rem;
    --mobile-shell-max: min(100%, calc(var(--mobile-grid-budget) + var(--mobile-shell-pad)));
  }

  .game-shell {
    width: min(100%, var(--mobile-shell-max));
    max-width: var(--mobile-shell-max);
    margin-inline: auto;
  }

  .board-stack {
    width: min(100%, var(--mobile-grid-budget));
    max-width: min(100%, var(--mobile-grid-budget));
  }

  .rail-block {
    --rail-row-min: 64px;
    padding: 8px 12px 10px;
  }

  .rail-tile {
    width: 60px;
    min-width: 52px;
    height: 60px;
    flex: 0 1 60px;
    font-size: 1.95rem;
  }

  .rail-tile.is-empty {
    width: 60px;
    min-width: 52px;
    height: 60px;
    flex: 0 1 60px;
  }

  .rail-tile.digits-3 { font-size: 1.15rem; }

  .op-slot {
    width: 36px;
    min-width: 30px;
    height: 36px;
    flex: 0 1 36px;
    font-size: 1.45rem;
  }

  .rail-paren {
    height: 60px;
    line-height: 60px;
    font-size: 2.3rem;
  }

  .picker {
    gap: 7px;
    min-height: 54px;
  }

  .picker button,
  .picker.has-parens button {
    width: 52px;
    height: 52px;
    flex: 0 0 52px;
    flex-basis: 52px;
    font-size: 1.65rem;
  }

  .picker.has-parens button.is-paren {
    font-size: 1.5rem;
  }
}

@media (max-width: 430px) {
  .game-header h1 {
    font-size: 1.4rem;
  }
}

/* Short but wide viewports: shrink the grid first; trim the rail only as needed.
   Operator picker stays a single row. */
@media (min-width: 801px) and (max-height: 820px) {
  :root {
    --grid-floor: 13rem; /* ~208px floor; prefer scroll over illegible tiles below this */
  }

  .board-stack {
    width: min(100%, max(var(--grid-floor), calc(100dvh - 20rem)));
    max-width: min(var(--desk-grid-max), max(var(--grid-floor), calc(100dvh - 20rem)));
    min-width: var(--grid-floor);
    margin-inline: auto;
  }

  .playfield-inner {
    gap: clamp(4px, 0.8vh, 8px);
  }

  .rail-block {
    --rail-row-min: 48px;
    padding: 6px 10px 8px;
    gap: 4px;
  }

  .rail-tile {
    width: 42px;
    min-width: 42px;
    height: 42px;
    font-size: 1.55rem;
  }

  .rail-tile.digits-3 { font-size: 0.96rem; }

  .rail-paren {
    height: 42px;
  }

  .op-slot {
    width: 30px;
    min-width: 30px;
    height: 30px;
    font-size: 1.35rem;
  }

  .picker {
    flex-wrap: nowrap;
    gap: 5px;
    min-height: 40px;
  }

  .picker button {
    width: 40px;
    height: 40px;
    flex: 0 0 40px;
    font-size: 1.45rem;
  }

  .picker.has-parens button {
    width: 40px;
    height: 40px;
    flex-basis: 40px;
    font-size: 1.4rem;
  }

  .picker.has-parens button.is-paren {
    font-size: 1.3rem;
  }
}

@media (min-width: 801px) and (max-height: 720px) {
  .board-stack {
    width: min(100%, max(var(--grid-floor), calc(100dvh - 17rem)));
    max-width: min(420px, max(var(--grid-floor), calc(100dvh - 17rem)));
  }

  .rail-block {
    --rail-row-min: 44px;
    padding: 5px 8px 6px;
  }

  .rail-tile {
    width: 40px;
    min-width: 40px;
    height: 40px;
    font-size: 1.45rem;
  }

  .rail-tile.digits-3 { font-size: 0.9rem; }

  .rail-paren {
    height: 40px;
  }

  .op-slot {
    width: 28px;
    min-width: 28px;
    height: 28px;
    font-size: 1.25rem;
  }

  .picker {
    gap: 4px;
    min-height: 36px;
  }

  .picker button,
  .picker.has-parens button {
    width: 36px;
    height: 36px;
    flex: 0 0 36px;
    flex-basis: 36px;
    font-size: 1.3rem;
  }

  .picker.has-parens button.is-paren {
    font-size: 1.2rem;
  }
}

@media (min-width: 801px) and (max-height: 660px) {
  html, body {
    position: static;
    height: auto;
    min-height: 100dvh;
    overflow-x: hidden;
    overflow-y: auto;
  }

  body {
    inset: auto;
  }

  #app.is-playing {
    height: auto;
    min-height: 100dvh;
    overflow: visible;
  }

  .game-shell {
    max-height: none;
    overflow: visible;
  }

  .board-stack {
    width: min(100%, max(var(--grid-floor), calc(100dvh - 15rem)));
    max-width: min(420px, max(var(--grid-floor), calc(100dvh - 15rem)));
  }
}

/*
  Phone / short landscape (option B): grid + rail stacked as one unit on the left;
  Equation Log sits to the right. Each log column is sized for the longest
  landscape equation line + hint sparkle (~170px at the landscape log font).
  The log panel is 2× that so two columns are in view; column-gap may peek
  past the right edge as a scroll cue.
  Drag disabled (tap-only). Rotate-to-portrait remains the fallback if this fails.
  Mode is owned by html.is-short-land (JS latch). Entry uses stable svh height;
  exit is portrait or width > 960 — not live max-height chrome jitter.
*/
html.is-short-land {
  /* Header + rail stack under the grid (log is beside, not below). */
  --land-chrome: 13.5rem;
  /*
    Min playable Number Grid (3×3 drives the floor):
    - Cards ≥40px to match --land-rail-tile tap size and keep numerals
      from overflowing (card-numeral floor 1.05rem ≈ card×0.46).
    - Gaps ≈3px ×2; well pad 4px ×2 → 3×40 + 6 + 8 = 134px ≈ 8.375rem.
    Rail tiles stay 40px, ops 22px, Submit/Clear/picker ≥34px (fixed below).
    Below this budget, allow page scroll rather than crushing controls.
  */
  --land-grid-min: 8.375rem;
  --land-grid: max(
    var(--land-grid-min),
    min(calc(100svh - var(--land-chrome)), 100%, 11.5rem)
  );
  /* Longest log line (e.g. (99 + 99) × 9 = 1782) + padding + sparkle. */
  --log-eq-col: 170px;
  --log-col-gap: 10px;
  --log-col-w: var(--log-eq-col);
  /* Start at exactly 2× one equation column. */
  --land-log: calc(var(--log-eq-col) * 2);
  --land-rail-tile: 40px;
  --land-rail-op: 22px;
  /* Wide enough for 4 numbers + 3 ops from the start. */
  --land-rail-min: calc(
    (4 * var(--land-rail-tile)) + (3 * var(--land-rail-op)) + 28px
  );
  /* Same pairing as desktop: helper row ↔ log head; grid pad ↔ first log cards. */
  --helper-row-h: 34px;
  --grid-well-pad: 4px;
}

html.is-short-land,
html.is-short-land body {
    position: static;
    height: auto;
    min-height: 100svh;
    overflow-x: hidden;
    overflow-y: auto;
    overflow-anchor: none;
  }

html.is-short-land body {
    inset: auto;
    width: 100%;
  }

html.is-short-land #app,
html.is-short-land #app.is-playing {
    height: auto;
    min-height: 100svh;
    overflow: visible;
    container-type: normal;
  }

html.is-short-land .game-shell,
html.is-short-land .game-shell.is-log-only,
html.is-short-land .game-shell.is-tutorial,
html.is-short-land .game-shell.is-tutorial.is-log-only {
    width: 100%;
    max-width: none;
    margin-inline: 0;
    height: auto;
    min-height: 0;
    max-height: none;
    overflow: visible;
    grid-template-columns: minmax(0, 1fr) var(--land-log);
    grid-template-rows: auto minmax(0, 1fr) auto;
    grid-template-areas:
      "header header"
      "playfield log"
      "stamp stamp";
    padding: 2px 8px calc(4px + env(safe-area-inset-bottom, 0px));
    padding-left: calc(8px + env(safe-area-inset-left, 0px));
    padding-right: calc(8px + env(safe-area-inset-right, 0px));
    gap: 4px 8px;
    align-items: stretch;
  }

html.is-short-land .game-shell.is-tutorial {
    grid-template-rows: auto auto minmax(0, 1fr) auto;
    grid-template-areas:
      "header header"
      "coach coach"
      "playfield log"
      "stamp stamp";
  }

/* Deferred post-V1.2: tutorial coach placement is wrong on some short
     landscape phones; revisit with the Help Me / tutorial rework. */

html.is-short-land .side-column {
    display: contents;
  }

html.is-short-land .round-status {
    display: none;
  }

html.is-short-land .game-header {
    grid-area: header;
    padding: 4px 8px;
    min-height: 0;
  }

html.is-short-land .game-header h1 {
    font-size: 1.05rem;
  }

html.is-short-land .game-mark {
    flex: 0 0 24px;
    width: 24px;
    height: 24px;
    border-radius: 7px;
  }

html.is-short-land .icon-btn {
    width: 28px;
    height: 28px;
  }

html.is-short-land .icon-btn.is-coplay {
    min-width: 28px;
    padding-left: 6px;
  }

html.is-short-land .icon-btn.is-coplay .icon-btn-gear {
    width: 28px;
    height: 28px;
    flex-basis: 28px;
  }

html.is-short-land .icon-btn.is-coplay .icon-btn-gear svg,
html.is-short-land .icon-btn > svg {
    width: 16px;
    height: 16px;
  }

html.is-short-land .playfield {
    grid-area: playfield;
    width: 100%;
    max-width: none;
    justify-self: stretch;
    /* Size the playfield|log row; log fills that height (desktop side-column pattern). */
    align-self: start;
    height: auto;
    overflow: visible;
    padding: 4px 6px;
  }

html.is-short-land .playfield-inner {
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: none;
    height: auto;
    max-height: none;
    gap: 4px;
  }

html.is-short-land .board-column {
    width: 100%;
    max-width: none;
    min-width: 0;
    gap: 2px;
  }

html.is-short-land .helper-tools {
    width: 100%;
    column-gap: 10px;
    row-gap: 0;
    /* Middle control stays on the playfield center; side controls hug it. */
    grid-template-columns: 1fr auto auto auto 1fr;
  }

html.is-short-land .helper-tools .helper-btn:nth-child(1) { grid-column: 2; }

html.is-short-land .helper-tools .helper-btn:nth-child(2) { grid-column: 3; }

html.is-short-land .helper-tools .helper-btn:nth-child(3) { grid-column: 4; }

html.is-short-land .helper-tools .helper-btn {
    height: var(--helper-row-h);
    min-height: var(--helper-row-h);
    padding: 0 8px;
    font-size: 0.76rem;
    border-radius: 10px;
  }

html.is-short-land .helper-tools .helper-btn svg {
    width: 14px;
    height: 14px;
  }

html.is-short-land .grid-stage {
    width: 100%;
    min-height: 0;
  }

html.is-short-land .board-stack {
    width: min(100%, var(--land-grid));
    max-width: min(100%, var(--land-grid));
    min-width: 0;
    margin-inline: auto;
  }

html.is-short-land .number-grid {
    width: 100%;
    aspect-ratio: 1;
    padding: var(--grid-well-pad);
    gap: clamp(2px, 0.8svh, 5px);
  }

html.is-short-land .rail-block {
    --rail-row-min: 40px;
    width: fit-content;
    max-width: 100%;
    min-width: min(100%, var(--land-rail-min));
    margin-inline: auto;
    padding: 4px 6px 4px;
    gap: 3px;
  }

html.is-short-land .rail-empty {
    font-size: clamp(0.52rem, 1.95svh, 0.68rem);
    gap: 1px;
  }

html.is-short-land .rail-scroll {
    overflow-x: auto;
    touch-action: pan-x;
  }

html.is-short-land .rail {
    justify-content: center;
    gap: 3px;
    padding: 1px 2px;
  }

html.is-short-land .rail-tile {
    width: var(--land-rail-tile);
    min-width: 34px;
    height: var(--land-rail-tile);
    flex: 0 0 var(--land-rail-tile);
    font-size: 1.35rem;
  }

html.is-short-land .rail-tile.is-empty {
    width: var(--land-rail-tile);
    min-width: 34px;
    height: var(--land-rail-tile);
    flex: 0 0 var(--land-rail-tile);
    border-radius: 6px;
  }

html.is-short-land .rail-tile.digits-3 { font-size: 0.82rem; }

html.is-short-land .op-slot {
    width: var(--land-rail-op);
    min-width: 18px;
    height: var(--land-rail-op);
    flex: 0 0 var(--land-rail-op);
    font-size: 1.05rem;
  }

html.is-short-land .rail-paren {
    height: var(--land-rail-tile);
    line-height: var(--land-rail-tile);
    font-size: 1.6rem;
  }

html.is-short-land .picker {
    flex-wrap: nowrap;
    gap: 4px;
    min-height: 34px;
  }

html.is-short-land .picker button,
html.is-short-land .picker.has-parens button {
    width: 34px;
    height: 34px;
    flex: 0 0 34px;
    flex-basis: 34px;
    font-size: 1.2rem;
  }

html.is-short-land .picker.has-parens button.is-paren {
    font-size: 1.05rem;
  }

html.is-short-land .rail-actions {
    width: 100%;
    min-width: 0;
    column-gap: 10px;
    row-gap: 0;
    /* Middle control stays on the playfield center; side controls hug it. */
    grid-template-columns: 1fr auto auto auto 1fr;
  }

html.is-short-land .rail-actions .helper-btn:nth-child(1) { grid-column: 2; }

html.is-short-land .rail-actions .helper-btn:nth-child(2) { grid-column: 3; }

html.is-short-land .rail-actions .helper-btn:nth-child(3) { grid-column: 4; }

html.is-short-land .rail-actions .helper-btn {
    min-height: 34px;
    padding: 5px 8px;
    font-size: 0.76rem;
    border-radius: 10px;
  }

html.is-short-land .rail-actions .helper-btn svg {
    width: 14px;
    height: 14px;
  }

html.is-short-land .equation-log {
    grid-area: log;
    align-self: stretch;
    width: 100%;
    max-width: none;
    min-width: 0;
    /* Match playfield panel height: do not let log content inflate the row. */
    height: 0;
    min-height: 100%;
    max-height: none;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    /* Top pad matches playfield so log-head lines up with helper tools. */
    padding: 4px 8px 8px;
    --log-pad-x: 8px;
    --log-pad-top: 4px;
  }

html.is-short-land .log-head {
    flex: 0 0 auto;
    position: relative;
    z-index: 7;
    height: var(--helper-row-h);
    min-height: var(--helper-row-h);
    margin: 0 0 var(--grid-well-pad);
    padding: 0;
    align-items: center;
    background: var(--surface);
  }

html.is-short-land .log-head h2,
html.is-short-land .side-title,
html.is-short-land .log-head-btn {
    font-size: clamp(0.72rem, 2.2svh, 0.92rem);
    line-height: 1;
  }

html.is-short-land .log-head-chevron,
html.is-short-land .log-head-chevron svg {
    width: 14px;
    height: 14px;
  }

html.is-short-land .log-progress {
    top: calc(var(--log-pad-top) + var(--helper-row-h));
    max-height: calc(100% - var(--log-pad-top) - var(--helper-row-h));
  }

html.is-short-land .log-scroll {
    flex: 1 1 auto;
    display: block;
    min-height: 0;
    height: 0;
    overflow-x: auto;
    overflow-y: hidden;
    overscroll-behavior-x: contain;
    touch-action: pan-x;
    -webkit-overflow-scrolling: touch;
  }

html.is-short-land .log-list {
    display: block;
    height: 100%;
    width: max-content;
    max-width: none;
    min-width: calc(var(--log-eq-col) * 2 + var(--log-col-gap));
    min-height: 0;
    overflow: visible;
    margin: 0;
    padding: 0;
    list-style: none;
    column-width: var(--log-eq-col);
    column-gap: var(--log-col-gap);
    column-fill: auto;
    gap: 0;
    contain: none;
  }

html.is-short-land .log-list li {
    break-inside: avoid;
    -webkit-column-break-inside: avoid;
    page-break-inside: avoid;
    box-sizing: border-box;
    width: var(--log-eq-col);
    min-width: var(--log-eq-col);
    max-width: var(--log-eq-col);
    margin: 0 0 6px;
    min-height: 34px;
    padding: 5px 8px 5px 12px;
    /* Same row box as before; type tracks short viewport like rail-empty / messages. */
    font-size: clamp(0.62rem, 2.05svh, 0.82rem);
    cursor: default;
    touch-action: pan-x;
    overflow: hidden;
  }

html.is-short-land .log-list li .log-eq {
    width: 100%;
    max-width: 100%;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 6px;
  }

html.is-short-land .log-list li .log-hint {
    width: 20px;
    min-width: 20px;
    height: 20px;
    justify-self: end;
  }

html.is-short-land .log-list li .log-hint svg {
    width: 12px;
    height: 12px;
  }

html.is-short-land .log-empty {
    min-height: 0;
    padding: 8px 0;
  }

html.is-short-land .build-stamp {
    grid-area: stamp;
    margin: 0;
    font-size: 0.55rem;
  }

html.is-short-land .feedback {
    font-size: 0.72rem;
  }

html.is-short-land #app.is-tap-only .number-grid .tile,
html.is-short-land #app.is-tap-only .rail-tile,
html.is-short-land #app.is-tap-only .op-slot,
html.is-short-land #app.is-tap-only .picker button {
    touch-action: manipulation;
    cursor: pointer;
  }


/* Very narrow short-landscape: one log column so play can fit a 4-number rail. */
@media (max-width: 640px) {
  html.is-short-land {
    --land-log: var(--log-eq-col);
  }
}

@media (prefers-reduced-motion: reduce) {
  .tile,
  .drag-ghost,
  .how-to summary svg,
  .tile.is-hint,
  .tile.is-hint.is-hint-fading,
  .number-grid .tile.is-grid-restore,
  .feedback.is-accepted,
  .feedback.is-neutral,
  .feedback.is-rejected,
  .feedback.is-accepted.is-leaving,
  .feedback.is-neutral.is-leaving,
  .feedback.is-rejected.is-leaving {
    transition: none;
    animation: none;
  }

  .number-grid.is-shuffling .tile {
    transform: none;
    opacity: 1;
  }

  .tile.is-hint {
    animation: none;
  }
}


/* —— Rail message card (rounded lip + stub behind rail; grows up for text) —— */
.rail-msg {
  /* Fallbacks; border/outer/inner synced from rail + tiles in JS. */
  --msg-border: 8px;
  --msg-outer-radius: 14px;
  --msg-inner-radius: 6px;
  --msg-font-size: 0.88rem;
  --msg-body-pad: 0.35rem 0.85rem 0.4rem;
  position: fixed;
  z-index: 40;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  pointer-events: none;
  /* Outer radius stays rail-matched; accent ring is padding over gradient. */
  padding: var(--msg-border);
  background: var(--accent-gradient);
  border: 0;
  border-radius: var(--msg-outer-radius);
  box-shadow: none;
  transition: none;
}

.rail-msg.is-animating {
  transition: height 0.28s ease, top 0.28s ease;
}

/* White fill with concentric inner radius (outer stays rail-matched). Always painted;
   closed peek stays accent-only via peek height ≤ border thickness. */
.rail-msg::before {
  content: "";
  position: absolute;
  inset: var(--msg-border);
  z-index: 0;
  border-radius: var(--msg-inner-radius);
  background: #ffffff;
  pointer-events: none;
}

.rail-msg-body,
.rail-msg-spacer {
  position: relative;
  z-index: 1;
}

.rail-msg-body {
  flex: 0 0 auto;
  min-height: 0;
  padding: var(--msg-body-pad);
}

.rail-msg:not(.is-ready) .rail-msg-body,
.rail-msg.is-closing .rail-msg-body {
  visibility: hidden;
}

.rail-msg:not(.is-open) .rail-msg-body {
  padding: 0;
  height: 0;
  overflow: hidden;
}

/* Fills the hidden stub behind the rail so text stays in the above-rail zone. */
.rail-msg-spacer {
  flex: 1 1 auto;
  min-height: 0;
}

.rail-msg-text {
  margin: 0;
  text-align: center;
  font-weight: 700;
  font-size: var(--msg-font-size);
  line-height: 1.35;
  color: var(--ink);
  pointer-events: none;
}

.rail-msg-text.is-tap {
  pointer-events: auto;
  cursor: pointer;
}

.rail-msg-text .math {
  font-weight: 700;
  /* Keep equation strings intact; wrap before/after the whole expression, never mid-equation. */
  display: inline-block;
  white-space: nowrap;
}

@media (prefers-reduced-motion: reduce) {
  .rail-msg {
    transition: none;
  }
}

/* Short landscape: shrink type to the rail/grid budget so copy is not clipped. */
html.is-short-land .rail-msg {
  --msg-font-size: clamp(0.58rem, 2.15svh, 0.72rem);
  --msg-body-pad: 0.16rem 0.5rem 0.18rem;
}
