:root {
  --ink: #0B0B0C;
  --ink-2: #17161A;
  --ink-3: #2A282C;
  --ivory: #EFE9DD;
  --ivory-dim: #A69F91;
  --red: #A6192E;
  --red-bright: #C42439;
  --gold: #B8964F;
  --gold-dim: #8B7440;
  --gold-bright: #E8C766;

  --font-display: 'Fraunces', Georgia, serif;
  --font-body: 'Public Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'IBM Plex Mono', 'SFMono-Regular', Consolas, monospace;

  --radius: 8px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--ink);
  color: var(--ivory);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

h1, h2, h3 { font-family: var(--font-display); margin: 0; font-weight: 500; }

button, select {
  font-family: inherit;
  color: inherit;
}

a { color: var(--gold-bright); }

:focus-visible {
  outline: 2px solid var(--gold-bright);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* --- Top bar --------------------------------------------------------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 24px;
  background: var(--ink-2);
  border-bottom: 1px solid var(--ink-3);
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-mark {
  color: var(--gold-bright);
  font-size: 1.3rem;
}

.brand-text {
  font-family: var(--font-display);
  font-size: 1.15rem;
  letter-spacing: 0.02em;
  color: var(--ivory);
}

.topbar-controls {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.ship-picker {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  color: var(--ivory-dim);
}

.ship-picker select {
  background: var(--ink);
  border: 1px solid var(--ink-3);
  color: var(--ivory);
  padding: 7px 10px;
  border-radius: 6px;
  font-size: 0.9rem;
  cursor: pointer;
}

.view-toggle {
  display: inline-flex;
  background: var(--ink);
  border: 1px solid var(--ink-3);
  border-radius: 999px;
  padding: 3px;
}

.view-toggle button {
  border: none;
  background: transparent;
  padding: 6px 16px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--ivory-dim);
}

.view-toggle button[aria-pressed="true"] {
  background: var(--red);
  color: var(--ivory);
}

/* --- Hero -------------------------------------------------------------- */

.hero {
  padding: 40px 24px 24px;
  max-width: 780px;
}

.eyebrow {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--gold);
  margin: 0 0 10px;
}

.hero h1 {
  font-size: clamp(1.7rem, 3.4vw, 2.6rem);
  line-height: 1.15;
  color: var(--ivory);
}

.hero-sub {
  margin-top: 12px;
  color: var(--ivory-dim);
  font-size: 1rem;
  line-height: 1.5;
  max-width: 60ch;
}

/* --- App layout -------------------------------------------------------- */

.app {
  flex: 1;
  display: grid;
  grid-template-columns: 76px minmax(0, 1fr) 320px;
  gap: 20px;
  padding: 0 24px 32px;
  align-items: start;
}

.rungs-col { position: sticky; top: 78px; min-width: 0; }

.rungs {
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: var(--ink-2);
  border: 1px solid var(--ink-3);
  border-radius: var(--radius);
  padding: 10px 8px;
}

.rung {
  align-self: center;
  width: var(--rung-width, 70%);
  height: 34px;
  border: 1px solid var(--ink-3);
  background: var(--ink);
  color: var(--gold-dim);
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.rung-num { font-family: var(--font-mono); font-size: 0.85rem; }

.rung:hover { border-color: var(--gold-dim); color: var(--gold-bright); }

.rung[aria-pressed="true"] {
  background: var(--red);
  border-color: var(--red-bright);
  color: var(--ivory);
}

.plan-col { min-width: 0; }

.plan-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding-bottom: 14px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--ink-3);
}

.plan-header h2 { font-size: 1.4rem; color: var(--ivory); }

.muted { color: var(--ivory-dim); font-size: 0.85rem; margin: 4px 0 0; }

