/* DUDO — Last Die Standing · web shell
   Reference resolution 2868x1320 (iPhone Pro Max landscape). Everything else letterboxes. */

:root {
  --bg: #0a0908;
  --bg-2: #14110e;
  --ink: #f2e9dc;
  --ink-dim: #a89a86;
  --brass: #d9a441;
  --brass-hi: #f3c96b;
  --brass-lo: #8c5f1c;
  --felt: #12352b;
  --danger: #e2574c;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-display: "Futura", "Avenir Next Condensed", "Arial Narrow", ui-sans-serif, system-ui, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  user-select: none;
  -webkit-user-select: none;
}

#app {
  position: fixed;
  inset: 0;
  height: 100dvh;
  background:
    radial-gradient(120% 90% at 50% 40%, #1b1712 0%, var(--bg) 60%),
    var(--bg);
}

/* ---------- Stage (letterboxed game) ---------- */

#stage {
  position: absolute;
  inset: 0;
  padding: var(--safe-t) var(--safe-r) var(--safe-b) var(--safe-l);
  display: grid;
  place-items: center;
}

#frame {
  position: relative;
  /* JS sets exact width/height; this is the no-JS fallback */
  aspect-ratio: 2868 / 1320;
  width: min(100%, calc((100dvh - var(--safe-t) - var(--safe-b)) * 2.172727));
  background: #000;
  box-shadow: 0 0 0 1px rgba(217, 164, 65, .12), 0 30px 80px rgba(0, 0, 0, .6);
  border-radius: 6px;
  overflow: hidden;
}

#unity-canvas {
  display: block;
  width: 100%;
  height: 100%;
  background: #000;
  outline: none;
  touch-action: none;
}

#app[data-state="intro"] #frame,
#app[data-state="loading"] #frame { opacity: 0; }
#app[data-state="playing"] #frame { opacity: 1; transition: opacity .6s ease; }

/* ---------- Intro / loader overlay ---------- */

#intro {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: calc(var(--safe-t) + 16px) calc(var(--safe-r) + 16px) calc(var(--safe-b) + 16px) calc(var(--safe-l) + 16px);
  z-index: 2;
  transition: opacity .5s ease, visibility .5s;
  /* subtle film grain */
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 .05 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
}

#app[data-state="playing"] #intro { opacity: 0; visibility: hidden; pointer-events: none; }

.glow {
  position: absolute;
  width: min(80vmin, 720px);
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(217, 164, 65, .18), rgba(217, 164, 65, 0) 65%);
  filter: blur(10px);
  animation: breathe 6s ease-in-out infinite;
  pointer-events: none;
}

.brand {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: clamp(4px, 1.2vmin, 12px);
  max-width: 640px;
}

h1 {
  margin: clamp(6px, 2vmin, 20px) 0 0;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(56px, 16vmin, 168px);
  line-height: .9;
  letter-spacing: .14em;
  padding-left: .14em; /* optical centering for tracking */
  background: linear-gradient(180deg, var(--brass-hi) 0%, var(--brass) 45%, var(--brass-lo) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 2px 30px rgba(217, 164, 65, .15);
}

.sub {
  margin: 0;
  font-size: clamp(11px, 2.2vmin, 18px);
  letter-spacing: .5em;
  padding-left: .5em;
  text-transform: uppercase;
  color: var(--ink);
  opacity: .85;
}

.tag {
  margin: clamp(4px, 1.5vmin, 14px) 0 clamp(10px, 3vmin, 28px);
  font-size: clamp(13px, 2.4vmin, 18px);
  color: var(--ink-dim);
}

.meta {
  margin: clamp(10px, 3vmin, 28px) 0 0;
  font-size: 12px;
  color: var(--ink-dim);
  opacity: .6;
  letter-spacing: .08em;
}

/* ---------- Play button ---------- */

#play {
  appearance: none;
  border: 0;
  cursor: pointer;
  font: 700 clamp(16px, 3vmin, 22px)/1 var(--font-display);
  letter-spacing: .3em;
  padding: clamp(14px, 2.6vmin, 20px) clamp(42px, 8vmin, 72px) clamp(14px, 2.6vmin, 20px) calc(clamp(42px, 8vmin, 72px) + .3em);
  text-transform: uppercase;
  color: #1a1206;
  border-radius: 999px;
  background: linear-gradient(180deg, var(--brass-hi), var(--brass) 55%, #b9822b);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, .5),
    inset 0 -2px 0 rgba(0, 0, 0, .25),
    0 10px 30px rgba(217, 164, 65, .25);
  transition: transform .15s ease, box-shadow .2s ease, filter .2s;
}
#play:hover { transform: translateY(-1px); filter: brightness(1.06); box-shadow: inset 0 1px 0 rgba(255,255,255,.5), inset 0 -2px 0 rgba(0,0,0,.25), 0 14px 40px rgba(217,164,65,.35); }
#play:active { transform: translateY(1px) scale(.98); }
#play:focus-visible { outline: 2px solid var(--brass-hi); outline-offset: 4px; }
#play[hidden] { display: none; }

/* ---------- Loading bar ---------- */

#loading { width: min(360px, 70vw); }
#loading[hidden] { display: none; }

.bar {
  height: 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .08);
  overflow: hidden;
}
#bar-fill {
  display: block;
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--brass-lo), var(--brass-hi));
  box-shadow: 0 0 12px rgba(243, 201, 107, .6);
  transition: width .25s ease;
}
#loading-label {
  margin: 12px 0 0;
  font-size: 13px;
  color: var(--ink-dim);
  font-variant-numeric: tabular-nums;
}

