/* =========================================================
   WORDY — Modern Design System & Game Styles
   ========================================================= */

:root {
  /* Fonts */
  --font-main: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;

  /* Theme Defaults (theme-dark) */
  --bg-app: #0b0f19;
  --bg-header: rgba(15, 23, 42, 0.75);
  --border-color: rgba(255, 255, 255, 0.08);
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-dim: #64748b;

  /* Tile Colors */
  --tile-empty-bg: rgba(255, 255, 255, 0.02);
  --tile-empty-border: #334155;
  --tile-active-border: #64748b;
  --tile-text: #f8fafc;

  /* Wordle Status Colors (Default Dark Palette) */
  --color-correct: #10b981;        /* Emerald */
  --color-correct-border: #059669;
  --color-present: #f59e0b;        /* Amber */
  --color-present-border: #d97706;
  --color-absent: #334155;         /* Deep Slate */
  --color-absent-border: #1e293b;

  /* Keyboards */
  --key-bg: #1e293b;
  --key-bg-hover: #334155;
  --key-bg-active: #475569;
  --key-text: #f1f5f9;
  --key-shadow: 0 3px 0 #0f172a;

  /* Modals & Surfaces */
  --modal-bg: rgba(15, 23, 42, 0.92);
  --card-bg: rgba(30, 41, 59, 0.7);
  --card-border: rgba(255, 255, 255, 0.1);
  --card-shadow: 0 20px 40px -15px rgba(0, 0, 0, 0.6);

  /* Accents */
  --accent-primary: #6366f1;
  --accent-primary-hover: #4f46e5;
  --accent-gradient: linear-gradient(135deg, #6366f1 0%, #8b5cf6 50%, #d946ef 100%);
  --toast-bg: rgba(15, 23, 42, 0.95);

  /* Sizing tokens */
  --tile-size: 58px;
  --tile-gap: 6px;
  --keyboard-max-width: 500px;
}

/* Midnight OLED Theme */
body.theme-midnight {
  --bg-app: #000000;
  --bg-header: rgba(10, 10, 10, 0.85);
  --border-color: rgba(255, 255, 255, 0.12);
  --text-main: #ffffff;
  --text-muted: #a1a1aa;
  --tile-empty-bg: #09090b;
  --tile-empty-border: #27272a;
  --tile-active-border: #52525b;
  --key-bg: #18181b;
  --key-bg-hover: #27272a;
  --key-shadow: 0 3px 0 #09090b;
  --modal-bg: rgba(10, 10, 10, 0.96);
  --card-bg: #121215;
}

/* Light Theme */
body.theme-light {
  --bg-app: #f1f5f9;
  --bg-header: rgba(255, 255, 255, 0.85);
  --border-color: rgba(0, 0, 0, 0.08);
  --text-main: #0f172a;
  --text-muted: #475569;
  --text-dim: #94a3b8;
  --tile-empty-bg: #ffffff;
  --tile-empty-border: #cbd5e1;
  --tile-active-border: #64748b;
  --tile-text: #0f172a;
  --color-absent: #78716c;
  --color-absent-border: #57534e;
  --key-bg: #e2e8f0;
  --key-bg-hover: #cbd5e1;
  --key-bg-active: #94a3b8;
  --key-text: #0f172a;
  --key-shadow: 0 3px 0 #94a3b8;
  --modal-bg: rgba(255, 255, 255, 0.96);
  --card-bg: rgba(248, 250, 252, 0.9);
  --card-border: rgba(0, 0, 0, 0.08);
  --card-shadow: 0 20px 40px -15px rgba(0, 0, 0, 0.15);
  --toast-bg: rgba(15, 23, 42, 0.95);
}

/* High Contrast Mode (Colorblind Friendly) */
body.high-contrast {
  --color-correct: #ea580c;        /* High-visibility Vibrant Orange */
  --color-correct-border: #c2410c;
  --color-present: #0284c7;        /* High-visibility Sky Blue */
  --color-present-border: #0369a1;
}

/* Global Reset */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: auto;
  font-family: var(--font-main);
  background-color: var(--bg-app);
  color: var(--text-main);
  transition: background-color 0.3s ease, color 0.3s ease;
}

/* Canvas Confetti */
#confetti-canvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: 9999;
}

/* Main Layout Wrapper */
#app-wrapper {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  max-width: 600px;
  margin: 0 auto;
  position: relative;
}

