:root {
  /* =========================================
     PALETA DE COLORES (VISUAL IDENTITY)
     ========================================= */
  
  /* CORE COLORS */
  --brand-h: 243;
  --brand-s: 75%;
  --brand-l: 59%;
  --brand-primary: hsl(var(--brand-h), var(--brand-s), var(--brand-l)); /* #6366F1 Vivid Indigo */
  
  /* DARK MODE (Default) */
  --bg-color: #0B0C15; /* Deep Void Blue */
  --canvas-bg: #0B0C15;
  
  --text-color: #F1F5F9; /* Slate 100 */
  --text-color-light: #94A3B8; /* Slate 400 */
  
  /* SEMANTIC SURFACES */
  --surface-glass: rgba(15, 23, 42, 0.2); /* Ultra-Transparent Dark */
  --surface-border: rgba(99, 102, 241, 0.2); /* Brand Hint */
  --surface-glass-strong: rgba(15, 23, 42, 0.55);
  --surface-strong-border: rgba(99, 102, 241, 0.35);
  
  /* UI ELEMENTS */
  --btn-primary-bg: var(--brand-primary);
  --btn-primary-text: #ffffff;
  --btn-secondary-bg: rgba(255, 255, 255, 0.05); /* Ghost White */
  --btn-secondary-border: rgba(255, 255, 255, 0.1);
  --btn-secondary-text: #E2E8F0;

  --shadow-color: rgba(0, 0, 0, 0.6);
  --shadow-spread: 0 8px 32px;

  /* Unified UI glass (matches title/guide) */
  --ui-glass-bg: rgba(99, 102, 241, 0.15);
  --ui-glass-border: rgba(99, 102, 241, 0.3);
  --ui-glass-blur: 10px;

  /* UI Text (Nav/Footer) */
  --nav-text-muted: #CBD5E1;
  --nav-text: #E2E8F0;
  --footer-text: #CBD5E1;

  /* Home UI spacing (runtime-adjusted for different devices) */
  --home-top-offset: 140px;
  --home-bottom-offset: 80px;
}

body.light-mode {
  /* OPTION 3: "Clinical & Modern" - Polished for High Visibility */
  --bg-color: #F1F5F9; /* Slate 100 - Perfect for seeing light 3D cubes */
  --canvas-bg: #F1F5F9;
  
  --text-color: #0F172A; /* Slate 900 */
  --text-color-light: #334155; /* Slate 700 - Better reading */
  
  /* Brand adaption: Professional Tech Blue */
  --brand-primary: #1E40AF; /* Blue 800 */

  /* SEMANTIC SURFACES - True Glassmorphism (Crystal Clear) */
  --surface-glass: rgba(255, 255, 255, 0.15); /* Maximum transparency */
  --surface-border: rgba(30, 64, 175, 0.1); 
  --surface-glass-strong: rgba(255, 255, 255, 0.75);
  --surface-strong-border: rgba(30, 64, 175, 0.2);
  
  /* UI ELEMENTS */
  --btn-primary-bg: #1E40AF;
  --btn-primary-text: #ffffff;
  --btn-secondary-bg: rgba(255, 255, 255, 0.5);
  --btn-secondary-border: #94A3B8;
  --btn-secondary-text: #1E40AF;

  --shadow-color: rgba(15, 23, 42, 0.12); 
  --shadow-spread: 0 4px 25px;

  --nav-text-muted: #334155;
  --nav-text: #1F2937;
  --footer-text: #475569;

  /* Light UI edges (subtle but visible) */
  --ui-border-light: rgba(100, 116, 139, 0.58);
  --ui-inset-light: rgba(100, 116, 139, 0.22);
  --ui-shadow-light: rgba(15, 23, 42, 0.08);
  --ui-surface-light: linear-gradient(180deg, rgba(255, 255, 255, 0.92), rgba(241, 245, 249, 0.88));
  --ui-surface-light-alt: linear-gradient(180deg, rgba(255, 255, 255, 0.82), rgba(226, 232, 240, 0.8));

  /* Unified UI glass (light) */
  --ui-glass-bg: var(--surface-glass);
  --ui-glass-border: var(--surface-border);
  --ui-glass-blur: 10px;
}

/* Specific component pop in Light Mode - Glass enabled for background visibility */
body.light-mode #nav-container,
body.light-mode .legend-overlay,
body.light-mode #ui-container {
  background: var(--ui-surface-light);
  border: 1px solid var(--ui-border-light);
  box-shadow:
    0 6px 18px var(--ui-shadow-light),
    inset 0 0 0 1px var(--ui-inset-light);
  backdrop-filter: blur(var(--ui-glass-blur)) saturate(1.6); /* Saturate helps background pop through */
  -webkit-backdrop-filter: blur(var(--ui-glass-blur)) saturate(1.6);
}

body.light-mode .nav-tab.active {
  background-color: #1E40AF;
  box-shadow: 0 4px 12px rgba(30, 64, 175, 0.3);
}

body.light-mode .nav-tab:not(.active) {
  color: #475569;
}

body.light-mode .nav-tab:hover:not(.active) {
  background: #F1F5F9;
  color: var(--text-color);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent; /* Remove mobile grey box */
}

/* Global Selection Style */
::selection {
  background: var(--brand-primary);
  color: #ffffff;
}
html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
}
body {
  background-color: var(--bg-color);
  font-family:
    "Inter",
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    Roboto,
    sans-serif;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 0; /* REMOVED PADDING FOR FULL WIDTH */
  transition:
    background-color 0.4s ease,
    color 0.4s ease;
}

