/*====================
  1) CSS Variables
====================*/
:root {
  /* Color system */
  --bg: #0b0e14;
  --surface: #121826;
  --surface-2: #191f2e;
  --text: #e6eaf2;
  --muted: #9da9bd;
  --accent: #7cdaff;
  --accent-2: #ff5cdf;
  --win: #82ff9e;
  --glow: 0 0 1.25rem rgba(124, 218, 255, 0.45);

  /* Motion tokens */
  --reel-speed: 0.2s; /* base spinning speed (updated for faster spin) */
  --reel-delay: 0.22s; /* stagger gap */
  --win-pulse: 0.6s; /* win-line pulse */
  --easing-snap: cubic-bezier(0.22, 1, 0.36, 1);

  /* Layout tokens */
  --radius: 16px;
  --radius-lg: 22px;
  --pad: 1rem;
  --pad-lg: 1.25rem;
  --symbol-row-h: clamp(64px, 8vw, 96px); /* global symbol row height for alignment */
}

/* Theme override using checkbox hack: force Light when unchecked, Dark when checked */
#themeSwitch:not(:checked) ~ .page {
  --bg: #fafafa;
  --surface: #ffffff;
  --surface-2: #f2f5f9;
  --text: #0e1116;
  --muted: #495469;
  --accent: #0ea5e9;
  --accent-2: #db2777;
  --win: #16a34a;
  --glow: 0 0 1.25rem rgba(14, 165, 233, 0.35);
}

/* Dark when checked */
#themeSwitch:checked ~ .page {
  --bg: #0b0e14;
  --surface: #121826;
  --surface-2: #191f2e;
  --text: #e6eaf2;
  --muted: #9da9bd;
  --accent: #7cdaff;
  --accent-2: #ff5cdf;
  --win: #82ff9e;
  --glow: 0 0 1.25rem rgba(124, 218, 255, 0.45);
}


/* Base elements */
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: "Space Grotesk", system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  line-height: 1.45;
}

/* Wrap page so theme variable overrides can affect background/color */
.page {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  color: var(--text);
  background: radial-gradient(1200px 600px at 20% -10%, rgba(124,218,255,0.12), transparent 60%),
              radial-gradient(800px 600px at 120% 0%, rgba(255,92,223,0.12), transparent 50%),
              var(--bg);
  transition: background-color .3s ease, color .2s ease;
}

.visually-hidden { position: absolute !important; clip: rect(1px, 1px, 1px, 1px); padding: 0 !important; border: 0 !important; height: 1px !important; width: 1px !important; overflow: hidden; }
.sr-only { position: absolute; left: -9999px; }

.site-header, .site-footer {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 1rem;
  padding: var(--pad-lg);
}

.site-footer { grid-template-columns: 1fr; text-align: center;  border-bottom: none; margin-top: 2rem; }
.logo {
  font-family: Kanit, system-ui, sans-serif;
  font-weight: 800;
  letter-spacing: 0.5px;
  margin: 0;
  justify-self: center;
  grid-column: 2;
}
.logo span { color: var(--accent); text-shadow: var(--glow); }

.toolbar { display: flex; align-items: center; gap: .75rem; grid-column: 3; justify-self: end; }
.toggle {
  --size: 52px; --thumb: 26px;
  position: relative; display: inline-grid; grid-auto-flow: column; align-items: center; gap: .35rem;
  width: var(--size); height: 30px; padding: 2px; border-radius: 999px; cursor: pointer;
  background: linear-gradient(135deg, var(--surface-2), var(--surface));
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.08), 0 8px 20px rgba(0,0,0,0.25);
}
.toggle::after {
  content: ""; position: absolute; inset: 2px; border-radius: 999px; background: linear-gradient(135deg, rgba(255,255,255,0.08), transparent);
}
.toggle .sun, .toggle .moon { font-size: 0.9rem; }

.container {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1.25rem;
  padding: clamp(5rem, 2vw, 2rem);
  max-width: 1180px;
  margin: 0 auto;
  overflow: hidden;
}

.machine {
  position: relative;
  background: linear-gradient(180deg, var(--surface), var(--surface-2));
  border-radius: var(--radius-lg);
  padding: var(--pad-lg);
  box-shadow: 0 16px 40px rgba(0,0,0,0.35), inset 0 0 0 1px rgba(255,255,255,0.06);
  transition: background .25s ease, box-shadow .25s ease;
}

