:root {
  color-scheme: dark;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

#speaker {
  position: absolute;
  width: 0;
  height: 0;
  opacity: 0;
  pointer-events: none;
}

html, body {
  margin: 0;
  height: 100%;
  background: #0b0b0b;
  color: #f4f4f4;
  font-family: "Courier New", ui-monospace, monospace;
  touch-action: none;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}

#app {
  position: relative;
  width: 100%;
  height: 100%;
  display: grid;
  grid-template: "stage" minmax(0, 1fr) "dock" auto / minmax(0, 1fr);
}

/* The stage holds the canvas. game.js sizes the canvas so every player sees the same slice of the pit. */
#stage {
  grid-area: stage;
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: #0b0b0b;
}

canvas {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #111;
  cursor: crosshair;
}


/* ---------- HUD: stats on the left (solo), sound and close on the right ---------- */

#hud {
  position: absolute;
  top: max(8px, env(safe-area-inset-top));
  left: 8px;
  right: 8px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
  pointer-events: none;
  z-index: 2;
}

.icons {
  display: flex;
  gap: 6px;
  margin-left: auto;
}

#live {
  pointer-events: none;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  color: #f4f4f4;
  background: rgba(10, 10, 10, 0.86);
  border: 2px solid #e8e8e8;
  font: 800 11px/1 ui-monospace, monospace;
  letter-spacing: 0.12em;
}

#live .on {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: #3dd68c;
}

#live i {
  width: 7px;
  height: 7px;
  background: currentColor;
}

#live b { font-weight: 800; }

#live .sep { opacity: 0.45; }

.icon {
  pointer-events: auto;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  color: #f4f4f4;
  background: rgba(10, 10, 10, 0.86);
  border: 2px solid #e8e8e8;
}

.icon:active { background: #333; }
.icon svg { width: 20px; height: 20px; }
.icon .off { display: none; }
.icon[aria-pressed="true"] { color: #8a8a8a; border-color: #777; }
.icon[aria-pressed="true"] .on { display: none; }
.icon[aria-pressed="true"] .off { display: block; }

#minimap {
  position: absolute;
  right: 8px;
  bottom: 8px;
  width: 176px;
  height: 110px;
  z-index: 2;
  pointer-events: none;
  border: 2px solid #e8e8e8;
  background: rgba(10, 10, 10, 0.7);
  image-rendering: auto;
  cursor: default;
  transform: none;
  left: auto;
  top: auto;
}

/* ---------- Dock: the action buttons sit under the map, never over it ---------- */

#dock {
  grid-area: dock;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 16px;
  padding: 8px 12px max(8px, env(safe-area-inset-bottom));
  background: #0b0b0b;
  border-top: 1px solid #2a2a2a;
  z-index: 3;
}

.pads {
  display: flex;
  gap: 10px;
  align-items: center;
}

.pad {
  position: relative;
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  padding: 0;
  color: #f4f4f4;
  background: #161616;
  border: 2px solid #e8e8e8;
  border-radius: 10px;
  overflow: hidden;
  touch-action: none;
}

.pad:active { background: #2e2e2e; }
.pad.act { background: #f2f2f2; color: #111; }
.pad.act:active { background: #bdbdbd; }
.pad svg { width: 28px; height: 28px; }

.pad kbd {
  position: absolute;
  left: 4px;
  bottom: 2px;
  font: inherit;
  font-size: 8px;
  letter-spacing: 0.04em;
  opacity: 0.65;
}

.pad b {
  position: absolute;
  top: 2px;
  right: 5px;
  font-size: 11px;
}

.pad i {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 0%;
  background: rgba(255, 255, 255, 0.3);
  pointer-events: none;
}

.pad.cool { opacity: 0.45; }

.stick {
  display: none;
  width: 92px;
  height: 92px;
  border-radius: 50%;
  border: 2px solid rgba(230, 230, 230, 0.7);
  background: rgba(20, 20, 20, 0.6);
  position: relative;
  touch-action: none;
  flex: none;
}

#knob {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: rgba(240, 240, 240, 0.88);
  position: absolute;
  left: 50%;
  top: 50%;
  margin: -19px 0 0 -19px;
  pointer-events: none;
}

@media (pointer: coarse) {
  .stick { display: block; }
  #dock { justify-content: space-between; padding: 6px 14px max(6px, env(safe-area-inset-bottom)); }
  .pad kbd { display: none; }
  .pads { gap: 8px; }
  .pad { width: 68px; height: 68px; border-radius: 12px; }
  .pad svg { width: 36px; height: 36px; }
  .pad b { top: 3px; right: 7px; font-size: 14px; }
  .stick { width: 88px; height: 88px; }
  #knob { width: 34px; height: 34px; margin: -17px 0 0 -17px; }
  .icon { width: 32px; height: 32px; }
  .icon svg { width: 18px; height: 18px; }
  #minimap { width: 112px; height: 70px; }
  #board { top: 6px; left: 6px; min-width: 104px; max-width: 128px; padding: 3px 5px; font-size: 9px; border-width: 1px; }
  #toast { top: 44px; font-size: 11px; padding: 4px 8px; }
  #toast.wave { top: 44px; font-size: 15px; padding: 6px 14px; }
}

#toast {
  position: absolute;
  top: 52px;
  left: 50%;
  transform: translateX(-50%);
  background: #111;
  border: 2px solid #ddd;
  padding: 6px 12px;
  font-size: 12px;
  letter-spacing: 0.06em;
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
  z-index: 3;
  max-width: 90vw;
  text-align: center;
}

#toast.show { opacity: 1; }
#toast.wave { font-size: 20px; letter-spacing: 0.22em; padding: 8px 22px; top: 40px; }

#title, .panel {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 12px;
  background: rgba(0, 0, 0, 0.78);
  z-index: 5;
  text-align: center;
  padding: 24px;
}

