/*
 * Visual language: a nautical chart on a chart table. Deep ink-navy for
 * the page (the "water"), warm parchment cards for content (the chart
 * itself), brass for accents (ship's instrument brass), and a compass
 * rose as the page's one signature flourish.
 */
:root {
  --ink: #0b2135;
  --ink-2: #123a56;
  --parchment: #f3ead9;
  --parchment-2: #e8dcc2;
  --brass: #c08a3e;
  --brass-dark: #96692b;
  --rust: #b6472f;
  --text-ink: #1c2b23;
  --text-parchment: #f3ead9;
  --text-parchment-muted: rgba(243, 234, 217, 0.72);
  --border-ink: rgba(11, 33, 53, 0.16);
  --radius: 10px;

  --font-display: "Fraunces", Georgia, serif;
  --font-body: "IBM Plex Sans", system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", "SFMono-Regular", Consolas, monospace;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font-body);
  color: var(--text-ink);
  background-color: var(--ink);
  background-image:
    repeating-linear-gradient(
      0deg,
      rgba(243, 234, 217, 0.05) 0,
      rgba(243, 234, 217, 0.05) 1px,
      transparent 1px,
      transparent 48px
    ),
    repeating-linear-gradient(
      90deg,
      rgba(243, 234, 217, 0.05) 0,
      rgba(243, 234, 217, 0.05) 1px,
      transparent 1px,
      transparent 48px
    );
}

main {
  max-width: 880px;
  margin: 0 auto;
  padding: 0 1rem 2.5rem;
}

/* --- Header --- */

header {
  max-width: 880px;
  margin: 0 auto;
  padding: 2.25rem 1rem 1.75rem;
  display: flex;
  align-items: flex-start;
  gap: 1.5rem;
  border-bottom: 1px solid rgba(192, 138, 62, 0.35);
  margin-bottom: 2rem;
}

.compass-rose {
  flex: 0 0 auto;
  width: 84px;
  height: 84px;
  color: var(--brass);
  transform: rotate(-6deg);
}

.compass-label {
  font-family: var(--font-mono);
  font-size: 8px;
  fill: currentColor;
  text-anchor: middle;
}

.header-copy {
  min-width: 0;
}

.eyebrow {
  margin: 0 0 0.4rem;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--brass);
}

header h1 {
  margin: 0 0 0.6rem;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: clamp(1.5rem, 3.6vw, 2.35rem);
  line-height: 1.15;
  letter-spacing: -0.01em;
  color: var(--text-parchment);
}

header p {
  margin: 0 0 0.5rem;
  max-width: 58ch;
  color: var(--text-parchment-muted);
  line-height: 1.5;
}

.disclaimer {
  font-size: 0.82rem;
  font-style: italic;
}

/* --- Shared card look for the map + route builder + results --- */

#route-builder,
#results {
  background: var(--parchment);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: 0 12px 28px rgba(4, 14, 24, 0.35);
}

#route-builder {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  margin-bottom: 1.25rem;
}

#results:empty {
  display: none;
}

#map {
  height: 420px;
  margin-bottom: 1.25rem;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--ink-2);
  border: 3px solid var(--brass);
  box-shadow: 0 12px 28px rgba(4, 14, 24, 0.35);
}

/* --- Stop rows --- */

.stop-row {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
}

.stop-row label {
  min-width: 92px;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--brass-dark);
}

.drag-handle {
  width: 24px;
  flex: 0 0 24px;
  text-align: center;
  cursor: grab;
  color: var(--brass-dark);
  opacity: 0.6;
  font-size: 1.2rem;
  user-select: none;
}

.drag-handle:hover {
  opacity: 1;
}

.stop-row.dragging {
  opacity: 0.4;
}

.port-input,
#speed-input {
  padding: 0.55rem 0.65rem;
  border: 1px solid var(--border-ink);
  border-radius: 6px;
  background: #fffdf8;
  color: var(--text-ink);
  font-family: var(--font-body);
  font-size: 1rem;
}

.port-input {
  flex: 1 1 200px;
}

.port-input:focus,
#speed-input:focus {
  outline: none;
  border-color: var(--brass);
  box-shadow: 0 0 0 3px rgba(192, 138, 62, 0.3);
}

