:root {
  /* Design Tokens from DESIGN.md */
  --color-primary: #0c0c11;
  --color-secondary: #e8e8f0;
  --color-tertiary: #16151c;
  --color-elevated: #1c1b24;
  --color-muted: #2a2a33;
  --color-border: #2e2d3b;

  /* Neon Workshop Palette */
  --neon-emerald: #00ff9d;
  --neon-emerald-glow: rgba(0, 255, 157, 0.45);
  --neon-amber: #ffb703;
  --neon-amber-glow: rgba(255, 183, 3, 0.45);
  --neon-cyan: #00e5ff;
  --neon-cyan-glow: rgba(0, 229, 255, 0.4);
  --neon-magenta: #ff007f;
  --neon-magenta-glow: rgba(255, 0, 127, 0.4);

  /* Typography */
  --font-family-base: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-family-display: "Trebuchet MS", "Lucida Grande", system-ui, sans-serif;
  --font-family-serif: Georgia, "Times New Roman", serif;

  /* Border Radii */
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 16px;

  /* Spacing */
  --space-sm: 1rem;
  --space-md: 2rem;
  --space-lg: 4rem;

  /* Tile Size */
  --tile-size: min(58px, 14vw);
  --tile-gap: min(8px, 2vw);
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100%;
  height: 100%;
  background-color: var(--color-primary);
  color: var(--color-secondary);
  font-family: var(--font-family-base);
  font-size: 1rem;
  overflow-x: hidden;
  user-select: none;
  -webkit-user-select: none;
}

/* Atmospheric Neon Backdrop */
.glow-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
  background: 
    radial-gradient(circle at 50% 0%, rgba(0, 229, 255, 0.08) 0%, transparent 60%),
    radial-gradient(circle at 10% 90%, rgba(255, 0, 127, 0.05) 0%, transparent 40%),
    radial-gradient(circle at 90% 80%, rgba(0, 255, 157, 0.04) 0%, transparent 45%);
  z-index: 0;
}

/* App Container */
.app-container {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 520px;
  margin: 0 auto;
  padding: 0.5rem 0.75rem;
  justify-content: space-between;
}

/* Header */
.cyber-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0;
  border-bottom: 1px solid rgba(232, 232, 240, 0.1);
}

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

.icon-btn {
  background: rgba(22, 21, 28, 0.7);
  border: 1px solid var(--color-border);
  color: var(--color-secondary);
  border-radius: var(--radius-md);
  padding: 0.45rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  backdrop-filter: blur(8px);
}

.icon-btn:hover {
  background: rgba(28, 27, 36, 0.9);
  border-color: var(--neon-cyan);
  color: #fff;
  box-shadow: 0 0 10px var(--neon-cyan-glow);
  transform: translateY(-1px);
}

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

.brand-title {
  text-align: center;
}

.brand-sub {
  display: block;
  font-size: 0.65rem;
  letter-spacing: 0.2em;
  color: var(--neon-cyan);
  font-weight: 700;
  text-shadow: 0 0 8px var(--neon-cyan-glow);
  margin-bottom: -2px;
}

.neon-title {
  font-family: var(--font-family-display);
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: #ffffff;
  text-shadow: 0 0 8px rgba(255, 255, 255, 0.6), 0 0 20px var(--neon-cyan-glow);
}

/* Mode Bar */
.mode-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0.4rem 0;
  padding: 0.25rem 0.4rem;
  background: rgba(22, 21, 28, 0.6);
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
  backdrop-filter: blur(10px);
}

.mode-tabs {
  display: flex;
  gap: 0.25rem;
}

.mode-tab {
  background: transparent;
  border: none;
  color: rgba(232, 232, 240, 0.6);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  padding: 0.35rem 0.65rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.mode-tab:hover {
  color: var(--color-secondary);
}

.mode-tab.active {
  background: var(--color-elevated);
  color: #fff;
  box-shadow: 0 0 10px rgba(0, 229, 255, 0.2);
  border: 1px solid rgba(0, 229, 255, 0.3);
}

.pulse-dot {
  width: 6px;
  height: 6px;
  background-color: var(--neon-emerald);
  border-radius: 50%;
  box-shadow: 0 0 8px var(--neon-emerald);
  animation: pulse-glow 2s infinite ease-in-out;
}

@keyframes pulse-glow {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.8); }
}

