:root {
  color-scheme: dark;
  --bg: #051009;
  --panel: #0c2518;
  --panel-soft: #123522;
  --panel-deep: #07180f;
  --gold: #f6d879;
  --gold-deep: #a8791e;
  --jade: #6ce9a7;
  --jade-soft: #baf7d4;
  --text: #fff9df;
  --muted: #aebfb3;
  --danger: #ff9e9e;
  --danger-bg: rgba(117, 24, 24, .22);
  --border: rgba(246, 216, 121, .24);
}

* { box-sizing: border-box; }
html { min-height: 100%; }
body {
  min-height: 100vh;
  margin: 0;
  padding: 14px;
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 50% -10%, rgba(108, 233, 167, .19), transparent 35%),
    linear-gradient(155deg, #020704, var(--bg) 48%, #06180e);
}

button, input, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .55; }

.ambient {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(90deg, transparent 49.8%, rgba(246,216,121,.025) 50%, transparent 50.2%),
    linear-gradient(0deg, transparent 49.8%, rgba(246,216,121,.02) 50%, transparent 50.2%);
  background-size: 72px 72px;
}

.game-shell, .admin-shell {
  position: relative;
  width: min(100%, 760px);
  margin: 0 auto;
  padding-bottom: max(20px, env(safe-area-inset-bottom));
}

.topbar, .admin-header, .panel-head, .machine-head, .paytable-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.topbar { margin-bottom: 12px; }
.top-actions { display: flex; gap: 8px; }
.eyebrow {
  margin: 0 0 4px;
  color: var(--jade);
  font-size: 12px;
  letter-spacing: .14em;
  text-transform: uppercase;
}
h1, h2, p { overflow-wrap: anywhere; }
h1 { margin: 0; font-size: clamp(25px, 6vw, 40px); }
h2 { margin: 0; font-size: 22px; }
.muted { color: var(--muted); }
.hidden { display: none !important; }

.icon-button, .back-link {
  min-width: 44px;
  min-height: 44px;
  display: inline-grid;
  place-items: center;
  border-radius: 13px;
  border: 1px solid var(--border);
  background: rgba(12, 37, 24, .86);
  color: var(--text);
  text-decoration: none;
}

.debug-banner {
  margin-bottom: 10px;
  border: 1px solid var(--danger);
  background: var(--danger-bg);
  color: #ffd0d0;
  padding: 9px 12px;
  border-radius: 12px;
  font-size: 13px;
  text-align: center;
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

.stat {
  min-width: 0;
  border: 1px solid var(--border);
  background: rgba(12, 37, 24, .86);
  border-radius: 14px;
  padding: 10px;
  text-align: center;
}
.stat span {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 12px;
}
.stat strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: clamp(15px, 4vw, 21px);
}

.machine {
  border: 2px solid var(--gold-deep);
  border-radius: 23px;
  padding: 14px;
  background:
    linear-gradient(180deg, rgba(246,216,121,.08), transparent 24%),
    rgba(7, 24, 15, .96);
  box-shadow: inset 0 0 0 4px rgba(0,0,0,.24);
}

.machine-head {
  margin-bottom: 11px;
  color: var(--muted);
  font-size: 13px;
}
.mode-badge {
  border: 1px solid rgba(108,233,167,.35);
  background: rgba(108,233,167,.1);
  color: var(--jade-soft);
  padding: 5px 9px;
  border-radius: 999px;
}

