:root {
  --bg: #14161b;
  --panel: #1c1f26;
  --panel-2: #23272f;
  --line: #2f3440;
  --text: #e6e8ee;
  --muted: #8b93a7;
  --accent: #ffd23f;
  --accent-2: #4fb3ff;
  --ok: #46c37b;
  --bad: #ff5d5d;
  --radius: 8px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 13px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
}

button, select, input, .btn {
  font: inherit;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 5px 10px;
}
button, .btn { cursor: pointer; white-space: nowrap; }
button:hover:not(:disabled), .btn:hover { border-color: #4a5263; background: #2a2f39; }
button:disabled { opacity: 0.45; cursor: default; }
button.primary { background: var(--accent); color: #1a1a1a; border-color: var(--accent); font-weight: 650; }
button.primary:hover:not(:disabled) { background: #ffdd66; }
button.danger { color: var(--bad); }
input[type="number"] { width: 72px; }
input[type="checkbox"] { padding: 0; accent-color: var(--accent); }
select { max-width: 100%; }
kbd {
  font: 11px ui-monospace, monospace;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 0 4px;
  margin-right: 2px;
}
code { font-family: ui-monospace, monospace; }

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.brand { font-weight: 750; letter-spacing: 0.2px; display: flex; align-items: center; gap: 6px; }
.logo { color: var(--accent); }
.rom-status { color: var(--muted); max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rom-status.ok { color: var(--ok); }
#areaSelect { min-width: 260px; }
.group { display: flex; gap: 4px; }
.spacer { flex: 1; }

.budget { display: flex; gap: 12px; }
.meter { display: grid; gap: 2px; min-width: 150px; font-size: 11px; color: var(--muted); }
.meter .bar { height: 5px; background: var(--panel-2); border-radius: 3px; overflow: hidden; }
.meter .fill { height: 100%; background: var(--ok); }
.meter.full .fill { background: var(--accent); }
.meter.over { color: var(--bad); }
.meter.over .fill { background: var(--bad); }

.layout {
  display: grid;
  grid-template-columns: 210px minmax(0, 1fr) 300px;
  gap: 10px;
  padding: 10px;
  min-height: calc(100% - 52px);
}
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }

.palette { padding: 10px; overflow: auto; max-height: calc(100vh - 72px); position: sticky; top: 10px; }
.palette h2, .inspector h2 { font-size: 13px; margin: 0 0 4px; }
.palette h3 { font-size: 11px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--muted); margin: 12px 0 4px; }
.palette button {
  display: block;
  width: 100%;
  text-align: left;
  margin: 2px 0;
  padding: 4px 8px;
  background: transparent;
  border-color: transparent;
}
.palette button.active { border-color: var(--accent-2); background: #1d2a38; }
.hint { color: var(--muted); font-size: 12px; margin: 4px 0; }

.center { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.map-toolbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 6px 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.map-toolbar label { display: flex; align-items: center; gap: 6px; color: var(--muted); }
.hover-info { color: var(--muted); font-family: ui-monospace, monospace; font-size: 12px; }
.map-scroll {
  overflow-x: auto;
  overflow-y: hidden;
  background: #0d0f13;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.map-host { position: relative; width: max-content; }
.map-host canvas { display: block; image-rendering: pixelated; }
.map-overlay { position: absolute; inset: 0; cursor: default; outline: none; }
.map-overlay.placing { cursor: crosshair; }

.play { padding: 10px; }
.play-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.play-head label { display: flex; align-items: center; gap: 6px; color: var(--muted); }
.play-status { color: var(--muted); }
.play-status.bad { color: var(--bad); }
.screen-wrap { display: flex; gap: 16px; align-items: flex-start; flex-wrap: wrap; }
#screen {
  width: 512px;
  height: 480px;
  max-width: 100%;
  aspect-ratio: 256 / 240;
  height: auto;
  background: #000;
  image-rendering: pixelated;
  border-radius: 4px;
  outline: 2px solid transparent;
}
#screen:focus { outline-color: var(--accent-2); }
.keys { display: grid; gap: 6px; color: var(--muted); }
.side { display: grid; gap: 12px; align-content: start; min-width: 280px; flex: 1; max-width: 420px; }
.board { background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; }
.board-head { display: flex; align-items: baseline; gap: 8px; }
.board h3 { margin: 0; font-size: 13px; letter-spacing: 0.5px; text-transform: uppercase; color: var(--accent); }
.board ol { list-style: none; margin: 8px 0 0; padding: 0; font-family: ui-monospace, monospace; }
.board li { display: grid; grid-template-columns: 2.2em 3.4em 1fr auto auto; gap: 8px; align-items: center; padding: 3px 4px; border-radius: 4px; }
.board li:nth-child(1) { color: var(--accent); }
.board li.mine { background: #2d3a24; }
.board .t { font-variant-numeric: tabular-nums; }
.board .d { color: var(--muted); font-size: 11px; }
.board li button { padding: 1px 7px; font-size: 11px; }
.finish { text-align: center; min-width: 360px; }
.finish-title { font: 800 20px ui-monospace, monospace; color: var(--accent); letter-spacing: 2px; }
.finish-time { font: 800 44px ui-monospace, monospace; margin: 4px 0; font-variant-numeric: tabular-nums; }
.initials { display: flex; justify-content: center; gap: 10px; margin: 16px 0 6px; outline: none; }
.initials .cell {
  width: 52px; height: 64px; display: grid; place-items: center;
  font: 800 38px ui-monospace, monospace; background: #13151a; border: 2px solid var(--line); border-radius: 8px;
}
.initials .cell.active { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(255, 210, 63, 0.25); }
.finish menu { justify-content: center; gap: 8px; }

.inspector { padding: 12px; overflow: auto; max-height: calc(100vh - 72px); position: sticky; top: 10px; }
.card { border-top: 1px solid var(--line); padding: 10px 0; }
.card:first-child { border-top: 0; padding-top: 0; }
.field { display: grid; grid-template-columns: 96px minmax(0, 1fr); gap: 8px; align-items: center; margin: 6px 0; }
.field select { width: 100%; }
.field > span { color: var(--muted); }
.row-btns { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.hex {
  font: 11px/1.5 ui-monospace, monospace;
  color: #b8c0d4;
  background: #13151a;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 8px;
  word-break: break-all;
  max-height: 140px;
  overflow: auto;
}
.title { font-size: 15px; font-weight: 650; margin-bottom: 2px; }
.sub { color: var(--muted); font-size: 12px; }

.dropzone {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(10, 11, 14, 0.92);
  z-index: 10;
}
.dropzone.hidden { display: none; }
.dropzone.drag .dropcard { border-color: var(--accent); }
.dropcard {
  text-align: center;
  padding: 36px 48px;
  border: 2px dashed var(--line);
  border-radius: 14px;
  background: var(--panel);
  max-width: 460px;
}
.dropcard h1 { margin: 0 0 8px; font-size: 22px; }
.error { color: var(--bad); }

dialog {
  max-width: 620px;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 18px 22px;
}
dialog::backdrop { background: rgba(0, 0, 0, 0.6); }
dialog h3 { margin-bottom: 4px; }
dialog menu { display: flex; justify-content: flex-end; padding: 0; margin: 14px 0 0; }

.toast {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: #2a2f39;
  border: 1px solid var(--line);
  padding: 8px 14px;
  border-radius: 8px;
  transition: transform 0.2s, opacity 0.2s;
  opacity: 0;
  pointer-events: none;
  z-index: 20;
}
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }
.toast.bad { border-color: var(--bad); }

@media (max-width: 1100px) {
  .layout { grid-template-columns: 1fr; }
  .palette, .inspector { position: static; max-height: none; }
}

/* --- shared bits added with the player view and courses --- */
.hidden { display: none !important; }
a.btn { text-decoration: none; display: inline-block; }
a.btn.subtle { color: var(--muted); }
.tag {
  font-size: 10px; font-weight: 650; text-transform: uppercase; letter-spacing: 0.6px;
  color: #1a1a1a; background: var(--accent-2); border-radius: 4px; padding: 1px 5px;
}
.field-inline { display: flex; align-items: center; gap: 6px; color: var(--muted); }
.screen-box { flex: 1 1 512px; min-width: 0; display: flex; justify-content: center; }
#screen { width: 512px; max-width: 100%; height: auto; }

/* player view: the game screen gets all the space the leaderboard leaves */
body.player { display: flex; flex-direction: column; min-height: 100%; }
.player #levelSelect { min-width: 220px; }
.player-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 16px;
  padding: 14px;
  flex: 1;
}
.player .stage { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.player .stage .play-status { text-align: center; }
.player .side { max-width: none; min-width: 0; }
@media (max-width: 900px) {
  .player-layout { grid-template-columns: 1fr; }
}

/* admin: course dialog */
.course-dialog { min-width: 440px; }
.course-dialog .field { grid-template-columns: 60px minmax(0, 1fr); }
.course-parts { list-style: none; padding: 0; margin: 10px 0; display: grid; gap: 4px; }
.course-parts li {
  display: grid; grid-template-columns: 1fr auto auto auto auto; gap: 6px; align-items: center;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; padding: 4px 6px 4px 10px;
}
.course-parts button { padding: 1px 8px; }
.hint.warn { color: #e8b04a; }