/* HEADER */
/* HEADER */
h1 {
  width: 100%;
  text-align: center;
  font-size: clamp(24px, 4vw, 36px);
  font-weight: 200;
  
  /* Reset H1 to transparent/default layout */
  background-color: transparent;
  color: var(--brand-primary);
  
  /* Tight Tracking for Bold Pop Look */
  letter-spacing: 1px;
  text-transform: uppercase;
  padding: 4px 0; /* Ultra-Compact Header */
  z-index: 10;
  text-shadow: 0 2px 10px var(--shadow-color);
  position: relative;
  pointer-events: none; /* Let clicks pass to canvas if not on text-layer */
}

h1 .text-layer {
  pointer-events: auto; /* Buttons/Title active */
}

/* 
   CONSTRAINED BACKGROUND 
   Only applied to the text wrapper, centered within H1
*/
h1 .text-layer {
  position: relative;
  z-index: 2;
  /* Unified Flex Layout (Responsive by Default) */
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 4px 20px; /* Reduced gaps: 4px Vertical, 20px Horizontal */
  
  width: fit-content;
  max-width: calc(100vw - 40px); /* Prevent overflow with viewport padding */
  margin: 0 auto;

  padding: 8px 24px; /* Tighter padding for 'Hug' effect */
  border-radius: 12px; /* Slightly tighter radius */
  
  /* PALETTE SYNC: Premium Glassmorphism (Global) */
  background-color: var(--ui-glass-bg); /* Unified glass */
  backdrop-filter: blur(var(--ui-glass-blur));
  -webkit-backdrop-filter: blur(var(--ui-glass-blur));
  border: 1px solid var(--ui-glass-border);
  
  color: var(--btn-primary-text);
  
  box-shadow: 0 8px 25px rgba(0,0,0,0.2); /* Enhanced shadow for floating effect */
  
  transition: background-color 0.4s ease, color 0.4s ease, box-shadow 0.4s ease;
}

/* Specific override removed - utilizing variables handles it automatically */
/* Specific override removed - utilizing variables handles it automatically */
body.light-mode h1 .text-layer {
  /* High contrast glass for header */
  background-color: var(--surface-glass); 
  color: var(--brand-primary); 
  border: 1px solid var(--surface-border);
  box-shadow: 0 4px 15px var(--shadow-color);
  backdrop-filter: blur(var(--ui-glass-blur));
}

/* Remove wide h1 overrides */
body.light-mode h1 {
  background-color: transparent;
  color: inherit;
}

/* Global Animation Canvas */
#header-canvas-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 3; /* Above text */
  pointer-events: none;
  overflow: visible;
}

/* Word Row Structure */
.word-row {
  display: flex;
  justify-content: center;
  gap: 12px; /* Desktop gap between letters */
}

/* Individual letter spacing wrapper */
h1 .letter-wrapper {
  display: inline-block;
  position: relative;
  min-width: 20px; /* Prevent collapse */
}

  h1 .letter-char {
    display: inline-block;
    transition: opacity 0.4s ease;
    font-weight: 900; /* Bold Global */
    /* Unified Pop Style */
    filter: drop-shadow(0 0 2px rgba(0,0,0,0.5));
  }

/* AREA CENTRAL (CANVAS) */
#canvas-wrapper {
  /* Default: Full Screen (Home Mode) */
  position: fixed; 
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  z-index: 1; /* Behind UI */
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  margin: 0;
  padding: 0;
  touch-action: none;
}

/* Generator & Game Modes: Contained Canvas (Clarity Fix) */
/* Generator & Game Modes: Natural Flow */
body.mode-generator #canvas-wrapper,
body.mode-game #canvas-wrapper {
  position: relative;
  flex: 1; /* Grow to fill space */
  width: 100%;
  min-height: 35vh; /* Reduced from 40vh for density */
  z-index: 1; 
  border-top: 1px solid var(--surface-border);
  border-bottom: 1px solid var(--surface-border);
  margin: 0;
}

#canvas-container {
  display: flex;
  justify-content: center;
  align-items: center;
  /* Sutil sombra para dar profundidad al área de dibujo */
  box-shadow: none; /* Removed shadow for flat look */
  border-radius: 0; /* Removed border radius to fit edges */
  background: var(--canvas-bg);
  transition:
    background 0.4s ease;
  width: 100%; /* Force full width */
  height: 100%; /* Force full height */
  max-width: none; /* Remove constraints */
  max-height: none;
}

canvas {
  display: block;
  border-radius: 0; /* Removed border radius */
  touch-action: none; /* Prevent browser zoom/scroll handling */
}

/* CONTROLES UI */
/* Professional Stats Dashboard */
.stats-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  row-gap: 8px;
  flex-wrap: wrap;
  width: 100%;
  margin: 0; /* Reset margins */
}

.stat-pill {
  background: var(--surface-glass);
  border: 1px solid var(--surface-border);
  border-radius: 20px;
  padding: 6px 12px; /* Compact padding */
  display: flex;
  align-items: center;
  gap: 8px;
  height: 32px; /* Reduced from 36px */
  backdrop-filter: blur(var(--ui-glass-blur));
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  font-size: 12px;
  font-weight: 600;
  transition: all 0.3s ease;
}

