:root {
  /* Unified Palette */
  --bg-color: #050505;
  --surface: #111111;
  --surface-border: #2a2a2a;
  --primary: #00ff41;
  /* Green for Credits */
  --primary-dim: rgba(0, 255, 65, 0.08);
  --secondary: #008F11;
  --accent: #00ccff;
  /* Blue for Hints */
  --accent-dim: rgba(0, 204, 255, 0.08);
  --danger: #ff3333;
  --locked: #333;
  --text: #e0e0e0;
  --text-muted: #888;
  --font-display: 'Rajdhani', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
  --safe-area-bottom: env(safe-area-inset-bottom);
  --kb-height: 200px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

body {
  background-color: var(--bg-color);
  color: var(--text);
  font-family: var(--font-display);
  margin: 0;
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

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

.fade-in {
  animation: fadeIn 0.3s ease-out forwards;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* --- CRT EFFECT --- */
.scanlines {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(rgba(18, 16, 16, 0) 50%, rgba(0, 0, 0, 0.25) 50%), linear-gradient(90deg, rgba(255, 0, 0, 0.06), rgba(0, 255, 0, 0.02), rgba(0, 0, 255, 0.06));
  background-size: 100% 2px, 3px 100%;
  pointer-events: none;
  z-index: 999;
  opacity: 0.4;
}

/* --- HEADER --- */
.app-header {
  padding: 15px 20px;
  background: rgba(10, 10, 10, 0.95);
  border-bottom: 1px solid var(--surface-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: 10;
  flex-shrink: 0;
}

.brand {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 1.2rem;
  letter-spacing: -1px;
  text-transform: uppercase;
  cursor: pointer;
}

.brand span {
  color: var(--primary);
}

.header-controls {
  display: flex;
  gap: 10px;
  align-items: center;
}

.user-rank {
  text-align: right;
}

.rank-title {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.rank-val {
  color: var(--primary);
  font-weight: bold;
  font-size: 0.9rem;
}

/* --- BUTTONS --- */
.btn-primary {
  background: transparent;
  border: 1px solid var(--primary);
  color: var(--primary);
  padding: 6px 12px;
  font-family: var(--font-mono);
  font-weight: bold;
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.2s;
  text-transform: uppercase;
  border-radius: 4px;
}

.btn-primary:hover {
  color: var(--primary);
  box-shadow: 0 0 10px rgba(0, 255, 65, 0.3);
}

.btn-accent {
  background: transparent;
  border: 1px solid var(--accent);
  color: var(--accent);
  padding: 6px 12px;
  font-family: var(--font-mono);
  font-weight: bold;
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.2s;
  text-transform: uppercase;
  border-radius: 4px;
}

.btn-accent:hover {
  box-shadow: 0 0 10px rgba(0, 204, 255, 0.3);
}

/* --- HUB SCREEN --- */
#hub-screen {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  padding-bottom: 80px;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 15px;
  margin-bottom: 30px;
}

.stats-card {
  background: var(--surface);
  border: 1px solid var(--surface-border);
  border-radius: 12px;
  padding: 15px;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}

.stats-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 4px;
  height: 100%;
  background: var(--primary);
}

.stats-card.hint-card::before {
  background: var(--accent);
}

.score-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-bottom: 5px;
}

.score-value {
  font-family: var(--font-mono);
  font-size: 1.8rem;
  font-weight: 700;
  letter-spacing: -1px;
}

.hint-text {
  color: var(--accent);
}

.section-title {
  font-size: 1rem;
  color: var(--text-muted);
  margin-bottom: 15px;
  text-transform: uppercase;
  letter-spacing: 2px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.section-title::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--surface-border);
}

.level-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 15px;
}

.level-node {
  background: var(--surface);
  border: 1px solid var(--surface-border);
  border-radius: 8px;
  padding: 15px;
  text-decoration: none;
  color: var(--text);
  transition: all 0.2s;
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  height: 120px;
  cursor: pointer;
}

.level-node:active {
  transform: scale(0.96);
}

.level-node.locked {
  opacity: 0.5;
  background: #080808;
  pointer-events: none;
  border-style: dashed;
}

.level-node.completed {
  border-color: var(--secondary);
  background: linear-gradient(135deg, var(--surface) 0%, rgba(0, 255, 65, 0.05) 100%);
}

.level-node.completed::after {
  content: '✔';
  position: absolute;
  top: 10px;
  right: 10px;
  color: var(--primary);
  font-size: 0.8rem;
}

.lvl-id {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-bottom: 5px;
}

.lvl-name {
  font-weight: 700;
  font-size: 1.1rem;
  line-height: 1.2;
}

