/* Main Menu Styles - Nordic Paper Theme */

/* Header */
.main-header {
  height: var(--header-height);
  width: 100% !important;
  max-width: none !important; /* Ensure no constraints */
  display: flexbox; /* Fallback */
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 20px;
  position: fixed;
  top: 0;
  left: 0;
  right: 0; /* Ensure spanning */
  margin: 0 !important; /* No gaps */
  z-index: 30000; /* Boost above Game Layers (20000+) */
  background: rgba(
    253,
    251,
    247,
    0.9
  ); /* Paper color with slight transparency */
  border-bottom: 1px solid var(--glass-border);
  backdrop-filter: blur(5px);
  /* Top corners straight, bottom corners rounded */
  border-radius: 0 0 12px 12px;
  box-sizing: border-box; /* Include padding in width */
  /* Ensure header acts as a reference for absolute centering */
}

/* Dark Mode Header */
body.dark-mode .main-header {
  background: rgba(30, 35, 41, 0.95) !important; /* Force override */
  border-bottom: 1px solid var(--glass-border);
  color: var(--text-main); /* Ensure text color is inherited/set */
  display: flex !important; /* Ensure visibility */
  opacity: 1 !important;
}

/* Header Alignment */
.header-left {
  display: flex;
  align-items: center; /* Or baseline */
  gap: 15px;
  flex: 1; /* Take up available space */
}

.app-title {
  font-size: 1.5rem; /* Slightly smaller to fit everything */
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--text-main);
  margin: 0;
  line-height: 1;
  white-space: nowrap;
}

.header-info {
  display: flex;
  gap: 8px;
  font-family: var(--font-main);
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-muted);
  align-items: center;
  white-space: nowrap;
}

#challenge-num {
  font-weight: 700;
  color: var(--accent-color);
  background: rgba(0, 0, 0, 0.05);
  padding: 2px 6px;
  border-radius: 4px;
}

/* Mobile: Adjust size but keep line if possible */
@media (max-width: 600px) {
  .app-title {
    font-size: 1.2rem;
  }
  .header-info {
    font-size: 0.8rem;
    gap: 5px;
  }
}

/* Very Small Screens: Hide Date */
@media (max-width: 425px) {
  #current-date {
    display: none;
  }
}

.btn-icon {
  font-size: 1.2rem;
  padding: 6px;
  border-radius: 50%;
  transition: all 0.2s;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--primary-color);
}

.btn-icon:hover {
  background: rgba(0, 0, 0, 0.05);
  color: var(--accent-color);
  transform: scale(1.05);
}

.header-right {
  display: flex;
  gap: 10px;
}

/* Menu Content Container */
/* Menu Content Container - SAFE ZONE */
.menu-container {
  /* Position safely between Header and Footer */
  margin-top: var(--header-height);
  height: calc(100dvh - var(--header-height) - var(--footer-height));
  min-height: 0; /* Allow flex shrinking if necessary */

  /* Centering Logic */
  display: flex;
  flex-direction: column;
  justify-content: center; /* Vertically center content in safe zone */
  align-items: center;

  padding: 0 20px; /* Horizontal padding only */
  gap: 20px;
  width: 100%;
  max-width: 800px;
  margin-left: auto;
  margin-right: auto;

  /* Ensure content doesn't overflow without scrolling if screen is weirdly small */
  overflow-y: auto;
  /* Hide scrollbar for cleaner look if content fits */
  scrollbar-width: none;
}

/* Wrapper for Tabs + Panels to bypass menu-container gap */
.tabs-group {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 600px; /* Keep consistent with panel/tabs */
  align-items: center; /* Center children */
  /* No gap here, so we control overlap precisely */
}

/* --- Home Tabs & Panels --- */
.home-tabs {
  display: flex;
  width: 100%;
  max-width: 600px;
  padding-left: 20px;
  margin-bottom: -1px; /* Minimal overlap to cover border */
  /* z-index: 10; REMOVED to allow interleaving with panels */
  position: relative;
}

