/* Base Theme (Book Edition Default) */
:root {
  --primary: #9d174d;
  --primary-glow: rgba(157, 23, 77, 0.4);
  --bg-dark: #1e1b1e;
  --glass-bg: rgba(255, 255, 255, 0.05);
  --glass-border: rgba(255, 255, 255, 0.1);
  --text-main: #f8fafc;
  --text-dim: #94a3b8;
  --accent-1: #f43f5e;
  --accent-2: #10b981;
  --accent-3: #4c1d95;
  --accent-4: #f59e0b;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: "Outfit", sans-serif;
  transition:
    background-color 0.8s ease,
    border-color 0.8s ease,
    color 0.8s ease,
    box-shadow 0.8s ease;
}

h1,
h2,
h3 {
  font-family: "Playfair Display", serif;
}

body {
  background-color: var(--bg-dark);
  color: var(--text-main);
  height: 100dvh;
  width: 100vw;
  overflow: hidden; /* Lock viewport entirely to prevent native bounce/scroll bugs */
  overscroll-behavior-y: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: center;
  padding-top: 0;
}

html {
  height: 100%;
  width: 100%;
  overflow: hidden;
  overscroll-behavior-y: none; /* Ensure no native pull-to-refresh */
}

.bg-gradient {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background:
    radial-gradient(circle at 10% 20%, var(--accent-3) 0%, transparent 40%),
    radial-gradient(circle at 90% 80%, var(--primary) 0%, transparent 40%);
  z-index: -1;
  transition: all 1.5s ease;
}

#fireworksCanvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 3000;
}

/* Landing Page Overlay */
.landing-page {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  z-index: 999;
  background: rgba(20, 20, 20, 0.85);
  -webkit-backdrop-filter: blur(5px);
  backdrop-filter: blur(5px);
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: center;
  transition:
    transform 0.6s cubic-bezier(0.68, -0.55, 0.265, 1.55),
    opacity 0.6s ease;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch; /* Smooth momentum scroll on iOS/WebView */
  padding: 0; /* padding applied to inner elements instead */
}

/* Spacer for top padding to keep the main content roughly centered visually on desktop */
.landing-content-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  padding: 2rem 0;
  flex-shrink: 0;
  min-height: calc(100vh - 400px); /* Push SEO down */
  justify-content: center;
}

.landing-page.hidden {
  transform: translateY(-100%);
  opacity: 0;
  pointer-events: none;
}

.mode-cards {
  display: flex;
  gap: 1rem;
  margin-top: 2rem;
  flex-wrap: wrap;
  justify-content: center;
  width: 100%;
  max-width: 1200px;
  padding: 0 1rem;
  overflow: visible;
}

/* Enhanced Mode Cards */
.mode-card {
  position: relative;
  background: rgba(30, 27, 30, 0.6);
  border: 1px solid var(--glass-border);
  padding: 1.5rem 1rem;
  border-radius: 24px;
  width: 200px;
  min-width: 0;
  max-width: calc(50% - 0.5rem); /* Never wider than half the screen */
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  cursor: pointer;
  transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  text-align: center;
  overflow: hidden;
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  flex-shrink: 1;
}

.mode-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: radial-gradient(circle at top, var(--card-glow), transparent 70%);
  opacity: 0.1;
  transition: opacity 0.4s;
}

/* Individual Themes */
.mode-card.custom {
  --card-glow: #6366f1;
}
.mode-card.books {
  --card-glow: #f472b6;
}
.mode-card.games {
  --card-glow: #10b981;
}
.mode-card.movies {
  --card-glow: #e11d48;
}
.mode-card.tvshows {
  --card-glow: #8b5cf6;
}
.mode-card.countries {
  --card-glow: #0ea5e9;
}

.mode-card:hover {
  transform: translateY(-15px) scale(1.05);
  border-color: var(--card-glow);
  box-shadow:
    0 20px 50px -10px rgba(0, 0, 0, 0.5),
    0 0 20px -5px var(--card-glow);
}

.mode-card:hover::before {
  opacity: 0.3;
}

.mode-icon {
  font-size: 3.5rem;
  filter: drop-shadow(0 0 15px rgba(0, 0, 0, 0.3));
  transition: transform 0.4s ease;
  z-index: 1;
}

.mode-card:hover .mode-icon {
  transform: scale(1.2) rotate(5deg);
  filter: drop-shadow(0 0 20px var(--card-glow));
}

.mode-title {
  font-size: 1.4rem;
  font-weight: 800;
  color: white;
  z-index: 1;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

.mode-desc {
  font-size: 0.8rem;
  color: var(--text-dim);
  z-index: 1;
  opacity: 0.8;
}

.mode-card:hover .mode-title {
  color: var(--card-glow);
}

/* Main App Container - Use CSS Grid for reliable vertical stacking */
.app-container {
  display: none;
  width: 100%;
  max-width: 1600px;
  padding: 1rem;
  margin: 0 auto;
  position: relative;
  z-index: 10;
  /* Grid layout: header at top, main below */
  display: grid;
  grid-template-rows: auto 1fr;
  grid-template-areas:
    "header"
    "main";
  gap: 1rem;
  height: 100dvh; /* Exact viewport height */
  max-width: 100vw;
  overflow-y: auto; /* Scroll internally */
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding-bottom: calc(1rem + env(safe-area-inset-bottom));
  padding-left: calc(1rem + env(safe-area-inset-left));
  padding-right: calc(1rem + env(safe-area-inset-right));
}

.app-container.visible {
  display: grid; /* Override display:none with grid, not flex */
  animation: fadeIn 0.8s ease;
}

header {
  grid-area: header;
  text-align: center;
  position: relative;
  z-index: 100;
  padding: calc(0.5rem + env(safe-area-inset-top)) 1rem 0.5rem 1rem;
  background: transparent;
  width: 100%;
}

.header-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  position: relative;
  padding: 0.5rem 0;
}

.header-left {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.header-right {
  display: flex;
  align-items: center;
  position: relative;
  flex-shrink: 0;
}

/* Branding - Centered */
.branding {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  flex: 1;
  text-align: center;
}

/* Options Dropdown */
/* Header Buttons (Glass Style) */
.back-btn,
.options-btn {
  background: rgba(255, 255, 255, 0.03); /* Almost clear */
  border: 1px solid var(--glass-border);
  color: var(--text-dim);
  padding: 0.5rem 1rem;
  border-radius: 12px;
  cursor: pointer;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  transition: all 0.2s;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.back-btn:hover,
.options-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: white;
  border-color: white;
  box-shadow: 0 0 15px rgba(255, 255, 255, 0.2);
  transform: translateY(-1px);
}

.options-dropdown {
  position: absolute;
  top: calc(100% + 0.5rem);
  right: 0;
  background: rgba(
    30,
    27,
    30,
    0.85
  ); /* Slightly darker glass for readability */
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--glass-border);
  border-radius: 12px;
  padding: 0.5rem 0;
  min-width: 220px;
  z-index: 100;
  display: none;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}
