:root {
  --bg: #050505;
  --bg-elev: #0e0e10;
  --bg-panel: rgba(18, 18, 20, 0.88);
  --red: #9b1b2a;
  --red-hot: #c42338;
  --red-dim: rgba(155, 27, 42, 0.35);
  --pink: #e84393;
  --violet: #9b4dca;
  --gold: #e8a54b;
  --text: #f4f0f1;
  --muted: #9a9094;
  --line: rgba(255, 255, 255, 0.08);
  --soft: #3d8f7a;
  --radius: 18px;
  --font: "Outfit", system-ui, sans-serif;
  --display: "Syne", "Outfit", sans-serif;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.45;
}

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }
img { max-width: 100%; display: block; }

.bg-glow {
  position: fixed;
  inset: -20%;
  background:
    radial-gradient(ellipse 50% 40% at 50% -10%, rgba(155, 27, 42, 0.45), transparent 60%),
    radial-gradient(ellipse 40% 35% at 85% 70%, rgba(155, 27, 42, 0.12), transparent 55%),
    radial-gradient(ellipse 35% 30% at 10% 80%, rgba(80, 20, 30, 0.2), transparent 50%);
  pointer-events: none;
  z-index: 0;
  animation: glow-drift 14s ease-in-out infinite alternate;
}

