/* Sail Trainer 3D — HUD styling */
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; overflow: hidden; }
body {
  font-family: "Avenir Next", "Segoe UI", system-ui, sans-serif;
  color: #eaf3fa;
  background: #0a2438;
  user-select: none;
  -webkit-user-select: none;
}
#app, #app canvas { position: fixed; inset: 0; }

kbd {
  background: rgba(255,255,255,0.14);
  border: 1px solid rgba(255,255,255,0.25);
  border-radius: 4px;
  padding: 0 5px;
  font-family: inherit;
  font-size: 0.9em;
}

.panel {
  position: fixed;
  background: rgba(7, 21, 33, 0.72);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(140, 190, 230, 0.18);
  border-radius: 14px;
  padding: 14px 16px;
  box-shadow: 0 8px 28px rgba(0, 8, 16, 0.35);
}

#brand {
  position: fixed; top: 12px; left: 50%; transform: translateX(-50%);
  font-size: 15px; letter-spacing: 0.4px; opacity: 0.92;
  text-shadow: 0 1px 6px rgba(0,0,0,0.5);
  pointer-events: none; z-index: 5;
}
#brand span { opacity: 0.65; font-size: 13px; }

/* ---------------- Lesson panel ---------------- */
#lessonPanel { top: 46px; left: 14px; width: 330px; z-index: 4; }
#lessonTitle { font-weight: 700; font-size: 15px; color: #8fd0ff; letter-spacing: 0.3px; }
#lessonBrief { margin-top: 6px; font-size: 12.5px; line-height: 1.45; opacity: 0.88; }
.environment-info { margin-top: 5px; color: #9ed8ff; font-size: 11px; letter-spacing: 0.04em; }
#lessonStep {
  margin-top: 10px; font-size: 13px; line-height: 1.45;
  background: rgba(90, 190, 255, 0.10);
  border-left: 3px solid #4fa8ff;
  padding: 8px 10px; border-radius: 0 8px 8px 0;
}
.markinfo { margin-top: 8px; font-size: 12px; color: #7dffb5; font-variant-numeric: tabular-nums; }

/* ---------------- Exam mode ----------------
   Tests hide the coaching aids: mainsheet trim bar, coach tip, status badge.
   Real-boat instruments (wind rose, speed/heading, mark info) stay. */
body.exam-mode #trimWrap { display: none; }
body.exam-mode #statusBadge { visibility: hidden; }
body.exam-mode #lessonPanel { border-color: rgba(255, 178, 80, 0.4); }
body.exam-mode #lessonTitle { color: #ffc270; }
body.exam-mode #lessonStep { background: rgba(255, 178, 80, 0.10); border-left-color: #ffb14f; }
.exampill {
  display: inline-block; margin-left: 8px; padding: 1px 8px; border-radius: 999px;
  font-size: 10px; letter-spacing: 1px; vertical-align: 2px;
  background: rgba(255, 178, 80, 0.18); border: 1px solid rgba(255, 178, 80, 0.5); color: #ffc270;
}

/* ---------------- Status ---------------- */
#statusWrap {
  position: fixed; top: 44px; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 8px; z-index: 4;
  pointer-events: none;
}
.status {
  padding: 7px 18px; border-radius: 999px; font-weight: 700; font-size: 14px;
  letter-spacing: 0.6px; opacity: 0; transition: opacity 0.25s;
  background: rgba(20, 40, 60, 0.8); border: 1px solid rgba(255,255,255,0.2);
}
.status.good { background: rgba(28, 130, 70, 0.85); border-color: #4fdc8b; }
.status.warn { background: rgba(160, 110, 20, 0.85); border-color: #ffc14f; }
.status.bad  { background: rgba(150, 35, 35, 0.88); border-color: #ff7a6e; animation: throb 1s infinite; }
@keyframes throb { 50% { transform: scale(1.05); } }
#raceClock {
  display: none; font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums;
  text-shadow: 0 1px 8px rgba(0,0,0,0.6);
}

/* ---------------- Wind rose ---------------- */
#rosePanel { top: 14px; right: 14px; padding: 8px; z-index: 4; }
#windRose { display: block; }
#windSectorsToggle {
  position: absolute; top: 1px; right: 1px;
  display: grid; place-items: center; width: 30px; height: 30px;
  border: 0; border-radius: 50%; background: transparent;
  color: #b5cada; cursor: pointer;
}
#windSectorsToggle:hover, #windSectorsToggle[aria-pressed="true"] {
  color: #fff; background: rgba(140, 190, 230, .16);
}
.windnums { display: flex; justify-content: space-between; font-size: 11.5px; padding: 2px 6px 4px; }
.windnums .true { color: #4fa8ff; }
.windnums .app { color: #ffb14f; }

/* ---------------- Instruments ---------------- */
#instruments {
  left: 14px; bottom: 14px; z-index: 4;
  display: grid; grid-template-columns: repeat(4, auto); gap: 4px 18px;
}
.inst label { font-size: 10px; letter-spacing: 1px; opacity: 0.6; }
.big { font-size: 30px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.1; }
.big.small { font-size: 22px; padding-top: 5px; }
.big small { font-size: 12px; opacity: 0.6; margin-left: 3px; }
#heelVal.danger { color: #ff8a80; }

/* ---------------- Trim + tip ---------------- */
#trimWrap {
  position: fixed; bottom: 14px; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 8px; z-index: 4;
}
#trimBar {
  background: rgba(7, 21, 33, 0.72);
  border: 1px solid rgba(140, 190, 230, 0.18);
  border-radius: 12px;
  backdrop-filter: blur(10px);
}
.tip {
  max-width: 460px; text-align: center; font-size: 13px; line-height: 1.4;
  background: rgba(7, 21, 33, 0.72); border: 1px solid rgba(140,190,230,0.18);
  border-radius: 10px; padding: 8px 14px;
  backdrop-filter: blur(10px);
}
.tip.pulse { animation: tipIn 0.35s ease-out; }
@keyframes tipIn { from { transform: translateY(8px); opacity: 0.2; } }