.options-dropdown.visible {
  display: block;
}
.dropdown-item {
  padding: 0.75rem 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--text-main);
  font-size: 0.9rem;
  transition: background 0.2s;
}
.dropdown-item:hover {
  background: rgba(255, 255, 255, 0.1);
}
.dropdown-item .icon {
  font-size: 1.1rem;
  width: 1.5rem;
  text-align: center;
}
.dropdown-divider {
  border: none;
  border-top: 1px solid var(--glass-border);
  margin: 0.5rem 0;
}
.dropdown-item select {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid var(--glass-border);
  color: white;
  padding: 0.3rem 0.5rem;
  border-radius: 6px;
  font-size: 0.8rem;
  margin-left: auto;
}

/* Mobile Header Responsiveness */
@media (max-width: 768px) {
  .header-top {
    width: 100%;
    padding: 0 0.5rem;
    box-sizing: border-box;
  }
  .header-left {
    flex-shrink: 0;
  }
  .header-controls {
    flex-shrink: 0;
    align-items: flex-end;
  }
  .toggle-btn,
  .select-custom {
    font-size: 0.75rem;
    padding: 0.4rem 0.6rem;
  }
  .mute-toggle {
    width: 38px;
    height: 38px;
    font-size: 1rem;
  }
  .back-btn {
    padding: 0.4rem 0.8rem;
    font-size: 0.8rem;
  }
}

@media (max-width: 480px) {
  .header-top {
    padding: 0 0.25rem;
    gap: 0.5rem;
  }
  .toggle-btn,
  .select-custom {
    font-size: 0.7rem;
    padding: 0.35rem 0.5rem;
  }
  .mute-toggle {
    width: 32px;
    height: 32px;
    font-size: 0.9rem;
  }
  .back-btn {
    padding: 0.35rem 0.6rem;
    font-size: 0.75rem;
  }
  #smartModeControls .toggle-btn {
    font-size: 0.65rem;
    padding: 0.3rem 0.4rem;
  }
}
.back-btn {
  position: relative;
  /* absolute removed */
  transform: none;
  top: auto;
  left: auto;
  background: transparent;
  border: 1px solid var(--glass-border);
  color: var(--text-dim);
  padding: 0.5rem 1rem;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.9rem;
  transition: all 0.2s;
}
.back-btn:hover {
  color: white;
  border-color: white;
}

.mute-toggle {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  width: 45px;
  height: 45px;
  border-radius: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  transition: all 0.3s;
  font-size: 1.2rem;
  padding: 0;
}

.mute-toggle:hover {
  background: rgba(255, 255, 255, 0.1);
  transform: scale(1.1);
}

.mute-toggle.muted {
  opacity: 0.6;
}

header h1 {
  font-size: 3.5rem;
  font-weight: 800;
  background: linear-gradient(to right, #fff, var(--primary));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: -0.02em;
  text-shadow: 0 0 30px var(--primary-glow);
  transition: all 0.8s ease;
  line-height: 1;
}

.subtitle {
  color: var(--text-dim);
  font-size: 1.1rem;
  text-transform: uppercase;
  letter-spacing: 0.3em;
  margin-top: 0.2rem;
  font-weight: 300;
  margin-left: 2px;
}

main {
  grid-area: main;
  display: flex;
  flex-wrap: wrap;
  gap: 1rem; /* Reduced gap to allow wheel to expand more */
  justify-content: center;
  align-items: flex-start;
  align-content: flex-start; /* Pack items at top */
  position: relative;
  z-index: 5; /* Below wheel components and header */
  width: 100%;
  padding: 0 0.5rem; /* Minimal padding */
}

/* Portrait orientation: stack vertically (screen taller than wide) */
@media (orientation: portrait) {
  main {
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    padding: 0 0.5rem;
    gap: 1rem;
    height: auto;
    min-height: min-content;
  }

  .app-container {
    height: 100dvh;
    overflow-y: auto;
    overflow-x: hidden;
  }

  /* Remove nested scroll on portrait - let the app-container handle all scrolling */
  #itemList {
    max-height: none;
    overflow-y: visible;
  }
}

/* Wheel Styles */
.wheel-section {
  flex: 2; /* Increased to prioritize wheel size */
  min-width: min(300px, 100%);
  max-width: 100%; /* Allow full width when needed */
  width: 100%; /* Ensure it tries to fill space */
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  margin-bottom: 0.5rem;
  position: relative;
  z-index: 10;
}

.wheel-wrapper {
  position: relative;
  width: min(calc(100vh - 120px), 100%); /* Size by viewport height, capped at container width */
  max-width: min(1400px, calc(100vw - 0.5rem));
  background: var(--glass-bg);
  border-radius: 50%;
  --wheel-pad: clamp(8px, 2.5vmin, 15px);
  padding: var(--wheel-pad);
  box-shadow:
    0 0 50px rgba(0, 0, 0, 0.5),
    inset 0 0 20px var(--glass-border);
  border: clamp(1px, 0.4vmin, 2px) solid var(--glass-border);
  display: flex;
  justify-content: center;
  align-items: center;
  aspect-ratio: 1 / 1;
  z-index: 15;
  overflow: visible;
}

@media (max-width: 768px) {
  .wheel-wrapper {
    margin: 0 auto;
    width: 100%;
    max-width: min(100%, 65vh);
    max-height: 65vh; /* Reduced from 80vh to leave room for scrolling below */
    border: 4px solid var(--glass-border);
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    box-shadow:
      0 0 50px rgba(0, 0, 0, 0.5),
      inset 0 0 20px var(--glass-border);
    border-radius: 50%;
    aspect-ratio: 1 / 1;
  }
}

/* Responsive sizing for different screen dimensions */
@media (max-height: 800px) and (min-width: 801px) {
  .wheel-wrapper {
    max-width: min(
      90vh,
      calc(100vw - 0.5rem)
    ); /* Use more vertical space, minimal padding */
  }
}

@media (max-width: 1200px) {
  .wheel-wrapper {
    max-width: calc(100vw - 0.5rem); /* Nearly full width */
  }
}

#wheelCanvas {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  touch-action: none; /* Critical: let JS handle dragging, prevent native scroll/pan */
}

.wheel-pointer {
  position: absolute;
  z-index: 100;
  background: white;
  width: clamp(30px, 8vmin, 47px);
  height: clamp(40px, 10.5vmin, 62px);
  clip-path: polygon(100% 0, 0 0, 50% 100%);
  transition: all 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  /* Default Position (Top) — sits at outer edge of glass border */
  top: calc(var(--wheel-pad, 15px) * -1);
  left: 50%;
  transform: translateX(-50%);
  filter: drop-shadow(0 4px 12px rgba(244, 63, 94, 0.6));
  pointer-events: none;
}

/* Red fill inset by 2px to reveal the white border */
.wheel-pointer::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  right: 2px;
  bottom: 2px;
  background: var(--accent-1);
  clip-path: polygon(100% 0, 0 0, 50% 100%);
}

/* Position Classes (Override Media Queries) */
.wheel-pointer.pos-top {
  top: calc(var(--wheel-pad, 15px) * -1) !important;
  left: 50% !important;
  right: auto !important;
  transform: translateX(-50%) !important;
  filter: drop-shadow(0 4px 12px rgba(244, 63, 94, 0.6));
}

.wheel-pointer.pos-right {
  top: 50% !important;
  right: calc(var(--wheel-pad, 15px) * -1) !important;
  left: auto !important;
  transform: translateY(-50%) rotate(90deg) !important;
  filter: drop-shadow(-4px 0 12px rgba(244, 63, 94, 0.6));
}