/* Balance stat widths for game HUD */
#game-ui-container .stat-pill {
  flex: 0 1 96px;
}
#game-ui-container .stat-pill.feedback {
  flex: 1 1 140px;
  min-width: 120px;
}

.stat-label {
  color: var(--text-color-light);
  font-size: 10px;
  letter-spacing: 1px;
  text-transform: uppercase;
}

.stat-value {
  color: var(--text-color);
  font-family: 'Inter', monospace; /* Tabular nums if possible */
  font-size: 14px;
}

/* Feedback Pill specific */
.stat-pill.feedback {
  min-width: 100px; /* Prevent jumping */
  justify-content: center;
  color: var(--text-color); /* Default */
  /* JS will override 'color' for Success/Error. Background remains glass. */
}

/* Feedback pill with horizontal time fill */
#feedbackPill {
  position: relative;
  overflow: hidden;
  justify-content: center;
}

.feedback-timer-bar {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: calc(var(--time-progress, 0) * 100%);
  background: linear-gradient(
    90deg,
    rgba(99, 102, 241, 0.35),
    rgba(99, 102, 241, 0.15)
  );
  opacity: 0;
  transition: width 0.12s linear, opacity 0.2s ease;
  z-index: 0;
  pointer-events: none;
}

#feedbackPill.timer-active .feedback-timer-bar {
  opacity: 1;
}

body.light-mode .feedback-timer-bar {
  background: linear-gradient(
    90deg,
    rgba(30, 64, 175, 0.25),
    rgba(30, 64, 175, 0.12)
  );
}

.feedback-time {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.4px;
  color: var(--text-color-light);
  opacity: 0;
  transition: opacity 0.2s ease;
  z-index: 1;
}

#feedbackPill.timer-active .feedback-time {
  opacity: 1;
  color: var(--text-color);
}

/* Replaces old feedback-msg style logic but keeps ID functional */
#feedbackDisplay {
  position: relative;
  z-index: 1;
  width: 100%;
  text-align: center;
  padding-left: 44px; /* keep space for time */
  padding-right: 36px;
  opacity: 1; /* Always visible as a placeholder */
  /* JS manages text content and transient opacity/colors */
  transition: color 0.2s ease, transform 0.2s ease;
}

/* Progress Bar (Game HUD) */
.progress-track {
  width: 95%;
  max-width: 360px;
  height: 8px;
  border-radius: 999px;
  background: var(--surface-glass);
  border: 1px solid var(--surface-border);
  overflow: hidden;
  box-shadow: 0 4px 12px var(--shadow-color);
  margin-top: 6px;
}

.progress-bar {
  width: 0%;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--brand-primary), rgba(99, 102, 241, 0.4));
  transition: width 0.25s ease;
}

@keyframes progressGlow {
  0% { box-shadow: 0 0 6px rgba(99, 102, 241, var(--glow-alpha)); }
  50% { box-shadow: 0 0 var(--glow-size) rgba(99, 102, 241, var(--glow-alpha-strong)); }
  100% { box-shadow: 0 0 6px rgba(99, 102, 241, var(--glow-alpha)); }
}

.progress-track.glow {
  --glow-alpha: 0.25;
  --glow-alpha-strong: 0.6;
  --glow-size: 14px;
  border-color: var(--brand-primary);
  animation: progressGlow 1.6s ease-in-out infinite;
}

.progress-bar.glow {
  box-shadow: 0 0 10px rgba(99, 102, 241, var(--glow-alpha-strong));
}
.game-hud {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  max-width: 600px;
  height: auto; 
  gap: 6px; /* Tight internal spacing */
  padding-bottom: 5px; /* Minimal bottom space */
  color: var(--text-color);
  pointer-events: none;
  margin: 0 auto;
}
.game-hud > * {
  pointer-events: auto;
  width: 100%;
}
.score-board {
  font-size: 14px;
  font-weight: 600;
  color: var(--brand-primary);
  margin-bottom: 5px;
}
/* Wrapper to align Word Box + Button side-by-side */
.target-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  width: 100%;
  max-width: 360px;
  margin: 0 auto; /* Removed bottom margin */
}

/* Spacer no longer needed with Balanced layout (Theme vs Color) */
.ghost-spacer {
  display: none !important;
}

/* The Box containing the Word */
.target-display {
  background: rgba(255, 255, 255, 0.03);
  border-radius: 12px;
  padding: 4px 10px; /* Tighter padding */
  display: flex;
  flex-direction: column; 
  align-items: center;
  justify-content: center;
  flex-grow: 1;
  max-width: 200px; /* Prevent squeezing buttons on mobile */
}

.target-display .label {
  text-align: center;
  margin-bottom: 0;
  font-size: 9px; /* Shrunk label */
  letter-spacing: 1px;
  opacity: 0.6;
  line-height: 1.2;
  white-space: normal;
}

.target-display h2 {
  font-size: 22px; /* Reduced from 32px */
  margin: 0;
  letter-spacing: 1.5px;
}



/* The Mini Toggle Button - Sits to the right */
.color-toggle-btn.mini-toggle {
  width: 44px; /* Matches height of a button nicely */
  height: 44px;
  font-size: 20px;
  border-radius: 12px; /* Soft square matches UI */
  margin: 0;
  flex-shrink: 0;
}
/* UNIVERSAL UI VISIBILITY LOGIC */
.mode-ui {
  display: none !important; 
  /* Layout properties moved to specific IDs to avoid conflicts */
  /* pointer-events: none; handled individually */
}

