:root {
  color-scheme: dark;
  --ink: #f4f1e8;
  --muted: #aeb9ae;
  --panel: #17261f;
  --panel-raised: #20342a;
  --panel-soft: rgba(23, 38, 31, 0.88);
  --line: rgba(234, 241, 230, 0.14);
  --accent: #d9f275;
  --accent-strong: #bfe24e;
  --goal: #ffb35c;
  --danger: #ff7d72;
  --shadow: 0 14px 38px rgba(0, 0, 0, 0.34);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #0e1713;
  color: var(--ink);
  overscroll-behavior: none;
}

button, input { font: inherit; }
button { touch-action: manipulation; }

.app-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  width: 100%;
  height: 100dvh;
  max-width: 900px;
  margin: 0 auto;
  background: var(--panel);
  border-inline: 1px solid var(--line);
}

.topbar {
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 72px;
  padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.brand-block { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 13px;
  background: var(--accent);
  color: #142018;
  font-size: 28px;
  font-weight: 900;
  transform: rotate(-12deg);
}

h1 { margin: 0; font-size: 18px; letter-spacing: -0.02em; }
.name-button {
  max-width: 145px;
  padding: 2px 0;
  overflow: hidden;
  color: var(--muted);
  background: none;
  border: 0;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}

.round-stats { display: flex; gap: 14px; }
.round-stats div { display: grid; text-align: right; }
.round-stats span { color: var(--muted); font-size: 10px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; }
.round-stats strong { font-size: 20px; font-variant-numeric: tabular-nums; line-height: 1.1; }

.game-area {
  position: relative;
  min-height: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 15% 12%, rgba(217, 242, 117, 0.08), transparent 34%),
    #101b16;
}

#mazeCanvas {
  display: block;
  width: 100%;
  height: 100%;
  outline: none;
  cursor: grab;
  touch-action: none;
}
#mazeCanvas:active { cursor: grabbing; }

.connection-banner {
  position: absolute;
  top: 10px;
  left: 50%;
  z-index: 4;
  padding: 7px 12px;
  border: 1px solid rgba(255, 179, 92, 0.35);
  border-radius: 999px;
  background: rgba(40, 28, 18, 0.92);
  color: #ffd4a2;
  font-size: 12px;
  transform: translateX(-50%);
  white-space: nowrap;
  box-shadow: var(--shadow);
}
.connection-banner.online { display: none; }

.round-banner {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 2;
  display: grid;
  gap: 1px;
  max-width: calc(100% - 120px);
  padding: 8px 11px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel-soft);
  pointer-events: none;
  backdrop-filter: blur(10px);
}
.round-banner strong { font-size: 13px; }
.round-banner span { color: var(--muted); font-size: 11px; }

.map-controls {
  position: absolute;
  right: 12px;
  top: 12px;
  z-index: 3;
  display: grid;
  gap: 7px;
}
.map-controls button, .reaction-bar button, .icon-button {
  display: grid;
  place-items: center;
  width: 44px;
  min-height: 44px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--panel-soft);
  color: var(--ink);
  font-size: 24px;
  cursor: pointer;
  box-shadow: 0 7px 18px rgba(0, 0, 0, 0.22);
  backdrop-filter: blur(10px);
}
.map-controls button:hover, .reaction-bar button:hover { background: var(--panel-raised); }
.map-controls .recenter { gap: 0; min-height: 54px; font-size: 22px; }
.control-label { font-size: 9px; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; }

.reaction-bar {
  position: absolute;
  left: 50%;
  bottom: 12px;
  z-index: 3;
  display: flex;
  gap: 7px;
  transform: translateX(-50%);
}
.reaction-bar button { width: 42px; min-height: 42px; font-size: 20px; }

.standings-panel {
  z-index: 5;
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--panel);
  border-top: 1px solid var(--line);
}
.standings-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  min-height: 54px;
  padding: 9px 16px;
  border: 0;
  background: transparent;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}
.standings-toggle > span:first-child { display: grid; gap: 1px; }
.standings-toggle strong { font-size: 14px; }
.standings-toggle small { color: var(--muted); font-size: 11px; }
.standings-body { max-height: 190px; overflow: auto; padding: 0 14px 12px; }
.standings-panel.collapsed .standings-body { display: none; }
.standings-panel.collapsed #standingsChevron { transform: rotate(180deg); }
#standingsList { display: grid; gap: 5px; margin: 0; padding: 0; list-style: none; counter-reset: standing; }
#standingsList li {
  counter-increment: standing;
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  padding: 5px 8px;
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.035);
  font-size: 12px;
}
#standingsList li::before { content: counter(standing); color: var(--muted); font-variant-numeric: tabular-nums; }
#standingsList li.self { outline: 1px solid rgba(217, 242, 117, 0.45); background: rgba(217, 242, 117, 0.08); }
.standing-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.standing-meta { color: var(--muted); font-size: 10px; }
.standing-score { font-weight: 800; font-variant-numeric: tabular-nums; }
#standingsEmpty { margin: 5px 2px; color: var(--muted); font-size: 12px; }

dialog {
  width: min(92vw, 420px);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: #1a2b23;
  color: var(--ink);
  box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(4, 9, 7, 0.72); backdrop-filter: blur(3px); }
dialog form { display: grid; gap: 12px; padding: 20px; }
.dialog-heading { display: flex; align-items: start; justify-content: space-between; gap: 16px; }
.dialog-heading h2 { margin: 2px 0 0; font-size: 20px; }
.eyebrow { color: var(--accent); font-size: 10px; font-weight: 800; letter-spacing: 0.1em; text-transform: uppercase; }
dialog p { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.5; }
dialog label { font-size: 12px; font-weight: 750; }
dialog input {
  width: 100%;
  min-height: 46px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 11px;
  outline: none;
  background: #101b16;
  color: var(--ink);
}
dialog input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(217, 242, 117, 0.13); }
.dialog-actions { display: flex; justify-content: end; gap: 9px; margin-top: 3px; }
.primary-button, .secondary-button {
  min-height: 42px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 11px;
  cursor: pointer;
}
.primary-button { border-color: transparent; background: var(--accent); color: #142018; font-weight: 800; }
.secondary-button { background: transparent; color: var(--ink); }
.icon-button { box-shadow: none; }
.form-error { min-height: 18px; color: var(--danger); }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(82px + env(safe-area-inset-bottom));
  z-index: 20;
  max-width: min(88vw, 420px);
  padding: 10px 14px;
  border-radius: 999px;
  background: #f4f1e8;
  color: #17261f;
  font-size: 12px;
  font-weight: 750;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 12px);
  transition: opacity 160ms ease, transform 160ms ease;
  box-shadow: var(--shadow);
}
.toast.visible { opacity: 1; transform: translate(-50%, 0); }
.install-button { position: fixed; right: 12px; bottom: 12px; z-index: 15; }

@media (min-width: 700px) and (orientation: landscape) {
  .app-shell { grid-template-columns: minmax(0, 1fr) 250px; grid-template-rows: auto minmax(0, 1fr); }
  .topbar { grid-column: 1 / -1; }
  .standings-panel { border-top: 0; border-left: 1px solid var(--line); }
  .standings-toggle { cursor: default; }
  .standings-body { display: block !important; max-height: calc(100dvh - 130px); }
  #standingsChevron { display: none; }
}

@media (max-height: 600px) {
  .topbar { min-height: 60px; }
  .standings-body { max-height: 120px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; animation: none !important; }
}