.wheel-pointer.pos-center {
  top: 50% !important;
  left: 50% !important;
  right: auto !important;
  bottom: auto !important;
  transform: translate(-50%, -50%) !important;
  width: 40px !important;
  height: 40px !important;
  clip-path: none !important;
  background: transparent !important;
  filter: none !important;
  display: flex;
  justify-content: center;
  align-items: center;
}

.wheel-pointer.pos-center::before {
  content: "";
  position: absolute;
  width: 39px;
  height: 24px;
  background: white;
  clip-path: polygon(0 0, 0 100%, 100% 50%);
  top: 50%;
  left: 58px;
  transform: translateY(-50%);
  filter: drop-shadow(0 4px 5px rgba(0, 0, 0, 0.5));
}

.wheel-pointer.pos-center::after {
  content: "";
  position: absolute;
  width: 35px;
  height: 20px;
  background: var(--accent-1);
  clip-path: polygon(0 0, 0 100%, 100% 50%);
  top: 50%;
  left: 60px;
  right: auto;
  bottom: auto;
  transform: translateY(-50%);
  filter: none;
  border: none;
  box-shadow: none;
}

.wheel-pointer.pos-bottom {
  top: auto !important;
  bottom: calc(var(--wheel-pad, 15px) * -1) !important;
  left: 50% !important;
  right: auto !important;
  transform: translateX(-50%) rotate(180deg) !important;
  filter: drop-shadow(0 -4px 12px rgba(244, 63, 94, 0.6));
}

.wheel-pointer.pos-left {
  top: 50% !important;
  left: calc(var(--wheel-pad, 15px) * -1) !important;
  right: auto !important;
  bottom: auto !important;
  transform: translateY(-50%) rotate(-90deg) !important;
  filter: drop-shadow(4px 0 12px rgba(244, 63, 94, 0.6));
}

/* Transitions for smooth movement */
.wheel-pointer {
  transition:
    top 0.3s ease,
    left 0.3s ease,
    bottom 0.3s ease,
    right 0.3s ease,
    transform 0.3s ease;
}

/* ==================== AdSense Styling ==================== */
/* Ad Container Base Styles */
.ad-container,
.sticky-bottom-ad,
.sidebar-ad-container {
  background: rgba(30, 27, 30, 0.7);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--glass-border);
  border-radius: 12px;
  overflow: hidden;
  min-height: 50px;
  min-width: 320px;
}

/* Sticky Top Banner (formerly bottom) */
.sticky-bottom-ad {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  right: auto;
  width: auto;
  min-width: 320px;
  min-height: 50px;
  max-width: 90%;
  z-index: 2000;
  padding: 10px 15px;
  display: none;
  justify-content: center;
  align-items: center;
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.3); /* Toned down box-shadow */
  animation: slideDownCentered 0.6s cubic-bezier(0.2, 0.8, 0.2, 1);
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: var(--glass-bg);
  backdrop-filter: blur(10px);
  border-radius: 100px;
}

.sticky-bottom-ad.dismissed {
  animation: slideUpCentered 0.4s ease-in forwards;
}

@keyframes slideDownCentered {
  from {
    transform: translate(-50%, -150%);
    opacity: 0;
  }
  to {
    transform: translate(-50%, 0);
    opacity: 1;
  }
}

@keyframes slideUpCentered {
  to {
    transform: translate(-50%, -150%);
    opacity: 0;
  }
}

/* DOM pointer visible on screen; canvas draws its own pointer only for recordings */
.wheel-pointer {
  display: block !important;
}

/* Dismiss Button */
.ad-dismiss {
  position: absolute;
  top: 4px;
  right: 4px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: var(--text-dim);
  width: 24px;
  height: 24px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  z-index: 10;
  line-height: 1;
  padding: 0;
}

.ad-dismiss:hover {
  background: rgba(255, 255, 255, 0.2);
  color: white;
  transform: scale(1.1);
}

/* Sidebar Ad removed — using Google Auto Ads */

/* Ensure main content wraps properly with sidebar */
@media (min-width: 1400px) {
  main {
    display: flex;
    flex-wrap: nowrap;
    justify-content: center;
    gap: 0; /* No gap, margin on sidebar handles spacing */
  }

  .wheel-section,
  .side-panel {
    flex-shrink: 1;
  }
}

/* Adjust main padding when top ad is visible */
body.bottom-ad-visible .app-container {
  padding-top: 110px; /* Space for top banner */
}

/* Ensure ads don't interfere with wheel */
.wheel-section {
  position: relative;
  z-index: 20;
}

/* Ad containers below modals, above background */
.sticky-bottom-ad {
  z-index: 50;
}

.modal-overlay {
  z-index: 100 !important;
}

#spinBtn {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: clamp(50px, 14vmin, 80px);
  height: clamp(50px, 14vmin, 80px);
  background: var(--primary);
  border: clamp(2px, 0.6vmin, 4px) solid rgba(255, 255, 255, 0.1);
  border-radius: 50%;
  cursor: pointer;
  font-weight: 800;
  font-size: clamp(0.6rem, 1.4vmin, 0.8rem);
  color: white;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.4);
  z-index: 5;
  transition: all 0.2s ease;
  display: flex;
  justify-content: center;
  align-items: center;
}

#spinBtn:hover {
  transform: translate(-50%, -50%) scale(1.1);
  box-shadow: 0 15px 30px rgba(0, 0, 0, 0.5);
}

#spinBtn:active {
  transform: translate(-50%, -50%) scale(0.95);
}

/* Toggle Pill */
.toggle-btn {
  padding: 0.2rem 0.6rem;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid var(--glass-border);
  color: var(--text-dim);
  text-transform: uppercase;
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  border-radius: 20px;
  margin-top: 5px;
  cursor: pointer;
}
.toggle-btn:hover {
  background: rgba(255, 255, 255, 0.2);
}
.toggle-btn.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

.select-custom {
  outline: none;
  text-align: center;
  -webkit-appearance: none;
  appearance: none;
}

/* Side Panel / List */
.side-panel {
  flex: 1 1 350px;
  width: 100%;
  max-width: 500px; /* Default cap for medium screens */
  z-index: 8; /* Below wheel and header, above main */
  position: relative;
  /* Padding removed, relying on flow */
}

/* On wide desktop, let the panel expand to fill remaining space */
@media (min-width: 1024px) {
  .side-panel {
    max-width: none; /* Remove cap - grow to fill available width */
    flex: 1 1 400px;
  }
}

@media (max-width: 1000px) {
  .side-panel {
    max-width: 100%;
  }
}

/* Landscape: keep wheel and panel side-by-side, wheel gets more room */
@media (orientation: landscape) {
  main {
    flex-wrap: nowrap;
    align-items: flex-start;
    gap: 3rem; /* Add clear padding between wheel and list */
    padding: 0 2rem; /* Add breathing room around the edges */
  }

  .wheel-section {
    flex: 1 1 55%;
    min-width: 0;
  }

  .side-panel {
    flex: 1 1 45%;
    min-width: 0;
  }

  .wheel-wrapper {
    max-width: 100%;
  }
}

