html, body { margin: 0; background: #fff; }
.tug-game, .tug-game *, .tug-game *::before, .tug-game *::after { box-sizing: border-box; }
.tug-game {
    --mia-blue: #009cdd;
    width: 100%; max-width: 960px; margin: 0 auto;
    color: #000; background: #fff; border: 2px solid #000;
    font: 12px/1.45 Manrope, 'Avenir Next', 'Segoe UI', sans-serif;
}
.tug-game h2, .tug-game p { margin: 0; }
.tug-game h2 { font: 700 11px/1.4 Sora, 'Avenir Next', sans-serif; }
.tug-game button {
    border: 1px solid #000; border-radius: 4px; color: #000; background: #fff;
    font: 700 11px/1.2 Manrope, sans-serif; padding: 7px 10px; cursor: pointer;
}
.tug-game button:hover, .tug-game button[aria-pressed="true"], .tug-game .tug-primary { background: var(--mia-blue); }
.tug-game button:disabled { opacity: .5; cursor: default; }
.tug-game :focus-visible { outline: 3px solid #000; outline-offset: 3px; }
.tug-game [hidden] { display: none !important; }
.tug-toolbar, .tug-toolbar-actions, .tug-panel-heading, .tug-slider-label, .tug-challenge-summary, .tug-challenge-status {
    display: flex; justify-content: space-between; align-items: center; gap: 8px;
}
.tug-toolbar { min-height: 48px; padding: 8px 12px; border-bottom: 2px solid #000; }
.tug-toolbar > strong { font: 700 12px Sora, sans-serif; white-space: nowrap; }
.tug-toolbar > strong span { font: 600 10px Manrope, sans-serif; margin-left: 8px; letter-spacing: .06em; }
.tug-toolbar-actions { justify-content: flex-end; }
.tug-game-area { position: relative; container-type: inline-size; }
#gameCanvas { display: block; width: 100%; aspect-ratio: 4 / 3; background: var(--mia-blue); }
#gameCanvas:focus-visible { outline: 3px solid #fff; outline-offset: -6px; }
.tug-mobile-hud-panel { display: contents; }
.tug-ship-control, .tug-hud { position: absolute; top: 12px; padding: 10px; border: 2px solid #000; border-radius: 4px; background: #fff; }
.tug-ship-control { left: 12px; width: clamp(150px, 20.5cqw, 194px); }
.tug-hud { right: 12px; width: clamp(150px, 20.5cqw, 194px); }
@container (max-width: 820px) {
    .tug-ship-control, .tug-hud { top: 8px; padding: 8px; font-size: 11px; }
    .tug-ship-control { left: 8px; } .tug-hud { right: 8px; }
    .tug-bp-display { font-size: 20px !important; }
    .tug-response-grid { gap: 5px !important; margin-top: 6px !important; }
}
.tug-panel-heading { margin-bottom: 8px; }
.tug-panel-heading button { padding: 5px 8px; }
.tug-slider-label { margin: 9px 0 5px; font-size: 10px; }
.tug-slider-label strong { font-size: 10px; }
#shipSpeedSlider { accent-color: var(--mia-blue); width: 100%; margin: 0; min-height: 22px; }
.tug-toggle-row { display: flex; gap: 5px; }
.tug-toggle-row button { flex: 1; }
.tug-force-type { display: inline-block; padding: 3px 6px; margin-bottom: 8px; background: #000; color: #fff; font-size: 9px; font-weight: 700; }
.tug-hud h2 { font: 400 9px Manrope, sans-serif; text-transform: uppercase; }
.tug-bp-display { display: block; font: 700 25px/1.5 Sora, sans-serif; }
.tug-bar { height: 5px; overflow: hidden; background: #dedede; }
.tug-bar > div { height: 100%; width: 0; background: var(--mia-blue); }
.tug-response-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.tug-response-grid span { display: block; font-size: 9px; }
.tug-response-grid strong { display: block; font: 700 13px/1.5 Sora, sans-serif; font-variant-numeric: tabular-nums; }
.tug-challenge { padding: 12px 14px; border-top: 2px solid #000; }
.tug-challenge-summary > div { flex: 1; }
.tug-challenge-summary p { font-size: 11px; margin-top: 3px; }
.tug-challenge-status { margin: 10px 0 4px; font-size: 11px; font-variant-numeric: tabular-nums; }
#challengeInstruction { margin-bottom: 9px; }
.tug-controls { padding: 10px 14px; border-top: 1px solid #000; }
.tug-controls .tug-panel-heading { margin-bottom: 0; }
#desktopControlDiagram { margin-top: 8px; }
#playInstructions { font-size: 11px; }
#playInstructions span { margin: 0 8px; }
.tug-explanation { margin-top: 8px !important; }
.tug-model-note { margin-top: 5px !important; font-size: 10px; color: #444; }
.tug-touch-controls, #mobileHudToggle, .tug-touch-help { display: none; }
.tug-pause-overlay { position: absolute; inset: 0; z-index: 5; background: rgb(255 255 255 / .86); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; }
.tug-pause-overlay strong { font: 700 22px Sora, sans-serif; }
/* v1 dialog styles retained for reference */
#towModeModal { top: 24px; bottom: auto; margin: 0 auto; max-height: calc(100dvh - 48px); width: min(420px, calc(100% - 32px)); padding: 26px; border: 2px solid #000; border-radius: 4px; font: inherit; color: #000; background: #fff; }
#towModeModal::backdrop { background: rgb(255 255 255 / .88); }
#towModeModal h2 { font-size: 21px; margin-bottom: 12px; }
#towModeModal p { margin-bottom: 18px; }
#towModeModal .tug-primary { width: 100%; min-height: 44px; }
#towModeModal .tug-modal-label { margin: 18px 0 10px; font-size: 11px; }
#towModeModal .tug-toggle-row button { padding: 12px 6px; }
#towModeModal button span { display: block; margin-top: 5px; font-size: 10px; font-weight: 400; }
.tug-sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px !important; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.tug-game:fullscreen { width: 100%; height: 100%; max-width: none; overflow: auto; }
.tug-game:fullscreen .tug-game-area { max-width: min(960px, calc((100dvh - 180px) * 4 / 3)); margin: auto; }
@media (max-width: 640px), (pointer: coarse) {
    .tug-touch-controls { position: absolute; bottom: 10px; left: 10px; right: 10px; display: flex; justify-content: space-between; align-items: flex-end; pointer-events: none; }
    .tug-touch-joystick-area, .tug-touch-rotate-area { display: flex; flex-direction: column; align-items: center; gap: 3px; }
    .tug-touch-controls span { font-size: 9px; font-weight: 700; text-transform: uppercase; background: #fff; padding: 1px 4px; }
    .tug-touch-joystick-base { width: 84px; height: 84px; border: 2px solid #000; border-radius: 50%; background: rgb(255 255 255 / .8); position: relative; pointer-events: auto; touch-action: none; user-select: none; }
    #joystickKnob { position: absolute; left: 50%; top: 50%; width: 32px; height: 32px; border-radius: 50%; transform: translate(-50%, -50%); border: 2px solid #000; background: var(--mia-blue); pointer-events: none; }
    .tug-touch-rotate-area > div { display: flex; gap: 7px; }
    .tug-touch-rotate-area button { width: 48px; height: 48px; font-size: 26px; background: rgb(255 255 255 / .85); border: 2px solid #000; pointer-events: auto; touch-action: none; user-select: none; }
    .tug-touch-rotate-area button.is-active { background: var(--mia-blue); }
    .tug-touch-help { display: block; }
}
@media (max-width: 640px), (pointer: coarse) and (max-height: 500px) {
    .tug-toolbar { padding: 6px 8px; gap: 5px; }
    .tug-toolbar > strong span { display: none; }
    .tug-toolbar-actions { gap: 5px; }
    .tug-toolbar-actions button { font-size: 10px; padding: 8px 6px; min-height: 36px; }
    #mobileHudToggle { display: inline-block; }
    .tug-game-area { display: grid; grid-template-columns: minmax(0, 1fr); }
    #gameCanvas { grid-area: 1 / 1; }
    .tug-mobile-hud-panel { display: none; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); border-top: 2px solid #000; }
    .tug-game.is-mobile-hud-open .tug-mobile-hud-panel { display: grid; }
    .tug-ship-control, .tug-hud { position: static; width: auto; min-width: 0; border: 0; border-radius: 0; padding: 8px; }
    .tug-ship-control { border-right: 1px solid #000; }
    .tug-hud h2 { font-size: 8px; }
    .tug-hud .tug-bp-display { font-size: 20px; }
    .tug-response-grid { gap: 5px; }
    .tug-response-grid span { font-size: 8px; }
    .tug-response-grid strong { font-size: 11px; }
    .tug-panel-heading { flex-wrap: wrap; }
    .tug-touch-controls { position: relative; grid-area: 1 / 1; bottom: auto; left: auto; right: auto; align-self: end; margin: 0 9px 9px; }
    .tug-pause-overlay { grid-area: 1 / 1; position: relative; }
    .tug-challenge { padding: 9px 10px; }
    .tug-challenge-summary { flex-wrap: wrap; }
    .tug-challenge-summary p { font-size: 10px; }
    .tug-challenge-status, #challengeInstruction { font-size: 10px; }
    .tug-controls { padding: 9px 10px; }
    #playInstructions { display: none; }
    .tug-explanation { font-size: 11px; }
    .tug-model-note { font-size: 9px; }
}
@media (prefers-reduced-motion: reduce) {
    .tug-game *, .tug-game *::before, .tug-game *::after { scroll-behavior: auto; transition: none; animation: none; }
}

/* v2: in bow spring the tug works in the upper half, so the panels move to the bottom corners */
.tug-game.is-bow .tug-ship-control, .tug-game.is-bow .tug-hud { top: auto; bottom: 12px; }
/* v2: force split bar, start and completion cards */
.tug-split { display: flex; height: 10px; border: 1px solid #000; background: #dedede; }
.tug-split > div { height: 100%; width: 0; }
#splitBrake { background: #000; }
#splitSteer { background: var(--mia-blue); }
#splitTow { background: repeating-linear-gradient(45deg, #000 0 3px, #fff 3px 6px); }
.tug-split-legend { display: flex; justify-content: space-between; gap: 6px; margin-top: 4px; font-size: 9px; font-variant-numeric: tabular-nums; }
.tug-split-legend span { display: flex; align-items: center; gap: 4px; white-space: nowrap; }
.tug-split-legend i { display: inline-block; width: 8px; height: 8px; border: 1px solid #000; }
.tug-split-legend i.is-brake { background: #000; }
.tug-split-legend i.is-steer { background: var(--mia-blue); }
.tug-overlay { position: absolute; inset: 0; z-index: 6; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgb(255 255 255 / .72); }
.tug-card { width: min(520px, 100%); max-height: 100%; overflow: auto; padding: 22px; border: 2px solid #000; border-radius: 4px; background: #fff; }
.tug-card h2 { font: 700 20px/1.25 Sora, sans-serif; margin-bottom: 10px; }
.tug-card h3 { font: 700 13px/1.3 Sora, sans-serif; margin: 0 0 4px; }
.tug-card p { margin-bottom: 10px; }
.tug-card .tug-card-small { font-size: 11px; color: #222; }
.tug-card-choices { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
.tug-card-choices > div { display: flex; flex-direction: column; gap: 6px; padding: 12px; border: 1px solid #000; border-radius: 4px; }
.tug-card-choices p { font-size: 11px; margin-bottom: 4px; flex: 1; }
.tug-card-choices button { width: 100%; min-height: 40px; }
.tug-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 12px 0; }
.tug-stats div { padding: 8px; border: 1px solid #000; border-radius: 4px; }
.tug-stats dt { font-size: 9px; text-transform: uppercase; }
.tug-stats dd { margin: 2px 0 0; font: 700 15px/1.3 Sora, sans-serif; font-variant-numeric: tabular-nums; }
.tug-card-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.tug-card-actions button { flex: 1; min-height: 40px; }
.tug-card-links { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px; margin-top: 14px; padding-top: 12px; border-top: 1px solid #000; }
.tug-card-links a { color: #000; font-weight: 700; text-decoration: underline; text-decoration-color: var(--mia-blue); text-decoration-thickness: 3px; text-underline-offset: 3px; }
.tug-card-links a:hover { background: var(--mia-blue); }
@media (max-width: 640px) {
    .tug-overlay { grid-area: 1 / 1; position: relative; padding: 8px; }
    .tug-card { padding: 14px; }
    .tug-card h2 { font-size: 16px; }
    .tug-card p { font-size: 11px; }
    .tug-card-choices { gap: 6px; }
    .tug-card-choices > div { padding: 8px; }
    .tug-stats { grid-template-columns: repeat(2, 1fr); gap: 5px; margin: 8px 0; }
}

/* Mobile, embedded: only the playfield and a full screen button, like the swing demo */
.tug-gate { display: none; }
.tug-game.is-gated > :not(.tug-game-area), .tug-game.is-gated .tug-game-area > :not(#gameCanvas, .tug-gate) { display: none !important; }
.tug-game.is-gated .tug-gate {
    display: block; position: absolute; left: 12px; right: 12px; bottom: 12px; z-index: 8;
    min-height: 48px; padding: 10px 12px; font-size: 14px; border: 2px solid #000;
}

/* Mobile, full screen (or the standalone page on a phone): the playfield gets the screen, the controls shrink */
.tug-game.is-full { height: 100dvh; max-width: none; border: 0; overflow: hidden; }
.tug-game.is-full .tug-game-area { max-width: none; margin: 0; }
.tug-game.is-full .tug-controls, .tug-game.is-full .tug-toolbar > strong { display: none; }
.tug-game.is-full .tug-toolbar { min-height: 0; padding: 6px 8px; border-bottom: 0; }
.tug-game.is-full .tug-toolbar-actions { flex-wrap: wrap; justify-content: flex-start; gap: 5px; }
.tug-game.is-full .tug-toolbar-actions button { font-size: 10px; padding: 6px; min-height: 32px; }
.tug-game.is-full .tug-challenge { padding: 6px 8px; }
.tug-game.is-full .tug-challenge h2 { font-size: 10px; }
.tug-game.is-full .tug-challenge-summary p, .tug-game.is-full .tug-challenge-status, .tug-game.is-full #challengeInstruction { font-size: 10px; }
.tug-game.is-full .tug-mobile-hud-panel { align-self: start; justify-self: stretch; z-index: 4; background: #fff; }
.tug-game.is-full .tug-overlay { padding: 8px; }
.tug-game.is-full .tug-card { padding: 12px; }
.tug-game.is-full .tug-card h2 { font-size: 15px; margin-bottom: 6px; }
.tug-game.is-full .tug-card p { font-size: 11px; margin-bottom: 6px; }
.tug-game.is-full .tug-card-choices { gap: 6px; margin-top: 8px; }
.tug-game.is-full .tug-card-choices > div { padding: 8px; gap: 4px; }
.tug-game.is-full .tug-card button { min-height: 34px; }
.tug-game.is-full .tug-stats { grid-template-columns: repeat(4, 1fr); gap: 5px; margin: 6px 0; }
/* Sideways: playfield on the left at full height, buttons and challenge in a narrow column on the right */
@media (orientation: landscape) {
    .tug-game.is-full { display: grid; grid-template-columns: auto minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); align-items: start; }
    .tug-game.is-full .tug-game-area { grid-column: 1; grid-row: 1 / -1; width: min(133.33dvh, 100vw - 190px); }
    .tug-game.is-full .tug-toolbar { grid-column: 2; grid-row: 1; border-left: 2px solid #000; }
    .tug-game.is-full .tug-challenge { grid-column: 2; grid-row: 2; border-left: 2px solid #000; border-top: 1px solid #000; overflow-y: auto; }
    .tug-game.is-full .tug-toolbar-actions button { flex: 1 1 70px; }
    .tug-game.is-full .tug-challenge-summary { flex-direction: column; align-items: stretch; }
}
/* Upright: toolbar on top, playfield, challenge underneath */
@media (orientation: portrait) {
    .tug-game.is-full { overflow-y: auto; }
}