.autocomplete-list {
  position: absolute;
  top: 100%;
  left: 116px;
  right: 0;
  background: #fffdf8;
  border: 1px solid var(--border-ink);
  border-radius: 6px;
  box-shadow: 0 8px 20px rgba(4, 14, 24, 0.18);
  z-index: 10;
  max-height: 200px;
  overflow-y: auto;
}

.autocomplete-item {
  padding: 0.5rem 0.65rem;
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 0.9rem;
}

.autocomplete-item:hover {
  background: var(--parchment-2);
}

/* --- Buttons --- */

.leg-remove-btn,
#add-stop-btn,
#calculate-btn,
#copy-link-btn {
  padding: 0.55rem 1.1rem;
  border-radius: 6px;
  font-family: var(--font-body);
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  align-self: flex-start;
}

#add-stop-btn,
#copy-link-btn {
  border: 1.5px solid var(--ink);
  background: transparent;
  color: var(--ink);
}

#add-stop-btn:hover,
#copy-link-btn:hover:not(:disabled) {
  background: rgba(11, 33, 53, 0.07);
}

#copy-link-btn:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

#calculate-btn {
  border: none;
  background: var(--brass);
  color: var(--ink);
  letter-spacing: 0.01em;
}

#calculate-btn:hover {
  background: var(--brass-dark);
  color: var(--text-parchment);
}

.leg-remove-btn {
  border: 1px solid rgba(182, 71, 47, 0.45);
  background: transparent;
  color: var(--rust);
  font-weight: 500;
}

.leg-remove-btn:hover {
  background: rgba(182, 71, 47, 0.08);
}

/* --- Speed + passages --- */

#speed-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

#speed-row label {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--brass-dark);
}

#speed-input {
  width: 5rem;
}

#passages-fieldset {
  border: 1px solid var(--border-ink);
  border-radius: 8px;
  background: var(--parchment-2);
  padding: 0.6rem 0.85rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem 1.1rem;
}

#passages-fieldset legend {
  padding: 0 0.3rem;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--brass-dark);
}

#passages-fieldset label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-weight: normal;
  font-size: 0.92rem;
  cursor: pointer;
}

#passages-fieldset input[type="checkbox"] {
  accent-color: var(--brass);
}

/* --- Results --- */

#results table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-mono);
  font-size: 0.92rem;
}

#results thead th {
  background: var(--ink);
  color: var(--text-parchment);
  text-align: right;
  text-transform: uppercase;
  font-size: 0.7rem;
  letter-spacing: 0.06em;
  font-weight: 500;
  padding: 0.6rem 0.6rem;
}

#results thead th:first-child,
#results tbody td:first-child {
  text-align: left;
}

#results tbody td {
  text-align: right;
  padding: 0.55rem 0.6rem;
  border-bottom: 1px solid var(--border-ink);
}

#results tfoot th {
  text-align: right;
  padding: 0.65rem 0.6rem;
  background: rgba(192, 138, 62, 0.22);
  border-top: 2px solid var(--brass);
  font-weight: 600;
}

#results tfoot th:first-child {
  text-align: left;
}

#results p {
  margin: 0.85rem 0 0;
  padding: 0.65rem 0.85rem;
  font-family: var(--font-body);
  font-size: 0.9rem;
  background: var(--parchment-2);
  border-left: 3px solid var(--brass);
  border-radius: 4px;
}

#results table + p {
  margin-top: 0.85rem;
}

/* --- Accessibility & motion --- */

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

@media (prefers-reduced-motion: no-preference) {
  .port-input,
  #speed-input,
  .leg-remove-btn,
  #add-stop-btn,
  #calculate-btn,
  #copy-link-btn,
  .drag-handle {
    transition: background-color 150ms ease, border-color 150ms ease, box-shadow 150ms ease,
      color 150ms ease, opacity 150ms ease;
  }
}

/* --- Responsive --- */

@media (max-width: 600px) {
  header {
    gap: 1rem;
    padding-top: 1.5rem;
  }

  .compass-rose {
    width: 52px;
    height: 52px;
  }

  .stop-row {
    flex-direction: column;
    align-items: stretch;
  }

  .port-input {
    flex-basis: auto;
  }

  .stop-row label {
    min-width: 0;
  }

  .autocomplete-list {
    left: 0;
  }

  #map {
    height: 320px;
  }
}
