/* Pong Programming Battle — dark arcade, neon player/enemy hues.
   Palette roles: player=mint, enemy=coral, warn=amber, info=sky. */
:root {
  --bg: #0a0e17;
  --panel: #101724;
  --panel2: #0d1320;
  --edge: #223046;
  --text: #e8eef7;
  --dim: #93a4bd;
  --player: #33f2a6;
  --enemy: #ff5c8c;
  --warn: #ff9e3d;
  --info: #6fb7ff;
  --accent: #ffd84d;
  --cta: #33f2a6;
}

* {
  box-sizing: border-box;
}
html,
body {
  height: 100%;
}
body {
  margin: 0;
  background: radial-gradient(120% 100% at 50% 0%, #101a2c 0%, var(--bg) 60%);
  color: var(--text);
  font-family: 'Hiragino Kaku Gothic ProN', 'Noto Sans JP', system-ui, sans-serif;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  overscroll-behavior: none;
}
button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: max(env(safe-area-inset-top), 8px) max(env(safe-area-inset-right), 14px) 6px
    max(env(safe-area-inset-left), 14px);
  gap: 8px;
  flex-wrap: wrap;
}
#topbar h1 {
  font-size: clamp(15px, 2.4vw, 20px);
  margin: 0;
  letter-spacing: 0.04em;
  background: linear-gradient(90deg, var(--player), var(--accent), var(--enemy));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.top-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}
.chip {
  border: 1px solid var(--edge);
  background: var(--panel);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 12px;
  min-height: 44px;
}
.switch {
  display: flex;
  gap: 6px;
  align-items: center;
  font-size: 12px;
  color: var(--dim);
  min-height: 44px;
}
.switch input {
  width: 20px;
  height: 20px;
  accent-color: var(--player);
}

/* ---- hero ---- */
#hero {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  background: radial-gradient(90% 90% at 50% 20%, #131f36 0%, #070a12 75%);
  text-align: center;
  padding: 24px;
}
body[data-hero='done'] #hero,
#hero[hidden] {
  display: none;
}
.hero-inner {
  max-width: 560px;
}
.kicker {
  color: var(--accent);
  letter-spacing: 0.3em;
  font-size: 13px;
}
#hero h2 {
  font-size: clamp(22px, 4.6vw, 36px);
  line-height: 1.35;
  margin: 10px 0 26px;
}
.hero-btns {
  display: flex;
  gap: 12px;
  justify-content: center;
}
.cta {
  background: linear-gradient(135deg, var(--player), #18c8ff);
  color: #04121a;
  font-weight: 700;
  border: 0;
  border-radius: 14px;
  padding: 13px 26px;
  font-size: 16px;
  min-height: 48px;
  box-shadow: 0 6px 30px rgba(51, 242, 166, 0.35);
}
.cta:disabled {
  opacity: 0.45;
  cursor: wait;
}
.ghost {
  background: transparent;
  border: 1px solid var(--edge);
  border-radius: 14px;
  padding: 13px 20px;
  min-height: 48px;
  color: var(--dim);
}
#how-panel {
  margin-top: 20px;
  text-align: left;
  background: var(--panel);
  border: 1px solid var(--edge);
  border-radius: 12px;
  padding: 6px 18px;
  color: var(--dim);
  font-size: 14px;
  line-height: 1.7;
}

/* ---- stage ---- */
#stage {
  flex: 1;
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 380px);
  grid-template-rows: minmax(0, 1fr) auto;
  grid-template-areas:
    'board bench'
    'editor bench';
  gap: 10px;
  padding: 0 max(env(safe-area-inset-right), 12px) max(env(safe-area-inset-bottom), 12px)
    max(env(safe-area-inset-left), 12px);
  min-height: 0;
}
#board {
  grid-area: board;
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}
#editor-panel {
  grid-area: editor;
  /* Its CodeMirror grows to document height; cap the panel so the board
     row keeps its space and the editor scrolls internally instead.
     Scrollable (not clipped) so the variable-watch rows under the
     editor stay reachable in the capped view. */
  max-height: 42dvh;
  overflow: auto;
  min-height: 0;
}
#bench {
  grid-area: bench;
}
#hud {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 2px 6px;
}
.score {
  font-size: clamp(26px, 4vw, 42px);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.score #score-l {
  color: var(--player);
}
.score #score-r {
  color: var(--enemy);
}
.score em {
  font-style: normal;
  color: var(--dim);
  margin: 0 8px;
}
.hud-meta {
  display: flex;
  gap: 14px;
  font-size: 13px;
  color: var(--dim);
  font-variant-numeric: tabular-nums;
}
#hud-wind {
  color: var(--info);
  font-weight: 700;
}
#court {
  flex: 1;
  width: 100%;
  min-height: 0;
  border-radius: 14px;
  border: 1px solid var(--edge);
  background: #05070d;
  touch-action: none;
}
.stam-row {
  display: flex;
  gap: 10px;
  padding: 6px 4px 0;
}
.stam-row meter {
  flex: 1;
  height: 8px;
}
meter::-webkit-meter-bar {
  background: #1a2334;
  border: 0;
  border-radius: 4px;
}
#stam-l::-webkit-meter-optimum-value {
  background: var(--player);
}
#stam-r::-webkit-meter-optimum-value {
  background: var(--enemy);
}
meter::-moz-meter-bar {
  background: var(--player);
}

