*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg-tile: #252540;
  --border: #3a3a55;
  --text: #e8e8f0;
  --text-dim: #6a6a88;
  --red: #e74c3c;
  --red-glow: rgba(231, 76, 60, 0.3);
  --red-bg: rgba(231, 76, 60, 0.15);
  --green: #4ade80;
  --green-glow: rgba(74, 222, 128, 0.3);
  --yellow: #f1c40f;
  --yellow-glow: rgba(241, 196, 15, 0.3);
  --accent: #8b5cf6;
  --accent-glow: rgba(139, 92, 246, 0.4);
  --neon-purple: #b44aff;
  --neon-purple-glow: rgba(180, 74, 255, 0.6);
  --neon-purple-glow-soft: rgba(180, 74, 255, 0.3);
  --game-bg: #15202b;
  --row-bg: rgba(17, 27, 36, 0.9);
  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

body {
  font-family: var(--font);
  background: var(--game-bg);
  color: var(--text);
  height: 100dvh;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  overflow-x: hidden;
}

/* === App Container === */
#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 500px;
  margin: 0 auto;
  padding: 6px;
}

/* === Game Area (neon border) === */
.game-area {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  border: 2px solid var(--neon-purple);
  border-radius: 16px;
  background: rgba(21, 32, 43, 0.9);
  box-shadow: inset 0 0 10px var(--neon-purple-glow-soft);
  overflow: hidden;
  filter:
    drop-shadow(0 0 6px var(--neon-purple-glow))
    drop-shadow(0 0 14px var(--neon-purple-glow-soft))
    drop-shadow(0 0 30px var(--neon-purple-glow-soft));
}

/* === Top Bar === */
.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 14px;
  z-index: 2;
  flex-shrink: 0;
}

.title-area {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.daily-badge {
  font-size: 11px;
  font-weight: 700;
  color: #ffab00;
  background: rgba(255, 171, 0, 0.15);
  padding: 2px 8px;
  border-radius: 8px;
  letter-spacing: 1px;
  animation: daily-glow 2s ease-in-out infinite alternate;
}

.daily-badge.hidden { display: none; }

@keyframes daily-glow {
  from { box-shadow: 0 0 4px rgba(255, 171, 0, 0.3); }
  to { box-shadow: 0 0 10px rgba(255, 171, 0, 0.6); }
}

.title-text {
  font-size: 16px;
  font-weight: 900;
  letter-spacing: 3px;
  color: var(--neon-purple);
  text-shadow: 0 0 10px var(--neon-purple-glow);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: opacity 0.15s;
}
.title-text:active {
  opacity: 0.6;
}

.title-sub {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 2px;
  color: var(--text-dim);
  text-transform: uppercase;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.hub-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: rgba(180, 74, 255, 0.15);
  border: 1px solid rgba(180, 74, 255, 0.3);
  border-radius: 8px;
  color: var(--neon-purple);
  text-decoration: none;
  transition: all 0.2s;
}

.hub-btn:active {
  background: rgba(180, 74, 255, 0.3);
}

.discord-login-btn.hidden { display: none; }
.discord-login-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  background: rgba(88, 101, 242, 0.25);
  border: 1px solid rgba(88, 101, 242, 0.4);
  border-radius: 8px;
  padding: 6px 10px;
  color: #8b9df7;
  cursor: pointer;
  font-size: 11px;
  font-weight: 700;
  font-family: var(--font);
  text-decoration: none;
  transition: all 0.2s;
  letter-spacing: 0.5px;
}

.discord-login-btn:active {
  background: rgba(88, 101, 242, 0.4);
}

.discord-login-btn.logged-in {
  background: rgba(74, 222, 128, 0.15);
  border-color: rgba(74, 222, 128, 0.3);
  color: var(--green);
  pointer-events: none;
}

.discord-login-btn .user-pic {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  object-fit: cover;
}

