/* ===== CUSTOM PROPERTIES ===== */
:root {
  --bg: #0a0b11;
  --bg-secondary: #12131d;
  --text: #e0e0e8;
  --text-muted: #6b6d80;
  --accent: #00e5ff;
  --accent-glow: rgba(0, 229, 255, 0.4);
  --accent-glow-strong: rgba(0, 229, 255, 0.7);
  --card-bg: rgba(18, 19, 29, 0.8);
  --card-border: rgba(0, 229, 255, 0.15);
  --font-display: 'Silkscreen', cursive;
  --font-body: system-ui, -apple-system, 'Segoe UI', sans-serif;
  --transition-screen: 600ms;
}

[data-theme="light"] {
  --bg: #f0f1f5;
  --bg-secondary: #e2e4eb;
  --text: #1a1b26;
  --text-muted: #6e7086;
  --accent: #0090a0;
  --accent-glow: rgba(0, 144, 160, 0.3);
  --accent-glow-strong: rgba(0, 144, 160, 0.6);
  --card-bg: rgba(226, 228, 235, 0.9);
  --card-border: rgba(0, 144, 160, 0.2);
}

/* ===== RESET & BASE ===== */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  overflow: hidden;
  min-height: 100dvh;
  transition: background-color 0.4s, color 0.4s;
}

a {
  color: var(--accent);
  text-decoration: none;
  transition: opacity 0.2s;
}

a:hover {
  opacity: 0.8;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

kbd {
  font-family: var(--font-display);
  font-size: 0.65rem;
  background: var(--bg-secondary);
  color: var(--text-muted);
  border: 1px solid var(--card-border);
  border-radius: 3px;
  padding: 2px 6px;
  margin: 0 2px;
}

/* ===== CANVAS & NOISE ===== */
#particles {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
}

#noise {
  position: fixed;
  inset: -50%;
  width: 200%;
  height: 200%;
  z-index: 1;
  pointer-events: none;
  opacity: 0.035;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  animation: noise 0.5s steps(4) infinite;
}

[data-theme="light"] #noise {
  opacity: 0.02;
}

@keyframes noise {
  0% { transform: translate(0, 0); }
  25% { transform: translate(-5%, -5%); }
  50% { transform: translate(5%, -10%); }
  75% { transform: translate(-10%, 5%); }
  100% { transform: translate(0, 0); }
}

/* ===== SETTINGS TOOLBAR ===== */
.settings {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 100;
  display: flex;
  gap: 8px;
}

.settings button {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  color: var(--text-muted);
  transition: color 0.2s, border-color 0.2s, box-shadow 0.2s;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.settings button:hover,
.settings button:focus-visible {
  color: var(--accent);
  border-color: var(--accent);
  box-shadow: 0 0 12px var(--accent-glow);
  outline: none;
}

/* Theme toggle icon visibility */
[data-theme="dark"] .icon-sun { display: block; }
[data-theme="dark"] .icon-moon { display: none; }
[data-theme="light"] .icon-sun { display: none; }
[data-theme="light"] .icon-moon { display: block; }

/* Sound toggle icon visibility */
[data-sound="on"] .icon-sound-on { display: block; }
[data-sound="on"] .icon-sound-off { display: none; }
[data-sound="off"] .icon-sound-on { display: none; }
[data-sound="off"] .icon-sound-off { display: block; }

/* ===== PAGE WRAP & CRT ===== */
#page-wrap {
  position: relative;
  z-index: 10;
  transform-origin: center center;
}

#page-wrap.crt-off {
  animation: crt-shutdown 0.55s cubic-bezier(0.755, 0.05, 0.855, 0.06) forwards;
}

@keyframes crt-shutdown {
  0% {
    transform: scale(1, 1.3) translate3d(0, 0, 0);
    filter: brightness(1);
    opacity: 1;
  }
  60% {
    transform: scale(1.3, 0.001) translate3d(0, 0, 0);
    filter: brightness(10);
    opacity: 1;
  }
  100% {
    transform: scale(0.000, 0.0001) translate3d(0, 0, 0);
    filter: brightness(50);
    opacity: 1;
  }
}

