/* v2: the real game embedded, with a site-drawn HUD and a chart plotter. */

/* Hero phone: a rudder bar instead of answer buttons */
.ui-rudder {
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: 24px;
  height: 52px;
  border-radius: 16px;
  background: rgba(251, 250, 246, 0.9);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 14px;
}
.ui-rudder .r-end {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}
.ui-rudder .r-end.port {
  background: var(--port);
}
.ui-rudder .r-end.stbd {
  background: var(--stbd);
}
.ui-rudder .r-track {
  flex: 1;
  height: 4px;
  border-radius: 4px;
  background: var(--hair-2);
  position: relative;
}
.ui-rudder .r-fill {
  position: absolute;
  left: 50%;
  width: 26%;
  top: 0;
  bottom: 0;
  background: var(--stbd);
  border-radius: 4px;
}
.ui-rudder .r-knob {
  position: absolute;
  left: 76%;
  top: 50%;
  width: 22px;
  height: 22px;
  translate: -50% -50%;
  border-radius: 50%;
  background: var(--ink);
  box-shadow: 0 0 0 4px rgba(251, 250, 246, 0.9);
}

/* ---------- Play layout ---------- */

.play {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(320px, 0.75fr);
  gap: clamp(20px, 3vw, 36px);
  align-items: start;
}

.stage {
  position: relative;
  height: clamp(520px, 72vh, 720px);
  border-radius: var(--r-lg);
  overflow: hidden;
  background: #2f74ad;
  box-shadow: var(--shadow-lg);
  isolation: isolate;
}
.stage iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
  opacity: 0;
  transition: opacity 0.6s var(--ease);
}
.stage[data-state="playing"] iframe,
.stage[data-state="ended"] iframe {
  opacity: 1;
}
.stage-poster {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 20% 10%;
  transition: opacity 0.6s;
}
.stage::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(12, 34, 48, 0.1), rgba(12, 34, 48, 0.72));
  pointer-events: none;
  transition: opacity 0.6s;
  z-index: 1;
}
.stage:not([data-state="poster"])::after,
.stage:not([data-state="poster"]) .stage-poster {
  opacity: 0;
}