#banner {
  position: absolute;
  top: 52%;
  left: 50%;
  transform: translate(-50%, -50%);
  padding: 8px 22px;
  border-radius: 999px;
  font-weight: 800;
  font-size: clamp(16px, 3vw, 26px);
  background: rgba(8, 12, 20, 0.82);
  border: 1px solid var(--edge);
  pointer-events: none;
  animation: banner-pop 0.18s ease-out;
}
#banner[data-kind='good'] {
  color: var(--player);
  border-color: var(--player);
}
#banner[data-kind='bad'] {
  color: var(--enemy);
  border-color: var(--enemy);
}
#banner[data-kind='warn'] {
  color: var(--warn);
  border-color: var(--warn);
}
#banner[data-kind='info'] {
  color: var(--info);
  border-color: var(--info);
}
@keyframes banner-pop {
  from {
    transform: translate(-50%, -50%) scale(0.7);
  }
}

#phase-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  text-align: center;
  gap: 10px;
  background: rgba(5, 8, 14, 0.45);
  border-radius: 14px;
}
#phase-overlay[hidden] {
  display: none;
}
#overlay-title {
  font-size: clamp(34px, 7vw, 72px);
  margin: 0;
  font-weight: 900;
  text-shadow: 0 0 40px rgba(255, 216, 77, 0.4);
}
#overlay-sub {
  color: var(--dim);
  margin: 0;
}
#boot-bar {
  position: absolute;
  left: 12px;
  bottom: 12px;
  color: var(--dim);
  font-size: 13px;
}

/* ---- bench ---- */
#bench {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
  overflow-y: auto;
}
.panel {
  background: var(--panel);
  border: 1px solid var(--edge);
  border-radius: 12px;
  padding: 10px 12px;
}
.panel h3 {
  margin: 0 0 8px;
  font-size: 13px;
  color: var(--dim);
  font-weight: 600;
  letter-spacing: 0.06em;
}
.panel.grow {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 240px;
}
.hint {
  margin: 0 0 6px;
  font-size: 12px;
  color: var(--dim);
}
.picks {
  display: grid;
  gap: 6px;
}
.pick {
  display: grid;
  gap: 2px;
  text-align: left;
  background: var(--panel2);
  border: 1px solid var(--edge);
  border-radius: 10px;
  padding: 8px 10px;
  min-height: 44px;
}
.pick b {
  font-size: 13px;
}
.pick span {
  font-size: 12px;
  color: var(--dim);
}
.pick i {
  font-size: 11px;
  color: var(--info);
  font-style: normal;
}
.pick.on {
  border-color: var(--player);
  box-shadow: 0 0 0 1px var(--player) inset;
}
.pick.locked,
.pick[disabled] {
  opacity: 0.45;
}
.pick.locked {
  cursor: not-allowed;
}
.pick.boss {
  border-color: var(--enemy);
  box-shadow:
    0 0 0 1px var(--enemy) inset,
    0 0 16px rgba(255, 54, 85, 0.22);
}
.pick.boss b::before {
  content: '♛ ';
  color: var(--enemy);
}
/* Execution-line trace in the editor: last line flashes hot, recently-run
   lines fade, brain errors mark the failing line. */
.CodeMirror .cm-exec-run {
  background: rgba(60, 200, 130, 0.1);
  transition: background-color 0.45s ease;
}
.CodeMirror .cm-exec-hot {
  background: rgba(80, 220, 150, 0.3);
}
.CodeMirror .cm-exec-err {
  background: rgba(255, 70, 90, 0.28);
}
#editor {
  display: none;
}
.CodeMirror {
  flex: 1;
  min-height: 180px;
  height: auto !important;
  border-radius: 8px;
  border: 1px solid var(--edge);
  font-size: 13px;
  background: #0d1420;
  color: #e6ecf6;
  caret-color: #e6ecf6;
}
/* Dark theme for the stock CodeMirror build: the default theme is light,
   which made text nearly the same color as the panel background. */