#crt-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  visibility: hidden;
  pointer-events: none;
}

#crt-overlay.visible {
  visibility: visible;
  background: #000;
  pointer-events: auto;
  animation: overlay-fade 0.6s 0.1s ease-out forwards;
}

@keyframes overlay-fade {
  0% { background: transparent; }
  100% { background: #000; }
}

/* Star flash — triggered immediately via sibling selector when crt-off starts */
#crt-overlay::before {
  content: '';
  position: fixed;
  top: 50%;
  left: 50%;
  width: 40px;
  height: 40px;
  margin: -20px 0 0 -20px;
  border-radius: 50%;
  background: #fff;
  opacity: 0;
  pointer-events: none;
  z-index: 201;
}

#page-wrap.crt-off ~ #crt-overlay::before {
  visibility: visible;
  animation: star-flash 1s ease-out forwards;
}

@keyframes star-flash {
  0% {
    opacity: 1;
    box-shadow:
      0 0 60px 40px #fff,
      0 0 200px 120px rgba(200, 220, 255, 0.8),
      0 0 400px 200px rgba(200, 220, 255, 0.3),
      /* horizontal rays */
      -60vw 0 200px 6px rgba(255, 255, 255, 0.8),
      60vw 0 200px 6px rgba(255, 255, 255, 0.8),
      /* vertical rays */
      0 -50vh 150px 4px rgba(255, 255, 255, 0.6),
      0 50vh 150px 4px rgba(255, 255, 255, 0.6),
      /* diagonal rays */
      -30vw -20vh 120px 4px rgba(255, 255, 255, 0.4),
      30vw 20vh 120px 4px rgba(255, 255, 255, 0.4),
      -30vw 20vh 120px 4px rgba(255, 255, 255, 0.4),
      30vw -20vh 120px 4px rgba(255, 255, 255, 0.4);
  }
  30% {
    opacity: 1;
    box-shadow:
      0 0 40px 20px #fff,
      0 0 120px 60px rgba(200, 220, 255, 0.6),
      0 0 250px 120px rgba(200, 220, 255, 0.2),
      -40vw 0 120px 4px rgba(255, 255, 255, 0.5),
      40vw 0 120px 4px rgba(255, 255, 255, 0.5),
      0 -30vh 80px 3px rgba(255, 255, 255, 0.4),
      0 30vh 80px 3px rgba(255, 255, 255, 0.4),
      -18vw -12vh 60px 2px rgba(255, 255, 255, 0.2),
      18vw 12vh 60px 2px rgba(255, 255, 255, 0.2),
      -18vw 12vh 60px 2px rgba(255, 255, 255, 0.2),
      18vw -12vh 60px 2px rgba(255, 255, 255, 0.2);
  }
  70% {
    opacity: 0.6;
    box-shadow:
      0 0 15px 8px rgba(255, 255, 255, 0.5),
      0 0 50px 25px rgba(200, 220, 255, 0.2),
      0 0 100px 50px rgba(200, 220, 255, 0.05),
      -15vw 0 40px 2px rgba(255, 255, 255, 0.15),
      15vw 0 40px 2px rgba(255, 255, 255, 0.15),
      0 -10vh 30px 1px rgba(255, 255, 255, 0.08),
      0 10vh 30px 1px rgba(255, 255, 255, 0.08),
      0 0 0 0 transparent,
      0 0 0 0 transparent,
      0 0 0 0 transparent,
      0 0 0 0 transparent;
  }
  100% {
    opacity: 0;
    box-shadow:
      0 0 0 0 transparent,
      0 0 0 0 transparent,
      0 0 0 0 transparent,
      0 0 0 0 transparent,
      0 0 0 0 transparent,
      0 0 0 0 transparent,
      0 0 0 0 transparent,
      0 0 0 0 transparent,
      0 0 0 0 transparent,
      0 0 0 0 transparent,
      0 0 0 0 transparent;
  }
}

