:root {
  --ink: #07141b;
  --ink-2: rgba(6, 18, 25, 0.76);
  --ink-3: rgba(6, 18, 25, 0.92);
  --parchment: #f1e7d3;
  --parchment-dim: #cbbfa8;
  --brass: #c9a25b;
  --brass-bright: #e4c47f;
  --brass-dim: rgba(201, 162, 91, 0.36);
  --sea: #2f7f91;
  --port: #e37c64;
  --starboard: #6fc3b0;
  --serif: "Palatino Linotype", "Book Antiqua", Palatino, "Iowan Old Style", Georgia, serif;
  --sans: "Avenir Next", "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #07141b;
  color: var(--parchment);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
}

#stage {
  position: fixed;
  inset: 0;
  z-index: 0;
}

#stage canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  outline: none;
}

/* The CSS2D label layer */
#stage > div {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

#hud {
  position: fixed;
  inset: 0;
  z-index: 3;
  pointer-events: none;
}

#hud button,
#hud input,
#hud .side-panel {
  pointer-events: auto;
}

/* ---------- title ---------- */
.title-block {
  position: absolute;
  top: 26px;
  left: 30px;
  max-width: 330px;
  padding: 13px 22px 12px 17px;
  border-left: 1px solid rgba(201, 162, 91, 0.5);
  border-radius: 2px;
  background: linear-gradient(90deg, rgba(4, 14, 20, 0.82), rgba(4, 14, 20, 0.4) 66%, rgba(4, 14, 20, 0));
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(3px);
}

.eyebrow {
  color: var(--brass);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.22em;
  text-transform: uppercase;
}

.title-block h1 {
  margin: 5px 0 4px;
  color: var(--parchment);
  font-family: var(--serif);
  font-size: clamp(34px, 3.2vw, 52px);
  font-weight: 400;
  letter-spacing: 0.01em;
  line-height: 0.96;
}

.title-block p {
  margin: 0;
  color: rgba(241, 231, 211, 0.68);
  font-family: var(--serif);
  font-size: 13px;
  font-style: italic;
  line-height: 1.35;
}

/* ---------- helm order ---------- */
.order-card {
  position: absolute;
  top: 24px;
  left: 50%;
  width: min(370px, 32vw);
  padding: 13px 20px 12px;
  transform: translateX(-50%);
  border: 1px solid var(--brass-dim);
  border-top-color: rgba(228, 196, 127, 0.75);
  border-radius: 3px;
  background:
    linear-gradient(180deg, rgba(201, 162, 91, 0.08), transparent 45%),
    rgba(5, 16, 22, 0.78);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.32), inset 0 1px 0 rgba(228, 196, 127, 0.12);
  text-align: center;
  backdrop-filter: blur(7px);
}

.order-label {
  color: var(--brass);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.24em;
  text-transform: uppercase;
}

.order-text {
  margin: 2px 0 3px;
  color: var(--parchment);
  font-family: var(--serif);
  font-size: clamp(23px, 2.3vw, 32px);
  line-height: 1.1;
  letter-spacing: 0.015em;
  transition: color 160ms ease, text-shadow 160ms ease;
}

.order-card[data-side="port"] .order-text {
  color: #f0c0a4;
  text-shadow: 0 0 18px rgba(227, 124, 100, 0.22);
}

.order-card[data-side="starboard"] .order-text {
  color: #bce8dc;
  text-shadow: 0 0 18px rgba(111, 195, 176, 0.2);
}

.order-card[data-hard="true"] .order-text {
  color: var(--brass-bright);
  text-shadow: 0 0 22px rgba(228, 196, 127, 0.28);
}

.order-sub {
  color: rgba(241, 231, 211, 0.58);
  font-size: 10px;
  letter-spacing: 0.055em;
  line-height: 1.35;
}

/* ---------- side panel ---------- */
.side-panel {
  position: absolute;
  top: 22px;
  right: 22px;
  width: 334px;
  max-height: calc(100vh - 210px);
  overflow-y: auto;
  border: 1px solid var(--brass-dim);
  border-radius: 3px;
  background:
    linear-gradient(180deg, rgba(201, 162, 91, 0.055), transparent 180px),
    var(--ink-2);
  box-shadow: 0 10px 35px rgba(0, 0, 0, 0.36);
  backdrop-filter: blur(9px);
  scrollbar-width: thin;
  scrollbar-color: var(--brass-dim) transparent;
}

