@font-face {
  font-family: LCDLocal;
  src: local("Courier New");
}

:root {
  color-scheme: dark;
  --case: #1d1d19;
  --case-edge: #34342b;
  --case-soft: #25251f;
  --panel: #141510;
  --panel-edge: #444337;
  --lcd: #b8c5a3;
  --lcd-dark: #1b2418;
  --lcd-ink: #151b13;
  --text: #f2f0e6;
  --muted: #b7b39c;
  --primary: #d8d0a0;
  --secondary: #32342c;
  --utility: #22231e;
  --danger: #5b2b27;
  --shadow: rgba(0, 0, 0, 0.42);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 20% 0%, rgba(216, 208, 160, 0.08), transparent 30%),
    linear-gradient(145deg, #0e0f0d, #24231d 55%, #10110f);
  color: var(--text);
}

body {
  margin: 0;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
}

.app {
  width: min(100%, 520px);
  min-height: 100svh;
  margin: 0 auto;
  padding: 4px 6px 12px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.04), transparent 15%),
    var(--case);
  border-inline: 1px solid rgba(255, 255, 255, 0.06);
  box-shadow: 0 22px 60px var(--shadow);
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

.app button,
.lcd-bezel,
.control-bank,
.keypad {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

.app input,
.app textarea,
.app select,
.app pre,
#output {
  -webkit-touch-callout: default;
  -webkit-user-select: text;
  user-select: text;
}

.boot-screen {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: block;
  padding: 18px 20px;
  border-radius: 9px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.1), transparent 16%),
    var(--lcd);
  color: var(--lcd-ink);
  opacity: 1;
  overflow: hidden;
  transition: opacity 180ms ease;
}

.boot-screen.is-complete {
  opacity: 0;
}

.boot-intro {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 10px;
  padding: 18px;
  font-family: LCDLocal, ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  text-align: center;
  text-transform: uppercase;
  overflow: hidden;
}

.boot-screen.is-post .boot-intro,
.boot-screen.is-intro .boot-device {
  opacity: 0;
  pointer-events: none;
}

.boot-screen.is-post .boot-device {
  opacity: 1;
}

.boot-intro::before,
.boot-intro::after {
  content: "";
  position: absolute;
  left: 8%;
  right: 8%;
  top: 50%;
  height: 2px;
  background: rgba(21, 27, 19, 0.72);
  transform-origin: center;
  animation: lcdFlashLine 760ms steps(4, end) both;
}

.boot-intro::after {
  top: auto;
  bottom: 50%;
  animation-delay: 110ms;
}

.boot-logo-text {
  position: relative;
  z-index: 2;
  font-size: clamp(2.25rem, 11vw, 4.4rem);
  font-weight: 900;
  line-height: 0.9;
  letter-spacing: 0.04em;
  text-shadow:
    0 1px 0 rgba(255, 255, 255, 0.26),
    0 0 1px rgba(21, 27, 19, 0.6);
  animation: lcdLogoBurst 1550ms steps(10, end) both;
}

.boot-logo-sub {
  position: relative;
  z-index: 2;
  font: 900 clamp(0.75rem, 3.4vw, 1.05rem) ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  letter-spacing: 0.18em;
  animation: lcdSubWake 1550ms steps(8, end) both;
}

.boot-piece {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 1;
  color: var(--lcd-ink);
  font: 900 clamp(2.2rem, 12vw, 4.2rem) "Times New Roman", Georgia, serif;
  line-height: 1;
  opacity: 0;
  filter: contrast(1.3);
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.22);
  transform: translate(-50%, -50%) scale(0.22);
  animation: lcdPieceBurst 1450ms steps(9, end) both;
}

.boot-piece-a { --burst-x: -96px; --burst-y: -64px; --burst-r: -24deg; animation-delay: 40ms; }
.boot-piece-b { --burst-x: 94px; --burst-y: -60px; --burst-r: 22deg; animation-delay: 90ms; }
.boot-piece-c { --burst-x: -104px; --burst-y: 50px; --burst-r: 18deg; animation-delay: 150ms; }
.boot-piece-d { --burst-x: 102px; --burst-y: 54px; --burst-r: -20deg; animation-delay: 205ms; }
.boot-piece-e { --burst-x: -34px; --burst-y: -88px; --burst-r: 28deg; animation-delay: 260ms; }
.boot-piece-f { --burst-x: 32px; --burst-y: 92px; --burst-r: -26deg; animation-delay: 315ms; }
@keyframes lcdLogoBurst {
  0% { opacity: 0; transform: scale(0.22); filter: blur(2px); }
  18% { opacity: 1; transform: scale(1.18); filter: blur(0); }
  34% { transform: scale(0.94); }
  50% { transform: scale(1.03); }
  76% { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(1.04); }
}

