/* Theme variables */
:root {
  --synex-black: #0a0a0f;
  --synex-dark: #12121a;
  --synex-surface: #1a1a28;
  --synex-elevated: #242436;
  --synex-border: #2d2d42;
  --synex-white: #ffffff;
  --synex-gray-100: #e8e8f0;
  --synex-gray-200: #c8c8d8;
  --synex-gray-300: #9898b0;
  --synex-gray-400: #686880;
  --synex-purple: #7c3aed;
  --synex-purple-light: #a78bfa;
  --synex-purple-dark: #5b21b6;
  --synex-cyan: #06b6d4;
  --synex-green: #10b981;
  --synex-yellow: #f59e0b;
  --synex-red: #ef4444;
  --color-clue-active: var(--synex-purple);
  --color-clue-revealed: var(--synex-gray-400);
  --color-guess-correct: var(--synex-green);
  --color-guess-wrong: var(--synex-red);
  --font-display: "Avenir Next", "Optima", "Trebuchet MS", sans-serif;
  --font-body: "Avenir Next", "Optima", "Trebuchet MS", sans-serif;
  --font-mono: "SF Mono", "Fira Code", "Consolas", monospace;
  --text-xs: clamp(0.75rem, 2vw, 0.875rem);
  --text-sm: clamp(0.875rem, 2.5vw, 1rem);
  --text-base: clamp(1rem, 3vw, 1.125rem);
  --text-lg: clamp(1.125rem, 3.5vw, 1.25rem);
  --text-xl: clamp(1.25rem, 4vw, 1.5rem);
  --text-2xl: clamp(1.5rem, 5vw, 2rem);
  --text-3xl: clamp(2rem, 6vw, 3rem);
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-12: 3rem;
  --space-16: 4rem;
  --radius-sm: 0.375rem;
  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;
  --radius-xl: 1rem;
  --radius-full: 9999px;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.3);
  --shadow-glow: 0 0 20px rgba(124, 58, 237, 0.3);
  --focus-ring: 0 0 0 3px rgba(124, 58, 237, 0.5);
}

/* Light theme adjustments */
@media (prefers-color-scheme: light) {
  :root {
    --synex-black: #ffffff;
    --synex-dark: #f8f8fc;
    --synex-surface: #f0f0f8;
    --synex-elevated: #e8e8f0;
    --synex-border: #c0c0d0;
    --synex-white: #0a0a0f;
    --synex-gray-100: #1a1a28;
    --synex-gray-200: #2d2d42;
    --synex-gray-300: #3a3a50;
    --synex-gray-400: #505068;
    --synex-purple-dark: #6d28d9;
  }
}

/* Base reset */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* Page baseline */
body {
  font-family: var(--font-body);
  background: radial-gradient(circle at top, rgba(124, 58, 237, 0.2), transparent 55%),
    radial-gradient(circle at 20% 80%, rgba(6, 182, 212, 0.25), transparent 45%),
    var(--synex-black);
  color: var(--synex-gray-100);
  min-height: 100vh;
  line-height: 1.6;
  touch-action: manipulation;
}

/* Ambient background texture */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 200 200'%3E%3Ccircle cx='40' cy='40' r='2' fill='%23ffffff' fill-opacity='0.08'/%3E%3Ccircle cx='140' cy='80' r='2' fill='%2306b6d4' fill-opacity='0.12'/%3E%3Ccircle cx='100' cy='160' r='2' fill='%237c3aed' fill-opacity='0.12'/%3E%3C/svg%3E");
  opacity: 0.6;
  pointer-events: none;
  z-index: -1;
}

a {
  color: inherit;
  text-decoration: none;
}

:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

/* Screen reader helpers */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.sr-only-focusable:focus {
  position: static;
  width: auto;
  height: auto;
  margin: 0;
  overflow: visible;
  clip: auto;
  white-space: normal;
}

/* Header and navigation */
.site-header {
  padding: var(--space-6) var(--space-8) var(--space-4);
}

.top-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  font-weight: 700;
}

.brand-logo {
  width: 200px;
  height: auto;
  overflow: visible;
}

.brand-title {
  font-size: var(--text-xl);
  letter-spacing: 0.05em;
}

.nav-actions {
  display: flex;
  gap: var(--space-2);
}

.icon-button {
  background: var(--synex-surface);
  border: 1px solid var(--synex-border);
  color: var(--synex-gray-100);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-full);
  font-size: var(--text-sm);
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}

.icon-button:hover {
  transform: translateY(-1px);
  border-color: var(--synex-purple-light);
  box-shadow: var(--shadow-sm);
}