.tab-btn {
  padding: 12px 24px;
  background: rgba(0, 0, 0, 0.05); /* Darker inactive state (Light Mode) */
  border: 1px solid transparent; /* Match glass border eventually */
  border-bottom: none;
  border-radius: 12px 12px 0 0;
  cursor: pointer;
  font-family: var(--font-paper);
  font-weight: 700;
  font-size: 1rem;
  color: var(--text-muted);
  transition: all 0.4s cubic-bezier(0.25, 0.8, 0.25, 1); /* Exact match with panel timing */
  position: relative;
  z-index: 5; /* Interleaved: Above Inactive Panel (2), Below Active Panel (15) */
  /* Visual depth for inactive tabs */
  box-shadow: inset 0 -5px 10px rgba(0, 0, 0, 0.05);

  /* Close the gap - INCREASED overlap */
  margin-right: -4px;
  /* Sync with Panel Deck Animation: Inactive tabs sit lower */
  transform: translateY(10px);
}

.tab-btn:hover {
  background: rgba(0, 0, 0, 0.1); /* Slightly darker on hover */
  color: var(--text-main);
}

/* Dark Mode Inactive Tab Fix */
body.dark-mode .tab-btn:not(.active) {
  background: rgba(0, 0, 0, 0.2); /* Darker inactive state (Dark Mode) */
  color: var(--text-muted);
  box-shadow: inset 0 -5px 10px rgba(0, 0, 0, 0.2);
}
body.dark-mode .tab-btn:not(.active):hover {
  background: rgba(0, 0, 0, 0.3);
  color: var(--text-main);
}

.tab-btn.active {
  background: var(--bg-paper); /* Match panel background (Light Mode) */
  color: var(--primary-color);
  z-index: 20; /* Ensure it is ABOVE panel */
  border: 1px solid var(--glass-border);
  border-bottom: 1px solid var(--bg-paper); /* Exact match 1px to cover */
  padding-bottom: 13px; /* Precise height adjustment */
  box-shadow: 0 -2px 5px rgba(0, 0, 0, 0.02);
  margin-top: 0; /* Reset vertical push */

  /* Rise up to meet the active panel */
  transform: translateY(0);
}

/* Dark Mode Active Tab Override */
body.dark-mode .tab-btn.active {
  background: #2d333b; /* Match Dark Mode Glass Panel color */
  border-bottom-color: #2d333b;
  color: var(--primary-color);
}

/* Panel Container - Deck Layout */
.home-panels {
  position: relative;
  /* z-index: 10; REMOVED to allow interleaving with tabs */
  width: 100%;
  max-width: 600px;
  grid-template-areas: "stack";
  display: grid; /* Stack children */
  margin-top: 0;
}

/* Base Panel Styles (Shared) */
.glass-panel {
  /* Both panels share this class */
  grid-area: stack; /* Occupy same space */
  background: var(--bg-paper);
  width: 100%;
  height: auto;
  min-height: 336px; /* Enforce consistency (Daily was ~335px) */
  align-self: start; /* Align to top */

  /* The Deck Animation */
  transition: all 0.4s cubic-bezier(0.25, 0.8, 0.25, 1);
  transform-origin: top center;

  /* Default State (Inactive/Behind) */
  opacity: 0;
  transform: scale(0.95) translateY(10px);
  z-index: 2; /* Bottom Layer */
  pointer-events: none;
  /* border: 1px solid var(--glass-border);  Already in global */
}

/* Active State (Front) */
.glass-panel.active {
  opacity: 1;
  transform: scale(1) translateY(0);
  z-index: 15; /* Front Layer (Below Active Tab 20) */
  pointer-events: all;
  position: relative; /* Default context */
}

/* Dark Mode Background Override */
body.dark-mode .glass-panel {
  background: #2d333b;
}

/* Custom Panel Helper */
.custom-panel {
  /* No more absolute positioning needed due to grid */
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px 20px !important; /* Significantly reduce top padding */
}

.custom-content {
  width: 100%;
  max-width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* Segmented Control (Difficulty) */
.difficulty-wrapper {
  margin-bottom: 15px; /* Reduce space */
  width: 100%;
  display: flex;
  justify-content: center;
}

/* ... Segmented Control styles ... */
.segmented-control {
  display: flex;
  background: rgba(0, 0, 0, 0.05);
  padding: 4px;
  border-radius: 8px;
  gap: 4px;
}

.seg-btn {
  padding: 6px 16px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-weight: 600;
  cursor: pointer;
  border-radius: 6px;
  transition: all 0.2s;
  font-family: var(--font-main);
  font-size: 0.9rem;
}

.seg-btn.active {
  background: white;
  color: var(--accent-color); /* Orange text for active state */
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

body.dark-mode .seg-btn.active {
  background: #334155;
  color: var(--accent-color);
}

/* Panel Titles */
.panel-section-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--primary-color);
  margin: 10px 0 8px; /* Compact margins */
  text-transform: uppercase;
  letter-spacing: 1px;
}