@keyframes lcdSubWake {
  0%, 28% { opacity: 0; transform: translateY(8px); }
  42%, 78% { opacity: 1; transform: translateY(0); }
  100% { opacity: 0; transform: translateY(-2px); }
}

@keyframes lcdPieceBurst {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.2) rotate(0); }
  14% { opacity: 0.96; transform: translate(-50%, -50%) scale(0.78) rotate(0); }
  46% { opacity: 0.9; transform: translate(calc(-50% + var(--burst-x) * 0.58), calc(-50% + var(--burst-y) * 0.58)) scale(1.02) rotate(calc(var(--burst-r) * 0.55)); }
  82% { opacity: 0.72; transform: translate(calc(-50% + var(--burst-x)), calc(-50% + var(--burst-y))) scale(0.92) rotate(var(--burst-r)); }
  100% { opacity: 0; transform: translate(calc(-50% + var(--burst-x) * 1.08), calc(-50% + var(--burst-y) * 1.08)) scale(0.72) rotate(var(--burst-r)); }
}

@keyframes lcdFlashLine {
  0% { opacity: 0; transform: scaleX(0); }
  26% { opacity: 0.86; transform: scaleX(1); }
  100% { opacity: 0; transform: scaleX(1); }
}
.boot-device {
  opacity: 0;
  transition: opacity 140ms steps(2, end);
  width: 100%;
  height: 100%;
  display: grid;
  align-content: start;
  gap: 7px;
  font-family: LCDLocal, ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  text-transform: uppercase;
}

.boot-title {
  font-size: clamp(1.55rem, 7vw, 2.35rem);
  font-weight: 900;
  line-height: 0.95;
  letter-spacing: 0.04em;
}

.boot-subtitle,
.boot-heading,
.boot-line {
  font: 900 clamp(0.68rem, 2.9vw, 0.94rem) ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  letter-spacing: 0.08em;
}

.boot-subtitle {
  margin-bottom: 12px;
}

.boot-heading {
  margin: 4px 0 2px;
}

.boot-lines {
  display: grid;
  gap: 5px;
  min-height: 0;
  overflow: hidden;
}

.boot-line {
  white-space: pre-wrap;
  animation: bootLineReveal 120ms steps(2, end) both;
}

@keyframes bootLineReveal {
  from { opacity: 0; transform: translateY(2px); }
  to { opacity: 1; transform: translateY(0); }
}

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

  .boot-line,
  .boot-logo-text,
  .boot-logo-sub,
  .boot-piece,
  .boot-intro::before,
  .boot-intro::after {
    animation: none;
  }
}
.lcd-wrap {
  margin: 0 0 12px;
  padding: 5px;
  border: 1px solid #4a493d;
  border-radius: 16px;
  background: linear-gradient(145deg, #11120f, #2b2b24);
  box-shadow:
    inset 0 0 0 2px #0b0c0a,
    0 12px 22px rgba(0, 0, 0, 0.36);
}

.lcd-bezel {
  position: relative;
  overflow: hidden;
  min-height: clamp(492px, 68svh, 620px);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 10px;
  padding: 10px;
  border: 3px solid #090b08;
  border-radius: 12px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.12), transparent 16%),
    var(--lcd);
  color: var(--lcd-ink);
  box-shadow: inset 0 0 18px rgba(19, 27, 16, 0.48);
}

.lcd-bezel.is-booting > :not(.boot-screen) {
  visibility: hidden;
}

.lcd-top {
  position: absolute;
  inset: 8px auto auto 8px;
  z-index: 3;
  display: flex;
  align-items: center;
}

.lcd-level {
  margin-left: 8px;
  font: 900 0.86rem ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  letter-spacing: 0.08em;
  line-height: 1;
}

.lcd-subrow {
  display: flex;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font: 900 0.86rem ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  letter-spacing: 0.12em;
}

.lcd-main {
  min-width: 0;
  block-size: clamp(2.35rem, 10vw, 3.15rem);
  display: flex;
  align-items: center;
  justify-content: center;
  align-self: center;
  width: 100%;
  overflow: hidden;
  white-space: nowrap;
  text-align: center;
  font-family: LCDLocal, ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: clamp(1.9rem, 8.8vw, 2.75rem);
  font-weight: 900;
  line-height: 0.96;
  letter-spacing: 0;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.32);
}

