:root {
  --bg: #0d1117;
  --bg-soft: #161b22;
  --bg-code: #0b0e14;
  --border: #2d333b;
  --text: #c9d1d9;
  --text-dim: #8b949e;
  --green: #3fb950;
  --green-dim: #2ea043;
  --amber: #d29922;
  --red: #f85149;
  --blue: #58a6ff;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
    "Liberation Mono", monospace;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial,
    sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  line-height: 1.6;
}

a {
  color: var(--blue);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

code,
pre,
kbd {
  font-family: var(--font-mono);
}

code {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.1em 0.35em;
  font-size: 0.9em;
}

pre {
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.8em 1em;
  overflow-x: auto;
}

/* ── TUI shell ─────────────────────────────────────────────────────────── */
.app-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  font-family: var(--font-mono);
}

.tui-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.35rem 0.75rem;
  background: var(--bg-soft);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.tui-tabs {
  display: flex;
  gap: 0.25rem;
  align-items: center;
}

.tab {
  color: var(--text-dim);
  padding: 0.15rem 0.6rem;
  border-radius: 4px;
  font-size: 0.85rem;
}

.tab:hover {
  color: var(--text);
  background: var(--bg-code);
  text-decoration: none;
}

.tab.active {
  color: var(--green);
  background: var(--bg-code);
}

.tui-status {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8rem;
  color: var(--text-dim);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.status-sep {
  color: var(--border);
}

/* ── Terminal ──────────────────────────────────────────────────────────── */
.terminal {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem 1rem;
  background: var(--bg);
  font-size: 0.9rem;
  line-height: 1.55;
  scrollbar-width: thin;
  scrollbar-color: var(--border) var(--bg);
}

.terminal-output > div {
  white-space: pre-wrap;
  word-break: break-word;
}

.terminal-output .out {
  color: var(--green);
}

.terminal-output .out.success {
  color: var(--green);
  font-weight: 600;
}

.terminal-output .out.error {
  color: var(--red);
  font-weight: 600;
}

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

.terminal-output .user-line {
  color: var(--text);
}

.terminal-output .replay-line {
  color: var(--amber);
}

.terminal-output .map-row {
  color: var(--green-dim);
  white-space: pre;
  line-height: 1.35;
}

.terminal-output .map-indent {
  display: inline-block;
  width: 1ch;
}

/* ── Map layout: grid beside legend when width allows, stacked below when not ── */
.map-layout {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 0 2.5rem;
  margin: 0.25rem 0 0.5rem;
}

.map-grid {
  flex: 0 0 auto;
  white-space: pre;
  line-height: 1.35;
}

.map-legend {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  padding-top: 0.1rem;
}

.legend-title {
  color: var(--text-dim);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: 0.25rem;
}

.legend-title:first-child {
  margin-top: 0;
}

.legend-row {
  white-space: nowrap;
}

.legend-entry {
  color: var(--text);
}

.legend-coord {
  color: var(--text-dim);
  font-size: 0.8rem;
}

/* ── Colored map tiles ──────────────────────────────────────────────────── */
.tile {
  display: inline-block;
  width: 1ch;
  text-align: center;
  font-weight: 600;
}

.terr-plain { color: #7ee787; }     /* grassland green */
.terr-forest { color: #2ea043; }    /* deep forest green */
.terr-hills { color: #d29922; }     /* amber hills */
.terr-water { color: #58a6ff; }     /* water blue */
.terr-mountain { color: #8b949e; }  /* gray mountains */

.marker-controlled { color: #f85149; font-weight: 700; }  /* red @ = you */
.marker-other { color: #d2a8ff; font-weight: 700; }       /* purple faction letters */

.legend-entry {
  color: var(--text);
}

/* ── Command line ──────────────────────────────────────────────────────── */
.command-line {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 1rem;
  background: var(--bg-soft);
  border-top: 1px solid var(--border);
}

.prompt {
  color: var(--green);
  white-space: nowrap;
  font-size: 0.85rem;
}

.command-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 0.9rem;
  caret-color: var(--green);
}

.command-input::placeholder {
  color: var(--text-dim);
}

/* ── Footer ────────────────────────────────────────────────────────────── */
.tui-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.3rem 1rem;
  background: var(--bg-soft);
  border-top: 1px solid var(--border);
  font-size: 0.75rem;
  color: var(--text-dim);
  flex-wrap: wrap;
}

.tui-help kbd {
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 3px;
  padding: 0 0.3em;
  font-size: 0.7rem;
}

.tui-footer .back {
  color: var(--blue);
}

/* ── Static pages (docs, faq, changelog) ───────────────────────────────── */
.wrap {
  max-width: 860px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 3rem;
}

.site-header .nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 860px;
  margin: 0 auto;
  padding: 0.75rem 1.25rem;
}

.brand {
  font-family: var(--font-mono);
  color: var(--green);
  font-weight: 600;
}

.cursor {
  animation: blink 1s step-end infinite;
}

@keyframes blink {
  50% { opacity: 0; }
}

.nav-links {
  display: flex;
  gap: 1rem;
  font-size: 0.9rem;
}

.nav-links a {
  color: var(--text-dim);
}

.nav-links a:hover,
.nav-links a[aria-current="page"] {
  color: var(--text);
}

.page-head h1 {
  font-family: var(--font-mono);
  font-size: 1.4rem;
  margin: 0 0 0.5rem;
}

.lede {
  color: var(--text-dim);
  font-size: 1.05rem;
  margin-top: 0;
}

h2 {
  font-size: 1.15rem;
  margin-top: 2rem;
  font-family: var(--font-mono);
}

h3 {
  font-size: 1rem;
}

section {
  margin-bottom: 1.5rem;
}

.terminal-demo {
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.75rem 1rem;
  overflow-x: auto;
  font-size: 0.85rem;
  line-height: 1.5;
}

.terminal-demo .prompt {
  color: var(--green);
}

.terminal-demo .dim {
  color: var(--text-dim);
}

.terminal-demo .out {
  color: var(--green);
}

.status-line {
  border-left: 3px solid var(--amber);
  padding: 0.4rem 0.9rem;
  background: var(--bg-soft);
  border-radius: 0 6px 6px 0;
}

.status-line .label {
  font-family: var(--font-mono);
  color: var(--amber);
  font-weight: 600;
}

.note {
  color: var(--text-dim);
  font-size: 0.9rem;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1rem;
}

.card {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.9rem 1rem;
}

.card h3 {
  margin-top: 0;
  color: var(--green);
  font-family: var(--font-mono);
  font-size: 0.95rem;
}

.card p {
  margin: 0;
  font-size: 0.9rem;
  color: var(--text-dim);
}

.feature-list li {
  margin-bottom: 0.4rem;
}

.site-footer {
  border-top: 1px solid var(--border);
  background: var(--bg-soft);
  padding: 0.75rem 1.25rem;
}

.footer-inner {
  max-width: 860px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  font-size: 0.8rem;
  color: var(--text-dim);
}

.footer-inner .back {
  color: var(--blue);
}

@media (max-width: 640px) {
  .tui-status {
    display: none;
  }
  .command-line {
    padding: 0.35rem 0.6rem;
  }
}
