* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; background: #0d1216; color: #f4ecd8; font: 15px/1.4 "Avenir Next", "Segoe UI", system-ui, sans-serif; user-select: none; }
canvas { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
#hud { pointer-events: none; }
.hidden { display: none !important; }

#score { position: fixed; top: 10px; left: 50%; transform: translateX(-50%); display: flex; gap: 18px; padding: 6px 18px; background: #14100ab0; border-radius: 6px; white-space: nowrap; }
#score b { font-size: 20px; }
#clock { align-self: center; font-variant-numeric: tabular-nums; opacity: .8; }
.t0 { color: #7fc0ff; }
.t1 { color: #ff8b78; }

#feed { position: fixed; top: 12px; right: 12px; display: flex; flex-direction: column; align-items: flex-end; gap: 4px; pointer-events: none; }
@media (max-width: 1000px) { #feed { top: 60px; } }
#feed div { background: #14100a99; padding: 3px 10px; border-radius: 4px; font-size: 13px; }

#keys { position: fixed; top: 12px; left: 12px; padding: 6px 10px; background: #14100a80; border-radius: 6px; font-size: 12px; line-height: 1.7; opacity: .8; pointer-events: none; }
@media (max-width: 1000px) { #keys { top: 60px; } }
#message { position: fixed; top: 22%; width: 100%; text-align: center; font-size: 30px; font-weight: 700; text-shadow: 0 2px 8px #000; pointer-events: none; white-space: pre-line; }
#hint { position: fixed; bottom: 150px; white-space: pre-line; width: 100%; text-align: center; font-size: 17px; text-shadow: 0 1px 4px #000; pointer-events: none; }

#board { position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); width: min(620px, 92vw); display: grid; grid-template-columns: 1fr 1fr; gap: 20px; padding: 20px; background: #14100ae6; border-radius: 10px; }
#board table { width: 100%; border-collapse: collapse; align-self: start; }
#board th { text-align: left; border-bottom: 1px solid #ffffff40; padding-bottom: 4px; }
#board td { padding: 2px 0; }
#board td + td, #board th + th { text-align: right; width: 44px; }
#board tr.me { font-weight: 700; color: #ffe08a; }

.overlay { position: fixed; inset: 0; display: grid; place-items: center; background: #0b0f1470; z-index: 5; overflow: auto; }
.card { width: min(480px, 94vw); background: #1c160df2; border: 1px solid #8a744a; border-radius: 10px; padding: 24px 28px; display: flex; flex-direction: column; gap: 12px; box-shadow: 0 20px 60px #000a; }
h1 { font: 700 34px/1.1 "Iowan Old Style", Georgia, serif; letter-spacing: 1px; text-align: center; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; opacity: .95; flex: 1; }
.row { display: flex; gap: 12px; }
input, select { font: inherit; padding: 7px 9px; border-radius: 5px; border: 1px solid #8a744a; background: #f4ecd8; color: #1c160d; }
button { font: 700 17px inherit; padding: 10px; border: 0; border-radius: 6px; background: #c8962e; color: #1c160d; cursor: pointer; }
button:hover { background: #e2ad3d; }
#hangar { border: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px; }
#hangar legend { font-size: 13px; margin-bottom: 4px; }
label.plane { position: relative; gap: 3px; padding: 8px 10px; border: 1px solid #8a744a80; border-radius: 8px; background: #14100a; cursor: pointer; min-width: 0; }
label.plane:hover { border-color: #e2ad3d; }
label.plane:has(:checked) { border-color: #e2ad3d; box-shadow: 0 0 0 1px #e2ad3d inset; background: #2d2312; }
label.plane:has(:focus-visible) { outline: 2px solid #f4ecd8; outline-offset: 2px; }
/* The whole card shows the choice, so the dot itself stays out of sight. */
.plane input { position: absolute; opacity: 0; pointer-events: none; }
.plane .kind { font: 700 17px/1.2 "Iowan Old Style", Georgia, serif; text-align: center; }
.plane .portraits { display: flex; justify-content: center; height: 96px; }
.plane img { flex: 1; min-width: 0; height: 100%; object-fit: contain; }
.plane .name { text-align: center; min-height: 2.8em; display: grid; place-items: center; }
.plane .spec { display: grid; grid-template-columns: 56px minmax(0, 1fr) 52px; gap: 4px; align-items: center; font-size: 11px; }
.plane .spec b { font-size: 10.5px; text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.plane .bar { height: 5px; border-radius: 3px; background: #f4ecd822; overflow: hidden; }
.plane .bar i { display: block; height: 100%; background: #c8962e; }
#hangar .shared { grid-column: 1 / -1; font-size: 12px; opacity: .75; text-align: center; }
/* Too narrow for bars: the numbers say it all. */
@media (max-width: 480px) {
  .plane .spec { grid-template-columns: 1fr auto; }
  .plane .bar { display: none; }
}
#joinError { color: #ff8b78; text-align: center; }
#joinError:empty { display: none; }
.keys { font-size: 13px; border-collapse: collapse; }
.keys td { padding: 1px 8px 1px 0; vertical-align: top; }
.keys td:first-child { white-space: nowrap; }
kbd { font: 12px ui-monospace, Menlo, monospace; border: 1px solid #8a744a; border-radius: 3px; padding: 0 5px; }
.note { font-size: 13px; opacity: .75; text-align: center; }
.center, #queueTitle { text-align: center; white-space: pre-line; }
#queueTitle { font: 700 24px/1.2 "Iowan Old Style", Georgia, serif; }
#leaveBtn { color: #f4ecd8; background: #14100a; border: 1px solid #f4ecd855; }

/* ---- phones ------------------------------------------------------------- */
:root { --safe-left: env(safe-area-inset-left, 0px); --safe-right: env(safe-area-inset-right, 0px); --safe-bottom: env(safe-area-inset-bottom, 0px); }
.handheld-only, #rotate { display: none; }
body.handheld { touch-action: none; overscroll-behavior: none; -webkit-user-select: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent; }
.handheld .handheld-only { display: flex; }
.handheld .desktop-only { display: none; }

#touch { position: fixed; inset: 0; z-index: 2; pointer-events: none; touch-action: none; }
#touch > *, #touch button { pointer-events: auto; touch-action: none; }
#touch button { font: 700 12px inherit; color: #f4ecd8; background: #14100a99; border: 1px solid #f4ecd855; border-radius: 8px; padding: 0 10px; min-height: 34px; }
#touch button.on, #touch button.down { background: #c8962ecc; color: #1c160d; }

#stickZone { position: absolute; left: 0; bottom: 0; width: 45%; height: 72%; }
#stickBase { position: absolute; left: calc(var(--safe-left) + 96px); top: calc(100% - 96px - var(--safe-bottom)); width: 128px; height: 128px; margin: -64px 0 0 -64px; border: 2px solid #f4ecd855; border-radius: 50%; background: #14100a40; pointer-events: none; }
#stickBase.active { border-color: #f4ecd8aa; }
#stickKnob { position: absolute; left: 37px; top: 37px; width: 50px; height: 50px; border-radius: 50%; background: #f4ecd8aa; }
.tilting #stickBase:not(.active) { opacity: .3; }

#throttle { --level: 0; position: absolute; right: calc(var(--safe-right) + 14px); bottom: calc(var(--safe-bottom) + 14px); width: 54px; height: min(52vh, 220px); border: 2px solid #f4ecd877; border-radius: 12px; background: #14100a80; overflow: hidden; }
#throttle .fill { position: absolute; left: 0; right: 0; bottom: 0; height: calc(var(--level) * 100%); background: #d9a63acc; pointer-events: none; }
#throttle.turbo { border-color: #ff7a62; }
#throttle.turbo .fill { background: #e0503acc; }
#throttle span { position: absolute; top: 6px; width: 100%; text-align: center; font-size: 11px; font-weight: 700; pointer-events: none; }

#touch button.fire { position: absolute; border-radius: 50%; padding: 0; }
#touch #fire { right: calc(var(--safe-right) + 86px); bottom: calc(var(--safe-bottom) + 24px); width: 104px; height: 104px; font-size: 18px; background: #a8271c99; }
/* A second trigger for the left thumb, for tilt steering. */
#touch #fire2 { display: none; left: calc(var(--safe-left) + 24px); bottom: calc(var(--safe-bottom) + 24px); width: 104px; height: 104px; font-size: 18px; background: #a8271c99; }
.tilting #fire2 { display: block !important; }
.tilting #stickZone { left: calc(var(--safe-left) + 140px); width: 30%; }
.tilting #stickBase:not(.active) { display: none; }
#touch #fire.down, #touch #fire2.down { background: #ff5a3acc; color: #fff; }

#buttons { position: absolute; top: 46px; left: 50%; transform: translateX(-50%); display: flex; gap: 6px; }
/* In-game menu: covers the controls so nothing underneath can be touched. */
#menu { background: #0b0f14b3; overscroll-behavior: contain; }
#menu h2 { font: 700 22px/1.1 "Iowan Old Style", Georgia, serif; text-align: center; }
#menu .note-live { font-size: 12px; opacity: .75; text-align: center; }
#menu .grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
#menu .grid button, #exitBtn, #planeBtn { font-size: 14px; color: #f4ecd8; background: #14100a; border: 1px solid #f4ecd855; }
#menu button:active { background: #c8962e; color: #1c160d; }
#menu button:disabled { opacity: .4; cursor: default; }

.handheld #score { top: 6px; gap: 10px; padding: 3px 10px; font-size: 12px; }
.handheld #score b { font-size: 15px; }
.handheld #feed { top: 160px; right: calc(var(--safe-right) + 10px); }
.handheld #feed div { font-size: 11px; padding: 1px 7px; }
.handheld #feed div:nth-last-child(n+4) { display: none; }
.handheld #message { top: 30%; font-size: 20px; }
.handheld #hint { bottom: calc(var(--safe-bottom) + 8px); left: 30%; width: 40%; font-size: 13px; }
.handheld #board { top: 90px; transform: translateX(-50%); gap: 12px; padding: 10px; font-size: 12px; max-height: calc(100% - 100px); overflow: auto; }

.handheld .overlay { place-items: start center; padding: 8px; touch-action: pan-y; }
.handheld .card { padding: 12px 16px; gap: 8px; margin: auto; }
.handheld h1 { font-size: 24px; }
.handheld input, .handheld select { font-size: 16px; /* smaller makes iPhones zoom in */ padding: 3px 8px; }
.handheld label { gap: 1px; font-size: 12px; }
.handheld .card button { padding: 8px; }
.handheld .note, .handheld #hangar .shared { display: none; }
.handheld label.plane { padding: 4px 8px; gap: 1px; }
.handheld .plane .kind { font-size: 14px; }
.handheld .plane .portraits { height: 56px; }
.handheld .plane .name { min-height: 0; font-size: 11px; }
/* Screens held sideways are low: picture and numbers go next to each other. */
.handheld .card { width: min(640px, 96vw); }
.handheld label.plane { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 10px; align-content: center; align-items: center; }
.handheld .plane .kind { grid-area: 1 / 1; }
.handheld .plane .portraits { grid-area: 2 / 1 / span 2; }
.handheld .plane .name { grid-area: 4 / 1; }
.handheld .plane .spec { grid-column: 2; grid-template-columns: 1fr auto; }
.handheld .plane .bar { display: none; }
.handheld #hangar legend { position: absolute; opacity: 0; }
.handheld .help { flex-direction: column; gap: 2px; padding-left: 0; list-style: none; font-size: 12px; text-align: center; }

@media (orientation: portrait) {
  .handheld #rotate { display: grid; position: fixed; inset: 0; z-index: 10; place-items: center; background: #0d1216; font-size: 22px; text-align: center; line-height: 2; }
}