.stage-start,
.stage-end {
  position: absolute;
  inset: auto 0 0 0;
  z-index: 3;
  padding: clamp(24px, 4vw, 44px);
  color: var(--paper);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 16px;
}
.stage-start .h2 em,
.stage-end .h2 em {
  color: var(--mark);
}
.stage-k {
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(244, 240, 230, 0.75);
}
.boat-pick {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.btn.ghost-light {
  --bg: rgba(244, 240, 230, 0.12);
  --fg: var(--paper);
  border-color: rgba(244, 240, 230, 0.4);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.stage-note {
  font-size: 13.5px;
  color: rgba(244, 240, 230, 0.7);
}
.stage:not([data-state="poster"]) .stage-start {
  display: none;
}

/* No WebGPU: say so, and demote the boats to a "try anyway" path. */
.stage .gpu-no {
  display: none;
}
.stage[data-gpu="no"] .gpu-no {
  display: block;
}
.stage[data-gpu="no"] .gpu-yes {
  display: none;
}
.stage[data-gpu="no"] .stage-start {
  gap: 12px;
}
.stage[data-gpu="no"] .stage-note.gpu-no {
  max-width: 52ch;
  font-size: 14.5px;
  line-height: 1.5;
  color: rgba(244, 240, 230, 0.85);
}
.stage[data-gpu="no"] .boat-pick .btn.light {
  --bg: rgba(244, 240, 230, 0.12);
  --fg: var(--paper);
  border-color: rgba(244, 240, 230, 0.4);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.stage-loading {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: none;
  place-items: center;
  align-content: center;
  gap: 14px;
  color: var(--paper);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.stage[data-state="loading"] .stage-loading {
  display: grid;
}
.spinner {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 2px solid rgba(244, 240, 230, 0.25);
  border-top-color: var(--paper);
  animation: spin 0.9s linear infinite;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.stage-end {
  display: none;
  inset: 0;
  justify-content: flex-end;
  background: linear-gradient(180deg, transparent 30%, rgba(12, 34, 48, 0.8));
}
.stage[data-state="ended"] .stage-end {
  display: flex;
}

/* HUD */
.hud {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  display: none;
}
.stage[data-state="playing"] .hud {
  display: block;
}
.hud-top {
  position: absolute;
  top: 14px;
  left: 14px;
  right: 14px;
  display: flex;
  justify-content: space-between;
  gap: 8px;
}
.hud-pills {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.hud .ui-pill {
  height: 30px;
  font-size: 11.5px;
  padding: 0 12px;
}
.hud .ui-pill b {
  font-weight: 500;
}
.hud-btn {
  border: 0;
  cursor: pointer;
  pointer-events: auto;
}
.hud-btn:hover {
  background: var(--card);
}
.hud-icon {
  width: 30px;
  padding: 0 !important;
  display: grid;
  place-items: center;
}
.hud-icon svg {
  fill: var(--ink);
}
.stage.paused #hud-pause svg {
  display: none;
}
.stage.paused #hud-pause::before {
  content: "";
  margin-left: 2px;
  border-left: 9px solid var(--ink);
  border-top: 6px solid transparent;
  border-bottom: 6px solid transparent;
}

/* Paused */
.stage-paused {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: none;
  place-items: center;
  padding: 20px;
  background: rgba(12, 34, 48, 0.42);
  backdrop-filter: blur(3px) saturate(0.7);
  -webkit-backdrop-filter: blur(3px) saturate(0.7);
  animation: fade 0.25s var(--ease);
}
.stage.paused .stage-paused {
  display: grid;
}
.stage.paused .coach,
.stage.paused .helmbar {
  opacity: 0;
}
.pause-card {
  width: min(340px, 100%);
  padding: 20px 22px;
  border-radius: var(--r-lg);
  background: rgba(251, 250, 246, 0.96);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.pause-card .ui-q {
  font-size: 24px;
}
.pause-actions {
  display: flex;
  gap: 8px;
  margin: 8px 0 4px;
}
@keyframes fade {
  from {
    opacity: 0;
  }
}

.mk {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--mark);
  box-shadow: 0 0 0 1.5px var(--ink);
}

.coach {
  position: absolute;
  top: 56px;
  left: 14px;
  max-width: min(360px, calc(100% - 28px));
  padding: 14px 16px;
  border-radius: 18px;
  background: rgba(251, 250, 246, 0.92);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: opacity 0.3s, transform 0.3s var(--ease);
}
.coach.hide {
  opacity: 0;
  transform: translateY(-6px);
}
.coach.threat .ui-eyebrow {
  color: var(--port);
}
.coach-hint {
  font-size: 13px;
  color: var(--ink-2);
  margin-top: 2px;
}
.coach-hint kbd {
  font-family: var(--mono);
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 5px;
  border: 1px solid var(--hair-2);
  background: var(--card);
}

/* Helm bar */
.helmbar {
  position: absolute;
  left: 50%;
  bottom: 18px;
  translate: -50% 0;
  width: min(440px, calc(100% - 28px));
  height: 58px;
  padding: 0 16px;
  border-radius: 999px;
  background: rgba(251, 250, 246, 0.92);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  display: flex;
  align-items: center;
  gap: 14px;
  pointer-events: auto;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.hb-end {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.06em;
  color: var(--ink-2);
}
.hb-end i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}
.hb-end.port i {
  background: var(--port);
}
.hb-end.stbd i {
  background: var(--stbd);
}
.hb-track {
  flex: 1;
  height: 100%;
  position: relative;
  cursor: grab;
  outline: none;
}
.hb-track:active {
  cursor: grabbing;
}
.hb-track::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 4px;
  translate: 0 -50%;
  border-radius: 4px;
  background: var(--hair-2);
}
.hb-center {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 2px;
  height: 14px;
  translate: -50% -50%;
  background: var(--ink-3);
  border-radius: 2px;
}
.hb-fill {
  position: absolute;
  top: 50%;
  height: 4px;
  translate: 0 -50%;
  border-radius: 4px;
  left: 50%;
  width: 0;
}
.hb-knob {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 28px;
  height: 28px;
  translate: -50% -50%;
  border-radius: 50%;
  background: var(--ink);
  box-shadow: 0 0 0 5px rgba(251, 250, 246, 0.92), 0 6px 14px -4px rgba(12, 34, 48, 0.5);
  transition: left 0.12s var(--ease);
}
.hb-track.dragging .hb-knob {
  transition: none;
}
.hb-track:focus-visible .hb-knob {
  outline: 3px solid var(--mark);
  outline-offset: 4px;
}

/* ---------- Side: plotter + debrief ---------- */

.side {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.plot-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.plot-scale {
  font-size: 12px;
}
.plot .inner {
  background: var(--card);
}
#plot {
  width: 100%;
  height: auto;
  aspect-ratio: 1;
}
.verdict {
  box-shadow: var(--shadow);
}
.verdict .criteria {
  margin-top: 10px;
}
.verdict .criteria:empty {
  display: none;
}
.verdict .criteria li {
  font-size: 14px;
  padding: 9px 0;
}
.verdict.fresh {
  animation: rise 0.5s var(--ease);
}

/* Plot SVG */
#plot .sea {
  fill: var(--card);
}
#plot .grid {
  stroke: var(--ink);
  stroke-width: 0.5;
  opacity: 0.12;
}
#plot .sounding {
  font-family: var(--serif);
  font-style: italic;
  font-size: 13px;
  fill: var(--ink-2);
  opacity: 0.6;
}
#plot .label {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.06em;
  fill: var(--ink-2);
  text-transform: uppercase;
}
#plot .rose {
  fill: none;
  stroke: var(--ink);
  stroke-width: 0.8;
  opacity: 0.55;
}
#plot .rose-n {
  fill: var(--ink);
  opacity: 0.7;
}
#plot .track {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}
#plot .track.you {
  stroke: var(--ink);
  stroke-width: 2;
  stroke-dasharray: 5 4;
}
#plot .track.other {
  stroke: var(--sea);
  stroke-width: 2.4;
  stroke-dasharray: 1 5;
}
#plot .track.old {
  opacity: 0.35;
}
#plot .mark-ring {
  fill: none;
  stroke: var(--ink);
  stroke-width: 1;
  stroke-dasharray: 2 3;
  opacity: 0.6;
}
#plot .mark {
  fill: var(--mark);
  stroke: var(--ink);
  stroke-width: 1.4;
}
#plot .risk {
  fill: none;
  stroke: var(--port);
  stroke-width: 1.4;
  stroke-dasharray: 3 3;
  transform-box: fill-box;
  transform-origin: center;
  animation: pulse 1.6s ease-in-out infinite;
}
#plot .cpa-line {
  stroke: var(--port);
  stroke-width: 1.2;
}
#plot .cpa-line.ok {
  stroke: var(--stbd);
}
#plot .cpa-bg {
  fill: var(--card);
  stroke: var(--hair-2);
}
#plot .cpa-text {
  font-family: var(--mono);
  font-size: 11px;
  fill: var(--ink);
}
#plot .boat-you {
  fill: var(--ink);
}
#plot .boat-other {
  fill: var(--card);
  stroke: var(--ink);
  stroke-width: 1.6;
}
#plot .heading-line {
  stroke: var(--ink);
  stroke-width: 1;
  stroke-dasharray: 3 4;
  opacity: 0.45;
}
#plot .wind {
  fill: var(--sea);
  opacity: 0.8;
}

@media (max-width: 1020px) {
  .play {
    grid-template-columns: 1fr;
  }
  .side {
    display: grid;
    grid-template-columns: 1fr 1fr;
    align-items: start;
  }
  .plot-head {
    grid-column: 1 / -1;
  }
}
@media (max-width: 680px) {
  .stage {
    height: min(78vh, 640px);
    margin: 0 calc(var(--gutter) * -1);
    border-radius: 0;
  }
  .side {
    grid-template-columns: 1fr;
  }
  .coach {
    top: 52px;
  }
  .coach .ui-q {
    font-size: 17px;
  }
  .hud-top .ui-pill {
    padding: 0 9px;
  }
  .hud-pills {
    flex-wrap: nowrap;
  }
  #hud-count {
    display: none;
  }
}
