:root {
  --bg: #0d0f12;
  --panel: #161a20;
  --edge: #2a303a;
  --text: #d7dce3;
  --muted: #8b93a1;
  --accent: #6fd3ff;
}

* { box-sizing: border-box; }

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

header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--edge);
  background: var(--panel);
  flex-wrap: wrap;
}

h1 { margin: 0; font-size: 15px; font-weight: 600; }
h2 { margin: 0 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }

.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

button, select, input[type="number"] {
  background: #222831;
  color: var(--text);
  border: 1px solid var(--edge);
  border-radius: 4px;
  padding: 4px 10px;
  font: inherit;
}
button { cursor: pointer; }
button:hover { border-color: #4a5566; }
button.on, button.tab.active { background: #2f4a5c; border-color: var(--accent); }

#layout {
  display: flex;
  gap: 16px;
  padding: 12px 16px;
  align-items: flex-start;
}

#stage { flex: none; }

#game {
  display: block;
  image-rendering: pixelated;
  background: #050607;
  border: 1px solid var(--edge);
  cursor: crosshair;
  touch-action: none;
}

#tabs { display: flex; gap: 4px; margin-bottom: 8px; flex-wrap: wrap; }
.zoom { display: inline-flex; gap: 4px; align-items: center; }
#blocks { display: flex; gap: 4px; flex-wrap: wrap; min-height: 40px; }
#blocks button.block { padding: 2px; border-radius: 3px; line-height: 0; }
#blocks button.block[hidden] { display: none; }
#blocks button.block.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
#blocks canvas { image-rendering: pixelated; }

.hint { margin: 8px 0 0; color: var(--muted); font-size: 12px; }

#side {
  width: 340px;
  flex: none;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#side section {
  background: var(--panel);
  border: 1px solid var(--edge);
  border-radius: 4px;
  padding: 10px;
}

#minimap {
  width: 100%;
  image-rendering: pixelated;
  border: 1px solid var(--edge);
  background: #12151a;
  max-height: 200px;
  object-fit: contain;
}

.row { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; align-items: center; }
.row label { display: flex; gap: 6px; align-items: center; }
.row input[type="number"] { width: 70px; }

pre#readout {
  margin: 0;
  font: 12px/1.5 ui-monospace, Menlo, Consolas, monospace;
  white-space: pre;
  overflow-x: auto;
}