.panel-glass {
  background: var(--glass-bg);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
  border: 1px solid var(--glass-border);
  padding: 2rem;
  border-radius: 32px;
  /* height: 100%; removed to prevent forcing overlap */
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
}

h2 {
  margin-bottom: 1.5rem;
  font-size: 1.5rem;
  font-weight: 700;
}

.input-group {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
}

input[type="text"] {
  flex: 1;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--glass-border);
  padding: 0.8rem 1rem;
  border-radius: 12px;
  color: white;
  font-size: 1rem;
  user-select: auto;
  -webkit-user-select: auto;
}

.filter-select {
  width: 100%;
  border: 1px solid var(--glass-border);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-dim);
  border-radius: 12px;
  padding: 0.8rem 1rem;
  cursor: pointer;
  margin-bottom: 1rem;
}

input[type="text"]:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-glow);
}

.curation-banner {
  background: var(--accent-3);
  color: white;
  padding: 0.5rem;
  text-align: center;
  border-radius: 8px;
  margin-bottom: 1rem;
  font-size: 0.9rem;
  display: none;
  animation: fadeInDown 0.3s ease;
}

.curating .curation-banner {
  display: block;
}
.curating .input-group,
.curating .remove-btn,
.curating .read-status-btn,
.curating .action-icon-btn {
  display: none !important;
}
.curating .item-node {
  cursor: pointer;
  border: 1px solid transparent;
}
.curating .item-node:hover {
  background: rgba(255, 255, 255, 0.1);
}
.curating .item-node.selected {
  background: var(--primary-glow);
  border-color: var(--primary);
}

.curate-check-indicator {
  display: none;
  color: var(--primary);
  font-weight: bold;
  font-size: 1.2rem;
  margin-right: 10px;
}
.curating .item-node.selected .curate-check-indicator {
  display: block;
}

button {
  padding: 0.8rem 1.5rem;
  border-radius: 12px;
  border: none;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

#addItemBtn {
  background: var(--primary);
  color: white;
}
#addItemBtn:hover {
  background: #be185d;
  box-shadow: 0 0 15px var(--primary-glow);
}

#itemList {
  list-style: none;
  max-height: 400px;
  overflow-y: auto;
  margin-bottom: 2rem;
  padding-right: 5px;
}

#itemList::-webkit-scrollbar {
  width: 6px;
}
#itemList::-webkit-scrollbar-thumb {
  background: var(--glass-border);
  border-radius: 3px;
}

.item-node {
  background: rgba(255, 255, 255, 0.03);
  padding: 0.8rem 1rem;
  border-radius: 12px;
  margin-bottom: 0.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border: 1px solid transparent;
  transition: all 0.2s;
}
.item-node:hover {
  background: rgba(255, 255, 255, 0.07);
  border-color: var(--glass-border);
}

.remove-btn,
.action-icon-btn {
  background: none;
  border: none;
  padding: 8px;
  cursor: pointer;
  transition: all 0.2s;
  font-size: 1.1rem;
}
.remove-btn {
  color: #f43f5e;
  opacity: 0.7;
}
.remove-btn:hover {
  color: #ff0000;
  opacity: 1;
  transform: scale(1.2);
}

.action-icon-btn {
  color: #3b82f6;
  opacity: 0.7;
}
.action-icon-btn:hover {
  color: #60a5fa;
  opacity: 1;
  transform: scale(1.2);
}

.actions {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}
.actions button {
  width: 100%;
}

.primary {
  background: var(--primary);
  color: white;
}
.secondary {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-dim);
}
.secondary:hover {
  background: rgba(255, 255, 255, 0.1);
  color: white;
}

/* Read/Status Button */
.read-status-btn {
  background: none;
  border: 1px solid var(--text-dim);
  border-radius: 50%;
  width: 24px;
  height: 24px;
  padding: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  color: transparent;
  flex-shrink: 0;
  transition: all 0.2s;
}
.read-status-btn:hover {
  border-color: var(--accent-2);
}
.read-status-btn.checked {
  background: var(--accent-2);
  border-color: var(--accent-2);
  color: white;
}

.item-left {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  overflow: hidden;
}
.item-text {
  cursor: pointer;
  transition: color 0.2s;
  display: block;
  position: relative;
  z-index: 1;
}
.item-text:hover {
  color: var(--accent-1);
  text-decoration: underline;
}
.item-text.done {
  text-decoration: line-through;
  color: var(--text-dim);
  font-style: italic;
}

/* Winner Announcement */
.winner-announcement {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: linear-gradient(145deg, var(--bg-dark), rgba(0, 0, 0, 0.9));
  -webkit-backdrop-filter: blur(25px);
  backdrop-filter: blur(25px);
  padding: 3rem;
  border-radius: 40px;
  box-shadow:
    0 0 100px var(--primary-glow),
    0 0 0 1px var(--glass-border);
  border: 1px solid var(--primary-glow);
  z-index: 2500;
  animation: popIn 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
  text-align: center;
  width: 95%;
  max-width: 800px;
  display: flex;
  gap: 2rem;
  align-items: center;
  /* Dynamic Gradient Overlay */
  background-image: linear-gradient(
    to right bottom,
    var(--primary-glow),
    rgba(0, 0, 0, 0.95),
    rgba(0, 0, 0, 0.98)
  );
}

.winner-cover {
  flex: 0 0 240px;
  height: 360px;
  background: #2a2a2a;
  border-radius: 12px;
  box-shadow: 0 10px 40px var(--primary-glow);
  overflow: hidden;
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  border: 1px solid var(--glass-border);
}
.winner-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.winner-details {
  flex: 1;
  text-align: left;
  display: flex;
  flex-direction: column;
}

.winner-label {
  color: var(--primary);
  text-transform: uppercase;
  letter-spacing: 0.3em;
  font-weight: 800;
  font-size: 0.9rem;
  margin-bottom: 0.5rem;
}

.winner-announcement h2 {
  color: white;
  font-size: clamp(1.4rem, 3vw, 2.5rem);
  margin-bottom: 1rem;
  line-height: 1.1;
}
.description-text {
  color: var(--text-dim);
  font-size: 1rem;
  line-height: 1.6;
  margin-bottom: 2rem;
  max-height: 180px;
  overflow-y: auto;
  padding-right: 10px;
}
.winner-actions {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}
.winner-actions a,
.winner-actions button {
  flex: 1;
  min-width: 140px;
}

.winner-announcement.fade-out {
  opacity: 0;
  transform: translate(-50%, -60%) scale(0.9);
  transition: all 0.6s ease;
}

@keyframes popIn {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.5);
  }
  100% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
}
@keyframes popInFlex {
  0% {
    opacity: 0;
    transform: scale(0.5);
  }
  100% {
    opacity: 1;
    transform: scale(1);
  }
}
@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@media (max-width: 800px) {
  .winner-announcement {
    flex-direction: column;
    padding: 2rem;
    max-height: 90vh;
    overflow-y: auto;
  }
  .winner-cover {
    flex: 0 0 200px;
    height: 300px;
  }
  /* Constrain wheel to fit below header - use 50vh max on mobile */

  .wheel-section {
    margin-top: 0;
    padding-top: 0;
  }
  .side-panel {
    flex: 1;
    margin-top: 0.5rem;
    width: 100%;
    max-width: 100%;
    margin-left: auto;
    margin-right: auto;
  }
  .panel-glass {
    padding: 1.5rem 1rem;
    width: 100%;
    max-width: 100%;
    margin: 0 auto;
    box-sizing: border-box;
  }
}

