/* ============================================================================
 * 5by5 Gaming — European Roulette · UI stylesheet
 * ========================================================================== */

:root {
  --gold: #c9a24b;
  --gold-bright: #e8cd8a;
  --cream: #efe6cd;
  --panel: rgba(10, 12, 14, 0.62);
  --panel-border: rgba(201, 162, 75, 0.28);
  --red: #b3252e;
  --serif: Georgia, 'Times New Roman', serif;
  --sans: 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
  --top-hud-height: 70px;
  --bottom-hud-height: 118px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  width: 100%; height: 100%; min-height: 100dvh;
  overflow: hidden;
  background: #070706;
  font-family: var(--sans);
  color: var(--cream);
  user-select: none;
  -webkit-user-select: none;
}

/* the WebGL scene owns only the band between the header and the dock */
#scene-container {
  position: fixed;
  left: var(--safe-left); right: var(--safe-right);
  top: calc(var(--top-hud-height) + var(--safe-top));
  bottom: calc(var(--bottom-hud-height) + var(--safe-bottom));
  overflow: hidden;
  background: #090908;
}
#scene-container canvas { display: block; width: 100%; height: 100%; }

/* Real element (not ::after) so restore transitions are announced to AT. */
.webgl-status {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
  color: var(--gold-bright);
  background: #070706;
  font-family: var(--serif);
  font-size: 14px;
  letter-spacing: 0.3em;
  text-align: center;
  padding: 24px;
}
body.webgl-recovering .webgl-status,
body.webgl-failed .webgl-status {
  display: flex;
}
body.webgl-recovering .webgl-status {
  pointer-events: none;
}
body.webgl-failed .webgl-status {
  cursor: pointer;
  pointer-events: auto;
}

/* ---------------- cinematic dressing ---------------- */

.vignette {
  position: fixed; pointer-events: none; z-index: 3;
  inset:
    calc(var(--top-hud-height) + var(--safe-top))
    var(--safe-right)
    calc(var(--bottom-hud-height) + var(--safe-bottom))
    var(--safe-left);
  background: radial-gradient(ellipse 78% 70% at 50% 46%,
    rgba(0,0,0,0) 0%, rgba(0,0,0,0.06) 66%, rgba(0,0,0,0.26) 100%);
}

.letterbox {
  position: fixed; left: 0; right: 0; height: 0; background: #000;
  z-index: 4; transition: height 1.1s cubic-bezier(.6,0,.3,1); pointer-events: none;
}
.letterbox-top { top: 0; }
.letterbox-bottom { bottom: 0; }
body.cinema .letterbox { height: 6.5vh; }
body.cinema .hud-top { opacity: 0.60; }
body.cinema .hud-bottom { opacity: 0.78; }

/* ---------------- HUD chrome ---------------- */

.hud-top {
  position: fixed; inset: 0 0 auto 0; z-index: 10;
  height: calc(var(--top-hud-height) + var(--safe-top));
  display: flex; justify-content: space-between; align-items: center;
  padding: var(--safe-top) max(24px, var(--safe-right)) 0 max(24px, var(--safe-left));
  pointer-events: none;
  background:
    linear-gradient(180deg, rgba(13, 13, 12, 0.99), rgba(8, 8, 8, 0.97)),
    radial-gradient(circle at 50% 0%, rgba(120, 82, 39, 0.10), transparent 60%);
  border-bottom: 1px solid rgba(201, 162, 75, 0.16);
  transition: opacity 0.8s ease;
}
.hud-top > * { pointer-events: auto; }

.brand-name {
  font-family: var(--serif); font-size: 19px; letter-spacing: 0.42em;
  color: var(--gold); text-shadow: 0 1px 12px rgba(0,0,0,0.8);
}
.brand-sub {
  font-size: 10px; letter-spacing: 0.34em; color: rgba(239,230,205,0.55);
  margin-top: 5px;
}

.hud-top-right { display: flex; align-items: flex-start; gap: 16px; }