.lvl-status {
  font-size: 0.7rem;
  margin-top: auto;
  padding-top: 10px;
  color: var(--primary);
  text-transform: uppercase;
}

/* --- GAME SCREEN --- */
#game-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#game-board {
  flex-grow: 1;
  overflow-y: auto;
  padding: 0 20px 20px;
  padding-bottom: calc(var(--kb-height) + 20px);
  scroll-behavior: smooth;
  max-width: 600px;
  margin: 0 auto;
  width: 100%;
}

.word-card {
  background: var(--surface);
  border-radius: 8px;
  padding: 20px;
  margin-top: 20px;
  transition: all 0.3s ease;
  border: 1px solid #333;
  position: relative;
}

.word-card.active {
  border-color: var(--primary);
  background: var(--primary-dim);
  box-shadow: 0 0 15px rgba(0, 255, 65, 0.15);
}

.word-card.solved {
  opacity: 0.6;
  filter: grayscale(0.8);
  border-color: #222;
}

.word-slots {
  display: flex;
  gap: 8px;
  margin-bottom: 15px;
  overflow-x: auto;
  padding-bottom: 5px;
  justify-content: center;
}

.slot {
  min-width: 32px;
  height: 45px;
  border-bottom: 2px solid #444;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  font-weight: bold;
  text-transform: uppercase;
  color: var(--text);
}

.slot.locked {
  color: var(--primary);
  border-bottom: 2px solid var(--primary);
  text-shadow: 0 0 5px rgba(0, 255, 65, 0.5);
}

.word-card.solved .slot {
  border-bottom: none;
  color: var(--primary);
}

.definition {
  text-align: center;
  font-family: 'Segoe UI', sans-serif;
  font-size: 0.95rem;
  color: var(--text-muted);
  line-height: 1.5;
}

/* Error Meter */
.error-track {
  height: 3px;
  background: #222;
  margin-top: 12px;
  margin-bottom: 12px;
  border-radius: 2px;
  overflow: hidden;
  width: 100%;
}

.error-fill {
  height: 100%;
  background: var(--primary);
  width: 0%;
  transition: width 0.3s, background-color 0.3s;
}

/* --- KEYBOARD --- */
#virtual-keyboard {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  height: var(--kb-height);
  background: #0f0f0f;
  border-top: 1px solid #333;
  display: grid;
  grid-template-rows: repeat(3, 1fr);
  padding: 10px;
  gap: 6px;
  z-index: 100;
  user-select: none;
}

.kb-row {
  display: flex;
  justify-content: center;
  gap: 4px;
}

.key {
  background: #222;
  color: white;
  border-radius: 4px;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  font-weight: bold;
  cursor: pointer;
  max-width: 45px;
  transition: background 0.1s;
}

.key:active {
  background: #444;
  transform: translateY(2px);
}

.key.big-key {
  flex: 1.5;
  max-width: 65px;
  font-size: 0.9rem;
}

.key.used-wrong {
  opacity: 0.3;
  background: #000;
}

@media (min-width: 768px) {
  #virtual-keyboard {
    display: none;
  }
  
  #game-board {
    padding-bottom: 20px;
  }
  
  .level-list {
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  }
}

/* --- MODAL --- */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(2px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: all;
}

.modal-content {
  background: #111;
  border: 1px solid var(--primary);
  box-shadow: 0 0 20px rgba(0, 255, 65, 0.1);
  width: 90%;
  max-width: 400px;
  padding: 0;
  transform: scale(0.95);
  transition: transform 0.3s;
}

.modal-overlay.active .modal-content {
  transform: scale(1);
}

.modal-header {
  background: rgba(0, 255, 65, 0.1);
  padding: 15px 20px;
  border-bottom: 1px solid #222;
}

.modal-header h2 {
  margin: 0;
  font-size: 1rem;
  color: var(--primary);
  letter-spacing: 2px;
}

.modal-body {
  padding: 20px;
  text-align: center;
  color: var(--text);
  line-height: 1.5;
  font-size: 0.9rem;
}

.modal-footer {
  padding: 0 20px 20px;
  display: flex;
  justify-content: center;
  gap: 10px;
}

/* --- BOTTOM NAV (HUB) --- */
.bottom-nav {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  background: rgba(15, 15, 15, 0.95);
  border-top: 1px solid var(--surface-border);
  padding: 15px 20px;
  padding-bottom: calc(15px + var(--safe-area-bottom));
  display: flex;
  justify-content: center;
  gap: 20px;
}

.nav-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  cursor: pointer;
  text-transform: uppercase;
}

.nav-btn:hover {
  color: var(--text);
}

.nav-btn.danger {
  color: #ff3333;
}