.status-indicator {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: rgba(232, 232, 240, 0.7);
}

/* Game Board */
.game-board-container {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-grow: 1;
  padding: 0.25rem 0;
}

.board {
  display: grid;
  grid-template-rows: repeat(6, 1fr);
  gap: var(--tile-gap);
  padding: 0.2rem;
}

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

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

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

/* Tile */
.tile {
  width: var(--tile-size);
  height: var(--tile-size);
  background: var(--color-tertiary);
  border: 2px solid var(--color-border);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-family-display);
  font-size: calc(var(--tile-size) * 0.48);
  font-weight: 700;
  text-transform: uppercase;
  color: var(--color-secondary);
  transition: border-color 0.15s ease, transform 0.15s ease;
  perspective: 1000px;
}

.tile.active-input {
  border-color: rgba(232, 232, 240, 0.7);
  box-shadow: 0 0 10px rgba(232, 232, 240, 0.2);
  animation: tile-pop 0.1s ease-in-out;
}

@keyframes tile-pop {
  0% { transform: scale(1); }
  50% { transform: scale(1.1); }
  100% { transform: scale(1); }
}

/* Tile States with Neon Glow */
.tile.correct {
  background: rgba(0, 255, 157, 0.12);
  border-color: var(--neon-emerald);
  color: #ffffff;
  box-shadow: 0 0 14px var(--neon-emerald-glow), inset 0 0 10px rgba(0, 255, 157, 0.15);
  text-shadow: 0 0 8px var(--neon-emerald);
}

.tile.present {
  background: rgba(255, 183, 3, 0.12);
  border-color: var(--neon-amber);
  color: #ffffff;
  box-shadow: 0 0 14px var(--neon-amber-glow), inset 0 0 10px rgba(255, 183, 3, 0.15);
  text-shadow: 0 0 8px var(--neon-amber);
}

.tile.absent {
  background: var(--color-muted);
  border-color: rgba(42, 42, 51, 0.8);
  color: rgba(232, 232, 240, 0.4);
  box-shadow: none;
}

/* 3D Flip Animation */
.tile.flip {
  animation: tile-flip 0.5s ease forwards;
}

@keyframes tile-flip {
  0% { transform: rotateX(0deg); }
  50% { transform: rotateX(90deg); }
  100% { transform: rotateX(0deg); }
}

/* Virtual Keyboard */
.keyboard-container {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
  padding-bottom: 0.5rem;
}

.kb-row {
  display: flex;
  justify-content: center;
  gap: 5px;
  width: 100%;
}

.kb-key {
  height: min(52px, 12vw);
  background: var(--color-tertiary);
  border: 1px solid var(--color-border);
  color: var(--color-secondary);
  border-radius: var(--radius-sm);
  font-family: var(--font-family-base);
  font-size: min(0.95rem, 3.8vw);
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  max-width: 44px;
  cursor: pointer;
  transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.4);
}

.kb-key:hover {
  background: var(--color-elevated);
  border-color: rgba(0, 229, 255, 0.4);
  color: #fff;
  transform: translateY(-1px);
}

.kb-key:active {
  transform: translateY(1px);
}

.kb-key.wide {
  flex: 1.5;
  max-width: 66px;
  font-size: min(0.8rem, 3.2vw);
  letter-spacing: 0.03em;
}

/* Keyboard Key Status Glows */
.kb-key.correct {
  background: rgba(0, 255, 157, 0.2);
  border-color: var(--neon-emerald);
  color: #ffffff;
  box-shadow: 0 0 10px var(--neon-emerald-glow);
  text-shadow: 0 0 6px var(--neon-emerald);
}

.kb-key.present {
  background: rgba(255, 183, 3, 0.2);
  border-color: var(--neon-amber);
  color: #ffffff;
  box-shadow: 0 0 10px var(--neon-amber-glow);
  text-shadow: 0 0 6px var(--neon-amber);
}

