/* ============================================================
   PYQUEST - MAIN.CSS
   Base styles, layout, screen system, HUD, typography
   ============================================================ */

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

:root {
  --bg: #0d0f1a;
  --surface: #13162b;
  --surface-2: #1a1e35;
  --border: #2a2f52;
  --text: #e2e8f0;
  --text-muted: #64748b;
  --text-dim: #94a3b8;
  --hp-color: #ef4444;
  --xp-color: #22c55e;
  --accent: #06b6d4;
  --font-pixel: 'Press Start 2P', monospace;
  --font-code: 'Fira Code', monospace;
  --font-body: 'Inter', sans-serif;
  --radius: 6px;
  --hud-height: 72px;
}

html, body {
  height: 100%;
  overflow: hidden;
}

/* Scale up the whole UI so 100% browser zoom is comfortable.
   The user was having to zoom to 120% — this CSS zoom makes
   the base look equivalent to that without manual browser zoom. */
html {
  zoom: 1.25;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ============================================================
   HEBREW MODE - Replace pixel font with Heebo everywhere
   Press Start 2P has no Hebrew glyphs; its CSS letter-spacing
   and tiny px sizes make Hebrew text unreadably small.
   Only the game title and level badge stay as pixel font.
   ============================================================ */
html[lang="he"] {
  --font-pixel: 'Heebo', 'Inter', sans-serif;
}

/* Restore pixel font only for purely English/ASCII elements */
html[lang="he"] .game-title,
html[lang="he"] .hud-level-badge {
  font-family: 'Press Start 2P', monospace;
}

/* Reset letter-spacing (set for pixel font, ruins proportional Hebrew) */
html[lang="he"] .game-subtitle,
html[lang="he"] .btn,
html[lang="he"] .zone-node-name,
html[lang="he"] .zone-node-number,
html[lang="he"] .hud-title,
html[lang="he"] .challenge-type-badge,
html[lang="he"] .challenge-encounter-name,
html[lang="he"] .reveal-title,
html[lang="he"] .complete-title,
html[lang="he"] .zone-clear-title,
html[lang="he"] .zone-clear-boss,
html[lang="he"] .game-over-title,
html[lang="he"] .hall-title,
html[lang="he"] .hall-subtitle,
html[lang="he"] .enc-xp-earned,
html[lang="he"] .enc-hp-remaining,
html[lang="he"] .encounter-name,
html[lang="he"] .encounter-desc {
  letter-spacing: 0;
}

/* Increase font sizes: pixel font uses 9-12px which is illegible for Hebrew */
html[lang="he"] .btn { font-size: 15px; }
html[lang="he"] .game-subtitle { font-size: clamp(14px, 2.5vw, 18px); text-transform: none; }
html[lang="he"] .hud-title { font-size: 14px; }
html[lang="he"] .challenge-type-badge { font-size: 13px; }
html[lang="he"] .challenge-encounter-name { font-size: 13px; }
html[lang="he"] .reveal-title { font-size: clamp(22px, 4vw, 32px); }
html[lang="he"] .complete-title { font-size: clamp(20px, 3vw, 28px); }
html[lang="he"] .zone-clear-title { font-size: clamp(20px, 3vw, 28px); }
html[lang="he"] .zone-clear-boss { font-size: 16px; }
html[lang="he"] .game-over-title { font-size: clamp(22px, 4vw, 36px); }
html[lang="he"] .hall-title { font-size: clamp(18px, 3vw, 26px); }
html[lang="he"] .hall-subtitle { font-size: 15px; }
html[lang="he"] .encounter-name { font-size: 15px; }
html[lang="he"] .encounter-desc { font-size: 13px; }
html[lang="he"] .zone-node-name { font-size: 13px; }
html[lang="he"] .zone-node-number { font-size: 11px; }

/* ============================================================
   SCREEN SYSTEM
   ============================================================ */

.screen {
  position: fixed;
  inset: 0;
  display: none;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
}

.screen.active {
  display: flex;
}

/* Screens with HUD need top padding */
.screen.hud-visible {
  padding-top: var(--hud-height);
}

/* ============================================================
   HUD
   ============================================================ */

.hud {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--hud-height);
  background: rgba(13, 15, 26, 0.95);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  z-index: 100;
  backdrop-filter: blur(8px);
}

