:root {
  color-scheme: dark;
  --bg: #111411;
  --panel: #191e19;
  --inset: #141914;
  --line: #2b332c;
  --line-strong: #3a443a;
  --text: #eff3e9;
  --soft: #c8d0c3;
  --muted: #a3ad9e;
  --mint: #b5ec74;
  --amber: #f0b966;
  --blue: #82b7ec;
  --danger: #ef927c;
  --tier-easy: #b5ec74;
  --tier-medium: #82b7ec;
  --tier-hard: #f0b966;
  --tier-very-hard: #f08f6e;
  --tier-impossible: #d2a4f5;
  --tier-extreme: #ff6f91;
  --sans: 'DM Sans', system-ui, sans-serif;
  --mono: 'DM Mono', ui-monospace, monospace;
  font-family: var(--sans);
  font-synthesis: none;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
}

button, input, select { font-family: inherit; }
:focus-visible { outline: 2px solid var(--mint); outline-offset: 2px; }

.app {
  width: min(1080px, calc(100% - 48px));
  margin: 0 auto;
  padding: 0 0 42px;
}

/* ---------- top bar ---------- */

.topbar {
  height: 72px;
  display: flex;
  align-items: center;
  gap: 24px;
  border-bottom: 1px solid #252b25;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  text-decoration: none;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -.5px;
  text-transform: lowercase;
}

.brand-mark {
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  background: var(--mint);
  color: #172017;
  font-weight: 800;
  border-radius: 7px;
}

.run-state {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--soft);
  font: 12px var(--mono);
  text-transform: uppercase;
  letter-spacing: .04em;
  white-space: nowrap;
}

.live-dot, .tag-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--mint);
  box-shadow: 0 0 10px #b5ec7470;
}