.slider {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0;
  margin-bottom: 6px;
}
.slider span { font-size: 12px; color: var(--muted); }
.slider input[type="range"] { width: 100%; margin: 2px 0; }
.slider output { font: 11px ui-monospace, Menlo, Consolas, monospace; color: var(--text); text-align: right; }
.slider output.changed { color: #f5c542; }

@media (max-width: 1100px) {
  #layout { flex-direction: column; }
  #side { width: 100%; max-width: 736px; }
}

.warn {
  padding: 12px 16px;
  background: #5c2a2a;
  color: #ffd9d9;
  border-bottom: 1px solid #a04444;
  font-size: 14px;
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(5, 6, 7, 0.88);
  overflow: auto;
  padding: 16px;
}
.overlay[hidden] { display: none; }

.dialog {
  width: min(900px, 100%);
  background: var(--panel);
  border: 1px solid var(--edge);
  border-radius: 6px;
  padding: 20px;
}
.dialog h2 { font-size: 16px; color: var(--text); text-transform: none; letter-spacing: 0; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.dialog-head h2 { margin: 0; }
.dialog h3 { margin: 12px 0 6px; font-size: 13px; color: var(--muted); }

.field { display: block; margin-bottom: 10px; color: var(--muted); font-size: 12px; }
.field input { display: block; width: 100%; margin-top: 3px; }
.field.small { flex: 1; margin-bottom: 0; }

input[type="text"], input[type="search"], input[type="password"], input[type="number"] {
  background: #222831;
  color: var(--text);
  border: 1px solid var(--edge);
  border-radius: 4px;
  padding: 5px 8px;
  font: inherit;
}
input:focus-visible, button:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.lobby-cols { display: grid; grid-template-columns: 1.5fr 1fr; gap: 20px; }
@media (max-width: 700px) { .lobby-cols { grid-template-columns: 1fr; } }

.list-tools { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; }
.search { position: relative; flex: 1; min-width: 120px; }
.search span { position: absolute; left: 8px; top: 50%; transform: translateY(-50%); font-size: 12px; pointer-events: none; }
.search input { width: 100%; padding-left: 28px; }
.segmented { display: flex; }
.segmented[hidden] { display: none; }
.segmented button { border-radius: 0; }
.segmented button:first-child { border-radius: 4px 0 0 4px; }
.segmented button:last-child { border-radius: 0 4px 4px 0; border-left: 0; }

.rooms-wrap { max-height: 280px; overflow: auto; border: 1px solid var(--edge); border-radius: 4px; }
.rooms-wrap table { width: 100%; border-collapse: collapse; }
.rooms-wrap th {
  position: sticky;
  top: 0;
  padding: 5px 8px;
  background: var(--panel);
  border-bottom: 1px solid var(--edge);
  color: var(--muted);
  font-size: 12px;
  font-weight: normal;
  text-align: left;
}
.rooms-wrap td { padding: 4px 8px; border-top: 1px solid var(--edge); vertical-align: middle; }
.rooms-wrap tr:first-child td { border-top: 0; }
.rooms-wrap .num { text-align: right; font-variant-numeric: tabular-nums; width: 1%; white-space: nowrap; }
.rooms-wrap .fav, .rooms-wrap .act { width: 1%; white-space: nowrap; }
.rooms-wrap td.empty { padding: 10px 8px; color: var(--muted); }
.room-name { display: flex; gap: 6px; align-items: center; word-break: break-word; }
.lock { font-size: 11px; }
button.star { padding: 0 4px; border: 0; background: transparent; color: var(--muted); font-size: 18px; line-height: 1; }
button.star:hover { color: var(--text); }
button.star.on { color: #f5c542; }

#lobby-status { min-height: 20px; margin: 12px 0 8px; color: var(--muted); }
#lobby-status.error, #unlock-status.error { color: #ff9b9b; }
button.secondary { background: transparent; }
button:disabled { opacity: .5; cursor: default; }

#notice {
  padding: 10px 16px;
  background: #5c2a2a;
  color: #ffd9d9;
  border-bottom: 1px solid #a04444;
}
#notice[hidden] { display: none; }

#conn-status { color: var(--muted); font-size: 12px; }

#chat-log {
  height: 150px;
  overflow-y: auto;
  margin-bottom: 6px;
  padding: 4px 6px;
  background: #0f1217;
  border: 1px solid var(--edge);
  border-radius: 4px;
  font-size: 12px;
  word-break: break-word;
}
.chat-line.history { opacity: .6; }
.chat-line.system { color: var(--muted); font-style: italic; }
.chat-name { color: var(--accent); }
#chat-input { width: 100%; }
#unlock .row input { flex: 1; min-width: 0; }
body.online #offline-tools { display: none; }
body:not(.online) #chat { display: none; }

.dialog.narrow { width: min(380px, 100%); }
.status { min-height: 20px; margin: 12px 0 0; color: var(--muted); }
.status.error { color: #ff9b9b; }
body.admin #admin-panel { max-width: 1100px; margin: 20px auto; padding: 0 16px; }
body.admin .rooms-wrap { max-height: none; }
.pager { display: flex; gap: 12px; align-items: center; justify-content: center; margin-top: 12px; color: var(--muted); }
button.danger { background: #5c2a2a; border-color: #a04444; }
.actions { display: flex; gap: 6px; justify-content: flex-end; }
#import-info { margin: 0 0 8px; }

#coins { display: inline-flex; gap: 6px; align-items: center; font-variant-numeric: tabular-nums; }
#coins[hidden] { display: none; }
#coins.complete { color: #f5c542; }
#tabs[inert], #blocks[inert] { opacity: .4; }