/* ---------------- Right rail ---------------- */
#rail::-webkit-scrollbar { display: none; }
.pickhead {
  font-size: 9px; letter-spacing: 1.6px; font-weight: 700; opacity: 0.65;
  text-align: right; padding-right: 4px; text-shadow: 0 1px 4px rgba(0,0,0,0.6);
}
.pickhead.exam { color: #ffc270; opacity: 0.9; margin-top: 6px; }
.picker { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.picker button { min-height: 34px; }
#testPicker button { border-color: rgba(255, 178, 80, 0.35); color: #ffd9a8; font-size: 11px; }
#testPicker button:hover { background: rgba(115, 80, 30, 0.7); }
#testPicker button.active { border-color: #ffb14f; color: #ffc270; background: rgba(140, 90, 30, 0.55); }
#testPicker button.done::after { content: ' ✓'; color: #7dffb5; }
.picker button, .railbtn {
  min-width: 44px; min-height: 40px;
  background: rgba(7, 21, 33, 0.72); color: #cfe6f7;
  border: 1px solid rgba(140,190,230,0.25); border-radius: 10px;
  font-size: 13px; font-weight: 700; cursor: pointer;
  backdrop-filter: blur(8px);
  transition: background 0.15s, border-color 0.15s;
}
.picker button:hover, .railbtn:hover { background: rgba(40, 80, 115, 0.8); }
.picker button.active { border-color: #4fa8ff; color: #8fd0ff; background: rgba(35, 90, 140, 0.6); }
.picker button.locked { opacity: 0.38; }
.railbtn.on { border-color: #4fdc8b; color: #7dffb5; }
.railbtn.wide { padding: 0 10px; font-size: 11px; }
#autoTrimBtn { font-size: 9px; line-height: 1.3; }

/* ---------------- Wind panel ---------------- */
#windPanel { right: 14px; bottom: 14px; width: 205px; display: none; z-index: 4; }
#windPanel.show { display: block; }
.ptitle { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 11px; letter-spacing: 1.5px; opacity: 0.65; margin-bottom: 8px; }
#freePanelToggle { display: none; border: 1px solid rgba(130,190,230,.38); border-radius: 6px; padding: 4px 7px; background: rgba(9,31,48,.94); color: #edf8ff; font: inherit; letter-spacing: .04em; }
#windPanel label { display: block; font-size: 12px; margin-top: 6px; }
#windPanel input[type="range"] { width: 100%; accent-color: #4fa8ff; }
#windPanel select { width: 100%; margin-top: 3px; padding: 5px 6px; border: 1px solid rgba(130,190,230,.38); border-radius: 5px; color: #edf8ff; background: rgba(9,31,48,.94); }
.panel-subtitle { margin-top: 10px; padding-top: 8px; border-top: 1px solid rgba(160,210,240,.2); font-size: 10px; letter-spacing: .12em; color: #9ed8ff; }
.attribution { margin-top: 10px; font-size: 9px; line-height: 1.35; opacity: .55; }
.attribution a { color: inherit; }

/* ---------------- Mobile menu (phones only; hidden on desktop) ---------------- */
#menuBtn, #menuBackdrop, #trimToggle { display: none; }

/* ---------------- Touch ---------------- */
#touch {
  position: fixed; bottom: 96px; left: 50%; transform: translateX(-50%);
  display: none; gap: 40px; z-index: 4;
}
@media (pointer: coarse) { #touch { display: flex; } }
.tgroup { text-align: center; }
.tgroup button {
  width: 58px; height: 58px; border-radius: 50%; font-size: 24px; margin: 0 5px;
  background: rgba(7,21,33,0.6); color: #eaf3fa; border: 1px solid rgba(140,190,230,0.35);
}
.tlabel { font-size: 10px; letter-spacing: 1px; opacity: 0.6; margin-top: 4px; }

/* ---------------- Points of sail ---------------- */
.pclose { float: right; cursor: pointer; opacity: 0.7; font-size: 12px; }
.pclose:hover { opacity: 1; }

/* ---------------- Help ---------------- */
#helpPanel { right: 70px; top: 300px; width: 300px; display: none; z-index: 6; }
#helpPanel.show { display: block; }
#helpPanel table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
#helpPanel td { padding: 4px 2px; vertical-align: top; }
#helpPanel td:first-child { white-space: nowrap; padding-right: 10px; }
#helpPanel .hint { margin-top: 8px; font-size: 12px; opacity: 0.85; line-height: 1.4; }

/* ---------------- Complete overlay ---------------- */
#completeOverlay {
  position: fixed; inset: 0; display: none; align-items: center; justify-content: center;
  background: rgba(4, 12, 20, 0.55); z-index: 10;
  backdrop-filter: blur(3px);
}
#completeOverlay.show { display: flex; }
#completeOverlay .card {
  width: min(520px, 88vw);
  background: rgba(10, 28, 44, 0.95);
  border: 1px solid rgba(140, 190, 230, 0.3);
  border-radius: 18px; padding: 28px 30px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
  animation: cardIn 0.4s ease-out;
}
@keyframes cardIn { from { transform: translateY(18px) scale(0.97); opacity: 0; } }
#completeOverlay h2 { color: #7dffb5; font-size: 20px; margin-bottom: 10px; }
#completeOverlay p { font-size: 14px; line-height: 1.55; opacity: 0.92; }
.raceResult { font-size: 16px; margin-bottom: 10px; color: #8fd0ff; }
.recap + .recap { margin-top: 16px; padding-top: 14px; border-top: 1px solid rgba(140, 190, 230, 0.22); }
.recapLabel {
  font-size: 11px; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase;
  color: #8fd0ff; opacity: 0.8; margin-bottom: 6px;
}
#completeOverlay .nextTitle { font-weight: 600; color: #cfe6f8; opacity: 1; }
#completeOverlay .nextPreview { margin-top: 3px; opacity: 0.78; }
.btnrow { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; }
.btnrow button {
  padding: 10px 18px; border-radius: 10px; font-size: 14px; font-weight: 600; cursor: pointer;
  background: rgba(255,255,255,0.08); color: #eaf3fa; border: 1px solid rgba(255,255,255,0.2);
}
.btnrow button.primary { background: #1e6fb8; border-color: #4fa8ff; }
.btnrow button:hover { filter: brightness(1.2); }

/* ---------------- Fail overlay ---------------- */
#failOverlay {
  position: fixed; inset: 0; display: none; align-items: center; justify-content: center;
  background: rgba(20, 6, 6, 0.55); z-index: 10;
  backdrop-filter: blur(3px);
}
#failOverlay.show { display: flex; }
#failOverlay .card {
  width: min(520px, 88vw);
  background: rgba(40, 14, 16, 0.95);
  border: 1px solid rgba(255, 122, 110, 0.4);
  border-radius: 18px; padding: 28px 30px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
  animation: cardIn 0.4s ease-out;
}
#failOverlay h2 { color: #ff8a80; font-size: 20px; margin-bottom: 10px; }
#failOverlay p { font-size: 14px; line-height: 1.55; opacity: 0.92; }
.failreason {
  background: rgba(255, 122, 110, 0.10); border-left: 3px solid #ff7a6e;
  padding: 8px 10px; border-radius: 0 8px 8px 0; margin-top: 8px;
}
#failOverlay .btnrow button.primary { background: #a8402f; border-color: #ff8a70; }

/* ---------------- Small screens ---------------- */
@media (max-width: 900px) {
  #lessonPanel { width: 260px; font-size: 12px; top: 40px; }
  #rosePanel { transform: scale(0.78); transform-origin: top right; }
  #instruments { gap: 2px 10px; }
  .big { font-size: 22px; }
  .big.small { font-size: 16px; }
  #trimBar { width: 300px; }
  .tip { max-width: 320px; font-size: 12px; }
}

/* ============================================================================
   MOBILE VIEW — a decluttered, phone-first layout.
   Narrow windows share the phone layout so every menu control stays reachable.
   During sailing the phone shows only the essentials; the lesson
   picker, exam picker and tool buttons move into a slide-in drawer (☰).
   ============================================================================ */
@media (max-width: 860px) {

  /* Brand wordmark is pure chrome — drop it to free the top of the screen. */
  #brand { display: none; }

  /* ---- Top band: SPEED (next to the menu button) ---- */
  #instruments {
    left: 62px; top: 12px; right: auto; bottom: auto;
    display: flex; align-items: baseline; gap: 10px;
    padding: 6px 12px; max-width: calc(100vw - 208px); overflow: hidden;
  }
  #instruments .inst { display: none; }                 /* HDG / HEEL / TRIM */
  #instruments .inst:first-child {                        /* keep SPEED */
    display: flex; align-items: baseline; gap: 3px;
  }
  #instruments .inst:first-child label { display: none; }
  #instruments .big { font-size: 18px; }
  #instruments .big small { font-size: 11px; }
  /* Keep the wind labels at readable sizes instead of scaling the whole panel. */
  #rosePanel { top: 8px; right: 4px; width: 190px; transform: none; }
  #windRose { width: 170px; height: 170px; margin: auto; }
  .windnums { font-size: 10px; padding: 2px 0 4px; gap: 4px; }

  /* ---- Lesson banner: the current step + goal, full width below the rose ---- */
  #lessonPanel {
    top: 224px; left: 10px; right: 10px; width: auto;
    max-height: 26vh; overflow-y: auto; padding: 10px 12px;
  }
  #lessonBrief { display: none; }               /* drop the long explanation */
  #lessonTitle { font-size: 13px; }
  #lessonStep { margin-top: 6px; font-size: 12.5px; padding: 7px 9px; }

  /* ---- Transient status: a centred toast over open water, clear of the banner ---- */
  #statusWrap { top: 54vh; bottom: auto; }

  /* ---- Mainsheet trim + coach tip: a band above the thumb controls.
     The trim gauge stays, with a − toggle to minimize it down to just the tip. ---- */
  #trimWrap { left: 10px; right: 10px; bottom: 96px; transform: none; align-items: center; gap: 6px; }
  #trimBar { display: block; width: min(340px, 100%); height: auto; }
  body.trim-min #trimBar { display: none; }
  #trimToggle {
    display: inline-flex; align-items: center; justify-content: center;
    align-self: flex-end; width: 30px; height: 26px; border-radius: 8px;
    background: rgba(7, 21, 33, 0.82); color: #cfe6f7;
    border: 1px solid rgba(140, 190, 230, 0.3);
    backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
    font-size: 18px; line-height: 1; cursor: pointer;
  }
  .tip { max-width: 100%; font-size: 12px; padding: 7px 12px; }

  /* ---- Touch controls: rudder and sheet in the bottom corners ---- */
  #touch {
    display: flex;
    left: 0; right: 0; bottom: 14px; transform: none;
    width: 100%; justify-content: space-between; gap: 0; padding: 0 14px;
  }

  /* ---- Free-sail wind controls: compact, clear of the thumbs ---- */
  #windPanel { right: 10px; top: 106px; bottom: auto; left: auto; width: min(205px, calc(100vw - 20px)); max-height: calc(100dvh - 126px); overflow-y: auto; }
  #freePanelToggle { display: inline-block; }
  body.free-panel-collapsed #windPanel { top: 62px; right: auto; left: 10px; width: 150px; overflow: hidden; }
  body.free-panel-collapsed #windPanel .ptitle { margin-bottom: 0; }
  body.free-panel-collapsed #freePanelBody { display: none; }

  /* ---- Diagram / help overlays: centred cards ---- */
  #helpPanel {
    top: 50%; left: 50%; right: auto;
    transform: translate(-50%, -50%);
    width: min(340px, 90vw); max-height: 82vh; overflow: auto;
  }
}