/* Generator UI: Visibility Toggle */
#ui-container.active {
  display: grid !important;
}

#ui-container #textInput { grid-area: input; }
#ui-container .maker-actions { grid-area: actions; }

/* Home UI: Remains Full Overlay */
/* Home UI: Remains Full Overlay (See definition below) */
#home-ui-container.active {
  display: flex !important;
}
#home-ui-container.active {
  display: flex !important;
}

/* Game UI: Natural Flow Dashboard */
#game-ui-container.active {
  display: flex !important;
  position: relative; /* In Flow */
  width: 100%;
  height: auto; /* Fit content */
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 4px 0; /* Reduced from 10px */
  z-index: 10;
  pointer-events: auto;
}

/* Consolidated Game HUD (Clean) */

/* Specific styling for the Instructions footer in Game Mode */
/* Specific styling for the Instructions footer in Game Mode */
.instructions {
  background: var(--surface-glass);
  padding: 6px 12px; /* Very compact */
  border-radius: 16px;
  margin-bottom: 10px; /* Reduced margin */
  font-size: 13px; /* Standardized to 13px */
  font-weight: 500;
  color: var(--text-color-light); /* Standardized color */
  text-align: center;
  pointer-events: auto;
  border: 1px solid var(--surface-border);
  backdrop-filter: blur(var(--ui-glass-blur));
  -webkit-backdrop-filter: blur(var(--ui-glass-blur));
  align-self: center;
  box-shadow: 0 4px 15px var(--shadow-color);
  
  /* Natural flow in flex-end container */
  width: 90%;
  max-width: 400px;
  opacity: 0.8; /* Subtle look */
  line-height: 1.4;
  white-space: normal; /* Allow wrapping */
}


#ui-container {
  pointer-events: auto;
  width: 100%;
  max-width: 600px;
  
  /* Natural Stack Position - Clean (No !important) */
  position: relative;
  height: auto;
  margin: 6px auto 10px auto; /* Added 6px 'air' from canvas top */

  display: none; /* Hidden by default, toggled by .active */
  grid-template-columns: minmax(180px, 1fr) auto;
  grid-template-areas: "input actions";
  grid-auto-rows: auto;
  align-items: center;
  column-gap: 8px;
  row-gap: 8px;
  
  /* VISUALS: The Glass Pill */
  padding: 10px 12px;
  background: var(--ui-glass-bg);
  border: 1px solid var(--ui-glass-border);
  border-radius: 18px;
  backdrop-filter: blur(var(--ui-glass-blur));
  -webkit-backdrop-filter: blur(var(--ui-glass-blur));
  
  flex-shrink: 0;
  z-index: 10;
  box-shadow: 0 8px 28px 0 var(--shadow-color);
  transition: all 0.4s ease;
}

/* Maker: clearer edges in light mode */
body.light-mode #ui-container {
  background: var(--ui-surface-light);
  border-color: var(--ui-border-light);
  box-shadow:
    0 6px 18px var(--ui-shadow-light),
    inset 0 0 0 1px var(--ui-inset-light);
}

/* Utilities group to keep theme/color together if they wrap */
.maker-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  justify-content: center;
}

.util-group {
  display: flex;
  gap: 8px;
  align-items: center;
}

input {
  min-width: 140px; /* Reduced from 180px to prevent overflow */
  padding: 0 16px; /* Horizontal only, height handles vertical */
  height: 42px; /* Tighter for single-row layout */
  font-size: 15px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-color);
  border: 1px solid var(--surface-border);
  border-radius: 12px;
  outline: none;
  transition: all 0.3s ease;
  font-family: inherit;
}
input::placeholder {
  color: var(--text-color-light);
  opacity: 1; /* Ensure full contrast */
}
input:focus {
  border-color: var(--brand-primary);
  box-shadow: 0 0 0 2px var(--shadow-color);
}

button {
  padding: 0 20px; /* Horizontal only */
  height: 44px; /* Match input height exactly for vertical symmetry */
  font-size: 13px;
  font-weight: 600;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  
  /* BASE IS NEUTRAL (Secondary) */
  background-color: var(--btn-secondary-bg);
  color: var(--text-color);
  border: 1px solid var(--btn-secondary-border);
  
  transition: all 0.2s ease;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
button:hover {
  transform: translateY(-1px);
  filter: brightness(1.1);
}
button:active {
  transform: scale(0.98);
}

button#generateButton {
  min-width: 110px;
  background-color: var(--btn-primary-bg);
  color: var(--btn-primary-text);
  border: none;
  box-shadow: 0 4px 15px var(--shadow-color);
}

button#saveButton {
  background: var(--btn-secondary-bg);
  color: var(--text-color);
  border: 1px solid var(--btn-secondary-border);
  font-weight: 500;
}

#ui-container button {
  height: 42px;
  padding: 0 12px;
  font-size: 12px;
}
button#saveButton:hover {
  background: var(--btn-secondary-border);
}

button#themeButton {
  z-index: 100;
  background-color: var(--surface-glass);
  color: var(--text-color);
  border: 1px solid var(--surface-border);
  backdrop-filter: blur(var(--ui-glass-blur));
  -webkit-backdrop-filter: blur(var(--ui-glass-blur));
  
  font-size: 20px; 
  width: 44px; 
  height: 44px;
  border-radius: 50%;
  
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px var(--shadow-color);
  transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  flex-shrink: 0;
  cursor: pointer;
}

