:root {
  --night: #070d24;
  --night2: #10204a;
  --panel: rgba(20, 36, 82, 0.62);
  --panel-edge: rgba(150, 190, 255, 0.22);
  --text: #f1f5ff;
  --muted: #a6b8de;
  --red: #ff4d5e;
  --red-dark: #b8213a;
  --green: #2ed47a;
  --gold: #ffcc4d;
  --ice: #8fe3ff;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font: 16px/1.45 Fredoka, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background:
    radial-gradient(900px 500px at 15% -5%, rgba(255, 77, 94, 0.18), transparent 60%),
    radial-gradient(1000px 600px at 85% -10%, rgba(46, 212, 122, 0.16), transparent 60%),
    radial-gradient(1200px 700px at 50% 120%, rgba(143, 227, 255, 0.16), transparent 60%),
    linear-gradient(var(--night), var(--night2));
  background-attachment: fixed;
  overflow-x: hidden;
}

#bgsnow { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 0; }

.hud, main { position: relative; z-index: 1; }

.hud {
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
  padding: 14px 22px 10px;
}

.logo {
  display: flex;
  flex-direction: column;
  line-height: 0.85;
  font-family: "Mountains of Christmas", Fredoka, cursive;
  font-weight: 700;
  filter: drop-shadow(0 3px 0 rgba(0, 0, 0, 0.35)) drop-shadow(0 0 18px rgba(255, 77, 94, 0.35));
}
.logo-org { font-family: Fredoka, sans-serif; font-size: 11px; font-weight: 600; letter-spacing: 3px; text-transform: uppercase; color: #cfe3ff; margin-bottom: 4px; }
.logo-a { font-size: 22px; color: var(--gold); letter-spacing: 1px; }
.logo-b {
  font-size: 38px;
  background: linear-gradient(180deg, #ffffff 0%, #ffffff 45%, #ffd0d6 55%, #ff4d5e 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.logo.small { align-items: center; margin-bottom: 4px; }

.chips { display: flex; gap: 10px; flex-wrap: wrap; }
.chip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 14px 7px 9px;
  border-radius: 16px;
  background: linear-gradient(180deg, rgba(60, 90, 170, 0.55), rgba(25, 45, 100, 0.7));
  border: 1px solid var(--panel-edge);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.15), 0 6px 18px rgba(0, 0, 0, 0.3);
  min-width: 120px;
}
.chip .ico {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 11px;
  background: rgba(255, 255, 255, 0.1);
  font-size: 19px;
}
.chip b { display: block; font-size: 18px; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.chip small { display: block; font-size: 12px; color: var(--muted); line-height: 1.1; }
.chip.gold b { color: var(--gold); text-shadow: 0 0 12px rgba(255, 204, 77, 0.45); }
.chip.ice b { color: var(--ice); }
.chip.bump { animation: bump 0.6s ease; }
@keyframes bump {
  0% { transform: scale(1); }
  30% { transform: scale(1.14); box-shadow: 0 0 28px rgba(255, 204, 77, 0.7); }
  100% { transform: scale(1); }
}

.me {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 14px 4px 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--panel-edge);
  font-weight: 600;
}
.me img { width: 40px; height: 40px; border-radius: 50%; background: radial-gradient(circle at 50% 35%, #3b5aa8, #1a2c5e); }
.me img:not([src]) { visibility: hidden; }

main {
  display: grid;
  grid-template-columns: minmax(300px, 520px) minmax(320px, 1fr) 320px;
  gap: 18px;
  padding: 4px 22px 22px;
  align-items: start;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  border-radius: 20px;
  padding: 14px;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12), 0 18px 40px rgba(0, 0, 0, 0.35);
}

h3 {
  margin: 2px 4px 10px;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.6px;
  color: var(--gold);
}

#stage { padding: 10px; }
#viewport {
  position: relative;
  height: max(440px, calc(100vh - 150px));
  overflow: hidden;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: #081028;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.06), inset 0 0 40px rgba(0, 0, 0, 0.6);
}
#game { display: block; border-radius: 10px; }

#speech {
  position: absolute;
  left: 0;
  top: 0;
  max-width: 250px;
  padding: 9px 13px;
  border-radius: 16px;
  background: #ffffff;
  color: #1a2147;
  font-weight: 500;
  font-size: 15px;
  line-height: 1.3;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.35), 0 0 0 3px rgba(46, 212, 122, 0.9);
  pointer-events: none;
  transform-origin: var(--tail, 50%) 100%;
  animation: speech-in 0.28s cubic-bezier(0.2, 1.6, 0.4, 1);
  z-index: 3;
}
#speech::after {
  content: "";
  position: absolute;
  left: var(--tail, 50%);
  bottom: -9px;
  width: 16px;
  height: 16px;
  margin-left: -8px;
  background: #ffffff;
  transform: rotate(45deg);
  box-shadow: 3px 3px 0 0 rgba(46, 212, 122, 0.9);
  border-radius: 0 0 4px 0;
}
#speech.thinking #speechtext::after {
  content: "";
  display: inline-block;
  width: 1.2em;
  text-align: left;
  animation: dots 1s steps(4) infinite;
}
@keyframes dots {
  0% { content: ""; }
  25% { content: "."; }
  50% { content: ".."; }
  75% { content: "..."; }
}
@keyframes speech-in {
  from { transform: scale(0.3); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

#banner {
  position: absolute;
  left: 50%;
  top: 38%;
  transform: translate(-50%, -50%);
  padding: 10px 28px;
  border-radius: 18px;
  font-family: "Mountains of Christmas", Fredoka, cursive;
  font-size: 46px;
  font-weight: 700;
  white-space: nowrap;
  color: #fff;
  text-shadow: 0 4px 0 rgba(0, 0, 0, 0.35), 0 0 24px rgba(255, 204, 77, 0.8);
  pointer-events: none;
  z-index: 4;
}
#banner small { display: block; text-align: center; font-family: Fredoka, sans-serif; font-size: 20px; color: var(--gold); }
#banner.play { animation: banner 1.8s cubic-bezier(0.2, 1.4, 0.4, 1) forwards; }
#banner.bad { text-shadow: 0 4px 0 rgba(0, 0, 0, 0.35), 0 0 24px rgba(255, 77, 94, 0.9); }
@keyframes banner {
  0% { transform: translate(-50%, -50%) scale(0.2) rotate(-8deg); opacity: 0; }
  18% { transform: translate(-50%, -50%) scale(1.15) rotate(2deg); opacity: 1; }
  28% { transform: translate(-50%, -50%) scale(1) rotate(0); }
  80% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
  100% { transform: translate(-50%, -80%) scale(0.9); opacity: 0; }
}

#overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  text-align: center;
  padding: 24px;
  font-size: 20px;
  background: rgba(6, 12, 32, 0.8);
  z-index: 5;
}
#overlay .big { font-size: 64px; margin-bottom: 8px; }

