@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap');

/* night — default (original dark terminal) */
:root,
[data-theme='night'] {
  --bg: #080808;
  --bg-mid: #0f0f0f;
  --surface: rgba(8, 8, 8, 0.92);
  --fg: #3399ff;
  --fg-dim: #1a5080;
  --fg-bright: #66bbff;
  --accent: #aaccff;
  --accent-strong: #66bbff;
  --border: #2a3a5a;
  --glow: rgba(51, 153, 255, 0.35);
  --error: #ff5555;
  --crt-mid: #0a0e14;
  --scanline: rgba(51, 153, 255, 0.03);
  --vignette-a: rgba(0, 0, 0, 0.85);
  --vignette-b: rgba(51, 153, 255, 0.06);
  --term-shadow-inset: rgba(0, 0, 0, 0.5);
  --term-shadow-glow: rgba(51, 153, 255, 0.15);
  --chrome-bg: #0c0c0c;
  --stars-opacity: 0.35;
}

/* day — pastel powder blue */
[data-theme='day'] {
  --bg: #eef6fb;
  --bg-mid: #e3f0f8;
  --surface: rgba(255, 255, 255, 0.92);
  --fg: #5a94b8;
  --fg-dim: #8eb5cc;
  --fg-bright: #3d789c;
  --accent: #6aa8cc;
  --accent-strong: #6a9fc4;
  --border: #bdd8ea;
  --glow: rgba(106, 168, 204, 0.42);
  --error: #d45c5c;
  --crt-mid: #e8f3fa;
  --scanline: rgba(61, 120, 156, 0.05);
  --vignette-a: rgba(106, 168, 204, 0.12);
  --vignette-b: rgba(255, 255, 255, 0.65);
  --term-shadow-inset: rgba(106, 168, 204, 0.08);
  --term-shadow-glow: rgba(106, 168, 204, 0.14);
  --chrome-bg: rgba(255, 255, 255, 0.55);
  --stars-opacity: 0.2;
}

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

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

body {
  font-family: 'Press Start 2P', monospace;
  font-size: 11px;
  line-height: 1.85;
  color: var(--fg);
  background: var(--bg);
}

/* CRT frame */
.crt {
  height: 100vh;
  padding: 20px 16px;
  background: radial-gradient(ellipse at center, var(--crt-mid) 0%, var(--bg) 75%);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.crt::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(
    0deg,
    var(--scanline) 0,
    var(--scanline) 1px,
    transparent 1px,
    transparent 3px
  );
  z-index: 100;
}

.crt::after {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  box-shadow:
    inset 0 0 80px var(--vignette-a),
    inset 0 0 32px var(--vignette-b);
  z-index: 101;
}

/* Terminal window chrome */
.term-window {
  position: relative;
  z-index: 1;
  width: min(100%, 720px);
  height: min(420px, 72vh);
  border: 2px solid var(--border);
  box-shadow:
    inset 0 0 32px var(--term-shadow-inset),
    0 0 28px var(--term-shadow-glow);
  background: var(--surface);
  display: flex;
  flex-direction: column;
}

.term-chrome {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 7px;
  color: var(--fg-dim);
  background: var(--chrome-bg);
  flex-shrink: 0;
}

.term-dots {
  letter-spacing: 0.35em;
  color: var(--fg-dim);
}

.term-title {
  color: var(--fg-dim);
  letter-spacing: 0.08em;
}

/* Terminal — input pinned to vertical center */
.terminal {
  position: relative;
  flex: 1;
  display: grid;
  grid-template-rows: 1fr auto 1fr;
  align-items: center;
  width: 100%;
  min-height: 0;
  padding: 0 16px 12px;
  background: var(--surface);
}

.output {
  grid-row: 1;
  align-self: end;
  width: 100%;
  max-height: 100%;
  overflow-y: auto;
  padding-bottom: 16px;
  scrollbar-width: thin;
  scrollbar-color: var(--fg-dim) var(--bg);
}

.output p {
  margin: 0 0 6px;
  word-break: break-word;
}

.output .dim {
  color: var(--fg-dim);
}

.output .error {
  color: var(--error);
}

.output .typed {
  color: var(--accent);
}

.output .success {
  color: var(--fg-bright);
}

.output .chat {
  color: var(--accent);
}

/* sub pages */
.page-bar {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  font-size: 9px;
  color: var(--fg-dim);
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}

.page-bar a {
  color: var(--fg-bright);
  text-decoration: none;
}

