:root {
  --bg: #050805;
  --panel: rgba(3, 12, 3, 0.88);
  --panel-strong: rgba(5, 18, 5, 0.95);
  --line: rgba(74, 255, 122, 0.55);
  --text: #86ff9c;
  --text-strong: #d8ffe0;
  --text-dim: rgba(134, 255, 156, 0.7);
  --accent: #39ff78;
  --accent-soft: rgba(57, 255, 120, 0.16);
  --danger: #ff6767;
  --shadow: 0 0 24px rgba(57, 255, 120, 0.12);
  --font-scale: 1;
  --scanline-opacity: 0.18;
  --flicker-opacity: 0.08;
  --content-width: 1400px;
}

body[data-theme="amber"] {
  --bg: #100902;
  --panel: rgba(23, 14, 3, 0.9);
  --panel-strong: rgba(28, 16, 4, 0.96);
  --line: rgba(255, 189, 89, 0.52);
  --text: #ffcd76;
  --text-strong: #ffe6bc;
  --text-dim: rgba(255, 205, 118, 0.74);
  --accent: #ffb347;
  --accent-soft: rgba(255, 179, 71, 0.17);
  --shadow: 0 0 24px rgba(255, 179, 71, 0.12);
}

body[data-theme="white"] {
  --bg: #090909;
  --panel: rgba(20, 20, 20, 0.92);
  --panel-strong: rgba(24, 24, 24, 0.98);
  --line: rgba(235, 235, 235, 0.34);
  --text: #f0f0f0;
  --text-strong: #ffffff;
  --text-dim: rgba(240, 240, 240, 0.74);
  --accent: #fafafa;
  --accent-soft: rgba(250, 250, 250, 0.14);
  --shadow: 0 0 24px rgba(255, 255, 255, 0.1);
}

body[data-high-contrast="on"] {
  --line: color-mix(in srgb, var(--accent) 86%, white 14%);
  --text-dim: var(--text);
  --shadow: 0 0 0 transparent;
}

* {
  box-sizing: border-box;
}

html {
  font-size: calc(16px * var(--font-scale));
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at top, rgba(57, 255, 120, 0.08), transparent 32%),
    linear-gradient(180deg, #020402 0%, var(--bg) 100%);
  color: var(--text);
  font-family: "Courier New", Courier, monospace;
  text-shadow: 0 0 8px rgba(57, 255, 120, 0.16);
  overflow-x: hidden;
}

body::before,
body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
}

body[data-scanlines="on"]::before {
  background:
    linear-gradient(
      to bottom,
      rgba(255, 255, 255, 0) 0%,
      rgba(255, 255, 255, 0) 50%,
      rgba(0, 0, 0, var(--scanline-opacity)) 51%,
      rgba(0, 0, 0, var(--scanline-opacity)) 100%
    );
  background-size: 100% 4px;
  opacity: 0.95;
}

body[data-flicker="on"]::after {
  background:
    linear-gradient(0deg, transparent 0%, rgba(255, 255, 255, var(--flicker-opacity)) 52%, transparent 100%);
  animation: crt-flicker 0.15s infinite alternate;
}

body[data-reduce-flicker="on"]::after {
  animation: none;
  opacity: 0.02;
}

@keyframes crt-flicker {
  0% {
    opacity: 0.12;
  }
  100% {
    opacity: 0.03;
  }
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  appearance: none;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.36), rgba(0, 0, 0, 0.72));
  color: var(--text);
  border-radius: 0.5rem;
  padding: 0.72rem 0.85rem;
  min-height: 2.85rem;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
}

button:hover,
button:focus-visible {
  background: var(--accent);
  color: #061108;
  border-color: var(--accent);
  outline: none;
  transform: translateY(-1px);
}

button:active {
  transform: translateY(0);
}

a {
  color: var(--text-strong);
}

.app-shell,
.loading-state {
  position: relative;
  z-index: 1;
}

.loading-state {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}

.loading-box {
  width: min(46rem, 100%);
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 1.25rem;
}