#talk { display: flex; flex-direction: column; gap: 10px; }

#log {
  height: max(220px, calc(100vh - 470px));
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 2px 4px 2px 2px;
  scrollbar-width: thin;
}
.entry {
  padding: 9px 12px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.08);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  animation: entry-in 0.25s ease;
}
.entry.pending { opacity: 0.6; }
.entry .res { display: flex; gap: 8px; align-items: center; margin-top: 5px; font-size: 13px; color: var(--muted); }
.entry.empty { background: none; border: 1px dashed rgba(255, 255, 255, 0.15); color: var(--muted); }
@keyframes entry-in {
  from { transform: translateY(6px); opacity: 0; }
}
.badge { display: inline-block; padding: 1px 9px; border-radius: 999px; font-weight: 700; font-size: 12px; letter-spacing: 0.3px; }
.badge.cleared { background: var(--green); color: #05301a; }
.badge.dead { background: var(--red); color: white; }
.badge.stuck { background: #5a6a9a; color: white; }
.badge.chat { background: rgba(255, 255, 255, 0.12); color: var(--muted); }

#ask textarea {
  width: 100%;
  resize: vertical;
  min-height: 70px;
  padding: 12px 14px;
  border-radius: 14px;
  border: 2px solid rgba(143, 227, 255, 0.25);
  background: rgba(6, 14, 40, 0.75);
  color: var(--text);
  font: inherit;
  transition: border-color 0.2s, box-shadow 0.2s;
}
#ask textarea:focus { outline: none; border-color: var(--gold); box-shadow: 0 0 0 4px rgba(255, 204, 77, 0.18); }
.row { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; gap: 8px; }
.hint { color: var(--muted); font-size: 12px; }

button {
  position: relative;
  border: 0;
  border-radius: 14px;
  padding: 11px 22px;
  background: linear-gradient(180deg, #ff6b78, var(--red));
  color: white;
  font: inherit;
  font-weight: 700;
  font-size: 17px;
  letter-spacing: 0.4px;
  cursor: pointer;
  box-shadow: 0 5px 0 var(--red-dark), 0 10px 20px rgba(255, 77, 94, 0.35);
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.25);
  transition: transform 0.08s, box-shadow 0.08s, filter 0.15s;
}
button:hover { filter: brightness(1.08); }
button:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--red-dark), 0 4px 10px rgba(255, 77, 94, 0.3); }
button:disabled { filter: grayscale(0.6) brightness(0.8); cursor: wait; transform: none; }