.hud.hidden { display: none; }

.hud-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 160px;
}

.hud-level-badge {
  font-family: var(--font-pixel);
  font-size: 9px;
  background: var(--accent);
  color: #000;
  padding: 4px 8px;
  border-radius: 3px;
  white-space: nowrap;
}

.hud-title {
  font-size: 11px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 140px;
}

.hud-center {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
  max-width: 400px;
  margin: 0 20px;
}

.bar-container {
  display: flex;
  align-items: center;
  gap: 8px;
}

.bar-label {
  font-family: var(--font-pixel);
  font-size: 7px;
  width: 20px;
  color: var(--text-muted);
}

.bar-track {
  position: relative;
  flex: 1;
  height: 14px;
  background: var(--surface-2);
  border-radius: 7px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.bar-fill {
  height: 100%;
  border-radius: 7px;
  transition: width 0.4s ease;
}

.hp-fill {
  background: linear-gradient(90deg, #dc2626, #ef4444);
  box-shadow: 0 0 8px rgba(239, 68, 68, 0.5);
}

.xp-fill {
  background: linear-gradient(90deg, #16a34a, #22c55e);
  box-shadow: 0 0 8px rgba(34, 197, 94, 0.5);
  transition: width 0.6s ease, background 0.3s;
}

.bar-text {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 9px;
  font-family: var(--font-pixel);
  color: #fff;
  text-shadow: 0 0 4px rgba(0,0,0,0.8);
  white-space: nowrap;
}

.hud-right {
  min-width: 80px;
  text-align: right;
}

.hud-zone-indicator {
  font-family: var(--font-pixel);
  font-size: 8px;
  color: var(--text-muted);
}

/* ============================================================
   STREAK BANNER
   ============================================================ */

.streak-banner {
  position: fixed;
  top: var(--hud-height);
  left: 50%;
  transform: translateX(-50%);
  background: linear-gradient(135deg, #f97316, #eab308);
  color: #000;
  padding: 8px 24px;
  border-radius: 0 0 12px 12px;
  z-index: 99;
  text-align: center;
  pointer-events: none;
  box-shadow: 0 4px 20px rgba(249, 115, 22, 0.5);
}

.streak-banner.hidden { display: none; }

.streak-text {
  display: block;
  font-family: var(--font-pixel);
  font-size: 10px;
}

.streak-sub {
  display: block;
  font-size: 11px;
  font-weight: 600;
}

/* ============================================================
   SCREEN: MENU
   ============================================================ */

#screen-menu {
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

#code-rain-canvas {
  position: absolute;
  inset: 0;
  opacity: 0.15;
}

.menu-content {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 40px;
}

.menu-title-wrapper {
  text-align: center;
}

.game-title {
  font-family: var(--font-pixel);
  font-size: clamp(28px, 5vw, 52px);
  color: var(--accent);
  text-shadow: 0 0 20px var(--accent), 0 0 40px var(--accent);
  letter-spacing: 4px;
  margin-bottom: 12px;
}

.game-subtitle {
  font-family: var(--font-pixel);
  font-size: clamp(10px, 2vw, 14px);
  color: var(--text-dim);
  letter-spacing: 6px;
  text-transform: uppercase;
}

.menu-buttons {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 260px;
}

.menu-tagline {
  font-size: 12px;
  color: var(--text-muted);
  font-style: italic;
  text-align: center;
}

/* ============================================================
   SCREEN: WORLD MAP
   ============================================================ */

#screen-world-map {
  padding: 20px;
  align-items: center;
}

.world-map-header {
  text-align: center;
  margin-bottom: 24px;
  width: 100%;
}

.screen-title {
  font-family: var(--font-pixel);
  font-size: 18px;
  color: var(--text);
  margin-bottom: 12px;
}

.player-info-bar {
  display: flex;
  justify-content: center;
  gap: 20px;
  font-size: 13px;
  color: var(--text-dim);
}

.player-info-bar span {
  padding: 4px 12px;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.world-map-container {
  flex: 1;
  overflow-y: auto;
  width: 100%;
  display: flex;
  justify-content: center;
  padding-bottom: 40px;
}

.zone-chain {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  padding: 20px;
}

.zone-node {
  position: relative;
  width: 280px;
  padding: 16px 20px;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
  user-select: none;
}

.zone-node:hover:not(.locked) {
  transform: scale(1.03);
}

.zone-node.locked {
  opacity: 0.4;
  cursor: not-allowed;
  filter: grayscale(1);
}

.zone-node.completed {
  border-color: #22c55e;
}

.zone-node.active {
  animation: node-pulse 2s ease-in-out infinite;
}

.zone-connector {
  width: 3px;
  height: 28px;
  background: var(--border);
  margin: 0 auto;
}

.zone-connector.active-line {
  background: linear-gradient(180deg, #22c55e, var(--accent));
}

.zone-node-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.zone-node-number {
  font-family: var(--font-pixel);
  font-size: 9px;
  color: var(--text-muted);
}

.zone-node-status-icon {
  font-size: 18px;
}

.zone-node-name {
  font-family: var(--font-pixel);
  font-size: 10px;
  margin-bottom: 4px;
}

.zone-node-subtitle {
  font-size: 11px;
  color: var(--text-muted);
}

.zone-node-stars {
  display: flex;
  gap: 4px;
  margin-top: 8px;
}

.zone-node-fog {
  position: absolute;
  inset: 0;
  border-radius: 8px;
  background: repeating-linear-gradient(
    45deg,
    transparent,
    transparent 4px,
    rgba(0,0,0,0.2) 4px,
    rgba(0,0,0,0.2) 8px
  );
  pointer-events: none;
}

/* ============================================================
   SCREEN: ZONE SELECT
   ============================================================ */

#screen-zone-select {
  padding: 20px;
}

.zone-select-header {
  display: flex;
  align-items: flex-start;
  gap: 20px;
  margin-bottom: 32px;
}

.zone-info {
  flex: 1;
}

.zone-select-name {
  font-family: var(--font-pixel);
  font-size: 16px;
  margin-bottom: 6px;
}

.zone-select-subtitle {
  color: var(--text-dim);
  margin-bottom: 4px;
}

.zone-select-boss {
  font-size: 12px;
  color: var(--text-muted);
  font-style: italic;
}

.encounters-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-width: 600px;
  margin: 0 auto;
}

.encounter-card {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 10px;
  padding: 20px;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
  display: flex;
  align-items: center;
  gap: 16px;
}

.encounter-card:hover:not(.encounter-locked) {
  transform: translateY(-2px);
}

.encounter-card.encounter-locked {
  opacity: 0.5;
  cursor: not-allowed;
}

.encounter-card.encounter-boss {
  border-width: 2px;
}

.encounter-icon {
  font-size: 32px;
  flex-shrink: 0;
}

.encounter-info {
  flex: 1;
}

.encounter-name {
  font-family: var(--font-pixel);
  font-size: 10px;
  margin-bottom: 6px;
}

.encounter-desc {
  font-size: 12px;
  color: var(--text-dim);
}

.encounter-stars {
  display: flex;
  gap: 4px;
}

/* ============================================================
   SCREEN: CHALLENGE
   ============================================================ */

#screen-challenge {
  padding: 20px;
  padding-top: calc(var(--hud-height) + 20px);
  min-height: 100vh;
}

.challenge-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 8px;
}