.stats-btn {
  background: rgba(55, 55, 95, 0.6);
  border: 1px solid rgba(139, 92, 246, 0.3);
  border-radius: 8px;
  padding: 6px 8px;
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.stats-btn:active {
  background: rgba(80, 80, 120, 0.8);
}

/* === Game Frame === */
.game-frame {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 0 8px 6px;
  overflow: hidden;
}

/* === Input Area (input tiles + length toggle) === */
.input-area {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: center;
  padding: 2px 8px;
  order: 2;
  flex-shrink: 0;
}

.len-toggle {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 2px solid var(--neon-purple);
  background: rgba(180, 74, 255, 0.15);
  color: var(--neon-purple);
  font-size: 16px;
  font-weight: 800;
  font-family: var(--font);
  cursor: pointer;
  flex-shrink: 0;
  transition: all 0.2s;
  text-shadow: 0 0 8px var(--neon-purple-glow);
  -webkit-tap-highlight-color: transparent;
}

.len-toggle:active {
  background: rgba(180, 74, 255, 0.35);
  transform: scale(0.9);
}

/* === Length Selector (legacy, hidden) === */
.length-selector {
  display: none;
  align-items: center;
  gap: 10px;
  padding: 4px 4px 6px;
  flex-shrink: 0;
}

.length-label {
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 2px;
  color: var(--text-dim);
  white-space: nowrap;
}

.length-buttons {
  display: flex;
  gap: 4px;
  flex: 1;
  justify-content: center;
}

.len-btn {
  width: 32px;
  height: 28px;
  font-size: 13px;
  font-weight: 700;
  font-family: var(--font);
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-tile);
  color: var(--text-dim);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  -webkit-tap-highlight-color: transparent;
}

.len-btn:active {
  transform: scale(0.95);
}

.len-btn.active {
  background: rgba(180, 74, 255, 0.2);
  border-color: var(--neon-purple);
  color: var(--neon-purple);
  box-shadow: 0 0 8px var(--neon-purple-glow-soft);
  font-weight: 800;
}

.len-btn.disabled {
  opacity: 0.3;
  pointer-events: none;
}

/* === Input Row === */
.input-row {
  display: flex;
  justify-content: center;
  gap: 5px;
  flex: 1;
}

.input-tile {
  flex: 1;
  max-width: 42px;
  aspect-ratio: 1;
  border: 2px solid var(--border);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  font-weight: 800;
  color: var(--text);
  background: var(--bg-tile);
  transition: border-color 0.15s;
  text-transform: uppercase;
}

.input-tile.filled {
  border-color: var(--neon-purple);
  box-shadow: 0 0 6px var(--neon-purple-glow-soft);
}

/* Reorder: guesses at top, input+keyboard at bottom */
.guesses-wrapper  { order: 1; }
.input-area       { order: 2; }
#keyboard         { order: 3; }

/* === Guess History === */
.guesses-wrapper {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

#guesses {
  display: flex;
  flex-direction: column;
  flex: 1;
  gap: 2px;
  padding: 2px 0;
}

/* === Guess Row === */
.guess-row {
  display: flex;
  align-items: stretch;
  gap: 5px;
  padding: 3px 6px;
  border-radius: 8px;
  background: var(--row-bg);
  animation: rowIn 0.3s ease;
  min-width: 0;
  flex: 1;
  min-height: 0;
}

/* Guess number badge — hidden in SP mode */
.guess-num {
  display: none;
}

/* Letter tiles */
.guess-letters {
  display: flex;
  gap: 3px;
  flex: 1;
  justify-content: center;
  align-items: stretch;
  min-width: 0;
}

.letter-tile {
  flex: 1;
  max-width: 50px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(11px, 3.5vw, 16px);
  font-weight: 800;
  border-radius: 5px;
  background: var(--bg-tile);
  border: 2px solid var(--border);
  color: var(--text);
  text-transform: uppercase;
}

.letter-tile.neutral {
  color: var(--text);
  border-color: var(--border);
}

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

.letter-tile.correct {
  color: var(--green);
  border-color: var(--green);
  background: rgba(74, 222, 128, 0.15);
}

