@font-face {
  font-family: "Outfit";
  src: url("/fonts/outfit.woff2") format("woff2");
  font-weight: 100 900;
  font-display: swap;
}

:root {
  --navy: #0b1026;
  --navy-2: #141a3d;
  --card: rgba(255, 255, 255, .06);
  --line: rgba(255, 255, 255, .1);
  --text: #f4f6ff;
  --soft: #aab3d6;
  --red: #ff3d6e;
  --gold: #ffc531;
  --green: #22c55e;
  --radius: 20px;
  --ease: cubic-bezier(.2, .8, .2, 1);
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  font-family: "Outfit", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background:
    radial-gradient(900px 600px at 15% -10%, rgba(99, 102, 241, .35), transparent 60%),
    radial-gradient(800px 600px at 110% 20%, rgba(255, 61, 110, .18), transparent 60%),
    linear-gradient(180deg, #121845, var(--navy) 60%);
  background-attachment: fixed;
  -webkit-tap-highlight-color: transparent;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

#app { max-width: 560px; margin: 0 auto; padding: 0 16px calc(24px + env(safe-area-inset-bottom)); }
.screen { display: none; animation: enter .35s var(--ease); }
.screen.active { display: block; }
@keyframes enter { from { opacity: 0; transform: translateY(8px); } }

/* Top bar */
.topbar {
  display: flex; align-items: center; gap: 12px; min-height: 64px;
  padding-top: env(safe-area-inset-top);
}
.topbar h2 { flex: 1; margin: 0; font-size: 20px; font-weight: 700; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-gap { width: 44px; }
.topbar-actions { display: flex; gap: 8px; }
.brand { display: flex; align-items: center; gap: 10px; flex: 1; color: inherit; text-decoration: none; font-size: 20px; font-weight: 700; }
.brand img { border-radius: 10px; }
.brand b { color: var(--gold); font-weight: 700; }
.icon-btn {
  display: grid; place-items: center; width: 44px; height: 44px; flex: none;
  border: 0; border-radius: 14px; font-size: 20px; line-height: 1;
  background: var(--card); box-shadow: inset 0 0 0 1px var(--line);
  transition: background .2s;
}
.icon-btn:hover { background: rgba(255, 255, 255, .12); }
.conn {
  flex: none; min-width: 44px; padding: 6px 10px; border-radius: 999px; font-size: 12px; font-weight: 600;
  color: var(--soft); background: var(--card); box-shadow: inset 0 0 0 1px var(--line);
}
.conn.on { color: #bbf7d0; background: rgba(34, 197, 94, .14); box-shadow: inset 0 0 0 1px rgba(34, 197, 94, .35); }
.conn.on::before { content: ""; display: inline-block; width: 7px; height: 7px; margin-right: 6px; border-radius: 50%; background: var(--green); vertical-align: 1px; }

/* Home */
.home-hero { margin: 8px 0 22px; padding: 24px 22px; border-radius: 24px; background: linear-gradient(135deg, rgba(255, 255, 255, .1), rgba(255, 255, 255, .03)); box-shadow: inset 0 0 0 1px var(--line); }
.home-hero h1 { margin: 0; font-size: clamp(28px, 7vw, 36px); font-weight: 800; letter-spacing: -.01em; }
.home-hero p { margin: 6px 0 0; color: var(--soft); }
.section-label { margin: 0 4px 10px; font-size: 13px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--soft); }
.modes { display: grid; gap: 12px; margin: 0; padding: 0; list-style: none; }
.mode {
  display: flex; align-items: center; gap: 16px; width: 100%; padding: 14px 18px 14px 14px; text-align: left;
  border: 0; border-radius: var(--radius); background: var(--card); box-shadow: inset 0 0 0 1px var(--line);
  transition: transform .2s var(--ease), background .2s;
}
.mode::after { content: "›"; margin-left: auto; font-size: 26px; color: var(--soft); }
.mode:hover { background: rgba(255, 255, 255, .1); transform: translateY(-2px); }
.mode:active { transform: scale(.985); }
.mode b { display: block; font-size: 18px; font-weight: 700; }
.mode small { display: block; margin-top: 2px; font-size: 14px; color: var(--soft); }
.mode-icon { display: grid; place-items: center; width: 56px; height: 56px; flex: none; border-radius: 16px; font-size: 22px; font-weight: 800; color: #fff; }
.m-computer { background: linear-gradient(135deg, #f5b82e, #e88a0c); font-size: 18px; }
.m-pass { background: linear-gradient(135deg, #8b5cf6, #6d3fd8); }
.m-team { background: linear-gradient(135deg, #20b26b, #168653); }
.m-online { background: linear-gradient(135deg, #3b82f6, #2563eb); font-size: 28px; }
.m-friends { background: linear-gradient(135deg, #ff6b8b, #e0508f); }
.app-cta {
  display: flex; align-items: center; gap: 14px; margin-top: 22px; padding: 14px 18px 14px 14px;
  border-radius: var(--radius); color: inherit; text-decoration: none;
  background: linear-gradient(135deg, rgba(255, 197, 49, .18), rgba(255, 61, 110, .14)); box-shadow: inset 0 0 0 1px rgba(255, 197, 49, .3);
}
.app-cta img { border-radius: 12px; }
.app-cta b { display: block; }
.app-cta small { color: var(--soft); }
.app-cta > span:last-child { margin-left: auto; font-size: 26px; color: var(--gold); }

/* Cards and forms */
.card { margin-top: 14px; padding: 20px; border-radius: var(--radius); background: var(--card); box-shadow: inset 0 0 0 1px var(--line); }
.card h3 { margin: 0 0 14px; font-size: 18px; }
.field { display: block; margin-bottom: 18px; }
.field-label { display: block; margin-bottom: 8px; font-size: 13px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--soft); }
.hint { margin: 10px 0 0; font-size: 14px; line-height: 1.5; color: var(--soft); }
.hint:empty { display: none; }
#setup-note { margin: 0 0 18px; }
.seg { display: flex; gap: 6px; padding: 5px; border-radius: 16px; background: rgba(0, 0, 0, .25); }
.seg button { flex: 1; min-height: 44px; border: 0; border-radius: 12px; background: transparent; font-weight: 600; color: var(--soft); transition: background .2s, color .2s; }
.seg button[aria-checked="true"] { color: #fff; background: linear-gradient(135deg, var(--red), #e8335e); box-shadow: 0 6px 16px -6px rgba(255, 61, 110, .7); }
.input {
  width: 100%; min-height: 50px; padding: 0 16px; border: 0; border-radius: 14px; font-size: 17px;
  background: rgba(0, 0, 0, .28); box-shadow: inset 0 0 0 1px var(--line); outline: none;
}
.input:focus { box-shadow: inset 0 0 0 2px var(--gold); }
.input.code { font-size: 22px; font-weight: 700; letter-spacing: .3em; text-transform: uppercase; text-align: center; }
.join { display: flex; gap: 10px; }
.join .btn { flex: none; padding: 0 26px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 18px; }
.two .btn { flex-direction: column; min-height: 72px; }
.two .btn small { font-size: 13px; font-weight: 500; opacity: .85; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 4px; min-height: 52px; padding: 0 22px;
  border: 0; border-radius: 16px; font-size: 17px; font-weight: 700; text-decoration: none;
  transition: transform .15s var(--ease), filter .2s, opacity .2s;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { color: #fff; background: linear-gradient(135deg, #ff5a83, var(--red) 55%, #e8335e); box-shadow: 0 12px 26px -12px rgba(255, 61, 110, .9); }
.btn.primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn.ghost { color: var(--text); background: rgba(255, 255, 255, .08); box-shadow: inset 0 0 0 1px var(--line); }
.btn.link { color: var(--soft); background: none; font-weight: 600; }
.btn.wide { width: 100%; }

/* Waiting */
.wait-card { text-align: center; padding: 30px 22px; }
.spinner { width: 54px; height: 54px; margin: 0 auto 18px; border-radius: 50%; border: 5px solid rgba(255, 255, 255, .12); border-top-color: var(--gold); animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.room-code { margin: 0 0 14px; font-size: 44px; font-weight: 800; letter-spacing: .18em; color: var(--gold); }
.wait-status { margin: 18px 0 0; color: var(--soft); line-height: 1.5; }
.wait-players { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin: 16px 0 0; padding: 0; list-style: none; }
.wait-players li { padding: 8px 14px; border-radius: 999px; background: rgba(255, 255, 255, .08); font-weight: 600; }
#wait-start { margin-top: 20px; }

/* Game */
#screen-game.active { display: flex; flex-direction: column; min-height: calc(100dvh - env(safe-area-inset-bottom)); }
.table {
  --board: min(100%, calc(100dvh - 360px), 620px);
  display: flex; flex-direction: column; align-items: center; flex: 1; justify-content: center; padding-bottom: 8px;
}
@media (max-height: 640px) { .table { --board: min(100%, calc(100dvh - 300px)); } }
.board-wrap { width: max(var(--board), 260px); aspect-ratio: 1; border-radius: calc(max(var(--board), 260px) / 15 * .55); box-shadow: 0 24px 60px -20px rgba(0, 0, 0, .7), 0 0 0 1px rgba(255, 255, 255, .08); }
#board { display: block; width: 100%; height: 100%; touch-action: manipulation; }
.docks { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; width: max(var(--board), 260px); padding: 10px 0; }
.dock {
  position: relative; grid-column: 1; justify-self: start; display: flex; align-items: center; gap: 10px; min-width: 0; max-width: 100%; padding: 7px 14px 7px 7px;
  border: 0; border-radius: 20px; text-align: left; background: rgba(255, 255, 255, .05);
  box-shadow: inset 0 0 0 1px var(--line); opacity: .55; transition: opacity .25s, background .25s, box-shadow .25s, transform .25s var(--ease);
  cursor: default;
}
.dock.right { grid-column: 2; justify-self: end; flex-direction: row-reverse; text-align: right; padding: 7px 7px 7px 14px; }
.dock.active { opacity: 1; background: rgba(255, 255, 255, .1); box-shadow: inset 0 0 0 2px var(--seat), 0 0 26px -6px var(--seat); }
.dock.tappable { cursor: pointer; animation: nudge 1.3s ease-in-out infinite; }
.dock.tappable .die { animation: glow 1.3s ease-in-out infinite; }
@keyframes nudge { 50% { transform: translateY(-3px); } }
@keyframes glow { 50% { filter: drop-shadow(0 0 10px var(--seat)); } }
.dock-info { display: flex; flex-direction: column; min-width: 0; }
.dock-name { font-size: 15px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dock-tag { font-size: 12px; color: var(--soft); }
.dock-tag:empty { display: none; }
.timer { position: absolute; left: 14px; right: 14px; bottom: 3px; height: 3px; border-radius: 3px; background: var(--gold); transform-origin: left; transform: scaleX(0); }
.dock.right .timer { transform-origin: right; }
.timer.run { animation: countdown var(--ms) linear forwards; }
@keyframes countdown { from { transform: scaleX(1); } to { transform: scaleX(0); } }

/* Die */
.die { --s: 46px; --pip: #172033; position: relative; width: var(--s); height: var(--s); flex: none; perspective: 300px; }
.die .cube { position: absolute; inset: 0; transform-style: preserve-3d; }
.die .face {
  position: absolute; inset: 0; display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr);
  padding: 16%; border-radius: 22%; background: radial-gradient(circle at 30% 25%, #ffffff, #eef1f6 60%, #d7dce6);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .06), inset 0 -3px 6px rgba(0, 0, 0, .08); backface-visibility: hidden;
}
.die .face span { display: grid; place-items: center; }
.die .pip::before { content: ""; width: 72%; aspect-ratio: 1; border-radius: 50%; background: radial-gradient(circle at 35% 30%, color-mix(in srgb, var(--pip), #fff 30%), var(--pip) 60%, color-mix(in srgb, var(--pip), #000 25%)); }
.die .f1 { transform: translateZ(calc(var(--s) / 2)); }
.die .f6 { transform: rotateY(180deg) translateZ(calc(var(--s) / 2)); }
.die .f3 { transform: rotateY(90deg) translateZ(calc(var(--s) / 2)); }
.die .f4 { transform: rotateY(-90deg) translateZ(calc(var(--s) / 2)); }
.die .f2 { transform: rotateX(90deg) translateZ(calc(var(--s) / 2)); }
.die .f5 { transform: rotateX(-90deg) translateZ(calc(var(--s) / 2)); }
.die.rolling { animation: hop .72s var(--ease); }
@keyframes hop { 35% { transform: translateY(-14px) scale(1.08); } 70% { transform: translateY(0) scale(.97); } }

.status { min-height: 1.4em; margin: 6px 0 0; font-size: 17px; font-weight: 600; text-align: center; }
.event { min-height: 1.3em; margin: 4px 0 0; font-size: 14px; color: var(--soft); text-align: center; }

/* Emotes */
.emotes {
  position: fixed; z-index: 20; top: calc(68px + env(safe-area-inset-top)); left: 50%; width: min(92vw, 420px); transform: translateX(-50%);
  display: flex; flex-wrap: wrap; gap: 8px; padding: 14px; border-radius: 20px;
  background: #1a2150; box-shadow: 0 20px 50px -10px rgba(0, 0, 0, .6), inset 0 0 0 1px var(--line);
}
.emotes button { border: 0; border-radius: 12px; background: rgba(255, 255, 255, .08); }
.emotes .emoji { width: calc((100% - 40px) / 6); aspect-ratio: 1; font-size: 26px; }
.emotes .phrase { flex: 1 1 calc(50% - 4px); min-height: 42px; font-size: 15px; font-weight: 600; }
.bubble {
  position: absolute; z-index: 5; left: 50%; bottom: calc(100% + 6px); transform: translateX(-50%); padding: 8px 14px; border-radius: 16px;
  white-space: nowrap; font-size: 15px; font-weight: 700; color: #172033; background: #fff; box-shadow: 0 10px 24px -8px rgba(0, 0, 0, .5);
  animation: pop .3s var(--ease);
}
.docks.top .bubble { bottom: auto; top: calc(100% + 6px); }
.bubble.big { font-size: 28px; padding: 4px 10px; }
@keyframes pop { from { opacity: 0; transform: translateX(-50%) scale(.6); } }

/* Dialogs */
.sheet {
  width: min(92vw, 400px); padding: 26px 22px 18px; border: 0; border-radius: 26px; color: var(--text); text-align: center;
  background: linear-gradient(180deg, #1d2559, #141a3d); box-shadow: 0 30px 80px -20px rgba(0, 0, 0, .8), inset 0 0 0 1px var(--line);
}
.sheet::backdrop { background: rgba(5, 8, 22, .65); backdrop-filter: blur(4px); }
.sheet[open] { animation: pop-in .3s var(--ease); }
@keyframes pop-in { from { opacity: 0; transform: scale(.92); } }
.sheet h3 { margin: 0 0 8px; font-size: 22px; }
.sheet p { margin: 0 0 18px; color: var(--soft); }
.sheet .btn { margin-top: 10px; }
.trophy { font-size: 56px; line-height: 1; margin-bottom: 8px; }
.ranking { margin: 16px 0 10px; padding: 0; list-style: none; text-align: left; }
.ranking li { display: flex; align-items: center; gap: 12px; padding: 10px 14px; margin-top: 8px; border-radius: 14px; background: rgba(255, 255, 255, .06); font-weight: 600; }
.ranking .medal { width: 28px; text-align: center; font-size: 20px; }
.ranking .swatch { width: 14px; height: 14px; border-radius: 50%; box-shadow: 0 0 0 2px rgba(255, 255, 255, .7); }

.toast {
  position: fixed; z-index: 30; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  max-width: 90vw; padding: 12px 18px; border-radius: 14px; font-weight: 600; color: #172033; background: #fff;
  box-shadow: 0 16px 40px -10px rgba(0, 0, 0, .6); animation: pop-up .3s var(--ease);
}
@keyframes pop-up { from { opacity: 0; transform: translate(-50%, 10px); } }
.noscript { padding: 40px 20px; text-align: center; }

@media (min-width: 700px) {
  #app { max-width: 680px; }
  .die { --s: 52px; }
}

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