@media (max-width: 600px) {
  .mode-cards {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
    margin-top: 1.5rem;
  }
  .mode-card {
    width: 100%;
    padding: 1rem;
  }
  .mode-icon {
    font-size: 2.5rem;
  }
  .mode-title {
    font-size: 1rem;
  }

  /* Improved Header for Mobile */
  .header-top {
    flex-direction: column;
    gap: 0.5rem;
    align-items: flex-start;
    padding: 0 0.5rem;
  }

  .header-left {
    width: 100%;
    justify-content: space-between; /* Keep logo and hamburger separate if needed */
  }

  .header-controls {
    flex-direction: row;
    width: 100%;
    justify-content: flex-start;
    gap: 0.5rem;
    margin-top: 5px;
    flex-wrap: wrap;
  }

  .header-controls .toggle-btn,
  .header-controls .select-custom {
    font-size: 0.7rem;
    padding: 0.3rem 0.5rem;
  }

  /* Thinner wheel edge on mobile */

  header h1 {
    font-size: 2.2rem;
  }
  .landing-page h1 {
    font-size: 3rem !important;
  }
}

@media (max-width: 400px) {
  .mode-cards {
    gap: 0.5rem;
  }
  .mode-card {
    padding: 0.8rem;
  }
}

/* Streamer Mode via OBS */
body.streamer-mode {
  background: transparent !important;
  overflow: hidden;
}
body.streamer-mode .app-container {
  padding: 0;
  margin: 0;
  justify-content: center;
  align-items: center;
  height: 100vh;
}
body.streamer-mode header,
body.streamer-mode .side-panel,
body.streamer-mode .result-log,
body.streamer-mode .fairness-panel,
body.streamer-mode .fairness-toggle,
body.streamer-mode #spinBtn {
  /* Hide spin button if using hotkeys? Actually maybe keep button or hide it */
  /* Usually streamers want the wheel only */
  display: none !important;
}
/* Ensure wheel container is centered */
body.streamer-mode .wheel-wrapper {
  transform: scale(1.2); /* Make it bigger */
}

/* Custom Scrollbar */
::-webkit-scrollbar {
  width: 8px;
}
::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
}

/* Toast Notification */
.toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%) translateY(150px);
  background: rgba(30, 27, 30, 0.95);
  border: 1px solid var(--glass-border);
  color: white;
  padding: 1rem 2rem;
  border-radius: 50px;
  z-index: 1000;
  transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 10px;
}
.toast.visible {
  transform: translateX(-50%) translateY(0);
}

/* Custom Modal */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.6);
  -webkit-backdrop-filter: blur(5px);
  backdrop-filter: blur(5px);
  display: none;
  justify-content: center;
  align-items: center;
  z-index: 4000;
  animation: fadeIn 0.3s ease;
}
.modal-overlay.visible {
  display: flex;
}

.modal-card {
  background: rgba(30, 27, 30, 0.98);
  border: 1px solid var(--glass-border);
  padding: 2rem;
  border-radius: 24px;
  width: 90%;
  max-width: 400px;
  text-align: center;
  box-shadow: 0 25px 50px rgba(0, 0, 0, 0.5);
  animation: popInFlex 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

.modal-title {
  font-size: 1.5rem;
  margin-bottom: 0.5rem;
  color: white;
}
.modal-msg {
  color: var(--text-dim);
  margin-bottom: 1.5rem;
  line-height: 1.5;
}
.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
}
.modal-input {
  width: 100%;
  padding: 0.8rem;
  border-radius: 8px;
  border: 1px solid var(--glass-border);
  background: rgba(255, 255, 255, 0.05);
  color: white;
  margin-bottom: 1.5rem;
  font-size: 1rem;
}
.modal-input:focus {
  outline: none;
  border-color: var(--primary);
}

/* Presentation Mode Styles */
.presentation-mode header,
.presentation-mode .side-panel,
.presentation-mode .landing-page,
.presentation-mode .back-btn,
.presentation-mode .subtitle,
.presentation-mode footer {
  display: none !important;
}

.presentation-mode .app-container {
  padding: 0;
  margin: 0;
  max-width: 100vw;
  height: 100vh;
  justify-content: center;
  overflow: hidden;
}

.presentation-mode .wheel-section {
  flex: 1;
  width: 100%;
  height: 100%;
  justify-content: center;
  transform: scale(1.1); /* Slight zoom for impact */
}

/* Ensure modal is still usable in presentation mode */
.presentation-mode .winner-announcement {
  z-index: 9999;
}

/* Utilities for moving inline styles */
.landing-title {
  font-size: 5rem;
  margin-bottom: 0;
  font-weight: 800;
  font-family: "Playfair Display", serif;
  background: linear-gradient(to right, #fff, var(--primary));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  text-shadow: 0 0 50px var(--primary-glow);
  animation: fadeIn 2s ease-out;
}
.landing-subtitle {
  color: var(--text-dim);
  font-size: 1.2rem;
  margin-top: 1rem;
  letter-spacing: 0.2rem;
  text-transform: uppercase;
}
.header-controls {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
}
.guide-btn {
  font-size: 1rem;
  font-weight: bold;
}
.filter-group {
  margin-bottom: 1rem;
  display: flex;
  gap: 1rem;
}
.flex-1-5 {
  flex: 1.5;
}
.flex-1 {
  flex: 1;
}
.no-margin-bottom {
  margin-bottom: 0;
}
.curate-btn-custom {
  border: 1px solid var(--accent-1);
  color: var(--accent-1);
}
.curation-controls-group {
  display: none;
  gap: 0.5rem;
  flex-direction: column;
}
.hidden {
  display: none;
}
.share-section {
  margin-top: 1.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--glass-border);
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}
.share-title {
  font-size: 0.9rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: 0.2rem;
  margin-top: 1rem;
}
.record-btn-custom {
  font-size: 0.9rem;
  padding: 0.7rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.status-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #555;
  transition: all 0.3s;
}
.grid-2-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}
.share-btn-small {
  font-size: 0.8rem;
  padding: 0.6rem;
}

/* Utility Classes for Row Layouts */
.row-flex {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
}
.gap-05 {
  gap: 0.5rem;
}
.margin-t-05 {
  margin-top: 0.5rem;
}

