/*
 * Captain's Bridge: one-screen lesson layout.
 * Large desktop/tablet-landscape viewports receive a fitted canvas and complete
 * control column without a page scroll. Small/short windows scroll naturally.
 * The canvas never stretches; its coordinate system is unchanged.
 */
:root { --bridge-gap: 9px; }
body { overflow-x: hidden; }
.shell { max-width: 1600px; padding: 10px 12px 16px; }
header { min-height: 60px; padding: 8px 15px; gap: 10px; border-radius: 18px; }
header h1 { font-size: clamp(1.35rem, 1.9vw, 1.95rem); line-height: 1.05; }
header p { font-size: .77rem; margin: 2px 0 0; }
header .bar { gap: 6px; flex-wrap: nowrap; }
header .bar button { padding: 7px 10px; min-height: 37px; font-size: .8rem; white-space: nowrap; flex: initial; }
.layout { gap: 11px; margin-top: 9px; grid-template-columns: minmax(0, 1fr) 302px; }
.seaWrap { min-width: 0; }
.sea { border-width: 5px; border-radius: 20px; }
canvas { width: 100%; height: auto; aspect-ratio: 1000/650; }
.seafooter { padding: 6px 3px 0; gap: 8px; align-items: center; }
.compass { padding: 3px 8px 3px 4px; gap: 7px; border-radius: 12px; box-shadow: 0 3px 0 #c9dfe2; }
.compass svg { width: 43px; height: 43px; }
.compass span { font-size: .77rem; }
.seafooter .small { font-size: .74rem; line-height: 1.3; }
.stack { gap: 8px; min-width: 0; }
.stack .panel { padding: 10px 11px; border-radius: 16px; box-shadow: 0 4px 0 #c4dee4,0 7px 15px #11506f0c; }
.stack h2 { font-size: 1.02rem; line-height: 1.1; margin: 0 0 8px; }
.panelHeading { display: flex; gap: 8px; align-items: baseline; justify-content: space-between; }
.panelHeading .micro { color: #58859a; font-weight: 750; font-size: .69rem; }
.stats { gap: 6px; margin-bottom: 7px; }
.stat { padding: 6px 3px 4px; font-size: .7rem; line-height: 1.1; border-radius: 11px; }
.stat strong { font-size: 1.23rem; line-height: 1.22; }
.statusStrip { padding: 6px; border-radius: 10px; gap: 2px 5px; font-size: .72rem; }
.statusStrip strong { font-size: .84rem; }
.log { padding: 8px 10px; min-height: 58px; max-height: 118px; overflow-y: auto; overscroll-behavior: contain; font-size: .79rem; line-height: 1.37; border-radius: 11px; margin-top: 8px; }
.ordersPanel .bar { margin-bottom: 7px; flex-wrap: nowrap; }
.ordersPanel .bar button, .toolPanel .bar button { padding: 7px 6px; min-height: 39px; font-size: .82rem; }
.ordersPanel .bar button { color: #155978; }
.ordersPanel .fields { gap: 7px; }
.ordersPanel .fields label { font-size: .78rem; gap: 3px; }
.ordersPanel .fields input { font-size: 1.09rem; padding: 7px 9px; min-height: 39px; border-radius: 10px; }
.ordersPanel .fields input::placeholder { color: #8ba7b0; font-size: .9rem; }
.ordersPanel p { margin: 0; }
#modeInfo { color: #597c89; line-height: 1.25; font-size: .72rem; min-height: 17px; margin: 0 0 8px; }
#bearingTip { margin: 6px 0; font-size: .7rem; color: #637e8e; line-height: 1.24; }
#actionBtn { min-height: 45px; padding: 7px 12px; font-size: .96rem; border-radius: 11px; }
.toolPanel .bar { gap: 7px; flex-wrap: nowrap; }
.toolHint { margin: 7px 0 0 !important; line-height: 1.3; font-size: .74rem !important; color: #628090; }
.toolHint strong { color: #165b77; }
.toolPanel h2 { margin-bottom: 7px; }
.phaseRibbon { padding: 5px 10px; font-size: .77rem; right: 8px; top: 8px; }
.waveNotice { padding: 10px 14px; }
.gameover { z-index: 5; }
body:has(dialog[open]) { overflow: hidden; }
dialog { max-height: min(90dvh, 820px); overflow: auto; }
:where(button,input):focus-visible { outline: 3px solid #e69b37; outline-offset: 2px; }

/* Desktop: board and every important control fitted to the available viewport. */
@media (min-width: 960px) and (min-height: 600px) {
  html, body { min-height: 100%; }
  .shell {
    height: 100vh; height: 100dvh; max-height: 100dvh;
    display: flex; flex-direction: column; overflow: hidden;
    padding-top: 8px; padding-bottom: 8px;
  }
  header { flex: 0 0 auto; }
  .layout {
    flex: 1 1 auto; min-height: 0; overflow: hidden;
    margin-top: 9px; grid-template-columns: minmax(0, 1fr) 302px;
  }
  .seaWrap {
    min-height: 0; height: 100%;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center; gap: 6px;
  }
  .sea {
    flex: 0 0 auto; max-width: 100%;
    width: 100%; /* precisely fitted by single-screen.js */
  }
  .seafooter {
    flex: 0 0 49px; height: 49px; width: 100%;
    padding: 0 4px; margin: 0;
    justify-content: space-between;
  }
  .stack {
    min-height: 0; height: 100%;
    display: flex; flex-direction: column; justify-content: space-between; overflow: hidden;
  }
  .stack .panel { flex: 0 0 auto; }
  .stack .missionPanel {
    flex: 0 0 auto; min-height: 0;
    display: flex; flex-direction: column;
  }
  .missionPanel .log {
    flex: 0 0 auto; min-height: 60px; max-height: 100px;
  }
}
@media (min-width: 960px) and (max-height: 760px) {
  .shell { padding: 7px 10px; }
  header { min-height: 50px; padding: 5px 12px; }
  header p { display: none; }
  .layout { margin-top: 6px; gap: 8px; }
  .stack { gap: 6px; }
  .stack .panel { padding: 8px 10px; }
  .stack h2 { margin-bottom: 5px; font-size: .98rem; }
  .stats { margin-bottom: 5px; }
  .stat { padding: 4px 2px 3px; }
  .stat strong { font-size: 1.14rem; }
  .statusStrip { padding: 4px 6px; }
  .ordersPanel .bar { margin-bottom: 5px; }
  .ordersPanel .bar button, .toolPanel .bar button { min-height: 35px; padding: 5px 6px; }
  .ordersPanel .fields input { min-height: 36px; padding: 6px 8px; }
  #modeInfo { margin-bottom: 5px; font-size: .68rem; }
  #bearingTip { margin: 4px 0; }
  #actionBtn { min-height: 40px; }
  .toolHint { margin-top: 5px !important; }
  .seafooter { flex-basis: 43px; height: 43px; }
  .compass svg { width: 36px; height: 36px; }
}
@media (min-width: 960px) and (max-height: 665px) {
  .shell { padding: 5px 9px; }
  header { min-height: 43px; }
  header h1 { font-size: 1.26rem; }
  header .bar button { min-height: 33px; padding: 5px 7px; }
  #modeInfo { display: none; }
  .seafooter .small { font-size: .69rem; }
  .stat strong { font-size: 1.04rem; }
  .panelHeading .micro { display: none; }
}
/* Portrait tablets and narrow windows: keep the vital controls visible, but never
   hide or clip them merely to force a one-screen layout. */
@media (max-width: 959px) {
  .shell { max-width: 100%; padding: 8px; }
  header { padding: 8px 12px; }
  header h1 { font-size: 1.44rem; }
  header p { display: none; }
  .layout { grid-template-columns: 1fr; gap: 9px; margin-top: 9px; }
  .seaWrap { display: block; width: 100%; }
  .sea { width: 100%; max-width: 100%; }
  .seafooter { justify-content: space-between; }
  .stack { display: grid; grid-template-columns: minmax(0,1fr) minmax(0,1fr); gap: 8px; }
  .stack .missionPanel { grid-column: 1 / -1; }
  .stack > .panel.toolPanel:last-child { grid-column: auto; }
  .stack .ordersPanel { grid-column: auto; }
  .missionPanel .log { min-height: 40px; max-height: 85px; }
}
@media (max-width: 620px) {
  header { gap: 7px; flex-wrap: wrap; }
  header h1 { font-size: 1.35rem; }
  header .bar { flex: 1 1 100%; gap: 5px; }
  header .bar button { flex: 1; min-width: 0; padding: 5px 5px; font-size: .77rem; }
  .stack { display: grid; grid-template-columns: 1fr; }
  .stack .missionPanel, .stack .ordersPanel, .stack .toolPanel { grid-column: 1; }
  .stack .panel { padding: 9px 11px; }
  .stats { margin-bottom: 5px; }
  .stat { padding: 5px 3px 3px; }
  .missionPanel .log { min-height: 38px; max-height: 75px; }
  .seafooter { gap: 5px; padding: 5px 2px; }
  .seafooter .small { max-width: 55%; text-align: right; font-size: .67rem; }
  .compass { gap: 4px; }
  .compass svg { width: 38px; height: 38px; }
  .compass span { font-size: .69rem; }
}
@media (max-width: 400px) {
  .seafooter .small { max-width: 55%; }
  .compass span { font-size: .64rem; }
  .statusStrip { font-size: .69rem; }
  .statusStrip strong { font-size: .78rem; }
}
@media (prefers-reduced-motion: reduce) { .log { scroll-behavior: auto; } }
