:root {
  --bg: #191613;
  --panel: rgba(31, 28, 24, 0.84);
  --panel-strong: rgba(42, 37, 32, 0.92);
  --panel-soft: rgba(58, 51, 44, 0.74);
  --ink: #ede3d4;
  --muted: #b8aa96;
  --line: rgba(255, 239, 215, 0.11);
  --accent: #d3954c;
  --accent-strong: #efc177;
  --ok: #86a58e;
  --error: #b97f72;
  --shadow: 0 28px 96px rgba(0, 0, 0, 0.4);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(211, 149, 76, 0.12), transparent 26%),
    radial-gradient(circle at bottom right, rgba(127, 146, 143, 0.12), transparent 22%),
    linear-gradient(180deg, #25211d 0%, #181512 55%, #12100d 100%);
  font: 14px/1.45 "Segoe UI", "Helvetica Neue", sans-serif;
}

button,
input,
select {
  font: inherit;
}

.legacy-hidden {
  display: none;
}

.app-shell {
  position: relative;
  min-height: 100vh;
}

.viewport-shell {
  position: relative;
  min-height: 100vh;
  overflow: hidden;
}

#mapCanvas {
  display: block;
  width: 100%;
  height: 100vh;
  background:
    radial-gradient(circle at 18% 14%, rgba(184, 135, 78, 0.1), transparent 24%),
    radial-gradient(circle at 78% 82%, rgba(96, 122, 118, 0.12), transparent 28%),
    linear-gradient(180deg, #24201c 0%, #1b1815 54%, #151310 100%);
  cursor: grab;
}

#mapCanvas.is-dragging {
  cursor: grabbing;
}

.overlay {
  position: absolute;
  z-index: 5;
  pointer-events: none;
}

.overlay-top-left {
  top: 82px;
  left: 20px;
  display: grid;
  gap: 14px;
  width: min(380px, calc(100vw - 40px));
  pointer-events: none;
}

.overlay-top-left > * {
  pointer-events: auto;
}

.overlay-bottom-left {
  left: 20px;
  bottom: 20px;
  width: min(420px, calc(100vw - 40px));
  pointer-events: none;
}

.overlay-bottom-left > * {
  pointer-events: auto;
}

.overlay-top-bar {
  top: 20px;
  left: 20px;
  width: min(380px, calc(100vw - 40px));
  pointer-events: none;
  z-index: 7;
}

.overlay-top-bar > * {
  pointer-events: auto;
}

.top-menu {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: linear-gradient(180deg, var(--panel-strong) 0%, var(--panel) 100%);
  backdrop-filter: blur(16px);
  box-shadow: var(--shadow);
  pointer-events: auto;
}

.top-menu-btn {
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.035);
  color: var(--ink);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.03em;
  cursor: pointer;
  pointer-events: auto;
  transition: border-color 0.12s ease, background-color 0.12s ease, transform 0.12s ease;
}

.top-menu-btn:hover {
  transform: translateY(-1px);
  border-color: rgba(239, 193, 119, 0.45);
}

.top-menu-btn.is-active {
  background: linear-gradient(135deg, rgba(211, 149, 76, 0.24) 0%, rgba(239, 193, 119, 0.2) 100%);
  border-color: rgba(239, 193, 119, 0.5);
}

.brand-card,
.selection-card,
.profile-card,
.engine-hud {
  backdrop-filter: blur(16px);
  box-shadow: var(--shadow);
}

.brand-card,
.selection-card,
.profile-card {
  width: 100%;
  padding: 18px 20px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: linear-gradient(180deg, var(--panel-strong) 0%, var(--panel) 100%);
}

.eyebrow {
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.brand-card h1,
.selection-card h2,
.engine-hud h2 {
  margin: 0;
  letter-spacing: -0.03em;
}

.brand-card h1 {
  font-size: 30px;
}

.selection-card h2,
.engine-hud h2 {
  font-size: 22px;
}

.lead,
.selection-detail,
.engine-meta {
  margin: 8px 0 0;
  color: var(--muted);
}

.selection-actions {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.selection-actions.is-hidden {
  display: none;
}

.profile-card.is-hidden {
  display: none;
}

.profile-head {
  display: grid;
  gap: 4px;
  margin-bottom: 12px;
}

.profile-meta {
  color: var(--muted);
  font-size: 12px;
}

#profileCanvas {
  display: block;
  width: 100%;
  height: 150px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.035);
}

