:root {
  color-scheme: dark;
  --accent: #f8b500;
  --accent-strong: #1ad5ff;
  --panel: rgba(5, 8, 20, 0.65);
  --border: rgba(255, 255, 255, 0.15);
  --text: #f6f6fa;
  --chip: #f8b500;
  font-family: 'Space Grotesk', 'Inter', system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at top, #141c3a, #070913 55%);
  color: var(--text);
  overflow: hidden;
}

[hidden] {
  display: none !important;
}

body::before,
body::after {
  content: '';
  position: fixed;
  width: 40vmin;
  height: 40vmin;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(26, 213, 255, 0.18), rgba(26, 213, 255, 0));
  filter: blur(8px);
  z-index: 0;
  pointer-events: none;
}

body::before {
  top: -10vmin;
  right: -5vmin;
}

body::after {
  bottom: -12vmin;
  left: -8vmin;
  background: radial-gradient(circle, rgba(248, 181, 0, 0.18), rgba(248, 181, 0, 0));
}

canvas {
  position: fixed;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.watermark {
  position: fixed;
  left: 0.9rem;
  bottom: 0.6rem;
  z-index: 5;
  font-size: 0.8rem;
  letter-spacing: 0.04em;
  color: rgba(255, 255, 255, 0.6);
  pointer-events: none;
}

#hud {
  position: absolute;
  left: 50%;
  top: 1.5rem;
  transform: translateX(-50%);
  width: min(92vw, 640px);
  padding: 1rem 1.25rem 1.25rem;
  border-radius: 1.25rem;
  background: var(--panel);
  border: 1px solid var(--border);
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(16px);
  z-index: 3;
  animation: riseIn 600ms ease-out;
}

.hud-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 0.75rem;
}

.hud-header h1 {
  margin: 0;
  font-size: 1.3rem;
  letter-spacing: 0.04em;
}

.subhead {
  margin: 0.2rem 0 0;
  font-size: 0.8rem;
  color: rgba(255, 255, 255, 0.7);
}

#status {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 0.5rem;
}

.status-node {
  flex: 1;
  min-width: 180px;
  padding: 0.5rem 0.75rem;
  border-radius: 0.85rem;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  text-transform: uppercase;
  font-size: 0.8rem;
  letter-spacing: 0.08em;
}

