:root {
  --bg: #0f1a14;
  --panel: #16241c;
  --panel-2: #1d3025;
  --line: #2e4a39;
  --text: #f4efe3;
  --muted: #a9b8ac;
  --gold: #ffd35a;
  --gold-2: #f0a500;
  --green: #2fbf71;
  --red: #ff5a67;
  --radius: 12px;
  --header-h: 48px;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, Ubuntu, sans-serif;
  -webkit-text-size-adjust: 100%;
}

a {
  color: var(--gold);
}

button,
input {
  font: inherit;
  color: inherit;
}

button {
  touch-action: manipulation;
  cursor: pointer;
}

[hidden] {
  display: none !important;
}

.site-header:empty {
  height: var(--header-h);
}

.page {
  padding: 8px 8px 40px;
}

/* ---------- Game frame ---------- */

.game-root {
  position: relative;
  margin: 0 auto;
  max-width: 980px;
  min-height: 480px;
  background: radial-gradient(120% 80% at 50% 0%, #1b3526 0%, #0c1510 70%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.stage {
  position: relative;
  height: clamp(260px, calc(100dvh - var(--header-h) - 250px), 560px);
  height: clamp(260px, calc(100vh - var(--header-h) - 250px), 560px);
  height: clamp(260px, calc(100dvh - var(--header-h) - 250px), 560px);
}

.stage canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: manipulation;
}

.net-note {
  position: absolute;
  right: 18px;
  bottom: 14px;
  font-size: 12px;
  color: #d9e6dc;
  background: rgba(0, 0, 0, 0.45);
  padding: 3px 9px;
  border-radius: 99px;
  pointer-events: none;
}

.hint {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: 23%;
  font-size: 14px;
  font-weight: 700;
  color: #fff;
  background: rgba(0, 0, 0, 0.55);
  padding: 6px 14px;
  border-radius: 99px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.25s;
  white-space: nowrap;
  max-width: 94%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hint.show {
  opacity: 1;
}

/* Menus and results: the page grows with the panel; the table stays behind it. */
.game-root.menu-mode {
  min-height: clamp(480px, calc(100dvh - var(--header-h) - 16px), 760px);
}

.game-root.menu-mode .stage {
  position: absolute;
  inset: 0;
  height: auto;
}

.game-root.menu-mode .players {
  display: none;
}

.game-root.menu-mode .overlay.show {
  position: relative;
  inset: auto;
  flex: 1;
  overflow: visible;
}

@media (min-width: 820px) {
  .panel.wide {
    max-width: 880px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0 16px;
    align-content: start;
  }

  .panel.wide > .logo,
  .panel.wide > .tagline {
    grid-column: 1 / -1;
  }
}

/* ---------- Players ---------- */

.players {
  display: grid;
  grid-template-columns: repeat(var(--n, 3), minmax(0, 1fr));
  gap: 6px;
  padding: 8px 8px 6px;
  min-height: 64px;
}

.chip {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  min-width: 0;
  transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
}

.chip.active {
  border-color: var(--gold);
  box-shadow: 0 0 0 1px var(--gold), 0 0 18px rgba(255, 211, 90, 0.35);
  transform: translateY(-1px);
}

.chip.me .name::after {
  content: ' (you)';
  color: var(--muted);
  font-weight: 500;
}

.chip.off {
  opacity: 0.55;
}

.avatar {
  flex: none;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 900;
  font-size: 15px;
  color: #10170f;
  position: relative;
}

.avatar svg {
  width: 20px;
  height: 20px;
}

.avatar .ring {
  position: absolute;
  inset: -4px;
  width: auto;
  height: auto;
}

.chip-body {
  min-width: 0;
  flex: 1;
}

.chip .name {
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chip .score {
  font-size: 17px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}

.chip .score small {
  font-size: 11px;
  font-weight: 700;
  color: var(--gold);
  margin-left: 4px;
}

.chip .bar {
  height: 4px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.1);
  overflow: hidden;
  margin-top: 3px;
}

.chip .bar i {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--green), var(--gold));
  border-radius: 3px;
  transition: width 0.6s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.chip .tag {
  font-size: 10px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.bubble {
  position: absolute;
  left: 50%;
  top: 100%;
  transform: translate(-50%, 4px) scale(0.6);
  opacity: 0;
  background: #fff;
  color: #1a1a1a;
  border-radius: 14px;
  padding: 4px 10px 4px 6px;
  display: flex;
  align-items: center;
  gap: 5px;
  font-weight: 800;
  font-size: 13px;
  white-space: nowrap;
  z-index: 5;
  pointer-events: none;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
  transition: transform 0.18s cubic-bezier(0.3, 1.6, 0.5, 1), opacity 0.18s;
}

.bubble::before {
  content: '';
  position: absolute;
  top: -6px;
  left: 50%;
  margin-left: -6px;
  border: 6px solid transparent;
  border-top: 0;
  border-bottom-color: #fff;
}

.bubble.show {
  opacity: 1;
  transform: translate(-50%, 6px) scale(1);
}

.bubble svg {
  width: 22px;
  height: 22px;
}

/* ---------- Controls ---------- */

.controls {
  padding: 6px 10px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.timer {
  height: 5px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 3px;
  overflow: hidden;
}

.timer i {
  display: block;
  height: 100%;
  width: 100%;
  background: var(--gold);
  transform-origin: left;
}

.timer.low i {
  background: var(--red);
}

.sel-info {
  text-align: center;
  font-size: 14px;
  color: var(--muted);
  min-height: 20px;
}

.sel-info b {
  color: var(--gold);
}

.sel-info .bad {
  color: var(--red);
}

.btn-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.btn {
  border: 0;
  border-radius: 12px;
  padding: 12px 14px;
  font-weight: 900;
  font-size: 18px;
  letter-spacing: 0.3px;
  min-height: 54px;
  transition: transform 0.08s, filter 0.2s, opacity 0.2s;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.35);
}

.btn:active:not(:disabled) {
  transform: translateY(3px);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.35);
}

