/* Ludo Toybox — glossy toy-box look. Palette by role: warm wood + ivory world,
   saturated candy pieces, gold for rewards. */

:root {
  --red: #e8453c;
  --red-d: #b52c24;
  --green: #2db35a;
  --green-d: #1c8540;
  --yellow: #f7c325;
  --yellow-d: #cf9608;
  --blue: #2f6fe0;
  --blue-d: #1d4dab;
  --gold: #f5b82e;
  --gold-d: #c98a0c;
  --ivory: #fff7e8;
  --cream: #fff1d6;
  --wood: #c98b4a;
  --wood-d: #7a4a22;
  --ink: #4a2c17;
  --ink-soft: #7b5a40;
  --night: #2a170c;
  --shadow: 0 6px 18px rgba(40, 18, 4, 0.35);
  --radius: 18px;
  --ds: 56px;
  --board: 360px;
  --font-ui: "Nunito", ui-rounded, system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-display: "Lilita One", "Nunito", ui-rounded, system-ui, sans-serif;
  color-scheme: light;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  background: var(--night);
  color: var(--ink);
  font: 800 16px/1.35 var(--font-ui);
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

button:focus-visible,
input:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 3px;
}

[hidden] {
  display: none !important;
}

.backdrop {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(120% 90% at 50% 45%, rgba(42, 23, 12, 0) 35%, rgba(26, 12, 4, 0.72) 100%),
    url("assets/bg.webp") center / cover no-repeat,
    var(--night);
  filter: saturate(1.05);
}

body.in-game .backdrop {
  background:
    radial-gradient(90% 80% at 50% 50%, rgba(42, 23, 12, 0.15) 30%, rgba(26, 12, 4, 0.85) 100%),
    url("assets/bg.webp") center / cover no-repeat,
    var(--night);
  filter: blur(3px) saturate(0.95) brightness(0.8);
  transform: scale(1.04);
}

.screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom)
    env(safe-area-inset-left);
  animation: screen-in 0.35s ease-out both;
}

@keyframes screen-in {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.99);
  }
}

/* ───────────── buttons ───────────── */

.btn {
  --c1: #ff6b5f;
  --c2: var(--red);
  --c3: var(--red-d);
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 52px;
  padding: 10px 22px 12px;
  border: 0;
  border-radius: var(--radius);
  background: linear-gradient(180deg, var(--c1), var(--c2) 55%);
  box-shadow:
    0 5px 0 var(--c3),
    0 9px 16px rgba(40, 18, 4, 0.35),
    inset 0 2px 0 rgba(255, 255, 255, 0.45);
  color: #fff;
  font: 400 20px/1.1 var(--font-display);
  letter-spacing: 0.4px;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.22);
  transition:
    transform 0.08s ease,
    box-shadow 0.08s ease,
    filter 0.15s ease;
}

.btn::after {
  content: "";
  position: absolute;
  inset: 3px 8px auto;
  height: 40%;
  border-radius: 14px 14px 30px 30px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.35), rgba(255, 255, 255, 0));
  pointer-events: none;
}

.btn:hover {
  filter: brightness(1.06);
}

.btn:active:not(:disabled) {
  transform: translateY(4px);
  box-shadow:
    0 1px 0 var(--c3),
    0 3px 8px rgba(40, 18, 4, 0.35),
    inset 0 2px 0 rgba(255, 255, 255, 0.45);
}

.btn:disabled {
  filter: grayscale(0.7) brightness(0.9);
  opacity: 0.55;
  cursor: default;
}

.btn.green {
  --c1: #4fd27b;
  --c2: var(--green);
  --c3: var(--green-d);
}

.btn.blue {
  --c1: #5a93ff;
  --c2: var(--blue);
  --c3: var(--blue-d);
}

.btn.gold {
  --c1: #ffd666;
  --c2: var(--gold);
  --c3: var(--gold-d);
  color: #5a3304;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.5);
}

.btn.ghost {
  --c1: #fff8ea;
  --c2: #f3e3c6;
  --c3: #cdb48c;
  color: var(--ink);
  text-shadow: none;
}

.btn.big {
  width: 100%;
  min-height: 60px;
  font-size: 22px;
}

.btn.small {
  min-height: 40px;
  padding: 6px 14px 8px;
  font-size: 16px;
  border-radius: 14px;
}

.btn-ico {
  font-size: 1.1em;
  filter: drop-shadow(0 2px 0 rgba(0, 0, 0, 0.2));
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 14px;
  background: rgba(255, 247, 232, 0.14);
  box-shadow: inset 0 0 0 1.5px rgba(255, 247, 232, 0.22);
  color: #fff7e8;
  font-size: 20px;
  transition: background 0.15s ease;
}