#title h1, .panel h2 {
  margin: 0;
  font-size: clamp(30px, 6vw, 54px);
  letter-spacing: 0.1em;
}

#title p, .panel p {
  max-width: 36rem;
  margin: 0;
  color: #d0d0d0;
  line-height: 1.45;
}

#title ul, .panel ul {
  text-align: left;
  margin: 0;
  padding-left: 18px;
  color: #c8c8c8;
  font-size: 14px;
  line-height: 1.5;
}

button {
  font-family: inherit;
  background: #f2f2f2;
  color: #111;
  border: 0;
  padding: 12px 18px;
  letter-spacing: 0.08em;
  cursor: pointer;
}

button:active { background: #bdbdbd; }

#title small {
  color: #888;
  font-size: 11px;
  max-width: 28rem;
}

#tags {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 2;
  overflow: hidden;
}

.tag {
  position: absolute;
  left: 0;
  top: 0;
  text-align: center;
  white-space: nowrap;
}

.tag b,
.tag i {
  display: inline-block;
  background: rgba(8, 8, 8, 0.88);
  border: 1px solid #f2f2f2;
  color: #fff;
  line-height: 1.2;
}

.tag b {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.03em;
  padding: 1px 6px;
}

.tag i {
  display: block;
  margin: 2px auto 0;
  width: fit-content;
  font-style: normal;
  font-size: 10px;
  letter-spacing: 0.08em;
  padding: 0 5px;
  border-color: #bbb;
  color: #f4f4f4;
}

.tag u {
  display: block;
  width: 36px;
  height: 4px;
  margin: 3px auto 0;
  background: #2a2a2a;
  border: 1px solid #888;
  text-decoration: none;
}

.tag u s {
  display: block;
  height: 100%;
  background: #f2f2f2;
  text-decoration: none;
}

#deadnote {
  position: absolute;
  left: 50%;
  top: 46%;
  transform: translate(-50%, -50%);
  z-index: 3;
  background: rgba(8, 8, 8, 0.88);
  border: 2px solid #f2f2f2;
  padding: 10px 14px;
  letter-spacing: 0.08em;
  font-size: 14px;
}

#board {
  position: absolute;
  top: 8px;
  left: 8px;
  min-width: 150px;
  max-width: 190px;
  padding: 6px 8px;
  background: rgba(10, 10, 10, 0.8);
  border: 2px solid #e8e8e8;
  font-size: 11px;
  pointer-events: none;
  z-index: 2;
}

#board h3 {
  margin: 0 0 4px;
  font-size: 10px;
  letter-spacing: 0.08em;
  color: #aaa;
  font-weight: 400;
}

#board .row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  line-height: 1.5;
  color: #cfcfcf;
}

#board .row span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#board .row.me { color: #fff; font-weight: 700; }

button:disabled { opacity: 0.5; cursor: default; }


#title .invite {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: 2px dashed #e8e8e8;
  background: rgba(10, 10, 10, 0.6);
}