.btn:disabled {
  opacity: 0.35;
  cursor: default;
  filter: grayscale(0.6);
}

.btn small {
  display: block;
  font-size: 12px;
  font-weight: 700;
  opacity: 0.85;
}

.btn-roll {
  background: linear-gradient(180deg, #45d98a, #1c9a55);
  color: #06260f;
}

.btn-roll.risky {
  background: linear-gradient(180deg, #ff9a5a, #e0482a);
  color: #2a0800;
}

.btn-bank {
  background: linear-gradient(180deg, #ffe07a, #e6a100);
  color: #3a2400;
}

.btn-roll:focus-visible,
.btn-bank:focus-visible,
.mbtn:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 2px;
}

.emotes {
  display: flex;
  justify-content: center;
  gap: 6px;
}

.emote {
  width: 40px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel);
  display: grid;
  place-items: center;
  padding: 0;
}

.emote svg {
  width: 24px;
  height: 24px;
}

.emote:disabled {
  opacity: 0.4;
}

.toolbar {
  position: absolute;
  top: 78px;
  right: 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 3;
}

.tbtn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(0, 0, 0, 0.45);
  font-weight: 800;
  font-size: 14px;
  display: grid;
  place-items: center;
  padding: 0;
}

/* ---------- Overlays ---------- */

.overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: none;
  overflow-y: auto;
  background: rgba(6, 14, 9, 0.84);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
}

.overlay.show {
  display: block;
}

.overlay.clear {
  background: rgba(6, 14, 9, 0.35);
}

.panel {
  max-width: 560px;
  margin: 0 auto;
  padding: 18px 16px 24px;
  animation: pop 0.25s ease-out;
}

@keyframes pop {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.98);
  }
}

.logo {
  text-align: center;
  font-weight: 900;
  font-size: clamp(34px, 8vw, 56px);
  letter-spacing: 1px;
  line-height: 1;
  margin: 6px 0 2px;
  color: var(--gold);
  text-shadow: 0 3px 0 #7a4b00, 0 8px 22px rgba(0, 0, 0, 0.6);
}

.logo em {
  font-style: normal;
  color: var(--red);
  text-shadow: 0 3px 0 #6b0714, 0 8px 22px rgba(0, 0, 0, 0.6);
}

.tagline {
  text-align: center;
  color: var(--muted);
  margin: 6px 0 14px;
  font-size: 14px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 10px;
}

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

.lvl {
  flex: none;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff1a8, var(--gold-2));
  color: #3a2400;
  display: grid;
  place-items: center;
  font-weight: 900;
  font-size: 18px;
  box-shadow: 0 0 0 3px rgba(255, 211, 90, 0.25);
}

.me-main {
  flex: 1;
  min-width: 0;
}

.name-input {
  width: 100%;
  background: transparent;
  border: 0;
  border-bottom: 1px dashed var(--line);
  font-weight: 800;
  font-size: 16px;
  padding: 2px 0;
}

.name-input:focus {
  outline: none;
  border-bottom-color: var(--gold);
}

.xpbar {
  height: 10px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
  margin-top: 6px;
}

.xpbar i {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--green), var(--gold));
  border-radius: 6px;
  transition: width 0.8s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.small {
  font-size: 12px;
  color: var(--muted);
}