/* Header */
#game-header {
  height: 60px;
  min-height: 60px;
  padding: 0 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-color);
  background: var(--bg-header);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: 100;
}

.header-left, .header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  width: 38px;
  height: 38px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.18s ease;
}

.icon-btn:hover {
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.08);
  border-color: var(--border-color);
  transform: translateY(-1px);
}

.icon-btn:active {
  transform: translateY(1px);
}

.mode-pill {
  display: flex;
  align-items: center;
  gap: 5px;
  background: rgba(99, 102, 241, 0.12);
  border: 1px solid rgba(99, 102, 241, 0.3);
  color: #818cf8;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.mode-pill:hover {
  background: rgba(99, 102, 241, 0.22);
  border-color: rgba(99, 102, 241, 0.5);
  transform: scale(1.03);
}

.mode-icon {
  font-size: 0.85rem;
  color: #a5b4fc;
}

/* Logo */
.logo-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}

.logo-tile {
  width: 28px;
  height: 28px;
  background: var(--accent-gradient);
  color: #ffffff;
  font-size: 1.1rem;
  font-weight: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4);
}

.logo-title {
  font-size: 1.45rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  background: linear-gradient(135deg, #ffffff 0%, #cbd5e1 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

body.theme-light .logo-title {
  background: linear-gradient(135deg, #0f172a 0%, #334155 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

/* Toast Container */
#toast-container {
  position: absolute;
  top: 72px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  pointer-events: none;
}

.toast {
  background: var(--toast-bg);
  color: #f8fafc;
  padding: 10px 18px;
  border-radius: 12px;
  font-size: 0.9rem;
  font-weight: 700;
  border: 1px solid rgba(255, 255, 255, 0.15);
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.4);
  animation: toastIn 0.25s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  pointer-events: auto;
}

.toast.fade-out {
  animation: toastOut 0.25s ease forwards;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateY(-12px) scale(0.95); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes toastOut {
  from { opacity: 1; transform: translateY(0) scale(1); }
  to { opacity: 0; transform: translateY(-10px) scale(0.95); }
}

/* Game Board Area */
#game-main {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
  overflow: hidden;
}

#board-container {
  width: 100%;
  max-width: 360px;
  aspect-ratio: 5 / 6;
  max-height: 440px;
  display: flex;
  align-items: center;
  justify-content: center;
}

#board {
  display: grid;
  grid-template-rows: repeat(6, 1fr);
  grid-gap: var(--tile-gap);
  width: 100%;
  height: 100%;
}

.board-row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  grid-gap: var(--tile-gap);
}

/* Individual Tiles */
.tile {
  width: 100%;
  height: 100%;
  aspect-ratio: 1;
  border: 2px solid var(--tile-empty-border);
  background: var(--tile-empty-bg);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.85rem;
  font-weight: 800;
  text-transform: uppercase;
  color: var(--tile-text);
  box-shadow: inset 0 1px 2px rgba(255, 255, 255, 0.04);
  perspective: 1000px;
  transition: border-color 0.15s ease;
}

/* Tile States */
.tile.active {
  border-color: var(--tile-active-border);
  animation: popLetter 0.12s cubic-bezier(0.18, 0.89, 0.32, 1.28);
}

.tile.revealed {
  border-color: transparent;
  color: #ffffff !important;
}

.tile.correct {
  background-color: var(--color-correct);
  border-color: var(--color-correct-border);
  box-shadow: 0 4px 14px rgba(16, 185, 129, 0.3);
}

.tile.present {
  background-color: var(--color-present);
  border-color: var(--color-present-border);
  box-shadow: 0 4px 14px rgba(245, 158, 11, 0.3);
}

.tile.absent {
  background-color: var(--color-absent);
  border-color: var(--color-absent-border);
}

/* Animations */
@keyframes popLetter {
  0% { transform: scale(0.85); }
  60% { transform: scale(1.12); }
  100% { transform: scale(1); }
}

.board-row.shake {
  animation: rowShake 0.5s ease-in-out;
}

@keyframes rowShake {
  0%, 100% { transform: translateX(0); }
  15%, 45%, 75% { transform: translateX(-6px); }
  30%, 60%, 90% { transform: translateX(6px); }
}

/* Flip Card 3D Animation */
.tile.flip {
  animation: tileFlip 0.55s ease forwards;
}