.turn-indicator {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.45rem 0.7rem;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(0, 0, 0, 0.35);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.turn-indicator::before {
  content: '';
  width: 0.6rem;
  height: 0.6rem;
  border-radius: 50%;
  background: var(--chip);
  box-shadow: 0 0 12px var(--chip);
}

.scoreboard {
  display: flex;
  gap: 1rem;
  margin: 0.5rem 0;
  font-size: 0.85rem;
}

.score {
  padding: 0.35rem 0.6rem;
  border-radius: 0.6rem;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.game-over {
  position: fixed;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 0.5rem;
  background: rgba(0, 0, 0, 0.55);
  z-index: 6;
  text-align: center;
  font-family: 'Space Grotesk', 'Inter', system-ui, sans-serif;
}

.game-over.is-visible {
  animation: winReveal 700ms ease-out;
}

.game-over-face {
  font-size: 5rem;
  color: #f8e08e;
}

.game-over-text {
  font-size: 2rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: #ffffff;
}

.game-over-card {
  margin: 0.6rem auto 0.2rem;
  padding: 0.7rem 1.2rem;
  border-radius: 1rem;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(8, 12, 22, 0.7);
  min-width: min(70vw, 320px);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.35);
}

.game-over-winner {
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: 0.35rem;
}

.game-over-scores {
  display: flex;
  justify-content: space-between;
  font-size: 0.9rem;
  color: rgba(255, 255, 255, 0.8);
}

.welcome {
  position: fixed;
  inset: 0;
  display: grid;
  place-content: center;
  text-align: center;
  gap: 0.6rem;
  background: radial-gradient(circle at top, rgba(10, 14, 24, 0.85), rgba(2, 4, 10, 0.95));
  z-index: 7;
  opacity: 0;
  pointer-events: none;
}

.welcome.intro-visible {
  animation: introFadeIn 3s ease forwards;
  pointer-events: auto;
}

.welcome.intro-fade-out {
  animation: introFadeOut 1.2s ease forwards;
}

.welcome-title {
  font-family: 'UnifrakturCook', 'Space Grotesk', 'Inter', system-ui, sans-serif;
  font-size: 2.8rem;
  letter-spacing: 0.08em;
}

.welcome-sub {
  font-size: 1.1rem;
  color: rgba(255, 255, 255, 0.7);
}

.welcome-steps {
  list-style: none;
  padding: 0;
  margin: 0.8rem 0 1.1rem;
  display: grid;
  gap: 0.45rem;
  font-size: 0.95rem;
  color: rgba(255, 255, 255, 0.82);
}

.welcome-steps li {
  padding: 0.5rem 0.75rem;
  border-radius: 0.75rem;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.welcome-sub.small-print {
  font-size: 0.85rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.welcome-btn {
  margin-top: 1rem;
  padding: 0.8rem 1.6rem;
  border-radius: 999px;
  border: none;
  background: #1ad5ff;
  color: #04060f;
  font-weight: 600;
  cursor: pointer;
}

.game-over-btn {
  margin-top: 0.75rem;
  padding: 0.7rem 1.4rem;
  border-radius: 999px;
  border: none;
  background: #f8b500;
  color: #05070f;
  font-weight: 600;
  cursor: pointer;
}

#inventory {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(125px, 1fr));
  gap: 0.6rem;
  margin-bottom: 0.5rem;
}

.net-panel {
  margin-top: 0.6rem;
  padding: 0.75rem;
  border-radius: 0.9rem;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(0, 0, 0, 0.28);
  display: grid;
  gap: 0.5rem;
}

.net-panel.is-hidden {
  display: none;
}

.net-header {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: rgba(255, 255, 255, 0.7);
}

.net-row {
  display: grid;
  grid-template-columns: 90px 1fr;
  gap: 0.5rem;
  align-items: center;
}

.net-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: rgba(255, 255, 255, 0.6);
}

.net-panel input {
  border-radius: 0.6rem;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(6, 10, 20, 0.7);
  color: var(--text);
  padding: 0.45rem 0.6rem;
}

.net-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 0.5rem;
}

.net-actions button.secondary {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.net-status-row .secondary {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.net-status-row .secondary:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.net-status {
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.7);
}

.net-status-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.net-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.05);
}

.net-dot {
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 50%;
  background: #64748b;
  box-shadow: 0 0 8px rgba(100, 116, 139, 0.5);
}

.net-pill.is-connecting .net-dot {
  background: #1ad5ff;
  box-shadow: 0 0 10px rgba(26, 213, 255, 0.7);
  animation: pulse 1.2s ease-in-out infinite;
}

.net-pill.is-waiting .net-dot {
  background: #f8b500;
  box-shadow: 0 0 10px rgba(248, 181, 0, 0.7);
  animation: pulse 1.4s ease-in-out infinite;
}

.net-pill.is-connected .net-dot {
  background: #39f37a;
  box-shadow: 0 0 12px rgba(57, 243, 122, 0.7);
}

.net-pill.is-error .net-dot {
  background: #ff6b6b;
  box-shadow: 0 0 12px rgba(255, 107, 107, 0.7);
}

.net-room-summary {
  font-size: 0.7rem;
  color: rgba(255, 255, 255, 0.6);
}

#inventory button,
#reset {
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  padding: 0.65rem 0.9rem;
  font-size: 0.85rem;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.03);
  color: var(--text);
  transition: border-color 0.2s ease, transform 0.2s ease;
}

#inventory button:disabled {
  opacity: 0.25;
  cursor: not-allowed;
}

#inventory button:hover:not(:disabled),
#reset:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}

#hint {
  margin: 0.35rem 0;
  font-size: 0.8rem;
  color: rgba(255, 255, 255, 0.75);
}

#reset {
  margin-top: 0.5rem;
  width: 100%;
  background: linear-gradient(120deg, #1ad5ff, #f8b500);
  border: none;
  color: #030711;
  font-weight: 600;
}

#toggle-hud.secondary {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.hud-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.6rem;
  margin-top: 0.6rem;
}

.hud-collapsible {
  transition: transform 420ms ease, opacity 420ms ease;
}

