@font-face {
  font-family: "Baloo 2";
  font-style: normal;
  font-weight: 400 800;
  font-display: swap;
  src: url("../assets/fonts/baloo2-variable.woff2") format("woff2");
}

:root {
  --blue: #063b86;
  --blue2: #0b56a7;
  --sky: #55aee4;
  --gold: #ffd83d;
  --gold-deep: #e5a700;
  --ink: #07346f;
  --text-dim: #b8d4f0;
  --surface: linear-gradient(165deg, #0c2450e6, #081a3ae6);
  --surface-border: 1px solid #ffffff14;
  --radius-lg: 22px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --shadow-card: 0 10px 30px -12px #000a14cc;
  --font-display: "Baloo 2", -apple-system, "Segoe UI", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  height: 100dvh;
  overflow: hidden;
  display: flex;
  font-family: var(--font-display);
  font-weight: 500;
  color: #fff;
  background: radial-gradient(circle at 50% -10%, #1e63b8 0, #0a2a63 45%, #050d1f 100%);
}

.app {
  flex: 1;
  min-height: 0;
  width: 100%;
  max-width: 1600px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: clamp(8px, 1.4vh, 16px);
  padding: clamp(10px, 1.6vh, 20px) clamp(12px, 2vw, 26px);
}

/* ---------- Top bar ---------- */

.topbar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: clamp(8px, 1.2vw, 14px);
  min-width: 0;
}

.brand img.logo {
  width: clamp(44px, 7.5vh, 78px);
  height: clamp(44px, 7.5vh, 78px);
  border-radius: 50%;
  object-fit: cover;
  box-shadow: 0 3px 12px #00071a80;
  flex-shrink: 0;
}

.brand-text {
  min-width: 0;
}

h1 {
  font-size: clamp(19px, 4.4vh, 46px);
  font-weight: 800;
  letter-spacing: 0.5px;
  margin: 0;
  line-height: 1.1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-shadow: 0 2px 8px #041e4d;
}

h1 span {
  color: var(--gold);
}

.sub {
  font-size: clamp(11px, 1.9vh, 18px);
  font-weight: 700;
  letter-spacing: 2px;
  color: var(--text-dim);
  margin-top: 2px;
}

.topbar-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

/* ---------- Main layout ---------- */

.layout {
  flex: 1;
  min-height: 0;
  display: flex;
  gap: clamp(10px, 1.4vw, 20px);
}

.machine {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: var(--surface-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card), inset 0 1px 0 #ffffff0f;
  padding: clamp(12px, 2vh, 24px);
}

.sidebar {
  width: clamp(230px, 22vw, 320px);
  flex-shrink: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: clamp(8px, 1.2vh, 14px);
}

/* ---------- Machine internals ---------- */

.marquee {
  flex-shrink: 0;
  background: linear-gradient(160deg, #ffe978, var(--gold-deep));
  color: var(--ink);
  text-align: center;
  font-size: clamp(14px, min(3.2vh, 2.6vw), 36px);
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border-radius: var(--radius-md);
  padding: clamp(6px, 1vh, 11px) 16px;
  margin-bottom: clamp(6px, 1.2vh, 14px);
  box-shadow: 0 6px 18px -8px #e5a700aa;
}

.marquee.spinning {
  animation: marquee-pulse 0.9s ease-in-out infinite;
}

.marquee.celebrate {
  animation: marquee-pop 0.5s ease;
}

@keyframes marquee-pulse {
  0%, 100% {
    box-shadow: 0 6px 18px -8px #e5a700aa;
    filter: brightness(1);
  }
  50% {
    box-shadow: 0 0 30px -4px #ffd83dee;
    filter: brightness(1.12);
  }
}

@keyframes marquee-pop {
  0% {
    transform: scale(0.92);
  }
  55% {
    transform: scale(1.03);
  }
  100% {
    transform: scale(1);
  }
}

#reels {
  flex: 1;
  min-height: 56px;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 3px;
  overflow: hidden;
  border: 2px solid #ffd83d66;
  border-radius: var(--radius-md);
  background: #04070f;
  position: relative;
  box-shadow: inset 0 0 26px #000c;
}

.reel {
  position: relative;
  overflow: hidden;
  background: linear-gradient(90deg, #060810, #141f38, #060810);
  border-right: 1px solid #ffffff12;
}

.reel:last-child {
  border-right: none;
}

.track {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
}

.cell {
  height: var(--cell-h, 58px);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(11px, 1.7vw, 20px);
  font-weight: 700;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
  padding: 0 6px;
  color: #fff;
  text-shadow: 0 1px 4px #000a;
}

.fast .cell {
  filter: blur(2.2px);
  opacity: 0.72;
}

.payline {
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: min(70px, 88%);
  transform: translateY(-50%);
  border-top: 2px solid var(--gold);
  border-bottom: 2px solid var(--gold);
  background: #ffd83d1a;
  box-shadow: 0 0 16px -2px #ffd83d88;
  z-index: 5;
  pointer-events: none;
}

.payline::before,
.payline::after {
  content: "";
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  border: 8px solid transparent;
}

.payline::before {
  left: -1px;
  border-left-color: var(--gold);
}

.payline::after {
  right: -1px;
  border-right-color: var(--gold);
}

.controls {
  flex-shrink: 0;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 16px;
  margin-top: clamp(8px, 1.5vh, 20px);
  text-align: center;
}

.stat b {
  font-size: clamp(16px, 3vh, 30px);
  font-weight: 800;
  color: var(--gold);
  display: block;
  line-height: 1.1;
}

.stat span {
  font-size: clamp(9px, 1.3vh, 12px);
  letter-spacing: 1.5px;
  color: var(--text-dim);
}

.spin {
  width: clamp(64px, 11vh, 100px);
  height: clamp(64px, 11vh, 100px);
  border-radius: 50%;
  border: none;
  font-family: var(--font-display);
  background: linear-gradient(160deg, #ffe792, var(--gold) 55%, var(--gold-deep));
  color: var(--ink);
  font-weight: 800;
  font-size: clamp(13px, 2.2vh, 20px);
  letter-spacing: 1px;
  cursor: pointer;
  box-shadow: 0 6px 18px -6px #000000aa, 0 0 0 4px #ffd83d2e;
  transition: transform 0.12s ease, box-shadow 0.12s ease, filter 0.15s ease;
}

.spin:hover:not(:disabled) {
  filter: brightness(1.06);
  transform: scale(1.04);
  box-shadow: 0 8px 22px -6px #000000bb, 0 0 0 6px #ffd83d3d;
}

.spin:active:not(:disabled) {
  transform: scale(0.95);
}

.spin:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  filter: saturate(0.5);
}

.winner-panel {
  flex-shrink: 0;
  border: 1px solid #ffd83d59;
  border-radius: var(--radius-md);
  background: linear-gradient(160deg, #0d2f6b, #061838);
  box-shadow: inset 0 1px 0 #ffffff0d;
  text-align: center;
  padding: clamp(8px, 1.5vh, 18px);
  margin-top: clamp(8px, 1.5vh, 20px);
}

.winner-label {
  letter-spacing: 1.5px;
  font-weight: 700;
  font-size: clamp(10px, 1.5vh, 14px);
  color: var(--gold);
  margin-bottom: 2px;
}

#winnerDisplay {
  font-size: clamp(18px, 4.5vh, 54px);
  font-weight: 800;
  line-height: 1.15;
  text-shadow: 0 0 18px #ffffff70;
  min-height: 1.15em;
}

#statusText {
  margin-top: 4px;
  color: var(--text-dim);
  font-weight: 600;
  font-size: clamp(10px, 1.5vh, 14px);
}

/* ---------- Sidebar panels ---------- */

.panel {
  background: var(--surface);
  border: var(--surface-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  padding: clamp(10px, 1.6vh, 18px);
}

.panel h3 {
  color: var(--gold);
  font-weight: 700;
  margin: 0 0 clamp(6px, 1vh, 12px);
  font-size: clamp(12px, 1.8vh, 16px);
  letter-spacing: 0.5px;
}

.prizes-panel {
  flex-shrink: 0;
  padding-block: calc(clamp(10px, 1.6vh, 18px) + 10px);
}

.prizes-list {
  list-style: none;
  margin: 0;
  padding: 0;
  font-size: clamp(11px, 1.6vh, 14px);
  color: var(--text-dim);
}

.prizes-list li {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: clamp(3px, 0.7vh, 7px) 0;
  border-bottom: 1px solid #ffffff0d;
}

.prizes-list li:last-child {
  border-bottom: none;
}

.prizes-list li b {
  color: var(--gold);
  min-width: 2.6em;
}

.log-panel {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

#logList {
  list-style: none;
  flex: 1;
  min-height: 0;
  margin: 0 0 10px;
  padding: 0;
  overflow-y: auto;
  font-size: clamp(11px, 1.6vh, 14px);
}

#logList li {
  padding: clamp(4px, 0.8vh, 8px) 0;
  border-bottom: 1px solid #ffffff0d;
}

.log-empty {
  color: var(--text-dim);
}

.log-meta {
  color: var(--text-dim);
  font-size: 0.85em;
}

.export-row {
  flex-shrink: 0;
  display: flex;
  gap: 8px;
}

/* ---------- Buttons ---------- */

button {
  font-family: inherit;
}

.btn {
  background: #ffffff12;
  border: 1px solid #ffffff24;
  color: #fff;
  border-radius: 999px;
  padding: 8px 16px;
  cursor: pointer;
  font-weight: 700;
  font-size: clamp(11px, 1.6vh, 14px);
  transition: background 0.15s ease, transform 0.1s ease, filter 0.15s ease;
}

.btn:hover:not(:disabled) {
  background: #ffffff22;
  transform: translateY(-1px);
}

.btn:active:not(:disabled) {
  transform: translateY(0);
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-gold {
  background: linear-gradient(160deg, #ffe792, var(--gold) 60%, var(--gold-deep));
  border: none;
  color: var(--ink);
}

.btn-gold:hover:not(:disabled) {
  background: linear-gradient(160deg, #fff0ab, #ffdf5c 60%, #f0b400);
  filter: brightness(1.03);
}

.btn-small {
  padding: 6px 12px;
}

button:focus-visible,
input:focus-visible,
summary:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--sky);
  outline-offset: 2px;
}

/* ---------- Setup dialog ---------- */

dialog.modal {
  background: linear-gradient(165deg, #0d2650, #081a3a);
  color: #fff;
  border: 1px solid #ffffff1f;
  border-radius: var(--radius-lg);
  box-shadow: 0 30px 80px -20px #000c;
  padding: clamp(18px, 3vh, 28px);
  width: min(540px, 92vw);
  max-height: 86dvh;
  overflow-y: auto;
}

dialog.modal::backdrop {
  background: #02060fb8;
  backdrop-filter: blur(4px);
}

dialog.modal h3 {
  color: var(--gold);
  font-weight: 800;
  font-size: 18px;
  margin: 0 0 10px;
}

.dialog-help {
  color: var(--text-dim);
  font-size: 14px;
  line-height: 1.6;
  margin: 0 0 14px;
}

.file-label {
  display: inline-block;
  margin-bottom: 12px;
}

textarea#namesTextarea {
  width: 100%;
  min-height: 110px;
  background: #020b1d;
  border: 1px solid #ffffff1f;
  border-radius: var(--radius-sm);
  color: #fff;
  font-family: inherit;
  font-size: 14px;
  padding: 10px;
  resize: vertical;
  transition: border-color 0.15s ease;
}

textarea#namesTextarea:focus {
  outline: none;
  border-color: var(--sky);
  box-shadow: 0 0 0 3px #55aee433;
}

.dialog-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  align-items: center;
}