@keyframes tileFlip {
  0% {
    transform: rotateX(0deg);
  }
  49% {
    transform: rotateX(90deg);
  }
  50% {
    transform: rotateX(90deg);
  }
  100% {
    transform: rotateX(0deg);
  }
}

/* Win Wave Bounce */
.tile.bounce {
  animation: tileBounce 0.65s ease forwards;
}

@keyframes tileBounce {
  0%, 100% { transform: translateY(0); }
  30% { transform: translateY(-22px) scale(1.05); }
  60% { transform: translateY(6px); }
}

/* Virtual Keyboard Area */
#keyboard-container {
  width: 100%;
  max-width: var(--keyboard-max-width);
  margin: 0 auto;
  padding: 0 8px 12px 8px;
}

#keyboard {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.keyboard-row {
  display: flex;
  justify-content: center;
  gap: 5px;
  touch-action: manipulation;
}

.key-btn {
  font-family: inherit;
  font-size: 1rem;
  font-weight: 700;
  height: 52px;
  background-color: var(--key-bg);
  color: var(--key-text);
  border: none;
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex: 1;
  max-width: 44px;
  box-shadow: var(--key-shadow);
  transition: background-color 0.2s ease, transform 0.08s ease, filter 0.15s ease;
  user-select: none;
}

.key-btn:hover {
  background-color: var(--key-bg-hover);
  filter: brightness(1.1);
}

.key-btn:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.5);
  background-color: var(--key-bg-active);
}

.key-wide {
  flex: 1.5;
  max-width: 68px;
  font-size: 0.8rem;
  letter-spacing: 0.03em;
}

/* Keyboard status coloring after tile reveals */
.key-btn.correct {
  background-color: var(--color-correct) !important;
  color: #ffffff !important;
  box-shadow: 0 3px 0 var(--color-correct-border) !important;
}

.key-btn.present {
  background-color: var(--color-present) !important;
  color: #ffffff !important;
  box-shadow: 0 3px 0 var(--color-present-border) !important;
}

.key-btn.absent {
  background-color: var(--color-absent) !important;
  color: rgba(255, 255, 255, 0.45) !important;
  box-shadow: 0 3px 0 var(--color-absent-border) !important;
}

/* Modals */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1rem;
  opacity: 1;
  transition: opacity 0.25s ease;
}

.modal-overlay.hidden {
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
}

