/* Black-and-vector look. The game is always dark; that's the aesthetic.
   Desktop layout fits the window with no page scrolling: controls on the left,
   a square arena in the middle, reference on the right, timeline at the bottom. */

:root {
  --bg: #000;
  --fg: #e8e8e8;
  --muted: #8a8a8a;
  --line: #3a3a3a;
  --enemy: #ff6b6b;
  --shield: #5fd7ff;
  --ram: #ffaa33;
  --thrust: #f4e285;
  --rock: #9a9a9a;
  --won: #7dff9b;
  --panel: 230px;
  --font: ui-monospace, 'Cascadia Mono', 'SFMono-Regular', Menlo, Consolas, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 13px/1.45 var(--font);
}

button {
  font: inherit;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 2px;
  padding: 4px 8px;
  min-height: 32px;
  cursor: pointer;
}
button:hover { border-color: var(--fg); }
button:focus-visible { outline: 2px solid var(--fg); outline-offset: 1px; }

kbd {
  font: 11px var(--font);
  color: var(--fg);
  border: 1px solid var(--line);
  padding: 0 4px;
}

h2 {
  margin: 0 0 6px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--muted);
}

/* --- page grid ------------------------------------------------------------- */

.app {
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-columns: var(--panel) minmax(0, 1fr) var(--panel);
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  grid-template-areas:
    'top   top   top'
    'boot  boot  boot'
    'left  stage right'
    'edit  edit  edit';
  gap: 10px 14px;
  padding: 10px 14px 12px;
  max-width: 1600px;
  margin: 0 auto;
}

.top { grid-area: top; display: flex; align-items: baseline; gap: 16px; }
.top h1 { margin: 0; font-size: 20px; letter-spacing: 0.4em; font-weight: 700; }
.puzzle-name { color: var(--muted); }
.day-nav { display: flex; gap: 6px; }
.day-nav[hidden] { display: none; }
.day-nav a {
  color: var(--fg);
  text-decoration: none;
  border: 1px solid var(--line);
  padding: 2px 8px;
}
.day-nav a:hover { border-color: var(--fg); }
.day-nav a[hidden] { display: none; }
.help-btn { margin-left: auto; }

.boot { grid-area: boot; border: 1px solid var(--line); padding: 10px 14px; }
.boot p { margin: 0 0 6px; }
.boot-help { color: var(--muted); }
.boot code { color: var(--fg); }

.panel { overflow-y: auto; min-height: 0; }
.panel section { margin-bottom: 14px; }
.panel-left { grid-area: left; }
.panel-right { grid-area: right; }

/* --- arena: the largest square that fits -------------------------------------- */