.challenge-meta {
  display: flex;
  gap: 10px;
  align-items: center;
}

.challenge-type-badge {
  font-family: var(--font-pixel);
  font-size: 8px;
  padding: 5px 10px;
  border-radius: 4px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--accent);
}

.challenge-progress {
  font-family: var(--font-pixel);
  font-size: 9px;
  color: var(--text-muted);
}

.challenge-encounter-name {
  font-size: 12px;
  color: var(--text-muted);
  font-style: italic;
}

.challenge-body {
  max-width: 720px;
  margin: 0 auto;
  width: 100%;
}

.challenge-narrative {
  font-size: 14px;
  color: var(--text-dim);
  margin-bottom: 20px;
  line-height: 1.7;
  font-style: italic;
  padding: 12px 16px;
  border-left: 3px solid var(--accent);
  background: rgba(6, 182, 212, 0.05);
  border-radius: 0 var(--radius) var(--radius) 0;
}

.challenge-content {
  margin-bottom: 20px;
}

.challenge-footer {
  max-width: 720px;
  margin: 0 auto;
  width: 100%;
}

.hint-box {
  margin-top: 12px;
  padding: 12px 16px;
  background: rgba(234, 179, 8, 0.1);
  border: 1px solid #eab308;
  border-radius: var(--radius);
  font-size: 13px;
  color: #fde047;
}