/* Onboarding pairs a quiet reading panel with the approved yacht artwork. */
[hidden] { display: none !important; }
body[data-flow="welcome"] #simulator > :not(#app),
body[data-flow="track-introduction"] #simulator > :not(#app),
body[data-flow="theory"] #simulator > :not(#app),
body[data-flow="track-complete"] #simulator > :not(#app) { visibility: hidden; }
#introOverlay {
  position: fixed; inset: 0; z-index: 11; display: flex;
  overflow-y: auto; align-items: flex-start; color: #10294b; background: #f7f9fc;
}
#introOverlay .card {
  width: 47%; min-height: 100%; padding: 32px clamp(28px, 4.1vw, 72px);
  background: #f7f9fc; display: flex; flex-direction: column;
}
.intro-brand { display: flex; align-items: center; gap: 13px; font-size: 21px; font-weight: 550; }
.intro-brand svg { width: 28px; height: 34px; flex: none; }
.intro-page { width: 100%; max-width: 610px; margin: auto 0; padding: 56px 0 24px; }
#introVisual { position: fixed; left: 47%; right: 0; top: 0; bottom: 0; pointer-events: none; container-type: size; background: #8dbbdf; }
/* Display only the yacht region of the approved source mockup (x=742..1586).
   Container units cover any panel aspect ratio without exposing its baked-in UI. */