.icon-btn:hover {
  background: rgba(255, 247, 232, 0.24);
}

.icon-spacer {
  width: 44px;
}

.pill {
  border: 0;
  border-radius: 999px;
  padding: 8px 14px;
  background: rgba(255, 247, 232, 0.9);
  color: var(--ink);
  font-weight: 900;
  font-size: 14px;
  box-shadow: 0 3px 0 rgba(122, 74, 34, 0.55);
}

/* ───────────── menu ───────────── */

.menu {
  margin: auto;
  width: min(420px, calc(100vw - 32px));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 16px 0;
}

.logo {
  margin: 0;
  font: 400 clamp(64px, 20vw, 104px) / 0.9 var(--font-display);
  letter-spacing: 2px;
  display: flex;
  gap: 2px;
}

.lt {
  display: inline-block;
  -webkit-text-stroke: 3px #fff;
  paint-order: stroke fill;
  text-shadow:
    0 6px 0 rgba(58, 30, 10, 0.55),
    0 12px 22px rgba(20, 8, 2, 0.45);
  animation: letter-in 0.7s cubic-bezier(0.2, 1.6, 0.4, 1) both;
}

.lt.r {
  color: var(--red);
  transform: rotate(-6deg);
}
.lt.g {
  color: var(--green);
  animation-delay: 0.07s;
  transform: rotate(4deg) translateY(-4px);
}
.lt.y {
  color: var(--yellow);
  animation-delay: 0.14s;
  transform: rotate(-3deg);
}
.lt.b {
  color: var(--blue);
  animation-delay: 0.21s;
  transform: rotate(6deg) translateY(-3px);
}

@keyframes letter-in {
  from {
    opacity: 0;
    translate: 0 -40px;
    scale: 0.4;
  }
}

.logo-sub {
  margin-top: -8px;
  padding: 4px 18px 5px;
  border-radius: 999px;
  background: linear-gradient(180deg, #ffd666, var(--gold));
  box-shadow: 0 4px 0 var(--gold-d);
  color: #5a3304;
  font: 400 18px/1 var(--font-display);
  letter-spacing: 6px;
}

.mascots {
  display: flex;
  justify-content: center;
  gap: 4px;
  height: 104px;
  align-items: flex-end;
  margin: 4px 0 2px;
}

.mascot {
  border: 0;
  padding: 0;
  background: none;
  width: 84px;
  height: 96px;
  display: grid;
  place-items: end center;
  animation: mascot-in 0.6s cubic-bezier(0.2, 1.5, 0.4, 1) both;
}

.mascot img {
  max-width: 100%;
  max-height: 100%;
  filter: drop-shadow(0 6px 6px rgba(30, 12, 2, 0.45));
  transition: transform 0.2s ease;
  pointer-events: none;
}

.mascot:hover img {
  transform: translateY(-4px) scale(1.04);
}

.mascot.hop img {
  animation: hop 0.55s cubic-bezier(0.3, 1.4, 0.5, 1);
}

@keyframes mascot-in {
  from {
    opacity: 0;
    transform: translateY(30px) scale(0.6);
  }
}

@keyframes hop {
  0% {
    transform: translateY(0) scale(1, 1);
  }
  20% {
    transform: translateY(2px) scale(1.12, 0.86);
  }
  50% {
    transform: translateY(-26px) scale(0.94, 1.08) rotate(-6deg);
  }
  80% {
    transform: translateY(0) scale(1.08, 0.92);
  }
  100% {
    transform: none;
  }
}

.menu-buttons {
  width: 100%;
  display: grid;
  gap: 14px;
  margin-top: 4px;
}

.menu-foot {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  margin-top: 6px;
}

/* ───────────── top bar ───────────── */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  height: 56px;
  padding: 6px 10px;
  flex: none;
  position: relative;
  z-index: 5;
}

.topbar-title {
  color: #fff7e8;
  font: 400 20px/1 var(--font-display);
  letter-spacing: 0.5px;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.35);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-title b {
  color: var(--gold);
  letter-spacing: 3px;
}

/* ───────────── game table ───────────── */

.table {
  flex: 1;
  display: grid;
  gap: 8px 10px;
  padding: 0 8px 10px;
  justify-content: center;
  align-content: center;
  grid-template-columns: calc(var(--board) / 2 - 5px) calc(var(--board) / 2 - 5px);
  grid-template-areas:
    "c0 c1"
    "board board"
    "c3 c2"
    "roll roll";
  min-height: 0;
}