.tip { margin: 0 4px; font-size: 13px; color: var(--muted); }

#mountain { flex-shrink: 0; display: block; width: 100%; height: 420px; border-radius: 14px; }

#side { display: flex; flex-direction: column; max-height: max(560px, calc(100vh - 130px)); }
#board { list-style: none; margin: 0; padding: 0 4px 0 0; counter-reset: rank; flex: 1; min-height: 120px; overflow-y: auto; scrollbar-width: thin; scrollbar-color: rgba(143, 227, 255, 0.3) transparent; }
#board li {
  counter-increment: rank;
  display: grid;
  grid-template-columns: 30px 36px 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  border-radius: 12px;
}
#board li:nth-child(odd) { background: rgba(255, 255, 255, 0.04); }
#board li::before {
  content: counter(rank);
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  font-weight: 700;
  font-size: 13px;
  background: rgba(255, 255, 255, 0.1);
}
#board li:nth-child(1)::before { background: linear-gradient(#ffe27a, #e0a422); color: #4a3200; }
#board li:nth-child(2)::before { background: linear-gradient(#f2f5fb, #aab4c8); color: #2b3245; }
#board li:nth-child(3)::before { background: linear-gradient(#f0b07a, #b86b33); color: #3d1e06; }
#board li.mine { background: rgba(255, 204, 77, 0.14); box-shadow: inset 0 0 0 1px rgba(255, 204, 77, 0.4); }
#board img { width: 36px; height: 36px; }
#board .who { min-width: 0; }
#board .who b { display: block; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#board .who small { color: var(--muted); font-size: 12px; }
#board .pts { font-weight: 700; color: var(--gold); font-variant-numeric: tabular-nums; }

#card {
  position: fixed;
  z-index: 20;
  width: 240px;
  padding: 14px;
  border-radius: 18px;
  background: linear-gradient(160deg, rgba(36, 56, 120, 0.97), rgba(14, 24, 60, 0.97));
  border: 1px solid rgba(143, 227, 255, 0.3);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.15);
  pointer-events: none;
  animation: card-in 0.15s ease-out;
}
@keyframes card-in { from { opacity: 0; transform: translateY(6px) scale(0.96); } }
#card .top { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
#card .top img { width: 72px; height: 72px; border-radius: 50%; background: radial-gradient(circle at 50% 35%, #3b5aa8, #1a2c5e); box-shadow: 0 0 0 3px rgba(255, 204, 77, 0.35); }
#card .top b { display: block; font-size: 18px; line-height: 1.1; overflow-wrap: anywhere; }
#card .top span { display: block; color: var(--muted); font-size: 14px; }
#card .rank { display: inline-block; margin-top: 4px; padding: 1px 8px; border-radius: 999px; background: rgba(255, 204, 77, 0.18); color: var(--gold); font-size: 12px; font-weight: 700; }
#card dl { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin: 0; }
#card dl div { padding: 6px 8px; border-radius: 10px; background: rgba(255, 255, 255, 0.06); }
#card dt { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; }
#card dd { margin: 0; font-weight: 700; font-variant-numeric: tabular-nums; }
#card dd.gold { color: var(--gold); }
#board li { cursor: default; }
#mountain.pointing { cursor: pointer; }