.crt-message {
  font-family: var(--font-display);
  font-size: 1.2rem;
  color: #555;
  opacity: 0;
  animation: crt-msg-in 1.5s 2s ease forwards;
}

#crt-overlay.visible .crt-message {
  opacity: 0;
  animation: crt-msg-in 1.5s 2s ease forwards;
}

@keyframes crt-msg-in {
  to { opacity: 1; }
}

/* ===== SCREEN SYSTEM ===== */
.screen {
  position: fixed;
  inset: 0;
  z-index: 10;
  opacity: 0;
  visibility: hidden;
  transform: translateX(30px);
  transition: opacity var(--transition-screen) ease,
              transform var(--transition-screen) ease,
              visibility 0s var(--transition-screen);
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}

.screen.active {
  opacity: 1;
  visibility: visible;
  transform: translateX(0);
  transition: opacity var(--transition-screen) ease,
              transform var(--transition-screen) ease,
              visibility 0s 0s;
}

.screen.exiting {
  opacity: 0;
  transform: translateX(-30px);
  visibility: visible;
  transition: opacity var(--transition-screen) ease,
              transform var(--transition-screen) ease,
              visibility 0s var(--transition-screen);
}

.screen-inner {
  max-width: 720px;
  margin: 0 auto;
  padding: 80px 24px 48px;
  min-height: 100dvh;
}

/* ===== MAIN MENU ===== */
.main-layout {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 100dvh;
  padding-top: 48px;
  padding-bottom: 48px;
}

.main-header {
  margin-bottom: 40px;
}

.title {
  font-family: var(--font-display);
  font-size: clamp(1.6rem, 5vw, 2.8rem);
  font-weight: 700;
  color: var(--accent);
  text-shadow: 0 0 20px var(--accent-glow), 0 0 60px var(--accent-glow);
  line-height: 1.2;
  margin-bottom: 8px;
}

.subtitle {
  font-family: var(--font-display);
  font-size: clamp(0.7rem, 2vw, 0.9rem);
  color: var(--text-muted);
  margin-bottom: 16px;
}

.contact-links {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 20px;
  font-size: 0.85rem;
}

.contact-links a {
  color: var(--text-muted);
  transition: color 0.2s;
}

.contact-links a:hover {
  color: var(--accent);
  opacity: 1;
}

/* ===== MENU NAV ===== */
.menu {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 40px;
}

.menu-item {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 0 12px;
  padding: 10px 4px;
  font-family: var(--font-display);
  font-size: clamp(0.95rem, 3vw, 1.3rem);
  color: var(--text-muted);
  text-align: left;
  transition: color 0.2s, text-shadow 0.2s;
  position: relative;
}

.menu-item:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 4px;
  border-radius: 4px;
}

.menu-item .cursor {
  font-size: 0.7em;
  opacity: 0;
  transform: translateX(-8px);
  transition: opacity 0.2s, transform 0.2s;
  color: var(--accent);
  flex-shrink: 0;
}

.menu-item.focused {
  color: var(--text);
  text-shadow: 0 0 15px var(--accent-glow), 0 0 40px var(--accent-glow);
}

.menu-item.focused .cursor {
  opacity: 1;
  transform: translateX(0);
  animation: cursor-bob 1.2s ease-in-out infinite;
}

@keyframes cursor-bob {
  0%, 100% { transform: translateX(0); }
  50% { transform: translateX(5px); }
}

.menu-item:hover {
  color: var(--text);
}

.menu-hint {
  font-size: 0.7em;
  color: var(--text-muted);
}

.menu-item-desc {
  grid-column: 2;
  font-family: var(--font-body);
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.4;
  visibility: hidden;
  opacity: 0;
  transition: opacity 0.2s, visibility 0.2s;
}

.menu-item.focused .menu-item-desc {
  visibility: visible;
  opacity: 1;
}