#title .invite span { color: #aaa; font-size: 11px; letter-spacing: 0.12em; }
#title .invite strong { font-size: 34px; letter-spacing: 0.3em; padding-left: 0.3em; }
#title .invite button { font: inherit; font-size: 11px; padding: 4px 10px; cursor: pointer; background: #111; color: #f4f4f4; border: 1px solid #e8e8e8; }


#title p:empty, .panel p:empty { display: none; }

/* game over, leaderboard and help share one panel look */
.panel { overflow-y: auto; }
.panel h2 { font-size: clamp(24px, 5vw, 40px); }
.panel ul { max-width: 30rem; }
.panel ul li + li { margin-top: 6px; }
.panel b { color: #fff; }

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

.panel .row button, #help-ok { min-width: 110px; }
button.ghost { background: transparent; color: #f2f2f2; border: 2px solid #e8e8e8; padding: 10px 16px; }
button.ghost:active { background: #333; }

#overlay-rank, .rankline {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 14px 6px 6px;
  border: 2px solid #e8e8e8;
  background: rgba(10, 10, 10, 0.7);
}

#overlay-rank[hidden] { display: none; }
.medal { position: relative; width: 64px; height: 64px; flex: none; }
.medal img { position: absolute; inset: 0; width: 100%; height: 100%; }
.medal img[hidden] { display: none; }
.rank-copy { display: grid; gap: 2px; text-align: left; }
.rank-copy b { font-size: 18px; letter-spacing: 0.05em; }
.rank-copy em { font-style: normal; color: #cfcfcf; font-size: 13px; }

#overlay-goal { font-size: 12px; color: #9a9a9a !important; }

#lb ol {
  list-style: none;
  margin: 0;
  padding: 0;
  width: min(100%, 26rem);
  max-height: 46vh;
  overflow-y: auto;
  border: 2px solid #e8e8e8;
  background: rgba(10, 10, 10, 0.7);
}

#lb ol:empty { display: none; }

#lb li {
  display: grid;
  grid-template-columns: 2.2em 28px 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 3px 10px;
  text-align: left;
  font-size: 13px;
  color: #cfcfcf;
}

#lb li + li { border-top: 1px solid #2a2a2a; }
#lb li.me { color: #fff; font-weight: 700; background: #262626; }
#lb li .pos { color: #8a8a8a; }
#lb li img { width: 26px; height: 26px; }
#lb li span:nth-child(3) { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

#lb-name { display: grid; gap: 6px; width: min(100%, 26rem); }
#lb-name p { margin: 0; }
#lb-name .field { display: flex; gap: 6px; }
#lb-name input {
  flex: 1;
  min-width: 0;
  font: inherit;
  padding: 10px 12px;
  background: #111;
  color: #fff;
  border: 2px solid #e8e8e8;
}
#lb-error { color: #e0a0a0; min-height: 1em; }

#lb .mini { position: relative; width: 26px; height: 26px; }

#lb, #stats, #help { background: rgba(8, 8, 8, 0.97); }
#help { z-index: 6; }

.panel { align-content: safe center; }

.statgrid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
  width: min(100%, 28rem);
}
.statgrid div {
  display: grid;
  gap: 2px;
  padding: 8px 4px;
  border: 2px solid #e8e8e8;
  background: rgba(10, 10, 10, 0.7);
}
.statgrid b { font-size: 20px; }
.statgrid span { font-size: 10px; letter-spacing: 0.08em; color: #aaa; }
@media (max-width: 480px) {
  .statgrid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
.tag i { display: none; }

#lb .mini img { position: absolute; inset: 0; width: 100%; height: 100%; }

.tag u { display: none; }

#title { background: #050505; }

.podium-row {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 10px;
  min-height: 200px;
}

.podium-slot {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 108px;
  gap: 4px;
}

.podium-slot .podium-name {
  max-width: 100%;
  overflow: hidden;
  font-size: 13px;
  letter-spacing: 0.04em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.podium-slot em {
  min-height: 1em;
  color: #bbb;
  font-size: 11px;
  font-style: normal;
}

.podium-slot i {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  width: 100%;
  border: 2px solid #e8e8e8;
  border-bottom: 0;
}

.podium-slot i b { margin-top: 8px; font-size: 22px; }
.podium-slot.second i { height: 78px; background: #bdbdbd; color: #111; }
.podium-slot.first i { height: 116px; background: #f4f4f4; color: #111; }
.podium-slot.third i { height: 52px; background: #6e6e6e; color: #fff; }

#podium { background: rgba(5, 5, 5, 0.97); }