.filters {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.legend {
  display: inline-flex;
  gap: 6px;
  flex-wrap: wrap;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: 999px;
  border: 1px solid var(--ink-3);
  background: var(--ink-2);
  color: var(--ivory-dim);
  font-size: 0.78rem;
  cursor: pointer;
  transition: opacity 0.15s ease, border-color 0.15s ease;
}

.chip[aria-pressed="true"] { color: var(--ivory); border-color: var(--gold-dim); }
.chip[aria-pressed="false"] { opacity: 0.4; }

.chip-swatch {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  display: inline-block;
}

.pill-toggle {
  padding: 5px 12px;
  border-radius: 999px;
  border: 1px solid var(--ink-3);
  background: var(--ink-2);
  color: var(--ivory-dim);
  font-size: 0.78rem;
  cursor: pointer;
}

.pill-toggle[aria-pressed="true"] {
  background: var(--gold-dim);
  border-color: var(--gold);
  color: var(--ink);
  font-weight: 600;
}

/* --- Map view ------------------------------------------------------------ */

.plan-wrap {
  position: relative;
  max-width: 620px;
  margin: 0 auto;
  background:
    repeating-linear-gradient(0deg, rgba(184,150,79,0.05) 0 1px, transparent 1px 28px),
    repeating-linear-gradient(90deg, rgba(184,150,79,0.05) 0 1px, transparent 1px 28px),
    var(--ink-2);
  border: 1px solid var(--ink-3);
  border-radius: var(--radius);
  padding: 12px;
}

#deck-plan {
  width: 100%;
  height: auto;
  aspect-ratio: 560 / 990;
  display: block;
}

.hull { fill: var(--ink); stroke: var(--gold); stroke-width: 2; }

.corridor { stroke: var(--gold-dim); stroke-dasharray: 4 4; stroke-width: 1; opacity: 0.7; }

.bow-label, .stern-label, .col-label {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.12em;
  fill: var(--gold-dim);
  text-anchor: middle;
}

.shaft rect { fill: var(--ink-3); stroke: var(--red); stroke-width: 1; }
.shaft line { stroke: var(--red); opacity: 0.6; }

.cabin rect {
  stroke: var(--ink);
  stroke-width: 1.5;
  cursor: pointer;
  transition: opacity 0.15s ease;
}

.cabin-label {
  font-family: var(--font-mono);
  font-size: 15px;
  font-weight: 500;
  text-anchor: middle;
  pointer-events: none;
  user-select: none;
}

.cabin.is-dim rect { opacity: 0.14; }
.cabin.is-dim .cabin-label { opacity: 0.14; }

.cabin.is-active rect {
  stroke: var(--gold-bright);
  stroke-width: 3;
  filter: drop-shadow(0 0 4px rgba(232, 199, 102, 0.7));
}

.cabin.is-shortlisted rect { stroke: var(--ivory); stroke-dasharray: 3 2; }

.compass circle, .compass line { stroke: var(--gold-dim); fill: none; opacity: 0.5; }
.compass text { fill: var(--gold-dim); font-family: var(--font-mono); font-size: 8px; text-anchor: middle; }

.tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--ink);
  border: 1px solid var(--gold-dim);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 0.78rem;
  box-shadow: 0 6px 18px rgba(0,0,0,0.5);
  z-index: 10;
}

.tooltip strong { display: block; font-family: var(--font-mono); color: var(--gold-bright); }
.tooltip span { display: block; margin-top: 2px; color: var(--ivory-dim); }

/* --- List view ------------------------------------------------------------ */

.table-wrap {
  border: 1px solid var(--ink-3);
  border-radius: var(--radius);
  overflow: auto;
  background: var(--ink-2);
}

table { width: 100%; border-collapse: collapse; font-size: 0.86rem; }

th {
  text-align: left;
  padding: 10px 14px;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--gold-dim);
  border-bottom: 1px solid var(--ink-3);
  cursor: pointer;
  white-space: nowrap;
}

th[data-dir="asc"]::after { content: " \25B2"; font-size: 0.6rem; }
th[data-dir="desc"]::after { content: " \25BC"; font-size: 0.6rem; }

td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--ink-3);
  color: var(--ivory);
}

tr { cursor: pointer; }
tr:hover td { background: rgba(184,150,79,0.06); }
tr.is-active td { background: rgba(166,25,46,0.16); }

