:root {
  --bg: #0d1020;
  --panel: rgba(255, 255, 255, 0.05);
  --panel-border: rgba(255, 255, 255, 0.09);
  --text: #eef0ff;
  --muted: #8d93b8;
  --you: #6c8cff;
  --jev: #26d7a4;
  --pause: #f5b942;
  --danger: #ff5a6e;
  --btn: #1d2344;
  --btn-press: #2b3363;
  --radius: 14px;
  --gutter: 10px;
  --mode: var(--muted);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: radial-gradient(120% 80% at 50% 0%, #1b2150 0%, var(--bg) 60%) fixed, var(--bg);
  color: var(--text);
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
}

button {
  font: inherit;
  color: inherit;
}

[hidden] {
  display: none !important;
}

.app {
  height: 100vh;
  height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: max(6px, env(safe-area-inset-top)) max(var(--gutter), env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom))
    max(var(--gutter), env(safe-area-inset-left));
}

.app.mode-you {
  --mode: var(--you);
}
.app.mode-jev {
  --mode: var(--jev);
}
.app.mode-paused {
  --mode: var(--pause);
}
.app.mode-over {
  --mode: var(--danger);
}

/* HUD strip */
.hud {
  display: grid;
  grid-template-columns: 1.35fr 0.9fr 0.8fr 1fr 40px 40px;
  gap: 5px;
  flex: none;
}

.stat {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 3px 7px 4px;
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 42px;
}

.stat .label {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
}

.stat .value {
  font-size: 17px;
  line-height: 1.2;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stat.next {
  position: relative;
}

.stat.next canvas {
  position: absolute;
  right: 5px;
  bottom: 4px;
  width: 44px;
  height: 26px;
}

.icon-btn {
  height: 42px;
  border-radius: 10px;
  border: 1px solid var(--panel-border);
  background: var(--panel);
  display: grid;
  place-items: center;
  cursor: pointer;
  padding: 0;
}

.icon-btn svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: var(--text);
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-btn svg.solid {
  fill: var(--text);
  stroke: none;
}

/* Board */
.stage {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  justify-content: center;
  align-items: center;
}

.board-wrap {
  position: relative;
}

#board {
  display: block;
  border-radius: 8px;
  background: #080a16;
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--mode) 70%, transparent), 0 0 22px color-mix(in srgb, var(--mode) 30%, transparent),
    0 10px 40px rgba(0, 0, 0, 0.45);
  transition: box-shadow 0.25s ease;
}

.toast {
  position: absolute;
  left: 50%;
  top: 18%;
  transform: translate(-50%, -6px);
  background: rgba(8, 10, 22, 0.85);
  border: 1px solid var(--mode);
  color: var(--text);
  font-weight: 700;
  font-size: 15px;
  padding: 8px 14px;
  border-radius: 999px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(8, 10, 22, 0.8);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  border-radius: 8px;
  padding: 14px;
  overflow-y: auto;
}

.overlay-card {
  text-align: center;
  width: 100%;
  max-width: 290px;
}

.overlay-card h2 {
  margin: 0 0 6px;
  font-size: 22px;
}

.overlay-card p {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.overlay-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.btn {
  border: 0;
  border-radius: 12px;
  padding: 13px 14px;
  font-weight: 700;
  font-size: 15px;
  cursor: pointer;
  background: var(--btn);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.btn svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
}

.btn svg .dot {
  fill: currentColor;
  stroke: none;
}

.btn.primary {
  background: var(--you);
  color: #0b0e20;
}

.btn.jev {
  background: var(--jev);
  color: #062a20;
}

.btn.ghost {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.25);
}

.settings {
  margin-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  text-align: left;
  font-size: 12px;
  color: var(--muted);
}

.settings label {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  cursor: pointer;
}

.settings input {
  accent-color: var(--jev);
  margin: 1px 0 0;
  width: 16px;
  height: 16px;
  flex: none;
}

.settings b {
  color: var(--text);
  font-weight: 600;
}

.overlay-card .best {
  margin: 12px 0 0;
  font-size: 12px;
}

.overlay-card .keys {
  display: none;
  margin: 8px 0 0;
  font-size: 11px;
}

@media (hover: hover) and (pointer: fine) {
  .overlay-card .keys {
    display: block;
  }
}

/* Status line: who is playing */
.status {
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
  height: 26px;
  min-width: 0;
  font-size: 13px;
}

.pill {
  flex: none;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.1em;
  padding: 4px 9px;
  border-radius: 999px;
  color: #0b0e20;
  background: var(--mode);
}

.status-text {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--muted);
}

.status-text b {
  color: var(--text);
}

/* Controls */
.controls {
  flex: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.pad {
  display: grid;
  grid-template-columns: 1fr 1fr 14px 1fr 1fr;
  gap: 8px;
}

.pad .ctl[data-action="turn_left"] {
  grid-column: 4;
}

.pad .ctl[data-action="turn_right"] {
  grid-column: 5;
}

.row2 {
  display: grid;
  grid-template-columns: 1fr 1.25fr;
  gap: 8px;
}

.ctl {
  height: clamp(48px, 7vh, 60px);
  border-radius: var(--radius);
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: linear-gradient(180deg, #232a52, var(--btn));
  box-shadow: 0 3px 0 #0a0d1f, inset 0 1px 0 rgba(255, 255, 255, 0.06);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  touch-action: none;
  transition: transform 0.05s ease, background 0.05s ease, opacity 0.2s ease;
  padding: 0 8px;
  min-width: 0;
}

.ctl svg {
  width: 26px;
  height: 26px;
  flex: none;
  fill: none;
  stroke: var(--text);
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.ctl .dot {
  fill: var(--text);
  stroke: none;
}

.ctl.rot {
  background: linear-gradient(180deg, #34295e, #261d48);
}

.ctl span {
  font-weight: 700;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ctl.pressed,
.ctl:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #0a0d1f;
  background: var(--btn-press);
}

/* While Jev plays, the move buttons still work: pressing one takes over. */
.mode-jev .ctl[data-action] {
  opacity: 0.55;
}

.jev-btn {
  background: linear-gradient(180deg, #17493f, #113a32);
  border-color: rgba(38, 215, 164, 0.4);
}

.jev-btn svg {
  stroke: var(--jev);
}

.jev-btn .dot {
  fill: var(--jev);
}

.jev-btn span {
  color: var(--jev);
}

.jev-btn .icon-you {
  display: none;
}

/* Jev playing: the button becomes "Take over" in the player's colour. */
.mode-jev .jev-btn {
  background: linear-gradient(180deg, #2c3a7a, #222c63);
  border-color: rgba(108, 140, 255, 0.55);
  box-shadow: 0 3px 0 #0a0d1f, 0 0 18px rgba(108, 140, 255, 0.25);
}

.mode-jev .jev-btn svg,
.mode-jev .jev-btn span {
  stroke: var(--text);
  color: var(--text);
}

.mode-jev .jev-btn .icon-jev {
  display: none;
}

.mode-jev .jev-btn .icon-you {
  display: block;
}

@media (max-height: 640px) {
  .ctl {
    height: 46px;
  }
  .stat {
    height: 38px;
  }
  .stat .value {
    font-size: 15px;
  }
}
