* { box-sizing: border-box; margin: 0; }
html, body { height: 100%; overflow: hidden; background: #0a2f49;
  font-family: "Segoe UI", system-ui, sans-serif; }

#scene { position: fixed; inset: 0; width: 100vw; height: 100vh; display: block; }

#hud {
  position: fixed; left: 0; right: 0; bottom: 18px;
  display: flex; justify-content: center; gap: 36px;
  pointer-events: none; color: #f3e6c8; text-shadow: 0 1px 3px rgba(0, 0, 0, 0.75);
}
#hud > div { display: flex; flex-direction: column; align-items: center; }
#hud span:first-child { font-size: 1.9rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.hud-sub { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 1.5px; opacity: 0.8; }

#hint {
  position: fixed; top: 12px; left: 50%; transform: translateX(-50%);
  color: #f3e6c8; opacity: 0.75; font-size: 0.85rem;
  background: rgba(0, 0, 0, 0.28); padding: 6px 14px; border-radius: 20px;
  pointer-events: none;
}

#clock {
  position: fixed; top: 12px; left: 14px;
  color: #f3e6c8; background: rgba(0, 0, 0, 0.3);
  padding: 6px 13px; border-radius: 6px;
  font-size: 0.92rem; letter-spacing: 0.5px; font-variant-numeric: tabular-nums;
  pointer-events: none;
}