/* ===== KEYBOARD HINTS ===== */
.keyboard-hints {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 24px;
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* ===== BACK BUTTON ===== */
.back-btn {
  font-family: var(--font-display);
  font-size: 0.8rem;
  color: var(--text-muted);
  padding: 8px 0;
  margin-bottom: 24px;
  transition: color 0.2s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.back-btn:hover,
.back-btn:focus-visible {
  color: var(--accent);
  outline: none;
}

/* ===== SCREEN TITLES ===== */
.screen-title {
  font-family: var(--font-display);
  font-size: clamp(1.3rem, 4vw, 2rem);
  color: var(--accent);
  text-shadow: 0 0 20px var(--accent-glow);
  margin-bottom: 6px;
}

.screen-subtitle {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 32px;
}

/* ===== QUEST CARDS (Singleplayer) ===== */
.quest-grid {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.quest-card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  padding: 20px;
  transition: box-shadow 0.3s, border-color 0.3s;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.quest-card:hover {
  box-shadow: 0 0 20px var(--accent-glow), inset 0 0 20px rgba(0, 229, 255, 0.03);
  border-color: var(--accent);
}

.quest-card h3 {
  font-family: var(--font-display);
  font-size: 0.9rem;
  color: var(--accent);
  margin-bottom: 8px;
}

.quest-card p {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 12px;
  line-height: 1.5;
}

.quest-tag {
  display: inline-block;
  font-family: var(--font-display);
  font-size: 0.6rem;
  color: var(--accent);
  border: 1px solid var(--card-border);
  border-radius: 4px;
  padding: 3px 8px;
  margin-right: 6px;
}

/* ===== TIMELINE (Multiplayer) ===== */
.timeline {
  position: relative;
  padding-left: 24px;
}

.timeline::before {
  content: '';
  position: absolute;
  left: 4px;
  top: 8px;
  bottom: 8px;
  width: 2px;
  background: var(--card-border);
}

.timeline-entry {
  position: relative;
  padding-bottom: 32px;
}

.timeline-entry::before {
  content: '';
  position: absolute;
  left: -24px;
  top: 8px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 10px var(--accent-glow);
  border: 2px solid var(--bg);
}

.timeline-entry:last-child {
  padding-bottom: 0;
}

.timeline-date {
  font-family: var(--font-display);
  font-size: 0.65rem;
  color: var(--accent);
  background: var(--bg-secondary);
  border: 1px solid var(--card-border);
  border-radius: 4px;
  padding: 2px 8px;
  display: inline-block;
  margin-bottom: 8px;
}

.timeline-entry h3 {
  font-family: var(--font-display);
  font-size: 0.85rem;
  color: var(--text);
  margin-bottom: 2px;
}

.timeline-company {
  font-size: 0.8rem;
  color: var(--accent);
  margin-bottom: 6px;
}

.timeline-entry > p:last-child {
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.5;
}

/* ===== CREDITS CARDS ===== */
.credits-grid {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.credit-card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 8px;
  padding: 20px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  opacity: 0;
  transform: translateY(20px);
  animation: credit-fade-up 0.5s ease forwards;
}

.screen.active .credit-card:nth-child(1) { animation-delay: 0.1s; }
.screen.active .credit-card:nth-child(2) { animation-delay: 0.25s; }
.screen.active .credit-card:nth-child(3) { animation-delay: 0.4s; }
.screen.active .credit-card:nth-child(4) { animation-delay: 0.55s; }

@keyframes credit-fade-up {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.credit-card h3 {
  font-family: var(--font-display);
  font-size: 0.9rem;
  color: var(--accent);
  margin-bottom: 8px;
}

.credit-card p {
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.5;
  margin-bottom: 12px;
}

.credit-link {
  font-family: var(--font-display);
  font-size: 0.7rem;
}

/* ===== UPCOMING CARDS ===== */
.upcoming-grid {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.upcoming-card {
  background: var(--card-bg);
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 20px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  animation: upcoming-pulse 3s ease-in-out infinite;
}

@keyframes upcoming-pulse {
  0%, 100% { box-shadow: 0 0 0 var(--accent-glow); }
  50% { box-shadow: 0 0 20px var(--accent-glow); }
}

.upcoming-card h3 {
  font-family: var(--font-display);
  font-size: 0.9rem;
  color: var(--accent);
  margin-bottom: 8px;
}

.upcoming-card p {
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.5;
  margin-bottom: 16px;
}

.loading-bar {
  height: 6px;
  background: var(--bg-secondary);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 8px;
}

.loading-fill {
  height: 100%;
  width: var(--progress);
  background: var(--accent);
  border-radius: 3px;
  box-shadow: 0 0 8px var(--accent-glow);
  animation: loading-shimmer 2s ease-in-out infinite;
}

@keyframes loading-shimmer {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

.loading-label {
  font-family: var(--font-display);
  font-size: 0.6rem;
  color: var(--text-muted);
}

/* ===== BLOG ===== */
.blog-post {
  max-width: 65ch;
}

.blog-post-title {
  font-family: var(--font-display);
  font-size: clamp(1rem, 3vw, 1.4rem);
  color: var(--accent);
  text-shadow: 0 0 15px var(--accent-glow);
  margin-bottom: 8px;
}

.blog-date {
  font-size: 0.75rem;
  color: var(--text-muted);
  display: block;
  margin-bottom: 24px;
}

.blog-body p {
  font-size: 0.9rem;
  color: var(--text);
  line-height: 1.7;
  margin-bottom: 16px;
}

.blog-body p:last-child {
  margin-bottom: 0;
}

.blog-post + .blog-post {
    margin-top: 48px;
    padding-top: 48px;
    border-top: 1px solid var(--card-border);
}

.blog-body code {
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 0.85em;
  background: var(--bg-secondary);
  padding: 2px 6px;
  border-radius: 3px;
  color: var(--accent);
}

/* ===== TABLET (768px) ===== */
@media (min-width: 768px) {
  .screen-inner {
    padding: 100px 40px 60px;
  }

  .main-layout {
    padding-top: 60px;
    padding-bottom: 60px;
  }

  .menu-item {
    padding: 12px 4px;
  }

  .quest-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
  }

  .credits-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 16px;
  }

  .upcoming-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
  }
}

/* ===== DESKTOP (1024px) ===== */
@media (min-width: 1024px) {
  .screen-inner {
    max-width: 900px;
    padding: 100px 60px 80px;
  }

  .title {
    font-size: 2.8rem;
  }

  .menu-item {
    font-size: 1.3rem;
    padding: 14px 4px;
  }
}

/* ===== REDUCED MOTION ===== */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  #noise {
    animation: none;
    display: none;
  }

  .screen {
    transition: none;
  }

  .menu-item .cursor {
    transition: none;
    animation: none;
    transform: translateX(0);
  }

  .menu-item.focused .cursor {
    animation: none;
    transform: translateX(0);
  }
}

/* ===== CONSENT BANNER ===== */
.consent-banner {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 300;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 8px;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  max-width: calc(100% - 32px);
}

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

.consent-text {
  font-family: var(--font-display);
  font-size: 0.55rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.consent-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.consent-actions button {
  font-family: var(--font-display);
  font-size: 0.55rem;
  padding: 4px 10px;
  border-radius: 4px;
  border: 1px solid var(--card-border);
  background: var(--bg-secondary);
  color: var(--text-muted);
  transition: color 0.2s, border-color 0.2s;
}

.consent-actions button:hover {
  color: var(--accent);
  border-color: var(--accent);
}

/* ===== SCROLLBAR ===== */
.screen::-webkit-scrollbar {
  width: 4px;
}

.screen::-webkit-scrollbar-track {
  background: transparent;
}

.screen::-webkit-scrollbar-thumb {
  background: var(--card-border);
  border-radius: 2px;
}

.screen::-webkit-scrollbar-thumb:hover {
  background: var(--accent);
}