.tile-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
}
.tile {
  min-width: 0;
  aspect-ratio: .88;
  display: grid;
  place-items: center;
  border-radius: 13px;
  border: 2px solid rgba(246,216,121,.36);
  background:
    radial-gradient(circle at 38% 20%, rgba(255,255,255,.14), transparent 28%),
    linear-gradient(145deg, #165334, #071d12);
  box-shadow: inset 0 0 0 3px rgba(0,0,0,.24);
  transition: transform .2s ease, filter .2s ease, opacity .2s ease;
  user-select: none;
}
.tile-icon {
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(25px, 8vw, 57px);
  font-weight: 700;
  color: var(--gold);
  text-shadow: 0 2px 0 rgba(0,0,0,.55);
}
.tile-label {
  display: block;
  margin-top: -8px;
  color: var(--muted);
  font-size: clamp(8px, 2.3vw, 12px);
}
.tile.wild {
  border-color: var(--gold);
  background: linear-gradient(145deg, #6c5017, #1d1405);
}
.tile.scatter {
  border-color: #ffbd91;
  background: linear-gradient(145deg, #8b2a21, #2b0907);
}
.tile.winning {
  transform: translateY(-3px) scale(1.035);
  border-color: var(--jade);
  filter: brightness(1.4);
}
.tile.removing {
  transform: scale(.4) rotate(8deg);
  opacity: 0;
}
.tile.entering { animation: tile-drop .32s ease both; }
.tile-grid.spinning .tile { animation: tile-pulse .22s linear infinite alternate; }

@keyframes tile-pulse {
  from { transform: translateY(-2px); filter: brightness(.8) blur(.2px); }
  to { transform: translateY(2px); filter: brightness(1.2) blur(.8px); }
}
@keyframes tile-drop {
  from { transform: translateY(-28px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.win-panel {
  min-height: 67px;
  margin-top: 11px;
  padding: 10px 12px;
  border: 1px solid rgba(108,233,167,.22);
  border-radius: 14px;
  background: rgba(18,53,34,.55);
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 14px;
}
.win-panel span {
  display: block;
  color: var(--muted);
  font-size: 10px;
}
.win-panel strong { font-size: 22px; color: var(--gold); }
.win-panel p { margin: 0; text-align: right; color: var(--jade-soft); }

.controls {
  display: grid;
  grid-template-columns: 1fr 1.35fr 1fr;
  gap: 9px;
  margin-top: 13px;
}
.control-button, .spin-button, .secondary-controls button,
.info-panel button, .primary-button, .danger-button, .admin-actions button {
  border-radius: 17px;
  min-height: 56px;
  border: 1px solid rgba(108,233,167,.25);
  background: var(--panel-soft);
  color: var(--text);
  font-weight: 750;
}
.spin-button {
  border: 0;
  color: #211706;
  background: linear-gradient(180deg, #ffeaa0, #d79d28);
  box-shadow: 0 5px 0 #825a12;
  display: grid;
  place-items: center;
}
.spin-button span { font-size: 21px; line-height: 1; }
.spin-button small { font-size: 10px; opacity: .72; }
.spin-button:active { transform: translateY(3px); box-shadow: 0 2px 0 #825a12; }

.secondary-controls {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 11px;
}
.secondary-controls button, .info-panel button {
  min-height: 44px;
  border-radius: 12px;
}

.info-panel, .admin-card, .notice {
  margin-top: 14px;
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 15px;
  background: rgba(12,37,24,.96);
}
.info-panel > p { color: var(--muted); line-height: 1.55; }
.pay-row {
  display: grid;
  grid-template-columns: 1.3fr repeat(3, 1fr);
  gap: 8px;
  padding: 9px 0;
  border-bottom: 1px solid rgba(255,255,255,.07);
  font-size: 14px;
}
.pay-row strong { color: var(--gold); }
.legal-note { color: var(--muted); font-size: 12px; line-height: 1.5; }

footer {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-top: 14px;
  color: var(--muted);
  font-size: 11px;
}

.admin-header {
  align-items: flex-start;
  margin-bottom: 16px;
}
.admin-header p { margin-bottom: 0; }
.back-link { padding: 0 12px; white-space: nowrap; }
.notice {
  color: var(--jade-soft);
  line-height: 1.5;
}
.admin-card { padding: 18px; }
.admin-card h2 { margin-bottom: 14px; }
.form-grid {
  display: grid;
  gap: 13px;
}
.form-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
label {
  display: grid;
  gap: 7px;
  color: var(--text);
}
label small { color: var(--muted); line-height: 1.35; }
input, select {
  width: 100%;
  min-height: 46px;
  border: 1px solid rgba(246,216,121,.25);
  border-radius: 12px;
  padding: 10px 12px;
  background: var(--panel-deep);
  color: var(--text);
}
input:focus, select:focus { outline: 2px solid var(--jade); outline-offset: 2px; }
.button-field { display: flex; align-items: end; }
.button-field button { width: 100%; }
.primary-button {
  background: linear-gradient(180deg, #7ff0b6, #2c9e65);
  color: #04150c;
  border: 0;
}
.danger-button {
  border-color: rgba(255,158,158,.35);
  background: rgba(119,29,29,.35);
}
.status-line { color: var(--muted); margin: 12px 0 0; }
.status-line.success { color: var(--jade); }
.status-line.error { color: var(--danger); }
.danger-zone { border-color: rgba(255,158,158,.3); }
.switch-row {
  grid-template-columns: auto 1fr;
  align-items: center;
  margin-bottom: 14px;
}
.switch-row input { width: 22px; min-height: 22px; }
.admin-actions {
  display: grid;
  grid-template-columns: 1.2fr 1fr 1fr;
  gap: 9px;
  margin-top: 14px;
}
.admin-actions button { min-height: 50px; }

@media (max-width: 560px) {
  body { padding: 9px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .machine { padding: 9px; border-radius: 18px; }
  .tile-grid { gap: 4px; }
  .tile { border-radius: 9px; }
  .win-panel { grid-template-columns: 1fr; gap: 5px; }
  .win-panel p { text-align: left; }
  .secondary-controls, .admin-actions { grid-template-columns: 1fr; }
  .form-grid.two, .form-grid.three { grid-template-columns: 1fr; }
  .admin-header { display: grid; }
  .back-link { width: fit-content; margin-top: 10px; }
  .pay-row { font-size: 12px; }
  footer { display: grid; }
}