.table.landscape {
  grid-template-columns: minmax(150px, 250px) var(--board) minmax(150px, 250px);
  grid-template-rows: auto 1fr auto;
  grid-template-areas:
    "c0 board c1"
    ". board roll"
    "c3 board c2";
  gap: 10px 18px;
}

.panel[data-corner="0"] {
  grid-area: c0;
}
.panel[data-corner="1"] {
  grid-area: c1;
}
.panel[data-corner="2"] {
  grid-area: c2;
}
.panel[data-corner="3"] {
  grid-area: c3;
}

.board-wrap {
  grid-area: board;
  position: relative;
  width: var(--board);
  height: var(--board);
  justify-self: center;
  align-self: center;
  border-radius: calc(var(--board) * 0.045);
  box-shadow:
    0 18px 40px rgba(20, 8, 2, 0.55),
    0 4px 0 rgba(90, 50, 20, 0.6);
}

.board-wrap.shake {
  animation: shake 0.42s cubic-bezier(0.36, 0.07, 0.19, 0.97);
}

@keyframes shake {
  10%,
  90% {
    transform: translate(-1px, 1px);
  }
  20%,
  80% {
    transform: translate(3px, -2px);
  }
  30%,
  50%,
  70% {
    transform: translate(-5px, 2px) rotate(-0.4deg);
  }
  40%,
  60% {
    transform: translate(5px, -1px) rotate(0.4deg);
  }
}

#board {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  touch-action: none;
}

.toast {
  position: absolute;
  left: 50%;
  top: 50%;
  translate: -50% -50%;
  max-width: 86%;
  padding: 10px 18px 11px;
  border-radius: 999px;
  background: rgba(58, 30, 12, 0.88);
  color: #fff7e8;
  font: 400 clamp(16px, 4.4vw, 22px) / 1.15 var(--font-display);
  letter-spacing: 0.3px;
  text-align: center;
  box-shadow:
    0 8px 20px rgba(20, 8, 2, 0.45),
    inset 0 0 0 2px rgba(255, 214, 102, 0.55);
  pointer-events: none;
  opacity: 0;
  scale: 0.7;
  transition:
    opacity 0.2s ease,
    scale 0.25s cubic-bezier(0.3, 1.6, 0.5, 1);
  z-index: 3;
}

.toast.show {
  opacity: 1;
  scale: 1;
}

.toast.gold {
  background: linear-gradient(180deg, #ffd666, var(--gold));
  color: #5a3304;
  box-shadow:
    0 8px 20px rgba(20, 8, 2, 0.45),
    inset 0 0 0 2px #fff4c7;
}

/* ───────────── player panels ───────────── */

.panel {
  --pc: var(--red);
  --pd: var(--red-d);
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  height: 68px;
  padding: 6px 8px;
  border-radius: 20px;
  background: rgba(255, 247, 232, 0.9);
  box-shadow:
    0 4px 0 rgba(122, 74, 34, 0.55),
    0 8px 18px rgba(20, 8, 2, 0.3);
  transition:
    transform 0.3s cubic-bezier(0.3, 1.5, 0.5, 1),
    box-shadow 0.3s ease,
    opacity 0.3s ease;
}

.panel[data-corner="1"],
.panel[data-corner="2"] {
  flex-direction: row-reverse;
  text-align: right;
}

.panel.empty {
  visibility: hidden;
}

.panel.done {
  opacity: 0.72;
}

.panel.active {
  transform: scale(1.04);
  box-shadow:
    0 4px 0 var(--pd),
    0 0 0 3px var(--pc),
    0 10px 26px rgba(20, 8, 2, 0.4);
}

.panel[data-color="1"] {
  --pc: var(--green);
  --pd: var(--green-d);
}
.panel[data-color="2"] {
  --pc: var(--yellow);
  --pd: var(--yellow-d);
}
.panel[data-color="3"] {
  --pc: var(--blue);
  --pd: var(--blue-d);
}

.avatar {
  position: relative;
  flex: none;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 35%, #fff 0%, var(--pc) 75%);
  box-shadow:
    inset 0 -4px 0 rgba(0, 0, 0, 0.18),
    0 2px 0 var(--pd);
  display: grid;
  place-items: center;
}

.avatar img {
  width: 90%;
  height: 90%;
  object-fit: contain;
  object-position: 50% 80%;
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.25));
}

.panel.active .avatar img {
  animation: bob 1.1s ease-in-out infinite;
}

@keyframes bob {
  50% {
    transform: translateY(-3px);
  }
}

.timer {
  position: absolute;
  inset: -4px;
  width: calc(100% + 8px);
  height: calc(100% + 8px);
  rotate: -90deg;
  pointer-events: none;
}