.letter-tile.present {
  color: var(--yellow);
  border-color: var(--yellow);
  background: rgba(241, 196, 15, 0.15);
}

.guess-row .letter-tile {
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  transition: transform 0.1s ease;
}

.letter-tile.tile-tap {
  transform: scale(0.88);
}

.guess-row.all-absent .letter-tile.absent {
  box-shadow: 0 0 8px var(--red-glow);
}

/* Empty pre-rendered rows */
.guess-row.empty-row {
  opacity: 0.25;
  animation: none;
}
.guess-row.empty-row .letter-tile {
  cursor: default;
}
.guess-row.empty-row .empty-counts {
  visibility: hidden;
}

/* Loss overlay */
.win-bubble.loss {
  border-color: var(--red, #f87171);
  box-shadow: 0 0 40px rgba(248, 113, 113, 0.2);
}

/* Count indicators */
.guess-counts {
  display: flex;
  gap: 3px;
  flex-shrink: 0;
  align-self: center;
}

.count {
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 800;
  border-radius: 5px;
}

.count-correct {
  background: var(--green);
  color: #1a1a2e;
  box-shadow: 0 0 8px var(--green-glow);
}

.count-present {
  background: var(--yellow);
  color: #1a1a2e;
  box-shadow: 0 0 8px var(--yellow-glow);
}

.count-absent {
  background: var(--red);
  color: #fff;
  box-shadow: 0 0 8px var(--red-glow);
}

.count.zero {
  opacity: 0.25;
  box-shadow: none;
}

/* === Keyboard === */
#keyboard {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 100%;
  max-width: 520px;
  margin: 4px auto 0;
  flex-shrink: 0;
  padding: 0 2px;
}

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

.key {
  flex: 1;
  max-width: 48px;
  height: 40px;
  padding: 0 2px;
  font-size: 16px;
  font-weight: 700;
  font-family: var(--font);
  border: 1px solid rgba(139, 92, 246, 0.35);
  border-radius: 8px;
  background: rgba(55, 55, 95, 0.95);
  color: #f0f0ff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  transition: all 0.2s ease;
  text-shadow: 0 0 8px rgba(200, 200, 255, 0.25);
  box-shadow: 0 0 4px rgba(139, 92, 246, 0.12);
  -webkit-tap-highlight-color: transparent;
}

.key:active { background: rgba(80, 80, 120, 0.95); }

.key.wide {
  max-width: 64px;
  font-size: 12px;
  letter-spacing: 0.5px;
}

.key.enter-key {
  background: rgba(74, 222, 128, 0.3);
  color: var(--green);
  border-color: rgba(74, 222, 128, 0.4);
  text-shadow: 0 0 8px rgba(74, 222, 128, 0.4);
}

.key.enter-key:active {
  background: rgba(74, 222, 128, 0.5);
}

.key.absent {
  background: rgba(40, 30, 35, 0.6);
  color: rgba(231, 76, 60, 0.35);
  border: 1px solid rgba(231, 76, 60, 0.12);
  text-shadow: none;
  box-shadow: none;
}

.key.inword {
  background: rgba(74, 222, 128, 0.25);
  color: var(--green);
  border: 1px solid rgba(74, 222, 128, 0.4);
  text-shadow: 0 0 8px rgba(74, 222, 128, 0.4);
  box-shadow: 0 0 6px rgba(74, 222, 128, 0.15);
}

/* === Loading Overlay === */
.loading-overlay {
  position: absolute;
  inset: 0;
  background: rgba(21, 32, 43, 0.95);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  z-index: 20;
  border-radius: 16px;
}

.loading-overlay.hidden { display: none; }

.loading-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid rgba(180, 74, 255, 0.2);
  border-top-color: var(--neon-purple);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.loading-text {
  font-size: 14px;
  color: var(--text-dim);
  letter-spacing: 1px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* === Win Overlay === */
#win-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  border-radius: 16px;
  animation: fadeIn 0.3s ease;
}

#win-overlay.hidden { display: none; }