.hint-box.hidden { display: none; }

/* ============================================================
   SCREEN: ANSWER REVEAL
   ============================================================ */

#screen-answer-reveal {
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.reveal-container {
  max-width: 600px;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
}

.reveal-result {
  text-align: center;
}

.reveal-title {
  font-family: var(--font-pixel);
  font-size: clamp(14px, 3vw, 22px);
  letter-spacing: 2px;
}

.reveal-title.correct { color: #22c55e; text-shadow: 0 0 20px #22c55e; }
.reveal-title.wrong { color: #ef4444; text-shadow: 0 0 20px #ef4444; }

.reveal-correct-answer {
  width: 100%;
}

.reveal-label {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 8px;
  font-family: var(--font-pixel);
}

.reveal-answer-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  font-family: var(--font-code);
  font-size: 14px;
  color: #22c55e;
}

.reveal-explanation {
  width: 100%;
  font-size: 14px;
  color: var(--text-dim);
  line-height: 1.7;
  padding: 16px;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.reveal-rewards {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  justify-content: center;
}

.reward-badge {
  font-family: var(--font-pixel);
  font-size: 9px;
  padding: 6px 14px;
  border-radius: 4px;
  border: 1px solid;
}

.reward-xp {
  color: #22c55e;
  border-color: #22c55e;
  background: rgba(34, 197, 94, 0.1);
}

.reward-hp-loss {
  color: #ef4444;
  border-color: #ef4444;
  background: rgba(239, 68, 68, 0.1);
}

/* ============================================================
   SCREEN: ENCOUNTER COMPLETE
   ============================================================ */

#screen-encounter-complete {
  align-items: center;
  justify-content: center;
}

.encounter-complete-container {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
}

.complete-title {
  font-family: var(--font-pixel);
  font-size: 20px;
  color: #22c55e;
  text-shadow: 0 0 20px #22c55e;
}

.stars-display {
  display: flex;
  gap: 16px;
  justify-content: center;
}

.complete-stats {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.xp-earned {
  font-family: var(--font-pixel);
  font-size: 12px;
  color: #22c55e;
}

.hp-remaining {
  font-size: 13px;
  color: var(--text-dim);
}

/* ============================================================
   SCREEN: ZONE CLEAR
   ============================================================ */

#screen-zone-clear {
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.zone-clear-container {
  text-align: center;
  max-width: 500px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

.zone-clear-title {
  font-family: var(--font-pixel);
  font-size: 20px;
  color: var(--accent);
  text-shadow: 0 0 20px var(--accent);
}

.zone-clear-boss {
  color: var(--text-dim);
  font-size: 14px;
}

.zone-clear-xp-breakdown {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 24px;
  width: 100%;
}

.xp-line {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  padding: 4px 0;
  color: var(--text-dim);
}

.xp-line.total {
  border-top: 1px solid var(--border);
  margin-top: 8px;
  padding-top: 8px;
  color: #22c55e;
  font-weight: 700;
  font-family: var(--font-pixel);
  font-size: 11px;
}

.level-up-banner {
  background: linear-gradient(135deg, #7c3aed, #a855f7);
  border-radius: 10px;
  padding: 16px 32px;
  animation: level-up-pulse 1s ease-in-out infinite;
}

.level-up-banner.hidden { display: none; }

.level-up-text {
  font-family: var(--font-pixel);
  font-size: 16px;
  color: #fff;
  text-shadow: 0 0 20px #fff;
}

/* ============================================================
   SCREEN: GAME OVER
   ============================================================ */

#screen-game-over {
  align-items: center;
  justify-content: center;
}

.game-over-container {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.game-over-title {
  font-family: var(--font-pixel);
  font-size: clamp(18px, 4vw, 32px);
  color: #ef4444;
  text-shadow: 0 0 30px #ef4444;
  animation: glitch 1.5s infinite;
}

.game-over-subtitle {
  font-family: var(--font-code);
  font-size: 14px;
  color: var(--text-muted);
}

.game-over-context {
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 8px;
}

.game-over-buttons {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  justify-content: center;
}

/* ============================================================
   SCREEN: HALL OF LEGENDS
   ============================================================ */

#screen-hall {
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.hall-container {
  max-width: 500px;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
}

.hall-title {
  font-family: var(--font-pixel);
  font-size: 18px;
  color: #eab308;
  text-shadow: 0 0 20px #eab308;
}

.hall-subtitle {
  color: var(--text-muted);
  font-size: 13px;
}

.hall-scores {
  width: 100%;
}

.hall-score-row {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.hall-rank {
  font-family: var(--font-pixel);
  font-size: 11px;
  width: 30px;
  color: var(--text-muted);
}

.hall-rank.gold { color: #eab308; }
.hall-rank.silver { color: #94a3b8; }
.hall-rank.bronze { color: #f97316; }

.hall-name {
  flex: 1;
  font-weight: 600;
}

.hall-score-info {
  text-align: right;
  font-size: 12px;
  color: var(--text-dim);
}

.hall-score-info strong {
  display: block;
  color: #22c55e;
  font-family: var(--font-pixel);
  font-size: 10px;
}

.hall-empty {
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  padding: 40px;
}

/* ============================================================
   MODAL
   ============================================================ */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  backdrop-filter: blur(4px);
}

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

.modal-box {
  background: var(--surface);
  border: 2px solid #a855f7;
  border-radius: 12px;
  padding: 32px;
  max-width: 440px;
  width: 90%;
  text-align: center;
  box-shadow: 0 0 60px rgba(168, 85, 247, 0.3);
  display: flex;
  flex-direction: column;
  gap: 20px;
  align-items: center;
}

/* ============================================================
   RESPONSIVE
   ============================================================ */

@media (max-width: 640px) {
  :root { --hud-height: 80px; }

  .hud {
    flex-wrap: wrap;
    height: auto;
    min-height: var(--hud-height);
    padding: 8px 12px;
    gap: 6px;
  }

  .hud-left { min-width: unset; }
  .hud-right { min-width: unset; }
  .hud-center { max-width: 100%; margin: 0; }

  .game-title { font-size: 28px; }

  .encounter-card { flex-direction: column; text-align: center; }

  .zone-select-header { flex-direction: column; }

  .reveal-container { gap: 16px; }
}