.kb-key.absent {
  background: #14141a;
  border-color: #1c1b24;
  color: rgba(232, 232, 240, 0.25);
  box-shadow: none;
}

/* Toast Notifications */
.toast-container {
  position: fixed;
  top: 12%;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 1000;
  pointer-events: none;
}

.toast {
  background: rgba(22, 21, 28, 0.95);
  color: #ffffff;
  border: 1px solid var(--neon-cyan);
  box-shadow: 0 0 16px var(--neon-cyan-glow);
  border-radius: var(--radius-md);
  padding: 0.6rem 1.2rem;
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  backdrop-filter: blur(12px);
  animation: toast-in 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275), toast-out 0.25s ease 2.2s forwards;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(-12px) scale(0.9); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes toast-out {
  from { opacity: 1; transform: translateY(0); }
  to { opacity: 0; transform: translateY(-12px); }
}

/* Cyber Dialogs (<dialog>) */
.cyber-dialog {
  border: none;
  background: transparent;
  padding: 0;
  margin: auto;
  max-width: 460px;
  width: calc(100% - 2rem);
  z-index: 100;
}

.cyber-dialog::backdrop {
  background: rgba(12, 12, 17, 0.85);
  backdrop-filter: blur(10px);
}

.dialog-content {
  background: rgba(22, 21, 28, 0.95);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-sm);
  box-shadow: 0 10px 35px rgba(0, 0, 0, 0.8), 0 0 25px rgba(0, 229, 255, 0.15);
  backdrop-filter: blur(16px);
  position: relative;
  overflow: hidden;
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.dialog-title {
  font-family: var(--font-family-display);
  font-size: 1.2rem;
  letter-spacing: 0.08em;
  color: #fff;
  text-shadow: 0 0 10px var(--neon-cyan-glow);
}

.dialog-close {
  background: none;
  border: none;
  color: rgba(232, 232, 240, 0.6);
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
  transition: color 0.15s ease;
}

.dialog-close:hover {
  color: #fff;
}

/* The Definition Reveal Neon Sign Card */
.neon-sign-card {
  position: relative;
  background: #08080c;
  border: 2px solid var(--neon-cyan);
  box-shadow: 0 0 20px var(--neon-cyan-glow), inset 0 0 15px rgba(0, 229, 255, 0.1);
  border-radius: var(--radius-md);
  padding: 1.2rem 1rem;
  text-align: center;
  margin-bottom: 1.2rem;
}

.neon-target-word {
  font-family: var(--font-family-display);
  font-size: 2.2rem;
  font-weight: 800;
  letter-spacing: 0.15em;
  color: #ffffff;
  text-transform: uppercase;
  text-shadow: 
    0 0 5px #00e5ff,
    0 0 15px #00e5ff,
    0 0 30px #00e5ff,
    0 0 60px #00e5ff;
  animation: neon-flicker 2.5s infinite alternate ease-in-out;
}

@keyframes neon-flicker {
  0%, 18%, 22%, 25%, 53%, 57%, 100% {
    opacity: 1;
    text-shadow: 
      0 0 5px #00e5ff,
      0 0 15px #00e5ff,
      0 0 30px #00e5ff,
      0 0 50px rgba(0, 229, 255, 0.8);
  }
  19%, 24%, 55% {
    opacity: 0.4;
    text-shadow: none;
  }
}

.neon-phonetic {
  font-size: 0.75rem;
  letter-spacing: 0.15em;
  color: var(--neon-cyan);
  opacity: 0.85;
  margin-top: 0.2rem;
}

.definition-body {
  background: var(--color-elevated);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 1rem;
  margin-bottom: 1.2rem;
}

.definition-label {
  font-size: 0.65rem;
  letter-spacing: 0.15em;
  color: var(--neon-amber);
  font-weight: 700;
  margin-bottom: 0.4rem;
}

.definition-text {
  font-family: var(--font-family-serif);
  font-size: 1.05rem;
  line-height: 1.5;
  color: #f1f1f8;
}