/* Layout grid */
.game-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 320px);
  gap: var(--space-8);
  padding: 0 var(--space-8) var(--space-12);
}

/* Mode toggle */
.mode-switch {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2);
  background: rgba(55, 55, 75, 0.9);
  border-radius: var(--radius-full);
  border: 1px solid rgba(100, 100, 130, 0.5);
  box-shadow: var(--shadow-sm);
}

.mode-button {
  background: transparent;
  color: rgba(255, 255, 255, 0.85);
  border: none;
  padding: var(--space-2) var(--space-6);
  border-radius: var(--radius-full);
  cursor: pointer;
  font-size: var(--text-sm);
  font-weight: 500;
}

.mode-button:hover {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.1);
}

.mode-button.active {
  background: linear-gradient(120deg, var(--synex-purple), var(--synex-cyan));
  color: #ffffff;
  box-shadow: var(--shadow-glow);
}

.mode-status {
  margin-left: auto;
  font-size: var(--text-sm);
  color: rgba(255, 255, 255, 0.9);
  font-weight: 500;
}

/* Game board layout */
.game-board {
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
}

/* Clue progression steps */
.clue-progress {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(40px, 1fr));
  gap: var(--space-2);
}

.clue-step {
  background: var(--synex-surface);
  border-radius: var(--radius-md);
  padding: var(--space-2);
  text-align: center;
  border: 1px solid var(--synex-border);
  color: var(--synex-gray-200);
  font-weight: 700;
}

.clue-step.active {
  background: var(--synex-purple);
  color: var(--synex-white);
  box-shadow: var(--shadow-glow);
}

.clue-step.revealed {
  background: var(--synex-elevated);
  color: var(--synex-gray-200);
}

/* Clue card */
.clue-card {
  background: linear-gradient(135deg, var(--synex-surface) 0%, var(--synex-elevated) 100%);
  border: 1px solid var(--synex-border);
  border-radius: var(--radius-xl);
  padding: var(--space-6);
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow-lg);
}

.clue-card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 4px;
  background: linear-gradient(90deg, var(--synex-purple), var(--synex-cyan));
}

.clue-tier-badge {
  position: absolute;
  top: var(--space-4);
  right: var(--space-4);
  background: var(--synex-purple);
  color: white;
  font-size: var(--text-xs);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-full);
  font-weight: 600;
}

.clue-text {
  font-size: var(--text-lg);
  color: var(--synex-gray-100);
  padding-right: 4rem;
  white-space: pre-line;
}

.category-hint {
  margin-top: var(--space-3);
  padding-top: var(--space-3);
  border-top: 1px solid var(--synex-border);
  font-size: var(--text-sm);
  color: var(--synex-cyan);
  font-weight: 500;
}

.category-hint:empty {
  display: none;
}

.guess-counter {
  margin-top: var(--space-3);
  padding: var(--space-2) var(--space-3);
  background: rgba(124, 58, 237, 0.15);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--synex-purple-light);
  text-align: center;
}

.guess-counter:empty {
  display: none;
}

/* Guess history */
.guess-history {
  background: rgba(55, 55, 75, 0.85);
  border-radius: var(--radius-lg);
  border: 1px solid rgba(100, 100, 130, 0.5);
  padding: var(--space-4);
}

.guess-history h2 {
  font-size: var(--text-base);
  margin-bottom: var(--space-3);
  color: #ffffff;
  font-weight: 700;
}

.guess-list {
  list-style: none;
  display: grid;
  gap: var(--space-2);
}

.guess-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  background: var(--synex-elevated);
  border: 1px solid var(--synex-border);
  font-family: var(--font-mono);
  letter-spacing: 0.2em;
  text-transform: uppercase;
}

.guess-item.correct {
  background: rgba(16, 185, 129, 0.2);
  border-color: rgba(16, 185, 129, 0.5);
  color: var(--synex-white);
}

.guess-item.wrong {
  background: rgba(239, 68, 68, 0.15);
  border-color: rgba(239, 68, 68, 0.4);
}

/* Guess input area */
.input-area {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

/* Letter tiles */
.tile-row {
  display: grid;
  grid-template-columns: repeat(5, minmax(48px, 1fr));
  gap: var(--space-2);
}

.letter-tile {
  height: clamp(56px, 14vw, 72px);
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--synex-surface);
  border: 2px solid var(--synex-border);
  border-radius: var(--radius-md);
  font-size: var(--text-2xl);
  font-weight: 700;
  font-family: var(--font-mono);
  text-transform: uppercase;
  transition: all 0.15s ease;
}