.timer circle {
  fill: none;
  stroke: #fff;
  stroke-width: 4;
  stroke-linecap: round;
  stroke-dasharray: 100 100;
  stroke-dashoffset: calc(100 - var(--p, 100));
  filter: drop-shadow(0 0 2px rgba(0, 0, 0, 0.4));
}

.timer.low circle {
  stroke: #ff5a4a;
}

.pinfo {
  min-width: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.pname {
  font: 400 17px/1.1 var(--font-display);
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.panel.me .avatar::after {
  content: attr(data-you);
  position: absolute;
  left: 50%;
  bottom: -6px;
  translate: -50% 0;
  padding: 1px 5px 2px;
  border-radius: 6px;
  background: var(--pd);
  color: #fff;
  font: 900 9px/1.2 var(--font-ui);
  letter-spacing: 0.3px;
  white-space: nowrap;
  box-shadow: 0 0 0 1.5px #fff;
}

.pstat {
  font-size: 12px;
  color: var(--ink-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pstat .dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  margin: 0 4px 1px 0;
  border-radius: 50%;
  background: #37c465;
}

.pstat .dot.off {
  background: #b9a48d;
}

.phome {
  display: flex;
  gap: 3px;
}

.panel[data-corner="1"] .phome,
.panel[data-corner="2"] .phome {
  justify-content: flex-end;
}

.phome i {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: rgba(74, 44, 23, 0.14);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.2);
}

.phome i.in {
  background: radial-gradient(circle at 40% 35%, #fff 0 15%, var(--pc) 45%, var(--pd));
  box-shadow: 0 0 0 1px var(--pd);
}

.dock {
  flex: none;
  width: calc(var(--ds) + 6px);
  height: calc(var(--ds) + 6px);
  border-radius: 16px;
  background: rgba(74, 44, 23, 0.1);
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.15);
}

.rank-badge {
  position: absolute;
  top: -8px;
  left: 50%;
  translate: -50% 0;
  padding: 2px 8px;
  border-radius: 999px;
  background: linear-gradient(180deg, #ffd666, var(--gold));
  color: #5a3304;
  font: 400 12px/1.2 var(--font-display);
  box-shadow: 0 2px 0 var(--gold-d);
}

/* ───────────── roll area ───────────── */

.roll-area {
  grid-area: roll;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 72px;
}

.btn.roll {
  min-width: min(300px, 80vw);
  min-height: 56px;
  font-size: 22px;
}

.btn.roll:not(:disabled) {
  animation: roll-pulse 1.4s ease-in-out infinite;
}

@keyframes roll-pulse {
  50% {
    filter: brightness(1.12);
    scale: 1.03;
  }
}

.roll-hint {
  color: rgba(255, 247, 232, 0.75);
  font-size: 13px;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.roll-area.ready .roll-hint {
  opacity: 1;
}

.table.landscape .roll-area {
  align-self: center;
}

.table.landscape .btn.roll {
  min-width: 0;
  width: 100%;
}

/* ───────────── 3D dice ───────────── */

.dice {
  position: absolute;
  left: 0;
  top: 0;
  width: var(--ds);
  height: var(--ds);
  z-index: 20;
  touch-action: none;
  will-change: transform;
  pointer-events: none;
}

.dice.interactive {
  pointer-events: auto;
  cursor: grab;
}

.dice.dragging {
  cursor: grabbing;
}

.dice-shadow {
  position: absolute;
  left: 8%;
  right: 8%;
  bottom: -10%;
  height: 26%;
  border-radius: 50%;
  background: radial-gradient(closest-side, rgba(30, 12, 2, 0.55), rgba(30, 12, 2, 0));
  will-change: transform, opacity;
}

.dice-body {
  position: absolute;
  inset: 0;
  perspective: 420px;
  will-change: transform;
}

.dice.ready .dice-body::before {
  content: "";
  position: absolute;
  inset: -18%;
  border-radius: 30%;
  background: radial-gradient(closest-side, rgba(255, 214, 102, 0.85), rgba(255, 214, 102, 0));
  animation: glow 1.2s ease-in-out infinite;
}

@keyframes glow {
  50% {
    opacity: 0.35;
    scale: 1.15;
  }
}

.dice.land .dice-tilt {
  animation: land 0.32s cubic-bezier(0.3, 1.8, 0.5, 1);
}

@keyframes land {
  0% {
    scale: 1.18;
  }
  100% {
    scale: 1;
  }
}

.dice.six .dice-body::after {
  content: "";
  position: absolute;
  inset: -40%;
  border-radius: 50%;
  background: conic-gradient(
    from 0deg,
    rgba(255, 214, 102, 0) 0deg,
    rgba(255, 214, 102, 0.75) 20deg,
    rgba(255, 214, 102, 0) 40deg,
    rgba(255, 214, 102, 0) 60deg,
    rgba(255, 214, 102, 0.75) 80deg,
    rgba(255, 214, 102, 0) 100deg,
    rgba(255, 214, 102, 0) 120deg,
    rgba(255, 214, 102, 0.75) 140deg,
    rgba(255, 214, 102, 0) 160deg,
    rgba(255, 214, 102, 0) 180deg,
    rgba(255, 214, 102, 0.75) 200deg,
    rgba(255, 214, 102, 0) 220deg,
    rgba(255, 214, 102, 0) 240deg,
    rgba(255, 214, 102, 0.75) 260deg,
    rgba(255, 214, 102, 0) 280deg,
    rgba(255, 214, 102, 0) 300deg,
    rgba(255, 214, 102, 0.75) 320deg,
    rgba(255, 214, 102, 0) 340deg
  );
  mask: radial-gradient(closest-side, #000 30%, transparent 100%);
  -webkit-mask: radial-gradient(closest-side, #000 30%, transparent 100%);
  animation: spin 2.4s linear infinite;
  z-index: -1;
}

@keyframes spin {
  to {
    rotate: 360deg;
  }
}

.dice-tilt {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  transform: rotateX(-16deg) rotateY(20deg);
}

.cube {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  will-change: transform;
}

.face,
.core {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
}

.core {
  background: #eadcc4;
  backface-visibility: visible;
  inset: 3%;
}

.core.cx {
  transform: rotateY(90deg);
}
.core.cy {
  transform: rotateX(90deg);
}

.face {
  border-radius: 20%;
  background:
    radial-gradient(120% 120% at 30% 20%, #fffdf6 0%, #fbf1dd 55%, #eddcbd 100%);
  box-shadow:
    inset 0 0 0 1.5px rgba(160, 120, 70, 0.35),
    inset -3px -4px 8px rgba(150, 105, 55, 0.28),
    inset 3px 3px 6px rgba(255, 255, 255, 0.9);
  display: grid;
  grid-template: repeat(3, 1fr) / repeat(3, 1fr);
  padding: 14%;
  gap: 4%;
}

.face i {
  width: 100%;
  aspect-ratio: 1;
  align-self: center;
  border-radius: 50%;
  background: radial-gradient(circle at 38% 32%, #ff8a7a 0 12%, #d7302a 42%, #8e1510 100%);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.35);
}

.face.f1 i {
  grid-area: 2 / 2;
  scale: 1.45;
}

.f1 {
  transform: translateZ(calc(var(--ds) / 2));
}
.f2 {
  transform: rotateX(90deg) translateZ(calc(var(--ds) / 2));
}
.f3 {
  transform: rotateY(90deg) translateZ(calc(var(--ds) / 2));
}
.f4 {
  transform: rotateY(-90deg) translateZ(calc(var(--ds) / 2));
}
.f5 {
  transform: rotateX(-90deg) translateZ(calc(var(--ds) / 2));
}
.f6 {
  transform: rotateY(180deg) translateZ(calc(var(--ds) / 2));
}

/* ───────────── floating celebration layer ───────────── */

.float-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 30;
  overflow: hidden;
}

.pop-text {
  position: absolute;
  translate: -50% -50%;
  font: 400 clamp(24px, 7vw, 40px) / 1 var(--font-display);
  color: #fff;
  -webkit-text-stroke: 4px var(--ink);
  paint-order: stroke fill;
  text-shadow: 0 5px 0 rgba(40, 18, 4, 0.5);
  white-space: nowrap;
  animation: pop-text 1.1s cubic-bezier(0.2, 1.4, 0.4, 1) both;
}

.pop-text.gold {
  color: #ffd84d;
}

@keyframes pop-text {
  0% {
    opacity: 0;
    scale: 0.3;
    rotate: -12deg;
  }
  25% {
    opacity: 1;
    scale: 1.15;
    rotate: 3deg;
  }
  45% {
    scale: 1;
    rotate: 0deg;
  }
  80% {
    opacity: 1;
    translate: -50% -90%;
  }
  100% {
    opacity: 0;
    translate: -50% -130%;
  }
}

.home-star {
  position: absolute;
  width: 34%;
  max-width: 190px;
  aspect-ratio: 357 / 400;
  translate: -50% -58%;
  pointer-events: auto;
  cursor: pointer;
  animation: star-pop 1.9s cubic-bezier(0.2, 1.5, 0.4, 1) both;
  filter: drop-shadow(0 10px 14px rgba(40, 18, 4, 0.45));
}

.home-star.tapped {
  animation:
    star-pop 1.9s cubic-bezier(0.2, 1.5, 0.4, 1) both,
    star-spin 0.6s ease-out;
}

@keyframes star-pop {
  0% {
    opacity: 0;
    scale: 0.1;
    rotate: -90deg;
  }
  22% {
    opacity: 1;
    scale: 1.12;
    rotate: 8deg;
  }
  34% {
    scale: 0.96;
    rotate: -2deg;
  }
  44% {
    scale: 1;
    rotate: 0deg;
  }
  82% {
    opacity: 1;
    scale: 1;
    translate: -50% -70%;
  }
  100% {
    opacity: 0;
    scale: 0.6;
    translate: -50% -140%;
  }
}

@keyframes star-spin {
  to {
    rotate: 360deg;
  }
}

.mini-rank {
  position: absolute;
  left: 50%;
  top: 50%;
  translate: -50% -50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 14px 22px 16px;
  border-radius: 24px;
  background: rgba(255, 247, 232, 0.96);
  box-shadow:
    0 6px 0 rgba(122, 74, 34, 0.6),
    0 20px 40px rgba(20, 8, 2, 0.5);
  animation: mini-rank 2.6s cubic-bezier(0.2, 1.4, 0.4, 1) both;
  text-align: center;
}

.mini-rank img {
  width: 96px;
}

.mini-rank b {
  font: 400 22px/1.1 var(--font-display);
}

@keyframes mini-rank {
  0% {
    opacity: 0;
    scale: 0.4;
  }
  14% {
    opacity: 1;
    scale: 1.06;
  }
  22% {
    scale: 1;
  }
  85% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    scale: 0.9;
  }
}

/* ───────────── lobby ───────────── */

.lobby {
  flex: 1;
  width: min(560px, 100%);
  margin: 0 auto;
  padding: 4px 14px 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
}

.card {
  border-radius: 20px;
  background: rgba(255, 247, 232, 0.95);
  box-shadow:
    0 4px 0 rgba(122, 74, 34, 0.55),
    0 10px 22px rgba(20, 8, 2, 0.35);
}

.invite {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
}

.invite-text {
  flex: 1;
  min-width: 0;
}

.invite-title {
  font: 400 18px/1.1 var(--font-display);
}

.invite-link {
  font-size: 13px;
  color: var(--ink-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  user-select: all;
  -webkit-user-select: all;
}

.seats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.seat {
  --pc: var(--red);
  --pd: var(--red-d);
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 12px 10px;
  text-align: center;
  border-top: 8px solid var(--pc);
  animation: screen-in 0.3s ease-out both;
}

.seat[data-color="1"] {
  --pc: var(--green);
  --pd: var(--green-d);
}
.seat[data-color="2"] {
  --pc: var(--yellow);
  --pd: var(--yellow-d);
}
.seat[data-color="3"] {
  --pc: var(--blue);
  --pd: var(--blue-d);
}

.seat .avatar {
  width: 64px;
  height: 64px;
}

.seat.open .avatar {
  background: rgba(74, 44, 23, 0.1);
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.15);
}

.seat.open .avatar img {
  opacity: 0.25;
  filter: grayscale(1);
}

.seat-name {
  font: 400 18px/1.1 var(--font-display);
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.seat-sub {
  font-size: 12px;
  color: var(--ink-soft);
  min-height: 16px;
}

.seat-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
}

.seat-actions .btn.small {
  min-height: 34px;
  font-size: 14px;
  padding: 4px 10px 6px;
}

.lobby-hint {
  margin: 0;
  color: #fff7e8;
  text-align: center;
  font-size: 14px;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

/* ───────────── sheets ───────────── */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(20, 8, 2, 0.55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  animation: fade-in 0.2s ease-out both;
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
}

.sheet {
  position: relative;
  width: min(460px, 100%);
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  padding: 22px 18px 20px;
  border-radius: 26px;
  background: linear-gradient(180deg, #fffaf0, var(--cream));
  box-shadow:
    0 6px 0 rgba(122, 74, 34, 0.7),
    0 30px 60px rgba(20, 8, 2, 0.55);
  animation: sheet-in 0.35s cubic-bezier(0.2, 1.4, 0.4, 1) both;
}

@keyframes sheet-in {
  from {
    opacity: 0;
    transform: translateY(24px) scale(0.94);
  }
}

.sheet-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 38px;
  height: 38px;
  background: rgba(74, 44, 23, 0.08);
  box-shadow: none;
  color: var(--ink);
  font-size: 16px;
}

.sheet h2 {
  margin: 0 40px 14px 0;
  font: 400 26px/1.1 var(--font-display);
}

.field {
  margin: 0 0 16px;
}

.field-label {
  display: block;
  margin-bottom: 8px;
  font-size: 14px;
  color: var(--ink-soft);
}

.seg {
  display: flex;
  gap: 6px;
  padding: 4px;
  border-radius: 16px;
  background: rgba(74, 44, 23, 0.08);
}

.seg button {
  flex: 1;
  min-height: 42px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  font-weight: 900;
  font-size: 15px;
  color: var(--ink-soft);
  transition:
    background 0.15s ease,
    color 0.15s ease;
}

.seg button.on {
  background: #fff;
  color: var(--ink);
  box-shadow: 0 2px 0 rgba(122, 74, 34, 0.4);
}

.color-pick {
  display: flex;
  gap: 10px;
  justify-content: space-between;
}

.color-pick button {
  flex: 1;
  height: 78px;
  border: 0;
  border-radius: 16px;
  background: rgba(74, 44, 23, 0.07);
  display: grid;
  place-items: center;
  transition:
    transform 0.15s ease,
    background 0.15s ease;
}

.color-pick button img {
  height: 60px;
  filter: drop-shadow(0 3px 2px rgba(0, 0, 0, 0.3));
}

.color-pick button.on {
  background: #fff;
  box-shadow:
    0 0 0 3px var(--gold),
    0 3px 0 rgba(122, 74, 34, 0.4);
  transform: translateY(-2px);
}

.text-input {
  width: 100%;
  height: 48px;
  padding: 0 14px;
  border: 0;
  border-radius: 14px;
  background: #fff;
  box-shadow: inset 0 0 0 2px rgba(122, 74, 34, 0.25);
  font: 800 17px var(--font-ui);
  color: var(--ink);
  user-select: text;
  -webkit-user-select: text;
}

.text-input.code {
  text-transform: uppercase;
  letter-spacing: 5px;
  text-align: center;
  font-size: 20px;
}

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

.local-row {
  display: grid;
  grid-template-columns: 44px 1fr;
  gap: 8px 10px;
  align-items: center;
  margin-bottom: 12px;
}

.local-row img {
  height: 42px;
  justify-self: center;
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.3));
}

.local-row .text-input {
  grid-column: 2;
  height: 40px;
  font-size: 15px;
}

.divider {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 18px 0 14px;
  color: var(--ink-soft);
  font-size: 13px;
}

.divider::before,
.divider::after {
  content: "";
  flex: 1;
  height: 2px;
  background: rgba(122, 74, 34, 0.15);
}

.sheet .btn + .btn {
  margin-top: 10px;
}

.rules {
  margin: 0;
  padding-left: 20px;
  display: grid;
  gap: 8px;
  font-weight: 700;
  color: var(--ink);
}

.toggle-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 2px;
  border-bottom: 2px solid rgba(122, 74, 34, 0.1);
}

.switch {
  width: 54px;
  height: 32px;
  border: 0;
  border-radius: 999px;
  background: rgba(74, 44, 23, 0.2);
  position: relative;
  transition: background 0.2s ease;
}

.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 3px rgba(0, 0, 0, 0.25);
  transition: translate 0.2s cubic-bezier(0.3, 1.5, 0.5, 1);
}

.switch.on {
  background: var(--green);
}

.switch.on::after {
  translate: 22px 0;
}

/* ───────────── win overlay (interactive art) ───────────── */

.win {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 16px;
  background: radial-gradient(circle at 50% 40%, rgba(255, 214, 102, 0.35), rgba(20, 8, 2, 0.85) 70%);
  animation: fade-in 0.4s ease-out both;
  touch-action: none;
}

.win-rays {
  position: absolute;
  left: 50%;
  top: 38%;
  width: 180vmax;
  height: 180vmax;
  translate: -50% -50%;
  background: repeating-conic-gradient(
    from 0deg,
    rgba(255, 230, 150, 0.22) 0deg 9deg,
    rgba(255, 230, 150, 0) 9deg 22.5deg
  );
  mask: radial-gradient(closest-side, #000 10%, transparent 70%);
  -webkit-mask: radial-gradient(closest-side, #000 10%, transparent 70%);
  animation: spin 24s linear infinite;
  pointer-events: none;
}

.win-card {
  position: relative;
  width: min(400px, 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 0 18px 18px;
  border-radius: 30px;
  background: linear-gradient(180deg, rgba(255, 250, 240, 0.97), rgba(255, 238, 206, 0.97));
  box-shadow:
    0 8px 0 rgba(122, 74, 34, 0.75),
    0 30px 70px rgba(20, 8, 2, 0.6);
  animation: sheet-in 0.6s cubic-bezier(0.2, 1.4, 0.4, 1) 0.1s both;
}

.win-art {
  position: relative;
  width: 210px;
  height: 200px;
  margin-top: -110px;
  perspective: 600px;
}

.win-trophy {
  position: absolute;
  inset: 0;
  margin: auto;
  height: 100%;
  cursor: pointer;
  filter: drop-shadow(0 16px 18px rgba(40, 18, 4, 0.5));
  transform: rotateX(var(--tx, 0deg)) rotateY(var(--ty, 0deg));
  transition: transform 0.12s ease-out;
  animation: trophy-in 0.9s cubic-bezier(0.2, 1.5, 0.4, 1) 0.2s both;
}

.win-trophy.spin {
  animation: trophy-spin 0.8s cubic-bezier(0.3, 1.3, 0.5, 1);
}

@keyframes trophy-in {
  from {
    opacity: 0;
    translate: 0 -120px;
    scale: 0.4;
  }
}

@keyframes trophy-spin {
  from {
    rotate: y 0deg;
  }
  to {
    rotate: y 360deg;
  }
}

.win-mascot {
  position: absolute;
  right: -52px;
  bottom: -6px;
  height: 104px;
  filter: drop-shadow(0 6px 6px rgba(40, 18, 4, 0.45));
  animation:
    mascot-in 0.6s cubic-bezier(0.2, 1.5, 0.4, 1) 0.5s both,
    cheer 0.9s ease-in-out 1.1s infinite;
  pointer-events: none;
}

@keyframes cheer {
  0%,
  100% {
    transform: translateY(0) rotate(0deg);
  }
  30% {
    transform: translateY(-16px) rotate(-8deg) scale(1.03, 0.97);
  }
  60% {
    transform: translateY(0) rotate(4deg) scale(1.05, 0.95);
  }
}

.win-title {
  font: 400 36px/1 var(--font-display);
  color: var(--gold);
  -webkit-text-stroke: 4px #fff;
  paint-order: stroke fill;
  text-shadow: 0 4px 0 rgba(122, 74, 34, 0.5);
}

.win-name {
  font: 400 22px/1.1 var(--font-display);
  color: var(--ink);
}

.win-ranking {
  width: 100%;
  margin: 8px 0 6px;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 6px;
}

.win-ranking li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
  border-radius: 14px;
  background: rgba(74, 44, 23, 0.06);
  animation: screen-in 0.4s ease-out both;
}

.win-ranking li b {
  width: 30px;
  font: 400 20px/1 var(--font-display);
  color: var(--ink-soft);
}

.win-ranking li:first-child {
  background: linear-gradient(180deg, #ffe38a, #ffd05a);
}

.win-ranking li:first-child b {
  color: #7a4a05;
}

.win-ranking img {
  height: 34px;
}

.win-ranking span {
  flex: 1;
  font-weight: 900;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.win-actions {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 4px;
}

.win-actions .btn {
  margin: 0 !important;
}

.win-hint {
  font-size: 12px;
  color: var(--ink-soft);
  margin-top: 4px;
}

/* ───────────── fx + status ───────────── */

#fx {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: 55;
}

.net-status {
  position: fixed;
  top: calc(env(safe-area-inset-top) + 62px);
  left: 50%;
  translate: -50% 0;
  z-index: 70;
  padding: 6px 14px;
  border-radius: 999px;
  background: #ff6b5f;
  color: #fff;
  font-size: 13px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.noscript {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  color: #fff;
}

/* Phones: the four panels share half the board width each, so everything in
   them tightens up to leave room for the name. */
@media (max-width: 560px) {
  .panel {
    height: 60px;
    gap: 6px;
    padding: 5px 6px;
    border-radius: 16px;
  }
  .panel .avatar {
    width: 42px;
    height: 42px;
  }
  .pname {
    font-size: 15px;
  }
  .pstat {
    font-size: 11px;
  }
  .phome i {
    width: 9px;
    height: 9px;
  }
  .dock {
    width: calc(var(--ds) + 2px);
    height: calc(var(--ds) + 2px);
    border-radius: 12px;
  }
  .btn.roll {
    min-height: 58px;
  }
}

@media (max-height: 640px) and (orientation: portrait) {
  .mascots {
    height: 76px;
  }
  .mascot {
    width: 64px;
    height: 72px;
  }
  .btn.big {
    min-height: 52px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