.neon-badge {
  background: rgba(0, 255, 157, 0.15);
  border: 1px solid var(--neon-emerald);
  color: var(--neon-emerald);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  padding: 0.25rem 0.6rem;
  border-radius: var(--radius-sm);
  box-shadow: 0 0 10px var(--neon-emerald-glow);
}

.neon-badge.lost {
  background: rgba(255, 0, 127, 0.15);
  border-color: var(--neon-magenta);
  color: var(--neon-magenta);
  box-shadow: 0 0 10px var(--neon-magenta-glow);
}

/* Dialog Action Buttons */
.dialog-actions {
  display: flex;
  gap: 0.6rem;
}

.cyber-btn {
  flex: 1;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
  font-family: var(--font-family-base);
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.cyber-btn.primary-glow {
  background: rgba(0, 255, 157, 0.15);
  border-color: var(--neon-emerald);
  color: #fff;
  box-shadow: 0 0 12px var(--neon-emerald-glow);
}

.cyber-btn.primary-glow:hover {
  background: rgba(0, 255, 157, 0.3);
  box-shadow: 0 0 20px var(--neon-emerald-glow);
  transform: translateY(-1px);
}

.cyber-btn.accent-glow {
  background: rgba(0, 229, 255, 0.15);
  border-color: var(--neon-cyan);
  color: #fff;
  box-shadow: 0 0 12px var(--neon-cyan-glow);
}

.cyber-btn.accent-glow:hover {
  background: rgba(0, 229, 255, 0.3);
  box-shadow: 0 0 20px var(--neon-cyan-glow);
  transform: translateY(-1px);
}

/* Stats Overview */
.stats-overview {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.5rem;
  margin-bottom: 1.5rem;
}

.stat-box {
  background: var(--color-elevated);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 0.6rem 0.3rem;
  text-align: center;
}

.stat-val {
  display: block;
  font-family: var(--font-family-display);
  font-size: 1.5rem;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 0 8px var(--neon-cyan-glow);
}

.stat-lbl {
  font-size: 0.6rem;
  font-weight: 700;
  color: rgba(232, 232, 240, 0.6);
  letter-spacing: 0.05em;
}

.distribution-title {
  font-size: 0.85rem;
  letter-spacing: 0.1em;
  color: var(--neon-cyan);
  margin-bottom: 0.6rem;
}

.distribution-chart {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

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

.dist-num {
  width: 12px;
  color: rgba(232, 232, 240, 0.7);
}

.dist-bar-wrapper {
  flex-grow: 1;
  background: var(--color-elevated);
  border-radius: var(--radius-sm);
  overflow: hidden;
  height: 22px;
}

.dist-bar {
  background: var(--color-muted);
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 8px;
  color: #fff;
  font-size: 0.75rem;
  min-width: 24px;
  transition: width 0.4s ease;
}

.dist-bar.highlight {
  background: var(--neon-emerald);
  box-shadow: 0 0 10px var(--neon-emerald-glow);
  color: #0c0c11;
  font-weight: 800;
}

/* Help Modal Styling */
.help-content {
  font-size: 0.9rem;
  line-height: 1.5;
  color: rgba(232, 232, 240, 0.85);
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}

.help-examples {
  margin: 0.5rem 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.example-row {
  display: flex;
  gap: 6px;
}

.example-row .tile {
  width: 36px;
  height: 36px;
  font-size: 1rem;
}

.example-desc {
  font-size: 0.8rem;
  margin-bottom: 0.4rem;
}

.color-correct {
  color: var(--neon-emerald);
  text-shadow: 0 0 5px var(--neon-emerald-glow);
}

.color-present {
  color: var(--neon-amber);
  text-shadow: 0 0 5px var(--neon-amber-glow);
}

.color-absent {
  color: rgba(232, 232, 240, 0.5);
}

.help-bonus {
  background: rgba(0, 229, 255, 0.08);
  border: 1px solid rgba(0, 229, 255, 0.3);
  border-radius: var(--radius-md);
  padding: 0.75rem;
}

.bonus-tag {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  color: var(--neon-cyan);
  margin-bottom: 0.3rem;
  text-shadow: 0 0 6px var(--neon-cyan-glow);
}

.hidden {
  display: none !important;
}