.win-bubble {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  background: var(--game-bg);
  padding: 28px 36px;
  border-radius: 20px;
  border: 2px solid var(--green);
  box-shadow: 0 0 40px var(--green-glow);
  animation: popIn 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  max-width: 90%;
  text-align: center;
}

.win-emoji {
  font-size: 48px;
  line-height: 1;
}

.win-word {
  font-size: 32px;
  font-weight: 900;
  letter-spacing: 6px;
  text-transform: uppercase;
  color: #fff;
}

.win-detail {
  font-size: 14px;
  color: var(--text-dim);
  letter-spacing: 1px;
}

.play-again-btn {
  margin-top: 4px;
  padding: 12px 32px;
  font-size: 15px;
  font-weight: 700;
  font-family: var(--font);
  border: none;
  border-radius: 10px;
  background: rgba(74, 222, 128, 0.25);
  color: var(--green);
  border: 1.5px solid rgba(74, 222, 128, 0.4);
  cursor: pointer;
  letter-spacing: 1px;
  transition: all 0.2s;
}

.play-again-btn:active {
  background: rgba(74, 222, 128, 0.4);
  transform: scale(0.97);
}

/* === Stats Overlay === */
#stats-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 15;
  border-radius: 16px;
  animation: fadeIn 0.2s ease;
}

#stats-overlay.hidden { display: none; }

.stats-panel {
  background: var(--game-bg);
  border: 2px solid var(--neon-purple);
  box-shadow: 0 0 30px var(--neon-purple-glow-soft);
  border-radius: 16px;
  padding: 20px 24px;
  width: 90%;
  max-width: 360px;
  max-height: 80%;
  overflow-y: auto;
  animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.stats-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 3px;
  color: var(--neon-purple);
}

.stats-close {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 22px;
  cursor: pointer;
  padding: 4px;
  line-height: 1;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 18px;
}

.stat-card {
  background: rgba(37, 37, 64, 0.6);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  text-align: center;
}

.stat-value {
  font-size: 24px;
  font-weight: 900;
  color: var(--text);
  line-height: 1.2;
}

.stat-value.green { color: var(--green); }
.stat-value.purple { color: var(--neon-purple); }
.stat-value.yellow { color: var(--yellow); }

.stat-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1.5px;
  color: var(--text-dim);
  margin-top: 4px;
}

.stats-history-label {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 2px;
  color: var(--text-dim);
  margin-bottom: 8px;
}

.stats-history {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 200px;
  overflow-y: auto;
}

.history-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  background: rgba(37, 37, 64, 0.4);
  border-radius: 8px;
  font-size: 13px;
}

.history-word {
  font-weight: 800;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--text);
}

.history-guesses {
  font-weight: 700;
  color: var(--green);
  font-size: 12px;
}

.history-loss {
  color: var(--red);
}

.stats-empty {
  font-size: 13px;
  color: var(--text-dim);
  text-align: center;
  padding: 16px 0;
}

/* === Error Toast === */
.toast {
  position: absolute;
  top: 60px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(231, 76, 60, 0.9);
  color: #fff;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  z-index: 25;
  animation: toastIn 0.3s ease, toastOut 0.3s ease 1.5s forwards;
  pointer-events: none;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(-10px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

@keyframes toastOut {
  from { opacity: 1; }
  to { opacity: 0; }
}

/* === Animations === */
@keyframes rowIn {
  from { opacity: 0; transform: translateY(-12px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes popIn {
  0% { transform: scale(0.5); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

/* === Scrollbar === */
.stats-history::-webkit-scrollbar { width: 4px; }
.stats-history::-webkit-scrollbar-track { background: transparent; }
.stats-history::-webkit-scrollbar-thumb { background: #30363d; border-radius: 2px; }
.stats-panel::-webkit-scrollbar { width: 4px; }
.stats-panel::-webkit-scrollbar-track { background: transparent; }
.stats-panel::-webkit-scrollbar-thumb { background: #30363d; border-radius: 2px; }