.hud-collapsed {
  transform: translate(-50%, -130%);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.quick-toolbar {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 4;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: flex-end;
}

.hud-fab {
  padding: 0.6rem 1rem;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(10, 14, 24, 0.85);
  color: var(--text);
  cursor: pointer;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
}

.hud-fab.secondary {
  background: rgba(255, 255, 255, 0.08);
}

.turn-pill {
  position: fixed;
  right: 1rem;
  top: 1rem;
  z-index: 4;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.55rem 0.85rem;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(10px);
  font-size: 0.85rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.9);
}

.turn-pill .dot {
  width: 0.65rem;
  height: 0.65rem;
  border-radius: 50%;
  background: var(--chip);
  box-shadow: 0 0 10px var(--chip);
}

.controls-hint {
  position: fixed;
  left: 1rem;
  bottom: 1rem;
  z-index: 4;
  max-width: 360px;
  padding: 0.85rem 1rem;
  border-radius: 1rem;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(9, 12, 22, 0.75);
  backdrop-filter: blur(12px);
  color: rgba(255, 255, 255, 0.88);
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.32);
}

.controls-hint-title {
  font-size: 0.95rem;
  font-weight: 600;
  margin-bottom: 0.4rem;
}

.controls-hint-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.4rem 0.6rem;
  font-size: 0.85rem;
}

.kbd {
  display: inline-block;
  min-width: 34px;
  padding: 0.1rem 0.35rem;
  margin-right: 0.3rem;
  border-radius: 0.4rem;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.08);
  font-weight: 600;
  letter-spacing: 0.04em;
}

.chip-btn {
  margin-top: 0.55rem;
  padding: 0.45rem 0.9rem;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  cursor: pointer;
  font-size: 0.85rem;
}

.chip-btn:hover {
  border-color: var(--accent);
  background: rgba(255, 255, 255, 0.12);
}

#boot-error {
  position: absolute;
  inset: 1.5rem;
  padding: 1.25rem 1.5rem;
  border-radius: 1rem;
  background: rgba(13, 8, 5, 0.92);
  border: 1px solid rgba(255, 119, 119, 0.5);
  color: #ffd6d6;
  z-index: 5;
  font-size: 0.95rem;
}

.coin-toss {
  position: fixed;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 0.6rem;
  text-align: center;
  background: radial-gradient(circle at top, rgba(10, 14, 24, 0.85), rgba(2, 4, 10, 0.95));
  z-index: 6;
}

.coin-wrap {
  perspective: 900px;
  display: grid;
  place-items: center;
}

.coin {
  width: 110px;
  height: 110px;
  border-radius: 50%;
  position: relative;
  transform-style: preserve-3d;
  background: radial-gradient(circle at 30% 30%, #ffe59a, #c68a1a);
  box-shadow: 0 16px 30px rgba(0, 0, 0, 0.4);
}

.coin.is-flipping {
  animation: coinFlip 1400ms ease-in-out;
}

.coin-face {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 2.4rem;
  font-weight: 700;
  color: rgba(10, 12, 18, 0.8);
  backface-visibility: hidden;
}

.coin-face-back {
  transform: rotateY(180deg);
}

.coin-text {
  font-size: 1.4rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.coin-sub {
  font-size: 0.9rem;
  color: rgba(255, 255, 255, 0.7);
}

@media (max-width: 560px) {
  #hud {
    top: 0.75rem;
    padding: 0.85rem 1rem;
  }
}

@keyframes riseIn {
  from {
    transform: translate(-50%, 8px);
    opacity: 0;
  }
  to {
    transform: translate(-50%, 0);
    opacity: 1;
  }
}

@keyframes introFadeIn {
  0% {
    opacity: 0;
  }
  100% {
    opacity: 1;
  }
}

@keyframes introFadeOut {
  0% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}

@keyframes winReveal {
  0% {
    opacity: 0;
    transform: scale(0.96);
  }
  100% {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes coinFlip {
  0% {
    transform: rotateY(0deg) translateY(0);
  }
  50% {
    transform: rotateY(540deg) translateY(-16px);
  }
  100% {
    transform: rotateY(1080deg) translateY(0);
  }
}

@keyframes pulse {
  0% {
    transform: scale(0.9);
    opacity: 0.6;
  }
  50% {
    transform: scale(1.1);
    opacity: 1;
  }
  100% {
    transform: scale(0.9);
    opacity: 0.7;
  }
}