/* Additional Utility Classes */
.flex-col {
  display: flex;
  flex-direction: column;
}
.flex-col-overflow {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.item-meta {
  font-size: 0.75rem;
  color: var(--text-dim);
}
.item-meta-upper {
  font-size: 0.75rem;
  color: var(--text-dim);
  text-transform: uppercase;
}
.loading-meta {
  font-size: 0.7rem;
  color: #fbbf24;
}
.actions-right {
  display: flex;
  align-items: center;
  gap: 20px;
}
.pointer-none {
  pointer-events: none;
}
.text-center {
  text-align: center;
}
.text-white {
  color: white;
}
.margin-b-1-5 {
  margin-bottom: 1.5rem;
}
.margin-b-2 {
  margin-bottom: 2rem;
}
.margin-b-0-5 {
  margin-bottom: 0.5rem;
}
.op-0-8 {
  opacity: 0.8;
}
.winner-links-group {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  width: 100%;
  margin-bottom: 1.5rem;
}
.winner-btn-small {
  font-size: 0.85rem;
  padding: 6px 12px;
}
.winner-cover-placeholder {
  color: #666;
  flex-direction: column;
}
.winner-cover-placeholder span {
  font-size: 3rem;
}
.display-block {
  display: block;
}
.justify-center {
  justify-content: center;
}
.max-w-600 {
  max-width: 600px;
}
.max-h-85 {
  max-height: 85vh;
}
.overflow-y-auto {
  overflow-y: auto;
}
.text-left {
  text-align: left;
}
.padding-2-5 {
  padding: 2.5rem;
}
.font-2rem {
  font-size: 2rem;
}
.color-primary {
  color: var(--primary);
}
.flex {
  display: flex;
}
.gap-10 {
  gap: 10px;
}
.no-decoration {
  text-decoration: none;
}
.margin-b-1 {
  margin-bottom: 1rem;
}
.padding-l-1-5 {
  padding-left: 1.5rem;
}
.code-block {
  background: rgba(0, 0, 0, 0.3);
  padding: 1rem;
  border-radius: 8px;
  font-size: 0.8rem;
  color: #a78bfa;
  overflow-x: auto;
  font-family: monospace;
}
.list-disc {
  list-style: disc;
}

/* Continent Selector Styles */
.continent-selector {
  display: none;
  margin-bottom: 1.5rem;
  background: rgba(255, 255, 255, 0.05);
  padding: 1rem;
  border-radius: 12px;
  border: 1px solid var(--glass-border);
}
.continent-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 0.8rem;
}
.continent-btn {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--glass-border);
  color: white;
  padding: 0.5rem;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.85rem;
  transition: all 0.3s;
}
.continent-btn:hover {
  border-color: transparent;
  filter: brightness(1.15);
}
.continent-btn.active {
  border-color: transparent;
  box-shadow: 0 0 15px rgba(0, 0, 0, 0.3);
  filter: brightness(1.1);
}

/* Per-region globe-inspired colours — only when active */
.continent-btn:nth-child(1).active {
  background: #c2884d;
} /* Africa — sandy gold */
.continent-btn:nth-child(2).active {
  background: #c0392b;
} /* Asia — deep red */
.continent-btn:nth-child(3).active {
  background: #2e6fba;
} /* Europe — royal blue */
.continent-btn:nth-child(4).active {
  background: #27864a;
} /* N. America — forest green */
.continent-btn:nth-child(5).active {
  background: #1fa87e;
} /* S. America — emerald */
.continent-btn:nth-child(6).active {
  background: #1596a8;
} /* Oceania — ocean cyan */
.continent-btn:nth-child(7).active {
  background: #7e57c2;
} /* The World — purple */

.continent-btn.text-danger-light {
  color: #fca5a5;
}
.continent-label {
  font-size: 0.8rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

/* History List Styles */
.history-list {
  list-style: none;
  padding: 0;
  margin-top: 1rem;
  max-height: 300px;
  overflow-y: auto;
}
.history-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px;
  border-bottom: 1px solid var(--glass-border);
  text-align: left;
}
.history-item:last-child {
  border-bottom: none;
}
.history-item img {
  width: 40px;
  height: 50px;
  object-fit: cover;
  border-radius: 4px;
  background: #333;
}
.history-info {
  flex: 1;
}
.history-name {
  font-weight: 600;
  color: white;
  display: block;
}
.history-date {
  font-size: 0.75rem;
  color: var(--text-dim);
}
.history-empty {
  padding: 2rem;
  color: var(--text-dim);
  font-style: italic;
  text-align: center;
}

.winner-cover {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 24px;
  overflow: hidden;
  min-height: 250px;
  border: 1px solid var(--glass-border);
}
.winner-cover img {
  max-width: 100%;
  max-height: 450px;
  object-fit: contain;
}
/* Accessibility Class */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}
@media (min-width: 2000px) {
  .app-container {
    max-width: 95vw;
  }
  .wheel-wrapper,
  .side-panel {
    max-width: 85vh;
  }
}

/* Landing Page Styles */
.landing-title {
  font-size: 4rem;
  margin-bottom: 0.5rem;
  text-align: center;
  background: linear-gradient(to right, #fff, #f472b6);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
.landing-subtitle {
  color: var(--text-dim);
  font-size: 1.2rem;
  margin-bottom: 2rem;
}
.help-btn-landing {
  margin-top: 3rem;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: white;
  padding: 0.8rem 2rem;
  font-weight: 400;
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  transition: all 0.3s;
}
.help-btn-landing:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: translateY(-2px);
}

.help-btn-landing:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: translateY(-2px);
}

/* Help Modal Styles */
.modal-help-content {
  max-width: 500px;
  text-align: center;
}
.help-modal-title {
  margin-bottom: 1rem;
}
.help-list {
  text-align: left;
  opacity: 0.9;
  line-height: 1.6;
}
.help-tip {
  margin-top: 1rem;
  font-size: 0.9rem;
  color: var(--text-dim);
}
.help-got-it-btn {
  margin-top: 2rem;
  width: 100%;
}

/* Compact Smart Mode Toggle (Header) */
.smart-mode-compact {
  display: none; /* Hidden by default, shown only in custom mode */
  background: rgba(99, 102, 241, 0.2);
  border: 1px solid rgba(99, 102, 241, 0.4);
  color: white;
  padding: 0.4rem 0.8rem;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s;
  white-space: nowrap;
  margin-left: 0.5rem;
}
.smart-mode-compact:hover {
  background: rgba(99, 102, 241, 0.4);
  transform: scale(1.05);
}
.smart-mode-compact.active {
  background: rgba(99, 102, 241, 0.5);
  border-color: rgba(99, 102, 241, 0.8);
  box-shadow: 0 0 10px rgba(99, 102, 241, 0.3);
}
.smart-mode-compact.visible {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}