.selection-action-btn {
  padding: 11px 13px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.045);
  color: var(--ink);
  font-weight: 700;
  font-size: 12px;
  line-height: 1.05;
  letter-spacing: 0.03em;
  cursor: pointer;
  transition: border-color 0.12s ease, background-color 0.12s ease, transform 0.12s ease, opacity 0.12s ease;
}

.selection-action-btn:hover:not(:disabled) {
  transform: translateY(-1px);
  border-color: rgba(239, 193, 119, 0.45);
}

.selection-action-btn:disabled {
  opacity: 0.45;
  cursor: default;
}

.status {
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  white-space: pre-wrap;
}

.status-ok {
  border-color: rgba(134, 165, 142, 0.35);
}

.status-error {
  border-color: rgba(185, 127, 114, 0.38);
}

.status-idle {
  border-color: rgba(211, 149, 76, 0.28);
}

.engine-hud {
  position: absolute;
  right: 20px;
  bottom: 20px;
  z-index: 6;
  width: min(520px, calc(100vw - 40px));
  padding: 18px 20px 16px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: linear-gradient(180deg, rgba(34, 30, 26, 0.94) 0%, rgba(24, 21, 18, 0.92) 100%);
}

.engine-hud.is-hidden {
  display: none;
}

.hud-header {
  display: grid;
  gap: 14px;
  align-items: start;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.metric {
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.035);
}

.metric span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.metric strong {
  font-size: 18px;
}

.hud-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.hud-action-btn {
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.045);
  color: var(--ink);
  font-weight: 700;
  font-size: 12px;
  line-height: 1.05;
  letter-spacing: 0.03em;
  cursor: pointer;
  transition: border-color 0.12s ease, background-color 0.12s ease, transform 0.12s ease, opacity 0.12s ease;
}

.hud-action-btn:hover:not(:disabled) {
  transform: translateY(-1px);
  border-color: rgba(239, 193, 119, 0.45);
}

.hud-action-btn.is-active {
  background: linear-gradient(135deg, rgba(211, 149, 76, 0.24) 0%, rgba(239, 193, 119, 0.2) 100%);
  border-color: rgba(239, 193, 119, 0.5);
}

.hud-action-btn:disabled {
  opacity: 0.45;
  cursor: default;
}

.hud-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 16px;
}

.mode-panel.is-hidden {
  display: none;
}

.control-card {
  padding: 14px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.035);
}

.control-card-wide {
  grid-column: 1 / -1;
}

.control-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.control-head span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.control-head strong {
  font-size: 18px;
}

.ae-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.ae-block {
  display: grid;
  gap: 10px;
}

.ae-label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.ae-status-copy {
  color: var(--muted);
  line-height: 1.5;
  min-height: 22px;
}

.waypoint-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.slider {
  width: 100%;
  accent-color: var(--accent-strong);
}

.slider-accent {
  accent-color: var(--accent);
}

.mode-buttons,
.reverser-buttons {
  display: grid;
  gap: 8px;
}

.mode-buttons {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

.reverser-buttons {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.mode-buttons button,
.reverser-buttons button {
  padding: 12px 10px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  color: var(--ink);
  font-weight: 700;
  cursor: pointer;
  transition: border-color 0.12s ease, background-color 0.12s ease, transform 0.12s ease;
}

.mode-buttons button:hover,
.reverser-buttons button:hover {
  transform: translateY(-1px);
  border-color: rgba(239, 193, 119, 0.45);
}

.mode-buttons button.is-active,
.reverser-buttons button.is-active {
  background: linear-gradient(135deg, rgba(211, 149, 76, 0.24) 0%, rgba(239, 193, 119, 0.2) 100%);
  border-color: rgba(239, 193, 119, 0.5);
}

.mode-buttons button {
  font-size: 12px;
  letter-spacing: 0.03em;
}

.reverser-buttons {
  gap: 8px;
}

#reverserSlider {
  display: none;
  margin-top: 10px;
}

.control-message {
  margin-top: 14px;
  min-height: 20px;
  color: var(--muted);
}

@media (max-width: 900px) {
  .overlay-top-left {
    width: min(340px, calc(100vw - 32px));
    top: 16px;
    left: 16px;
  }

  .engine-hud {
    right: 16px;
    bottom: 16px;
    width: min(460px, calc(100vw - 32px));
  }

  .metric-grid,
  .hud-actions,
  .hud-grid {
    grid-template-columns: 1fr;
  }

  .mode-buttons {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