.page-bar a:hover {
  color: var(--accent);
}

.page-bar .label {
  color: var(--fg);
  letter-spacing: 0.06em;
}

#world-map {
  position: relative;
  z-index: 1;
  height: calc(100vh - 42px - 118px);
  width: 100%;
  background: var(--bg);
}

.map-page {
  overflow: hidden;
}

.year-panel {
  position: relative;
  z-index: 2;
  padding: 12px 16px 10px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.year-form {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.year-field {
  display: flex;
  align-items: center;
  gap: 0.6em;
  flex: 1;
}

.year-prompt {
  color: var(--fg-bright);
  font-size: 9px;
}

.year-field input {
  flex: 1;
  min-width: 0;
  padding: 0;
  font: inherit;
  font-size: 9px;
  color: var(--fg-bright);
  background: transparent;
  border: none;
  outline: none;
  caret-color: var(--fg-bright);
}

.year-go {
  font: inherit;
  font-size: 8px;
  color: var(--bg);
  background: var(--fg);
  border: none;
  padding: 8px 12px;
  cursor: pointer;
}

.year-go:hover {
  background: var(--fg-bright);
}

.year-slider {
  width: 100%;
  accent-color: var(--fg);
  margin: 0 0 8px;
}

.year-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 8px;
  margin-bottom: 6px;
}

.year-label {
  color: var(--fg-bright);
}

.year-hint {
  color: var(--fg-dim);
  text-align: right;
}

.map-status {
  margin: 0;
  font-size: 7px;
  color: var(--fg-dim);
  min-height: 1.4em;
}

.map-status.loading {
  color: var(--fg);
}

.map-tooltip {
  font-family: 'Press Start 2P', monospace;
  font-size: 8px;
  background: var(--bg);
  color: var(--fg-bright);
  border: 1px solid var(--border);
  box-shadow: 0 0 12px var(--term-shadow-glow);
  padding: 6px 8px;
}

.leaflet-container {
  background: var(--bg);
  font-family: 'Press Start 2P', monospace;
}

.page-body {
  position: relative;
  z-index: 1;
  max-width: 640px;
  margin: 0 auto;
  padding: 32px 20px 48px;
}

.page-body h1 {
  font-size: 11px;
  font-weight: normal;
  color: var(--fg-bright);
  margin: 0 0 24px;
}

.page-body p,
.page-body li {
  font-size: 10px;
  line-height: 2;
  color: var(--accent);
}

.page-body ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.page-body li {
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.page-body .dim {
  color: var(--fg-dim);
  font-size: 8px;
}

/* Command input — screen center */
.input-line {
  grid-row: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5em;
  width: 100%;
}

.spacer {
  grid-row: 3;
}

.prompt {
  color: var(--fg-bright);
  white-space: nowrap;
  flex-shrink: 0;
}

.input-wrap {
  display: inline-flex;
  align-items: center;
  max-width: min(100%, 420px);
  min-width: 0;
}

.input-line input {
  padding: 0;
  font: inherit;
  color: var(--fg-bright);
  background: transparent;
  border: none;
  outline: none;
  caret-color: transparent;
  width: 0;
  min-width: 0;
}

.cursor-block {
  display: inline-block;
  width: 0.55em;
  height: 1.05em;
  margin-left: 1px;
  background: var(--fg-bright);
  box-shadow: 0 0 8px var(--glow);
  animation: cursor-blink 1.05s step-start infinite;
  flex-shrink: 0;
}

.cursor-block.paused {
  animation-play-state: paused;
  opacity: 0.35;
}

@keyframes cursor-blink {
  0%,
  49% {
    opacity: 1;
  }
  50%,
  100% {
    opacity: 0;
  }
}

.input-line input:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* Subtle phosphor noise */
.stars {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: var(--stars-opacity);
  background-image:
    radial-gradient(1px 1px at 12% 18%, var(--fg) 50%, transparent 50%),
    radial-gradient(1px 1px at 38% 62%, var(--fg-dim) 50%, transparent 50%),
    radial-gradient(1px 1px at 72% 22%, var(--fg) 50%, transparent 50%),
    radial-gradient(1px 1px at 88% 48%, var(--fg-dim) 50%, transparent 50%),
    radial-gradient(1px 1px at 52% 82%, var(--fg) 50%, transparent 50%);
}

@media (max-width: 480px) {
  body {
    font-size: 9px;
  }

  .crt {
    padding: 16px 12px;
  }

  .term-window {
    height: min(380px, 68vh);
  }
}