.letter-tile.filled {
  border-color: var(--synex-purple-light);
  background: var(--synex-elevated);
  animation: pop 0.1s ease;
}

.letter-tile.correct {
  background: var(--synex-green);
  border-color: var(--synex-green);
  color: white;
}

.letter-tile.incorrect {
  background: var(--synex-gray-400);
  border-color: var(--synex-gray-400);
}

.guess-input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  pointer-events: auto;
}

/* Buttons */
.primary-button,
.ghost-button {
  padding: var(--space-3) var(--space-6);
  border-radius: var(--radius-full);
  border: none;
  font-size: var(--text-sm);
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.primary-button {
  background: linear-gradient(120deg, var(--synex-purple), var(--synex-cyan));
  color: white;
  box-shadow: var(--shadow-glow);
}

.primary-button:hover {
  transform: translateY(-2px);
}

.ghost-button {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.3);
  color: #ffffff;
}

.ghost-button:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.5);
}

/* On-screen keyboard */
.keyboard {
  display: grid;
  gap: var(--space-2);
}

.keyboard-row {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  gap: var(--space-2);
}

.keyboard-key {
  padding: var(--space-2);
  border-radius: var(--radius-md);
  border: 1px solid var(--synex-border);
  background: var(--synex-surface);
  color: var(--synex-gray-100);
  font-size: var(--text-xs);
  cursor: pointer;
  font-weight: 600;
  transition: transform 0.1s ease, background 0.1s ease;
}

.keyboard-key:hover {
  transform: translateY(-1px);
}

.keyboard-key.action {
  grid-column: span 2;
  background: var(--synex-purple);
  color: #ffffff;
  font-weight: 700;
  border-color: var(--synex-purple);
}

.keyboard-key.action:hover {
  background: var(--synex-purple-light);
}

/* Sidebar stats */
.stats-panel {
  background: rgba(55, 55, 75, 0.95);
  border: 1px solid rgba(100, 100, 130, 0.5);
  border-radius: var(--radius-xl);
  padding: var(--space-6);
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  color: #ffffff;
}

.stats-panel h2 {
  color: #ffffff;
  font-weight: 700;
}

.stats-block {
  white-space: pre-line;
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  color: var(--synex-gray-200);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-4);
}

.stat-label {
  font-size: var(--text-xs);
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.75);
  letter-spacing: 0.08em;
  font-weight: 600;
}

.stat-value {
  font-size: var(--text-lg);
  font-weight: 700;
  color: #ffffff;
}

/* Modals */
.modal {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(10, 10, 15, 0.75);
  padding: var(--space-6);
  z-index: 20;
}

.modal.open {
  display: flex;
}

.modal-content {
  background: var(--synex-elevated);
  border-radius: var(--radius-xl);
  padding: var(--space-6);
  max-width: 500px;
  width: 100%;
  border: 1px solid var(--synex-border);
  box-shadow: var(--shadow-lg);
}

.modal-content h2 {
  margin-bottom: var(--space-3);
}

.modal-content p,
.modal-content ol {
  font-size: var(--text-sm);
  color: var(--synex-gray-200);
}

.modal-close {
  background: transparent;
  color: var(--synex-gray-100);
  border: 1px solid var(--synex-border);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-full);
  float: right;
  cursor: pointer;
  font-weight: 500;
}

.setting-group {
  margin-bottom: var(--space-4);
}

.setting-label {
  display: block;
  font-size: var(--text-sm);
  font-weight: 600;
  margin-bottom: var(--space-2);
  color: var(--synex-gray-100);
}