.stage-wrap {
  grid-area: stage;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.stage { position: relative; }
.stage canvas { display: block; background: var(--bg); }

.result {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: rgba(0, 0, 0, 0.72);
  text-align: center;
}
.result[hidden] { display: none; }
.result-title { font-size: 26px; letter-spacing: 0.3em; font-weight: 700; }
.result[data-status='won'] .result-title { color: var(--won); }
.result[data-status='lost'] .result-title { color: var(--enemy); }
.result-actions { display: flex; gap: 8px; }
.share-status { color: var(--muted); min-height: 1.5em; }

/* --- left panel ------------------------------------------------------------- */

/* The score: time and cost, big. */
.status { font-size: 13px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }
.status.won { color: var(--won); }
.status.lost { color: var(--enemy); }
.metrics { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin: 6px 0; }
.metric { border: 1px solid var(--line); padding: 6px 10px 4px; cursor: help; }
.metric .label { display: block; font-size: 11px; letter-spacing: 0.15em; text-transform: uppercase; color: var(--muted); }
.metric b { display: block; font-size: 34px; line-height: 1.1; font-weight: 700; color: var(--muted); }
.metrics.won .metric { border-color: var(--won); }
.metrics.won .metric b { color: var(--fg); }
.now { color: var(--muted); font-size: 12px; }
.now b { color: var(--fg); font-weight: 600; }

.controls { display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px; }
.controls button { padding: 4px 0; }

.palette { display: flex; flex-direction: column; gap: 4px; }
.action {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  text-align: left;
}
.action .glyph {
  flex: 0 0 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  line-height: 1;
}
.action .name { flex: 1; color: var(--fg); }
/* Price badge: every action shows what it costs. */
.action .price {
  min-width: 3.2em;
  padding: 1px 6px;
  border: 1px solid #6a6a6a;
  color: var(--fg);
  font-size: 14px;
  font-weight: 700;
  text-align: center;
}
.action .price.free { border-color: var(--line); color: var(--muted); font-size: 11px; font-weight: 400; }
.action kbd { color: var(--muted); }

.tools { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }

/* --- right panel ------------------------------------------------------------ */

.legend { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.legend li { display: grid; grid-template-columns: 34px 1fr; gap: 10px; align-items: center; cursor: help; }
.legend canvas { width: 34px; height: 34px; }
.legend b { display: block; font-size: 14px; letter-spacing: 0.08em; }
.legend .hint { font-size: 15px; line-height: 1.2; }

/* Symbol rows: a big glyph and a small note. */
.sym { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; font-size: 17px; }
.sym li { display: grid; grid-template-columns: 1.2em 4.5em 1.2em; align-items: baseline; gap: 6px; cursor: help; }
.sym .note { text-align: center; }

.note { color: var(--muted); font-size: 12px; }
.c-shield { color: var(--shield); }
.c-ram { color: var(--ram); }

/* --- timeline --------------------------------------------------------------- */

.editor { grid-area: edit; min-width: 0; }
.timeline {
  border: 1px solid var(--line);
  padding: 4px 6px 6px;
  overflow-x: auto;
  user-select: none;
}
.tl-inner { position: relative; }

/* Tick numbers; click or drag here to scrub. */
.tl-ruler {
  position: relative;
  height: 22px;
  cursor: ew-resize;
  touch-action: none;
}
.tl-ruler span {
  position: absolute;
  top: 3px;
  padding-left: 3px;
  font-size: 11px;
  color: #555;
  border-left: 1px solid #262626;
  line-height: 16px;
  pointer-events: none;
}
.tl-ruler span.major { color: var(--muted); border-left-color: var(--line); }

.track { display: flex; }
.slot {
  flex: 0 0 40px; /* SLOT_W in timeline.js */
  width: 40px;
  height: 52px;
  border: 1px solid #1c1c1c;
  font-size: 22px;
  line-height: 50px;
  text-align: center;
  overflow: hidden;
  cursor: pointer;
  touch-action: pan-x;
}
.slot.filled { border-color: var(--line); cursor: grab; touch-action: none; }
.slot.selected { background: #1f2a33; }
.slot.cursor { outline: 1px solid var(--fg); outline-offset: -1px; position: relative; z-index: 1; }
.slot.drop { background: #333; outline: 1px dashed var(--fg); outline-offset: -1px; }
/* The tick the run ends on, and slots that never run because of it. */
.slot.end-won { box-shadow: inset 0 -4px 0 var(--won); }
.slot.end-lost { box-shadow: inset 0 -4px 0 var(--enemy); }
.slot.end-timeout { box-shadow: inset 0 -4px 0 var(--muted); }
.slot.after-end { opacity: 0.35; }

/* Ticks the ram is switched on. */
.tl-bands { position: relative; height: 7px; margin-top: 3px; }
.band-ram { position: absolute; top: 0; height: 6px; background: var(--ram); }

/* Where playback is, across ruler, slots and bands. */
.tl-playhead {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  margin-left: -1px;
  background: var(--fg);
  box-shadow: 0 0 4px rgba(255, 255, 255, 0.6);
  pointer-events: none;
  z-index: 2;
}

.a-wait { color: var(--muted); }
.a-rot { color: var(--fg); }
.a-thrust { color: var(--thrust); }
.a-fire { color: var(--fg); }
/* The bullet dot is a small glyph: draw it bigger wherever it appears. */
.dot { font-size: 1.5em; line-height: 0.8; }
.slot.a-fire { font-size: 34px; }
.action.a-fire .glyph { font-size: 26px; }
.a-shield { color: var(--shield); }
.a-ram { color: var(--ram); }

/* --- help dialog ------------------------------------------------------------ */

.help {
  max-width: 640px;
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--line);
  padding: 20px 24px;
}
.help::backdrop { background: rgba(0, 0, 0, 0.7); }
.help h2 { font-size: 13px; color: var(--fg); }
.help h3 { margin: 14px 0 4px; font-size: 12px; color: var(--muted); font-weight: 600; }
.help p, .help ul { margin: 0 0 6px; color: #c8c8c8; }
.help ul { padding-left: 18px; }

/* --- narrow screens: stack, and let the page scroll ------------------------------ */

@media (max-width: 900px) {
  .app {
    height: auto;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: none;
    grid-template-areas: 'top' 'boot' 'stage' 'edit' 'left' 'right';
  }
  .panel { overflow: visible; }
  .palette { flex-direction: row; flex-wrap: wrap; }
  .action { min-height: 44px; }
  .action .name, .action kbd { display: none; }
}
