:root {
  --gold: #e4c36a;
  --gold-bright: #ffe9a0;
  --red: #c41a2b;
  --red-deep: #7a0c16;
  --panel: #14080c;
  --felt: #1a0a10;
  --text: #fff6d8;
  --muted: #cbb58a;
  --win: #7dff9a;
  --danger: #ff6b6b;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: #070406;
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

body {
  overflow: hidden;
}

.game-root {
  min-height: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(ellipse at 50% 20%, #4a1020 0%, transparent 50%),
    radial-gradient(ellipse at 50% 100%, #1a080c 0%, #070406 55%);
}

.cabinet {
  width: min(100vw, calc(100vh * 16 / 9));
  height: min(100vh, calc(100vw * 9 / 16));
  max-width: 1280px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto auto;
  gap: 0.6rem;
  padding: 0.7rem 1rem 0.9rem;
  background:
    linear-gradient(180deg, #3a1520 0%, #1a080c 40%, #12060a 100%);
  border: 4px solid var(--gold);
  box-shadow:
    inset 0 0 0 2px #7a4e20,
    0 12px 40px rgba(0,0,0,0.6);
  position: relative;
  overflow: hidden;
}

.logo {
  height: clamp(42px, 10vh, 88px);
  display: block;
  margin: 0 auto;
  max-width: 92%;
}

.reel-stage {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 0;
}

.reel-bezel {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.55rem;
  width: min(92%, 820px);
  height: 100%;
  padding: 0.7rem;
  background: #090509;
  border: 3px solid var(--gold);
  border-radius: 12px;
  box-shadow: inset 0 0 24px #000;
}

.reel {
  position: relative;
  height: 100%;
  min-height: 0;
  border-radius: 8px;
  overflow: hidden;
  background: #f4efe2;
  box-shadow: inset 0 0 0 3px #2a1a12;
}

.reel.is-win {
  box-shadow: inset 0 0 0 3px #ffe08a, 0 0 18px rgba(255, 210, 80, 0.7);
}

.reel-window {
  height: 100%;
  overflow: hidden;
}

.reel-strip {
  will-change: transform;
}

.reel-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 33.333%;
  user-select: none;
}

.reel-cell img {
  width: 86%;
  height: 86%;
  object-fit: contain;
  pointer-events: none;
}

.reel-cell.is-fallback {
  font-size: clamp(14px, 2.4vw, 28px);
  font-weight: 800;
  color: #6a1018;
  letter-spacing: 0.04em;
}

.reel-cell.is-payline img {
  animation: winPulse 0.7s ease-in-out infinite;
  filter: drop-shadow(0 0 10px #ffe08a);
}

@keyframes winPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.08); }
}

.payline {
  position: absolute;
  left: 4%;
  right: 4%;
  top: 50%;
  height: 4px;
  margin-top: -2px;
  background: linear-gradient(90deg, transparent, #ff4d4d 12%, #ffe08a 50%, #ff4d4d 88%, transparent);
  pointer-events: none;
  box-shadow: 0 0 10px #ff6b6b;
  z-index: 2;
}

.cabinet.is-jackpot .payline {
  height: 6px;
  animation: lineFlash 0.35s linear infinite;
}

@keyframes lineFlash {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.25; }
}

.hud {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 0.6rem;
  width: min(92%, 820px);
  margin: 0 auto;
}

.meter {
  background: var(--panel);
  border: 2px solid var(--gold);
  border-radius: 8px;
  padding: 0.35rem 0.6rem 0.45rem;
  text-align: center;
  min-height: 52px;
}

.meter-label {
  font-size: 11px;
  letter-spacing: 0.16em;
  color: var(--muted);
  font-weight: 700;
}

.meter-value {
  font-size: clamp(18px, 3.2vw, 32px);
  font-variant-numeric: tabular-nums;
  color: var(--gold-bright);
  font-weight: 800;
}

.meter-value.is-win { color: var(--win); }

.status {
  text-align: center;
  min-height: 1.4em;
  font-weight: 800;
  letter-spacing: 0.12em;
  color: var(--gold-bright);
  font-size: clamp(12px, 1.8vw, 18px);
}

.status.is-error { color: var(--danger); }
.status.is-win { color: var(--win); }

.controls {
  display: grid;
  grid-template-columns: auto auto 1fr auto auto auto;
  gap: 0.55rem;
  align-items: center;
  width: min(96%, 900px);
  margin: 0 auto;
}

.btn {
  min-height: 44px;
  min-width: 44px;
  border-radius: 8px;
  border: 2px solid var(--gold);
  background: #2a1016;
  color: var(--text);
  font-weight: 800;
  letter-spacing: 0.06em;
  cursor: pointer;
  font-size: 14px;
}

.btn:hover { filter: brightness(1.12); }
.btn:focus-visible { outline: 3px solid var(--gold-bright); outline-offset: 2px; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; filter: none; }

.btn-bet {
  min-width: 52px;
  font-size: 22px;
}

.spin {
  justify-self: center;
  width: min(160px, 28vw);
  height: 44px;
  min-height: 44px;
  max-height: 44px;
  border-radius: 22px;
  border: 2px solid var(--gold-bright);
  background: radial-gradient(circle at 35% 30%, #ff6a6a, var(--red) 42%, var(--red-deep));
  color: #fff8dc;
  font-size: 18px;
  letter-spacing: 0.1em;
  box-shadow: 0 2px 0 #4a0008;
  line-height: 1;
  padding: 0 1rem;
}

.spin:active:not(:disabled) {
  transform: translateY(2px);
  box-shadow: 0 0 0 #4a0008;
}

.aux-pay, .aux-sound {
  justify-self: stretch;
}

.icon-btn img {
  width: 22px;
  height: 22px;
  vertical-align: middle;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0 0.7rem;
}

.overlay {
  position: absolute;
  inset: 0;
  background: rgba(6, 2, 4, 0.86);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 5;
  padding: 1rem;
}

.overlay.is-open { display: flex; }

.paytable {
  width: min(560px, 96%);
  max-height: 92%;
  overflow: auto;
  background: #16080c;
  border: 3px solid var(--gold);
  border-radius: 12px;
  padding: 1rem 1.1rem 1.2rem;
}

.paytable h2 {
  margin: 0 0 0.8rem;
  text-align: center;
  color: var(--gold-bright);
}

.pay-row {
  display: grid;
  grid-template-columns: 56px 1fr auto;
  gap: 0.6rem;
  align-items: center;
  padding: 0.35rem 0;
  border-bottom: 1px solid #3a2418;
}

.pay-row img { width: 48px; height: 48px; }
.pay-mult { color: var(--gold-bright); font-weight: 800; font-size: 18px; }

.loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #070406;
  z-index: 6;
  font-weight: 800;
  letter-spacing: 0.16em;
  color: var(--gold);
}

.loading.is-done { display: none; }

#btn-reset {
  width: min(92%, 820px);
  margin: 0 auto;
  min-height: 44px;
}