.difficulty-options {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.difficulty-option {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto auto;
  gap: var(--space-1) var(--space-3);
  padding: var(--space-3);
  border-radius: var(--radius-md);
  border: 1px solid var(--synex-border);
  background: var(--synex-surface);
  cursor: pointer;
  transition: border-color 0.2s ease, background 0.2s ease;
}

.difficulty-option:hover {
  border-color: var(--synex-purple-light);
}

.difficulty-option input {
  grid-row: span 2;
  align-self: center;
  width: 18px;
  height: 18px;
  accent-color: var(--synex-purple);
}

.difficulty-btn {
  font-weight: 600;
  color: var(--synex-gray-100);
}

.difficulty-desc {
  font-size: var(--text-xs);
  color: var(--synex-gray-300);
}

.difficulty-option:has(input:checked) {
  border-color: var(--synex-purple);
  background: rgba(124, 58, 237, 0.1);
}

.toggle {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  font-size: var(--text-sm);
}

/* Footer */
.site-footer {
  padding: var(--space-12) var(--space-8);
  border-top: 1px solid var(--synex-border);
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.footer-brand {
  display: flex;
  align-items: center;
  gap: var(--space-4);
}

.footer-logo {
  width: 200px;
  overflow: visible;
}

.footer-links {
  display: flex;
  gap: var(--space-4);
  flex-wrap: wrap;
}

.footer-copy {
  font-size: var(--text-xs);
  color: var(--synex-gray-200);
}

/* Toast notifications */
.toast {
  position: fixed;
  top: 50%;
  left: 50%;
  background: var(--synex-surface);
  color: var(--synex-white);
  padding: var(--space-4) var(--space-6);
  border-radius: var(--radius-lg);
  border: 1px solid var(--synex-border);
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transform: translate(-50%, calc(-50% + 10px));
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
  z-index: 999;
  text-align: center;
  font-size: var(--text-lg);
  min-width: min(90vw, 320px);
  max-width: min(90vw, 520px);
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, -50%);
  pointer-events: auto;
}

/* Animations */
@keyframes pop {
  50% { transform: scale(1.08); }
}

@keyframes clueReveal {
  0% { opacity: 0; transform: translateY(20px); }
  100% { opacity: 1; transform: translateY(0); }
}

.clue-entering {
  animation: clueReveal 0.4s ease-out;
}

@keyframes celebrate {
  0%, 100% { transform: scale(1); }
  25% { transform: scale(1.1) rotate(-3deg); }
  75% { transform: scale(1.1) rotate(3deg); }
}

.victory .letter-tile {
  animation: celebrate 0.5s ease infinite;
  animation-delay: calc(var(--tile-index) * 0.1s);
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-5px); }
  40%, 80% { transform: translateX(5px); }
}

.guess-wrong {
  animation: shake 0.4s ease;
}

/* Letter fade-out animation after wrong guess */
@keyframes letterFadeOut {
  0% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.5;
    transform: scale(0.95);
  }
  100% {
    opacity: 0;
    transform: scale(0.8);
  }
}

.letter-tile.fading {
  animation: letterFadeOut 0.4s ease forwards;
  animation-delay: calc(var(--tile-index) * 0.08s);
}

/* Player greeting in header */
.player-greeting {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-sm);
  color: var(--synex-gray-200);
  margin-left: auto;
  margin-right: var(--space-4);
}

.player-greeting:empty {
  display: none;
}

.player-name {
  font-weight: 600;
  color: var(--synex-purple-light);
}

.streak-badge {
  background: linear-gradient(120deg, var(--synex-purple), var(--synex-cyan));
  color: white;
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: 700;
}

/* Setting note */
.setting-note {
  font-size: var(--text-xs);
  color: var(--synex-cyan);
  margin-bottom: var(--space-3);
  font-style: italic;
}

/* Welcome modal */
.welcome-modal {
  z-index: 100;
  background: rgba(10, 10, 15, 0.95);
}

.welcome-content {
  text-align: center;
  max-width: 400px;
}

.welcome-logo {
  width: 80px;
  height: 80px;
  margin: 0 auto var(--space-4);
}

.welcome-logo svg {
  width: 100%;
  height: 100%;
}

.welcome-content h2 {
  font-size: var(--text-2xl);
  background: linear-gradient(120deg, var(--synex-purple), var(--synex-cyan));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: var(--space-2);
}

.welcome-tagline {
  font-size: var(--text-base);
  color: var(--synex-gray-200);
  margin-bottom: var(--space-4);
}

.welcome-desc {
  font-size: var(--text-sm);
  color: var(--synex-gray-300);
  margin-bottom: var(--space-6);
  line-height: 1.6;
}

.welcome-form {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.welcome-input {
  background: var(--synex-surface);
  border: 2px solid var(--synex-border);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  font-size: var(--text-base);
  color: var(--synex-gray-100);
  text-align: center;
  transition: border-color 0.2s ease;
}

.welcome-input::placeholder {
  color: var(--synex-gray-400);
}

.welcome-input:focus {
  outline: none;
  border-color: var(--synex-purple);
}

.welcome-btn {
  padding: var(--space-4) var(--space-6);
  font-size: var(--text-base);
  font-weight: 700;
}

/* Responsive layout */
@media (max-width: 960px) {
  .game-shell {
    grid-template-columns: 1fr;
  }

  .stats-panel {
    order: 2;
  }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