.reels {
  position: relative;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: .9rem;
  align-items: stretch;
  padding: .5rem; /* inner breathing room around overlays */
}


.controls { 
  grid-column: 1 / -1; 
  justify-self: center;
  background: linear-gradient(180deg, var(--surface), var(--surface-2));
  border-radius: var(--radius);
  padding: .75rem 1rem;
  box-shadow: 0 8px 18px rgba(0,0,0,0.2), inset 0 0 0 1px rgba(255,255,255,0.06);
  width: 450px; /* Fixed width */
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 50px;
  position: relative; 
  isolation: isolate; 
}

.controls > * { position: relative; z-index: 1; }

/* Spin button styled as label to #spinToggle */
.spin-button {
  grid-column: 1 / -1;
  margin-top: 1rem;
  justify-self: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: white; font-weight: 700; letter-spacing: .5px;
  padding: .75rem 1.25rem; border-radius: 999px; cursor: pointer;
  box-shadow: 0 10px 24px rgba(124,218,255,0.35);
  transition: transform .2s var(--easing-snap), filter .2s;
  user-select: none;
  display: inline-flex; align-items: center; justify-content: center; min-height: 42px; line-height: 1;
}


#spinToggle:checked ~ .spin-button { filter: brightness(0.95) saturate(1.05); }
#spinToggle:checked ~ .reel:nth-of-type(2) .symbols { animation-delay: var(--reel-delay); }
#spinToggle:checked ~ .reel:nth-of-type(3) .symbols { animation-delay: calc(var(--reel-delay) * 2); }
.spin-button:hover { transform: translateY(-1px); filter: brightness(1.05); }
.spin-button:active { transform: translateY(1px) scale(0.98); }
#spinToggle:checked ~ .reel::before { animation: reel-sheen 1.5s ease-in-out 1; }

/* Reel viewport */
.reel {
  perspective: 800px; /* enables 3D effect */
  border-radius: var(--radius);
  background: radial-gradient(100% 100% at 50% 0%, rgba(255,255,255,0.06), transparent 40%)
              ,linear-gradient(180deg, rgba(255,255,255,0.06), rgba(0,0,0,0.15));
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.08), 0 18px 30px rgba(0,0,0,0.38);
  overflow: hidden;
  height: calc(var(--symbol-row-h) * 3);
  position: relative;
}

/* Reel sheen overlay */
.reel::before {
  content: "";
  position: absolute; inset: 0;
  background: linear-gradient(100deg, rgba(255,255,255,0.08) 0%, rgba(255,255,255,0.02) 40%, rgba(0,0,0,0.05) 60%, rgba(255,255,255,0.04) 100%);
  mix-blend-mode: soft-light;
  opacity: .28;
  pointer-events: none;
  z-index: 1;
}

/* Symbols column; forms the spinning strip */
.symbols {
  list-style: none; margin: 0; padding: 0;
  display: grid; grid-auto-rows: var(--symbol-row-h);
  align-content: start;
  transform-style: preserve-3d;
  /* Start in spinning state; animation-play-state toggled via #spinToggle */
  animation: reel-spin var(--reel-speed) linear infinite;
  will-change: transform, filter;
  position: relative; z-index: 0;
}

/* Toggle animation between spin and stop based on #spinToggle */
#spinToggle:not(:checked) ~ .reel .symbols { animation: reel-spin var(--reel-speed) linear infinite; }
#spinToggle:checked ~ .reel .symbols { animation: reel-stop var(--reel-speed) ease-out 1 forwards; }

/* Individual symbol styling */
.symbols li {
  display: grid; place-items: center;
  font-size: 2rem;
  text-shadow: 0 1px 0 rgba(0,0,0,0.10), 0 6px 18px rgba(0,0,0,0.15);
  transform: translateZ(0);
  transition: transform .25s var(--easing-snap), filter .2s ease;
}

.machine { position: relative; }

/* Win-line highlight: flashes when stopped */
.win-line {
  position: absolute;
  inset: 0;
  z-index: 10;
  opacity: 0;
  pointer-events: none;
}

.reels:has(#spinToggle:checked) ~ .win-line {
  animation: win-flash var(--win-pulse) ease-in-out 8 alternate;
  opacity: 1;
  border-radius: var(--radius-lg);
  box-shadow: 0 0 0 2px var(--win), 0 0 36px rgba(130,255,158,0.65), 0 0 8px rgba(124,218,255,0.35) inset;
}


/* Keyframes and reduced-motion rules moved to animation.css */