.coins { pointer-events: none; position: absolute; inset: 0; overflow: hidden; z-index: 4; }
.coin {
  position: absolute;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, #fff1b0, #d4a017);
  animation: coinFall 1.2s linear forwards;
}
@keyframes coinFall {
  to { transform: translateY(110vh) rotate(220deg); opacity: 0.2; }
}

.debug {
  display: none;
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 8;
  background: rgba(0,0,0,0.82);
  color: #9f6;
  font: 12px/1.4 ui-monospace, Consolas, monospace;
  padding: 8px;
  border: 1px solid #3a3;
  max-width: 280px;
  max-height: 90%;
  overflow: auto;
}

.debug.is-on { display: block; }
.debug button {
  margin: 2px 2px 0 0;
  font-size: 11px;
}

@media (max-aspect-ratio: 10/11) {
  body { overflow: auto; }
  .cabinet {
    width: 100vw;
    height: auto;
    min-height: 100vh;
    min-height: 100dvh;
    border-left: 0;
    border-right: 0;
    grid-template-rows: auto minmax(280px, 46vh) auto auto auto;
  }
  .controls {
    grid-template-columns: 1fr 1fr;
    grid-template-areas:
      "down up"
      "spin spin"
      "max max"
      "pay sound";
  }
  .btn-down { grid-area: down; }
  .btn-up { grid-area: up; }
  .spin { grid-area: spin; width: 100%; height: 72px; }
  .btn-max { grid-area: max; }
  .aux-pay { grid-area: pay; }
  .aux-sound { grid-area: sound; }
}

html.is-embed,
html.is-embed body,
html.is-embed .game-root {
  height: 100%;
  min-height: 100%;
  overflow: hidden;
}
html.is-embed .cabinet {
  width: 100%;
  height: 100%;
  max-width: none;
  border-width: 3px;
  gap: 0.3rem;
  padding: 0.35rem 0.5rem 0.55rem;
  grid-template-rows: auto minmax(0, 1fr) auto auto auto;
  overflow: hidden;
}
html.is-embed .logo {
  height: clamp(22px, 8vh, 40px);
}
html.is-embed .meter {
  min-height: 36px;
  padding: 0.15rem 0.35rem 0.2rem;
}
html.is-embed .meter-value {
  font-size: clamp(14px, 3.4vh, 22px);
}
html.is-embed .reel-bezel {
  padding: 0.4rem;
  gap: 0.35rem;
}
html.is-embed .controls {
  width: 100%;
  max-width: none;
  gap: 0.35rem;
  align-items: center;
  grid-template-columns: auto auto minmax(72px, 1fr) auto auto auto;
}
html.is-embed .btn {
  font-size: 12px;
  letter-spacing: 0.04em;
  padding: 0 0.45rem;
  white-space: nowrap;
  min-height: 44px;
  height: 44px;
}
html.is-embed .icon-btn {
  padding: 0 0.4rem;
}
html.is-embed .spin {
  width: 120px;
  max-width: 120px;
  height: 44px;
  min-height: 44px;
  max-height: 44px;
  font-size: 16px;
  letter-spacing: 0.08em;
  box-shadow: 0 2px 0 #4a0008;
}

@media (max-width: 840px) {
  html.is-embed .controls {
    grid-template-columns: 1fr 1fr;
    grid-template-areas:
      "down up"
      "spin spin"
      "max max"
      "pay sound";
  }
  html.is-embed .btn-down { grid-area: down; }
  html.is-embed .btn-up { grid-area: up; }
  html.is-embed .spin { grid-area: spin; max-width: none; width: 100%; }
  html.is-embed .btn-max { grid-area: max; }
  html.is-embed .aux-pay { grid-area: pay; }
  html.is-embed .aux-sound { grid-area: sound; }
}

@media (max-width: 420px) {
  .meter { min-height: 48px; }
  .logo { height: 48px; }
}