.loading-box h1,
.loading-box p {
  margin: 0 0 0.75rem;
}

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

.app-frame {
  width: min(var(--content-width), 100%);
  margin: 0 auto;
  padding: 1rem 1rem calc(6rem + env(safe-area-inset-bottom));
}

.top-shell {
  display: grid;
  grid-template-columns: minmax(0, 1.7fr) minmax(18rem, 1fr);
  gap: 1rem;
  margin-bottom: 1rem;
}

.title-block h1,
.title-block p,
.status-block p,
.status-block ul {
  margin: 0;
}

.title-block h1 {
  font-size: clamp(1.35rem, 2vw, 2rem);
  letter-spacing: 0.08em;
}

.title-block,
.title-block h1,
.title-subtitle,
.panel-title,
.panel-subtitle,
.stat-value,
.shell-body p,
.shell-body li,
.discord-message p,
.journal-entry p,
.party-member p,
.hall-entry p {
  overflow-wrap: anywhere;
  word-break: break-word;
}

.title-subtitle {
  margin-top: 0.35rem;
  color: var(--text-dim);
}

.status-list,
.pill-row,
.toolbar-row,
.menu-grid,
.action-grid,
.route-grid,
.stats-grid,
.setting-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
}

.status-pills {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 0.65rem;
}

.stat-pill,
.status-chip,
.setting-pill {
  border: 1px solid var(--line);
  background: var(--accent-soft);
  padding: 0.5rem 0.7rem;
  border-radius: 0.5rem;
  min-width: 0;
}

.stat-label,
.eyebrow,
.muted {
  color: var(--text-dim);
}

.stat-value {
  display: block;
  margin-top: 0.15rem;
  color: var(--text-strong);
}

.layout-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(20rem, 0.95fr);
  gap: 1rem;
  align-items: start;
}

.main-stack,
.panel-dock {
  display: grid;
  gap: 1rem;
  min-width: 0;
}

.panel-dock {
  align-content: start;
}

.panel-shell {
  border: 1px solid var(--line);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.03), transparent 12%),
    var(--panel);
  box-shadow: var(--shadow);
  min-width: 0;
}

.shell-body {
  padding: 1rem;
}

.terminal-window {
  min-height: 20rem;
  max-height: 34rem;
  overflow: auto;
  white-space: pre-wrap;
  scrollbar-width: thin;
}

.terminal-line {
  margin: 0 0 0.55rem;
}

.tone-system {
  color: var(--text-strong);
}

.tone-warning {
  color: #ffd38e;
}

.tone-danger {
  color: #ff8f8f;
}

.tone-omen {
  color: #f4b7ff;
}

.action-section h3,
.panel-section h3,
.menu-panel h2,
.shell-body h2,
.shell-body h3,
.shell-body h4,
.shell-body p,
.shell-body ul {
  margin-top: 0;
}

.menu-grid,
.action-grid,
.route-grid {
  margin-top: 0.8rem;
}

.choice-button {
  flex: 1 1 12rem;
  text-align: left;
}

.choice-button.terminal-primary {
  background: linear-gradient(180deg, rgba(57, 255, 120, 0.2), rgba(0, 0, 0, 0.78));
}

.choice-button.is-active,
.toolbar-button.is-active,
.setting-button.is-active {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}

.location-card,
.empty-state,
.menu-note,
.setting-card,
.detail-card,
.panel-note {
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.24);
  padding: 0.8rem;
  border-radius: 0.55rem;
}

.detail-card p:last-child,
.menu-note p:last-child,
.panel-note p:last-child,
.location-card p:last-child {
  margin-bottom: 0;
}

.menu-note {
  margin-top: 0.8rem;
}

.list-clean {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 0.75rem;
}

.list-row {
  display: grid;
  gap: 0.45rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px dashed rgba(255, 255, 255, 0.12);
}

.list-row:last-child {
  padding-bottom: 0;
  border-bottom: 0;
}

.mono {
  font-family: inherit;
}

.inline-meta {
  color: var(--text-dim);
  font-size: 0.95rem;
}

.footer-toolbar {
  display: none;
}