/*====================
  4) Message Bar & Overlay
====================*/
.message-bar {
  margin: 0;
  border-radius: var(--radius);
  padding: 0; /* Remove padding since .controls has it */
  box-shadow: none; /* Remove shadow since .controls has it */
  min-height: auto;
  z-index: 5;
  display: grid; 
  align-items: center;
  width: 100%; /* Fill .controls width */
  background: transparent; /* No background, uses .controls */
}

.message-bar .msg { 
  margin: 0; 
  opacity: 0; 
  transform: translateY(6px); 
  transition: opacity .25s ease, transform .25s var(--easing-snap); 
  position: relative; 
  display: none; 
  text-align: center; 
}
.message-bar { position: relative; }

/* Default state */
.msg-default { opacity: 1; transform: none; display: block; }

.intro {
  text-align: center;
  padding: 2rem;
}

.intro-links {
  display: flex;
  gap: 1rem;
  justify-content: center;
  flex-wrap: wrap;
}

.info-toggle, .about-toggle, .try-link {
  display: inline-block;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: white;
  padding: 0.75rem 1.5rem;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: 0 10px 24px rgba(124,218,255,0.25);
  transition: transform 0.2s ease;
  text-decoration: none; /* For .try-link */
}

.info-toggle:hover, .about-toggle:hover, .try-link:hover {
  transform: scale(1.05);
}

.back-home {
  grid-column: 1;
  justify-self: start;
}

.back-link {
  display: inline-block;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: white;
  padding: 0.5rem 1rem;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: 0 10px 24px rgba(124,218,255,0.25);
  transition: transform 0.2s ease;
  text-decoration: none;
  font-size: 0.9rem;
}

.back-link:hover {
  transform: scale(1.05);
}


/* Overlay (How To Play) */
.howto-overlay { position: fixed; inset: 0; display: grid; place-items: center; background: rgba(0,0,0,0.4); opacity: 0; pointer-events: none; transition: opacity .25s ease; z-index: 100; }
/* Show only the overlay adjacent to the corresponding checkbox */
#howtoToggle:checked + .howto-overlay { opacity: 1; pointer-events: auto; }
#aboutToggle:checked + .howto-overlay { opacity: 1; pointer-events: auto; }
.howto-card { width: min(680px, 92vw); background: linear-gradient(180deg, var(--surface), var(--surface-2)); color: var(--text); border-radius: 18px; padding: 1.25rem; box-shadow: 0 20px 40px rgba(0,0,0,0.45), inset 0 0 0 1px rgba(255,255,255,0.06); }
.howto-card h2 { margin-top: 0; font-family: Kanit, system-ui, sans-serif; }
.close-overlay { display: inline-block; margin-top: .75rem; background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: white; padding: .6rem 1rem; border-radius: 999px; cursor: pointer; box-shadow: 0 10px 24px rgba(124,218,255,0.25); }

/* Slot Machine Logic */

@keyframes show-win {
  to { opacity: 1; }
}


/* Style try-again/play-again buttons */
.try-again, .play-again {
  display: inline-block;
  margin-left: 0.5rem;
  background: var(--accent);
  color: white;
  padding: 0.4rem 0.8rem;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.9rem;
}

.play-again {
  display: inline-block;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: white;
  font-weight: 700;
  letter-spacing: .5px;
  padding: .75rem 1.25rem;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: 0 10px 24px rgba(124,218,255,0.35);
  transition: transform .2s var(--easing-snap), filter .2s;
  user-select: none;
  min-height: 42px;
  line-height: 1;
  margin-left: 0.5rem;
  text-decoration: none; /* Since it's a link */
}

.play-again:hover { transform: translateY(-1px); filter: brightness(1.05); }
.play-again:active { transform: translateY(1px) scale(0.98); }

#spinToggle:checked ~ .controls .spin-button { display: none; }

/* Style the new "Spin" button like the original */
.spin-again {
  display: inline-block;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: white;
  font-weight: 700;
  letter-spacing: .5px;
  padding: .75rem 1.25rem;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: 0 10px 24px rgba(124,218,255,0.35);
  transition: transform .2s var(--easing-snap), filter .2s;
  user-select: none;
  min-height: 42px;
  line-height: 1;
  margin-left: 0.5rem;
}

.spin-again:hover { transform: translateY(-1px); filter: brightness(1.05); }
.spin-again:active { transform: translateY(1px) scale(0.98); }