.badges {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.badge {
  font-size: 12px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 99px;
  background: var(--panel-2);
  border: 1px solid var(--line);
}

.badge.fire {
  color: #ffb36b;
}

.mbtns {
  display: grid;
  gap: 8px;
  margin: 12px 0;
}

.mbtn {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  border: 1px solid var(--line);
  background: var(--panel-2);
  border-radius: 12px;
  padding: 12px 14px;
  min-height: 58px;
}

.mbtn b {
  display: block;
  font-size: 17px;
}

.mbtn span {
  font-size: 13px;
  color: var(--muted);
}

.mbtn .ico {
  flex: none;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-size: 20px;
  background: rgba(255, 255, 255, 0.06);
}

.mbtn.primary {
  background: linear-gradient(180deg, #2fbf71, #178a4b);
  border-color: #45d98a;
  color: #04200e;
}

.mbtn.primary span {
  color: #0b3a1d;
}

.mbtn.primary .ico {
  background: rgba(255, 255, 255, 0.25);
}

.row2 {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}

.sbtn {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 10px;
  padding: 8px 4px;
  font-size: 12px;
  font-weight: 700;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  min-height: 56px;
  position: relative;
}

.sbtn .ico {
  font-size: 18px;
  line-height: 1;
}

.sbtn .dot {
  position: absolute;
  top: 5px;
  right: 8px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--red);
}

.missions {
  display: grid;
  gap: 8px;
}

.mission {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 10px;
  font-size: 13px;
  align-items: center;
}

.mission .xpbar {
  grid-column: 1 / -1;
  height: 6px;
  margin-top: 0;
}

.mission.done {
  color: var(--green);
}

.mission.done .xpbar i {
  background: var(--green);
}

.h2 {
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted);
  margin: 0 0 8px;
  display: flex;
  justify-content: space-between;
}

.panel h2 {
  margin: 4px 0 12px;
  font-size: 22px;
  text-align: center;
}

.back {
  display: block;
  margin: 14px auto 0;
  border: 1px solid var(--line);
  background: var(--panel-2);
  border-radius: 10px;
  padding: 10px 22px;
  font-weight: 800;
}

.opts {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
  margin: 8px 0;
}

.opt {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 10px;
  padding: 8px 14px;
  font-weight: 800;
  min-width: 64px;
}

.opt[aria-pressed='true'] {
  border-color: var(--gold);
  background: rgba(255, 211, 90, 0.14);
  color: var(--gold);
}

.code {
  font-size: 48px;
  font-weight: 900;
  letter-spacing: 10px;
  text-align: center;
  color: var(--gold);
  margin: 4px 0;
  font-variant-numeric: tabular-nums;
}

.join-row {
  display: flex;
  gap: 8px;
}

.join-row input {
  flex: 1;
  min-width: 0;
  text-transform: uppercase;
  letter-spacing: 6px;
  font-weight: 900;
  font-size: 20px;
  text-align: center;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px;
}

.seats {
  display: grid;
  gap: 6px;
  margin: 10px 0;
}

.seat {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  min-height: 48px;
}

.seat.empty {
  border-style: dashed;
  color: var(--muted);
  justify-content: center;
}

.seat .grow {
  flex: 1;
  font-weight: 700;
}

.x {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 18px;
  padding: 4px 8px;
}

.cta {
  display: block;
  width: 100%;
  border: 0;
  border-radius: 12px;
  padding: 14px;
  font-weight: 900;
  font-size: 18px;
  background: linear-gradient(180deg, #45d98a, #1c9a55);
  color: #06260f;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.35);
}

.cta.gold {
  background: linear-gradient(180deg, #ffe07a, #e6a100);
  color: #3a2400;
}

.cta:disabled {
  opacity: 0.4;
}

.cta + .cta,
.cta + .ghost,
.ghost + .cta {
  margin-top: 8px;
}

.ghost {
  display: block;
  width: 100%;
  border: 1px solid var(--line);
  background: var(--panel-2);
  border-radius: 12px;
  padding: 12px;
  font-weight: 800;
}

.spinner {
  width: 46px;
  height: 46px;
  margin: 18px auto;
  border-radius: 10px;
  background: #fffdf6;
  animation: tumble 0.9s infinite cubic-bezier(0.5, 0, 0.5, 1);
  position: relative;
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.4);
}

.spinner::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle, #1d1a17 18%, transparent 20%) 0 0 / 50% 50%;
  margin: 6px;
}

@keyframes tumble {
  50% {
    transform: rotate(180deg) scale(0.85);
  }
  100% {
    transform: rotate(360deg);
  }
}

/* Results */

.winner {
  text-align: center;
  font-size: 34px;
  font-weight: 900;
  margin: 6px 0 2px;
}