/* Footer Integration (Home Mode) - Ultra Clean */
footer #themeButton {
  position: absolute; /* Default: Corner for Mobile */
  right: 15px;
  top: 50%;
  transform: translateY(-50%);
  margin: 0;
  padding: 0;
  
  width: 26px; /* Slightly larger for touch on mobile */
  height: 26px;
  font-size: 13px;
  
  background: transparent;
  border: 1px solid var(--surface-border);
  box-shadow: none;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  opacity: 0.6;
  transition: all 0.3s ease;
}

/* Integrated Style for Desktop */
@media (min-width: 601px) {
  footer #themeButton {
    position: relative;
    right: auto;
    top: auto;
    transform: none;
    margin-left: 8px;
    width: 22px;
    height: 22px;
    font-size: 11px;
    opacity: 0.5;
    border-color: transparent;
  }
  
  footer #themeButton::before {
    content: "•";
    position: absolute;
    left: -12px;
    top: 50%;
    transform: translateY(-50%);
    opacity: 0.5;
    pointer-events: none;
  }
}

footer #themeButton:hover {
  opacity: 1;
  background: var(--surface-glass);
  border-color: var(--brand-primary);
  transform: translateY(-50%) scale(1.1);
}

@media (min-width: 601px) {
  footer #themeButton:hover {
    transform: scale(1.1); /* No translateY on desktop flow */
    box-shadow: 0 0 10px rgba(99, 102, 241, 0.2);
  }
}

body.light-mode footer #themeButton:hover {
  box-shadow: 0 0 10px rgba(30, 64, 175, 0.1);
}

/* Specific Contextual Adjustments */
body.mode-generator button#themeButton,
body.mode-game button#themeButton {
  position: static; /* Naturally in flow */
  transform: none; 
  border-radius: 12px;
  margin: 0;
  box-shadow: none;
  background: var(--surface-glass);
}

/* Align utility group in Generator */
.util-group {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: 15px; /* Separate from main actions */
  padding-left: 15px;
  border-left: 1px solid var(--surface-border);
}

/* Contextual Utility Buttons (Theme / Color) */
.color-toggle-btn {
  background-color: var(--surface-glass);
  color: var(--text-color);
  border: 1px solid var(--surface-border);
  backdrop-filter: blur(var(--ui-glass-blur));
  
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all 0.3s ease;
}

body.light-mode .color-toggle-btn {
  border-color: var(--ui-border-light);
  box-shadow:
    0 2px 8px var(--ui-shadow-light),
    inset 0 0 0 1px var(--ui-inset-light);
}

/* Generator: Small Icon Button */
.color-toggle-btn.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  padding: 0;
  font-size: 20px;
}

/* Game: Pill Button */
.color-toggle-btn.pill-btn {
  border-radius: 20px;
  padding: 8px 16px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.5px;
  width: auto;
  margin-top: 10px; /* Space from instructions */
}

/* Active State (Global) */
.color-toggle-btn.active {
  background-color: var(--brand-primary);
  color: #fff;
  border-color: transparent;
  box-shadow: 0 4px 12px var(--shadow-color);
}

/* Hint badge for Game mode */
.color-toggle-btn.hint-mode {
  position: relative;
}
.color-toggle-btn.hint-mode::after {
  content: attr(data-hints);
  position: absolute;
  top: -6px;
  right: -6px;
  width: 18px;
  height: 18px;
  border-radius: 999px;
  background: var(--brand-primary);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 6px var(--shadow-color);
}

.color-toggle-btn.cooldown {
  opacity: 0.6;
  filter: grayscale(0.3);
}

.color-toggle-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  filter: grayscale(0.5);
  box-shadow: none;
}

/* Hover Effects */
@media (hover: hover) {
  button#themeButton:hover,
  .color-toggle-btn:hover {
    transform: scale(1.05); /* Gentle scale */
    border-color: var(--brand-primary);
  }
}

/* TOUCH FEEDBACK */
button#themeButton:active,
.color-toggle-btn:active {
  transform: scale(0.95);
}

/* NAVEGACIÓN TAB */
#nav-container {
  display: flex;
  gap: 8px; /* Tighter gap default */
  margin: 4px auto 6px auto; /* Added side/bottom air */
  background: var(--ui-glass-bg);
  border: 1px solid var(--ui-glass-border);
  backdrop-filter: blur(var(--ui-glass-blur));
  -webkit-backdrop-filter: blur(var(--ui-glass-blur));
  padding: 4px 6px;
  border-radius: 12px;
  z-index: 20;
  flex-wrap: wrap; 
  justify-content: center;
  align-items: center;
  width: fit-content;
  max-width: 90%;
  pointer-events: auto;
}

/* Dark mode: reduce transparency for clearer nav */
body:not(.light-mode) #nav-container {
  background: var(--ui-glass-bg);
  border-color: var(--ui-glass-border);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

/* Push icons to the right ONLY when we have room (Desktop/Tablet) */
@media (min-width: 601px) {
  #themeButton {
    margin-left: 20px;
  }
}


.nav-tab {
  padding: 6px 14px; /* Pro Compact */
  font-size: 13px; /* Slightly smaller */
  font-weight: 500;
  color: var(--nav-text-muted);
  background: transparent;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
  min-height: 36px; /* Reduced from 44px */
  display: flex;
  align-items: center;
}

.nav-tab.active {
  background: var(--btn-primary-bg);
  color: var(--btn-primary-text);
  font-weight: 700;
  box-shadow: 0 2px 8px var(--shadow-color);
}