/* Switch List - Grid Layout */
.game-switches-list {
  width: 100%;
  max-width: 100%; /* Allow full width of panel */
  display: grid;
  grid-template-columns: 1fr 1fr; /* Two columns */
  gap: 15px;
  max-height: 400px; /* Prevent overflow of panel if list is long */
  overflow-y: auto; /* Scroll if needed, though 5 items should fit */
  padding: 4px; /* Space for focus rings/shadows */
}

.switch-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 20px; /* Slightly plumper rows */
  background: rgba(
    0,
    0,
    0,
    0.03
  ); /* Light grey for contrast against cream panel */
  border-radius: 8px;
  border: 1px solid var(--glass-border);
  min-width: 0; /* Flexbox safety */
}

body.dark-mode .switch-row {
  background: rgba(255, 255, 255, 0.05); /* Subtle glass in dark mode */
  border-color: rgba(255, 255, 255, 0.1);
}

/* Center last item if odd number of items */
.switch-row:last-child:nth-child(odd) {
  grid-column: 1 / -1; /* Span full width to allow centering */
  width: calc(50% - 7.5px); /* Exact match: 50% width minus half the 15px gap */
  max-width: none; /* Reset max-width if set */
  justify-self: center; /* Center in container */
}

.switch-row span {
  font-weight: 600;
  color: var(--text-main);
  white-space: nowrap; /* Prevent wrapping */
  font-size: 0.95rem; /* Slightly larger text */
}

/* Mobile: Single Column */
@media (max-width: 600px) {
  .game-switches-list {
    grid-template-columns: 1fr;
  }

  .switch-row:last-child:nth-child(odd) {
    grid-column: auto; /* Reset span */
    width: 100%; /* Full width on mobile to match others */
    max-width: 100%;
  }

  .panel-section-title {
    font-size: 1rem;
    margin: 15px 0 8px;
  }
}

/* Description Card */
.game-description {
  text-align: center;
  padding: 40px;
  width: 100%;
  max-width: 600px;
  background: white; /* Clean card on cream bg */
  /* Border/Shadow handled by global .glass-panel class now acting as paper-panel */
}

.game-description h2 {
  font-size: 2rem;
  margin-bottom: 20px;
  color: var(--primary-color);
}

.game-description p {
  font-size: 1.2rem;
  line-height: 1.6;
  margin-bottom: 20px;
  color: var(--text-main);
}

.game-description strong {
  color: var(--accent-color);
  font-weight: 600;
}

.tagline {
  font-style: italic;
  font-size: 1.1rem;
  margin-top: 20px;
  color: var(--text-muted) !important;
  font-family: var(--font-paper); /* Using Lora */
}