.live-dot.off { background: #838c7f; box-shadow: none; }
.divider { color: #6c7969; }

/* ---------- buttons and fields ---------- */

.toggle-button, .action-button {
  border: 1px solid var(--line-strong);
  background: #1e251e;
  color: var(--text);
  font: 500 13px var(--sans);
  border-radius: 7px;
  padding: 9px 13px;
  cursor: pointer;
  white-space: nowrap;
}

.toggle-button:hover { border-color: #788c72; }
.action-button:hover { border-color: #94b37d; background: #252f25; }
.action-button:disabled { opacity: .4; cursor: not-allowed; }
.action-button.primary { color: #182018; background: var(--mint); border-color: var(--mint); }
.action-button.primary:hover { background: #c9f296; border-color: #c9f296; }
.action-button.preset { min-width: 40px; padding-inline: 9px; font-family: var(--mono); }
.action-button.preset.active { border-color: var(--mint); color: var(--mint); }

.toggle-button { display: flex; align-items: center; gap: 9px; color: var(--soft); }
.toggle-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--mint); }
.toggle-button.paused .toggle-dot { background: #838c7f; }

.text-button {
  border: 0;
  background: none;
  color: var(--muted);
  font: 13px var(--sans);
  padding: 8px;
  cursor: pointer;
}

.text-button:hover { color: var(--text); }

.field {
  width: 86px;
  border: 1px solid #394339;
  background: #1b221b;
  border-radius: 6px;
  padding: 8px;
  color: var(--text);
  font: 13px var(--mono);
}

.field.wide { width: 130px; }
.field:disabled { opacity: .4; }

/* ---------- playfield ---------- */

.playfield {
  position: relative;
  margin-top: 22px;
  background: #18201a;
  border: 1px solid #2b362c;
  border-radius: 11px;
  overflow: hidden;
  box-shadow: 0 18px 60px #0003;
}

.playfield canvas { display: block; width: 100%; height: auto; aspect-ratio: 1000 / 510; }

.level-tag, .play-hint, .field-bottom {
  position: absolute;
  font: 11px var(--mono);
  letter-spacing: .08em;
  text-transform: uppercase;
  pointer-events: none;
}

.level-tag { top: 16px; left: 18px; display: flex; gap: 9px; align-items: center; color: #e2e9df; }
.tag-dot { width: 6px; height: 6px; }
.tag-separator { color: #8a9788; }
.play-hint { top: 17px; right: 18px; color: #bccab6; }
.play-hint span { color: var(--mint); padding: 0 4px; }
.field-bottom { bottom: 14px; left: 18px; right: 18px; display: flex; gap: 18px; align-items: center; color: #b4c0b0; }
.field-legend { margin-left: auto; display: flex; align-items: center; gap: 7px; }
.field-legend i { width: 9px; height: 12px; border-radius: 3px; display: inline-block; }
.field-legend i + i, .field-legend .legend-greedy { margin-left: 10px; }
.legend-explore { background: var(--amber); }
.legend-greedy { background: var(--mint); }
.field-legend .legend-zone { margin-left: 10px; background: #e9816855; border: 1px dashed #f08f6e; }

.touch-controls { display: none; position: absolute; inset: auto 12px 12px 12px; gap: 10px; align-items: flex-end; pointer-events: none; }

.touch-button {
  width: 58px;
  height: 58px;
  border: 1px solid #ffffff3a;
  border-radius: 50%;
  background: #111411b8;
  color: var(--text);
  font-size: 22px;
  cursor: pointer;
  pointer-events: auto;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.touch-button.pressed { background: var(--mint); color: #172017; border-color: var(--mint); }
.touch-sprint { margin-left: auto; }
.touch-jump { width: 68px; height: 68px; }

@media (pointer: coarse) {
  .touch-controls { display: flex; }
  .key-hint { display: none; }
  .field-bottom { bottom: auto; top: 40px; }
  .field-legend { margin-left: 0; }
  /* iOS zooms into fields with text smaller than 16px. */
  .field, .rule-picker select { font-size: 16px; }
}

/* ---------- control deck ---------- */

.control-deck { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 11px; }

.control-card {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 12px 14px;
  background: var(--panel);
  border: 1px solid #293029;
  border-radius: 8px;
}

.card-label { margin-right: auto; display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.card-label strong { font: 600 17px var(--mono); color: var(--mint); }
.card-status { font: 12px var(--mono); color: var(--muted); }
.card-status.saved, .panel-status.saved { color: var(--mint); }
.card-status.error { color: var(--danger); }

.eyebrow, .metric-label, .chart-caption, .controls {
  font: 11px var(--mono);
  letter-spacing: .09em;
  color: var(--muted);
}

/* ---------- training ---------- */


.panel {
  margin-bottom: 12px;
  padding: 16px;
  background: var(--panel);
  border: 1px solid #293029;
  border-radius: 8px;
}

.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.panel-heading h2 { font-size: 17px; font-weight: 600; letter-spacing: -.4px; margin: 5px 0 0; }
.panel-status { font: 12px var(--mono); color: var(--muted); text-align: right; }
.panel-note { margin: 10px 0 0; color: var(--muted); font-size: 12px; line-height: 1.45; }

.reward-toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 15px 0 9px; }
.rule-picker { display: flex; align-items: center; gap: 8px; color: var(--muted); font: 12px var(--mono); }

.rule-picker select {
  max-width: 240px;
  border: 1px solid var(--line-strong);
  background: #1c221c;
  color: #dce5d8;
  border-radius: 6px;
  padding: 8px;
  font: 13px var(--sans);
}

.rule-picker select:disabled { opacity: .5; }
.toolbar-spacer { flex: 1; }
.reward-list { display: grid; gap: 6px; }

.reward-row {
  display: grid;
  grid-template-columns: minmax(175px, 1fr) minmax(110px, 170px) 64px;
  align-items: center;
  gap: 12px;
  padding: 9px 10px;
  background: var(--inset);
  border: 1px solid #242c24;
  border-radius: 6px;
}

.reward-row.custom { grid-template-columns: minmax(175px, 1fr) minmax(90px, 130px) 64px auto 30px; }
.reward-name { font-size: 13px; color: #dce4d7; }
.reward-name small { display: block; margin-top: 3px; color: var(--muted); font: 11px var(--mono); }
.reward-row .field { width: 100%; }
.rule-enabled { display: flex; align-items: center; gap: 6px; color: var(--muted); font: 11px var(--mono); }
.rule-enabled input { accent-color: var(--mint); width: 15px; height: 15px; }

.remove-rule {
  width: 29px;
  height: 29px;
  border: 1px solid #394339;
  border-radius: 6px;
  background: #202520;
  color: var(--muted);
  cursor: pointer;
  font-size: 15px;
}

.remove-rule:hover { color: #f09a78; border-color: #f09a78; }

.param-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-top: 14px; }
.param { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: #dce4d7; }
.param .field { width: 100%; }
.param small { color: var(--muted); font-size: 12px; line-height: 1.35; }

/* ---------- statistics ---------- */

.stats-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 20px 1px 9px; }
.stats-note { color: var(--muted); font: 12px var(--mono); text-align: right; }
.metrics { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.metrics.six { grid-template-columns: repeat(6, 1fr); margin-bottom: 12px; }
.metric.small { min-height: 0; padding: 12px 14px; }
.metric.small strong { font-size: 21px; margin: 9px 0 0; }

.metric {
  min-height: 108px;
  padding: 14px 14px 12px;
  background: var(--panel);
  border: 1px solid #293029;
  border-radius: 8px;
}

.metric-label { display: block; }
.metric-label span { color: #88947f; margin-left: 3px; white-space: nowrap; }

.metric strong {
  display: block;
  font-size: 27px;
  line-height: 1;
  margin: 12px 0 9px;
  letter-spacing: -1px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.metric strong small { font-size: 15px; color: var(--muted); margin-left: 2px; }
.metric-foot { display: flex; gap: 7px; align-items: center; color: var(--muted); font: 11px var(--mono); }
.metric-swatch { display: inline-block; flex: none; width: 7px; height: 7px; border-radius: 50%; }
.mint { background: var(--mint); }
.amber { background: var(--amber); }
.blue { background: var(--blue); }
.compact .metric-foot { justify-content: space-between; }

.chart-wrap {
  margin: 11px 0 12px;
  padding: 14px 16px 10px;
  background: var(--panel);
  border: 1px solid #293029;
  border-radius: 8px;
}

.chart-caption { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.chart-legend { display: flex; gap: 15px; letter-spacing: 0; }
.chart-legend span { display: flex; align-items: center; gap: 6px; }
.chart-legend i { width: 14px; height: 2px; display: inline-block; }
.legend-reward { background: var(--amber); }
.legend-success { background: var(--mint); }
.legend-greedy-line { background: var(--blue); }
#chart { display: block; width: 100%; height: 130px; margin-top: 8px; }
.chart-axis { display: flex; justify-content: space-between; margin-top: 4px; color: var(--muted); font: 11px var(--mono); }
.chart-axis b { font-weight: 400; color: var(--soft); }

.controls { margin-top: 14px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }

.key {
  border: 1px solid #343d34;
  background: #1b211b;
  border-radius: 4px;
  padding: 4px 7px;
  color: var(--soft);
  font: 11px var(--mono);
}

.key.wide { padding-inline: 9px; }
.controls-label { margin-left: 4px; }
.controls-note { margin-left: auto; color: var(--muted); font: 12px var(--sans); letter-spacing: 0; }

/* ---------- navigation and screens ---------- */

.topnav { margin-left: auto; display: flex; gap: 4px; }

.topnav a {
  color: var(--muted);
  text-decoration: none;
  font: 500 13px var(--sans);
  padding: 8px 11px;
  border-radius: 7px;
}

.topnav a:hover { color: var(--text); }
.topnav a.active { color: var(--text); background: #1e251e; }

.screen { padding-top: 26px; }
.screen-head { margin-bottom: 20px; }
.screen-head h1, .game-head h1 { font-size: 26px; letter-spacing: -.8px; margin: 0; font-weight: 600; }
.screen-head p { margin: 8px 0 0; color: var(--muted); font-size: 14px; line-height: 1.5; max-width: 62ch; }
.back { display: inline-block; margin-bottom: 12px; color: var(--muted); text-decoration: none; font: 12px var(--mono); letter-spacing: .04em; }
.back:hover { color: var(--text); }
.title-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

.badge {
  --tier: var(--muted);
  display: inline-block;
  padding: 3px 9px;
  border: 1px solid var(--tier);
  border-radius: 999px;
  color: var(--tier);
  font: 500 11px var(--mono);
  letter-spacing: .08em;
  text-transform: uppercase;
  white-space: nowrap;
}

.tier-easy { --tier: var(--tier-easy); }
.tier-medium { --tier: var(--tier-medium); }
.tier-hard { --tier: var(--tier-hard); }
.tier-very-hard { --tier: var(--tier-very-hard); }
.tier-impossible { --tier: var(--tier-impossible); }
.tier-extreme { --tier: var(--tier-extreme); }

/* home */

.hero { padding: 34px 0 26px; }
.hero h1 { font-size: 46px; letter-spacing: -1.8px; margin: 8px 0 10px; font-weight: 700; }
.hero p { margin: 0; color: var(--soft); font-size: 16px; line-height: 1.5; max-width: 52ch; }
.menu { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.menu-item, .mode-button {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 20px;
  background: var(--panel);
  border: 1px solid #293029;
  border-radius: 10px;
  color: var(--text);
  text-decoration: none;
}

.menu-item strong, .mode-button strong { font-size: 19px; font-weight: 600; letter-spacing: -.4px; }
.menu-item span, .mode-button span { color: var(--muted); font-size: 13px; line-height: 1.4; }
.menu-item:hover, .mode-button:hover { border-color: #788c72; background: #1d231d; }
.menu-item.primary { background: var(--mint); border-color: var(--mint); color: #172017; }
.menu-item.primary span { color: #2f4420; }
.menu-item.primary:hover { background: #c9f296; border-color: #c9f296; }
.storage-warning { margin: 16px 0 0; color: var(--danger); font-size: 13px; }

/* level selection */

.tier-group { margin-bottom: 26px; }
.tier-head { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; flex-wrap: wrap; }
.tier-note { color: var(--muted); font: 12px var(--mono); }
.level-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }

.level-card {
  --tier: var(--muted);
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 13px 14px;
  background: var(--panel);
  border: 1px solid #293029;
  border-top: 2px solid var(--tier);
  border-radius: 8px;
  color: var(--text);
  text-decoration: none;
}

.level-card:hover { background: #1d231d; border-color: var(--tier); }
.level-card strong { font-size: 15px; font-weight: 600; }
.card-tier { color: var(--tier); font: 11px var(--mono); letter-spacing: .08em; text-transform: uppercase; margin-bottom: 5px; }
.record { font: 12px var(--mono); color: var(--soft); font-variant-numeric: tabular-nums; }
.record.none { color: #7f8a7b; }

/* level information */

.preview { display: block; width: 100%; height: 150px; background: #18201a; border: 1px solid #2b362c; border-radius: 8px; }
.info-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 10px; }
.info-grid.three { grid-template-columns: repeat(3, 1fr); margin: 0 0 24px; }
.mode-question { font-size: 19px; font-weight: 600; letter-spacing: -.4px; margin: 28px 0 12px; }
.mode-choice { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.level-pager { display: flex; justify-content: space-between; margin-top: 18px; }
.level-pager a { color: var(--muted); text-decoration: none; font: 12px var(--mono); padding: 6px 0; }
.level-pager a:hover { color: var(--text); }

/* game */

.game-head { display: flex; align-items: flex-end; gap: 12px 18px; flex-wrap: wrap; }
.game-head .back { margin: 0 0 4px; width: 100%; }
.game-head .run-state { margin-bottom: 5px; }
.mode-tag { color: var(--muted); font: 12px var(--mono); letter-spacing: .06em; text-transform: uppercase; }
[data-mode="ai"] .manual-only, [data-mode="manual"] .ai-only, [data-mode="replay"] .manual-only, [data-mode="replay"] .ai-only { display: none !important; }
[data-screen="game"]:not([data-mode="replay"]) .replay-only { display: none !important; }
.playfield { margin-top: 16px; }
.manual-deck { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; margin-top: 11px; }
.manual-actions { display: flex; flex-direction: column; gap: 8px; justify-content: center; }
.manual-actions .action-button { text-align: center; text-decoration: none; }
.action-button.danger { color: var(--danger); border-color: #6b4238; }
.action-button.danger:hover { border-color: var(--danger); background: #2a1f1c; }
.action-button[data-armed] { color: #172017; background: var(--amber); border-color: var(--amber); }
body.touch-on .touch-controls { display: flex; }
body.touch-on .key-hint { display: none; }

/* AI progress */

.progress-table { border: 1px solid #293029; border-radius: 8px; overflow: hidden; background: var(--panel); }

.progress-row {
  display: grid;
  grid-template-columns: 1.4fr 1fr 1fr 1fr 1fr 1fr 96px;
  gap: 10px;
  align-items: center;
  padding: 10px 14px;
  border-top: 1px solid #242c24;
  color: var(--soft);
  text-decoration: none;
  font: 13px var(--mono);
  font-variant-numeric: tabular-nums;
}

.progress-row:first-child { border-top: 0; }
.progress-row.header { color: var(--muted); font-size: 11px; letter-spacing: .08em; text-transform: uppercase; }
.progress-row strong { font: 600 14px var(--sans); color: var(--text); }
.progress-row.untrained { color: #7f8a7b; }
.progress-row.untrained strong { color: var(--soft); font-weight: 500; }
a.progress-row:hover { background: #1d231d; }
.row-action { color: var(--mint); text-align: right; }

/* settings */

.setting { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 13px 0; border-top: 1px solid #242c24; }
.setting:first-child { border-top: 0; padding-top: 0; }
.setting:last-child { padding-bottom: 0; }
.panel-heading + .setting { border-top: 0; }
.setting strong { display: block; font-size: 14px; font-weight: 600; }
.setting small { display: block; margin-top: 3px; color: var(--muted); font-size: 12px; line-height: 1.4; }
.field.wide { width: 190px; }

/* ---------- editors: rules, restricted areas, random levels ---------- */

.rule-heading { margin: 16px 0 8px; font: 11px var(--mono); letter-spacing: .09em; text-transform: uppercase; color: var(--muted); font-weight: 400; }
.rule-heading-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-top: 6px; }
.rule-heading-row .rule-heading { margin-bottom: 10px; }
.rule-heading-row .action-button { margin-bottom: 8px; }
.empty-note { margin: 0; padding: 12px; color: var(--muted); font-size: 12px; line-height: 1.45; background: var(--inset); border: 1px dashed #2f382f; border-radius: 6px; }

.row-button {
  border: 1px solid #394339;
  border-radius: 6px;
  background: #202520;
  color: var(--soft);
  font: 12px var(--sans);
  padding: 6px 10px;
  cursor: pointer;
}

.row-button:hover { border-color: #94b37d; }

.rule-editor {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  align-items: start;
  margin-top: 8px;
  padding: 14px;
  background: var(--inset);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
}

.rule-editor select.field, .generator select.field { font-family: var(--sans); }
.rule-editor .param.wide { grid-column: span 2; }   /* the two dropdowns need room for their text */
.rule-editor-actions { grid-column: 1 / -1; display: flex; gap: 8px; }

.zone-list { display: grid; gap: 6px; margin-top: 12px; }
.zone-row { display: flex; align-items: center; gap: 8px; padding: 8px 10px; background: var(--inset); border: 1px solid #242c24; border-radius: 6px; }
.zone-name { margin-right: auto; font: 12px var(--mono); color: var(--soft); font-variant-numeric: tabular-nums; }
.zone-options { display: flex; align-items: center; gap: 8px 18px; flex-wrap: wrap; margin-top: 12px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--soft); cursor: pointer; }
.check input { accent-color: var(--mint); width: 15px; height: 15px; }
.panel-status.left { text-align: left; margin: 10px 0 0; min-height: 1.2em; }
.panel-status.error { color: var(--danger); }

.editor-bar { display: flex; align-items: center; gap: 12px; margin-top: 8px; padding: 10px 14px; background: var(--panel); border: 1px solid var(--line-strong); border-radius: 8px; }
.editor-bar input { flex: 1; accent-color: var(--mint); }
.playfield.editing { border-color: #f08f6e; }
.playfield.editing canvas { cursor: crosshair; touch-action: none; }
.playfield.editing .field-bottom { display: none; }

.generator { display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.generator .param { min-width: 150px; }
.generator .card-status { flex-basis: 100%; }
.danger-text { color: var(--danger); }
.level-pager { align-items: center; }

/* ---------- speed statistics and the network viewer ---------- */

.metric.small .metric-foot { margin-top: 7px; line-height: 1.3; align-items: flex-start; }
.speed-help { margin: -4px 0 14px; max-width: 110ch; }
.action-button.preset[data-model] { font-family: var(--sans); }

.net-tools { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.net-agent { display: flex; align-items: center; gap: 6px; color: var(--muted); font: 12px var(--mono); }
.net-agent .field { width: 82px; }
.net-body { display: grid; grid-template-columns: minmax(0, 1fr) 250px; gap: 14px; margin-top: 12px; }
.net-stage { min-width: 0; }

#netCanvas {
  display: block;
  width: 100%;
  aspect-ratio: 900 / 460;
  background: #121712;
  border: 1px solid #242c24;
  border-radius: 8px;
  cursor: grab;
  touch-action: pan-y;
}

#netCanvas.dragging { cursor: grabbing; }
.net-legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 9px; color: var(--muted); font: 11px var(--mono); }
.net-legend span { display: flex; align-items: center; gap: 6px; }
.net-line { display: inline-block; width: 18px; height: 2px; background: var(--mint); }
.net-line.negative { background: #f08f6e; }
.net-line.thick { height: 4px; background: #eff3e9; }
.net-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; border: 1px solid #5c6a58; background: #1b221b; }
.net-dot.on { background: #eff3e9; }
.net-dot.choice { border: 2px solid var(--amber); background: #eff3e9; }
.net-side { display: flex; flex-direction: column; gap: 12px; min-width: 0; }

.net-stats { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 5px 12px; padding: 12px; background: var(--inset); border: 1px solid #242c24; border-radius: 8px; font: 12px var(--mono); }
.net-stats dt { color: var(--muted); }
.net-stats dd { margin: 0; text-align: right; color: var(--text); font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.net-inspector { padding: 12px; background: var(--inset); border: 1px solid #242c24; border-radius: 8px; font-size: 12px; color: var(--soft); line-height: 1.45; }
.net-inspector h3 { margin: 0 0 6px; font-size: 13px; font-weight: 600; color: var(--text); }
.net-inspector h4 { margin: 10px 0 4px; font: 11px var(--mono); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); font-weight: 400; }
.net-inspector table { width: 100%; border-collapse: collapse; font: 11px var(--mono); }
.net-inspector td { padding: 2px 0; vertical-align: top; }
.net-inspector td:last-child { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; padding-left: 8px; }
.net-inspector .plus { color: var(--mint); }
.net-inspector .minus { color: #f08f6e; }

/* ---------- narrow screens ---------- */

@media (max-width: 900px) {
  .metrics { grid-template-columns: repeat(2, 1fr); }
  .metrics.six { grid-template-columns: repeat(3, 1fr); }
  .net-body { grid-template-columns: 1fr; }
  .rule-editor { grid-template-columns: 1fr 1fr; }
  .level-grid { grid-template-columns: repeat(3, 1fr); }
  .info-grid { grid-template-columns: repeat(2, 1fr); }
  .info-grid.three { grid-template-columns: repeat(3, 1fr); }
  .progress-row { grid-template-columns: 1.3fr 1fr 1fr 1fr 1fr 84px; }
  .progress-row .optional { display: none; }
  .param-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 650px) {
  .app { width: calc(100% - 24px); padding-bottom: 24px; }
  .topbar { height: auto; flex-direction: column; align-items: stretch; gap: 6px; padding: 10px 0 8px; }
  .brand { font-size: 14px; }
  .topnav { margin-left: 0; flex-wrap: wrap; }
  .topnav a { padding: 8px 9px; font-size: 13px; white-space: nowrap; }
  .nav-account { margin-left: auto; }
  .screen { padding-top: 18px; }
  .hero { padding: 16px 0 20px; }
  .hero h1 { font-size: 36px; }
  .menu, .mode-choice { grid-template-columns: 1fr; }
  .level-grid { grid-template-columns: repeat(2, 1fr); }
  .info-grid.three { grid-template-columns: 1fr; }
  .manual-deck { grid-template-columns: 1fr 1fr; }
  .ghost-tile { grid-column: 1 / -1; }
  .manual-actions { grid-column: 1 / -1; flex-direction: row; }
  .manual-actions .action-button { flex: 1; }
  .progress-row { grid-template-columns: 1.3fr 1fr 1fr 58px; padding: 10px; font-size: 12px; }
  .progress-row span:nth-child(2), .progress-row span:nth-child(3) { display: none; }
  .metrics.six { grid-template-columns: repeat(2, 1fr); }
  .rule-editor { grid-template-columns: 1fr; }
  .rule-editor .param.wide { grid-column: auto; }
  .reward-row.custom { grid-template-columns: 1fr 76px 52px; }
  .reward-row.custom .row-button { justify-self: start; }
  .generator .param, .generator .field.wide { width: 100%; }
  .setting { flex-direction: column; align-items: flex-start; gap: 9px; }
  .run-state { font-size: 11px; gap: 6px; }
  .playfield { margin-top: 13px; border-radius: 8px; }
  .level-tag { top: 11px; left: 11px; }
  .play-hint { display: none; }
  .field-bottom { left: 11px; right: 11px; top: 32px; }
  /* The field is too small here to put buttons on top of it. */
  .touch-controls { position: static; padding: 8px 10px; background: #141914; border-top: 1px solid #2b362c; }
  .touch-top { display: none !important; }
  .touch-button { width: 48px; height: 48px; font-size: 19px; }
  .touch-jump { width: 56px; height: 56px; }
  .control-deck { grid-template-columns: 1fr; gap: 7px; }
  .panel { padding: 12px; }
  .panel-heading { align-items: flex-start; }
  .rule-picker { width: 100%; justify-content: space-between; }
  .rule-picker select { max-width: 70%; }
  .toolbar-spacer { display: none; }
  .reward-row { grid-template-columns: 1fr 88px 52px; gap: 7px; padding: 8px; }
  .metrics { gap: 7px; }
  .metric { min-height: 96px; padding: 11px 12px; }
  .metric strong { font-size: 24px; margin: 10px 0 7px; }
  .chart-wrap { padding: 12px 11px 9px; }
  #chart { height: 110px; }
  .controls-note { margin-left: 0; width: 100%; }
}

/* ---------- account, leaderboards, profile ---------- */

a.action-button { display: inline-block; text-decoration: none; text-align: center; }
a.text-button, a.row-button { text-decoration: none; }
.nav-account { border: 1px solid var(--line-strong); color: var(--text) !important; margin-left: 6px; max-width: 170px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.board-filters { display: flex; align-items: flex-end; gap: 12px 16px; flex-wrap: wrap; margin-bottom: 12px; }
.board-filters .param { min-width: 150px; }
.board-filters select.field { width: 100%; font-family: var(--sans); }
.board-tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.board-tabs .action-button { font-family: var(--sans); }

.board-table { margin-top: 10px; border: 1px solid #293029; border-radius: 8px; overflow: hidden; background: var(--panel); }
.board-table:empty { display: none; }

.board-row {
  display: grid;
  grid-template-columns: 56px minmax(150px, 1.2fr) 92px minmax(0, 2fr) 176px;
  gap: 12px;
  align-items: center;
  padding: 10px 14px;
  border-top: 1px solid #242c24;
  color: var(--soft);
  font: 13px var(--mono);
}

.board-row:first-child { border-top: 0; }
.board-row.header { color: var(--muted); font-size: 11px; letter-spacing: .08em; text-transform: uppercase; }
.board-row.mine { background: #1f2a1c; }
.board-row.apart { border-top: 2px dashed var(--line-strong); }
.board-rank { color: var(--amber); font-weight: 500; font-variant-numeric: tabular-nums; }
.board-name { display: flex; flex-direction: column; gap: 2px; min-width: 0; font: 600 14px var(--sans); color: var(--text); overflow-wrap: anywhere; }
.board-name a { color: var(--text); text-decoration: none; }
.board-name a:hover { text-decoration: underline; }
.board-tag { font: 400 11px var(--mono); letter-spacing: .04em; }
.kind-human { color: var(--amber); }
.kind-table { color: var(--mint); }
.kind-network { color: var(--blue); }
.board-time { font: 600 15px var(--mono); color: var(--text); font-variant-numeric: tabular-nums; }
.board-detail { color: var(--muted); font-size: 12px; line-height: 1.4; }
.board-actions { display: flex; gap: 6px; justify-content: flex-end; }
.board-actions .row-button { white-space: nowrap; }
.board-table .empty-note { margin: 10px; }

.board-status { margin: 0 0 9px; padding: 8px 12px; border: 1px solid var(--line-strong); border-radius: 7px; background: var(--inset); color: var(--soft); font: 12px var(--mono); line-height: 1.45; }
.board-status.saved { color: var(--mint); border-color: #4c6a35; }
.board-status.error { color: var(--danger); border-color: #6b4238; }

.world-records { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; margin-top: 12px; padding: 12px 14px; background: var(--panel); border: 1px solid #293029; border-radius: 8px; color: var(--soft); font: 13px var(--mono); }
.world-records .text-button { margin-left: auto; color: var(--mint); padding: 4px 0; }

.auth-form { display: grid; gap: 12px; max-width: 360px; margin-top: 14px; }
.auth-form .action-button { justify-self: start; }
.panel-note.error { color: var(--danger); }
#accountOffline h2 { margin: 0; font-size: 17px; font-weight: 600; }
#accountOffline .action-button { margin-top: 12px; }
#profileAccount { color: var(--mint); }

/* ---------- replay and ghost ---------- */

.ghost-tile { border-style: dashed; border-color: var(--line-strong); }
.ghost-tile .metric-foot { align-items: flex-start; line-height: 1.35; }
#ghostGap.ahead { color: var(--mint); }
#ghostGap.behind { color: var(--danger); }

.replay-deck { display: grid; gap: 12px; margin-top: 11px; padding: 14px 16px; background: var(--panel); border: 1px solid #293029; border-radius: 8px; }
.replay-info { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 14px; }
.replay-info strong { font-size: 19px; font-weight: 600; letter-spacing: -.4px; }
.replay-controls { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.replay-controls input[type="range"] { flex: 1 1 220px; min-width: 150px; height: 30px; accent-color: var(--mint); }
.replay-speed { display: flex; align-items: center; gap: 6px; color: var(--muted); font: 12px var(--mono); }
.replay-clock { min-width: 124px; text-align: right; color: var(--soft); font: 13px var(--mono); font-variant-numeric: tabular-nums; }
.replay-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.replay-deck .panel-note { margin: 0; }

/* ---------- performance display ---------- */

.perf-bar { display: flex; flex-wrap: wrap; gap: 6px 18px; margin-bottom: 12px; padding: 9px 14px; background: var(--panel); border: 1px solid #293029; border-radius: 8px; color: var(--muted); font: 12px var(--mono); }
.perf-bar b { color: var(--text); font-weight: 500; font-variant-numeric: tabular-nums; }
.perf-warning { flex-basis: 100%; color: var(--amber); line-height: 1.45; }
.perf-warning.quiet { color: var(--muted); }

/* ---------- touch screens and phones ---------- */

.touch-top { display: none; position: absolute; top: 10px; right: 12px; gap: 8px; }
.touch-small { width: 40px; height: 40px; font-size: 17px; }
body.touch-on .touch-top { display: flex; }
body.touch-on .play-hint { display: none; }
body.playing { overscroll-behavior: none; }

.rotate-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 24px;
  text-align: center;
  background: var(--bg);
}

.rotate-overlay h2 { margin: 6px 0 0; font-size: 20px; font-weight: 600; letter-spacing: -.4px; max-width: 18ch; line-height: 1.25; }
.rotate-overlay p { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.45; max-width: 30ch; }
.rotate-icon { width: 50px; height: 86px; border: 3px solid var(--mint); border-radius: 10px; animation: rotate-hint 2.6s ease-in-out infinite; }
@keyframes rotate-hint { 0%, 25% { transform: rotate(0); } 60%, 100% { transform: rotate(-90deg); } }
@media (prefers-reduced-motion: reduce) { .rotate-icon { animation: none; transform: rotate(-90deg); } }

@media (pointer: coarse) {
  .touch-top { display: flex; }
  .play-hint { display: none; }
  /* Fingers need bigger targets than a mouse pointer. */
  .action-button, .toggle-button { min-height: 42px; }
  .row-button, .remove-rule { min-height: 38px; min-width: 38px; }
  .text-button { min-height: 38px; }
  .topnav a { padding-block: 10px; }
  /* While playing, a touch on the level is never a scroll, a zoom or a text selection. */
  [data-mode="manual"] .playfield { touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
  .replay-controls input[type="range"] { height: 40px; }
}

@media (max-width: 650px) {
  .board-filters .param { flex: 1 1 100%; }
  .board-row { grid-template-columns: 40px minmax(0, 1fr) auto; gap: 4px 10px; padding: 10px; }
  .board-row .board-detail, .board-row .board-actions { grid-column: 2 / -1; }
  .board-row .board-actions { justify-content: flex-start; margin-top: 4px; }
  .board-row.header span:nth-child(n+4) { display: none; }
  .world-records .text-button { margin-left: 0; }
  .replay-clock { text-align: left; }
  .perf-bar { gap: 4px 14px; padding: 8px 11px; }
}

/* A phone held sideways: the level fills the screen, the buttons sit on top of it. */
@media (pointer: coarse) and (orientation: landscape) and (max-height: 540px) {
  body.playing .topbar { display: none; }
  body.playing .app { width: 100%; padding: 0 max(8px, env(safe-area-inset-right)) 16px max(8px, env(safe-area-inset-left)); }
  body.playing .screen { padding-top: 4px; }
  body.playing .game-head { flex-wrap: nowrap; align-items: center; gap: 10px; min-height: 30px; }
  body.playing .game-head .back { width: auto; margin: 0; white-space: nowrap; }
  body.playing .game-head h1 { font-size: 15px; letter-spacing: -.2px; }
  body.playing .game-head .title-row { gap: 8px; flex-wrap: nowrap; }
  body.playing .game-head .mode-tag { white-space: nowrap; }
  body.playing .game-head .run-state { margin: 0 0 0 auto; }
  body.playing .playfield { margin: 4px auto 0; width: min(100%, calc((100vh - 42px) * 1000 / 510)); width: min(100%, calc((100dvh - 42px) * 1000 / 510)); border-radius: 8px; }
  body.playing .field-bottom { display: none; }
  body.playing .touch-controls { position: absolute; inset: auto 10px 10px 10px; padding: 0; background: none; border: 0; }
  body.playing .touch-top { display: flex !important; }
  body.playing .touch-button { width: 54px; height: 54px; font-size: 21px; }
  body.playing .touch-jump { width: 64px; height: 64px; }
  body.playing .touch-small { width: 38px; height: 38px; font-size: 16px; }
  body.playing .level-tag { display: none; }
}