.mode-toggle {
  height: 40px;
  padding: 0 9px 0 11px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: rgba(239,230,205,0.72);
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  cursor: pointer;
  backdrop-filter: blur(8px);
  transition: border-color 0.2s ease, color 0.2s ease, background 0.2s ease;
}
.mode-toggle:hover { border-color: var(--gold); color: var(--gold-bright); }
.mode-toggle-label {
  font-family: var(--serif);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.14em;
}
.mode-toggle-track {
  position: relative;
  width: 30px;
  height: 17px;
  border-radius: 999px;
  background: rgba(239,230,205,0.14);
  border: 1px solid rgba(239,230,205,0.24);
  transition: background 0.2s ease, border-color 0.2s ease;
}
.mode-toggle-knob {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: rgba(239,230,205,0.72);
  box-shadow: 0 1px 4px rgba(0,0,0,0.6);
  transition: transform 0.2s ease, background 0.2s ease;
}
.mode-toggle.active {
  color: var(--gold-bright);
  border-color: rgba(232,205,138,0.65);
  background: rgba(50,39,18,0.82);
}
.mode-toggle.active .mode-toggle-track {
  background: rgba(201,162,75,0.42);
  border-color: var(--gold);
}
.mode-toggle.active .mode-toggle-knob {
  transform: translateX(13px);
  background: #fff1c8;
}
.mode-toggle:disabled { opacity: 0.45; cursor: default; }

.top-btn-wrap { position: relative; display: flex; flex-direction: column; align-items: center; gap: 5px; }
.top-btn-label { font-size: 8px; letter-spacing: 0.3em; color: rgba(239,230,205,0.55); text-indent: 0.3em; }

.round-btn {
  background: var(--panel); border: 1px solid var(--panel-border);
  color: var(--cream); width: 40px; height: 40px; border-radius: 50%;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(8px); transition: all 0.2s ease; padding: 0;
}
.round-btn:hover { border-color: var(--gold); color: var(--gold-bright); }