/* ---------- Entrants dialog ---------- */

input#entrantsSearch {
  width: 100%;
  background: #020b1d;
  border: 1px solid #ffffff1f;
  border-radius: var(--radius-sm);
  color: #fff;
  font-family: inherit;
  font-size: 14px;
  padding: 10px 12px;
  margin-bottom: 10px;
  transition: border-color 0.15s ease;
}

input#entrantsSearch:focus {
  outline: none;
  border-color: var(--sky);
  box-shadow: 0 0 0 3px #55aee433;
}

.entrants-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: min(50vh, 420px);
  overflow-y: auto;
  font-size: 14px;
}

.entrants-list li {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid #ffffff0d;
  color: var(--text-dim);
}

.entrants-list li b {
  color: var(--gold);
  flex-shrink: 0;
}

.entrants-empty {
  color: var(--text-dim);
}

/* ---------- Confetti ---------- */

.confetti {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 20;
}

.confetti i {
  position: absolute;
  width: 8px;
  height: 14px;
  border-radius: 3px;
  animation: fall 2.2s linear forwards;
}

@keyframes fall {
  to {
    transform: translateY(110vh) rotate(720deg);
  }
}

/* ---------- Responsive: stack sidebar below machine ---------- */

@media (max-width: 840px) {
  .layout {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    flex: 0 0 auto;
    flex-direction: row;
    max-height: 26dvh;
  }

  .sidebar .panel {
    flex: 1;
    min-width: 0;
    min-height: 0;
    overflow-y: auto;
  }

  .log-panel {
    flex: 1.25;
  }
}

@media (max-width: 520px) {
  .sub {
    display: none;
  }

  .topbar {
    flex-wrap: wrap;
  }

  .topbar-actions .btn {
    padding: 6px 10px;
    font-size: 11px;
  }

  h1 {
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
    font-size: 14px;
  }
}