/* ---------- 3D die ---------- */

.die-scene {
  --s: clamp(52px, 12vmin, 96px);
  width: var(--s);
  height: var(--s);
  perspective: calc(var(--s) * 6);
}

.die {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  animation: tumble 9s cubic-bezier(.45, .05, .55, .95) infinite;
}

.face {
  position: absolute;
  inset: 0;
  border-radius: 18%;
  background: radial-gradient(130% 130% at 30% 25%, #fbf4e6, #e6d6bb 70%, #cdb994);
  box-shadow: inset 0 0 calc(var(--s) * .12) rgba(110, 80, 40, .35);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  padding: 14%;
  backface-visibility: hidden;
}
.face i {
  width: 72%;
  aspect-ratio: 1;
  place-self: center;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #4a1410, #1a0705 70%);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, .6);
}
.f1 i:nth-child(1) { grid-area: 2 / 2; background: radial-gradient(circle at 35% 30%, #c0392b, #5c0f08 75%); }

.f2 i:nth-child(1) { grid-area: 1 / 1; }
.f2 i:nth-child(2) { grid-area: 3 / 3; }

.f3 i:nth-child(1) { grid-area: 1 / 1; }
.f3 i:nth-child(2) { grid-area: 2 / 2; }
.f3 i:nth-child(3) { grid-area: 3 / 3; }

.f4 i:nth-child(1) { grid-area: 1 / 1; }
.f4 i:nth-child(2) { grid-area: 1 / 3; }
.f4 i:nth-child(3) { grid-area: 3 / 1; }
.f4 i:nth-child(4) { grid-area: 3 / 3; }

.f5 i:nth-child(1) { grid-area: 1 / 1; }
.f5 i:nth-child(2) { grid-area: 1 / 3; }
.f5 i:nth-child(3) { grid-area: 2 / 2; }
.f5 i:nth-child(4) { grid-area: 3 / 1; }
.f5 i:nth-child(5) { grid-area: 3 / 3; }

.f6 i:nth-child(1) { grid-area: 1 / 1; }
.f6 i:nth-child(2) { grid-area: 2 / 1; }
.f6 i:nth-child(3) { grid-area: 3 / 1; }
.f6 i:nth-child(4) { grid-area: 1 / 3; }
.f6 i:nth-child(5) { grid-area: 2 / 3; }
.f6 i:nth-child(6) { grid-area: 3 / 3; }

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

/* Loading: the die rattles like it's in the cup */
#app[data-state="loading"] .die { animation: rattle .5s linear infinite; }

@keyframes tumble {
  0%   { transform: rotateX(-20deg) rotateY(30deg); }
  25%  { transform: rotateX(70deg)  rotateY(120deg); }
  50%  { transform: rotateX(160deg) rotateY(250deg); }
  75%  { transform: rotateX(250deg) rotateY(300deg); }
  100% { transform: rotateX(340deg) rotateY(390deg); }
}
@keyframes rattle {
  0%   { transform: rotateX(-20deg) rotateY(30deg)  translate(0, 0); }
  25%  { transform: rotateX(80deg)  rotateY(110deg) translate(2px, -3px); }
  50%  { transform: rotateX(170deg) rotateY(200deg) translate(-2px, 2px); }
  75%  { transform: rotateX(260deg) rotateY(290deg) translate(3px, 1px); }
  100% { transform: rotateX(340deg) rotateY(390deg) translate(0, 0); }
}
@keyframes breathe {
  0%, 100% { transform: scale(1);    opacity: .8; }
  50%      { transform: scale(1.08); opacity: 1; }
}

/* ---------- Rotate prompt (touch devices in portrait) ---------- */

#rotate {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  background: rgba(10, 9, 8, .96);
  color: var(--ink);
  font-size: 16px;
  letter-spacing: .05em;
}
#app.portrait #rotate { display: flex; }

.phone {
  width: 44px;
  height: 78px;
  border: 3px solid var(--brass);
  border-radius: 10px;
  position: relative;
  animation: turn 2.4s ease-in-out infinite;
}
.phone::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 6px;
  width: 10px;
  height: 3px;
  margin-left: -5px;
  border-radius: 2px;
  background: var(--brass);
}
@keyframes turn {
  0%, 20%   { transform: rotate(0deg); }
  50%, 80%  { transform: rotate(-90deg); }
  100%      { transform: rotate(0deg); }
}

/* ---------- Fullscreen button + toast ---------- */

#fs-btn {
  position: absolute;
  top: calc(var(--safe-t) + 10px);
  right: calc(var(--safe-r) + 10px);
  z-index: 4;
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(217, 164, 65, .3);
  border-radius: 10px;
  background: rgba(20, 17, 14, .6);
  color: var(--brass-hi);
  cursor: pointer;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  opacity: .7;
  transition: opacity .2s;
}
#fs-btn:hover { opacity: 1; }
#fs-btn[hidden] { display: none; }
#app[data-state="playing"] #fs-btn { opacity: .35; }

#toast {
  position: absolute;
  left: 50%;
  bottom: calc(var(--safe-b) + 18px);
  transform: translateX(-50%);
  z-index: 6;
  max-width: min(560px, 90vw);
  padding: 12px 18px;
  border-radius: 12px;
  background: rgba(20, 17, 14, .92);
  border: 1px solid rgba(217, 164, 65, .3);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.4;
  text-align: center;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .5);
}
#toast.error { border-color: rgba(226, 87, 76, .6); }
#toast[hidden] { display: none; }

@media (prefers-reduced-motion: reduce) {
  .die, .glow, .phone { animation: none !important; }
}