.intro-photo { width: 100%; height: 100%; background-image: url('assets/onboarding-yacht-source.png'); background-repeat: no-repeat; background-position: right center; background-size: max(187.915cqw, 159.879cqh) max(117.536cqw, 100cqh); }
#introOverlay h1 { font-size: clamp(38px, 4.5vw, 70px); font-weight: 700; line-height: 1.08; letter-spacing: -2px; margin: 0 0 24px; }
#introOverlay p { font-size: 17px; line-height: 1.55; color: #53647d; }
#introOverlay .intro-lead { font-size: clamp(20px, 2vw, 29px); line-height: 1.4; margin-bottom: 28px; }
#introOverlay .intro-meta { font-size: 16px; margin-bottom: 28px; }
#introOverlay button { font: inherit; cursor: pointer; border-radius: 5px; }
#introOverlay .intro-cta { display: flex; align-items: center; justify-content: space-between; gap: 24px; width: 100%; min-height: 62px; padding: 15px 24px; background: #103660; color: white; border: 1px solid #103660; font-size: 21px; font-weight: 600; }
#introOverlay .intro-cta:hover { background: #194775; }
.intro-secondary { border-top: 1px solid #d6dfe9; margin-top: 40px; padding-top: 34px; }
#introOverlay h2 { color: #10294b; font-size: 23px; line-height: 1.3; margin-bottom: 10px; }
#introOverlay .intro-link, #introOverlay .intro-back { background: transparent; color: #103660; border: 0; padding: 12px 0; min-height: 44px; text-align: left; }
#introOverlay .intro-link { font-size: 19px; font-weight: 650; margin-top: 14px; }
.intro-link span { margin-left: 18px; }
#introOverlay .intro-link:hover, #introOverlay .intro-back:hover { text-decoration: underline; text-underline-offset: 5px; }
#introOverlay .intro-back { margin: -32px 0 28px; color: #53647d; }
#introOverlay .intro-footnote { font-size: 14px; margin-top: 26px; }
body[data-flow="welcome"] .intro-footnote { margin-top: 52px; }
.journey-page .intro-meta { margin-bottom: 14px; font-size: 13px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; }
body[data-flow="track-introduction"] .journey-page h1 { font-size: clamp(38px, 4vw, 62px); margin-bottom: 14px; }
#introOverlay .journey-page .intro-lead { margin-bottom: 0; font-size: clamp(18px, 1.8vw, 25px); }
.journey-map { --journey-indent: clamp(100px, 10vw, 132px); position: relative; min-height: 306px; margin: 18px 0 24px; }
.journey-route { position: absolute; inset: 0 auto 0 0; width: var(--journey-indent); height: 100%; overflow: visible; pointer-events: none; }
.journey-course { fill: none; stroke: #91abc4; stroke-width: 1.3; vector-effect: non-scaling-stroke; }
.journey-boat { fill: #103660; }
.journey-finish { fill: none; stroke: #103660; stroke-width: 1.6; vector-effect: non-scaling-stroke; }
.journey-stops { position: relative; display: grid; grid-template-rows: repeat(3, 1fr); min-height: 306px; list-style: none; }
.journey-stops li { display: flex; flex-direction: column; justify-content: center; padding-left: var(--journey-indent); }
.journey-stops strong { font-size: 20px; line-height: 1.3; }
#introOverlay .journey-stops p { margin-top: 3px; font-size: 15px; line-height: 1.42; }
.intro-exam-details { padding-left: 20px; line-height: 1.6; margin: 30px 0; color: #53647d; }
.intro-exam-details li { margin: 12px 0; }
.intro-eyebrow { color: #53647d; font-size: 14px; margin-bottom: 20px; }
#introOverlay .btnrow button { background: #edf2f8; border: 1px solid #d6dfe9; color: #103660; }
#introOverlay .btnrow .primary { background: #103660; border-color: #103660; color: #fff; }
#introOverlay .replay-choices button { background: #edf2f8; border-color: #d6dfe9; color: #103660; }
/* The theory card floats over the live simulator, leaving the yacht in view. */
body[data-flow="theory"] #introOverlay {
  background: transparent; pointer-events: none; overflow: hidden;
  align-items: center; padding: 20px;
}
body[data-flow="theory"] #introOverlay .card {
  pointer-events: auto; width: min(460px, 39vw); min-height: 0;
  max-height: calc(100dvh - 40px); overflow-y: auto;
  padding: 22px 26px; border: 1px solid #d6dfe9; border-radius: 14px;
  box-shadow: 0 18px 56px rgba(7, 29, 53, .25);
  background: rgba(247, 249, 252, .97);
}
body[data-flow="theory"] #introVisual { display: none; }
body[data-flow="theory"] .intro-brand { font-size: 15px; }
body[data-flow="theory"] .intro-brand svg { width: 20px; height: 24px; }
body[data-flow="theory"] .intro-page { padding: 16px 0 0; margin: 0; }
body[data-flow="theory"] #introOverlay h1 { font-size: clamp(28px, 2.5vw, 36px); letter-spacing: -.8px; margin: 12px 0 8px; }
body[data-flow="theory"] #introOverlay p { font-size: 15px; line-height: 1.4; }
.theory-header, .theory-nav { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.theory-count { color: #62758c; font-size: 11px; font-weight: 750; letter-spacing: .1em; white-space: nowrap; }
#introOverlay .theory-skip { border: 0; padding: 9px 0; background: transparent; color: #103660; text-decoration: underline; text-underline-offset: 3px; font-size: 12px; font-weight: 650; }
#introOverlay .theory-lead { margin: 0 0 10px; }
.theory-focus { margin: 0 0 4px !important; color: #317394; font-size: 11px !important; font-weight: 800; letter-spacing: .08em; }
.theory-compass { display: grid; grid-template-columns: 174px 1fr; align-items: center; gap: 8px; margin: 0 0 10px; padding: 5px 9px 7px; background: #ecf2f6; border-radius: 9px; }
.theory-compass-wheel { position: relative; padding-top: 12px; }
.theory-compass-wheel svg { display: block; width: 174px; height: 174px; }
.theory-wind-label { position: absolute; top: 0; left: 0; width: 100%; text-align: center; color: #103660; font-size: 11px; font-weight: 750; }
.theory-compass-key { display: grid; gap: 2px; }
.theory-key-item { display: flex; align-items: center; gap: 7px; min-height: 24px; padding: 2px 6px; border-radius: 4px; color: #52677b; font-size: 12px; line-height: 1.2; }
.theory-key-item i { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.theory-key-item.current { background: #fff; color: #103660; font-weight: 750; }
.theory-sector.current { stroke: #103660; stroke-width: 2; }
.theory-readout { background: #e9f0f6; border-left: 3px solid #4384ad; border-radius: 5px; padding: 9px 12px; min-height: 0; }
.theory-readout span { font-weight: 750; color: #103660; font-size: 14px; }
#introOverlay .theory-readout p { margin: 4px 0 0; font-size: 13px; }
#introOverlay .theory-takeaway { margin: 10px 0 0; }
.theory-playback { display: flex; gap: 8px; margin-top: 9px; }
#introOverlay .theory-playback button { min-height: 40px; flex: 1; border: 1px solid #a9bacb; background: #fff; color: #103660; padding: 7px 9px; font-size: 13px; font-weight: 650; }
#introOverlay .theory-playback button:hover:not(:disabled) { background: #e8f0f6; }
#introOverlay .theory-playback button:disabled { opacity: .65; cursor: default; }
.theory-nav { margin-top: 12px; }
#introOverlay .theory-nav .intro-back { margin: 0; }
#introOverlay .theory-nav .primary { min-height: 44px; border: 0; background: #103660; color: white; padding: 9px 14px; font-size: 14px; font-weight: 700; }
#introOverlay .theory-nav .primary:hover { background: #194775; }
@media (max-width: 760px) {
  #introOverlay { display: block; padding-top: 23vh; }
  #introOverlay .card { width: 100%; min-height: 77vh; padding: 24px; position: relative; z-index: 1; }
  #introVisual { left: 0; height: 23vh; bottom: auto; }
  .intro-photo { background-position: right 75%; }
  .intro-brand { font-size: 18px; }
  .intro-brand svg { width: 23px; height: 28px; }
  .intro-page { padding-top: 36px; margin: 0 auto; }
  #introOverlay h1 { font-size: 42px; letter-spacing: -1.3px; margin-bottom: 18px; }
  #introOverlay .intro-lead { font-size: 22px; }
  #introOverlay .intro-cta { min-height: 56px; font-size: 19px; }
  .intro-secondary { margin-top: 28px; padding-top: 26px; }
  #introOverlay h2 { font-size: 21px; }
  body[data-flow="welcome"] .intro-footnote { margin-top: 28px; }
  #introOverlay .intro-back { margin: -16px 0 16px; }
  .wide-break { display: none; }
  #introOverlay.journey-active { padding-top: 16vh; }
  #introOverlay.journey-active .card { min-height: 84vh; }
  #introOverlay.journey-active #introVisual { height: 16vh; }
  #introOverlay.journey-active .intro-page { padding-top: 20px; }
  #introOverlay.journey-active .intro-back { margin-bottom: 8px; }
  #introOverlay.journey-active .intro-meta { margin-bottom: 8px; }
  body[data-flow="track-introduction"] .journey-page h1 { font-size: clamp(34px, 8vw, 42px); }
  #introOverlay .journey-page .intro-lead { font-size: 19px; }
  .journey-map, .journey-stops { min-height: 238px; }
  .journey-map { --journey-indent: 78px; margin: 10px 0 14px; }
  .journey-stops strong { font-size: 18px; }
  #introOverlay .journey-stops p { font-size: 14px; }
  body[data-flow="theory"] #introOverlay { display: flex; align-items: flex-end; padding: 0; }
  body[data-flow="theory"] #introOverlay .card {
    width: 100%; max-height: min(52dvh, 390px); min-height: 0;
    border-radius: 16px 16px 0 0; padding: 12px 20px max(12px, env(safe-area-inset-bottom));
  }
  body[data-flow="theory"] .intro-brand { display: none; }
  body[data-flow="theory"] .intro-page { padding: 0; }
  body[data-flow="theory"] .theory-header { position: sticky; top: -12px; z-index: 1; background: #f7f9fc; padding: 8px 0; }
  body[data-flow="theory"] #introOverlay h1 { font-size: 25px; margin: 4px 0 5px; }
  body[data-flow="theory"] #introOverlay p { font-size: 14px; }
  body[data-flow="theory"] .theory-readout { min-height: 0; }
  body[data-flow="theory"] .theory-compass { grid-template-columns: 154px 1fr; padding: 3px 5px 5px; }
  body[data-flow="theory"] .theory-compass-wheel svg { width: 154px; height: 154px; }
  body[data-flow="theory"] .theory-key-item { min-height: 21px; padding: 1px 4px; font-size: 11px; }
}
@media (max-width: 355px) {
  body[data-flow="theory"] .theory-compass { grid-template-columns: 134px 1fr; }
  body[data-flow="theory"] .theory-compass-wheel svg { width: 134px; height: 134px; }
}
@media (max-height: 540px) and (min-width: 761px) {
  #introOverlay .card { padding: 24px 32px; }
  .intro-page { padding-top: 36px; }
  #introOverlay h1 { font-size: 40px; }
  .journey-map, .journey-stops { min-height: 235px; }
  .journey-map { margin: 8px 0 14px; }
  .journey-stops strong { font-size: 18px; }
  #introOverlay .journey-stops p { font-size: 14px; }
}
button:focus-visible { outline: 3px solid #ffbe6a; outline-offset: 4px; }
[tabindex="-1"]:focus { outline: none; }
.track-switch { background: #102b40; border: 1px solid #426278; color: #cfe6f7; border-radius: 8px; padding: 7px 4px; cursor: pointer; font: inherit; font-size: 12px; }
.track-switch[aria-pressed="true"] { border-color: #8fd0ff; color: #fff; background: #205475; }
#replayIntroBtn { font-size: 10px; line-height: 1.35; white-space: normal; }
.replay-choices { display: grid; gap: 8px; margin-top: 24px; }
.replay-choices button { padding: 12px 16px; background: #102f45; color: #eaf3fa; border: 1px solid #426278; border-radius: 9px; text-align: left; cursor: pointer; font: inherit; font-size: 14px; }
body.tutorial-active #lessonBrief, body.tutorial-active #lessonStep,
body.tutorial-active #tipText, body.tutorial-active #statusWrap { display: none; }
body.tutorial-active #lessonPanel { max-height: calc(100dvh - 220px); overflow-y: auto; }
#tutorialCoach { margin-top: 14px; }
.coach-heading { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
#coachCount { color: #8fd0ff; font-size: 12px; font-weight: 800; letter-spacing: 1px; }
.coach-steps { display: flex; gap: 5px; list-style: none; margin: 10px 0 12px; padding: 0; }
.coach-steps li { flex: 1; height: 24px; display: grid; place-items: center; border: 1px solid #5b7d92; border-radius: 5px; color: #a7c0cf; font-size: 11px; font-weight: 800; }
.coach-steps li.done { background: #286579; color: #fff; border-color: #60b69f; }
.coach-steps li[aria-current="step"] { background: #f5bd67; border-color: #ffe0a4; color: #17344f; box-shadow: 0 0 0 2px #f5bd6755; }
#coachAdvance { margin: 2px 0 10px; padding: 8px 10px; background: #225e71; color: #edfff5; border-left: 3px solid #88ddb4; border-radius: 4px; font-size: 12px; font-weight: 700; }
#guidanceToggle { border: 0; border-bottom: 1px solid #688ca5; background: transparent; color: #cfe6f7; padding: 6px 0; cursor: pointer; font-size: 11px; }
#coachTitle { font-size: 20px; margin: 4px 0 8px; color: #f0f7fc; }
#coachGoal { margin: 0 0 12px; color: #bce8d8; font-size: 13px; line-height: 1.45; }
.coach-instruction { margin: 8px 0; padding: 8px 10px; background: #244257; border-radius: 5px; }
.coach-instruction strong { display: block; color: #8fd0ff; font-size: 10px; letter-spacing: .09em; }
.coach-instruction p { margin: 3px 0 0 !important; }
#coachAction, #coachRecovery { font-size: 13px; line-height: 1.5; margin: 8px 0; }
#coachSail { color: #edf8ff; font-size: 13px; line-height: 1.45; }
#coachProgress { display: block; width: 100%; height: 8px; accent-color: #7dffb5; margin: 16px 0 8px; }
#coachProgressText { color: #9eeac7; font-size: 12px; }
#coachRecovery { color: #ffcd8b; }
#coachRecovery:empty { display: none; }
.tutorial-highlight { outline: 2px solid #ffbe6a; outline-offset: 4px; border-radius: 6px; }
#completeOverlay, #failOverlay { overflow-y: auto; padding: 20px; }
@media (max-width: 600px) {
  .btnrow { flex-wrap: wrap; }
  .btnrow button { min-height: 44px; }
}
@media (max-width: 860px) {
  body.tutorial-active #lessonPanel { max-height: calc(100dvh - 415px); }
  #coachTitle { font-size: 17px; }
  #coachAction, #coachRecovery { font-size: 12px; }
  #guidanceToggle { min-height: 36px; }
  #replayIntroBtn { font-size: 13px; }
  #rail .track-switch { min-height: 44px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

@media (max-width: 860px) and (max-height: 500px) {
  body.tutorial-active #lessonPanel { top: 70px; right: auto; width: min(340px, 48vw); max-height: calc(100dvh - 175px); }
  #rosePanel { width: 180px; }
  #windRose { width: 154px; height: 154px; }
  #trimWrap { left: auto; width: min(280px, 42vw); }
}

/* The instruction surface shares the theory card's cool paper palette. */
#lessonPanel {
  background: rgba(247, 249, 252, .72); color: #103660;
  border-color: #d6dfe9;
}
#lessonTitle, #coachTitle { color: #103660; }
.environment-info, #coachCount { color: #38627e; }
#guidanceToggle { color: #315b78; border-bottom-color: #7895aa; }
#coachGoal { color: #25634e; }
.coach-instruction { background: rgba(218, 231, 241, .8); }
.coach-instruction strong { color: #315b78; }
#coachSail { color: #103660; }
.coach-steps li { color: #526c80; border-color: #9fb4c4; }
.coach-steps li.done { background: #d5eadf; color: #245d48; border-color: #7fae96; }
#coachAdvance { background: #d9eee4; color: #245d48; border-left-color: #438369; }
#coachProgress { accent-color: #267653; }
#coachProgressText, .markinfo { color: #246347; }
#coachRecovery { color: #885010; }
#coachFeedback { font-variant-numeric: tabular-nums; }
.coach-instruction #coachFeedback { margin-top: 8px; }
.coach-instruction #coachProgress { margin-top: 8px; }
#coachProgress[hidden] { display: none; }
body.exam-mode #lessonTitle { color: #805015; }
body.exam-mode #lessonPanel { border-color: #b88b4c; }
body.exam-mode .exampill { color: #805015; border-color: #b88b4c; }


/* Navigation drawer on every screen size. */
/* ---- Menu button + slide-in drawer ---- */
#menuBtn {
  display: flex; align-items: center; justify-content: center;
  position: fixed; top: 10px; left: 10px; z-index: 9;
  width: 44px; height: 44px; border-radius: 12px;
  background: rgba(7, 21, 33, 0.82); color: #eaf3fa;
  border: 1px solid rgba(140, 190, 230, 0.3);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  font-size: 20px; line-height: 1; cursor: pointer;
}

#menuBackdrop {
  display: block; position: fixed; inset: 0; z-index: 9;
  background: rgba(2, 8, 14, 0.5);
  opacity: 0; pointer-events: none; transition: opacity 0.26s;
}
body.menu-open #menuBackdrop { opacity: 1; pointer-events: auto; }

/* Navigation slides in beside the hamburger button on the left. */
#rail {
  position: fixed; display: flex; flex-direction: column;
  top: 0; right: auto; bottom: 0; left: 0;
  width: min(320px, 84vw); height: 100dvh; max-height: 100dvh;
  padding: 62px 16px 20px; gap: 10px; z-index: 10;
  align-items: stretch; overflow-y: auto;
  background: rgba(7, 21, 33, 0.95);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-right: 1px solid rgba(140, 190, 230, 0.22);
  box-shadow: 12px 0 40px rgba(0, 6, 12, 0.45);
  transform: translateX(-100%); transition: transform 0.28s ease;
}
body.menu-open #rail { transform: translateX(0); }
#rail .pickhead { text-align: left; padding: 0 0 2px 2px; font-size: 10px; }
#rail .picker { grid-template-columns: repeat(3, 1fr); }
#rail .picker button, #rail .railbtn { min-height: 46px; font-size: 13px; }
#rail .railbtn { text-align: center; }
#autoTrimBtn { font-size: 11px; }


#menuBtn { z-index: 11; }
#rail .track-switch { min-height: 44px; }
#quickControls {
  position: fixed; right: 14px; top: 300px; z-index: 4;
  display: flex; flex-direction: column; align-items: stretch; gap: 8px;
}
@media (min-width: 861px) { #lessonPanel { top: 70px; } }
@media (max-width: 860px) {
  #quickControls { left: 10px; right: auto; top: 66px; gap: 5px; }
  #quickControls .railbtn { min-height: 40px; }
}
@media (max-width: 860px) and (max-height: 500px) {
  #quickControls { top: 10px; left: 145px; flex-direction: row; }
}