/* Start Button */
.btn-primary {
  padding: 16px 48px;
  font-size: 1.5rem;
  font-weight: 700;
  color: white;
  background: var(--accent-color); /* Burnt Orange */
  border-radius: 8px; /* Less rounded, more paper-like */
  box-shadow: 0 4px 0 #c2410c; /* Hard shadow for tactile feel */
  transition: all 0.1s ease;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.btn-primary:hover {
  background: #ea580c; /* Darker orange */
}

.btn-primary:active {
  transform: translateY(4px);
  box-shadow: 0 0 0 #c2410c; /* Animate to 0 offset instead of none */
}

.btn-primary:disabled {
  background: var(--glass-border) !important; /* Lighter gray */
  color: var(--text-muted) !important;
  box-shadow: none !important;
  transform: translateY(4px) !important; /* Stay pressed */
  cursor: not-allowed;
  opacity: 1; /* Handle opacity via color */
  pointer-events: none;
  border: none !important; /* Ensure no border */
}

/* Dark Mode Button Overrides */
body.dark-mode .btn-primary {
  color: #1e293b; /* Dark text on bright orange for contrast */
  box-shadow: 0 4px 0 #f57c00; /* Matching lighter shadow */
}

body.dark-mode .btn-primary:hover {
  background: #ff9800; /* Darker orange (Orange 500) - Lighter than 600 */
}

body.dark-mode .btn-primary:active {
  box-shadow: 0 0 0 #f57c00; /* Animate to 0 offset dark mode color */
}

/* Footer */
.main-footer {
  text-align: center;
  padding: 4px; /* Slim footer */
  font-size: 0.8rem; /* Slightly smaller text */
  color: var(--text-muted);
  width: 100%;
  border-top: 1px solid var(--glass-border);
  background: var(--bg-paper);
  /* Fixed positioning */
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 100;
}

.version-tag {
  color: var(--accent-color);
  font-weight: 700;
  font-size: 0.65rem; /* Smaller as requested */
  opacity: 0.8;
  margin-left: 5px;
  text-decoration: none; /* It's a link now */
  cursor: pointer;
}

.version-tag:hover {
  text-decoration: underline;
  opacity: 1;
}

.main-footer a {
  color: var(--primary-color);
  text-decoration: none;
  font-weight: 500;
}

.main-footer a:hover {
  text-decoration: underline;
  color: var(--accent-color);
}

/* Sidebar Removed */

@media (max-width: 600px) {
  /* Enforce consistency on mobile */
  .glass-panel {
    min-height: 457px;
  }

  .app-title {
    font-size: 1.4rem;
  }

  .game-description {
    padding: 20px;
  }

  .game-description h2 {
    font-size: 1.5rem;
  }

  .btn-primary {
    padding: 12px 36px;
    font-size: 1.2rem;
  }
}

/* Settings Dropdown */
.settings-dropdown {
  position: absolute;
  top: 120%; /* Below the button */
  right: -10px; /* Align right */
  width: 250px;
  padding: 16px;
  background: var(--bg-paper);
  z-index: 1001;
  display: flex;
  flex-direction: column;
  gap: 15px;
  transform-origin: top right;
  transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.settings-dropdown.hidden {
  display: flex !important; /* Keep flex context */
  opacity: 0;
  transform: scale(0.9) translateY(-10px);
  pointer-events: none;
}

.settings-dropdown:not(.hidden) {
  opacity: 1;
  transform: scale(1) translateY(0);
  pointer-events: auto; /* Force enable interaction */
  cursor: default;
}

.dropdown-header {
  font-size: 1rem;
  font-weight: 700;
  color: var(--primary-color);
  margin-bottom: 5px;
  text-transform: uppercase;
  letter-spacing: 1px;
  border-bottom: 2px solid var(--accent-color);
  padding-bottom: 5px;
  border-bottom: 2px solid var(--accent-color);
  padding-bottom: 5px;
  width: 100%;
}

.dropdown-divider {
  height: 1px;
  background: var(--glass-border);
  margin: 10px 0;
  width: 100%;
}

.setting-item {
  display: flex;
  justify-content: center; /* Centered since text is gone */
  align-items: center;
  font-weight: 500;
  color: var(--text-main);
  width: 100%;
}

/* Theme Switch */
.theme-switch-wrapper {
  display: flex;
  align-items: center;
  gap: 12px; /* Little more space */
}

.theme-icon {
  font-size: 1.4rem;
  transition: all 0.3s ease;
}

/* DEFAULT (Light Mode) State */
.theme-icon.sun {
  opacity: 1;
  transform: scale(1.1);
  text-shadow: 0 0 10px #f59e0b;
}

.theme-icon.moon {
  opacity: 0.3;
  transform: scale(0.9);
}

/* DARK MODE State (Inherited from body) */
body.dark-mode .theme-icon.sun {
  opacity: 0.3;
  transform: scale(0.9);
  text-shadow: none;
}

body.dark-mode .theme-icon.moon {
  opacity: 1;
  transform: scale(1.1);
  text-shadow: 0 0 10px #a78bfa;
}

/* The Switch */
.switch {
  position: relative;
  display: inline-block;
  width: 48px;
  height: 26px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #cbd5e1; /* Light grey when off */
  transition: 0.4s;
  border-radius: 34px;
}

/* The slider circle (Manual Switch) */
.slider:before {
  position: absolute;
  content: "";
  height: 20px;
  width: 20px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: 0.4s;
  border-radius: 50%;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

/* Input Checked (Manual Switch) */
input:checked + .slider {
  background-color: var(--accent-color);
}

input:checked + .slider:before {
  transform: translateX(22px);
}

/* Small Auto Switch Structure */
.switch-small {
  position: relative;
  display: inline-block;
  width: 34px;
  height: 20px;
}

.switch-small input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider-small {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #cbd5e1; /* Light grey when off */
  transition: 0.4s;
  border-radius: 34px;
}

/* Dark Mode Override for Sliders */
body.dark-mode .slider,
body.dark-mode .slider-small {
  background-color: #444c56; /* Darker grey for dark mode background */
}

/* Small Slider Circle */
.slider-small:before {
  position: absolute;
  content: "";
  height: 14px;
  width: 14px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: 0.4s;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

input:checked + .slider-small {
  background-color: var(--accent-color);
}

input:checked + .slider-small:before {
  transform: translateX(14px);
}

.setting-label {
  font-size: 0.9rem;
  font-weight: 500;
  margin-right: auto; /* Push switch to right */
}

/* Disabled Manual State - Only dim the switch */
.option-manual {
  transition: all 0.3s;
}

.option-manual.disabled .switch {
  opacity: 0.4;
  pointer-events: none;
  filter: grayscale(1);
}

/* Ensure icons stay visible */
.option-manual.disabled .theme-icon {
  filter: none;
}

/* Language Selector */
.lang-select {
  padding: 4px 8px;
  border-radius: 4px;
  border: 1px solid var(--glass-border);
  background: var(--bg-paper);
  color: var(--text-main);
  font-family: var(--font-main);
  font-size: 0.9rem;
  cursor: pointer;
  outline: none;
}

.lang-select:focus {
  border-color: var(--accent-color);
}

/* Landscape Tablet / Short Desktop Adjustment (Home) */
@media (min-width: 769px) and (max-height: 850px) {
  .menu-container {
    gap: 15px;
    padding: 10px 20px;
    justify-content: center;
  }

  .glass-panel {
    min-height: 0 !important;
    height: 48vh; /* Proportional to viewport height */
    max-height: 420px; /* Cap growth on very tall monitors within range */
    display: flex;
    flex-direction: column;
    justify-content: center;
  }

  .game-description {
    padding: 20px 40px !important;
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
  }

  .game-description h2 {
    font-size: clamp(1.2rem, 5vh, 2.2rem) !important;
    margin-bottom: 12px !important;
  }

  .game-description p {
    font-size: clamp(1rem, 3vh, 1.3rem) !important;
    line-height: 1.4 !important;
    margin-bottom: 10px !important;
  }

  .tagline {
    margin-top: 5px !important;
    font-size: clamp(0.9rem, 2.5vh, 1.1rem) !important;
  }

  .custom-panel {
    padding: 10px 20px !important;
    justify-content: space-evenly;
  }

  .panel-section-title {
    font-size: 0.95rem !important;
    margin: 8px 0 5px !important;
  }

  .difficulty-wrapper {
    margin-bottom: 8px !important;
  }

  .seg-btn {
    padding: 4px 12px !important;
    font-size: 0.85rem !important;
  }

  .game-switches-list {
    gap: 10px !important;
    max-height: none !important;
  }

  .switch-row {
    padding: 8px 16px !important;
  }

  .switch-row span {
    font-size: 0.9rem !important;
  }

  .btn-primary {
    padding: 12px 40px !important;
    font-size: 1.3rem !important;
  }
}

/* Ultra Short Heights (e.g. Smart TV at 545px) */
@media (min-width: 769px) and (max-height: 600px) {
  .menu-container {
    gap: 10px !important;
    padding: 5px 20px !important;
  }

  .glass-panel {
    height: 52vh !important; /* Slightly more relative height */
  }

  .game-description {
    padding: 10px 30px !important;
  }

  .game-description h2 {
    font-size: clamp(1.1rem, 4.5vh, 1.8rem) !important;
    margin-bottom: 8px !important;
  }

  .game-description p {
    font-size: clamp(0.9rem, 3vh, 1.1rem) !important;
    margin-bottom: 5px !important;
  }

  .panel-section-title {
    margin: 5px 0 3px !important;
    font-size: 0.85rem !important;
  }

  .difficulty-wrapper {
    margin-bottom: 5px !important;
  }

  .game-switches-list {
    display: flex !important;
    flex-wrap: wrap !important;
    justify-content: center !important;
    grid-template-columns: none !important; /* Disable grid */
    gap: 6px !important;
    max-height: none !important;
  }

  .switch-row {
    flex: 0 1 calc(33% - 6px) !important; /* 3 per row approx */
    min-width: 140px !important; /* Minimum width to avoid text clashing with switch */
    margin: 0 !important;
  }

  .switch-row {
    padding: 6px 12px !important;
  }

  .switch-row span {
    font-size: 0.8rem !important;
  }

  .btn-primary {
    padding: 10px 30px !important;
    font-size: 1.1rem !important;
  }
}