.winner.win {
  color: var(--gold);
  text-shadow: 0 3px 0 #7a4b00;
}

.standings {
  display: grid;
  gap: 5px;
  margin: 10px 0;
}

.standing {
  display: grid;
  grid-template-columns: 26px 1fr auto;
  gap: 8px;
  align-items: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 7px 10px;
  font-weight: 700;
}

.standing.me {
  border-color: var(--gold);
}

.standing .pts {
  font-variant-numeric: tabular-nums;
  font-weight: 900;
}

.xp-lines {
  display: grid;
  gap: 3px;
  font-size: 13px;
  margin: 8px 0;
}

.xp-lines div {
  display: flex;
  justify-content: space-between;
  opacity: 0;
  animation: fadein 0.3s forwards;
}

.xp-lines .lucky {
  color: var(--gold);
  font-weight: 800;
}

@keyframes fadein {
  to {
    opacity: 1;
  }
}

.unlock {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(255, 211, 90, 0.12);
  border: 1px solid rgba(255, 211, 90, 0.5);
  margin-top: 6px;
  font-weight: 700;
}

.unlock canvas {
  flex: none;
  width: 40px;
  height: 40px;
}

.grid-items {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 8px;
}

.item {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 10px;
  padding: 8px 4px;
  font-size: 12px;
  font-weight: 700;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.item canvas {
  width: 64px;
  height: 64px;
}

.item[aria-pressed='true'] {
  border-color: var(--gold);
  box-shadow: 0 0 0 1px var(--gold);
}

.item:disabled {
  opacity: 0.5;
  cursor: default;
}

.ach {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 8px 10px;
  border-radius: 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  margin-bottom: 6px;
  font-size: 13px;
}

.ach .medal {
  flex: none;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: #2a3a30;
  color: #5b6f61;
  font-weight: 900;
}

.ach.got .medal {
  background: radial-gradient(circle at 35% 30%, #fff1a8, var(--gold-2));
  color: #3a2400;
}

.ach b {
  display: block;
}

.lb {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.lb td {
  padding: 6px 4px;
  border-bottom: 1px solid var(--line);
}

.lb td:last-child {
  text-align: right;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

.lb tr.me td {
  color: var(--gold);
}

.score-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.score-table td {
  padding: 7px 4px;
  border-bottom: 1px solid var(--line);
}

.score-table td:last-child {
  text-align: right;
  font-weight: 900;
  color: var(--gold);
}

.score-table .dice {
  display: inline-flex;
  gap: 3px;
  vertical-align: middle;
}

.pip-die {
  width: 20px;
  height: 20px;
  border-radius: 5px;
  background: #fffdf6;
  color: #1d1a17;
  font-size: 12px;
  font-weight: 900;
  display: inline-grid;
  place-items: center;
}

.toast-msg {
  margin: 10px 0;
  padding: 10px;
  border-radius: 10px;
  background: rgba(255, 90, 103, 0.12);
  border: 1px solid rgba(255, 90, 103, 0.4);
  font-size: 14px;
}

/* ---------- Page below the game ---------- */

.ad-slot {
  max-width: 970px;
  margin: 12px auto 0;
  min-height: 0;
}

.ad-slot[data-filled='true'] {
  min-height: 90px;
}

.about {
  max-width: 820px;
  margin: 24px auto 0;
  color: var(--muted);
  line-height: 1.55;
  font-size: 15px;
}

.about h1,
.about h2 {
  color: var(--text);
}

kbd {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0 5px;
  font-size: 12px;
  color: var(--text);
}

/* ---------- Small screens ---------- */

@media (max-width: 600px) {
  .page {
    padding: 4px 4px 32px;
  }

  .stage {
    height: clamp(250px, calc(100dvh - var(--header-h) - 262px), 520px);
  }

  .players {
    gap: 4px;
    padding: 6px 4px 4px;
  }

  .chip {
    flex-direction: column;
    align-items: stretch;
    gap: 2px;
    padding: 5px 6px;
    text-align: center;
  }

  .chip .avatar {
    display: none;
  }

  .chip .name {
    font-size: 11px;
  }

  .chip.me .name::after {
    content: '';
  }

  .chip.me {
    background: #1f3829;
  }

  .chip .score {
    font-size: 16px;
  }

  .chip .tag {
    display: none;
  }

  .btn {
    font-size: 17px;
    min-height: 52px;
    padding: 8px;
  }

  .emote {
    width: 44px;
  }

  .toolbar {
    top: 76px;
    right: 10px;
  }

  .row2 {
    grid-template-columns: repeat(5, 1fr);
    gap: 4px;
  }

  .sbtn {
    font-size: 10.5px;
  }
}