.nav-tab:hover:not(.active) {
  background: var(--btn-secondary-bg);
  color: var(--nav-text);
}

/* FOOTER */
footer {
  width: 100%;
  padding: 6px 15px; 
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap; /* Safety for small screens */
  gap: 4px; 
  
  font-size: 10px;
  font-weight: 500;
  color: var(--footer-text);
  z-index: 10;
  flex-shrink: 0;
  opacity: 0.8;
  letter-spacing: 2px;
  text-transform: uppercase;
  border-top: 1px solid var(--surface-border);
  background: var(--surface-glass);
  backdrop-filter: blur(10px);
  margin-top: auto; 
  transition: all 0.4s ease;
  pointer-events: auto;
}

body.light-mode footer {
  background: var(--surface-glass);
  border-top: 1px solid var(--surface-border);
  box-shadow: 0 -4px 15px var(--shadow-color);
  backdrop-filter: blur(10px) saturate(1.6);
  color: #1F2937;
  font-weight: 500;
  letter-spacing: 2px;
  font-size: 10px;
  opacity: 1;
}

/* INTRO & LEGEND STYLES */
#home-ui-container {
  pointer-events: none; /* Allow canvas interaction behind */
  display: flex;
  justify-content: center; /* Center horizontally */
  align-items: center; /* Center vertically (restore "Middle of Canvas") */
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
  z-index: 15; /* Ensure it is above Footer (10) but below Nav (20) */
  box-sizing: border-box; 
  overflow: hidden; 
}

.legend-overlay {
  pointer-events: auto; /* Re-enable for the guide */
  background: var(--ui-glass-bg); 
  border: 1px solid var(--ui-glass-border);
  backdrop-filter: blur(var(--ui-glass-blur)); 
  -webkit-backdrop-filter: blur(var(--ui-glass-blur));
  padding: 6px; /* Compact default */
  border-radius: 12px;
  width: min(600px, 98vw); /* Wider by default */
  max-height: calc(100vh - 120px); 
  overflow-y: auto;
  overflow-x: hidden;
  box-shadow: 0 10px 30px var(--shadow-color);
  display: flex;
  flex-direction: column;
  align-items: center; /* Ensure children (H2) are centered */
  gap: 0;
  transition: all 0.3s ease;
}

/* When collapsed: make container transparent, only show title */
.legend-overlay:has(.guide-content.collapsed) {
  background: transparent !important;
  border-color: transparent !important;
  backdrop-filter: none !important;
  box-shadow: none !important;
  padding: 0 !important;
}

/* MINIMALIST PREVIEW PANEL */
#char-preview-panel {
  /* Minimalist Bar */
  background: rgba(0, 0, 0, 0.2); /* Subtle darkness */
  border: 1px solid transparent; /* Dynamic color will apply here */
  border-radius: 12px;
  padding: 6px 16px; /* Very compact */
  margin-bottom: 10px; /* Reduced margin */
  
  display: flex;
  align-items: center;
  justify-content: center; /* Centered content */
  gap: 20px;
  
  min-height: 50px; /* Reduced from 70px */
  transition: all 0.3s ease;
}

body.light-mode #char-preview-panel {
  background: #F1F5F9;
  border: 1px solid #E2E8F0;
}

.preview-left {
  display: flex;
  align-items: center;
  gap: 15px;
  width: 100%;
  justify-content: center;
}

.preview-visual-host {
  width: 30px;
  height: 30px;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Escalar el módulo visual dentro del preview */
.preview-visual-host .alpha-cell {
  transform: scale(1.2); /* Slightly smaller scale */
  border-color: transparent; 
  background: transparent;
  pointer-events: none;
}

.preview-char {
  font-size: 28px; /* Compact */
  font-weight: 700;
  color: var(--accent-color); /* Will be overridden by JS inline color */
  min-width: 30px;
  text-align: center;
}

/* Hide the label if user wants "creative unification" (color only) */
.preview-info {
  display: none; 
}

.legend-overlay h2 {
  font-size: 14px;
  margin: 0 0 16px 0;
  
  /* Match Nav Tab Active Style */
  background-color: var(--btn-primary-bg);
  color: var(--btn-primary-text); /* Always white - matches nav tabs */
  padding: 10px 20px;
  border-radius: 20px;
  border: 1px solid var(--brand-primary);
  
  text-align: center;
  box-shadow: 0 2px 8px rgba(99, 102, 241, 0.15);
  text-transform: uppercase;
  letter-spacing: 1px;
  
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  transition: all 0.2s ease;
  width: fit-content;
  min-width: auto;
  margin-left: auto;
  margin-right: auto;
  position: relative;
  z-index: 1;
}

body.light-mode .legend-overlay h2 {
  background-color: var(--brand-primary);
  border-color: #1E40AF;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.2);
}

.legend-overlay h2:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.25), 0 2px 6px rgba(0,0,0,0.15);
}

/* Dark mode: avoid hover overlap artifacts */
body:not(.light-mode) .legend-overlay h2:hover {
  transform: none;
  box-shadow: 0 3px 10px rgba(99, 102, 241, 0.22), 0 2px 6px rgba(0,0,0,0.2);
}

.legend-overlay h2:active {
  transform: scale(0.98);
}

.legend-desc {
  font-size: 13px;
  color: var(--text-color);
  opacity: 0.9;
  margin-bottom: 12px;
  line-height: 1.5;
  font-weight: 400;
  letter-spacing: 0.3px;
}