#join {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(4, 8, 24, 0.75);
  backdrop-filter: blur(6px);
  padding: 16px;
  z-index: 10;
}
#rules { margin: 0 4px; }
#rules summary { cursor: pointer; font-size: 13px; color: var(--gold); font-weight: 600; list-style-position: inside; }
#rules .tip { margin: 8px 0 0; }
#welcome { position: fixed; inset: 0; display: grid; place-items: center; background: rgba(4, 8, 24, 0.75); backdrop-filter: blur(6px); padding: 16px; z-index: 11; }
#welcome .panel { width: min(460px, 100%); display: grid; gap: 12px; padding: 26px; }
#welcome h2 { margin: 0; text-align: center; color: var(--gold); }
#welcome .tip { margin: 0; font-size: 14px; color: var(--text); }
#welcomerules { display: grid; gap: 10px; }
#welcomego { justify-self: center; }
#joinform { position: relative; width: min(400px, 100%); display: grid; gap: 12px; padding: 26px; justify-items: center; text-align: center; }
#joinform p { margin: 0; color: var(--muted); }
#joinelf { width: 160px; height: 160px; border-radius: 50%; background: radial-gradient(circle at 50% 40%, #33529e, #14224c 70%); box-shadow: 0 0 0 4px rgba(255, 204, 77, 0.35), 0 0 40px rgba(143, 227, 255, 0.25); }
#joinform input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 14px;
  border: 2px solid rgba(143, 227, 255, 0.25);
  background: rgba(6, 14, 40, 0.75);
  color: var(--text);
  font: inherit;
  font-size: 18px;
  text-align: center;
}
#joinform input:focus { outline: none; border-color: var(--gold); }
#joinform > button { width: 100%; }
.tabs { display: flex; gap: 4px; width: 100%; padding: 4px; border-radius: 14px; background: rgba(6, 14, 40, 0.75); }
.tabs button { flex: 1; padding: 8px 10px; border: 0; border-radius: 10px; background: transparent; color: var(--muted); font: inherit; font-weight: 600; box-shadow: none; cursor: pointer; transform: none; }
.tabs button.on { background: rgba(143, 227, 255, 0.16); color: var(--text); }
.me > div { display: grid; line-height: 1.15; }
.me small { color: var(--muted); font-size: 12px; }
#logout { margin-left: 4px; padding: 4px 8px; border: 0; border-radius: 10px; background: rgba(255, 255, 255, 0.08); color: var(--muted); font-size: 14px; box-shadow: none; cursor: pointer; }
#logout:hover { color: var(--text); background: rgba(255, 255, 255, 0.16); }
.err { color: #ffaaa5 !important; min-height: 1.2em; }

[hidden] { display: none !important; }

@media (max-width: 1240px) {
  main { grid-template-columns: minmax(300px, 460px) 1fr; }
  #side { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr 1fr; gap: 0 18px; }
  #side h3:nth-of-type(2) { grid-column: 2; grid-row: 1; }
  #mountain { grid-column: 1; }
  #side { max-height: none; }
  #board { grid-column: 2; grid-row: 2; max-height: 420px; }
}

@media (max-width: 860px) {
  .hud { padding: 12px 16px 8px; }
  .me { margin-left: 0; }
  main { grid-template-columns: minmax(0, 1fr); padding: 0 16px 16px; }
  #side { display: block; }
  #board { max-height: 60vh; }
  #viewport { height: 75vh; }
  .chip { min-width: 0; }
}
#joinform > #joinclose { position: absolute; z-index: 1; top: 10px; right: 10px; left: auto; width: auto; padding: 4px 10px; border-radius: 10px; background: rgba(255, 255, 255, 0.08); color: var(--muted); box-shadow: none; font-size: 16px; }
#joinclose:hover { color: var(--text); background: rgba(255, 255, 255, 0.16); }
#joinform > #joinlogout { width: auto; padding: 4px 10px; background: none; box-shadow: none; color: var(--muted); font-size: 13px; text-decoration: underline; }
#joinlogout:hover { color: var(--text); }
#finale { position: fixed; inset: 0; z-index: 12; overflow-y: auto; display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 28px 16px 40px; background: radial-gradient(ellipse at 50% 0%, #2a3f86 0%, #0b1433 60%, #050a1c 100%); }
#finale h2 { margin: 0; color: var(--gold); font-size: 28px; }
#podium { width: min(820px, 100%); aspect-ratio: 820 / 340; }
#standings { width: min(560px, 100%); margin: 0; padding: 0; list-style: none; display: grid; gap: 6px; }
#standings li { display: grid; grid-template-columns: 40px 40px 1fr auto; align-items: center; gap: 10px; padding: 6px 12px; border-radius: 14px; background: rgba(255, 255, 255, 0.06); }
#standings li.mine { box-shadow: 0 0 0 2px var(--gold); }
#standings .rank { font-weight: 700; color: var(--muted); text-align: center; font-size: 18px; }
#standings img { width: 36px; height: 36px; border-radius: 50%; background: radial-gradient(circle at 50% 35%, #3b5aa8, #1a2c5e); }
#standings small { display: block; color: var(--muted); }
#standings .pts { font-weight: 700; color: var(--gold); font-size: 18px; }
#finale .merry { margin: 8px 0 0; font-size: 20px; color: var(--text); }
#busy { position: fixed; inset: 0; z-index: 11; display: grid; place-items: center; padding: 16px; background: rgba(4, 8, 24, 0.6); backdrop-filter: blur(4px); }
#busy .panel { width: min(400px, 100%); display: grid; gap: 10px; padding: 24px; text-align: center; animation: busy-pop 0.35s cubic-bezier(0.2, 1.4, 0.4, 1); }
#busy h2 { margin: 0; color: var(--gold); }
#busy p { margin: 0; color: var(--muted); }
#busy .row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
#busy .row button { flex: 1; min-width: 140px; }
#busy button.ghost { background: rgba(255, 255, 255, 0.08); box-shadow: none; color: var(--text); }
.busyelves { display: flex; justify-content: center; gap: 6px; }
.busyelves img { width: 56px; height: 56px; animation: busy-hop 0.6s ease-in-out infinite alternate; }
.busyelves img:nth-child(2) { animation-delay: 0.3s; }
@keyframes busy-hop { from { transform: translateY(0); } to { transform: translateY(-8px); } }
@keyframes busy-pop { from { transform: scale(0.85); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.potdchip { cursor: pointer; font: inherit; color: var(--text); min-width: 0; padding: 7px; border-radius: 16px; }
.potdchip:hover { filter: brightness(1.15); }
.potdchip b { color: var(--gold); }
#potd { position: fixed; inset: 0; z-index: 11; display: grid; place-items: center; padding: 16px; background: rgba(4, 8, 24, 0.7); backdrop-filter: blur(5px); }
#potd .panel { position: relative; box-sizing: border-box; width: min(560px, 100%); max-height: calc(100vh - 32px); display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto auto auto minmax(0, 1fr); gap: 10px; padding: 24px; animation: busy-pop 0.35s cubic-bezier(0.2, 1.4, 0.4, 1); }
#potd h2 { margin: 0; color: var(--gold); text-align: center; }
#potd h3 { margin: 0 0 6px; font-size: 14px; color: var(--gold); }
#potdinfo { margin: 0; color: var(--muted); text-align: center; font-size: 14px; }
#potdclose { position: absolute; top: 10px; right: 10px; width: 34px; height: 34px; padding: 0; border-radius: 50%; background: rgba(255, 255, 255, 0.08); box-shadow: none; color: var(--text); }
#potdlast { padding: 10px; border-radius: 14px; background: rgba(255, 204, 77, 0.1); border: 1px solid rgba(255, 204, 77, 0.35); }
#potdlist { margin: 0; padding: 0; list-style: none; overflow-y: auto; display: grid; gap: 6px; align-content: start; }
#potd li { display: grid; grid-template-columns: 36px minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 8px; border-radius: 12px; background: rgba(255, 255, 255, 0.05); }
#potd li img { width: 36px; height: 36px; }
#potd li q { display: block; overflow-wrap: anywhere; }
#potd li small { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; overflow-wrap: anywhere; }
#potd li button { min-width: 64px; padding: 6px 10px; font-size: 14px; background: rgba(255, 255, 255, 0.08); box-shadow: none; color: var(--text); }
#potd li button.voted { background: rgba(255, 77, 94, 0.25); }
#potd li button:disabled { opacity: 0.45; cursor: default; }
#potd .votes { font-size: 14px; }
#potdown { display: flex; gap: 8px; }
#potdown select { flex: 1; min-width: 0; padding: 8px; border-radius: 10px; background: rgba(255, 255, 255, 0.08); color: var(--text); border: 1px solid var(--panel-edge); font: inherit; font-size: 14px; }
#potdown select option { background: #1a2550; }
#potdown button { padding: 8px 14px; font-size: 14px; }
#potd .empty { color: var(--muted); text-align: center; margin: 12px 0; }
#log .snag { display: block; margin-top: 4px; font-size: 12px; color: #ffcc4d; }
#log .flair { margin-left: 6px; font-size: 12px; }