.CodeMirror-gutters {
  background: #0a1019;
  border-right: 1px solid var(--edge);
}
.CodeMirror-linenumber {
  color: #5a6478;
}
.CodeMirror-cursor {
  border-left: 1.5px solid #e6ecf6;
}
.CodeMirror-selected {
  background: rgba(110, 160, 255, 0.24);
}
.CodeMirror-focused .CodeMirror-selected {
  background: rgba(110, 160, 255, 0.34);
}
.CodeMirror-line::selection,
.CodeMirror-line > span::selection,
.CodeMirror-line > span > span::selection {
  background: rgba(110, 160, 255, 0.34);
}
.cm-s-default .cm-keyword {
  color: #c678dd;
}
.cm-s-default .cm-atom {
  color: #56b6c2;
}
.cm-s-default .cm-number {
  color: #d19a66;
}
.cm-s-default .cm-def {
  color: #61afef;
}
.cm-s-default .cm-variable,
.cm-s-default .cm-variable-2,
.cm-s-default .cm-variable-3 {
  color: #e6ecf6;
}
.cm-s-default .cm-property {
  color: #61afef;
}
.cm-s-default .cm-operator {
  color: #56b6c2;
}
.cm-s-default .cm-comment {
  color: #7a869e;
  font-style: italic;
}
.cm-s-default .cm-string,
.cm-s-default .cm-string-2 {
  color: #98c379;
}
.cm-s-default .cm-meta {
  color: #e5c07b;
}
.cm-s-default .cm-qualifier {
  color: #e5c07b;
}
.cm-s-default .cm-builtin {
  color: #e5c07b;
}
.cm-s-default .cm-bracket {
  color: #abb2bf;
}
.cm-s-default .cm-tag {
  color: #e06c75;
}
.cm-s-default .cm-attribute {
  color: #d19a66;
}
.cm-s-default .cm-error {
  color: #f8f8f2;
  background: #e06c75;
}
/* Editor expand toggle: focus mode fills the whole stage. */
.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.panel-head h3 {
  margin: 0;
}
#editor-expand {
  font-size: 14px;
  line-height: 1;
  padding: 6px 10px;
}
/* Focus mode: a fixed overlay, not an abs-pos grid item — an abs-pos grid
   child uses its grid area as containing block and would collapse with the
   emptied editor row. Fixed covers the viewport on every layout. */
#editor-panel.expanded {
  position: fixed;
  inset: 1rem;
  z-index: 60;
  max-height: none;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.55);
}
#editor-panel.expanded .CodeMirror {
  flex: 1;
  height: auto;
  min-height: 0;
}
#deploy {
  margin: 0 0 8px;
  width: 100%;
  position: relative;
  z-index: 2;
}
#enemy-code-panel summary {
  cursor: pointer;
  font-size: 13px;
  color: var(--dim);
  min-height: 30px;
}
#enemy-code-panel pre {
  max-height: 200px;
  overflow: auto;
  font-size: 11px;
  line-height: 1.5;
  background: var(--panel2);
  border-radius: 8px;
  padding: 8px;
}
#log {
  max-height: 90px;
  overflow-y: auto;
  font-family: ui-monospace, monospace;
  font-size: 11px;
  color: var(--dim);
  white-space: pre-wrap;
}
#caption {
  position: fixed;
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 12px;
  color: var(--dim);
}

/* ---- responsive: iPhone portrait = stage over bench; landscape = side by side ---- */
@media (max-width: 860px) {
  #stage {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(300px, 52dvh) auto 1fr;
    grid-template-areas:
      'board'
      'editor'
      'bench';
  }
  #bench {
    overflow: visible;
  }
}
@media (max-width: 860px) and (orientation: landscape) {
  #stage {
    grid-template-columns: minmax(0, 1.5fr) minmax(260px, 1fr);
    grid-template-rows: minmax(0, 1fr) auto;
    grid-template-areas:
      'board bench'
      'editor bench';
    height: 100dvh;
    overflow-y: auto;
  }
  #topbar {
    position: static;
  }
  #bench {
    overflow-y: auto;
  }
}
@media (prefers-reduced-motion: reduce) {
  #banner {
    animation: none;
  }
  .CodeMirror .cm-exec-run {
    transition: none;
  }
}

/* ---------- debug toolbar + watch panel ---------- */
.seg {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 999px;
  overflow: hidden;
}
.seg-btn {
  padding: 5px 9px;
  font: inherit;
  font-size: 12px;
  color: var(--muted);
  background: transparent;
  border: 0;
  cursor: pointer;
}
.seg-btn + .seg-btn {
  border-left: 1px solid var(--line);
}
.seg-btn.on {
  background: var(--acc);
  color: #04140f;
}
#watch-panel {
  display: grid;
  gap: 4px;
  margin-top: 8px;
  max-height: 30dvh;
  overflow: auto;
  /* It is a flex child of #editor-panel — refuse to shrink to 0 or the
     rows render outside a collapsed box; the panel scrolls instead. */
  flex-shrink: 0;
}
#watch-panel[hidden] {
  display: none;
}
#watch-panel .wv {
  display: grid;
  grid-template-columns: minmax(72px, auto) minmax(40px, 1fr) 130px;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
#watch-panel .wv-name {
  color: #7dd3fc;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#watch-panel .wv-val {
  color: var(--text);
  text-align: right;
}
#watch-panel .wv-spark {
  width: 130px;
  height: 18px;
  background: rgba(255, 255, 255, 0.04);
  border-radius: 4px;
}
