:root {
  --red: #ef1720;
  --blue: #0d79d5;
  --white: #f7fbff;
  --ink: #05070d;
  --panel: rgba(9, 14, 27, 0.92);
  --gold: #ffd52e;
  --timer-progress: 270.18;
}

* { box-sizing: border-box; }

html, body { width: 100%; height: 100%; overflow: hidden; }

body {
  margin: 0;
  color: var(--white);
  background:
    radial-gradient(circle at 50% 18%, rgba(19, 74, 154, .25), transparent 32%),
    linear-gradient(165deg, #05070d 0%, #060912 60%, #030409 100%);
  font-family: Impact, Haettenschweiler, "Arial Narrow Bold", "Arial Black", sans-serif;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

button { font: inherit; }

.speed-lines,
.speed-lines::before,
.speed-lines::after {
  position: fixed;
  inset: 0;
  pointer-events: none;
}

.speed-lines {
  z-index: -1;
  opacity: .6;
  background:
    linear-gradient(164deg, transparent 22%, rgba(238,23,32,.25) 22.3%, transparent 23%),
    linear-gradient(16deg, transparent 68%, rgba(12,112,220,.22) 68.3%, transparent 69%);
}

.speed-lines::before,
.speed-lines::after {
  content: "";
  background: repeating-conic-gradient(from 180deg at 50% 5%, transparent 0deg 7deg, rgba(255,255,255,.035) 7.2deg 7.6deg);
}

.speed-lines::after {
  opacity: .45;
  transform: rotate(180deg);
  background: repeating-conic-gradient(from 180deg at 50% 12%, transparent 0deg 12deg, rgba(239,23,32,.1) 12.3deg 12.8deg, transparent 13deg 18deg, rgba(13,121,213,.1) 18.2deg 18.7deg);
}

.game-shell {
  width: min(100%, 820px);
  height: 100vh;
  height: 100svh;
  height: 100dvh;
  max-height: 100vh;
  max-height: 100svh;
  max-height: 100dvh;
  margin: 0 auto;
  padding: max(clamp(5px, 1.1vh, 10px), env(safe-area-inset-top)) 14px max(clamp(6px, 1.25vh, 12px), env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: clamp(5px, 1vh, 10px);
}

.topbar {
  min-height: clamp(42px, 6vh, 58px);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.mini-logo {
  width: clamp(100px, 15vh, 132px);
  height: clamp(40px, 5.6vh, 54px);
  object-fit: contain;
  object-position: center;
}

.top-actions { display: flex; gap: 8px; }

.icon-button,
.close-button {
  width: 42px;
  height: 42px;
  border: 2px solid rgba(255,255,255,.65);
  border-radius: 50%;
  color: white;
  background: rgba(4,7,14,.7);
  cursor: pointer;
}

.icon-button:active,
.close-button:active { transform: scale(.94); }

.scoreboard {
  display: grid;
  grid-template-columns: 1fr 96px 1fr;
  align-items: center;
  min-height: clamp(70px, 9.8vh, 92px);
  padding: 6px 12px;
  border: 1px solid rgba(255,255,255,.2);
  border-radius: 18px;
  background: linear-gradient(90deg, rgba(239,23,32,.15), rgba(9,14,27,.88) 35% 65%, rgba(13,121,213,.18));
  box-shadow: inset 0 0 24px rgba(255,255,255,.035), 0 12px 35px rgba(0,0,0,.25);
}

.stat { display: flex; flex-direction: column; }
.high-stat { text-align: right; }
.stat-label { color: #aebbd2; font-family: Arial, sans-serif; font-size: .7rem; font-weight: 900; letter-spacing: .16em; }
.stat strong { font-size: clamp(1.6rem, 7vw, 2.6rem); line-height: 1; text-shadow: 0 3px 0 rgba(0,0,0,.45); }
.score-stat strong { color: #ff3640; }
.high-stat strong { color: #46a9ff; }

.timer-wrap {
  width: clamp(66px, 9.2vh, 88px);
  height: clamp(66px, 9.2vh, 88px);
  position: relative;
  display: grid;
  place-items: center;
}

.timer-ring { position: absolute; inset: 0; transform: rotate(-90deg); }
.timer-track,
.timer-progress { fill: none; stroke-width: 7; }
.timer-track { stroke: rgba(255,255,255,.12); }
.timer-progress {
  stroke: var(--gold);
  stroke-linecap: round;
  stroke-dasharray: var(--timer-progress);
  stroke-dashoffset: 0;
  transition: stroke-dashoffset .1s linear, stroke .25s;
}
.timer-wrap strong { z-index: 1; font-size: 2rem; }
.timer-wrap.is-urgent { animation: timer-urgency var(--urgency-speed, 1s) ease-in-out infinite; }

.dice-stage {
  padding: clamp(5px, .8vh, 8px) 18px clamp(6px, 1vh, 10px);
  text-align: center;
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(255,255,255,.065), rgba(255,255,255,.018));
}

.match-prompt { margin: 0 0 7px; color: #cfdbed; font-family: Arial, sans-serif; font-size: .72rem; font-weight: 900; letter-spacing: .18em; }
.dice-row { display: flex; align-items: center; justify-content: center; gap: clamp(12px, 5vw, 28px); }
.plus-sign { font-size: 2rem; color: rgba(255,255,255,.6); }

.die {
  width: clamp(54px, 10.5vh, 92px);
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border: 3px solid #fff;
  border-radius: 22%;
  background: linear-gradient(145deg, #fff, #d8e2ec);
  box-shadow: inset -7px -8px 13px rgba(0,0,0,.16), inset 5px 5px 8px rgba(255,255,255,.9), 0 9px 16px rgba(0,0,0,.4);
  transition: transform .16s ease;
}

.die.is-rolling { animation: dice-pop .28s ease; }
.die-dot {
  width: 56%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--dot-color, #ef1720);
  box-shadow: inset 3px 3px 6px rgba(255,255,255,.25), inset -4px -4px 7px rgba(0,0,0,.18);
}

.round-meta {
  margin-top: 7px;
  display: flex;
  justify-content: center;
  gap: 16px;
  font-family: Arial, sans-serif;
  font-size: .78rem;
  font-weight: 900;
  letter-spacing: .08em;
}
.multiplier { color: var(--gold); }

.play-area {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.tutorial-guide {
  position: absolute;
  z-index: 7;
  top: 4px;
  left: 50%;
  width: min(70%, 330px);
  padding: 8px 12px;
  transform: translateX(-50%);
  border: 2px solid #54c7ff;
  border-radius: 11px;
  color: #eaf8ff;
  background: rgba(5, 10, 22, .94);
  box-shadow: 0 7px 20px rgba(0,0,0,.45), 0 0 16px rgba(84,199,255,.24);
  text-align: center;
  pointer-events: none;
}
.tutorial-guide[hidden] { display: none; }
.tutorial-guide strong,
.tutorial-guide span { display: block; }
.tutorial-guide strong { color: var(--gold); font: 900 .66rem Arial, sans-serif; letter-spacing: .13em; }
.tutorial-guide span { margin-top: 3px; font: 800 .72rem/1.2 Arial, sans-serif; }
.tutorial-guide.is-complete { border-color: #4cff7b; box-shadow: 0 7px 20px rgba(0,0,0,.45), 0 0 18px rgba(76,255,123,.34); }

.star-man-surprise {
  position: absolute;
  z-index: 4;
  top: 0;
  left: 5%;
  width: 41px;
  aspect-ratio: 496 / 793;
  overflow: hidden;
  pointer-events: none;
  opacity: 0;
  transform: translateY(2px) scale(.72);
  transform-origin: center top;
  filter: drop-shadow(0 7px 7px rgba(0,0,0,.42));
}

.star-man-surprise img {
  display: block;
  width: 400%;
  max-width: none;
  height: 100%;
  object-fit: fill;
  transform: translateX(0);
}

.star-man-surprise.is-visible {
  animation: star-man-visit 2.1s ease-in-out both;
}

.star-man-surprise.is-visible img {
  animation: star-man-wave 1.25s steps(3, end) .28s 1 both;
}

@keyframes star-man-visit {
  0%, 100% { opacity: 0; transform: translateY(2px) scale(.72); }
  14%, 78% { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes star-man-wave {
  from { transform: translateX(0); }
  to { transform: translateX(-75%); }
}

@media (prefers-reduced-motion: reduce) {
  .star-man-surprise.is-visible { animation: star-man-visit 2.1s ease both; }
  .star-man-surprise.is-visible img { animation: none; }
}

.wild-reserve {
  position: relative;
  flex: 0 0 66px;
  min-height: 66px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 9px;
  padding: 2px 3px 6px;
  overflow: hidden;
}

.wild-reserve-label {
  color: #aebbd2;
  font: 900 .62rem Arial, sans-serif;
  letter-spacing: .12em;
}

.wild-stack {
  position: relative;
  width: 53px;
  height: 58px;
  flex: 0 0 53px;
  padding: 0;
  border: 1px solid rgba(255,255,255,.45);
  border-radius: 9px;
  color: white;
  background: linear-gradient(135deg, #111722, #05070d);
  box-shadow: 4px 4px 0 rgba(255,255,255,.12), 8px 8px 0 rgba(255,255,255,.06);
  cursor: pointer;
}

.wild-stack img {
  position: absolute;
  left: 4px;
  top: 4px;
  width: 43px;
  height: 50px;
  object-fit: cover;
  border-radius: 5px;
}

.wild-count { display: block; color: var(--gold); font-size: 1.5rem; line-height: 1; }
.wild-stack:hover { filter: brightness(1.14); transform: translateY(-1px); }
.wild-stack:active { transform: scale(.96); }
.wild-stack:disabled { opacity: .3; filter: grayscale(1); cursor: not-allowed; box-shadow: none; }

.card-grid {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  align-content: center;
  gap: clamp(5px, 1.4vw, 10px);
  min-height: 0;
  overflow: hidden;
  padding: 4px 0;
}

.card-grid[data-count="6"] { grid-template-columns: repeat(3, minmax(0, 1fr)); grid-template-rows: repeat(2, minmax(0, 1fr)); }
.card-grid[data-count="9"] { grid-template-columns: repeat(3, minmax(0, 1fr)); grid-template-rows: repeat(3, minmax(0, 1fr)); }
.card-grid[data-count="12"] { grid-template-columns: repeat(4, minmax(0, 1fr)); grid-template-rows: repeat(3, minmax(0, 1fr)); }
.card-grid[data-count="15"] { grid-template-columns: repeat(5, minmax(0, 1fr)); grid-template-rows: repeat(3, minmax(0, 1fr)); }

.card-button {
  position: relative;
  min-width: 0;
  min-height: 0;
  height: 100%;
  padding: 0;
  border: 0;
  border-radius: 8px;
  overflow: hidden;
  background: var(--card-background, #111);
  box-shadow: 0 5px 9px rgba(0,0,0,.42);
  cursor: pointer;
  transition: transform .11s ease, border-color .11s ease, filter .11s ease;
}

.card-button img { width: 100%; height: 100%; display: block; object-fit: contain; }
.card-grid.is-loading-cards .card-button { visibility: hidden; }
.card-button:hover { transform: translateY(-2px); filter: brightness(1.08); }
.card-button:active { transform: scale(.96); }
.card-button.is-correct { border-color: #4cff7b; animation: correct-pulse .34s ease; }
.card-button.is-wrong { border-color: #ff2935; animation: wrong-shake .28s ease; filter: saturate(.25); }
.card-button.is-selected { border-color: #71d8ff; filter: brightness(1.16); }
.card-button.is-tutorial-target {
  z-index: 3;
  box-shadow: 0 0 0 4px var(--gold), 0 0 22px 8px rgba(255,213,46,.72), 0 5px 9px rgba(0,0,0,.42);
  animation: tutorial-card-glow .58s ease-in-out infinite alternate;
}
.card-button.is-tutorial-target::after {
  content: "TAP ME";
  position: absolute;
  left: 50%;
  top: 6px;
  transform: translateX(-50%) skew(-7deg);
  padding: 3px 7px;
  border: 2px solid white;
  border-radius: 5px;
  color: #111728;
  background: var(--gold);
  box-shadow: 0 3px 0 rgba(0,0,0,.36);
  font: 900 .56rem Arial, sans-serif;
  letter-spacing: .08em;
  white-space: nowrap;
}

.card-grid.is-shuffling .card-button {
  pointer-events: none;
  animation: hyperspace-shuffle .48s cubic-bezier(.2,.8,.2,1) both;
}
.card-grid.is-shuffling .card-button:nth-child(2n) { animation-direction: reverse; }
.card-grid.is-shuffling .card-button:nth-child(3n) { animation-delay: .035s; }

.feedback {
  position: fixed;
  z-index: 8;
  left: 50%;
  top: 48%;
  transform: translate(-50%, -50%) scale(.6) rotate(-5deg);
  opacity: 0;
  pointer-events: none;
  color: white;
  font-size: clamp(3.4rem, 18vw, 8rem);
  font-style: italic;
  text-shadow: 5px 6px 0 #081429, 8px 9px 0 var(--red);
}
.feedback.show { animation: bop-feedback .48s ease forwards; }
.feedback.wrong { color: #ff303b; text-shadow: 4px 5px 0 #06070a; }

.game-footer {
  min-height: clamp(22px, 3vh, 30px);
  display: flex;
  justify-content: center;
  gap: 6px;
  color: #a7b4c9;
  font-family: Arial, sans-serif;
  font-size: clamp(.62rem, 2.5vw, .8rem);
  font-weight: 900;
  letter-spacing: .08em;
}
.game-footer strong { color: white; }

.overlay {
  position: fixed;
  z-index: 20;
  inset: 0;
  display: none;
  place-items: center;
  padding: clamp(6px, 2vh, 20px);
  background: rgba(1,3,8,.82);
  backdrop-filter: blur(9px);
  overflow: hidden;
}
.overlay.is-visible { display: grid; animation: overlay-in .22s ease; }

.ad-overlay {
  z-index: 35;
  padding: 0;
  background: #030715;
  backdrop-filter: none;
}

.ad-overlay.is-visible { animation: none; }

.ad-overlay img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  display: block;
  object-fit: contain;
  object-position: center;
}

.overlay-card {
  width: min(100%, 520px);
  max-height: calc(100dvh - 12px);
  padding: clamp(22px, 6vw, 38px);
  position: relative;
  text-align: center;
  border: 2px solid rgba(255,255,255,.22);
  border-radius: 26px;
  background:
    linear-gradient(150deg, rgba(239,23,32,.15), transparent 35%),
    linear-gradient(330deg, rgba(13,121,213,.2), transparent 40%),
    #080d19;
  box-shadow: 0 25px 80px rgba(0,0,0,.6), inset 0 0 36px rgba(255,255,255,.035);
  overflow: hidden;
}

.hero-logo { width: min(86%, 350px); height: 180px; object-fit: contain; mix-blend-mode: screen; }
.arcade-badge { width: max-content; margin: -17px auto 18px; padding: 5px 18px; transform: skew(-8deg); color: white; border: 2px solid white; background: var(--red); font-size: 1.2rem; letter-spacing: .2em; box-shadow: 5px 5px 0 #0877cc; }
.overlay-card h1 { margin: 0 0 12px; font-size: clamp(2rem, 9vw, 3.5rem); font-style: italic; line-height: .95; }
.overlay-card h2 { margin: 4px 0 18px; font-size: clamp(1.8rem, 8vw, 2.8rem); }
.overlay-card p { margin: 10px auto 20px; max-width: 430px; color: #d3dbea; font: 600 1rem/1.45 Arial, sans-serif; }
.quick-rules { display: flex; justify-content: center; flex-wrap: wrap; gap: 7px; margin: 0 0 20px; }
.quick-rules span { padding: 6px 9px; border-radius: 6px; color: #dbe8ff; background: rgba(255,255,255,.08); font: 800 .68rem Arial, sans-serif; letter-spacing: .06em; }
.player-name-label { display: block; margin: 12px 0 6px; color: #9eadc3; font: 900 .7rem Arial, sans-serif; letter-spacing: .13em; }
.player-name-input { width: min(100%, 340px); min-height: 45px; padding: 8px 13px; border: 2px solid rgba(84,199,255,.55); border-radius: 10px; color: white; background: rgba(255,255,255,.08); text-align: center; font: 900 1rem Arial, sans-serif; outline: none; }
.player-name-input:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(255,213,46,.12); }
.difficulty-picker { width: min(100%, 390px); margin: 13px auto; padding: 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; border: 0; }
.difficulty-picker legend { width: 100%; margin-bottom: 6px; color: #9eadc3; font: 900 .66rem Arial, sans-serif; letter-spacing: .12em; }
.difficulty-picker input { position: absolute; opacity: 0; }
.difficulty-picker span { min-height: 55px; padding: 8px 4px; display: grid; place-content: center; border: 2px solid rgba(255,255,255,.18); border-radius: 9px; background: rgba(255,255,255,.055); cursor: pointer; }
.difficulty-picker strong, .difficulty-picker small { display: block; }
.difficulty-picker strong { font: 900 .72rem Arial, sans-serif; }
.difficulty-picker small { margin-top: 4px; color: #9eadc3; font: 800 .56rem Arial, sans-serif; }
.difficulty-picker input:checked + span { border-color: var(--gold); color: var(--gold); background: rgba(255,213,46,.12); box-shadow: 0 0 14px rgba(255,213,46,.14); }
.countdown-overlay { z-index: 30; background: rgba(1,3,8,.96); backdrop-filter: none; }
.countdown-overlay.is-visible { animation: none; }
.countdown-overlay > strong {
  display: inline-block;
  max-width: calc(100vw - 20px);
  padding: .14em .26em .2em .18em;
  overflow: visible;
  color: white;
  font-size: clamp(3.75rem, 18vw, 8.25rem);
  font-style: italic;
  line-height: .92;
  white-space: nowrap;
  text-shadow: 6px 7px 0 var(--red), -3px -3px 0 #0877cc;
  transform: translateZ(0);
  transform-origin: center;
  will-change: transform, opacity;
}
.countdown-overlay > strong.is-popping { animation: start-pop .55s ease both; }

.bonus-game-overlay { z-index: 40; padding: 0; background: #030715; backdrop-filter: none; }
.bonus-game-overlay.is-visible { animation: none; }
.bonus-game-overlay iframe { width: 100%; height: 100%; border: 0; background: #030715; }

.primary-button {
  width: min(100%, 340px);
  min-height: 58px;
  padding: 12px 20px;
  border: 3px solid white;
  border-radius: 12px;
  color: white;
  background: linear-gradient(180deg, #ff3038, #d80e17);
  box-shadow: 0 7px 0 #87080e, 0 14px 24px rgba(0,0,0,.3);
  font-size: 1.35rem;
  letter-spacing: .06em;
  cursor: pointer;
}
.primary-button:active { transform: translateY(5px); box-shadow: 0 2px 0 #87080e; }
.text-button { margin-top: 20px; padding: 7px; border: 0; color: #78bfff; background: transparent; font: 900 .82rem Arial, sans-serif; letter-spacing: .12em; cursor: pointer; }
.start-card > .primary-button,
.start-card > .text-button {
  width: min(100%, 340px);
  min-height: 52px;
  display: block;
  margin-left: auto;
  margin-right: auto;
}
.start-card > .text-button {
  height: 56px;
  margin-top: 14px;
  padding: 10px 18px;
  border: 2px solid #54c7ff;
  border-radius: 12px;
  color: #dff7ff;
  background: rgba(13,121,213,.18);
  font-size: .88rem;
}
.start-card > .text-button:active { transform: translateY(2px); }
.start-legal { margin-top: 12px; display: grid; justify-items: center; gap: 4px; color: #8795aa; font: 700 .58rem/1.25 Arial, sans-serif; letter-spacing: .035em; }
.legal-link { padding: 5px 8px; border: 0; color: #78bfff; background: transparent; font: 900 .64rem Arial, sans-serif; letter-spacing: .1em; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
.legal-link:focus-visible, .legal-site-link:focus-visible { outline: 2px solid var(--gold); outline-offset: 3px; }
.close-button { position: absolute; top: 14px; right: 14px; font: 400 2rem/1 Arial, sans-serif; }

.rules-card { text-align: left; }
.rules-card h2 { text-align: center; color: var(--gold); }
.rules-card ol { margin: 0 0 18px; padding-left: 25px; color: #e4eaf3; font: 600 .95rem/1.5 Arial, sans-serif; }
.rules-card li { margin-bottom: 8px; padding-left: 4px; }
.wild-rule { display: grid; grid-template-columns: 72px 1fr; align-items: center; gap: 14px; margin: 15px 0 23px; padding: 12px; border-radius: 14px; background: rgba(255,255,255,.075); }
.wild-rule img { width: 72px; border-radius: 8px; }
.wild-rule p { margin: 0; font-size: .88rem; }
.rules-card .primary-button { display: block; margin: auto; }

.small-card { max-width: 410px; }
.pause-audio-controls { width: min(100%, 340px); margin: 0 auto 18px; display: grid; gap: 9px; }
.pause-audio-controls .sound-toggle { width: 100%; margin: 0; }
.sound-toggle {
  width: min(100%, 340px);
  min-height: 50px;
  margin: 0 auto 18px;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border: 2px solid #54c7ff;
  border-radius: 12px;
  color: #dff7ff;
  background: rgba(13,121,213,.18);
  font: 900 .82rem Arial, sans-serif;
  letter-spacing: .09em;
  cursor: pointer;
}
.sound-toggle[aria-pressed="false"] { border-color: #718096; color: #aeb8c7; background: rgba(255,255,255,.06); }
.sound-toggle-icon { color: #54c7ff; text-shadow: 0 0 10px #54c7ff; }
.sound-toggle[aria-pressed="false"] .sound-toggle-icon { color: #7c8798; text-shadow: none; }
.pause-actions { width: min(100%, 340px); margin: 17px auto 0; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.pause-legal-button { margin-top: 14px; }
.secondary-button { min-height: 46px; padding: 9px 10px; border: 2px solid #54c7ff; border-radius: 10px; color: #dff7ff; background: rgba(13,121,213,.16); font: 900 .72rem Arial, sans-serif; letter-spacing: .05em; cursor: pointer; }
.secondary-button:active { transform: scale(.96); }
.danger-button { border-color: #ff4c55; color: #ffd9dc; background: rgba(239,23,32,.14); }
.legal-card { text-align: left; }
.legal-card h2 { text-align: center; color: var(--gold); }
.legal-content { max-height: min(58dvh, 510px); margin: 0 0 18px; padding: 0 8px 0 2px; overflow-y: auto; scrollbar-color: #2878bc rgba(255,255,255,.06); }
.legal-content section { margin: 0 0 14px; padding: 11px 13px; border-radius: 12px; background: rgba(255,255,255,.055); }
.legal-content h3 { margin: 0 0 6px; color: #8fd7ff; font: 900 .72rem Arial, sans-serif; letter-spacing: .12em; }
.legal-content p { margin: 0; max-width: none; color: #d3dbea; font: 600 .82rem/1.42 Arial, sans-serif; }
.legal-site-link { display: block; width: max-content; margin: 4px auto 8px; color: var(--gold); font: 900 .76rem Arial, sans-serif; letter-spacing: .08em; }
.legal-card > .primary-button { display: block; margin: auto; }
.result-kicker { margin: 0 !important; color: #ff2b35 !important; font-size: 1.5rem !important; letter-spacing: .2em; }
.result-card { display: flex; flex-direction: column; }
.result-card-scroll { min-height: 0; padding: 2px 3px; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.result-actions { flex: 0 0 auto; padding-top: 10px; padding-bottom: max(2px, env(safe-area-inset-bottom)); }
.result-native-actions { width: min(100%, 340px); margin: 0 auto 10px; display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 8px; }
.result-native-actions .secondary-button { width: 100%; }
.result-card h2 { color: var(--gold); line-height: 1; }
.final-score { margin: 18px auto; display: flex; flex-direction: column; }
.final-score span { color: #9eadc3; font: 900 .72rem Arial, sans-serif; letter-spacing: .16em; }
.final-score strong { color: white; font-size: clamp(3.3rem, 16vw, 5.7rem); line-height: 1; text-shadow: 4px 5px 0 var(--red); }
.result-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 18px 0 22px; }
.result-stats div { min-width: 0; padding: 11px 4px; border-radius: 10px; background: rgba(255,255,255,.07); }
.result-stats strong, .result-stats span { display: block; }
.result-stats strong { font-size: 1.35rem; }
.result-stats span { margin-top: 4px; color: #9eadc3; font: 800 .58rem Arial, sans-serif; letter-spacing: .04em; }
.high-score-message { min-height: 24px; color: var(--gold) !important; font-weight: 900 !important; }
.score-breakdown, .achievements { width: min(100%, 340px); margin: 0 auto 13px; padding: 10px 14px; border-radius: 12px; background: rgba(255,255,255,.055); }
.score-breakdown h3, .achievements h3 { margin: 0 0 7px; color: #9eadc3; font: 900 .66rem Arial, sans-serif; letter-spacing: .12em; }
.score-breakdown div { display: flex; justify-content: space-between; padding: 4px 3px; color: #cad5e6; font: 800 .78rem Arial, sans-serif; }
.score-breakdown strong { color: white; }
.achievement-list { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
.achievement-badge { padding: 6px 8px; border: 1px solid #586579; border-radius: 999px; color: #78869a; background: rgba(0,0,0,.2); font: 900 .57rem Arial, sans-serif; }
.achievement-badge.is-earned { border-color: var(--gold); color: #171000; background: var(--gold); box-shadow: 0 0 13px rgba(255,213,46,.28); }
.top-scores { width: min(100%, 340px); margin: 0 auto 22px; padding: 12px 16px; border: 1px solid rgba(255,213,46,.35); border-radius: 13px; background: rgba(255,213,46,.06); }
.top-scores h3 { margin: 0 0 8px; color: var(--gold); font: 900 .75rem Arial, sans-serif; letter-spacing: .14em; }
.top-scores ol { margin: 0; padding: 0; list-style: none; }
.top-scores li { display: flex; align-items: center; justify-content: space-between; padding: 5px 8px; border-top: 1px solid rgba(255,255,255,.08); }
.top-scores li:first-child { border-top: 0; }
.top-scores li span { color: #9eadc3; font: 900 .75rem Arial, sans-serif; }
.top-scores li .top-score-player { flex: 1; padding: 0 8px; overflow: hidden; color: #dbe4f2; text-align: left; text-overflow: ellipsis; white-space: nowrap; }
.top-scores li strong { color: white; font-size: 1.05rem; }
.buy-game-button { display: block; margin: 0 auto 10px; color: #111; text-decoration: none; background: var(--gold); box-shadow: 0 0 18px rgba(255,213,46,.38); }
.result-actions .primary-button { display: block; margin-left: auto; margin-right: auto; }
.buy-game-button:hover { filter: brightness(1.08); }

@keyframes dice-pop { 50% { transform: scale(.82) rotate(12deg); } }
@keyframes timer-urgency { 50% { transform: scale(1.07); filter: drop-shadow(0 0 10px rgba(239,23,32,.8)); } }
@keyframes correct-pulse { 45% { transform: scale(1.08); filter: brightness(1.2); } }
@keyframes tutorial-card-glow { from { transform: scale(.96); filter: brightness(1.03); } to { transform: scale(1.035); filter: brightness(1.2); } }
@keyframes wrong-shake { 25% { transform: translateX(-7px) rotate(-2deg); } 75% { transform: translateX(7px) rotate(2deg); } }
@keyframes hyperspace-shuffle {
  0% { transform: translate(0, 0) rotate(0) scale(1); opacity: 1; }
  38% { transform: translate(var(--shuffle-x, 12px), -12px) rotate(7deg) scale(.82); opacity: .55; }
  70% { transform: translate(var(--shuffle-x-back, -12px), 7px) rotate(-5deg) scale(.9); opacity: .75; }
  100% { transform: translate(0, 0) rotate(0) scale(1); opacity: 1; }
}
@keyframes bop-feedback { 0% { opacity: 0; transform: translate(-50%, -50%) scale(.5) rotate(-8deg); } 35% { opacity: 1; transform: translate(-50%, -50%) scale(1.12) rotate(-5deg); } 100% { opacity: 0; transform: translate(-50%, -60%) scale(1.05) rotate(-3deg); } }
@keyframes overlay-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes start-pop { 0% { opacity: 0; transform: scale(.45) rotate(-8deg); } 45% { opacity: 1; transform: scale(1.12) rotate(-3deg); } 100% { opacity: 1; transform: scale(1); } }

@media (max-height: 860px) {
  .game-shell { gap: 5px; padding-top: max(5px, env(safe-area-inset-top)); padding-bottom: max(6px, env(safe-area-inset-bottom)); }
  .topbar { min-height: 42px; }
  .mini-logo { width: 100px; height: 40px; }
  .icon-button { width: 36px; height: 36px; }
  .scoreboard { min-height: 70px; grid-template-columns: 1fr 70px 1fr; }
  .timer-wrap { width: 64px; height: 64px; }
  .timer-wrap strong { font-size: 1.6rem; }
  .dice-stage { padding: 4px 12px 5px; }
  .match-prompt { margin-bottom: 3px; }
  .die { width: 56px; }
  .round-meta { margin-top: 3px; }
  .wild-reserve { flex-basis: 66px; min-height: 66px; }
  .star-man-surprise { width: 41px; }
  .game-footer { min-height: 21px; font-size: .62rem; }

  .overlay-card { padding: 14px 22px; border-radius: 20px; }
  .hero-logo { width: min(70%, 250px); height: 92px; }
  .arcade-badge { margin: -11px auto 8px; padding: 3px 14px; font-size: .9rem; }
  .overlay-card h1 { margin-bottom: 6px; font-size: clamp(1.55rem, 6vh, 2.5rem); }
  .overlay-card h2 { margin: 2px 0 7px; font-size: clamp(1.45rem, 5vh, 2.1rem); }
  .overlay-card p { margin: 5px auto 8px; font-size: .84rem; line-height: 1.25; }
  .player-name-label { margin: 5px 0 4px; }
  .player-name-input { min-height: 36px; padding: 5px 10px; }
  .difficulty-picker { margin: 7px auto; gap: 5px; }
  .difficulty-picker legend { margin-bottom: 4px; }
  .difficulty-picker span { min-height: 43px; padding: 5px 3px; }
  .quick-rules { gap: 5px; margin-bottom: 8px; }
  .quick-rules span { padding: 4px 7px; font-size: .6rem; }
  .primary-button { min-height: 46px; padding: 8px 16px; font-size: 1.05rem; }
  .text-button { margin-top: 7px; padding: 4px; }
  .start-card > .primary-button,
  .start-card > .text-button { min-height: 44px; height: 46px; }
  .start-card > .text-button { margin-top: 7px; padding: 7px 14px; }
  .start-legal { margin-top: 5px; font-size: .52rem; }
  .legal-link { padding: 3px 6px; font-size: .58rem; }
  .rules-card ol { margin-bottom: 7px; font-size: .78rem; line-height: 1.25; }
  .rules-card li { margin-bottom: 3px; }
  .wild-rule { grid-template-columns: 52px 1fr; gap: 9px; margin: 6px 0 8px; padding: 7px; }
  .wild-rule img { width: 52px; }
  .wild-rule p { font-size: .76rem; }
  .sound-toggle { min-height: 42px; margin-bottom: 9px; }
  .pause-actions { margin-top: 9px; }
  .secondary-button { min-height: 40px; }
  .pause-legal-button { margin-top: 7px; }
  .legal-content { max-height: 62dvh; margin-bottom: 8px; }
  .legal-content section { margin-bottom: 7px; padding: 7px 9px; }
  .legal-content p { font-size: .72rem; line-height: 1.3; }
  .result-kicker { font-size: 1.1rem !important; }
  .final-score { margin: 5px auto; }
  .final-score strong { font-size: clamp(2.6rem, 10vh, 4rem); }
  .result-stats { margin: 6px 0 8px; }
  .result-stats div { padding: 6px 4px; }
  .score-breakdown, .achievements { margin-bottom: 6px; padding: 6px 10px; }
  .score-breakdown div { padding: 2px 3px; }
  .achievement-badge { padding: 4px 7px; }
  .high-score-message { min-height: 18px; }
  .top-scores { margin-bottom: 7px; padding: 6px 12px; }
  .top-scores li { padding: 3px 7px; }
}

@media (max-width: 520px) {
  .game-shell { gap: 7px; }
  .topbar { min-height: 48px; }
  .mini-logo { width: 112px; height: 43px; }
  .icon-button { width: 38px; height: 38px; }
  .scoreboard { min-height: 81px; grid-template-columns: 1fr 82px 1fr; }
  .timer-wrap { width: 76px; height: 76px; }
  .dice-stage { padding: 7px 12px 8px; }
  .wild-reserve { flex-basis: 66px; min-height: 66px; }
  .wild-stack { width: 45px; height: 50px; flex-basis: 45px; padding: 0; }
  .wild-stack img { width: 37px; height: 42px; }
  .wild-count { font-size: 1.25rem; }
  .card-grid { min-height: 0; }
  .card-button { border-radius: 6px; }

  html.native-ios .game-shell {
    padding-top: max(54px, calc(env(safe-area-inset-top) + 6px));
  }
  html.native-ios .topbar {
    flex: 0 0 48px;
    position: relative;
    z-index: 8;
  }
  html.native-ios #gameOverOverlay {
    padding-top: max(54px, calc(env(safe-area-inset-top) + 6px));
    padding-bottom: max(8px, env(safe-area-inset-bottom));
  }
  html.native-ios #gameOverOverlay .result-card {
    max-height: calc(100dvh - 62px);
  }
}

@media (max-height: 700px) and (orientation: landscape) {
  .game-shell { width: min(100%, 980px); height: 100svh; min-height: 0; display: grid; grid-template-columns: 270px 1fr; grid-template-rows: auto auto 1fr auto; }
  .topbar, .scoreboard, .dice-stage, .game-footer { grid-column: 1; }
  .card-grid { grid-column: 2; grid-row: 1 / 5; }
  .topbar { min-height: 42px; }
  .scoreboard { grid-template-columns: 1fr 74px 1fr; }
  .timer-wrap { width: 70px; height: 70px; }
  .dice-row { gap: 12px; }
  .die { width: 68px; }
}

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