.bg-noise {
  position: fixed;
  inset: 0;
  opacity: 0.04;
  pointer-events: none;
  z-index: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

@keyframes glow-drift {
  from { transform: translateY(0) scale(1); }
  to { transform: translateY(2%) scale(1.04); }
}

.view {
  display: none;
  position: relative;
  z-index: 1;
  width: min(960px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 1.5rem 0 3rem;
  animation: fade-up 0.45s ease both;
}

.view-game-wide { width: min(1280px, calc(100% - 1.5rem)); }
.view-active { display: block; }

@keyframes fade-up {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ─── BRAND ─── */
.brand-hero { text-align: center; padding: 1.5rem 0 1rem; }

.logo-hero {
  width: min(220px, 55vw);
  margin: 0 auto 0.75rem;
  filter: drop-shadow(0 12px 40px rgba(155, 27, 42, 0.45));
  animation: logo-in 0.8s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

@keyframes logo-in {
  from { opacity: 0; transform: scale(0.92) translateY(10px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.tagline {
  margin: 0;
  font-family: var(--display);
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-size: 0.78rem;
  color: var(--muted);
}

.age-note {
  text-align: center;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 1.25rem;
  border-style: dashed;
}

/* ─── PANELS & FORMS ─── */
.panel {
  background: var(--bg-panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.25rem 1.35rem;
  backdrop-filter: blur(12px);
  box-shadow: var(--shadow);
}

.stack { display: flex; flex-direction: column; gap: 0.85rem; }

.stack h2, .panel h3 {
  margin: 0;
  font-family: var(--display);
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: -0.02em;
}

label {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  font-size: 0.82rem;
  color: var(--muted);
}

input, select {
  background: #0a0a0c;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.75rem 0.9rem;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

input:focus, select:focus {
  border-color: var(--red);
  box-shadow: 0 0 0 3px var(--red-dim);
}

.code-input {
  letter-spacing: 0.2em;
  text-transform: uppercase;
  font-weight: 600;
}

.check-row {
  flex-direction: row !important;
  align-items: flex-start;
  gap: 0.65rem !important;
}

.check-row input { width: auto; margin-top: 0.15rem; }
.check-hint { display: block; font-size: 0.75rem; color: #6a6064; margin-top: 0.15rem; }

.home-grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}

.hint { font-size: 0.8rem; color: var(--muted); margin: 0.25rem 0 0; }
.muted { color: var(--muted); font-weight: 400; }

/* ─── BUTTONS ─── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  border-radius: 999px;
  padding: 0.85rem 1.25rem;
  font-weight: 600;
  transition: transform 0.15s ease, background 0.2s, box-shadow 0.2s;
}

.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(1px); }

.btn-primary {
  background: linear-gradient(135deg, var(--red-hot), var(--red));
  color: #fff;
  box-shadow: 0 10px 30px rgba(155, 27, 42, 0.4);
}

.btn-ghost {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
}

.btn-tiny {
  padding: 0.4rem 0.75rem;
  font-size: 0.78rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.05);
}

/* ─── AVATARS ─── */
.avatar-picker { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.25rem; }

.avatar-opt {
  width: 2.4rem;
  height: 2.4rem;
  border-radius: 12px;
  font-size: 1.2rem;
  border: 2px solid transparent;
  background: rgba(0, 0, 0, 0.35);
  transition: border-color 0.2s, box-shadow 0.2s, transform 0.15s;
}

.avatar-opt:hover { transform: scale(1.08); }
.avatar-opt.selected {
  border-color: var(--red-hot);
  box-shadow: 0 0 16px rgba(196, 35, 56, 0.45);
}

/* ─── TOPBAR & LOBBY ─── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.logo-sm {
  width: 56px;
  height: auto;
  filter: drop-shadow(0 4px 12px rgba(155, 27, 42, 0.35));
}

.topbar-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  justify-content: flex-end;
}

.room-pill {
  font-size: 0.85rem;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--line);
  padding: 0.4rem 0.75rem;
  border-radius: 999px;
}

.room-pill strong {
  color: var(--text);
  letter-spacing: 0.14em;
  cursor: pointer;
}

.lobby-layout {
  display: grid;
  gap: 1rem;
  grid-template-columns: 1.1fr 0.9fr;
}

.lobby-footer {
  margin-top: 1rem;
  display: flex;
  justify-content: center;
}

.room-intensity-badge {
  margin-top: 0.5rem;
  padding: 0.65rem 0.85rem;
  border-radius: 12px;
  background: rgba(155, 27, 42, 0.12);
  border: 1px solid rgba(155, 27, 42, 0.3);
  font-size: 0.85rem;
}

@media (max-width: 720px) {
  .lobby-layout { grid-template-columns: 1fr; }
}

/* ─── PLAYER LIST ─── */
.player-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.player-list li {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.7rem 0.8rem;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid rgba(255, 255, 255, 0.07);
}

.player-list li.ready {
  border-color: rgba(61, 143, 122, 0.45);
  box-shadow: inset 3px 0 0 var(--soft);
}

.player-list li.is-me {
  border-color: rgba(155, 27, 42, 0.45);
  background: rgba(155, 27, 42, 0.1);
}

.player-avatar { font-size: 1.6rem; line-height: 1; }

.player-list .name {
  font-weight: 600;
  font-size: 0.92rem;
  flex: 1;
}

.tag {
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 0.18rem 0.42rem;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--muted);
}

.tag-host {
  border-color: rgba(155, 27, 42, 0.55);
  color: #ffb4bc;
  background: rgba(155, 27, 42, 0.15);
}

.tag-ready {
  border-color: rgba(61, 143, 122, 0.55);
  color: #9be7d0;
  background: rgba(61, 143, 122, 0.15);
}

.tag-intensity {
  border-color: rgba(232, 67, 147, 0.45);
  color: #ffb4d9;
  background: rgba(232, 67, 147, 0.12);
}

/* ─── GAME LAYOUT ─── */
.game-layout {
  display: grid;
  grid-template-columns: minmax(240px, 280px) 1fr;
  gap: 1.25rem;
  align-items: start;
}

@media (max-width: 900px) {
  .game-layout { grid-template-columns: 1fr; }
}

.game-sidebar { position: sticky; top: 1rem; }

.progress-bar-wrap label { font-size: 0.78rem; color: var(--muted); }

.progress-bar {
  height: 6px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 99px;
  overflow: hidden;
  margin: 0.35rem 0;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--violet), var(--pink), var(--red-hot));
  border-radius: 99px;
  transition: width 0.5s ease;
  width: 0%;
  box-shadow: 0 0 12px rgba(232, 67, 147, 0.5);
}

.players-hud { display: flex; flex-direction: column; gap: 0.45rem; margin-top: 0.75rem; }

.hud-player {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 0.5rem;
  align-items: center;
  padding: 0.55rem 0.65rem;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--line);
  font-size: 0.85rem;
}

.hud-player.current {
  border-color: rgba(232, 67, 147, 0.5);
  background: rgba(232, 67, 147, 0.08);
  box-shadow: 0 0 20px rgba(232, 67, 147, 0.15);
}

.hud-money { color: var(--gold); font-weight: 700; font-size: 0.82rem; }

.current-turn {
  margin-top: 0.75rem;
  padding: 0.65rem;
  border-radius: 12px;
  background: rgba(155, 27, 42, 0.12);
  border: 1px solid rgba(155, 27, 42, 0.25);
  font-size: 0.9rem;
  text-align: center;
}

.game-actions { display: flex; flex-direction: column; gap: 0.5rem; margin-top: 1rem; }

/* ─── 3D BOARD ─── */
.board-scene {
  perspective: 1400px;
  perspective-origin: 50% 40%;
  padding: 1rem 0 2rem;
}

.board-stage {
  transform-style: preserve-3d;
  transform: rotateX(12deg);
  transition: transform 0.6s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.board-stage:hover { transform: rotateX(8deg) scale(1.01); }

.board {
  display: grid;
  grid-template-columns: repeat(11, 1fr);
  grid-template-rows: repeat(11, 1fr);
  gap: 3px;
  aspect-ratio: 1;
  max-width: min(92vw, 780px);
  margin: 0 auto;
  padding: 6px;
  border-radius: 14px;
  background: linear-gradient(145deg, #1a1214 0%, #0a0809 50%, #141018 100%);
  border: 2px solid rgba(155, 27, 42, 0.35);
  box-shadow:
    0 40px 80px rgba(0, 0, 0, 0.7),
    0 0 0 1px rgba(255, 255, 255, 0.04) inset,
    0 -20px 40px rgba(155, 27, 42, 0.15) inset;
  transform-style: preserve-3d;
}

.board-center {
  grid-column: 2 / 11;
  grid-row: 2 / 11;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 0.5rem;
  border-radius: 10px;
  background:
    radial-gradient(ellipse 80% 70% at 50% 40%, rgba(155, 27, 42, 0.25), transparent 65%),
    linear-gradient(160deg, #120c0e 0%, #080608 100%);
  border: 1px solid rgba(155, 27, 42, 0.2);
  box-shadow:
    inset 0 8px 32px rgba(0, 0, 0, 0.6),
    inset 0 -4px 16px rgba(155, 27, 42, 0.1);
  text-align: center;
  padding: 1rem;
  transform: translateZ(8px);
}

.board-center .logo-board {
  width: min(120px, 40%);
  filter: drop-shadow(0 8px 24px rgba(155, 27, 42, 0.5));
}

.board-center .board-title {
  font-family: var(--display);
  font-size: 0.7rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0;
}

.board-center .board-code {
  font-family: var(--display);
  font-size: 1rem;
  letter-spacing: 0.25em;
  color: var(--pink);
  margin: 0;
}

/* Tiles */
.tile {
  position: relative;
  border-radius: 6px;
  background: linear-gradient(165deg, #1e1a1c 0%, #121012 45%, #0c0a0b 100%);
  border: 1px solid rgba(255, 255, 255, 0.06);
  font-size: 0.5rem;
  padding: 3px 2px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  text-align: center;
  overflow: hidden;
  min-height: 48px;
  transform-style: preserve-3d;
  transform: translateZ(2px);
  box-shadow:
    0 4px 8px rgba(0, 0, 0, 0.5),
    0 1px 0 rgba(255, 255, 255, 0.06) inset,
    0 -2px 4px rgba(0, 0, 0, 0.4) inset;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.tile:hover {
  transform: translateZ(6px) scale(1.03);
  z-index: 5;
  box-shadow:
    0 8px 20px rgba(0, 0, 0, 0.6),
    0 0 16px rgba(155, 27, 42, 0.2);
}

.tile-corner {
  min-height: 58px;
  background: linear-gradient(165deg, #2a181c 0%, #141012 100%);
}

.tile-special {
  background: linear-gradient(165deg, #221418 0%, #100c0e 100%);
}

.tile.active {
  outline: 2px solid var(--pink);
  outline-offset: 1px;
  z-index: 6;
  box-shadow:
    0 0 24px rgba(232, 67, 147, 0.45),
    0 6px 16px rgba(0, 0, 0, 0.5);
}

.tile.has-owner::after {
  content: "";
  position: absolute;
  inset: 2px;
  border-radius: 4px;
  border: 1px solid rgba(232, 165, 75, 0.35);
  pointer-events: none;
}

.tile-color {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 10px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
}

.tile-emoji {
  font-size: 0.95rem;
  line-height: 1;
  margin-bottom: 1px;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.6));
}

.tile-name {
  font-size: 0.48rem;
  line-height: 1.1;
  color: var(--muted);
  word-break: break-word;
  max-width: 100%;
  padding: 0 1px 2px;
}

.tile-tokens {
  position: absolute;
  top: 28%;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 1px;
  z-index: 4;
}

.tile-token {
  font-size: 0.75rem;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.9));
  animation: token-bob 2s ease-in-out infinite;
}

.tile-token:nth-child(2) { animation-delay: 0.3s; }
.tile-token:nth-child(3) { animation-delay: 0.6s; }

@keyframes token-bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-2px); }
}

/* ─── 3D DICE ─── */
.dice-display {
  display: flex;
  gap: 1.25rem;
  justify-content: center;
  margin-top: 1.5rem;
  transform: translateZ(20px);
}

.die-3d {
  width: 3.5rem;
  height: 3.5rem;
  position: relative;
  transform-style: preserve-3d;
  animation: die-roll 0.6s cubic-bezier(0.2, 0.8, 0.2, 1);
}

@keyframes die-roll {
  0% { transform: rotateX(0) rotateY(0) scale(0.8); opacity: 0; }
  60% { transform: rotateX(360deg) rotateY(180deg) scale(1.1); }
  100% { transform: rotateX(720deg) rotateY(360deg) scale(1); opacity: 1; }
}

.die-face {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  background: linear-gradient(145deg, #fff 0%, #e8e4e6 50%, #d0c8cc 100%);
  color: #1a0a0e;
  border-radius: 12px;
  font-size: 1.6rem;
  font-weight: 800;
  box-shadow:
    0 12px 28px rgba(0, 0, 0, 0.55),
    0 2px 0 #fff inset,
    0 -3px 6px rgba(0, 0, 0, 0.15) inset;
}

/* ─── MODALS ─── */
.card-modal {
  border: none;
  padding: 0;
  background: transparent;
  max-width: min(480px, 92vw);
}

.card-modal::backdrop {
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(6px);
}

.card-modal-inner { margin: 0; animation: pop 0.3s ease; }

@keyframes pop {
  from { opacity: 0; transform: scale(0.95) translateY(10px); }
  to { opacity: 1; transform: none; }
}

.card-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.82rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.card-desc { font-size: 1.05rem; line-height: 1.55; }

.card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 0.75rem 0;
}

.card-meta span {
  padding: 0.25rem 0.6rem;
  border-radius: 99px;
  background: rgba(155, 27, 42, 0.2);
  font-size: 0.8rem;
}

.card-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 1rem; }

/* ─── TOASTS ─── */
.toasts {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.toast {
  padding: 0.75rem 1rem;
  border-radius: 12px;
  background: var(--bg-panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  animation: fade-up 0.3s ease;
  font-size: 0.9rem;
}