.side-panel::-webkit-scrollbar { width: 6px; }
.side-panel::-webkit-scrollbar-thumb { background: var(--brass-dim); border-radius: 3px; }

.panel-section {
  padding: 16px 17px 17px;
  border-bottom: 1px solid rgba(201, 162, 91, 0.16);
}

.panel-section:last-child { border-bottom: 0; }

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 11px;
}

.panel-section h2 {
  margin: 0 0 11px;
  color: var(--brass);
  font-family: var(--serif);
  font-size: 15px;
  font-weight: 400;
  letter-spacing: 0.055em;
}

.panel-heading h2 { margin: 0; }

.speed-pill {
  padding: 3px 8px 2px;
  border: 1px solid rgba(201, 162, 91, 0.28);
  border-radius: 20px;
  color: var(--brass-bright);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.11em;
  text-transform: uppercase;
}

.readout-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px 14px;
  margin-bottom: 11px;
}

.readout-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 5px;
  padding: 3px 0;
  border-bottom: 1px solid rgba(241, 231, 211, 0.065);
}

.readout-row span {
  color: rgba(241, 231, 211, 0.5);
  font-size: 9px;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.readout-row b {
  color: var(--parchment);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  font-weight: 400;
  white-space: nowrap;
}

.rope-readout {
  display: grid;
  grid-template-columns: 8px 1fr 8px 1fr;
  align-items: center;
  gap: 5px;
  padding-top: 8px;
  border-top: 1px solid rgba(241, 231, 211, 0.07);
  color: rgba(241, 231, 211, 0.55);
  font-size: 9px;
  letter-spacing: 0.04em;
}

.rope-readout b {
  color: var(--parchment);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-weight: 400;
}

.rope-swatch {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  box-shadow: 0 0 7px currentColor;
}
.rope-swatch.port { color: var(--port); background: var(--port); }
.rope-swatch.starboard { color: var(--starboard); background: var(--starboard); }

.turn-readout {
  margin-top: 9px;
  color: rgba(241, 231, 211, 0.38);
  font-size: 9px;
  letter-spacing: 0.035em;
  text-align: right;
}

/* parts */
.parts-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.parts-list li {
  display: grid;
  grid-template-columns: 21px 1fr;
  gap: 9px;
  padding: 8px 0;
  border-bottom: 1px solid rgba(241, 231, 211, 0.055);
}

.parts-list li:last-child { border-bottom: 0; }

.parts-list .num {
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
  margin-top: 1px;
  border: 1px solid rgba(201, 162, 91, 0.45);
  border-radius: 50%;
  color: var(--brass-bright);
  font-family: var(--serif);
  font-size: 10px;
  line-height: 1;
}

.parts-list b {
  color: var(--parchment);
  font-family: var(--serif);
  font-size: 12.5px;
  font-weight: 400;
  letter-spacing: 0.02em;
}

.parts-list p {
  margin: 3px 0 0;
  color: rgba(241, 231, 211, 0.57);
  font-size: 10.5px;
  line-height: 1.42;
}

.rig-note {
  margin: 2px 0 12px;
  padding: 11px 11px 10px;
  border-left: 2px solid rgba(201, 162, 91, 0.55);
  background: rgba(201, 162, 91, 0.045);
}

.rig-note-label {
  color: var(--brass);
  font-size: 8px;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.rig-note p {
  margin: 5px 0 0;
  color: rgba(241, 231, 211, 0.75);
  font-size: 10.5px;
  line-height: 1.45;
}

.rig-note p b { color: var(--parchment); font-weight: 600; }
.rig-note p.small {
  color: rgba(241, 231, 211, 0.45);
  font-size: 9.5px;
  line-height: 1.4;
}
.rig-note em { color: rgba(241, 231, 211, 0.7); font-style: italic; }

/* ---------- controls ---------- */
.controls {
  position: absolute;
  left: 30px;
  bottom: 26px;
  width: min(520px, calc(100vw - 410px));
  padding: 12px 14px 11px;
  border: 1px solid var(--brass-dim);
  border-radius: 3px;
  background: var(--ink-2);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(9px);
}

.control-row {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
}

.control-row + .control-row,
.wheel-slider-row + .control-row,
.control-row + .wheel-slider-row {
  margin-top: 8px;
}

button {
  padding: 7px 11px 6px;
  border: 1px solid rgba(201, 162, 91, 0.44);
  border-radius: 2px;
  background: rgba(201, 162, 91, 0.055);
  color: var(--parchment);
  font-family: var(--sans);
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background 140ms ease, border-color 140ms ease, color 140ms ease;
}

button:hover {
  border-color: rgba(228, 196, 127, 0.85);
  background: rgba(201, 162, 91, 0.14);
  color: var(--brass-bright);
}

button:active { transform: translateY(1px); }

button.active {
  border-color: rgba(228, 196, 127, 0.8);
  background: rgba(201, 162, 91, 0.2);
  color: var(--brass-bright);
}

.view-buttons {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1;
  min-width: 240px;
}

.view-label {
  margin-right: 3px;
  color: rgba(241, 231, 211, 0.42);
  font-size: 8.5px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.view-btn {
  padding: 6px 8px 5px;
  font-size: 8.5px;
}

.view-btn.active {
  border-color: rgba(228, 196, 127, 0.85);
  background: rgba(201, 162, 91, 0.22);
  color: var(--brass-bright);
}

button.toggle::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-right: 6px;
  border: 1px solid currentColor;
  border-radius: 50%;
  vertical-align: 1px;
}

button.toggle.active::before {
  background: currentColor;
  box-shadow: 0 0 6px currentColor;
}

.wheel-slider-row,
.deck-slider-row {
  display: flex;
  align-items: center;
  gap: 8px;
  color: rgba(241, 231, 211, 0.5);
  font-size: 9px;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

.wheel-slider-row {
  width: 100%;
}

.wheel-slider-row > span {
  width: 88px;
  flex: none;
}

.wheel-slider-row input { flex: 1; }

.wheel-slider-row output {
  width: 52px;
  color: var(--parchment);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 10px;
  text-align: right;
}

.deck-slider-row {
  flex: 1;
  min-width: 150px;
}

.deck-slider-row input {
  flex: 1;
  min-width: 70px;
}

input[type="range"] {
  height: 18px;
  margin: 0;
  accent-color: var(--brass-bright);
  background: transparent;
  cursor: pointer;
}

.hint {
  margin-top: 9px;
  color: rgba(241, 231, 211, 0.36);
  font-size: 9px;
  line-height: 1.55;
  letter-spacing: 0.025em;
}

kbd {
  display: inline-block;
  min-width: 15px;
  padding: 0 3px;
  border: 1px solid rgba(241, 231, 211, 0.17);
  border-radius: 2px;
  color: rgba(241, 231, 211, 0.66);
  font-family: inherit;
  font-size: 8px;
  line-height: 14px;
  text-align: center;
}

/* ---------- compass ---------- */
.compass-hud {
  position: absolute;
  right: 30px;
  bottom: 28px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  width: 118px;
  padding: 9px 8px 7px;
  border: 1px solid var(--brass-dim);
  border-radius: 50% 50% 3px 3px / 46% 46% 3px 3px;
  background: rgba(5, 16, 22, 0.7);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(7px);
}

.compass-rose {
  position: relative;
  width: 92px;
  height: 92px;
  border: 1px solid rgba(201, 162, 91, 0.38);
  border-radius: 50%;
  background:
    radial-gradient(circle at center, rgba(201, 162, 91, 0.08), transparent 64%),
    repeating-conic-gradient(from 0deg, rgba(201, 162, 91, 0.12) 0deg 0.7deg, transparent 0.7deg 15deg);
}

.compass-rose::before,
.compass-rose::after {
  content: "";
  position: absolute;
  inset: 13px;
  border: 1px solid rgba(201, 162, 91, 0.16);
  border-radius: 50%;
}
.compass-rose::after { inset: 39px; border-color: rgba(201, 162, 91, 0.3); }

.cardinal {
  position: absolute;
  color: rgba(241, 231, 211, 0.52);
  font-family: var(--serif);
  font-size: 8px;
  line-height: 1;
  transform: translate(-50%, -50%);
}
.cardinal.n { top: 8px; left: 50%; color: var(--brass-bright); }
.cardinal.e { top: 50%; right: 0; left: auto; transform: translate(50%, -50%); }
.cardinal.s { bottom: 8px; top: auto; left: 50%; transform: translate(-50%, 50%); }
.cardinal.w { top: 50%; left: 0; transform: translate(-50%, -50%); }

.tick {
  position: absolute;
  width: 1px;
  height: 5px;
  left: 50%;
  top: 2px;
  background: rgba(201, 162, 91, 0.4);
  transform-origin: 50% 44px;
}
.tick.t0 { transform: translateX(-50%) rotate(0deg); }
.tick.t90 { transform: translateX(-50%) rotate(90deg); }
.tick.t180 { transform: translateX(-50%) rotate(180deg); }
.tick.t270 { transform: translateX(-50%) rotate(270deg); }

.ship-arrow {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 12px;
  height: 30px;
  margin-left: -6px;
  margin-top: -22px;
  transform-origin: 50% 22px;
  transition: transform 170ms linear;
  filter: drop-shadow(0 0 5px rgba(228, 196, 127, 0.35));
}

.ship-arrow::before {
  content: "";
  position: absolute;
  left: 3px;
  top: 0;
  width: 0;
  height: 0;
  border-left: 3px solid transparent;
  border-right: 3px solid transparent;
  border-bottom: 13px solid var(--brass-bright);
}

.ship-arrow::after {
  content: "";
  position: absolute;
  left: 4px;
  top: 11px;
  width: 4px;
  height: 15px;
  background: linear-gradient(var(--brass-bright), rgba(228, 196, 127, 0.3));
  clip-path: polygon(50% 100%, 0 0, 100% 0);
}

.compass-center {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--brass-bright);
  box-shadow: 0 0 7px rgba(228, 196, 127, 0.65);
  transform: translate(-50%, -50%);
}

.compass-read {
  display: flex;
  align-items: baseline;
  gap: 5px;
}

.compass-read span {
  color: var(--parchment);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 13px;
}

.compass-read small {
  color: rgba(241, 231, 211, 0.36);
  font-size: 8px;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

/* ---------- toast ---------- */
.toast {
  position: absolute;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  padding: 7px 13px;
  border: 1px solid rgba(201, 162, 91, 0.25);
  border-radius: 2px;
  background: rgba(5, 16, 22, 0.78);
  color: rgba(241, 231, 211, 0.68);
  font-size: 9.5px;
  letter-spacing: 0.03em;
  white-space: nowrap;
  opacity: 0;
  transition: opacity 400ms ease;
  backdrop-filter: blur(6px);
}
.toast.show { opacity: 1; }
.toast kbd { margin: 0 1px; }

/* ---------- 3D labels ---------- */
.part-label {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px 4px 5px;
  border: 1px solid rgba(201, 162, 91, 0.4);
  border-radius: 2px;
  background: rgba(5, 16, 22, 0.72);
  box-shadow: 0 3px 12px rgba(0, 0, 0, 0.28);
  color: rgba(241, 231, 211, 0.82);
  font-family: var(--sans);
  font-size: 9px;
  letter-spacing: 0.055em;
  line-height: 1;
  white-space: nowrap;
  pointer-events: none;
  backdrop-filter: blur(4px);
}

.part-label .dot {
  display: grid;
  place-items: center;
  width: 14px;
  height: 14px;
  border: 1px solid rgba(201, 162, 91, 0.55);
  border-radius: 50%;
  color: var(--brass-bright);
  font-family: var(--serif);
  font-size: 8px;
  line-height: 1;
}

.part-label.below {
  border-color: rgba(111, 195, 176, 0.3);
}
.part-label.below .dot {
  border-color: rgba(111, 195, 176, 0.5);
  color: var(--starboard);
}

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .side-panel { width: 302px; }
  .controls { width: min(470px, calc(100vw - 360px)); }
  .title-block { max-width: 240px; }
}

@media (max-width: 850px) {
  .side-panel { display: none; }
  .title-block p { display: none; }
  .controls { width: calc(100vw - 60px); }
  .compass-hud { transform: scale(0.86); transform-origin: bottom right; }
  .order-card { width: 300px; }
}