/* =========================================
   ALPHABET GUIDE (VISUAL SPACE / GRID)
   ========================================= */

/* The Container - "Organized in Space" */
#alphabet-grid {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap; /* WRAP CONTENT NATURALLY */
  width: 100%;
  max-width: 100%;
  margin: 0;
  gap: 2px; /* Hyper Density Gap */
  padding: 0; /* No outer padding */
  justify-content: center; 
  align-items: flex-start;
}

/* The Group Card - "Ghost Cluster" */
.legend-group {
  flex: 1 1 auto;
  width: auto;
  min-width: 65px; /* Dense default */
  max-width: 100%;
  
  background: transparent;
  border-radius: 8px;
  padding: 2px; /* Minimalist default */
  border: 1px solid transparent; 
  
  display: flex;
  flex-direction: column;
  align-items: center; 
  position: relative;
  
  transition: all 0.3s ease;
}

/* INTERACTIVE VISUAL UNIFIER */
.legend-group:hover {
  background: rgba(255, 255, 255, 0.03);
  border-color: rgba(255, 255, 255, 0.1);
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

/* The "Totem" - Visual Anchor */
.legend-group::before {
  content: '';
  display: block;
  width: 20px;
  height: 3px;
  background: var(--group-color);
  border-radius: 3px;
  margin-bottom: 4px; /* Tighther anchor */
  box-shadow: 0 0 6px var(--group-color);
  opacity: 0.6;
  transition: all 0.3s ease;
}
.legend-group:hover::before {
  opacity: 1;
  width: 36px; 
  transform: scaleY(1.5);
}

.group-header {
  display: none;
}

/* Inner Grid */
.group-grid {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 2px;
}

/* Collapsible Content */
.guide-content {
  overflow: hidden;
  max-height: 80vh; 
  opacity: 1;
  transition: max-height 0.4s ease, opacity 0.3s ease, margin 0.3s ease;
  margin-top: 10px;
}

.guide-content.collapsed {
  max-height: 0 !important;
  opacity: 0 !important;
  margin-top: 0 !important;
  margin-bottom: 0 !important;
  padding-top: 0 !important;
  padding-bottom: 0 !important;
  pointer-events: none;
  visibility: hidden;
  overflow: hidden; /* Ensure nothing leaks */
}

/* Cell Styles */
.alpha-cell {
  position: relative;
  width: 34px;
  height: 34px;
  flex-shrink: 0;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--surface-border);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  cursor: pointer;
}

.mini-module {
  width: 26px;
  height: 26px;
  transition: transform 0.3s ease;
}

/* Hover Effects */
@media (hover: hover) {
  .alpha-cell:hover .mini-module { transform: scale(1.15); }
  .alpha-cell:hover {
    transform: scale(1.05);
    border-color: var(--brand-primary);
    background: var(--btn-secondary-bg);
  }
}
@media (hover: none) {
  .alpha-cell:active { opacity: 0.7; transform: scale(0.95); }
}

/* Scrollbar Styling */
.legend-overlay { scroll-behavior: smooth; }
.legend-overlay::-webkit-scrollbar { width: 6px; }
.legend-overlay::-webkit-scrollbar-track { background: transparent; }
.legend-overlay::-webkit-scrollbar-thumb { background: var(--surface-border); border-radius: 3px; }

/* ============================================
    RESPONSIVE DESIGN (Consolidated)
   ============================================ */

/* Mobile Standard (Ref: iPhone 12 Pro 390px, Pixel XL 412px) */
@media (max-width: 600px) {
  h1 { font-size: 20px; padding: 4px 0; } /* Ultra-compact even on mobile */
  
  /* Generator UI Container - Add margin on small screens */
  #ui-container {
    margin-left: 12px;
    margin-right: 12px;
    width: calc(100% - 24px);
    padding: 10px 10px;
  }

  #ui-container .maker-actions { justify-content: center; }
  
  /* Container for the 3D Words */
  h1 .text-layer {
    display: flex;
    flex-direction: column; /* Force stack on mobile */
    align-items: center;
    padding: 12px 16px; /* Adjusted padding for mobile */
    gap: 8px; /* More vertical gap between word rows */
    
    background-color: rgba(99, 102, 241, 0.15);
    backdrop-filter: blur(var(--ui-glass-blur));
    border-radius: 16px;
    width: fit-content;
    max-width: 95vw; /* Constrain to viewport */
  }
  
  /* The Individual Words */
  .word-row {
    gap: 8px; /* Comfortable letter spacing on mobile */
    justify-content: center;
    width: 100%;
    flex-wrap: wrap; /* Allow wrapping if word is too long */
  }

  /* The Letters - BIGGER NOW */
  h1 .letter-char {
    font-size: 30px; /* Increased from 22px to fill space */
  }
  
  /* Nav Bar - Clean Wrap, No Scroll */
  #nav-container { 
    padding: 3px 4px; 
    gap: 6px;
    overflow: visible; /* No scroll */
    justify-content: center; /* Center everything */
    width: fit-content;
    max-width: 90%;
  }
  .nav-tab { font-size: 12px; padding: 6px 8px; min-height: 40px; }

  #game-ui-container {
    padding-left: 18px;
    padding-right: 18px;
  }

  .game-hud {
    padding-left: 10px;
    padding-right: 10px;
  }

  .feedback-time {
    left: 16px;
    font-size: 10px;
  }

  #feedbackDisplay {
    padding-left: 52px;
    padding-right: 36px;
  }

  /* Game HUD compact on small screens */
  #game-ui-container .stat-pill {
    height: 30px;
    padding: 4px 10px;
    gap: 6px;
  }
  #game-ui-container .stat-label { font-size: 9px; }
  #game-ui-container .stat-value { font-size: 13px; }
  #game-ui-container .stat-pill.feedback {
    flex-basis: 100%;
    justify-content: center;
    width: 86%;
    max-width: 360px;
    margin: 0 auto;
  }
  .progress-track { height: 6px; }
  .target-wrapper { gap: 12px; }
  .progress-track { width: 100%; max-width: 360px; }
  .target-display h2 { font-size: 20px; }

  /* Home UI: avoid overlap with header/nav on small screens */
  #home-ui-container {
    justify-content: center;
    align-items: center;
    padding-top: calc(var(--home-top-offset) + env(safe-area-inset-top));
    padding-bottom: calc(var(--home-bottom-offset) + env(safe-area-inset-bottom));
  }

  .legend-overlay {
    width: min(600px, 94vw);
    max-height: calc(100vh - var(--home-top-offset) - var(--home-bottom-offset) - 20px);
  }
}