.lcd-main-medium,
.lcd-main-long,
.lcd-main-xlong {
  font-size: clamp(1.9rem, 8.8vw, 2.75rem);
}

.lcd-board-row {
  --captured-tray-height: 46px;
  justify-self: center;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: stretch;
  gap: 8px;
  width: min(100%, 498px);
}

.lcd-board-row:has(.eval-bar.hidden) {
  grid-template-columns: minmax(0, 1fr);
  gap: 0;
  width: min(100%, 452px);
}

.lcd-board-frame {
  justify-self: center;
  display: grid;
  grid-template-columns: clamp(12px, 3vw, 16px) minmax(0, 1fr) clamp(6px, 1.4vw, 10px);
  grid-template-rows: auto clamp(14px, 3.4vw, 17px) var(--captured-tray-height);
  gap: 1px;
  width: min(100%, 452px);
  min-width: 0;
  align-self: start;
}

.lcd-board-frame.is-list {
  display: block;
  width: min(100%, 390px);
}

.lcd-board-frame.is-list .lcd-ranks,
.lcd-board-frame.is-list .lcd-files,
.lcd-board-frame.is-list .lcd-captured {
  display: none;
}

.lcd-board {
  grid-column: 2;
  grid-row: 1;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  width: 100%;
  aspect-ratio: 1 / 1;
  border: 2px solid rgba(21, 27, 19, 0.72);
  background: rgba(21, 27, 19, 0.12);
  box-shadow: inset 0 0 0 1px rgba(21, 27, 19, 0.18);
}

.lcd-ranks {
  grid-column: 1;
  grid-row: 1;
  display: grid;
  grid-template-rows: repeat(8, 1fr);
  align-items: center;
  justify-items: center;
  font: 900 clamp(0.7rem, 2.45vw, 0.82rem) ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color: var(--lcd-ink);
}

.lcd-files {
  grid-column: 2;
  grid-row: 2;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  align-items: center;
  justify-items: center;
  font: 900 clamp(0.7rem, 2.45vw, 0.82rem) ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color: var(--lcd-ink);
}

