:root {
  color-scheme: dark;
  color: #f3f3ee;
  background: #121516;
  font-family: system-ui, sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; }
button { font: inherit; touch-action: manipulation; }

.cabinet {
  position: relative;
  width: 100%;
  height: 100vh;
  height: 100dvh;
}

.viewport { position: absolute; inset: 0; overflow: hidden; isolation: isolate; touch-action: pinch-zoom; background: #232729; }
.viewport canvas { position: absolute; inset: 0; display: block; width: 100%; height: 100%; }

.room {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

.room-section {
  --picture-height: 100%;
  --picture-y: center;
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: #252624 url('./assets/layers/00_background.webp') center var(--picture-y) / 100% var(--picture-height) no-repeat;
}

.room-floor { visibility: hidden; }
.portrait-projection .room-wall {
  --picture-height: var(--wall-picture-height);
  --picture-y: top;
  bottom: auto;
  height: var(--ground);
}
.portrait-projection .room-floor {
  --picture-height: var(--floor-picture-height);
  --picture-y: bottom;
  top: var(--ground);
  visibility: visible;
}

.room.alternate .room-section { background-image: url('./assets/layers/00_background_alternate.webp'); }
.room.alternate .wall-lamp-left, .room.alternate .wall-lamp-right { display: none; }

.wall-lamp {
  position: absolute;
  inset: 0;
  background: url('./assets/layers/00_background_lights_off.webp') center var(--picture-y) / 100% var(--picture-height) no-repeat;
  opacity: 0;
}

.wall-lamp-left {
  -webkit-mask-image: linear-gradient(to right, #000 41%, transparent 59%);
  mask-image: linear-gradient(to right, #000 41%, transparent 59%);
  animation: lamp-dip 11s -1.4s infinite;
}
.wall-lamp-right {
  -webkit-mask-image: linear-gradient(to left, #000 41%, transparent 59%);
  mask-image: linear-gradient(to left, #000 41%, transparent 59%);
  animation: lamp-dip 17s -0.8s infinite;
}
.wall-lamp-alternate { display: none; }
.room.alternate .wall-lamp-alternate {
  display: block;
  background-image: radial-gradient(ellipse at 50% 4%, #040a12ae 0%, #060b1288 30%, transparent 80%);
  animation: lamp-dip 13s -1.8s infinite;
}

@keyframes lamp-dip {
  0%, 20%, 33%, 100% { opacity: 0; }
  22%, 25% { opacity: .96; }
  28% { opacity: .30; }
  30%, 31% { opacity: .84; }
}

.foreground {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 2;
  pointer-events: none;
  background: url('./assets/layers/06_doorway_foreground.webp') center / 100% 100% no-repeat;
}
#foreground-right { opacity: .91; }

.viewport::after {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  background: radial-gradient(ellipse at 49% 43%, transparent 45%, #03080c47 100%);
}

.controls {
  --ink: #0b0d0f;
  --panel: #171a1df5;
  --raised: #22292c;
  --hover: #344147;
  --quiet: #c0c9cb;
  --accent: #ffb786;
  --spin-size: clamp(68px, 9vmin, 104px);
  --rail-height: calc(var(--spin-size) * .74);
  position: absolute;
  z-index: 2;
  bottom: max(8px, env(safe-area-inset-bottom));
  left: 50%;
  width: min(920px, max(64%, min(92%, 570px)));
  transform: translateX(-50%);
}

.dock-status {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  padding: 0 6px;
  height: 23px;
  color: var(--quiet);
  font-size: 11px;
  line-height: 1;
  text-shadow: 0 1px 3px #000, 0 0 7px #000;
}
#status { grid-column: 2; margin: 0; color: #f5f7f4; text-align: center; white-space: nowrap; }
.dock-links { grid-column: 3; display: flex; justify-self: end; }
.dock-links a { color: var(--quiet); padding: 4px 2px; }

.dock-body {
  display: grid;
  grid-template-columns: var(--rail-height) minmax(116px, 1fr) minmax(32px, 0.13fr) var(--spin-size) minmax(48px, .18fr);
  grid-template-areas: 'tools readouts steps spin play';
  grid-template-rows: var(--spin-size);
  align-items: center;
  gap: 7px;
}

.dock-tools { grid-area: tools; position: relative; z-index: 1; }
.dock-play { grid-area: play; }
.bet-stepper { grid-area: steps; }
.dock-play, .bet-stepper {
  display: grid;
  grid-template-rows: repeat(2, minmax(0, 1fr));
  height: var(--rail-height);
}
#auto, #bet-up { grid-row: 1; }
#quick, #bet-down { grid-row: 2; }

.dock-readouts, .bet-stepper, .dock-play, .dock-tools summary { position: relative; isolation: isolate; }
.dock-readouts::before, .bet-stepper::before, .dock-play::before, .dock-tools summary::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: -1;
  border: 2px solid var(--ink);
  border-top-color: #303b40;
  border-radius: 9px;
  background: var(--panel);
  transform: skewX(-8deg);
  pointer-events: none;
}

.dock-tools summary {
  display: grid;
  place-items: center;
  height: var(--rail-height);
  list-style: none;
  cursor: pointer;
}
.dock-tools summary::-webkit-details-marker { display: none; }
.dock-tools summary:hover::before, .dock-tools[open] summary::before { background: var(--hover); }
.menu-mark {
  display: block;
  width: 18px;
  height: 12px;
  border-block: 2px solid #e9eeed;
  background: linear-gradient(#e9eeed, #e9eeed) center / 100% 2px no-repeat;
}
.dock-menu {
  position: absolute;
  bottom: calc(100% + 7px);
  left: 0;
  width: 160px;
  display: grid;
  gap: 5px;
  padding: 7px;
  background: #1c2428;
  border: 1px solid #566168;
  border-radius: 8px;
  box-shadow: 0 6px 22px #08090ba6;
}
.dock-tools:not([open]) .dock-menu { display: none; }
.controls .dock-menu button { justify-content: start; min-height: 38px; padding-inline: 9px; }

.dock-readouts {
  grid-area: readouts;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  height: var(--rail-height);
  padding-inline: 9px;
}
.readout { display: grid; align-content: center; justify-items: center; min-width: 0; padding: 3px 5px; gap: 4px; }
.balance-readout { justify-items: start; }
.bet-readout { justify-items: end; }
.readout > span { color: var(--quiet); font-size: clamp(8px, 1.15vw, 12px); font-weight: 830; text-transform: uppercase; letter-spacing: .05em; }
.readout strong { font: 800 clamp(13px, 2vmin, 22px)/1.1 system-ui, sans-serif; font-variant-numeric: tabular-nums; white-space: nowrap; }
#win[data-hit] { color: var(--accent); }

.controls button {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  gap: 3px;
  min-width: 0;
  padding: 0 5px;
  border: 1px solid var(--ink);
  border-radius: 5px;
  background: var(--raised);
  color: #f1f5f4;
  font-size: 11px;
  font-weight: 740;
  white-space: nowrap;
  cursor: pointer;
}
.controls button:enabled:hover { background: var(--hover); }
.controls :is(button, summary, a):focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.controls button:disabled { opacity: .42; cursor: default; }
.controls button[aria-pressed='true'] { color: var(--accent); }
.bet-stepper button, .dock-play button { border: 0; background: transparent; }
.bet-stepper button { font-size: 21px; line-height: 1; }
.utility-mark { font-size: 16px; line-height: 1; }
#bet-up, #auto { box-shadow: inset 0 -1px #383f44; }

#spin {
  grid-area: spin;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 5px;
  width: var(--spin-size);
  height: var(--spin-size);
  justify-self: center;
  border: 3px solid #090b0d;
  border-radius: 50%;
  background: #202629;
  color: #f3f7f6;
  box-shadow: inset 0 0 0 1px #66838d, 0 3px 8px #04050672;
  font-size: 10px;
  font-weight: 820;
  text-transform: uppercase;
  letter-spacing: .07em;
}
#spin:enabled:hover { background: #313f44; }
#spin[data-spinning] { color: var(--accent); }
@media (prefers-reduced-motion: no-preference) {
  #spin { transition: transform 100ms ease-out; }
  #spin:enabled:active { transform: translateY(1px) scale(.96); }
}
.spin-icon {
  position: relative;
  width: calc(var(--spin-size) * .43);
  aspect-ratio: 1;
  border: 3px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  transform: rotate(-35deg);
}
.spin-icon::after {
  content: '';
  position: absolute;
  right: -4px;
  top: 1px;
  border-block: 4px solid transparent;
  border-left: 7px solid currentColor;
  transform: rotate(53deg);
}
#spin[data-spinning] .spin-icon {
  width: calc(var(--spin-size) * .30);
  border: 0;
  border-radius: 4px;
  background: currentColor;
  transform: none;
}
#spin[data-spinning] .spin-icon::after { display: none; }

@media (max-width: 660px) and (orientation: landscape) {
  .controls { width: calc(100% - 20px); }
  .dock-body { gap: 6px; }
  .dock-status { padding-inline: 2px; }
  .dock-readouts { padding-inline: 5px; }
}

@media (max-height: 300px) and (orientation: landscape) {
  .controls { --spin-size: 52px; bottom: max(4px, env(safe-area-inset-bottom)); }
  .dock-status { height: 17px; }
  .dock-body { grid-template-columns: var(--rail-height) minmax(116px,1fr) 29px var(--spin-size) 49px; }
  #spin { gap: 2px; font-size: 8px; }
  .readout { gap: 2px; }
  .dock-play button { font-size: 9px; padding-inline: 2px; }
  .utility-mark { font-size: 13px; }
}

@media (orientation: portrait) {
  .controls { --spin-size: clamp(76px, 23vw, 96px); width: min(424px, calc(100% - 20px)); }
  .dock-body {
    grid-template-columns: repeat(6, minmax(0, 1fr));
    grid-template-areas: 'win win win win win win' 'play play spin spin tools tools' 'balance balance balance down amount up';
    grid-template-rows: 20px var(--spin-size) 47px;
    gap: 5px;
  }
  .dock-readouts, .bet-stepper { display: contents; }
  .dock-readouts::before, .bet-stepper::before, .dock-play::before { display: none; }
  .readout { height: 100%; align-content: center; justify-items: center; gap: 3px; }
  .balance-readout { grid-area: balance; justify-items: start; padding-left: 7px; }
  .win-readout { grid-area: win; display: flex; justify-content: center; align-items: center; gap: 7px; padding: 0; }
  .bet-readout { grid-area: amount; }
  .readout strong { font-size: clamp(12px, 3.7vw, 18px); text-shadow: 0 1px 5px #050607; }
  .readout > span { font-size: 10px; }
  #bet-down { grid-area: down; }
  #bet-up { grid-area: up; }
  .dock-play { display: grid; grid-template-columns: repeat(2, 44px); grid-template-rows: 44px; justify-content: center; gap: 4px; height: 44px; }
  #auto, #quick { grid-row: 1; }
  #auto, #bet-up { box-shadow: none; }
  .dock-play button, .bet-stepper button, .dock-tools summary {
    width: min(44px, 100%);
    height: 44px;
    justify-self: center;
    border: 2px solid var(--ink);
    border-top-color: #475258;
    border-radius: 50%;
    background: var(--raised);
  }
  .dock-play button { flex-direction: column; gap: 0; font-size: 8px; }
  .dock-tools { display: grid; justify-items: center; }
  .dock-tools summary::before { display: none; }
  .dock-tools summary:hover, .dock-tools[open] summary { background: var(--hover); }
  .dock-menu { left: auto; right: 0; }
}

@media (max-width: 300px) and (orientation: portrait) {
  .controls { --spin-size: 62px; width: calc(100% - 12px); }
  .dock-status { font-size: 9px; padding-inline: 2px; gap: 3px; }
  .dock-play { grid-template-columns: repeat(2, minmax(0,1fr)); gap: 2px; }
  .dock-play button, .bet-stepper button, .dock-tools summary { height: 35px; }
  .readout strong { font-size: 11px; }
  .readout > span { font-size: 9px; }
}

@media (prefers-reduced-motion: reduce) {
  .wall-lamp, .room.alternate .wall-lamp-alternate { animation: none; }
}