.mono { font-family: var(--font-mono); }

.cat-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  margin-right: 6px;
}

/* --- Side column -------------------------------------------------------- */

.side-col {
  display: flex;
  flex-direction: column;
  gap: 16px;
  position: sticky;
  top: 78px;
}

.panel {
  background: var(--ink-2);
  border: 1px solid var(--ink-3);
  border-radius: var(--radius);
  padding: 16px;
}

.panel h3 {
  font-size: 1rem;
  color: var(--gold-bright);
  margin-bottom: 10px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.panel-head h3 { margin-bottom: 0; }

.panel-head span#shortlist-count {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--ivory-dim);
}

.text-btn {
  background: none;
  border: none;
  color: var(--gold-bright);
  font-size: 0.76rem;
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.ship-tagline {
  margin: 0 0 10px;
  font-family: var(--font-display);
  font-size: 0.95rem;
  font-style: italic;
  color: var(--ivory);
}

.detail-empty {
  color: var(--ivory-dim);
  font-size: 0.85rem;
  font-style: italic;
}

.stub {
  border: 1px dashed var(--gold-dim);
  border-radius: 6px;
  padding: 14px;
  background: linear-gradient(180deg, rgba(184,150,79,0.06), transparent 60%);
}

.stub-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding-bottom: 10px;
  border-bottom: 1px dashed var(--ink-3);
}

.stub-id { font-family: var(--font-mono); font-size: 1.2rem; color: var(--gold-bright); letter-spacing: 0.03em; }
.stub-cat { font-size: 0.76rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; }

.stub-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 12px 0 0;
}

.stub-grid dt { font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ivory-dim); margin: 0; }
.stub-grid dd { font-family: var(--font-mono); font-size: 0.86rem; margin: 2px 0 0; color: var(--ivory); }

.shortlist-btn {
  width: 100%;
  margin-top: 14px;
  padding: 10px;
  background: var(--red);
  border: none;
  border-radius: 6px;
  color: var(--ivory);
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  transition: filter 0.15s ease;
}

.shortlist-btn:hover { filter: brightness(1.12); }

.tray-empty { color: var(--ivory-dim); font-size: 0.82rem; font-style: italic; }

.tray-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }

.tray-list li {
  display: grid;
  grid-template-columns: 10px auto 1fr auto 20px;
  align-items: center;
  gap: 8px;
  font-size: 0.78rem;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--ink-3);
}

.tray-swatch { width: 8px; height: 8px; border-radius: 50%; }
.tray-id { font-family: var(--font-mono); color: var(--gold-bright); }
.tray-ship, .tray-cat { color: var(--ivory-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.tray-list button {
  background: none;
  border: none;
  color: var(--ivory-dim);
  font-size: 1rem;
  cursor: pointer;
  line-height: 1;
}

.tray-list button:hover { color: var(--red-bright); }

/* --- Footer -------------------------------------------------------------- */

.site-footer {
  border-top: 1px solid var(--ink-3);
  background: var(--ink-2);
  padding: 22px 24px;
  text-align: center;
}

.site-footer p { margin: 4px 0; font-size: 0.8rem; color: var(--ivory-dim); }
.site-footer strong { color: var(--gold-bright); }

/* --- Responsive ------------------------------------------------------- */

@media (max-width: 1080px) {
  .app {
    grid-template-columns: 64px minmax(0, 1fr);
  }
  .side-col {
    grid-column: 1 / -1;
    position: static;
    flex-direction: row;
    flex-wrap: wrap;
  }
  .side-col .panel { flex: 1 1 260px; }
}

@media (max-width: 700px) {
  .topbar { padding: 12px 16px; }
  .hero { padding: 28px 16px 18px; }
  .app { grid-template-columns: 1fr; padding: 0 16px 24px; gap: 14px; }
  .rungs-col { position: static; }
  .rungs { flex-direction: row; overflow-x: auto; padding: 8px; }
  .rung { width: 54px; flex: none; }
  .stub-grid { grid-template-columns: 1fr 1fr; }
  .side-col { flex-direction: column; }
}
