:root {
  --bg: #07080b;
  --panel: rgba(8, 10, 16, 0.86);
  --text: #e8ebf2;
  --muted: #8d95a8;
  --accent: #f5d326;
  --line: #2b303b;
  --touch-h: 0px;
  color-scheme: dark;
}

@media (pointer: coarse) {
  :root { --touch-h: 112px; }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", "Noto Sans TC", sans-serif;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#app {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

#stage {
  position: relative;
  aspect-ratio: 416 / 400;
  width: min(100vw, calc((100dvh - var(--touch-h)) * 1.04), 832px);
  touch-action: none;
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.overlay {
  position: absolute;
  inset: 12% 6% 4%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  text-align: center;
  overflow: auto;
}

.hidden { display: none !important; }

h1 {
  margin: 0;
  font-size: clamp(22px, 6vw, 34px);
  letter-spacing: 0.06em;
  color: var(--accent);
}
h1 small {
  display: block;
  font-size: 0.5em;
  letter-spacing: 0.2em;
  color: var(--muted);
}
h2 { margin: 0; font-size: clamp(24px, 7vw, 36px); }
p { margin: 0; }

.row { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }

button {
  font: inherit;
  font-weight: 600;
  color: var(--text);
  background: #1b1f28;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 18px;
  min-height: 44px;
  cursor: pointer;
}
button:hover { background: #252a35; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button.primary { background: var(--accent); color: #1a1600; border-color: var(--accent); }
button.primary:hover { background: #ffe24d; }

.modes {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  width: min(100%, 420px);
}
.mode { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 12px 8px; }
.mode b { font-size: 17px; }
.mode span { font-size: 11px; font-weight: 400; opacity: 0.75; }
.mode.online { border-color: #4a7bd1; }
.mode.online b { color: #8fb4ff; }
button.small { min-height: 0; padding: 6px 12px; font-size: 13px; font-weight: 400; color: var(--muted); }

.segmented { gap: 0; }
.segmented button { border-radius: 0; min-width: 80px; }
.segmented button:first-child { border-radius: 8px 0 0 8px; }
.segmented button:last-child { border-radius: 0 8px 8px 0; }
.segmented button[aria-pressed="true"] { background: #39404f; color: var(--accent); }

.toggles { font-size: 14px; color: var(--muted); gap: 4px 14px; }
.toggles label { display: inline-flex; align-items: center; gap: 4px; cursor: pointer; }

.records { border-collapse: collapse; font-size: 14px; min-width: 200px; }
.records caption { color: var(--muted); font-size: 12px; padding-bottom: 4px; }
.records td { padding: 2px 10px; border-top: 1px solid var(--line); }
.records td:first-child { color: var(--muted); }
.records td:last-child { text-align: right; font-variant-numeric: tabular-nums; }

.hint { font-size: 12px; color: var(--muted); }
.new-record { color: var(--accent); font-weight: 700; margin-bottom: 6px; }

#recordForm { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
#recordForm .new-record { flex-basis: 100%; }
#nameInput {
  font: inherit;
  color: var(--text);
  background: #11141b;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 12px;
  width: 12em;
  -webkit-user-select: text;
  user-select: text;
}

#pauseBtn {
  position: absolute;
  top: 1.5%;
  right: 1.5%;
  min-height: 0;
  padding: 2px 8px;
  font-size: 11px;
  opacity: 0.6;
}

#touch { display: none; }
.touch-only { display: none; }

@media (pointer: coarse) {
  #touch {
    display: flex;
    gap: 16px;
    width: min(100vw, 520px);
    height: var(--touch-h);
    padding: 12px 16px;
  }
  #touch button {
    flex: 1;
    font-size: 32px;
    border-radius: 16px;
    touch-action: none;
  }
  #touch button:active { background: #39404f; }
  .kbd-only { display: none; }
  .touch-only { display: block; }
}

.stack { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.error { color: #ff7b7b; font-size: 14px; min-height: 1em; }
.code { font-size: 1.5em; letter-spacing: 0.15em; color: var(--accent); }
#roomInput {
  font: inherit;
  font-size: 18px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  text-align: center;
  width: 6em;
  color: var(--text);
  background: #11141b;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  -webkit-user-select: text;
  user-select: text;
}
#netStatus {
  position: absolute;
  left: 50%;
  bottom: 2%;
  transform: translateX(-50%);
  padding: 3px 10px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.6);
  color: var(--text);
  font-size: 12px;
  pointer-events: none;
  white-space: nowrap;
}
button:disabled { opacity: 0.45; cursor: default; }

/* Party run leaderboard on the death overlay */
.boardTitle { margin: 6px 0 2px; font-size: 13px; }
.board { margin: 0 0 8px; padding: 0; list-style: none; font-size: 13px; text-align: left; display: inline-block; }
.board li.left { opacity: .55; }

/* Party run death overlay: a compact panel at the bottom so the spectator camera stays visible. */
#ghostOver {
  inset: auto 4% 3%;
  max-height: 46%;
  gap: 4px;
  padding: 8px 12px;
  background: color-mix(in srgb, var(--panel) 82%, transparent);
}
#ghostOver h2 { margin: 0; font-size: 18px; }
#ghostOver p { margin: 0; }
#ghostOver .boardTitle { display: none; }
#ghostOver .board { margin: 0; font-size: 12px; columns: 2; column-gap: 16px; }