/* Custom Mode Help Modal */
.custom-mode-modal {
  max-width: 450px;
  text-align: left;
}
.custom-mode-modal h2 {
  text-align: center;
  margin-bottom: 1.5rem;
}
.custom-mode-modal .feature-list {
  background: rgba(255, 255, 255, 0.05);
  border-radius: 12px;
  padding: 1rem;
  margin-bottom: 1rem;
}
.custom-mode-modal .feature-item {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
  align-items: flex-start;
}
.custom-mode-modal .feature-item:last-child {
  margin-bottom: 0;
}
.custom-mode-modal .feature-icon {
  font-size: 1.2rem;
  flex-shrink: 0;
}
.custom-mode-modal .feature-text {
  font-size: 0.9rem;
  line-height: 1.4;
  opacity: 0.9;
}
.custom-mode-modal .mode-tip {
  background: rgba(99, 102, 241, 0.15);
  border-left: 3px solid var(--primary);
  padding: 0.75rem;
  border-radius: 0 8px 8px 0;
  font-size: 0.85rem;
  margin-bottom: 1.5rem;
}
/* Mobile Header Layout Fix (Override) */
@media (max-width: 768px) {
  .header-top {
    flex-direction: row; /* Horizontal layout */
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem;
    gap: 0.5rem;
  }
  .header-left {
    width: auto; /* Allow it to shrink to button size */
    display: block;
    position: static;
    margin-bottom: 0;
  }
  .back-btn {
    position: static;
    margin: 0;
  }
  .branding {
    flex: 1; /* Take up remaining space */
    display: flex;
    flex-direction: column;
    align-items: center; /* Center title in available space */
    /* If there's overlap, we might need text-align: left or right */
  }
  header h1 {
    font-size: 1.5rem; /* Compact font size */
    line-height: 1;
    margin: 0;
  }
  .subtitle {
    font-size: 0.7rem;
    margin: 0;
  }
  .header-controls {
    width: 100%; /* Controls on new line if needed? Or width auto to sit on right? */
    /* Let's try to put controls on the right if they fit, or wrap */
    width: auto;
    justify-content: flex-end;
    gap: 0.5rem;
  }

  /* Force controls to new line if screen is very narrow? */
  /* Actually user wants title next to menu. */
}

/* ==================== Color Swatch Picker ==================== */
.swatch-label {
  font-size: 0.8rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-top: 0.75rem;
  margin-bottom: 0.4rem;
}

.swatch-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  max-height: 120px;
  overflow-y: auto;
  padding: 4px 0;
}

.color-swatch {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid transparent;
  transition:
    transform 0.15s,
    border-color 0.15s;
  flex-shrink: 0;
}

.color-swatch:hover {
  transform: scale(1.2);
  border-color: rgba(255, 255, 255, 0.5);
}

.color-swatch.selected {
  border-color: white;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.4);
  transform: scale(1.15);
}

/* Palette Editor (in Options dropdown) */
.palette-editor {
  padding: 0.5rem 0.75rem;
}

.palette-editor .swatch-grid {
  max-height: 90px;
}

.palette-swatch {
  position: relative;
}

.palette-swatch .remove-swatch {
  position: absolute;
  top: -5px;
  right: -5px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #ef4444;
  color: white;
  font-size: 9px;
  line-height: 14px;
  text-align: center;
  cursor: pointer;
  display: none;
  border: none;
  padding: 0;
}

.palette-swatch:hover .remove-swatch {
  display: block;
}

.add-swatch-btn {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px dashed rgba(255, 255, 255, 0.3);
  background: transparent;
  color: rgba(255, 255, 255, 0.5);
  font-size: 16px;
  line-height: 22px;
  cursor: pointer;
  transition:
    border-color 0.2s,
    color 0.2s;
  flex-shrink: 0;
}

.add-swatch-btn:hover {
  border-color: white;
  color: white;
}

/* ==================== Foldable & Mobile Layout Fixes ==================== */

/*
  RESPONSIVE STRATEGY — works on any screen, any device:
  - Landing page mode cards use CSS Grid with auto-fit
  - Content uses percentage-based max-widths and clamp() for fluid typography
  - Breakpoints only for structural layout changes

  Screen tiers:
    <380px   = Fold cover / ultra-narrow (2-col compact grid, scroll enabled)
    380-599px = Regular phones (2-col grid, comfortable spacing)
    600-899px = Fold internal / large phones (3-col grid)
    900px+    = Tablets / Desktop (auto-fit, up to 6 across)
*/

/* --- Base responsive: make mode cards a responsive grid --- */
.mode-cards {
  display: grid !important;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 1rem;
  margin-top: 2rem;
  width: 100%;
  max-width: 1200px;
  padding: 0 1rem;
}

.mode-card {
  width: auto;
  max-width: none;
}

/* Fluid typography for SEO content */
.seo-container {
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.seo-container h2 {
  font-size: clamp(1.5rem, 4vw, 2.2rem);
}

.seo-container h3 {
  font-size: clamp(1.1rem, 3vw, 1.5rem);
}

/* --- Tier 1: Ultra-narrow / Fold cover screen (<380px) --- */
@media (max-width: 380px) {
  .app-container {
    padding: 0.25rem 0 !important;
  }

  main {
    padding: 0 !important;
  }

  .wheel-wrapper {
    margin: 0 !important;
    width: 100vw !important;
    max-width: min(100vw, 60vh) !important;
    max-height: 60vh !important;
    border-radius: 50%;
    aspect-ratio: 1 / 1;
  }

  .wheel-section {
    width: 100%;
    align-items: center;
    justify-content: center;
    padding: 0;
  }

  header h1 {
    font-size: 1.6rem;
  }

  header {
    padding: 0.25rem 0.5rem !important;
  }

  .landing-page {
    justify-content: flex-start;
    padding: 1rem 0;
  }

  .landing-title {
    font-size: 2rem !important;
    margin-bottom: 0.25rem;
  }

  .landing-subtitle {
    font-size: 0.9rem;
    margin-bottom: 0.5rem;
  }

  .mode-cards {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5rem;
    padding: 0 0.5rem;
    margin-top: 1rem;
    width: 100%;
    max-width: 100vw;
  }

  .mode-card {
    padding: 0.75rem 0.5rem;
    border-radius: 16px;
    gap: 0.4rem;
  }

  .mode-icon {
    font-size: 1.8rem;
  }

  .mode-title {
    font-size: 0.8rem;
  }

  .mode-desc {
    font-size: 0.6rem;
  }

  .help-btn-landing {
    margin-top: 0.75rem;
    padding: 0.4rem 1.2rem;
    font-size: 0.8rem;
  }

  .seo-content-section {
    padding: 2rem 0.75rem !important;
  }

  .seo-container {
    font-size: 0.9rem !important;
  }

  .site-footer {
    padding: 1.5rem 0.75rem;
  }

  .footer-links {
    gap: 0.75rem;
    font-size: 0.85rem;
  }
}

/* --- Tier 2: Small phones (381-599px) --- */
@media (min-width: 381px) and (max-width: 599px) {
  .mode-cards {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
    padding: 0 1rem;
    width: 100%;
  }

  .mode-card {
    padding: 1.25rem 0.75rem;
  }

  .mode-icon {
    font-size: 2.2rem;
  }

  .landing-title {
    font-size: 2.5rem !important;
  }
}

/* --- Tier 3: Fold internal / large phones (600-899px) --- */
@media (min-width: 600px) and (max-width: 899px) {
  .landing-page {
    justify-content: flex-start;
  }

  .landing-title {
    font-size: 3.5rem !important;
  }

  .mode-cards {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
    max-width: 650px;
    padding: 0 2rem;
    width: 100%;
  }

  .mode-card {
    padding: 1.5rem 1rem;
  }

  .mode-icon {
    font-size: 2.5rem;
  }

  .seo-content-section {
    padding: 3rem 2rem;
  }

  .footer-links {
    gap: 2rem;
  }
}

/* --- Tier 4: Tablets / Desktop (900px+) --- */
@media (min-width: 900px) {
  .mode-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 200px));
    gap: 1.5rem;
    justify-content: center;
    width: 100%;
  }

  .mode-card {
    padding: 2rem 1.5rem;
  }

  .mode-icon {
    font-size: 3.5rem;
  }
}

