:root {
  --bg: #0f1418;
  --panel: #161d23;
  --box: #1d262e;
  --line: #2a3640;
  --text: #e6edf2;
  --muted: #8a9aa6;
  --accent: #4fc3f7;
  --gold: #ffd54f;
  --danger: #ef5350;
}

* { box-sizing: border-box; }

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

#app {
  display: flex;
  height: 100vh;
}

#stage {
  position: relative;
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

#game {
  display: block;
  border-radius: 8px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5);
  cursor: crosshair;
}

#panel {
  width: 300px;
  flex-shrink: 0;
  padding: 16px;
  background: var(--panel);
  border-left: 1px solid var(--line);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

h1, h2 { margin: 0; }
h2 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-top: 4px;
}

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.stat {
  background: var(--box);
  border-radius: 8px;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
}
.stat .label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.stat .value { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.value.gold { color: var(--gold); }
.value.danger { color: var(--danger); }

.box {
  background: var(--box);
  border-radius: 8px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.mods { display: flex; flex-wrap: wrap; gap: 4px; }
.mods:empty { display: none; }
.chip {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(255, 183, 77, 0.15);
  color: #ffb74d;
  border: 1px solid rgba(255, 183, 77, 0.35);
}
.chip.boss { background: rgba(239, 83, 80, 0.15); color: var(--danger); border-color: rgba(239, 83, 80, 0.4); }

button {
  font: inherit;
  color: var(--text);
  background: #26323c;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}
button:hover:not(:disabled) { background: #2e3c48; }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.primary { background: #1e6b8f; border-color: #2a87b3; justify-content: center; }
button.primary:hover:not(:disabled) { background: #2380ab; }
button.wide { width: 100%; }

kbd {
  font: 11px ui-monospace, Menlo, monospace;
  padding: 1px 5px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: var(--muted);
}

.shop { display: grid; grid-template-columns: 1fr; gap: 6px; }
.shop-item { justify-content: flex-start; }
.shop-item .name { flex: 1; text-align: left; }
.shop-item .cost { color: var(--gold); font-variant-numeric: tabular-nums; }
.shop-item.active { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.swatch { width: 12px; height: 12px; border-radius: 3px; flex-shrink: 0; }

.sel-head { display: flex; justify-content: space-between; font-weight: 700; font-size: 15px; }
.kv {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 2px 12px;
  margin: 0;
  font-size: 13px;
}
.kv dt { color: var(--muted); }
.kv dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.kv .up { color: #aed581; }

.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.actions .span2 { grid-column: span 2; }

.controls { display: grid; grid-template-columns: 1fr; gap: 6px; }

.muted { color: var(--muted); }
.small { font-size: 12px; margin: 0; }
.help { margin-top: auto; }
.hidden { display: none !important; }

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(8, 12, 15, 0.72);
  backdrop-filter: blur(3px);
}
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 28px 32px;
  max-width: 440px;
  width: calc(100% - 32px);
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.card h1 { font-size: 32px; letter-spacing: 0.02em; }
.card .tag { color: var(--accent); margin: 0; }
.card .rules { text-align: left; color: var(--muted); padding-left: 18px; margin: 0; }
.card .rules li { margin: 4px 0; }
.card p { margin: 0; }
.best { color: var(--gold); }
.card.wide { max-width: 760px; }
.card .row { display: flex; gap: 8px; justify-content: center; }
.card .row button { align-self: auto; }

.map-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 8px;
}
.map-card {
  flex-direction: column;
  align-items: stretch;
  gap: 4px;
  padding: 6px;
  text-align: left;
}
.card .map-card { padding: 6px; font-size: 13px; }
.map-card canvas { width: 100%; aspect-ratio: 20 / 12; border-radius: 4px; display: block; }
.map-card .map-name { font-weight: 700; }
.map-card .map-meta { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); }
.map-card.selected { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.map-desc { color: var(--muted); min-height: 2.8em; font-size: 13px; }
.diff { font-weight: 700; }
.diff-Easy { color: #aed581; }
.diff-Normal { color: #4fc3f7; }
.diff-Hard { color: #ffb74d; }
.diff-Expert { color: #ef5350; }

.map-label { font-size: 13px; color: var(--muted); display: flex; justify-content: space-between; }
.map-label strong { color: var(--text); }
.card button { align-self: center; padding: 10px 28px; font-size: 16px; }

@media (max-width: 900px) {
  #app { flex-direction: column; height: auto; min-height: 100vh; }
  #stage { height: 62vw; flex: none; }
  #panel { width: 100%; border-left: none; border-top: 1px solid var(--line); }
}

.name-field { display: flex; flex-direction: column; gap: 4px; text-align: left; font-size: 12px; color: var(--muted); }
.name-field input {
  font: inherit;
  font-size: 15px;
  color: var(--text);
  background: var(--box);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  user-select: text;
}
.name-field input:focus { outline: none; border-color: var(--accent); }
.danger { color: var(--danger); }

.tabs { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.tabs button { padding: 6px 12px; }
.tabs button.active { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.small-tabs button { padding: 4px 10px; font-size: 12px; }
.card.board { max-height: calc(100vh - 32px); }
.board-body { overflow-y: auto; min-height: 120px; max-height: 46vh; }
.board table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; font-size: 14px; }
.board th { text-align: left; color: var(--muted); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; padding: 4px 8px; }
.board td { padding: 6px 8px; border-top: 1px solid var(--line); text-align: left; }
.board th:nth-child(n+3), .board td:nth-child(n+3) { text-align: right; }
.board td:first-child { color: var(--muted); width: 3em; }
.board td.name { overflow-wrap: anywhere; }
.board tr.me td { background: rgba(79, 195, 247, 0.12); }
.board tr.top1 td:first-child { color: #ffd54f; font-weight: 700; }
.board tr.top2 td:first-child { color: #cfd8dc; font-weight: 700; }
.board tr.top3 td:first-child { color: #ffab91; font-weight: 700; }
.board #board-status:empty { display: none; }
#overlay-board { z-index: 5; }