.history-badge {
  width: 30px; height: 30px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700; color: #f4efdf;
  background: rgba(255,255,255,0.06);
}
.history-badge.red { background: radial-gradient(circle at 35% 30%, #d3434b, #91161e); }
.history-badge.black { background: radial-gradient(circle at 35% 30%, #3a3d45, #101114); }
.history-badge.green { background: radial-gradient(circle at 35% 30%, #2e9a5d, #0a5e30); }

.history-panel {
  position: absolute; top: 48px; right: 0; z-index: 20;
  display: none; grid-template-columns: repeat(6, 28px); gap: 6px;
  background: var(--panel); border: 1px solid var(--panel-border);
  border-radius: 12px; padding: 10px; backdrop-filter: blur(10px);
  box-shadow: 0 12px 40px rgba(0,0,0,0.5);
}
.history-panel.open { display: grid; }
.history-panel:empty { display: none !important; }
.history-panel .h-num {
  width: 28px; height: 28px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 600; color: #f4efdf;
  border: 1px solid rgba(255,255,255,0.22);
  box-shadow: inset 0 -2px 4px rgba(0,0,0,0.4);
}
.history-panel .h-num.red { background: radial-gradient(circle at 35% 30%, #cf4048, #8d161e); }
.history-panel .h-num.black { background: radial-gradient(circle at 35% 30%, #3a3d45, #101114); }
.history-panel .h-num.green { background: radial-gradient(circle at 35% 30%, #2e9a5d, #0a5e30); }
.history-panel .h-num:first-child { outline: 2px solid rgba(232,205,138,0.7); outline-offset: 1px; }

/* ---------------- banner & toast ---------------- */

.banner {
  position: fixed; top: 15%; left: 50%; transform: translateX(-50%) scale(0.94);
  z-index: 9; text-align: center; pointer-events: none;
  padding: 26px 70px;
  background: radial-gradient(closest-side, rgba(2,3,4,0.5) 0%, rgba(2,3,4,0.24) 55%, rgba(2,3,4,0) 96%);
  opacity: 0; transition: opacity 0.55s ease, transform 0.55s ease;
}
.banner.show { opacity: 1; transform: translateX(-50%) scale(1); }
.banner-title {
  font-family: var(--serif); font-size: clamp(30px, 4.6vw, 58px);
  letter-spacing: 0.16em; color: var(--cream);
  text-shadow: 0 2px 24px rgba(0,0,0,0.85), 0 0 60px rgba(201,162,75,0.25);
}
.banner-title .num-red { color: #e05560; }
.banner-title .num-black { color: #cfd4e0; }
.banner-title .num-green { color: #4fc98a; }
.banner-sub {
  margin-top: 10px; font-size: clamp(13px, 1.5vw, 19px);
  letter-spacing: 0.32em; color: rgba(239,230,205,0.8);
}
.banner-sub.win { color: var(--gold-bright); text-shadow: 0 0 26px rgba(232,205,138,0.5); }

/* compact status pill — betting phase, never hides the board */
.banner.status {
  top: calc(var(--top-hud-height) + 16px);
  padding: 10px 26px;
  background: rgba(8, 9, 8, 0.72);
  border: 1px solid rgba(201, 162, 75, 0.20);
  border-radius: 999px;
}
.banner.status .banner-title { font-size: 18px; letter-spacing: 0.28em; }
.banner.status .banner-sub { display: none; }

/* medium treatment — the spin call during the camera move */
.banner.medium { top: 12%; }
.banner.medium .banner-title { font-size: clamp(24px, 3.2vw, 40px); }
.banner.medium .banner-sub { font-size: clamp(11px, 1.2vw, 15px); }

/* Result card: warm, high-contrast backing so outcome copy cannot disappear
 * against either green felt, dark wood or the spinning number band. */
.banner.result {
  width: min(560px, calc(100vw - 32px));
  padding: 18px 28px 20px;
  background: linear-gradient(
    180deg,
    rgba(249, 245, 233, 0.96),
    rgba(229, 218, 190, 0.94)
  );
  border: 1px solid rgba(201, 162, 75, 0.78);
  border-radius: 16px;
  box-shadow:
    0 14px 50px rgba(0,0,0,0.52),
    inset 0 1px 0 rgba(255,255,255,0.72);
}
.banner.result .banner-title {
  color: #19150f;
  font-size: clamp(27px, 4vw, 48px);
  text-shadow: none;
}
.banner.result .banner-title .num-red { color: #a91f29; }
.banner.result .banner-title .num-black { color: #17191d; }
.banner.result .banner-title .num-green { color: #08713d; }
.banner.result .banner-sub {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  color: #292116;
  font-family: var(--sans);
  letter-spacing: 0.14em;
  text-shadow: none;
}
.banner.result .banner-sub.win { color: #24532f; text-shadow: none; }
.result-net { font-size: clamp(14px, 1.7vw, 19px); font-weight: 700; }
.result-return { font-size: clamp(11px, 1.25vw, 14px); color: #6a5735; }

.toast {
  position: fixed; bottom: calc(var(--bottom-hud-height) + var(--safe-bottom) + 16px); left: 50%; transform: translate(-50%, 12px);
  z-index: 11; background: rgba(20, 8, 8, 0.85); color: #f0d9d0;
  border: 1px solid rgba(220, 120, 90, 0.4); border-radius: 8px;
  padding: 10px 20px; font-size: 13px; letter-spacing: 0.08em;
  opacity: 0; transition: all 0.3s ease; pointer-events: none;
  backdrop-filter: blur(6px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.info { background: rgba(10, 14, 12, 0.85); color: var(--cream); border-color: var(--panel-border); }

.tooltip {
  position: fixed; z-index: 12; pointer-events: none;
  background: rgba(8, 10, 11, 0.88); border: 1px solid var(--panel-border);
  color: var(--cream); font-size: 12px; letter-spacing: 0.06em;
  padding: 6px 11px; border-radius: 6px; white-space: nowrap;
  opacity: 0; transition: opacity 0.15s ease;
  backdrop-filter: blur(6px);
}
.tooltip.show { opacity: 1; }
.tooltip .pays { color: var(--gold-bright); }

.skip-3d {
  position: fixed;
  z-index: 40;
  top: max(14px, var(--safe-top));
  right: max(14px, var(--safe-right));
  min-width: 84px;
  padding: 11px 18px;
  color: var(--gold-bright);
  background: rgba(9, 10, 9, 0.88);
  border: 1px solid rgba(232,205,138,0.65);
  border-radius: 999px;
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.22em;
  text-indent: 0.22em;
  cursor: pointer;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(-6px);
  transition: opacity 0.16s ease, transform 0.16s ease, border-color 0.16s ease;
}
.skip-3d:hover { border-color: var(--gold-bright); }

/* Opt-in close-up temporarily gives WebGL the full viewport. */
body.three-d-spin #scene-container { inset: 0 !important; }
body.three-d-spin .vignette { inset: 0 !important; }
body.three-d-spin .hud-top,
body.three-d-spin .hud-bottom {
  opacity: 0 !important;
  visibility: hidden;
  pointer-events: none;
}
body.three-d-spin .letterbox { height: 0 !important; }
/* Opacity-only for status live regions: visibility:hidden would drop them from
 * the a11y tree, so result updates during close-up would never be announced. */
body.three-d-spin .banner,
body.three-d-spin .toast {
  opacity: 0 !important;
}
body.three-d-spin .tooltip {
  opacity: 0 !important;
  visibility: hidden;
}
body.three-d-spin .skip-3d {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateY(0);
}

/* ---------------- bottom HUD: four-column control dock ---------------- */

.hud-bottom {
  position: fixed; inset: auto 0 0 0; z-index: 10;
  height: calc(var(--bottom-hud-height) + var(--safe-bottom));
  padding: 12px max(16px, var(--safe-right)) calc(14px + var(--safe-bottom)) max(16px, var(--safe-left));
  display: grid;
  grid-template-columns: 330px minmax(430px, 1fr) 226px 224px;
  align-items: stretch;
  gap: 14px;
  background: linear-gradient(180deg, rgba(12, 12, 11, 0.98), rgba(6, 6, 6, 0.995));
  border-top: 1px solid rgba(201, 162, 75, 0.16);
  transition: opacity 0.8s ease;
}

.panel, .spin-btn { min-height: 88px; border-radius: 12px; }

.panel {
  background: linear-gradient(180deg, rgba(17, 18, 17, 0.96), rgba(8, 9, 8, 0.98));
  border: 1px solid rgba(201, 162, 75, 0.35);
  box-shadow:
    inset 0 1px 0 rgba(255, 236, 190, 0.05),
    0 8px 24px rgba(0, 0, 0, 0.45);
}

/* stats: BALANCE | TOTAL BET | LAST WIN in one horizontal strip */
.stats-panel { position: relative; display: flex; align-items: stretch; padding: 10px 8px 14px; width: 100%; height: 100%; }
.stat { padding: 0 16px; display: flex; flex-direction: column; justify-content: center; gap: 5px; min-width: 92px; }
.stat-label { font-size: 9px; letter-spacing: 0.24em; color: rgba(232,205,138,0.62); white-space: nowrap; }
.stat-value {
  font-family: var(--serif); font-size: 21px; color: var(--cream);
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
.stat-value.win { color: var(--gold-bright); }
.stat-divider { width: 1px; background: rgba(239,230,205,0.14); margin: 6px 0; }
.stat-value.flash { animation: money-flash 0.9s ease; }
@keyframes money-flash {
  0% { text-shadow: 0 0 0 rgba(232,205,138,0); }
  30% { text-shadow: 0 0 22px rgba(232,205,138,0.9); color: #fff3d6; }
  100% { text-shadow: 0 0 0 rgba(232,205,138,0); }
}
.text-btn {
  position: absolute; right: 12px; bottom: 3px;
  background: none; border: none; cursor: pointer;
  color: rgba(239,230,205,0.28); font-size: 7px; letter-spacing: 0.24em;
  padding: 1px 0; transition: color 0.2s ease;
}
.text-btn:hover { color: var(--gold); }
.reset-label-compact { display: none; }

/* chip tray with prev / next arrows */
.chip-tray-panel {
  position: relative; display: flex; align-items: center; justify-content: center;
  gap: 4px; padding: 8px 10px 12px; width: 100%; height: 100%;
}
.chip-tray { display: flex; gap: 9px; align-items: center; }
.tray-arrow {
  background: none; border: none; cursor: pointer; padding: 0 8px;
  color: rgba(239,230,205,0.5); font-size: 30px; line-height: 1;
  font-family: var(--serif); transition: color 0.18s ease; align-self: center;
}
.tray-arrow:hover { color: var(--gold-bright); }
.chip-btn {
  position: relative; width: 62px; height: 62px; border-radius: 50%;
  border: none; background: none; cursor: pointer; padding: 0;
  transition: transform 0.18s ease, filter 0.18s ease;
  filter: drop-shadow(0 4px 8px rgba(0,0,0,0.55)) saturate(0.92) brightness(0.94);
}
.chip-btn img { width: 100%; height: 100%; display: block; border-radius: 50%; }
.chip-btn:hover { transform: translateY(-3px); filter: drop-shadow(0 8px 14px rgba(0,0,0,0.6)); }
.chip-btn.selected {
  transform: translateY(-4px) scale(1.1);
  filter: drop-shadow(0 8px 16px rgba(0,0,0,0.65)) drop-shadow(0 0 14px rgba(232,205,138,0.6));
}
.chip-btn.selected::after {
  content: ''; position: absolute; inset: -4px; border-radius: 50%;
  border: 2px solid var(--gold-bright);
}
.limits {
  position: absolute; bottom: 3px; left: 50%; transform: translateX(-50%);
  font-size: 7px; letter-spacing: 0.3em; color: rgba(239,230,205,0.3); white-space: nowrap;
}

/* actions: square icon buttons UNDO / CLEAR / REBET */
.actions { padding: 9px; display: flex; align-items: center; gap: 8px; width: 100%; height: 100%; }
.action-btn {
  flex: 1 1 0; height: 70px; border-radius: 10px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  background: rgba(255,255,255,0.03); border: 1px solid rgba(239,230,205,0.18);
  color: rgba(239,230,205,0.85); font-size: 9px; letter-spacing: 0.18em; text-indent: 0.18em;
  transition: all 0.18s ease; outline: none; font-family: var(--sans);
}
.action-btn svg { opacity: 0.8; }
.action-btn:focus-visible { border-color: var(--gold-bright); }
.action-btn:hover:not(:disabled) { border-color: var(--gold); color: var(--gold-bright); background: rgba(201,162,75,0.08); }
.action-btn:disabled, .spin-btn:disabled { opacity: 0.32; cursor: default; }

/* spin: dark plate, gold border & lettering, auto-spin hint */
.spin-btn {
  width: 100%; min-width: 0; padding: 12px 18px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 5px;
  color: var(--gold-bright);
  background: linear-gradient(180deg, rgba(46,36,18,0.96) 0%, rgba(24,18,8,0.97) 100%);
  border: 1px solid var(--gold);
  box-shadow: 0 6px 24px rgba(0,0,0,0.5), inset 0 1px 0 rgba(232,205,138,0.25), inset 0 0 24px rgba(201,162,75,0.08);
  transition: all 0.18s ease;
}
.spin-main {
  display: flex; align-items: center; gap: 12px;
  font-family: var(--serif); font-size: 20px; letter-spacing: 0.4em; text-indent: 0.4em;
}
.spin-main svg { flex: none; opacity: 0.9; }
.spin-sub { font-size: 7.5px; letter-spacing: 0.3em; text-indent: 0.3em; color: rgba(232,205,138,0.55); font-family: var(--sans); }
.spin-btn:hover:not(:disabled) {
  border-color: var(--gold-bright);
  box-shadow: 0 8px 34px rgba(201,162,75,0.35), inset 0 1px 0 rgba(232,205,138,0.4);
  transform: translateY(-1px);
}
.spin-btn:active:not(:disabled) { transform: translateY(1px); }
.spin-btn.auto {
  border-color: var(--gold-bright);
  box-shadow: 0 0 30px rgba(232,205,138,0.4), inset 0 0 24px rgba(201,162,75,0.2);
}
.spin-btn.auto .spin-main svg { animation: auto-rotate 2.4s linear infinite; }
@keyframes auto-rotate { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }

.limits { font-size: 8px; letter-spacing: 0.3em; color: rgba(239,230,205,0.34); }

/* ---------------- intro ---------------- */

.intro {
  position: fixed; inset: 0; z-index: 50;
  background: radial-gradient(ellipse 90% 90% at 50% 30%, #101812 0%, #05070a 60%, #010102 100%);
  display: flex; align-items: center; justify-content: center;
  opacity: 1; visibility: visible;
  /* visibility flips immediately when shown; when hiding, wait out the fade */
  transition: opacity 1.2s ease, visibility 0s linear 0s;
}
.intro.hidden {
  opacity: 0; pointer-events: none; visibility: hidden;
  transition: opacity 1.2s ease, visibility 0s linear 1.2s;
}
.intro-inner { text-align: center; max-width: 640px; padding: 0 24px; }
.intro-kicker { font-size: 11px; letter-spacing: 0.6em; color: rgba(201,162,75,0.75); margin-bottom: 26px; }
.intro-title {
  font-family: var(--serif); font-weight: 500; font-size: clamp(44px, 7vw, 84px);
  line-height: 1.06; letter-spacing: 0.14em; color: var(--cream);
  text-shadow: 0 4px 44px rgba(201,162,75,0.28);
}
.intro-rule {
  width: 210px; height: 1px; margin: 30px auto;
  background: linear-gradient(90deg, transparent, var(--gold), transparent);
}
.intro-sub { font-size: 13px; letter-spacing: 0.34em; color: rgba(239,230,205,0.55); margin-bottom: 44px; }
.enter-btn {
  font-family: var(--serif); font-size: 15px; letter-spacing: 0.4em; text-indent: 0.4em;
  color: var(--gold-bright); background: none; cursor: pointer;
  border: 1px solid rgba(201,162,75,0.55); border-radius: 999px;
  padding: 16px 46px; transition: all 0.3s ease;
}
.enter-btn:hover {
  background: rgba(201,162,75,0.12); border-color: var(--gold-bright);
  box-shadow: 0 0 44px rgba(201,162,75,0.3);
}
.intro-hints { margin-top: 46px; font-size: 11px; line-height: 2; letter-spacing: 0.14em; color: rgba(239,230,205,0.34); }

/* ---------------- responsive HUD ---------------- */

@media (max-width: 1250px) {
  :root { --bottom-hud-height: 106px; }
  .hud-bottom {
    grid-template-columns: 280px minmax(360px, 1fr) 190px 190px;
    gap: 10px; padding-inline: 10px;
  }
  .panel, .spin-btn { min-height: 78px; }
  .stat { padding: 0 10px; min-width: 78px; }
  .stat-value { font-size: 17px; }
  .chip-btn { width: 52px; height: 52px; }
  .action-btn { height: 62px; width: auto; }
  .spin-main { font-size: 17px; }
}

@media (max-width: 1080px) and (min-height: 701px) {
  :root { --bottom-hud-height: 196px; }
  .hud-bottom { grid-template-columns: 1fr auto 1fr; grid-template-rows: 1fr 1fr; gap: 8px; }
  .chip-tray-panel { grid-column: 1 / -1; grid-row: 1; }
  .stats-panel, .panel, .spin-btn { min-height: 0; }
  .chip-btn { width: 44px; height: 44px; }
  .action-btn { height: 100%; padding: 0 10px; }
  .spin-main { font-size: 15px; }
  .limits { display: none; }
  .banner-title { letter-spacing: 0.1em; }
  .brand-name { font-size: 15px; letter-spacing: 0.3em; }
  .brand-sub { font-size: 9px; }
}

@media (max-width: 700px) {
  .stats-panel { padding: 6px 2px 10px; }
  .stat { padding: 0 8px; min-width: 0; }
  .stat-value { font-size: 14px; }
  .chip-btn { width: 38px; height: 38px; }
  .spin-main { font-size: 13px; letter-spacing: 0.26em; text-indent: 0.26em; gap: 8px; }
  .spin-sub { display: none; }
  .action-btn { font-size: 8px; }
  .history-panel { grid-template-columns: repeat(4, 26px); }
  .toast { font-size: 12px; }
}

@media (orientation: landscape) and (max-height: 700px) and (min-width: 760px) {
  :root {
    --top-hud-height: 48px;
    --bottom-hud-height: 84px;
  }

  .hud-top {
    height: calc(var(--top-hud-height) + var(--safe-top));
    padding: var(--safe-top) max(14px, var(--safe-right)) 0 max(14px, var(--safe-left));
  }

  .brand-name {
    font-size: 14px;
    letter-spacing: 0.34em;
  }

  .brand-sub { display: none; }
  .hud-top-right { gap: 10px; }
  .round-btn { width: 34px; height: 34px; }
  .top-btn-label { display: none; }

  .hud-bottom {
    grid-template-columns:
      minmax(150px, 0.80fr)
      minmax(255px, 1.35fr)
      minmax(132px, 0.70fr)
      minmax(120px, 0.65fr);
    grid-template-rows: 1fr;
    gap: 6px;
    padding: 6px max(7px, var(--safe-right)) calc(7px + var(--safe-bottom)) max(7px, var(--safe-left));
  }

  .chip-tray-panel {
    grid-column: auto;
    grid-row: auto;
  }

  .panel,
  .spin-btn {
    min-height: 0;
    height: 100%;
    border-radius: 8px;
  }

  .stats-panel { padding: 4px 5px; }
  .stat {
    min-width: 0;
    padding: 0 8px;
    gap: 2px;
  }
  .stat-label { font-size: 7px; letter-spacing: 0.14em; }
  .stat-value { font-size: 15px; }

  .stat-last-win,
  .divider-last-win,
  .limits {
    display: none;
  }

  .text-btn {
    right: 6px;
    bottom: 2px;
    font-size: 6.5px;
    letter-spacing: 0.14em;
  }
  .text-btn .reset-label-full { display: none; }
  .text-btn .reset-label-compact { display: inline; }

  .chip-tray-panel {
    padding: 4px 5px;
    gap: 1px;
  }
  .chip-tray { gap: 5px; }
  .chip-btn { width: 34px; height: 34px; }
  .chip-btn.selected { transform: translateY(-2px) scale(1.08); }
  .tray-arrow { padding: 0 3px; font-size: 23px; }

  .actions {
    padding: 4px;
    gap: 4px;
  }
  .action-btn {
    height: 100%;
    min-width: 0;
    padding: 0 3px;
    gap: 2px;
    border-radius: 7px;
    font-size: 7px;
    letter-spacing: 0.08em;
    text-indent: 0.08em;
  }
  .action-btn svg { width: 14px; height: 14px; }

  .spin-btn {
    padding: 4px 7px;
    gap: 2px;
  }
  .spin-main {
    gap: 5px;
    font-size: 14px;
    letter-spacing: 0.22em;
    text-indent: 0.22em;
  }
  .spin-main svg { width: 16px; height: 16px; }
  .spin-sub { display: none; }

  .banner.medium { top: calc(var(--top-hud-height) + 8px); }
  .banner.medium .banner-title { font-size: 20px; }
  .banner.medium .banner-sub { margin-top: 4px; font-size: 10px; }

  body.cinema .hud-top,
  body.cinema .hud-bottom {
    opacity: 1;
  }
  body.cinema .letterbox { height: 0; }
}

@media (orientation: landscape) and (max-height: 700px) and (max-width: 759px) {
  :root {
    --top-hud-height: 44px;
    --bottom-hud-height: 122px;
  }

  .hud-top {
    height: calc(var(--top-hud-height) + var(--safe-top));
    padding: var(--safe-top) max(10px, var(--safe-right)) 0 max(10px, var(--safe-left));
  }
  .brand-name { font-size: 12px; letter-spacing: 0.28em; }
  .brand-sub,
  .top-btn-label {
    display: none;
  }
  .round-btn { width: 32px; height: 32px; }

  .hud-bottom {
    grid-template-columns: minmax(160px, 1fr) 144px 124px;
    grid-template-rows: 50px 58px;
    gap: 5px;
    padding: 5px max(6px, var(--safe-right)) calc(7px + var(--safe-bottom)) max(6px, var(--safe-left));
  }
  .chip-tray-panel {
    grid-column: 1 / -1;
    grid-row: 1;
  }
  .stats-panel {
    grid-column: 1;
    grid-row: 2;
  }
  .actions {
    grid-column: 2;
    grid-row: 2;
  }
  .spin-btn {
    grid-column: 3;
    grid-row: 2;
  }

  .panel,
  .spin-btn {
    min-height: 0;
    height: 100%;
    border-radius: 8px;
  }

  .chip-tray-panel { padding: 3px 5px; }
  .chip-tray { gap: 5px; }
  .chip-btn { width: 34px; height: 34px; }
  .tray-arrow { padding: 0 4px; font-size: 22px; }

  .stats-panel { padding: 3px 4px; }
  .stat {
    min-width: 0;
    padding: 0 6px;
    gap: 1px;
  }
  .stat-label { font-size: 6.5px; letter-spacing: 0.10em; }
  .stat-value { font-size: 13px; }

  .stat-last-win,
  .divider-last-win,
  .limits {
    display: none;
  }

  .text-btn {
    right: 5px;
    bottom: 1px;
    font-size: 6px;
    letter-spacing: 0.12em;
  }
  .text-btn .reset-label-full { display: none; }
  .text-btn .reset-label-compact { display: inline; }

  .actions {
    padding: 3px;
    gap: 3px;
  }
  .action-btn {
    height: 100%;
    min-width: 0;
    padding: 0;
    gap: 1px;
    font-size: 0;
    border-radius: 6px;
  }
  .action-btn svg { width: 16px; height: 16px; }

  .spin-btn { padding: 3px 5px; }
  .spin-main {
    gap: 4px;
    font-size: 12px;
    letter-spacing: 0.16em;
    text-indent: 0.16em;
  }
  .spin-main svg { width: 14px; height: 14px; }
  .spin-sub { display: none; }

  .banner.medium { top: calc(var(--top-hud-height) + 5px); }
  .banner.medium .banner-title { font-size: 18px; }
  .banner.medium .banner-sub { display: none; }

  body.cinema .hud-top,
  body.cinema .hud-bottom {
    opacity: 1;
  }
  body.cinema .letterbox { height: 0; }
}

/* Portrait phones: rotate the 3D composition (wheel above a 3×12 board) and
 * use the otherwise-empty left margin as a vertical control rail. */
@media (orientation: portrait) and (max-width: 1080px) {
  :root {
    --top-hud-height: 48px;
    --bottom-hud-height: 52px;
    --portrait-rail-width: 74px;
  }

  .hud-top {
    height: calc(var(--top-hud-height) + var(--safe-top));
    padding: var(--safe-top) max(10px, var(--safe-right)) 0 max(10px, var(--safe-left));
  }
  .brand-name { font-size: 12px; letter-spacing: 0.26em; }
  .brand-sub,
  .top-btn-label {
    display: none;
  }
  .hud-top-right { gap: 8px; }
  .round-btn { width: 32px; height: 32px; }

  #scene-container {
    left: calc(var(--portrait-rail-width) + var(--safe-left));
    right: var(--safe-right);
    top: calc(var(--top-hud-height) + var(--safe-top));
    bottom: calc(var(--bottom-hud-height) + var(--safe-bottom));
  }
  .vignette {
    inset:
      calc(var(--top-hud-height) + var(--safe-top))
      var(--safe-right)
      calc(var(--bottom-hud-height) + var(--safe-bottom))
      calc(var(--portrait-rail-width) + var(--safe-left));
  }

  .hud-bottom {
    inset: calc(var(--top-hud-height) + var(--safe-top)) auto 0 0;
    width: calc(var(--portrait-rail-width) + var(--safe-left));
    height: auto;
    padding: 5px 5px calc(5px + var(--safe-bottom)) max(5px, var(--safe-left));
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 5px;
    border-top: 0;
    border-right: 1px solid rgba(201, 162, 75, 0.22);
  }

  .panel,
  .spin-btn {
    min-height: 0;
    width: 100%;
    border-radius: 8px;
  }

  .chip-tray-panel {
    position: static;
    order: 1;
    flex: 1 1 auto;
    width: 100%;
    height: auto;
    min-height: 0;
    padding: 5px 3px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 0;
  }
  .chip-tray {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
  }
  .chip-btn {
    width: 34px;
    height: 34px;
  }
  .chip-btn.selected { transform: translateX(3px) scale(1.08); }
  .tray-arrow,
  .limits {
    display: none;
  }

  .actions {
    position: static;
    order: 2;
    flex: 0 0 126px;
    width: 100%;
    height: 126px;
    padding: 4px;
    display: flex;
    flex-direction: column;
    gap: 4px;
  }
  .action-btn {
    width: 100%;
    height: auto;
    min-height: 0;
    flex: 1 1 0;
    padding: 2px 0;
    gap: 1px;
    border-radius: 6px;
    font-size: 7px;
    letter-spacing: 0.06em;
    text-indent: 0.06em;
  }
  .action-btn svg { width: 15px; height: 15px; }

  .spin-btn {
    position: static;
    order: 3;
    flex: 0 0 58px;
    height: 58px;
    padding: 4px 2px;
    gap: 1px;
  }
  .spin-main {
    flex-direction: column;
    gap: 2px;
    font-size: 11px;
    letter-spacing: 0.14em;
    text-indent: 0.14em;
  }
  .spin-main svg { width: 15px; height: 15px; }
  .spin-sub { display: none; }

  .stats-panel {
    position: fixed;
    z-index: 11;
    left: calc(var(--portrait-rail-width) + var(--safe-left));
    right: var(--safe-right);
    bottom: 0;
    width: auto;
    height: calc(var(--bottom-hud-height) + var(--safe-bottom));
    padding: 5px max(8px, var(--safe-right)) calc(5px + var(--safe-bottom)) 8px;
    display: flex;
    align-items: stretch;
    border-radius: 0;
  }
  .stat {
    min-width: 0;
    flex: 1 1 0;
    padding: 0 8px;
    gap: 2px;
  }
  .stat-label { font-size: 7px; letter-spacing: 0.12em; }
  .stat-value { font-size: 14px; }
  .stat-last-win,
  .divider-last-win {
    display: none;
  }

  .text-btn {
    right: 8px;
    bottom: calc(4px + var(--safe-bottom));
    font-size: 7px;
    letter-spacing: 0.14em;
  }
  .text-btn .reset-label-full { display: none; }
  .text-btn .reset-label-compact { display: inline; }

  .banner,
  .toast {
    left: calc(50% + var(--portrait-rail-width) / 2);
  }
  .banner.status {
    top: calc(var(--top-hud-height) + 8px);
    padding: 7px 16px;
  }
  .banner.status .banner-title { font-size: 13px; }
  .banner.result {
    width: calc(100vw - var(--portrait-rail-width) - 20px);
    padding: 14px 14px 16px;
  }
  .banner.result .banner-title { font-size: 25px; }
  .banner.medium {
    top: calc(var(--top-hud-height) + 8px);
  }
  .banner.medium .banner-title { font-size: 18px; }
  .banner.medium .banner-sub { display: none; }

  body.cinema .hud-top,
  body.cinema .hud-bottom {
    opacity: 1;
  }
  body.cinema .letterbox { height: 0; }
}

@media (orientation: portrait) and (max-width: 360px) {
  :root { --portrait-rail-width: 68px; }
  .chip-btn { width: 30px; height: 30px; }
  .chip-tray { gap: 3px; }
  .actions { flex-basis: 108px; height: 108px; }
  .spin-btn { flex-basis: 50px; height: 50px; }
  .action-btn span { display: none; }
}