/* --- Portrait wheel sizing (phones/tablets/unfolded) --- */
@media (min-width: 380px) and (max-width: 1024px) and (orientation: portrait) {
  .wheel-wrapper {
    /* Limit the wheel on very tall portrait items to leave room, but let it scroll if needed */
    max-height: 70vh !important;
    max-width: min(100%, 70vh) !important;
    margin: 0 auto;
  }

  .wheel-section {
    flex: 0 0 auto;
    margin-bottom: 1rem;
  }

  .side-panel {
    max-width: 90%;
    margin: 0 auto;
    /* Remove max-height constraints here to let the page scroll the panel naturally */
    overflow-y: visible;
  }
}

/* --- Landscape mobile / Fold unfolded landscape --- */
@media (max-height: 600px) and (orientation: landscape) {
  .app-container {
    height: 100vh;
    grid-template-rows: auto 1fr;
    overflow: hidden;
  }

  main {
    flex-direction: row !important;
    flex-wrap: nowrap !important;
    align-items: stretch;
    justify-content: center;
    height: 100%;
    overflow: hidden;
    padding: 0 1rem 1rem 1rem;
    gap: 1rem;
  }

  .wheel-section {
    flex: 0 0 auto;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100%;
    margin-bottom: 0;
    max-width: 50vw;
  }

  .wheel-wrapper {
    height: auto;
    width: auto;
    max-height: min(100%, 80vh);
    max-width: min(100%, 80vh);
    aspect-ratio: 1 / 1;
    margin: 0 !important;
  }

  .side-panel {
    flex: 1 1 300px;
    max-width: 50vw;
    max-height: 100%;
    overflow-y: auto;
    margin: 0 !important;
  }

  .panel-glass {
    padding: 1rem;
  }

  #itemList {
    max-height: 30vh;
    overflow-y: auto;
  }

  .header-top {
    padding: 0.25rem 1rem;
  }
  .branding h1 {
    font-size: 1.5rem;
  }
  .branding .subtitle {
    display: none;
  }

  /* Landscape landing: compact cards */
  .mode-cards {
    grid-template-columns: repeat(3, 1fr);
    max-width: 700px;
    gap: 0.75rem;
  }

  .mode-card {
    padding: 0.75rem 0.5rem;
    gap: 0.3rem;
  }

  .mode-icon {
    font-size: 1.8rem;
  }

  .mode-title {
    font-size: 0.8rem;
  }

  .mode-desc {
    font-size: 0.6rem;
  }
}

/* Scanner Active State */
body.scanner-active {
  background: transparent !important;
}
body.scanner-active .app-container {
  display: none !important;
}

/* ==================== SEO Text Content & Footer ==================== */
.seo-content-section {
  width: 100%;
  padding: 4rem 2rem;
  z-index: 5;
  position: relative;
  display: flex;
  justify-content: center;
  margin-top: 2rem;
  background: transparent;
  border-top: 1px solid rgba(255, 255, 255, 0.05); /* very subtle separator */
}

.seo-container {
  max-width: 800px;
  width: 100%;
  color: var(--text-dim);
  line-height: 1.8;
  font-size: 1.05rem;
}

.seo-container h2 {
  font-size: 2.2rem;
  color: var(--text-main);
  margin-bottom: 1.5rem;
  font-family: "Playfair Display", serif;
}

.seo-container h3 {
  font-size: 1.5rem;
  color: var(--text-main);
  margin-top: 2.5rem;
  margin-bottom: 1rem;
  font-family: "Playfair Display", serif;
}

.seo-container p {
  margin-bottom: 1.5rem;
}

.seo-container ul {
  list-style-type: none;
  padding-left: 0;
  margin-bottom: 1.5rem;
}

.seo-container ul li {
  margin-bottom: 0.8rem;
  padding-left: 1.5rem;
  position: relative;
}

.seo-container ul li::before {
  content: "✦";
  position: absolute;
  left: 0;
  color: var(--primary);
}

.site-footer {
  width: 100%;
  background: #111;
  border-top: 1px solid var(--glass-border);
  padding: 3rem 2rem;
  text-align: center;
  position: relative;
  z-index: 5;
}

.footer-container {
  max-width: 800px;
  margin: 0 auto;
}

.footer-links {
  display: flex;
  justify-content: center;
  gap: 1.5rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

.footer-links a {
  color: var(--text-main);
  text-decoration: none;
  font-weight: 500;
  transition: color 0.3s;
}

.footer-links a:hover {
  color: var(--primary);
}

.site-footer p {
  color: var(--text-dim);
  font-size: 0.9rem;
}

/* =========================================================================
   NATIVE MOBILE APP (.capacitor-app)
   ========================================================================= */
body.capacitor-app {
  /* Force vertical scroll on the app container, disable pull-to-refresh on body */
  overscroll-behavior-y: none;
}

.capacitor-app .app-container {
  height: 100dvh;
  overflow-y: auto;
  overflow-x: hidden;
  padding-bottom: 3rem; /* padding for scrolling past list */
}

/* Hide web-only elements */
.capacitor-app .seo-content-section,
.capacitor-app .site-footer,
.capacitor-app .sticky-bottom-ad,
.capacitor-app #fullscreenBtn,
.capacitor-app button[onclick="copyOBSLink()"] {
  display: none !important;
}

/* Landing Page (Mobile App Layout) */
.capacitor-app .landing-page {
  justify-content: flex-start;
  padding: 1rem 0;
  overflow-y: auto;
}

.capacitor-app .landing-title {
  font-size: 2.2rem !important;
  margin-top: 1rem;
}

.capacitor-app .mode-cards {
  display: grid !important;
  grid-template-columns: repeat(2, 1fr) !important;
  gap: 1rem !important;
  padding: 1rem 1.5rem !important;
  max-width: none !important;
  width: 100% !important;
}

.capacitor-app .mode-card {
  padding: 1.5rem 1rem !important;
}

/* Main App layout (Single column vertical flow) */
.capacitor-app main {
  display: flex !important;
  flex-direction: column !important;
  align-items: center !important;
  flex-wrap: nowrap !important;
  gap: 1.5rem !important;
  padding: 0 1rem !important;
  height: auto !important;
}

/* Header */
.capacitor-app header {
  padding: 0.5rem 1rem !important;
}

.capacitor-app .back-btn {
  padding: 0.4rem 0.6rem;
}
.capacitor-app .back-text {
  display: none; /* Hide 'Menu' text to save space */
}

/* Wheel - capped so list is visible below */
.capacitor-app .wheel-section {
  width: 100% !important;
  max-width: 100% !important;
  flex: none !important;
}

.capacitor-app .wheel-wrapper {
  margin: 0 auto;
  width: 100% !important;
  max-width: min(100%, 50vh) !important;
  max-height: 50vh !important;
  aspect-ratio: 1 / 1 !important;
}

/* Side Panel / List */
.capacitor-app .side-panel {
  max-width: 100% !important;
  width: 100% !important;
  flex: none !important;
}

.capacitor-app .panel-glass {
  padding: 1.5rem !important;
  border-radius: 24px !important;
  box-shadow: 0 10px 30px -10px rgba(0,0,0,0.5) !important;
}

.capacitor-app #itemList {
  max-height: none !important;
  overflow-y: visible !important;
}