@media (max-width: 550px) {
  #ui-container {
    grid-template-columns: 1fr;
    grid-template-areas:
      "input"
      "actions";
  }

  #ui-container .maker-actions { justify-content: center; }
}

@media (max-width: 480px) {
  #ui-container .maker-actions {
    flex-wrap: wrap;
    justify-content: center;
  }
}

@media (min-width: 450px) and (max-width: 600px) {
  #game-ui-container .stat-pill.feedback {
    width: 88%;
    max-width: 380px;
  }
}

@media (min-width: 601px) {
  .stats-row {
    justify-content: space-between;
    flex-wrap: nowrap;
    gap: 6px;
    padding: 0 12px;
  }

  #game-ui-container .stat-pill.score { order: 1; }
  #game-ui-container .stat-pill.feedback { order: 2; }
  #game-ui-container .stat-pill.level { order: 3; }
}

/* Micro Mobile (Galaxy Fold Cover < 350px) */
@media (max-width: 350px) {
  /* Only shrink if absolutely necessary */
  h1 .letter-char { font-size: 24px; }
  .nav-tab { font-size: 11px; padding: 6px 8px; }
  
  /* Even tighter */
  .legend-group { min-width: 50px; }
  
  .alpha-cell { width: 28px; height: 28px; }
  .mini-module { width: 20px; height: 20px; }
}

/* Landscape */
@media (max-width: 900px) and (orientation: landscape) {
  .legend-overlay {
    max-height: calc(100vh - 40px);
    width: 80%;
  }
}

/* =========================================
   GAME UI & THEMING
   ========================================= */
/* GAMEPLAY TEXT HUD HIGHLIGHTING (Consolidated) */
.char-done { color: var(--text-color-light); text-decoration: line-through; opacity: 0.6; }
.char-current { color: var(--brand-primary); text-decoration: underline; text-underline-offset: 4px; font-weight: 700; }
.char-future { color: var(--text-color); opacity: 0.4; }
.char-hidden { color: var(--text-color-light); opacity: 0.25; letter-spacing: 2px; }

.feedback-msg.success { color: #44ff44; }
.feedback-msg.error { color: #ff4444; }

body.light-mode .feedback-msg.success { color: #15803d; }
body.light-mode .feedback-msg.error { color: #b91c1c; }
body.light-mode .stat-pill {
  background: var(--ui-surface-light);
  border-color: var(--ui-border-light);
  box-shadow:
    0 2px 8px var(--ui-shadow-light),
    inset 0 0 0 1px var(--ui-inset-light);
  backdrop-filter: blur(5px);
}
body.light-mode .target-display {
  background: var(--ui-surface-light);
  border: 1px solid var(--ui-border-light);
  box-shadow:
    0 2px 8px var(--ui-shadow-light),
    inset 0 0 0 1px var(--ui-inset-light);
  backdrop-filter: blur(5px);
}
body.light-mode .target-display h2 {
  color: #0F172A;
  text-shadow:
    0 0 1px rgba(15, 23, 42, 0.45),
    0 2px 3px rgba(15, 23, 42, 0.2);
  font-weight: 700;
}
body.light-mode #targetWordDisplay {
  color: #0F172A;
  font-weight: 700;
  opacity: 1;
}
body.light-mode .progress-track {
  background: var(--ui-surface-light-alt);
  border-color: var(--ui-border-light);
  box-shadow:
    0 2px 8px var(--ui-shadow-light),
    inset 0 0 0 1px var(--ui-inset-light);
}
body.light-mode .instructions {
  background: var(--ui-surface-light);
  border-color: var(--ui-border-light);
  box-shadow:
    0 2px 8px var(--ui-shadow-light),
    inset 0 0 0 1px var(--ui-inset-light);
}
body.light-mode .stat-label,
body.light-mode .instructions,
body.light-mode .target-display .label {
  color: #1F2937;
  font-weight: 600;
}
body.light-mode .target-display .label {
  opacity: 0.85;
}

body.light-mode button#themeButton {
  border: 1px solid var(--ui-border-light);
  box-shadow:
    0 2px 8px var(--ui-shadow-light),
    inset 0 0 0 1px var(--ui-inset-light);
}

body.light-mode .instructions {
  color: #1F2937;
  opacity: 0.95;
}