/* chart table — the navigator's hand-drawn chart */
#chart-overlay {
  position: fixed; inset: 0; z-index: 20; display: none;
  flex-direction: column; align-items: center; justify-content: center;
  background: rgba(18, 11, 4, 0.6);
}
#chart-frame {
  background: radial-gradient(120% 120% at 50% 30%, #f1e4c2, #d8c08f 82%);
  border: 14px solid #6b4a22; border-radius: 4px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.55), inset 0 0 70px rgba(120, 80, 30, 0.28);
  max-width: 92vw; max-height: 84vh; line-height: 0;
}
#chart-svg { height: 78vh; width: auto; display: block; }
#chart-close { margin-top: 12px; color: #f0e6cf; font-style: italic; opacity: 0.85; cursor: pointer; }
.ct-grid { stroke: rgba(90, 60, 30, 0.35); stroke-width: 1; }
.ct-grid-label { fill: #6b4a22; font: 12px Georgia, "Times New Roman", serif; }
.ct-land { fill: rgba(156, 126, 74, 0.5); stroke: #5b3d1c; stroke-width: 1.4; }
.ct-place { fill: #7a3b1c; }
.ct-place-label { fill: #5b3d1c; font: italic 12px Georgia, serif; }
.ct-track { fill: none; stroke: #8a2e1c; stroke-width: 2; stroke-dasharray: 6 4; }
.ct-ship { fill: #b5331f; stroke: #3a1108; stroke-width: 1.5; }
.ct-ship-label {
  fill: #7a2e1c; font: italic 13px Georgia, serif;
  paint-order: stroke; stroke: rgba(241, 228, 194, 0.85); stroke-width: 3px;
}

#sight-cue {
  position: fixed; top: 54px; left: 50%; transform: translateX(-50%); display: none;
  color: #2a1c08; background: #f0d877; padding: 7px 16px; border-radius: 20px;
  font-weight: 700; font-size: 0.92rem; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
  pointer-events: none;
}

/* backstaff sight */
#backstaff-overlay {
  position: fixed; inset: 0; z-index: 25; display: none;
  align-items: center; justify-content: center; background: rgba(14, 9, 3, 0.75);
}
#bs-panel {
  background: radial-gradient(120% 120% at 50% 20%, #f1e4c2, #d8c08f 85%);
  border: 12px solid #5b3d1c; border-radius: 6px; padding: 16px 18px;
  width: min(92vw, 760px); text-align: center; color: #3a2614;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.6);
}
#bs-title { margin: 0 0 8px; font: 700 1.2rem Georgia, serif; color: #5b3d1c; }
#bs-svg { width: 100%; height: auto; display: block; background: #cfe0ec; border-radius: 4px; touch-action: none; }
#bs-readout { margin: 10px 0 4px; font: 1.1rem Georgia, serif; }
#bs-readout b { font-size: 1.3rem; }
#bs-result { min-height: 2.6em; font: italic 1rem Georgia, serif; line-height: 1.4; }
#bs-buttons { display: flex; gap: 10px; justify-content: center; margin: 8px 0; }
#bs-buttons button { padding: 9px 14px; border: none; border-radius: 6px; font-weight: 700; cursor: pointer; font-family: Georgia, serif; }
#bs-mark { background: #2e6f4e; color: #fff; }
#bs-fix { background: #b07b1c; color: #fff; }
#bs-fix:disabled { background: #c9b78f; color: #6b5a36; cursor: default; }
#bs-close { background: #cdbd96; color: #2a2118; }
#bs-tip { font: italic 0.85rem Georgia, serif; opacity: 0.8; }
.bs-tick { fill: #6b4a22; font: 13px Georgia, serif; text-anchor: middle; }
.bs-sun { fill: #ffd23f; }
.bs-sun-glow { fill: rgba(255, 210, 63, 0.35); }
.bs-arm { stroke: #8a5a1e; stroke-width: 7; stroke-linecap: round; }
.bs-handle { fill: #c9962f; stroke: #5b3d1c; stroke-width: 2; cursor: grab; }
.bs-pivot { fill: #5b3d1c; }
.bs-star { fill: #eaf2ff; }
.bs-star-glow { fill: rgba(220, 235, 255, 0.35); }
.bs-plumb { stroke: #caa45a; stroke-width: 2; stroke-dasharray: 2 3; }
.bs-plumb-bob { fill: #6b4a22; }
.bs-steady-ring-bg { fill: none; stroke: rgba(58, 38, 20, 0.3); stroke-width: 4; pointer-events: none; }
.bs-steady-ring { fill: none; stroke-width: 4; stroke-linecap: round; pointer-events: none; }

#speed-cue {
  position: fixed; top: 90px; left: 50%; transform: translateX(-50%); display: none;
  color: #2a1c08; background: #d9b27a; padding: 6px 14px; border-radius: 18px;
  font-weight: 700; font-size: 0.85rem; box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
  pointer-events: none;
}

/* log-line */
#logline-overlay {
  position: fixed; inset: 0; z-index: 25; display: none;
  align-items: center; justify-content: center; background: rgba(14, 9, 3, 0.75);
}
#log-panel {
  background: radial-gradient(120% 120% at 50% 20%, #f1e4c2, #d8c08f 85%);
  border: 12px solid #5b3d1c; border-radius: 6px; padding: 16px 22px;
  width: min(92vw, 460px); text-align: center; color: #3a2614;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.6);
}
#log-panel h2 { margin: 0 0 8px; font: 700 1.15rem Georgia, serif; color: #5b3d1c; }
#log-svg { width: 280px; height: auto; display: block; margin: 0 auto; }
#log-readout { margin: 8px 0 2px; font: 1.05rem Georgia, serif; }
#log-readout b { font-size: 1.5rem; font-variant-numeric: tabular-nums; }
#log-result { min-height: 2.2em; font: italic 1rem Georgia, serif; }
#log-buttons { display: flex; gap: 10px; justify-content: center; margin: 8px 0; }
#log-buttons button { padding: 9px 14px; border: none; border-radius: 6px; font-weight: 700; cursor: pointer; font-family: Georgia, serif; }
#log-heave { background: #2e6f4e; color: #fff; }
#log-enter { background: #b07b1c; color: #fff; }
#log-enter:disabled { background: #c9b78f; color: #6b5a36; cursor: default; }
#log-close { background: #cdbd96; color: #2a2118; }
#log-tip { font: italic 0.85rem Georgia, serif; opacity: 0.8; }
.lg-frame { fill: rgba(120, 80, 30, 0.12); stroke: #6b4a22; stroke-width: 3; }
.lg-cap { fill: #6b4a22; }
.lg-sand { fill: #d8a23a; }
.lg-stream { stroke: #d8a23a; stroke-width: 3; }
.lg-stream-last { stroke: #f2c14e; stroke-width: 5; }
.lg-empty-flash { fill: none; stroke: #f2c14e; stroke-width: 5; pointer-events: none; }
#log-nip {
  display: block; margin: 6px auto 4px; padding: 12px 40px; border: none; border-radius: 10px;
  background: #8a2e1c; color: #fff; font: 800 1.3rem Georgia, serif; letter-spacing: 2px; cursor: pointer;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
}
#log-nip:disabled { background: #c9b78f; color: #6b5a36; cursor: default; box-shadow: none; }
#log-nip:not(:disabled):active { transform: scale(0.95); }

/* lead line */
#leadline-overlay {
  position: fixed; inset: 0; z-index: 25; display: none;
  align-items: center; justify-content: center; background: rgba(14, 9, 3, 0.75);
}
#lead-panel {
  background: radial-gradient(120% 120% at 50% 20%, #f1e4c2, #d8c08f 85%);
  border: 12px solid #5b3d1c; border-radius: 6px; padding: 16px 22px;
  width: min(92vw, 380px); text-align: center; color: #3a2614;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.6);
}
#lead-panel h2 { margin: 0 0 8px; font: 700 1.1rem Georgia, serif; color: #5b3d1c; }
#lead-svg { width: 210px; height: auto; display: block; margin: 0 auto; border-radius: 4px; }
#lead-result { min-height: 3em; font: 1.05rem Georgia, serif; line-height: 1.4; margin: 8px 0; }
#lead-buttons { display: flex; gap: 10px; justify-content: center; margin: 8px 0; }
#lead-buttons button { padding: 9px 14px; border: none; border-radius: 6px; font-weight: 700; cursor: pointer; font-family: Georgia, serif; }
#lead-heave { background: #2e6f4e; color: #fff; }
#lead-close { background: #cdbd96; color: #2a2118; }
#lead-tip { font: italic 0.85rem Georgia, serif; opacity: 0.8; }
.lead-tick { fill: #cfe0ec; font: 11px Georgia, serif; }
.lead-rope { stroke: #e8dcc0; stroke-width: 2; stroke-dasharray: 3 4; }
.lead-weight { fill: #2a2a2e; stroke: #11111a; stroke-width: 1; }
.lead-meter-frame { fill: rgba(14, 48, 71, 0.4); stroke: #0e3047; stroke-width: 1.5; }
.lead-meter-zone { fill: rgba(46, 111, 78, 0.6); }
.lead-meter-fill { fill: #f0d877; }
.lead-mark-tag { stroke: #e8dcc0; stroke-width: 3; }
.lead-mark-label { fill: #f6ecd2; font: 10px Georgia, serif; }
#lead-call { background: #b07b1c; color: #fff; }
#lead-call:disabled { background: #c9b78f; color: #6b5a36; cursor: default; }
#lead-heave { touch-action: none; user-select: none; -webkit-user-select: none; }

/* story scenes */
#scene-overlay {
  position: fixed; inset: 0; z-index: 30; display: none;
  align-items: center; justify-content: center; background: rgba(8, 6, 3, 0.82);
}
#scene-card {
  background: radial-gradient(130% 130% at 50% 0%, #f6ecd2, #ddc794 90%);
  border: 14px solid #4a3115; border-radius: 8px; padding: 22px 26px;
  width: min(94vw, 620px); color: #2f2113; box-shadow: 0 30px 90px rgba(0, 0, 0, 0.7);
}
#scene-title { margin: 0 0 10px; font: 700 1.5rem Georgia, serif; color: #5b3d1c; text-align: center; }
#scene-text p { font: 1.05rem/1.55 Georgia, serif; margin: 0 0 10px; }
#scene-buttons { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin-top: 14px; }
#scene-buttons button {
  padding: 11px 20px; border: none; border-radius: 6px; font: 700 1rem Georgia, serif;
  background: #2e6f4e; color: #fff; cursor: pointer;
}
#scene-buttons button:nth-child(2) { background: #b07b1c; }
#scene-buttons button:nth-child(3) { background: #8a3b2e; }

/* leaderboard */
#leaderboard-overlay {
  position: fixed; inset: 0; z-index: 35; display: none;
  align-items: center; justify-content: center; background: rgba(8, 6, 3, 0.85);
}
#lb-card {
  background: radial-gradient(130% 130% at 50% 0%, #f6ecd2, #ddc794 90%);
  border: 14px solid #4a3115; border-radius: 8px; padding: 20px 24px;
  width: min(94vw, 540px); color: #2f2113; box-shadow: 0 30px 90px rgba(0, 0, 0, 0.7);
}
#lb-title { margin: 0 0 6px; font: 700 1.4rem Georgia, serif; color: #5b3d1c; text-align: center; }
#lb-score { text-align: center; font: 700 1.1rem Georgia, serif; margin-bottom: 8px; }
#lb-form { display: none; gap: 8px; justify-content: center; margin-bottom: 10px; }
#lb-name {
  padding: 8px 10px; border: 2px solid #8a6a3a; border-radius: 5px;
  font: 1rem Georgia, serif; width: 200px; text-transform: uppercase;
}
#lb-save { padding: 8px 16px; border: none; border-radius: 5px; background: #2e6f4e; color: #fff; font-weight: 700; cursor: pointer; }
#lb-list { max-height: 50vh; overflow-y: auto; margin: 6px 0; border-top: 1px solid #b9a06f; }
.lb-row {
  display: grid; grid-template-columns: 2.2em 1fr auto auto; gap: 10px; align-items: baseline;
  padding: 5px 4px; border-bottom: 1px solid rgba(90, 60, 20, 0.18); font: 0.98rem Georgia, serif;
}
.lb-rank { color: #6b4a22; }
.lb-oc { font-size: 0.8rem; opacity: 0.7; }
.lb-sc { font-weight: 700; font-variant-numeric: tabular-nums; }
.lb-arrive .lb-oc { color: #2e6f4e; }
.lb-wreck .lb-oc { color: #8a3b2e; }
.lb-you { background: rgba(232, 193, 112, 0.55); border-radius: 4px; }
#lb-close { display: block; margin: 8px auto 0; padding: 9px 18px; border: none; border-radius: 6px; background: #cdbd96; color: #2a2118; font-weight: 700; cursor: pointer; }

/* status, lookout, sail label */
#status {
  position: fixed; top: 12px; right: 14px;
  color: #f3e6c8; background: rgba(0, 0, 0, 0.32); padding: 6px 14px; border-radius: 18px;
  font-size: 0.88rem; font-weight: 600; pointer-events: none; user-select: none;
}
#lookout {
  position: fixed; top: 52px; right: 14px; display: none;
  color: #dff0ff; background: rgba(10, 30, 45, 0.55); padding: 5px 12px; border-radius: 16px;
  font-size: 0.84rem; pointer-events: none; user-select: none;
}
/* weather chip — current weather, pinned under the lookout pill */
#weather-chip {
  position: fixed; top: 92px; right: 14px;
  color: #f6e3b4; background: rgba(72, 48, 8, 0.55); padding: 5px 12px; border-radius: 16px;
  font-size: 0.84rem; pointer-events: none; user-select: none;
}
.hud-sail { font-size: 1.05rem !important; font-weight: 700 !important; padding-top: 0.5em; }

/* instrument toolbar */
#toolbar {
  position: fixed; left: 14px; bottom: 16px; display: flex; flex-direction: column; gap: 7px;
  z-index: 5;
}
#toolbar button {
  padding: 8px 12px; border: 2px solid #5b3d1c; border-radius: 7px;
  background: linear-gradient(#f1e4c2, #ddc794); color: #3a2614;
  font: 700 0.85rem Georgia, serif; cursor: pointer; text-align: left;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.35); user-select: none;
}
#toolbar button:hover { background: linear-gradient(#fff3d8, #e8d3a4); transform: translateX(2px); }

/* watch-the-AI banner & captions */
#ai-banner {
  position: fixed; top: 50px; left: 50%; transform: translateX(-50%); display: none;
  align-items: center; gap: 14px; z-index: 6;
  background: rgba(176, 123, 28, 0.92); color: #fff; padding: 8px 16px; border-radius: 22px;
  font-weight: 700; font-size: 0.92rem; box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45);
}
#ai-banner button {
  padding: 6px 12px; border: none; border-radius: 14px; background: #2e6f4e; color: #fff;
  font-weight: 700; cursor: pointer;
}
#ai-caption {
  position: fixed; bottom: 96px; left: 50%; transform: translateX(-50%); display: none;
  max-width: min(86vw, 640px); text-align: center;
  color: #f6ecd2; font: italic 1.08rem Georgia, serif;
  background: rgba(8, 6, 3, 0.55); padding: 8px 18px; border-radius: 8px;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8); pointer-events: none;
}

#hud, #hint, #clock { user-select: none; }

#error-banner {
  position: fixed; top: 0; left: 0; right: 0; z-index: 10; display: none;
  background: #c0392b; color: #fff; padding: 10px; text-align: center; font-weight: 600;
}
