:root {
  --bg1: #2a0f08; --bg2: #5a1d0c;
  --gold: #f3b33d; --gold-2: #ffd77a; --cream: #fff6e6;
  --cabinet: #3b1408; --cabinet-edge: #7a2e12;
  --reel-bg: #fffaf0; --ink: #2b1306;
  --win: #ffd23f;
  --reel-w: min(26vw, 30vh, 300px);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(ellipse at top, var(--bg2), var(--bg1) 70%);
  color: var(--cream);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  overflow-x: hidden;
}
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.app { min-height: 100%; display: flex; flex-direction: column; }

.top { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 16px; flex-wrap: wrap; }
.logo { margin: 0; font-size: 26px; letter-spacing: .02em; color: var(--gold-2); text-shadow: 0 2px 0 #000a; }
.logo span { color: var(--cream); }
.tools { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
select, button, .filebtn, .modelink {
  font: inherit; font-size: 14px; color: var(--cream); background: #0005; border: 1px solid #fff3;
  border-radius: 10px; padding: 7px 10px; cursor: pointer;
}
select option { color: #000; }
.modelink { text-decoration: none; }
button.icon { min-width: 40px; }
button, .reel, .lever { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
.filebtn input { display: none; }
button:focus-visible, select:focus-visible, .filebtn:focus-within { outline: 2px solid var(--gold); outline-offset: 2px; }

.stage { flex: 1; display: flex; justify-content: center; align-items: center; gap: 18px; padding: 8px 16px 24px; }
.cabinet {
  background: linear-gradient(180deg, var(--cabinet-edge), var(--cabinet) 20%, var(--cabinet) 80%, var(--cabinet-edge));
  border: 3px solid var(--gold); border-radius: 28px; padding: 18px 22px 20px;
  box-shadow: 0 20px 60px #0009, inset 0 0 0 6px #0003;
  display: flex; flex-direction: column; align-items: center; gap: 12px;
}
.marquee {
  min-height: 1.6em; font-size: clamp(20px, 3.4vw, 34px); font-weight: 800; letter-spacing: .04em; text-align: center;
  color: var(--gold-2); text-shadow: 0 0 12px #f3b33d88;
}
.marquee.jackpot { animation: flash .35s steps(2) 8; color: var(--win); }
@keyframes flash { 50% { color: #fff; text-shadow: 0 0 24px #fff; } }

.reels { position: relative; display: grid; grid-template-columns: repeat(3, var(--reel-w)); gap: 12px;
  padding: 12px; background: #1c0904; border-radius: 18px; box-shadow: inset 0 6px 18px #000c; }
.reel {
  position: relative; width: var(--reel-w); height: calc(var(--reel-w) * 1.25 * 1.3);
  overflow: hidden; border-radius: 12px; background: var(--reel-bg);
  cursor: pointer;
}
.reel::before, .reel::after { content: ""; position: absolute; left: 0; right: 0; height: 18%; z-index: 2; pointer-events: none; }
.reel::before { top: 0; background: linear-gradient(#000a, #0000); }
.reel::after { bottom: 0; background: linear-gradient(#0000, #000a); }
.strip { position: absolute; left: 0; top: 0; width: 100%; will-change: transform; }
.strip.blur { filter: blur(2.5px) saturate(1.1); }
.cell { width: var(--reel-w); height: calc(var(--reel-w) * 1.25); padding: 4px; }
.cell img { width: 100%; height: 100%; object-fit: cover; border-radius: 8px; display: block; user-select: none; -webkit-user-drag: none; }
.reel.win { box-shadow: 0 0 0 4px var(--win), 0 0 28px var(--win); }
.payline { position: absolute; left: 4px; right: 4px; top: 50%; height: 0; border-top: 2px dashed #f3b33d66; pointer-events: none; z-index: 3; }

.captions { display: grid; grid-template-columns: repeat(3, var(--reel-w)); gap: 12px; text-align: center; min-height: 1.5em; }
.cap { font-weight: 700; font-size: clamp(14px, 1.8vw, 20px); color: var(--cream); transition: opacity .3s; }
.cap.dim { opacity: .25; }

.controls { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.spin {
  font-size: clamp(20px, 2.6vw, 28px); font-weight: 900; letter-spacing: .08em; text-transform: uppercase;
  padding: 14px 56px; border-radius: 999px; border: 0; color: #3a1300;
  background: linear-gradient(180deg, var(--gold-2), var(--gold) 60%, #c97f12);
  box-shadow: 0 6px 0 #8a4d06, 0 10px 24px #0008; transition: transform .08s, box-shadow .08s;
}
.spin:active:not(:disabled) { transform: translateY(4px); box-shadow: 0 2px 0 #8a4d06, 0 4px 12px #0008; }
.spin:disabled { filter: grayscale(.5) brightness(.8); cursor: default; }
.hint { font-size: 13px; color: #fff9; }
.stats { font-size: 13px; color: #fffa; min-height: 1em; }

.lever { position: relative; width: 44px; height: 260px; background: none; border: 0; padding: 0; cursor: pointer; align-self: center; }
.lever .arm { position: absolute; left: 18px; top: 30px; width: 8px; height: 200px; border-radius: 4px;
  background: linear-gradient(90deg, #888, #eee, #888); transform-origin: 50% 100%; transition: transform .25s; }
.lever .knob { position: absolute; left: 4px; top: 4px; width: 36px; height: 36px; border-radius: 50%; z-index: 1;
  background: radial-gradient(circle at 35% 35%, #ff8a7a, #c0261a 60%, #6d0d06); box-shadow: 0 4px 10px #0008; transition: transform .25s; }
.lever.pulled .arm { transform: scaleY(.25); }
.lever.pulled .knob { transform: translateY(150px); }

.viewer { position: fixed; inset: 0; background: #000d; display: flex; align-items: center; justify-content: center; z-index: 20; padding: 16px; }
.viewer[hidden] { display: none; }
.viewer figure { margin: 0; display: flex; flex-direction: column; align-items: center; gap: 10px; max-width: 92vw; }
.viewer img { max-width: 92vw; max-height: 76vh; border-radius: 12px; box-shadow: 0 10px 40px #000; }
.viewer figcaption { text-align: center; font-size: 20px; display: flex; flex-direction: column; }
.viewer figcaption span { font-size: 15px; color: #fffb; }
.vbanner { font-size: clamp(28px, 6vw, 56px); font-weight: 900; color: var(--win); text-shadow: 0 0 20px #f3b33d; min-height: 0; }
.vbanner:empty { display: none; }
.vclose { position: absolute; top: 14px; right: 16px; font-size: 28px; line-height: 1; background: #0008; }
.vnav { position: absolute; top: 50%; transform: translateY(-50%); font-size: 40px; line-height: 1; padding: 6px 14px; background: #0008; }
.vnav.prev { left: 12px; } .vnav.next { right: 12px; }
#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 30; width: 100%; height: 100%; }

@media (max-width: 700px) {
  :root { --reel-w: min(28vw, 34vh); }
  .lever { display: none; }
  .cabinet { padding: 14px 10px 16px; border-radius: 20px; }
  .reels, .captions { gap: 6px; }
  .reels { padding: 8px; }
  .logo { font-size: 22px; }
}
@media (prefers-reduced-motion: reduce) {
  .strip.blur { filter: none; }
  .marquee.jackpot { animation: none; }
}

/* iPhone tip and rotate hint */
.tip { position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 40; width: min(92vw, 420px);
  background: #1c0904; border: 2px solid var(--gold); border-radius: 16px; padding: 18px 18px 14px; box-shadow: 0 20px 60px #000c; text-align: center; }
.tip[hidden], .rotate[hidden] { display: none; }
.tip p { margin: 0 0 12px; line-height: 1.5; }
.rotate { position: fixed; left: 50%; bottom: max(14px, env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 15;
  background: #000b; border: 1px solid #fff3; border-radius: 999px; padding: 8px 8px 8px 16px; display: flex; gap: 10px; align-items: center; font-size: 14px; white-space: nowrap; }
.rotate button { padding: 2px 10px; }

/* Phone held sideways (or any short screen): reels sized by height, controls beside them */
@media (orientation: landscape) and (max-height: 520px) {
  :root { --reel-w: min(calc((100dvh - 84px) / 1.625), 24vw); }
  body { overflow: hidden; }
  .app { height: 100dvh; padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
  .top { position: absolute; top: max(4px, env(safe-area-inset-top)); right: max(8px, env(safe-area-inset-right)); padding: 0; z-index: 5; }
  .logo, .filebtn, #luckSelect { display: none; }
  #setSelect { padding: 4px 6px; font-size: 13px; max-width: 34vw; }
  .tools { gap: 6px; }
  .tools button.icon { padding: 4px 8px; min-width: 34px; font-size: 13px; }
  .stage { padding: 6px 8px; height: 100%; }
  .lever { display: none; }
  .cabinet { flex-direction: row; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px 14px;
    padding: 8px 12px; border-radius: 18px; max-height: 100%; }
  .cabinet { position: relative; padding-top: 34px; }
  .marquee { position: absolute; left: 16px; top: 6px; max-width: 48%; text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-height: 0; font-size: clamp(14px, 4.5dvh, 20px); }
  .reels { order: 2; padding: 6px; gap: 6px; }
  .captions { display: none; }
  .controls { order: 3; }
  .spin { padding: 12px 22px; font-size: 18px; writing-mode: horizontal-tb; }
  .hint { display: none; }
  .stats { display: none; }
  .reels, .captions { grid-template-columns: repeat(3, var(--reel-w)); }
}
@media (display-mode: fullscreen), (display-mode: standalone) { #fsBtn { display: none; } }