.modal-card {
  background: var(--modal-bg);
  border: 1px solid var(--card-border);
  border-radius: 20px;
  width: 100%;
  max-width: 480px;
  max-height: 88vh;
  overflow-y: auto;
  box-shadow: var(--card-shadow);
  display: flex;
  flex-direction: column;
  animation: modalEnter 0.28s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes modalEnter {
  from { opacity: 0; transform: translateY(16px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-header {
  padding: 1.25rem 1.5rem 0.8rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-color);
}

.modal-header h2 {
  font-size: 1.3rem;
  font-weight: 800;
  letter-spacing: -0.01em;
}

.modal-close {
  background: transparent;
  border: none;
  font-size: 1.8rem;
  color: var(--text-muted);
  cursor: pointer;
  line-height: 1;
  padding: 4px 8px;
  border-radius: 8px;
  transition: color 0.15s ease;
}

.modal-close:hover {
  color: var(--text-main);
}

.modal-body {
  padding: 1.5rem;
  font-size: 0.95rem;
  line-height: 1.6;
}

/* Help Modal Specifics */
.help-desc {
  font-size: 1.05rem;
  margin-bottom: 0.8rem;
}

.help-rules {
  list-style-type: none;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
  color: var(--text-muted);
}

.help-rules li::before {
  content: "•";
  color: #6366f1;
  font-weight: bold;
  display: inline-block;
  width: 1em;
}

.examples-section {
  border-top: 1px solid var(--border-color);
  padding-top: 1.2rem;
  margin-top: 1rem;
}

.examples-section h3 {
  font-size: 0.95rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 1rem;
}

.example-row {
  margin-bottom: 1.1rem;
}

.example-tiles {
  display: flex;
  gap: 5px;
  margin-bottom: 0.4rem;
}

.small-tile {
  width: 38px;
  height: 38px;
  font-size: 1.2rem;
  font-weight: 800;
  border-radius: 6px;
}

.help-footer-info {
  border-top: 1px solid var(--border-color);
  padding-top: 1rem;
  font-size: 0.88rem;
  color: var(--text-muted);
}

/* Game Over Banner */
.game-over-banner {
  text-align: center;
  padding: 1rem;
  background: var(--card-bg);
  border-radius: 14px;
  border: 1px solid var(--card-border);
  margin-bottom: 1.5rem;
}

.game-over-banner h3 {
  font-size: 1.6rem;
  font-weight: 900;
  margin-bottom: 0.25rem;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

#revealed-word {
  font-weight: 800;
  letter-spacing: 0.08em;
  color: #f59e0b;
}

/* Stats Overview */
.stats-overview {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 1.8rem;
  text-align: center;
}

.stat-box {
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  padding: 10px 4px;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.stat-val {
  font-size: 1.65rem;
  font-weight: 800;
  color: var(--text-main);
  line-height: 1.2;
}

.stat-lbl {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-top: 2px;
}

.section-heading {
  font-size: 0.95rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 0.9rem;
}

/* Guess Distribution */
.guess-distribution {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 1.8rem;
}

.dist-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  font-weight: 700;
}

.dist-num {
  width: 14px;
  text-align: center;
  color: var(--text-muted);
}

.dist-bar-wrap {
  flex: 1;
  background: rgba(255, 255, 255, 0.04);
  border-radius: 4px;
  height: 22px;
  overflow: hidden;
}

.dist-bar {
  background: var(--color-absent);
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 8px;
  color: #ffffff;
  border-radius: 4px;
  min-width: 22px;
  font-size: 0.75rem;
  transition: width 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}

.dist-bar.highlight {
  background: var(--color-correct);
}

/* Action Area in Stats */
.stats-action-area {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-top: 1px solid var(--border-color);
  padding-top: 1.2rem;
  gap: 12px;
  flex-wrap: wrap;
}

.countdown-wrap {
  display: flex;
  flex-direction: column;
}

.countdown-lbl {
  font-size: 0.75rem;
  text-transform: uppercase;
  color: var(--text-muted);
  font-weight: 600;
}

.countdown-time {
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  font-variant-numeric: tabular-nums;
  color: #818cf8;
}

.action-buttons-wrap {
  display: flex;
  gap: 10px;
  flex: 1;
  justify-content: flex-end;
}

.btn-primary, .btn-secondary, .btn-danger {
  padding: 10px 18px;
  border-radius: 12px;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  white-space: nowrap;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  border: none;
}

.btn-primary {
  background: var(--color-correct);
  color: #ffffff;
  box-shadow: 0 4px 15px rgba(16, 185, 129, 0.35);
}

.btn-primary:hover {
  filter: brightness(1.1);
  transform: translateY(-1px);
}

.btn-secondary {
  background: rgba(99, 102, 241, 0.15);
  border: 1px solid rgba(99, 102, 241, 0.3);
  color: #818cf8;
}

.btn-secondary:hover {
  background: rgba(99, 102, 241, 0.25);
  transform: translateY(-1px);
}

.btn-danger {
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: #f87171;
  width: 100%;
  justify-content: center;
}

.btn-danger:hover {
  background: rgba(239, 68, 68, 0.25);
}

/* Settings Items */
.settings-list {
  display: flex;
  flex-direction: column;
  gap: 1.4rem;
}

.setting-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.setting-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.setting-title {
  font-weight: 700;
  font-size: 1rem;
}

.setting-desc {
  font-size: 0.8rem;
  color: var(--text-muted);
}

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

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

.slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background-color: #334155;
  transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  border-radius: 34px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 20px;
  width: 20px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  border-radius: 50%;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

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

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

/* Select element in settings */
.theme-select {
  background: var(--card-bg);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  padding: 6px 12px;
  border-radius: 8px;
  font-family: inherit;
  font-weight: 600;
  font-size: 0.85rem;
  outline: none;
  cursor: pointer;
}

.settings-danger-zone {
  border-top: 1px solid var(--border-color);
  padding-top: 1.2rem;
  margin-top: 0.5rem;
}

/* Utility */
.hidden {
  display: none !important;
}

/* Mobile Screen Tuning */
@media (max-height: 680px) {
  #game-header {
    height: 50px;
    min-height: 50px;
  }
  .tile {
    font-size: 1.45rem;
  }
  .key-btn {
    height: 44px;
    font-size: 0.88rem;
  }
}