.lcd-captured {
  grid-column: 2;
  grid-row: 3;
  display: grid;
  grid-template-rows: repeat(2, 21px);
  align-self: end;
  gap: 2px;
  min-width: 0;
  padding-top: 2px;
  color: var(--lcd-ink);
  font: 900 clamp(0.61rem, 2.2vw, 0.72rem) ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.lcd-captured-row {
  display: grid;
  grid-template-columns: 13px minmax(0, 1fr) auto;
  align-items: center;
  gap: 3px;
  min-width: 0;
  border-top: 1px solid rgba(21, 27, 19, 0.18);
}

.lcd-captured-side {
  line-height: 1;
}

.lcd-captured-pieces {
  display: flex;
  align-items: center;
  gap: 3px;
  min-width: 0;
  height: 20px;
  overflow: hidden;
}

.lcd-captured-group {
  display: inline-flex;
  align-items: center;
  flex: 0 0 auto;
  height: 20px;
}

.lcd-captured-piece {
  display: inline-grid;
  place-items: center;
  width: 19px;
  height: 19px;
}

.lcd-captured-piece .lcd-piece-icon {
  width: 19px;
  height: 19px;
}

.lcd-captured-count {
  margin-left: -1px;
  font-size: 0.62rem;
  line-height: 1;
}

.lcd-material-lead {
  min-width: 20px;
  text-align: right;
  line-height: 1;
}

.eval-bar {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  justify-items: center;
  gap: 3px;
  width: 28px;
  align-self: start;
  min-height: 0;
  color: var(--lcd-ink);
  font: 900 0.64rem ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.eval-track {
  position: relative;
  width: 13px;
  min-height: 0;
  border: 2px solid rgba(21, 27, 19, 0.68);
  background: rgba(21, 27, 19, 0.28);
  overflow: hidden;
}

.eval-fill {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  height: 50%;
  background: rgba(184, 197, 163, 0.62);
  box-shadow: inset 0 0 0 1px rgba(21, 27, 19, 0.16);
}

.eval-marker {
  position: absolute;
  right: -4px;
  left: -4px;
  bottom: 50%;
  height: 2px;
  background: var(--lcd-ink);
  transform: translateY(1px);
}

.eval-label {
  white-space: nowrap;
  text-align: center;
  line-height: 1;
}

.eval-side {
  line-height: 1;
}

.lcd-square {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  border: 1px solid rgba(21, 27, 19, 0.16);
}

.lcd-square-light {
  background: rgba(184, 197, 163, 0.28);
}

.lcd-square-dark {
  background: rgba(21, 27, 19, 0.1);
}

.lcd-piece {
  display: grid;
  place-items: center;
  width: 92%;
  height: 92%;
  color: var(--lcd-ink);
}

.lcd-king-checkmated {
  transform-origin: 50% 88%;
  animation: kingCheckmated 700ms 120ms ease-in-out both;
}

@keyframes kingCheckmated {
  0%, 12% { transform: rotate(0deg); }
  24% { transform: rotate(-8deg); }
  38% { transform: rotate(7deg); }
  50% { transform: rotate(-5deg); }
  62% { transform: rotate(4deg); }
  100% { transform: translateX(18%) rotate(78deg); }
}

@media (prefers-reduced-motion: reduce) {
  .lcd-king-checkmated {
    animation: none;
    transform: translateX(18%) rotate(78deg);
  }
}

.lcd-piece-icon {
  width: 100%;
  height: 100%;
  overflow: visible;
}

.lcd-piece-white .lcd-piece-icon path {
  fill: none;
  stroke: currentColor;
  stroke-width: 2.4;
  stroke-linejoin: round;
  stroke-linecap: round;
  opacity: 0.92;
}

.lcd-piece-black .lcd-piece-icon path {
  fill: currentColor;
  stroke: none;
  opacity: 0.86;
}

.lcd-piece-black .lcd-piece-icon .lcd-bishop-cut {
  fill: none;
  stroke: var(--lcd);
  stroke-width: 2.6;
  stroke-linecap: round;
  opacity: 0.96;
}

.lcd-last-from::after,
.lcd-last-to::after {
  content: "";
  position: absolute;
  inset: 2px;
  border: 2px solid rgba(21, 27, 19, 0.58);
  pointer-events: none;
}

.lcd-last-to::after {
  background: rgba(21, 27, 19, 0.08);
}

.lcd-check::before {
  content: "!";
  position: absolute;
  top: 0;
  right: 2px;
  z-index: 1;
  color: var(--lcd-ink);
  font: 900 0.7rem ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.lcd-move-list {
  display: block;
  width: min(100%, 390px);
  aspect-ratio: auto;
  block-size: min(42svh, 292px);
  padding: 6px;
  overflow-y: auto;
  scrollbar-width: thin;
}

.lcd-move-row {
  display: grid;
  grid-template-columns: 2.1rem minmax(0, 1fr) minmax(0, 1fr);
  gap: 5px;
  align-items: center;
  min-height: 28px;
  font: 900 0.86rem ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.lcd-move-no,
.lcd-move-cell {
  min-width: 0;
  color: var(--lcd-ink);
}

.lcd-move-cell {
  min-height: 24px;
  padding: 2px 4px;
  border: 1px solid transparent;
  background: transparent;
  overflow: hidden;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
  font: inherit;
}

.lcd-move-grade {
  display: inline-block;
  inline-size: 1.45em;
  block-size: 1.45em;
  margin-left: 4px;
  padding: 0;
  border: 1px solid rgba(21, 27, 19, 0.38);
  border-radius: 999px;
  background: rgba(21, 27, 19, 0.1);
  text-align: center;
  font-size: 0.62rem;
  line-height: 1.35;
  vertical-align: 0.08em;
}

.lcd-move-cell:disabled {
  opacity: 0.35;
}

.lcd-move-selected {
  border-color: rgba(21, 27, 19, 0.58);
  background: rgba(21, 27, 19, 0.12);
}

.lcd-move-empty {
  display: grid;
  min-height: 100%;
  place-items: center;
  color: var(--lcd-ink);
  font: 900 0.9rem ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.lcd-review-summary {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 5px;
  width: min(100%, 390px);
  aspect-ratio: auto;
  block-size: min(42svh, 292px);
  padding: 8px;
  overflow: hidden;
}

.review-summary-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  align-items: center;
  gap: 6px;
  font: 900 0.6rem ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color: var(--lcd-ink);
}

.review-summary-head strong {
  display: grid;
  place-items: center;
  min-height: 26px;
  border: 1px solid rgba(21, 27, 19, 0.58);
  border-radius: 4px;
  background: rgba(184, 197, 163, 0.24);
  font-size: 0.86rem;
}

.review-summary-score {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 4px;
}

.review-summary-score:last-child {
  grid-template-columns: minmax(0, 1fr) auto;
}

.review-summary-score:last-child strong {
  order: -1;
}

.review-summary-rows {
  display: grid;
  align-content: start;
  gap: 2px;
  min-height: 0;
}

.review-summary-row {
  display: grid;
  grid-template-columns: 1fr 28px 1.7fr 1fr;
  align-items: center;
  gap: 4px;
  min-height: 18px;
  color: var(--lcd-ink);
  font: 900 clamp(0.78rem, 3.35vw, 1rem) ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.review-summary-row b {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border: 1px solid rgba(21, 27, 19, 0.55);
  border-radius: 50%;
  background: rgba(21, 27, 19, 0.1);
  font-size: 0.58rem;
  font-style: normal;
}

.review-summary-row em {
  font-style: normal;
}

.review-summary-row span:last-child {
  text-align: right;
}

.review-summary-progress {
  color: var(--lcd-ink);
  font: 900 0.64rem ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  letter-spacing: 0.08em;
  text-align: center;
}

.lcd-review-graph {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 6px;
  width: min(100%, 390px);
  aspect-ratio: auto;
  block-size: min(42svh, 292px);
  padding: 8px;
  overflow: hidden;
  border: 0;
  background: transparent;
  box-shadow: none;
}

.review-graph-plot {
  position: relative;
  min-height: 0;
  border: 2px solid rgba(21, 27, 19, 0.72);
  background:
    repeating-linear-gradient(
      to right,
      rgba(21, 27, 19, 0.14) 0,
      rgba(21, 27, 19, 0.14) 1px,
      transparent 1px,
      transparent 12.5%
    ),
    repeating-linear-gradient(
      to bottom,
      rgba(21, 27, 19, 0.1) 0,
      rgba(21, 27, 19, 0.1) 1px,
      transparent 1px,
      transparent 25%
    );
}

.review-graph-centre {
  position: absolute;
  inset-inline: 0;
  top: 50%;
  border-top: 2px solid rgba(21, 27, 19, 0.72);
}

.review-graph-labels {
  position: absolute;
  inset: 5px 6px;
  display: grid;
  grid-template-rows: auto 1fr auto;
  color: rgba(21, 27, 19, 0.8);
  font: 900 0.52rem ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  pointer-events: none;
}

.review-graph-labels span:nth-child(2) {
  align-self: center;
}

.review-graph-labels span:last-child {
  align-self: end;
}

.review-graph-point {
  position: absolute;
  width: 10px;
  height: 10px;
  min-height: 0;
  padding: 0;
  border: 2px solid var(--lcd-ink);
  border-radius: 50%;
  background: var(--lcd-ink);
  box-shadow: 0 0 0 1px rgba(184, 197, 163, 0.45);
  transform: translate(-50%, -50%);
}

.review-graph-point.is-black {
  background: rgba(21, 27, 19, 0.24);
}

.review-graph-point.is-book {
  width: 8px;
  height: 8px;
  border-radius: 2px;
  background: rgba(21, 27, 19, 0.16);
}

.review-graph-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--lcd-ink);
  font: 900 0.8rem ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.review-graph-footer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  color: var(--lcd-ink);
  font: 900 clamp(0.78rem, 3.35vw, 1rem) ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  letter-spacing: 0.08em;
}

.review-graph-footer strong {
  font-size: 0.76rem;
}


.legacy-controls {
  display: none;
}

.lcd-menu {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-auto-rows: minmax(32px, auto);
  align-content: start;
  gap: 2px;
  width: min(100%, 390px);
  aspect-ratio: auto;
  block-size: min(42svh, 292px);
  padding: 8px;
  overflow: hidden;
  border: 2px solid rgba(21, 27, 19, 0.72);
  background: rgba(21, 27, 19, 0.08);
  box-shadow: inset 0 0 0 1px rgba(21, 27, 19, 0.16);
}

.lcd-menu-row {
  display: grid;
  grid-template-columns: 20px minmax(0, 1fr) 18px;
  align-items: center;
  gap: 6px;
  min-width: 0;
  min-height: 32px;
  padding: 3px 5px;
  border: 1px solid transparent;
  border-radius: 3px;
  color: var(--lcd-ink);
  font: 900 clamp(0.78rem, 3.35vw, 1rem) ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  letter-spacing: 0.04em;
  text-align: left;
  box-shadow: none;
  background: transparent;
}

.lcd-menu-row.is-selected {
  border-color: rgba(21, 27, 19, 0.68);
  background: rgba(21, 27, 19, 0.13);
}

.lcd-menu-cursor,
.lcd-menu-next {
  display: inline-grid;
  place-items: center;
  color: var(--lcd-ink);
}

.lcd-menu-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lcd-menu-empty {
  display: grid;
  min-height: 100%;
  place-items: center;
  color: var(--lcd-ink);
  font: 900 0.8rem ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.lcd-sub,
.entry-state {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.entry-state {
  flex: 0 0 auto;
}

.lcd-sub {
  flex: 1 1 0;
}

.lcd-menu-button {
  flex: 0 0 34px;
  width: 34px;
  min-height: 28px;
  display: grid;
  place-content: center;
  gap: 4px;
  padding: 5px;
  border: 1px solid rgba(21, 27, 19, 0.6);
  border-radius: 4px;
  background: rgba(21, 27, 19, 0.08);
  box-shadow: none;
}

.lcd-top .lcd-menu-button {
  width: 31px;
  min-height: 27px;
  padding: 5px;
  background: rgba(21, 27, 19, 0.05);
}

.lcd-menu-button span {
  display: block;
  width: 17px;
  height: 3px;
  background: var(--lcd-ink);
  opacity: 0.9;
}

.turn-indicator {
  flex: 0 0 34px;
  width: 34px;
  height: 28px;
  border: 2px solid var(--lcd-ink);
  border-radius: 4px;
  background: transparent;
  opacity: 0.94;
}

.turn-indicator.turn-black {
  background: var(--lcd-ink);
}

.turn-indicator.is-thinking {
  animation: turnThinkingFlash 720ms steps(2, end) infinite;
}

@keyframes turnThinkingFlash {
  50% {
    opacity: 0.28;
  }
}

.control-bank,
.drawer {
  margin: 10px 0;
  padding: 11px;
  border: 1px solid var(--panel-edge);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.045), transparent 34%),
    var(--panel);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

.move-bank {
  padding-top: 12px;
  background: linear-gradient(180deg, #181a14, #11120f);
}

.section-label,
.drawer > summary,
.subdrawer > summary {
  color: var(--muted);
  font: 900 0.82rem ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.section-label {
  margin-bottom: 9px;
}

button,
select {
  min-width: 0;
  font: 800 0.92rem system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button {
  min-height: 48px;
  padding: 12px 10px;
  border: 1px solid #5b594c;
  border-radius: 7px;
  background: var(--secondary);
  color: var(--text);
  cursor: pointer;
  box-shadow: 0 2px 0 #080908;
}

button:active {
  transform: translateY(1px);
  box-shadow: 0 1px 0 #080908;
}

button:disabled,
select:disabled {
  opacity: 0.45;
  cursor: default;
}

select {
  width: 100%;
  min-height: 42px;
  border: 1px solid #5b594c;
  border-radius: 6px;
  background: #24241f;
  color: var(--text);
}

.buttons {
  display: grid;
  gap: 8px;
  margin-top: 9px;
}

.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.four {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.game-actions {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.advanced-actions {
  align-items: stretch;
}

.move-entry-grid {
  display: grid;
  grid-template-columns: minmax(0, 4fr) minmax(88px, 1.35fr);
  gap: 8px;
  align-items: stretch;
}

.keypad {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.keypad button {
  aspect-ratio: 1.22 / 1;
  min-height: 54px;
  background: #24271f;
  border-color: #686650;
  color: #faf5dc;
  font: 900 1.38rem ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  text-transform: uppercase;
}

.command-row {
  display: grid;
  grid-template-rows: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.command-row button {
  min-height: 0;
}

#playMove.has-new-game-hold {
  position: relative;
  padding-top: 18px;
}

#playMove.has-new-game-hold::before {
  content: "HOLD NEW";
  position: absolute;
  inset-block-start: 6px;
  inset-inline: 7px;
  color: rgba(21, 27, 19, 0.68);
  font: 900 clamp(0.52rem, 1.8vw, 0.66rem) ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  line-height: 1;
  text-align: right;
}

#playMove.is-long-press-arming {
  box-shadow:
    inset 0 0 0 2px rgba(21, 27, 19, 0.3),
    0 0 0 1px rgba(232, 219, 143, 0.38);
}

.keypad .expect {
  border-color: var(--primary);
}

.keypad .setup-choice-selected {
  border-color: var(--accent);
  color: #fffbe6;
  box-shadow:
    inset 0 0 0 2px rgba(232, 219, 143, 0.22),
    0 0 0 1px rgba(232, 219, 143, 0.22);
}

.setup-key {
  position: relative;
  display: block;
  padding: 5px 4px;
  overflow: hidden;
}

.setup-key-fn {
  position: absolute;
  inset-block-start: 7px;
  inset-inline: 7px;
  gap: 3px;
  min-width: 0;
  color: rgba(250, 245, 220, 0.72);
  font-size: clamp(0.58rem, 2vw, 0.72rem);
  line-height: 1;
}

.setup-key-fn.has-piece {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
}

.setup-key-fn.text-only {
  inset-inline: 4px;
  display: grid;
  place-items: center;
  justify-content: center;
}

.setup-key-main {
  position: absolute;
  inset-inline: 0;
  inset-block-end: 9px;
  color: #faf5dc;
  font-size: clamp(1.18rem, 5vw, 1.52rem);
  line-height: 1;
  text-align: center;
}

.setup-key-piece {
  display: grid;
  place-items: center;
  inline-size: clamp(15px, 4.8vw, 22px);
  block-size: clamp(15px, 4.8vw, 22px);
}

.setup-key-piece .lcd-piece-icon {
  inline-size: 100%;
  block-size: 100%;
}

.setup-key-piece-text {
  min-width: 0;
  overflow: hidden;
  font-weight: 900;
  line-height: 1;
  padding-top: 1px;
  text-overflow: clip;
  white-space: nowrap;
}

.play-key {
  position: relative;
  display: block;
  padding: 5px 4px;
  overflow: hidden;
}

.play-key-fn {
  position: absolute;
  inset-block-start: 7px;
  inset-inline: 7px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 3px;
  min-width: 0;
  color: rgba(250, 245, 220, 0.7);
  font-size: clamp(0.52rem, 1.8vw, 0.66rem);
  line-height: 1;
}

.play-key-symbol {
  flex: 0 0 auto;
  font-weight: 900;
}

.play-key-label {
  min-width: 0;
  overflow: hidden;
  font-weight: 900;
  text-overflow: clip;
  white-space: nowrap;
}

.play-key-main {
  position: absolute;
  inset-inline: 0;
  inset-block-end: 9px;
  color: #faf5dc;
  font-size: clamp(1.18rem, 5vw, 1.52rem);
  line-height: 1;
  text-align: center;
}

.play-key.is-long-press-arming {
  border-color: #eee4ae;
  box-shadow:
    inset 0 0 0 2px rgba(232, 219, 143, 0.28),
    0 0 0 1px rgba(232, 219, 143, 0.3);
}

.menu-shift-key {
  display: grid;
  grid-template-rows: auto 1fr;
  place-items: center;
  gap: 2px;
  padding: 7px 4px 6px;
}

.menu-key-file {
  color: rgba(250, 245, 220, 0.64);
  font-size: clamp(0.62rem, 2vw, 0.74rem);
  line-height: 1;
  letter-spacing: 0.08em;
}

.menu-key-symbol {
  color: #faf5dc;
  font-size: clamp(1.18rem, 4.6vw, 1.72rem);
  line-height: 1;
}

.menu-shift-key[aria-label="Select"] .menu-key-symbol,
.menu-shift-key[aria-label="Exit menu"] .menu-key-symbol {
  font-size: clamp(0.95rem, 3.7vw, 1.3rem);
  letter-spacing: 0.02em;
}

.primary-action {
  background: linear-gradient(180deg, #eee4ae, #c7bb77);
  border-color: #f8edb8;
  color: #181713;
}

.secondary-action {
  background: var(--secondary);
}

.utility-action {
  background: var(--utility);
  color: #dad7c4;
}

.danger {
  background: var(--danger);
  border-color: #86504b;
}

.play-bank button {
  min-height: 46px;
  padding-inline: 6px;
  font-size: 0.78rem;
}

.drawer {
  padding: 0;
}

.drawer > summary,
.subdrawer > summary {
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  cursor: pointer;
  list-style: none;
}

.drawer > summary::-webkit-details-marker,
.subdrawer > summary::-webkit-details-marker {
  display: none;
}

.drawer > summary::after,
.subdrawer > summary::after {
  content: "+";
  color: var(--text);
  font-size: 1rem;
}

.drawer[open] > summary::after,
.subdrawer[open] > summary::after {
  content: "-";
}

.drawer-body {
  padding: 0 11px 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.selector-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 11px;
}

.selector-tile {
  display: flex;
  min-height: 58px;
  flex-direction: column;
  justify-content: center;
  gap: 3px;
  text-align: left;
}

.selector-tile span {
  color: var(--muted);
  font-size: 0.72rem;
  text-transform: uppercase;
}

.selector-tile strong {
  font-size: 0.92rem;
  letter-spacing: 0.04em;
}

.row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  margin-top: 10px;
}

.setup-row {
  grid-template-columns: auto minmax(0, 1fr) auto minmax(0, 1fr);
  padding: 10px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 7px;
  background: #10110e;
}

.setup-row label:nth-of-type(3),
.setup-row #setupSide,
.setup-buttons,
#exitSetup {
  grid-column: 1 / -1;
}

.setup-buttons {
  margin-top: 2px;
}

label {
  color: var(--muted);
  font-weight: 800;
  font-size: 0.8rem;
  text-transform: uppercase;
}

pre {
  max-height: 180px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0;
  padding: 10px;
  border-radius: 6px;
  background: #090a08;
  color: #d8d4bd;
  font: 0.78rem/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.subdrawer {
  margin-top: 10px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 7px;
  background: #10110e;
}

.picker {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: end center;
  padding: 18px 14px max(18px, env(safe-area-inset-bottom));
  background: rgba(0, 0, 0, 0.58);
}

.picker-panel {
  width: min(100%, 492px);
  padding: 12px;
  border: 1px solid var(--panel-edge);
  border-radius: 10px;
  background: #181914;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.55);
}

.picker-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}

.picker-head h2 {
  margin: 0;
  font-size: 0.92rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.picker-head button {
  min-height: 38px;
  padding: 8px 10px;
}

.picker-options {
  display: grid;
  gap: 8px;
}

.picker-options button {
  text-align: left;
}

.pgn-import-text {
  width: 100%;
  min-height: 190px;
  resize: vertical;
  padding: 10px;
  border: 1px solid var(--panel-edge);
  border-radius: 6px;
  background: #10110e;
  color: var(--text);
  font: 700 0.82rem ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  line-height: 1.45;
}

.pgn-import-actions {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.pgn-import-actions button {
  text-align: center;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.hidden {
  display: none;
}

@media (orientation: landscape) and (min-width: 600px) and (max-height: 600px) {
  .app {
    width: min(100%, 1040px);
    min-height: 100svh;
    display: grid;
    grid-template-columns: minmax(0, 3fr) minmax(280px, 2fr);
    align-items: center;
    gap: 8px;
    padding: 4px 6px;
  }

  .lcd-wrap {
    min-width: 0;
    margin: 0;
  }

  .lcd-bezel {
    height: calc(100svh - 18px);
    min-height: 0;
    max-height: 590px;
    gap: 4px;
    padding: 8px;
  }

  .lcd-main,
  .lcd-main-medium,
  .lcd-main-long,
  .lcd-main-xlong {
    block-size: 2.2rem;
    font-size: clamp(1.75rem, 7svh, 2.4rem);
  }

  .lcd-board-row,
  .lcd-board-row:has(.eval-bar.hidden) {
    width: min(100%, calc(100svh - 102px));
  }

  .lcd-board-frame {
    --captured-tray-height: 34px;
    grid-template-rows: auto 14px var(--captured-tray-height);
    width: min(100%, calc(100svh - 138px));
  }

  .lcd-board-frame.is-list {
    width: min(100%, calc(100svh - 116px));
  }

  .lcd-ranks,
  .lcd-files,
  .lcd-captured,
  .lcd-subrow {
    font-size: 0.7rem;
  }

  .move-bank {
    min-width: 0;
    margin: 0;
    padding: 10px;
  }

  .move-entry-grid {
    grid-template-columns: minmax(0, 4fr) minmax(80px, 1.35fr);
  }

  .keypad button {
    min-height: clamp(48px, 14svh, 64px);
    aspect-ratio: auto;
  }
}
@media (max-width: 390px) {
  .app {
    padding: 2px 4px 10px;
  }

  .lcd-bezel {
  position: relative;
  overflow: hidden;
  min-height: min(69svh, 520px);
    padding: 8px;
  }

  .lcd-main {
    block-size: 2.65rem;
    font-size: clamp(1.85rem, 8.5vw, 2.35rem);
  }

  .lcd-main-medium,
  .lcd-main-long,
  .lcd-main-xlong {
    font-size: clamp(1.85rem, 8.5vw, 2.35rem);
  }


  .lcd-board-row {
    grid-template-columns: minmax(0, 1fr) auto;
    width: 100%;
  }

  .lcd-board-row:has(.eval-bar.hidden) {
    grid-template-columns: minmax(0, 1fr);
    width: 100%;
  }

  .lcd-board-frame {
    width: 100%;
  }


  .four {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .advanced-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .move-entry-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .command-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: none;
  }

  .command-row button {
    min-height: 46px;
  }

  button {
    min-height: 46px;
    padding: 10px 8px;
  }
}



