:root{color-scheme:dark;--bg:#111215;--fg:#eeeee7;--accent:#c5b4ff;font-family:system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif}
*{box-sizing:border-box;-webkit-tap-highlight-color:transparent}
html,body{margin:0;min-height:100%;background:var(--bg);color:var(--fg);-webkit-user-select:none;user-select:none;-webkit-touch-callout:none;overscroll-behavior-x:none}
button{font:inherit;color:inherit;border:0;cursor:pointer;touch-action:manipulation;-webkit-user-drag:none}
button:focus-visible{outline:3px solid #fff;outline-offset:5px}
button:disabled{opacity:.6;cursor:wait}
[hidden]{display:none!important}
#home{min-height:100vh;min-height:100dvh;display:flex;flex-direction:column;justify-content:center;gap:20px;width:min(100%,460px);margin:0 auto;padding:calc(28px + env(safe-area-inset-top)) 24px calc(28px + env(safe-area-inset-bottom))}
.game-choice{width:100%;min-height:100px;padding:26px 20px;border:1px solid #ffffff28;border-radius:20px;color:#201a2e;font-size:clamp(24px,6vw,34px);font-weight:800;letter-spacing:-.7px;box-shadow:0 7px 0 #0004;transition:transform .12s}
.game-choice:active{transform:translateY(4px)}
.planes-choice{background:#c5b4ff}.tanks-choice{background:#d5dca5}.pac-choice{background:#f4d579}
.home-update{align-self:center;margin-top:4px;min-width:210px;min-height:48px;padding:12px 22px;border:1px solid #777385;border-radius:14px;background:linear-gradient(#2d3039,#1b1d24);color:#e7e4ee;font-size:14px;font-weight:800;box-shadow:inset 0 1px #ffffff20,0 5px 0 #07080b;letter-spacing:.2px}
.home-update:active{transform:translateY(3px);box-shadow:inset 0 2px 5px #0008,0 2px 0 #07080b}
.home-update-status{margin:0;padding:10px 14px;border-radius:10px;background:#282233;color:#e0d2fc;text-align:center;font-size:12px;line-height:1.4}
.online-choice{margin-top:-9px;min-height:44px;border-radius:12px;border:1px solid #8f7eb7;background:#282331;color:#e2d6fc;font-size:13px;font-weight:800}
/* The room interface stays inside the screen, above the main menu and below the deck. */
.network-dialog{position:absolute;inset:0;z-index:5;display:grid;align-items:safe center;justify-items:center;overflow:auto;border-radius:inherit;padding:8px;background:#14101e;pointer-events:none}
.network-card{width:min(100%,420px)}
.network-card p{font-size:13px;line-height:1.35;margin:8px 0}
.network-eyebrow{font-size:clamp(9px,2.4vw,11px);letter-spacing:.12em}
.network-card .primary{width:100%;margin:0}
#roomSetup,#roomWaiting{display:grid;gap:8px}
.join-room{display:grid;gap:8px}
.join-room label{font-size:12px;color:#d6cadd}
.join-room input{min-width:0;width:100%;height:44px;text-align:center;font-size:max(16px,1rem);letter-spacing:.2em;text-transform:uppercase;user-select:text;-webkit-user-select:text}
.join-room button{min-height:42px}
#createdCode{display:block;font-size:clamp(20px,6vw,36px);letter-spacing:.15em;text-align:center;padding:7px 4px}
#roomMessage{color:#f4cc92}
body.online-match .game-wrap{background:#101820}
body.online-match .hud{max-width:calc(100% - 18px);gap:10px}
#gameScreen{max-width:1100px;margin:0 auto;padding:calc(16px + env(safe-area-inset-top)) max(16px,env(safe-area-inset-right)) calc(16px + env(safe-area-inset-bottom)) max(16px,env(safe-area-inset-left))}
.game-toolbar{display:flex;align-items:center;justify-content:space-between;gap:10px;margin-bottom:14px;flex-wrap:wrap}
.game-toolbar button{background:#26262e;border:1px solid #3b3b48;padding:11px 13px;border-radius:8px;font-size:12px;min-height:42px;white-space:nowrap}
#gameName{font-size:17px;font-weight:800}
.game-actions{display:flex;gap:7px;flex-wrap:wrap}
#updateGame{border-color:#736587;color:#d6c8f6}
#updateStatus{margin:0 0 14px;padding:12px 14px;background:#282233;border-radius:8px;font-size:12px;color:#e0d2fc;line-height:1.5}
.game-wrap{position:relative;overflow:hidden;border:1px solid #41414f;border-radius:12px;background:#0b101b}
#game{display:block;width:100%;aspect-ratio:1.6;touch-action:none;outline:none;contain:strict;-webkit-user-drag:none}
body.playing:not(.plane-controls) #game{image-rendering:pixelated}
#overlay{position:absolute;inset:0;background:#0c0c16ed;display:grid;place-items:center;text-align:center;padding:20px}
#overlay>div{max-width:500px}#overlay span{color:var(--accent);font-size:10px;letter-spacing:3px}#overlay h2{font-size:clamp(24px,4vw,46px);margin:18px 0;line-height:1.1}#overlay p{color:#b0aeba;line-height:1.7;font-size:13px}
.primary{background:var(--accent);color:#191322;border-radius:8px;padding:14px 26px;font-weight:800;margin-top:14px;min-height:44px}
.hud>span:empty{display:none}
.hud{display:flex;justify-content:space-between;font-size:12px;padding:16px 3px;color:#bbb0d6;font-weight:700;gap:10px}
.game-help{color:#9393a1;text-align:center;font-size:12px;line-height:1.6}
.touch{display:flex;justify-content:space-between;align-items:center;margin:8px auto;max-width:550px;touch-action:none;padding-bottom:env(safe-area-inset-bottom)}
.touch *{touch-action:none}
.touch button{background:#262832;border:1px solid #454655;border-radius:9px;min-width:52px;height:48px}
.touch button:active{background:#605178}
.dpad{display:grid;grid-template-columns:repeat(3,52px);gap:5px}.dpad button:first-child{grid-column:2}.dpad button:nth-child(2){grid-column:1}
.touch #fire{width:100px;height:84px;border-radius:22px;font-size:13px;font-weight:800;color:var(--accent)}
#joystickGroup{display:flex;flex-direction:column;align-items:center;gap:10px;padding:7px}
#joystick{position:relative;width:136px;height:136px;border-radius:50%;background:radial-gradient(circle,#292635 0 35%,#1c1e27 36% 100%);border:2px solid #4a435d;box-shadow:inset 0 0 0 10px #ffffff03;touch-action:none;cursor:grab}
#joystick.active{border-color:#c5b4ff;cursor:grabbing}
.joystick-axis{position:absolute;background:#c5b4ff20;pointer-events:none}.joystick-axis.horizontal{height:1px;left:13px;right:13px;top:50%}.joystick-axis.vertical{width:1px;top:13px;bottom:13px;left:50%}
#joystickKnob{position:absolute;left:50%;top:50%;width:54px;height:54px;margin:-27px;border-radius:50%;border:2px solid #c9b5ff;background:radial-gradient(circle at 35% 30%,#a48bd1,#5e4d7d);box-shadow:0 4px 12px #0006;pointer-events:none;will-change:transform}
.joystick-hint{font-size:8px;letter-spacing:1.4px;color:#a69bbd}
@media(min-width:1000px) and (pointer:fine){.touch{display:none}body.plane-controls .touch{display:flex}}
@media(max-width:650px){#gameScreen{padding-top:calc(10px + env(safe-area-inset-top));padding-left:10px;padding-right:10px}.game-toolbar{gap:8px;margin-bottom:10px}#gameName{font-size:15px}.game-toolbar button{font-size:11px;padding:9px 10px}.game-actions{width:100%;display:grid;grid-template-columns:auto auto auto 1fr;gap:5px}.game-actions button{padding:7px 5px;min-height:40px}.hud{font-size:9px;padding:12px 2px}.game-help{font-size:10px}#overlay{padding:12px}#overlay h2{margin:10px 0}#overlay p{font-size:11px}.primary{padding:10px 22px;margin-top:4px}#overlay span{font-size:8px}}
@media(max-height:520px) and (orientation:landscape) and (pointer:coarse){#gameScreen{max-width:100%;padding:calc(4px + env(safe-area-inset-top)) max(160px,env(safe-area-inset-right)) env(safe-area-inset-bottom) max(160px,env(safe-area-inset-left))}.game-toolbar{margin-bottom:5px;gap:5px}.game-toolbar button{padding:6px;font-size:10px;min-height:30px}#gameName{font-size:12px}.game-actions{gap:4px;width:auto;display:flex}.game-wrap{max-width:calc((100dvh - 90px)*1.6);margin:auto}.hud{padding:6px 0;font-size:9px}.game-help{display:none}.touch{position:fixed;inset:0 12px;max-width:none;pointer-events:none;margin:0;align-items:center}.touch>div,.touch>button{pointer-events:auto}}

body.plane-controls #game{image-rendering:pixelated}

/* Btbiplanes becomes a two-part handheld: screen above, controls below. */
body.plane-controls{overflow:hidden;height:100dvh;background:#11141b}
body.plane-controls #gameScreen{position:fixed;inset:0;width:100%;height:100dvh;max-width:none;margin:0;padding:0;overflow:hidden;background:#171b23}
body.plane-controls .game-wrap{position:absolute;inset:0 0 auto 0;width:100%;height:50dvh;max-width:none;margin:0;border:0;border-bottom:4px solid #080a0f;border-radius:0;background:#0b101b;box-shadow:0 5px 16px #0009;z-index:1}
body.plane-controls #game{width:100%;height:100%;aspect-ratio:auto;contain:strict}
body.plane-controls .game-toolbar{position:absolute;top:calc(10px + env(safe-area-inset-top));left:max(12px,env(safe-area-inset-left));right:max(12px,env(safe-area-inset-right));z-index:4;margin:0;gap:8px;flex-wrap:nowrap;pointer-events:none}
body.plane-controls .game-toolbar button{background:#17242ddd;border-color:#e3ddc44d;min-height:38px;box-shadow:0 3px 0 #081016aa}
body.plane-controls #gameName{display:none}
body.plane-controls .game-actions{width:auto;max-width:calc(100% - 70px);display:flex;justify-content:flex-end;gap:5px;flex-wrap:wrap}
body.plane-controls .hud{position:absolute;z-index:3;top:calc(62px + env(safe-area-inset-top));left:50%;transform:translateX(-50%);width:max-content;max-width:calc(100% - 24px);border-radius:8px;padding:8px 10px;background:#22343ec7;gap:20px;pointer-events:none;color:#f3e9c6;font-size:11px}
body.plane-controls .game-help{display:none}
body.plane-controls .touch{position:absolute;z-index:2;left:0;right:0;top:50dvh;bottom:0;margin:0;max-width:none;padding:clamp(18px,3.2dvh,34px) max(22px,calc(22px + env(safe-area-inset-right))) calc(14px + env(safe-area-inset-bottom)) max(22px,calc(22px + env(safe-area-inset-left)));pointer-events:none;display:flex;align-items:center;background:radial-gradient(circle at 18px 20px,#87909b 0 2px,#252b34 2.5px 5px,transparent 5.5px),radial-gradient(circle at calc(100% - 18px) 20px,#87909b 0 2px,#252b34 2.5px 5px,transparent 5.5px),radial-gradient(circle at 18px calc(100% - 20px),#87909b 0 2px,#252b34 2.5px 5px,transparent 5.5px),radial-gradient(circle at calc(100% - 18px) calc(100% - 20px),#87909b 0 2px,#252b34 2.5px 5px,transparent 5.5px),repeating-linear-gradient(115deg,#ffffff05 0 1px,transparent 1px 5px),linear-gradient(165deg,#343a45 0%,#20252e 45%,#11151c 100%);border-top:1px solid #626b78;box-shadow:inset 0 2px #aab1ba44,inset 0 -24px 38px #05070a88}
body.plane-controls .touch::before{content:'BTBIPLANES';position:absolute;left:50%;top:18px;transform:translateX(-50%);font-size:clamp(8px,1.5vw,12px);font-weight:900;letter-spacing:3px;color:#858b96;text-shadow:0 1px #000;pointer-events:none}
body.plane-controls .touch::after{content:'•••••';position:absolute;left:50%;bottom:calc(12px + env(safe-area-inset-bottom));transform:translateX(-50%) rotate(-10deg);font-size:18px;letter-spacing:6px;color:#090b10;text-shadow:0 1px #424854;pointer-events:none}
body.plane-controls .touch>div{pointer-events:auto}
body.plane-controls #joystickGroup{padding:0;gap:8px;justify-content:center}
body.plane-controls #joystick{width:clamp(122px,23dvh,172px);height:clamp(122px,23dvh,172px);background:repeating-conic-gradient(from 22.5deg,#252b35 0 3deg,#151922 3deg 42deg,#4d5562 42deg 45deg),radial-gradient(circle,#303744 0 34%,#0e1117 35% 57%,#3d4551 58% 66%,#12161d 67% 100%);border:4px solid #737c89;outline:2px solid #0a0d12;box-shadow:inset 0 0 0 6px #0b0e1488,inset 0 0 18px #000,0 8px 0 #080a0e,0 14px 24px #000c}
body.plane-controls #joystick.active{border-color:#b3b9c3;box-shadow:inset 0 0 0 6px #0b0e1488,inset 0 0 18px #000,0 5px 0 #080a0e,0 9px 16px #000b}
body.plane-controls #joystickKnob{background:radial-gradient(circle at 34% 27%,#d5d9df 0 3%,#9da5b1 8%,#59616e 30%,#292f39 68%,#13171e 100%);border:3px solid #a8b0bb;box-shadow:inset -7px -9px 13px #05070a99,inset 5px 5px 8px #ffffff2f,0 9px 0 #0b0e13,0 13px 17px #000b}
body.plane-controls #joystickKnob::after{content:'';position:absolute;inset:11% 19% 55% 19%;border-radius:50%;background:linear-gradient(#ffffff62,#ffffff08);pointer-events:none}
body.plane-controls .joystick-hint{color:#9ca2ad;text-shadow:0 1px #000;font-size:8px;font-weight:800}
#flightActions{display:flex;flex-direction:row-reverse;align-items:center;gap:clamp(16px,3vw,30px);transform:rotate(-7deg);padding:12px}
#flightActions button{position:relative;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:4px;font-weight:900;letter-spacing:.5px;outline:2px solid #07090d;box-shadow:inset 5px 7px 10px #ffffff35,inset -7px -9px 12px #0007,0 0 0 7px #0b0e13,0 0 0 9px #4a515d,0 10px 0 7px #07090d,0 18px 25px #000b;transform:translateY(0);transition:transform .05s,box-shadow .05s;overflow:hidden}
#flightActions button::before{content:'';position:absolute;left:17%;right:28%;top:8%;height:24%;border-radius:50%;background:linear-gradient(#ffffff62,#ffffff08);pointer-events:none}
#flightActions button:active{transform:translateY(7px);box-shadow:inset 2px 4px 10px #0009,0 0 0 7px #0b0e13,0 0 0 9px #4a515d,0 3px 0 7px #07090d,0 7px 12px #0009}
#flightActions .key-letter{font-size:clamp(19px,4dvh,30px);line-height:1}
#eject{padding:8px;width:clamp(78px,15dvh,106px);height:clamp(78px,15dvh,106px);min-height:0;border:4px solid #d48b60;border-radius:50%;background:radial-gradient(circle at 34% 25%,#f0bd8d 0 5%,#d47c4e 28%,#8c3f2a 73%,#56271d 100%);color:#fff0d5;font-size:clamp(7px,1.5dvh,10px)}
#eject:disabled,#eject[aria-disabled=true]{opacity:.45;cursor:default}
body.plane-controls #fire{background:radial-gradient(circle at 34% 25%,#d3c8f1 0 4%,#9482c9 27%,#554575 70%,#30283f 100%);border:4px solid #b9abe1;width:clamp(94px,18dvh,126px);height:clamp(94px,18dvh,126px);border-radius:50%;pointer-events:auto;color:#fff;font-size:clamp(8px,1.6dvh,11px)}
body.plane-controls #updateStatus{position:absolute;z-index:6;top:calc(104px + env(safe-area-inset-top));left:12px;right:12px;margin:0}
body.plane-controls #overlay{z-index:5}
@media(max-width:650px){body.plane-controls .game-toolbar button{font-size:9px;padding:6px 5px;min-height:34px}body.plane-controls .game-actions{gap:3px}body.plane-controls .hud{font-size:9px;gap:10px;top:calc(52px + env(safe-area-inset-top));padding:6px 8px}body.plane-controls .touch{padding-left:max(16px,env(safe-area-inset-left));padding-right:max(16px,env(safe-area-inset-right))}body.plane-controls #joystick{width:clamp(94px,30vw,132px);height:clamp(94px,30vw,132px)}body.plane-controls #joystickKnob{width:46px;height:46px;margin:-23px}body.plane-controls #fire{width:clamp(82px,26vw,112px);height:clamp(82px,26vw,112px)}#eject{width:clamp(68px,22vw,92px);height:clamp(68px,22vw,92px)}#flightActions{gap:10px}}
@media(max-width:350px){body.plane-controls .hud{top:calc(95px + env(safe-area-inset-top))}}
@media(max-height:520px){body.plane-controls .touch::before,body.plane-controls .touch::after,body.plane-controls .joystick-hint{display:none}body.plane-controls .touch{padding-top:8px;padding-bottom:max(8px,env(safe-area-inset-bottom))}body.plane-controls .hud{top:calc(48px + env(safe-area-inset-top))}#flightActions{gap:10px}}

/* Disable browser double-tap zoom on all ancestors, not just control buttons. */
html,body{touch-action:manipulation}
body.playing #gameScreen,body.playing #gameScreen *{touch-action:none}

/* Carbon insert and ribbed silicone thumb caps. All texture stays on the GPU. */
body.plane-controls .touch{isolation:isolate;column-gap:22px;padding-left:max(28px,env(safe-area-inset-left));padding-right:max(28px,env(safe-area-inset-right));background:radial-gradient(ellipse at 20% 0%,#464c54 0%,transparent 55%),linear-gradient(160deg,#282e36,#11161c 75%);border-top:2px solid #798089;box-shadow:inset 0 2px #c7ced42b,inset 0 -15px 28px #0009}
body.plane-controls .touch>.controller-inlay{position:absolute;inset:13px 13px calc(12px + env(safe-area-inset-bottom));z-index:-1;pointer-events:none;border:1px solid #59616b;border-radius:25px;background:linear-gradient(125deg,#ffffff10,transparent 38%,#00000050 80%),repeating-linear-gradient(135deg,#ffffff07 0 .6px,transparent .8px 2px),repeating-conic-gradient(from 45deg,#252c31 0% 25%,#171c21 0% 50%) 0 0/8px 8px;box-shadow:inset 0 1px 1px #d6e0e429,inset 0 0 0 4px #090c1080,inset 0 -8px 15px #0008,0 1px 0 #080b0e}
body.plane-controls .controller-inlay::before,body.plane-controls .controller-inlay::after{content:'';position:absolute;top:10px;bottom:10px;width:7px;background:radial-gradient(circle at 50% 4px,#12171b 0 1px,#858d94 1px 2px,#242c33 2px 3px,transparent 3px),radial-gradient(circle at 50% calc(100% - 4px),#12171b 0 1px,#858d94 1px 2px,#242c33 2px 3px,transparent 3px);pointer-events:none}
body.plane-controls .controller-inlay::before{left:8px}body.plane-controls .controller-inlay::after{right:8px}
body.plane-controls .touch::before,body.plane-controls .touch::after{z-index:0}
body.plane-controls #joystickGroup,body.plane-controls #flightActions{position:relative;z-index:1;flex-shrink:0}
body.plane-controls #joystick{border:3px solid #7e8791;outline:2px solid #080c10;background:radial-gradient(circle,#070b0f 0 31%,#222a32 32% 39%,#10161c 40% 57%,#48515b 58% 60%,#181f26 61% 68%,#060a0e 69% 100%);box-shadow:inset 0 5px 12px #000d,inset 0 -3px 4px #87939e44,0 7px 0 #05080c,0 13px 20px #000a}
body.plane-controls #joystick.active{border-color:#a5aeb8;box-shadow:inset 0 5px 12px #000d,inset 0 -3px 4px #87939e44,0 7px 0 #05080c,0 13px 20px #000a}
body.plane-controls #joystickKnob{width:68px;height:68px;margin:-34px;border:3px solid #59616b;background:radial-gradient(circle at 34% 25%,#6a717a 0%,#363d46 35%,#181e25 73%,#090e14 100%);box-shadow:inset 0 2px 2px #dbe3e357,inset -5px -8px 9px #000b,0 4px 0 #1c232b,0 9px 0 #0b1017,0 14px 14px #000c}
body.plane-controls #joystickKnob::before{content:'';position:absolute;inset:5px;border:1px solid #080c10;border-radius:50%;background:radial-gradient(ellipse at 40% 27%,#c0c6cb16,transparent 65%),repeating-radial-gradient(circle at 50% 50%,#858e9859 0 1px,#0b101599 1.5px 3px,#424b5559 3.5px 4px);box-shadow:inset 0 3px 6px #0009,inset 0 -2px 3px #bbc4cb2a}
body.plane-controls #joystickKnob::after{inset:8px 16px auto;height:8px;background:linear-gradient(#d6e0e437,transparent);filter:none}
body.plane-controls #flightActions{gap:clamp(32px,5vw,52px);transform:none;padding:12px 10px;align-items:center}
body.plane-controls #flightActions button{flex-shrink:0;isolation:isolate;outline:1px solid #080b0f;border-width:3px;box-shadow:inset 2px 3px 5px #e7e9f034,inset -4px -7px 8px #000a,0 0 0 5px #080d13,0 0 0 7px #515962,0 8px 0 5px #05090f,0 14px 16px #000b;transition:transform .06s,box-shadow .06s}
body.plane-controls #flightActions button::before{inset:5px;width:auto;height:auto;border:1px solid #060b1180;border-radius:50%;background:radial-gradient(ellipse at 37% 25%,#d6d9e51c,transparent 64%),repeating-radial-gradient(circle at 50% 50%,#b0b8c432 0 1px,#05081080 1.5px 3px,#c2c9d023 3.5px 4px);box-shadow:inset 0 4px 6px #0007,inset 0 -2px 2px #e9e6ee24;z-index:-1}
body.plane-controls #flightActions button::after{content:'';position:absolute;left:25%;right:25%;top:7%;height:6%;border-radius:50%;background:#e5e7ed30;pointer-events:none}
body.plane-controls #flightActions button span{position:relative;text-shadow:0 2px 2px #000c;pointer-events:none}
body.plane-controls #fire{background:radial-gradient(circle at 35% 25%,#625b79,#393347 55%,#1a1822 100%);border-color:#8b7ca9;color:#e8ddff}
body.plane-controls #eject{background:radial-gradient(circle at 35% 25%,#805e4c,#4b352d 55%,#241d1b 100%);border-color:#af8468;color:#ffe1bd;transform:translateY(-16px)}
body.plane-controls #flightActions #fire:active{transform:translateY(6px);box-shadow:inset 2px 4px 8px #000a,0 0 0 5px #080d13,0 0 0 7px #515962,0 2px 0 5px #05090f,0 5px 8px #0009}
body.plane-controls #flightActions #eject:active{transform:translateY(-10px);box-shadow:inset 2px 4px 8px #000a,0 0 0 5px #080d13,0 0 0 7px #515962,0 2px 0 5px #05090f,0 5px 8px #0009}
body.plane-controls #eject:disabled{opacity:.68}
@media(max-width:650px){body.plane-controls .touch{column-gap:18px;padding-left:max(24px,env(safe-area-inset-left));padding-right:max(24px,env(safe-area-inset-right))}body.plane-controls #joystick{width:clamp(90px,26vw,122px);height:clamp(90px,26vw,122px)}body.plane-controls #joystickKnob{width:54px;height:54px;margin:-27px}body.plane-controls #flightActions{gap:32px;padding:8px 0}body.plane-controls #fire{width:clamp(74px,21vw,96px);height:clamp(74px,21vw,96px)}body.plane-controls #eject{width:clamp(64px,18vw,82px);height:clamp(64px,18vw,82px)}}
@media(max-width:370px){body.plane-controls .touch{column-gap:14px;padding-left:20px;padding-right:20px}body.plane-controls #joystick{width:82px;height:82px}body.plane-controls #joystickKnob{width:48px;height:48px;margin:-24px}body.plane-controls #flightActions{gap:28px}body.plane-controls #fire{width:68px;height:68px}body.plane-controls #eject{width:60px;height:60px;font-size:7px}}

/* The tank camera fills the entire screen above the unchanged controller. */
body.tank-controls #game{object-fit:fill}
body.tank-controls .game-wrap{background:#151c17}
body.tank-controls .touch::before{content:'TANCHIKI'}
body.plane-controls #reverse{padding:8px;width:clamp(78px,15dvh,106px);height:clamp(78px,15dvh,106px);min-height:0;border:3px solid #af8468;border-radius:50%;background:radial-gradient(circle at 35% 25%,#805e4c,#4b352d 55%,#241d1b 100%);color:#ffe1bd;font-size:clamp(7px,1.5dvh,10px);transform:translateY(-16px)}
body.plane-controls #flightActions #reverse:active{transform:translateY(-10px);box-shadow:inset 2px 4px 8px #000a,0 0 0 5px #080d13,0 0 0 7px #515962,0 2px 0 5px #05090f,0 5px 8px #0009}
@media(max-width:650px){body.plane-controls #reverse{width:clamp(64px,18vw,82px);height:clamp(64px,18vw,82px)}}
@media(max-width:370px){body.plane-controls #reverse{width:60px;height:60px;font-size:7px}}

/* Keep both battlefields clear of the upper action buttons. */
body.plane-controls .game-toolbar{display:none}
body.plane-controls .hud{top:calc(10px + env(safe-area-inset-top))}

/* Recessed Select-style ESC key on the upper-left of both controller panels. */
#controllerEsc{display:none}
body.plane-controls #controllerEsc{display:block;position:absolute;z-index:3;top:25px;left:max(32px,env(safe-area-inset-left));width:60px;height:28px;min-height:0;padding:0;border:1px solid #747c84;border-radius:5px;background:linear-gradient(#515861,#292f36 48%,#1b2027);color:#d8dde2;font:700 10px Arial,sans-serif;letter-spacing:1.5px;text-shadow:0 1px 1px #000;box-shadow:inset 0 1px 1px #d2d9df55,inset 0 -2px 3px #0008,0 3px 0 #080c11,0 0 0 3px #0c1118,0 0 0 4px #47515b;pointer-events:auto;touch-action:none;transition:transform .06s,box-shadow .06s}
body.plane-controls #controllerEsc::before{content:'';position:absolute;inset:-8px}
body.plane-controls #controllerEsc:active{transform:translateY(2px);box-shadow:inset 0 2px 4px #000a,0 1px 0 #080c11,0 0 0 3px #0c1118,0 0 0 4px #47515b}
body.plane-controls #controllerEsc:focus-visible{outline:2px solid #d8dde2;outline-offset:6px}
body.plane-controls #controllerEsc:disabled{opacity:.45}

.pause-actions{display:flex;flex-wrap:wrap;justify-content:center;gap:10px;margin-top:14px}
.pause-actions .primary{margin-top:0}
.pause-exit{min-height:44px;padding:12px 22px;border:1px solid #777385;border-radius:8px;background:linear-gradient(#323540,#20232b);color:#eeeaf4;font-weight:700}
.pause-exit:active{background:#151820;transform:translateY(1px)}
/* Allow the four-side battle counters to fit narrow phone screens. */
body.tank-controls .hud{flex-wrap:wrap;justify-content:center;gap:4px 12px}

body.tank-controls .hud{font-size:9px;gap:4px 10px}
#tankScores{position:absolute;z-index:3;top:calc(42px + env(safe-area-inset-top));left:50%;transform:translateX(-50%);display:grid;grid-template-columns:repeat(2,max-content);gap:3px 16px;padding:6px 10px;border-radius:8px;background:#172925d9;font:700 9px system-ui,sans-serif;pointer-events:none;max-width:calc(100% - 20px)}
#teamScore0{color:#a8d481}#teamScore1{color:#e8bd79}#teamScore2{color:#76c9f1}#teamScore3{color:#ed8d88}
@media(max-width:400px){#tankScores{font-size:8px;gap:3px 9px}body.tank-controls .hud{font-size:8px}}

.pac-choice{background:linear-gradient(135deg,#a7b6c8,#637d9b);color:#152338;font-size:clamp(20px,5.4vw,30px)}

body.rally-controls .touch::before{content:'FOREST RALLY'}
body.rally-controls .game-wrap{background:#101723}
body.rally-controls .hud{font-size:clamp(8px,1.3vw,11px);gap:12px;max-width:calc(100% - 18px);padding:6px 9px;background:#162336ed;color:#f0d49b}
body.plane-controls #mazePause,body.plane-controls #mazeRestart{width:clamp(78px,16dvh,116px);height:clamp(78px,16dvh,116px);padding:8px;min-height:0;border:3px solid #8b7ca9;border-radius:50%;background:radial-gradient(circle at 35% 25%,#625b79,#393347 55%,#1a1822);color:#e8ddff;font-size:clamp(7px,1.5dvh,10px);pointer-events:auto}
body.plane-controls #mazeRestart{background:radial-gradient(circle at 35% 25%,#805e4c,#4b352d 55%,#241d1b);border-color:#af8468;color:#ffe1bd;transform:translateY(-16px)}
body.plane-controls #flightActions #mazeRestart:active{transform:translateY(-10px)}
@media(max-width:650px){body.plane-controls #mazePause{width:clamp(74px,21vw,96px);height:clamp(74px,21vw,96px)}body.plane-controls #mazeRestart{width:clamp(64px,18vw,82px);height:clamp(64px,18vw,82px)}}
@media(max-width:370px){body.plane-controls #mazePause{width:68px;height:68px}body.plane-controls #mazeRestart{width:60px;height:60px;font-size:7px}}

/* Reference console: one physical controller surface shared by menu and games. */
:root{--deck-height:min(32dvh,52vw);--console-edge:#8a7a98;--console-radius:24px;--display-gutter:10px;--display-joint:5px;--shell-finish:linear-gradient(115deg,#3c3547,#241e2c 28%,#332a3e 68%,#27212f);--deck-finish:repeating-linear-gradient(0deg,#ffffff08 0 1px,#09070d0c 1px 2px,transparent 2px 4px),linear-gradient(170deg,#5e5666,#3d3845 13%,#26232d 49%,#373240 84%,#4e4658);--carbon-finish:linear-gradient(152deg,#cdb9e332,transparent 38%,#08070c66 88%), repeating-linear-gradient(0deg,#09081055 0 .6px,transparent .6px 1.4px), repeating-conic-gradient(from 45deg,#39343f 0 12.5%,#26232e 12.5% 25%,#1c1a22 25% 37.5%,#282530 37.5% 50%) 0 0/8px 8px}
.sr-only{position:absolute!important;width:1px!important;height:1px!important;padding:0!important;margin:-1px!important;overflow:hidden!important;clip:rect(0,0,0,0)!important;white-space:nowrap!important;border:0!important}
body:not(.playing){height:100dvh;overflow:hidden;background:radial-gradient(ellipse at top,#29232e,#0d0e13 72%)}
#home.console-shell{width:min(100%,760px);height:100dvh;min-height:0;margin:0 auto;padding:0;gap:0;display:flex;flex-direction:column;justify-content:flex-start;isolation:isolate;overflow:hidden}
.console-display{position:relative;display:flex;flex-direction:column;flex:1;min-height:0;margin:var(--display-gutter) var(--display-gutter) var(--display-joint);padding:10px;gap:9px}
.console-header{display:flex;align-items:center;justify-content:space-between;min-height:27px;padding:0 4px;color:#d5c5e9}
.console-brand{
 display:flex;align-items:center;gap:.28em;color:#fff0c9;
 font:950 clamp(16px,5vw,27px)/1 system-ui,sans-serif;letter-spacing:.04em;text-shadow:0 2px #774225;
}
.console-brand::before,.console-brand::after{
 content:'';width:clamp(12px,4vw,28px);height:9px;
 background:repeating-linear-gradient(to bottom,#e6a65f 0 1px,#a55739 1px 2px,transparent 2px 4px);
 clip-path:polygon(0 0,100% 0,84% 100%,34% 100%);
}
.console-brand::after{transform:scaleX(-1)}
.console-utilities{display:flex;gap:7px}.console-utilities button{width:29px;height:27px;min-height:0;padding:0;border:1px solid #89759d;border-radius:6px;background:linear-gradient(#4b4056,#241e2e);font-size:19px;color:#e8cef6;box-shadow:0 2px 0 #08080d,inset 0 1px #d7c9e34d}
.console-games,.console-modes,.flight-scene-options{pointer-events:none}
.console-games{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:7px;flex-shrink:0}
.console-card{
 display:flex;flex-direction:column;align-items:center;justify-content:center;gap:2px;min-width:0;
 min-height:clamp(48px,8dvh,66px);padding:3px 2px 4px;border:2px solid #826b91;border-radius:8px;
 background:linear-gradient(155deg,#352739,#19131f 80%);color:#ead9b8;
 box-shadow:inset 0 0 0 1px #08070e,0 2px #08070e;
 font:850 clamp(9px,2.6vw,13px)/1.1 system-ui,sans-serif;letter-spacing:.04em;
}
.console-tab-icon{
 width:clamp(40px,14vw,66px);aspect-ratio:5 / 3;
 background:url('assets/menu-tab-icons-v1.webp') left center / 300% 100% no-repeat;
 filter:drop-shadow(0 2px 1px #09080b);
}
#menuCard1 .console-tab-icon{background-position:center}
#menuCard2 .console-tab-icon{background-position:right}
.console-card[aria-selected="true"]{
 border-color:#efb85b;background:linear-gradient(150deg,#5d422d,#251d22 85%);color:#ffe39c;
 box-shadow:inset 0 0 0 1px #5b402a,inset 0 1px #fff1ad,0 2px #08070e,0 0 8px #e1a45238;
}
.console-scene{position:relative;overflow:hidden;flex:1;min-height:90px;border:1px solid #887292;border-radius:9px;background:#11151d;box-shadow:inset 0 0 20px #000;isolation:isolate}
/* Backdrop picker uses the same display area and body controls as the console menu. */
.flight-scene-menu {
  flex: 1; min-height: 0; padding: clamp(6px,2vw,14px); overflow: auto;
  display: grid; grid-template-rows: auto 1fr auto; gap: clamp(4px,1.2dvh,10px);
  border: 1px solid #887292; border-radius: 9px; background: #171323;
}
.flight-scene-menu h1 { margin: 0; font-size: clamp(13px,4.5vw,24px); }
.flight-scene-menu p { margin: 0; font: 700 clamp(8px,2vw,11px) monospace; color: #d7c7e1; }
.flight-scene-options { display: grid; grid-template-rows: repeat(3,1fr); gap: 6px; }
.flight-scene-options [role="option"] {
  position: relative; isolation: isolate; overflow: hidden;
  display: flex; flex-direction: column; justify-content: center;
  min-height: 32px; text-align: left; padding: 4px 10px; border: 2px solid #72637c;
  border-radius: 8px; color: #faf2df;
  background: linear-gradient(110deg,#10101cf5 5%,#10101c9e 72%,transparent),var(--scene-palette);
}
.flight-scene-options [role="option"]:nth-child(1) { --scene-palette: linear-gradient(164deg,#7597ac 53%,#63856d 54%,#3f6247 78%); }
.flight-scene-options [role="option"]:nth-child(2) { --scene-palette: linear-gradient(160deg,#e3b87e 53%,#b97850 54%,#e4ad6e 78%); }
.flight-scene-options [role="option"]:nth-child(3) { --scene-palette: linear-gradient(162deg,#aacdde 53%,#e1f1f6 54%,#7292a1 78%); }
.flight-scene-options canvas {
  position: absolute; inset: 0; z-index: -2; width: 100%; height: 100%;
  object-fit: cover; image-rendering: pixelated; pointer-events: none;
}
.flight-scene-options [role="option"]::before {
  content: ''; position: absolute; inset: 0; z-index: -1;
  background: linear-gradient(90deg,#100e1df5,#100e1d92 54%,#100e1d19); pointer-events: none;
}
.flight-scene-options [role="option"][aria-selected="true"] { border-color: #f5cc75; box-shadow: inset 0 0 0 1px #a78550; }
.flight-scene-options b { display: block; font-size: clamp(12px,3.4vw,17px); }
.flight-scene-options span { display: block; color: #d6cddb; font-size: clamp(9px,2.5vw,12px); }
.rally-room-actions { display: grid; gap: 8px; }
.rally-room-actions .primary { margin: 0; }
.rally-room-actions #rallyJoinStep { background: #414052; color: #f3e7f4; }
.room-flight-scene { display: grid; gap: 4px; margin: 0; color: #f2deba; font-size: 13px; }
.room-flight-scene select {
  width: 100%; background: #211a2b; color: #f6e7c8; border: 1px solid #887292;
  border-radius: 6px; padding: 8px; font: inherit;
}
@media (orientation: landscape) {
  .flight-scene-options { grid-template: 1fr / repeat(3,1fr); }
}
.console-scene>img{position:absolute;width:100%;height:100%;object-fit:cover;object-position:52% 50%;z-index:-2}
.console-scene::after{content:'';position:absolute;inset:0;z-index:-1;background:linear-gradient(#130e19ba,transparent 45%,transparent 87%,#0a0814a6);pointer-events:none}
.scene-heading{
 position:absolute;top:6%;left:6px;right:6px;margin:0;text-align:center;color:#fff0c7;
 font:italic 950 clamp(29px,10vw,70px)/.91 system-ui,sans-serif;letter-spacing:.005em;
 text-shadow:2px 3px #39211a,0 5px 12px #120d13;
}
.console-scene[data-game="rally"] .scene-heading{max-width:6.2em;margin-inline:auto}
.console-hint{position:absolute;bottom:6px;left:2px;right:2px;margin:0;text-align:center;color:#fff0cb;text-shadow:0 1px 3px #000,0 1px 6px #000;font:700 clamp(7px,2vw,10px)/1.3 monospace;letter-spacing:.04em;pointer-events:none}
.console-modes{display:flex;gap:9px;flex-shrink:0}
.console-mode{
 position:relative;display:flex;align-items:center;justify-content:center;gap:6px;flex:1;min-width:0;
 min-height:0;height:clamp(44px,7dvh,59px);border:2px solid #f8cf77;border-radius:9px;
 background:repeating-linear-gradient(125deg,#fff1 0 1px,transparent 1px 4px),linear-gradient(#ffd27d,#cd8c35);
 color:#211314;font:950 clamp(14px,4.4vw,23px)/1 system-ui,sans-serif;letter-spacing:.04em;text-shadow:0 1px #ffe6a5;
 box-shadow:inset 0 0 0 2px #845120,inset 0 3px #fff1b1,0 3px #08070b;
}
.mode-online{
 border-color:#b59bc1;background:repeating-linear-gradient(125deg,#fff1 0 1px,transparent 1px 4px),linear-gradient(#543e5f,#291b32);
 color:#fff0d9;box-shadow:inset 0 0 0 2px #28192e,inset 0 3px #a784b2,0 3px #08070b;text-shadow:0 2px #1a101d;
}
.console-mode.focused{outline:2px solid #fff0bc;outline-offset:2px}
.mode-online.focused{outline-color:#e5bdff}
.console-display .home-update-status{position:absolute;z-index:4;bottom:60px;left:8px;right:8px;font-size:11px;box-shadow:0 8px 30px #000}
.menu-deck-wrap{height:var(--deck-height);flex-shrink:0;position:relative;overflow:hidden;border-radius:0 0 24px 24px;background:repeating-conic-gradient(from 45deg,#211e27 0% 25%,#14131a 0% 50%) 0 0/8px 8px}
.control-deck{position:relative;width:min(100%,calc(var(--deck-height)*1.9394));height:100%;margin:0 auto;background:url('assets/console-reference-v1.webp') center bottom/100% auto no-repeat;isolation:isolate;container-type:inline-size}
.control-deck .deck-stick,body.plane-controls .touch .control-deck #joystickGroup{position:absolute;left:11.8%;top:18.5%;width:33%;height:auto;aspect-ratio:1;z-index:2;padding:0;margin:0;flex-shrink:0;pointer-events:auto;touch-action:none}
/* The base and cap are independent circles; no baked-in cap is exposed on movement. */
.control-deck .deck-stick::before,body.plane-controls .touch .control-deck #joystick::before{content:'';position:absolute;inset:-2%;width:auto;height:auto;border-radius:50%;background:radial-gradient(circle closest-side,#100d16 0 69%,#211929 70% 74%,transparent 75% 79%,#16111d 80% 83%,transparent 84% 94%,#110d17 95% 98%,#38303f 99%),conic-gradient(from 28deg,#a794b1,#41344d 23%,#796087 48%,#221b2a 69%,#b7a3c5 89%,#a794b1);box-shadow:inset 0 2px 3px #e2d3ef66,inset 0 -4px 7px #000b,0 4px 7px #050409b8;pointer-events:none}
.control-deck .deck-knob,body.plane-controls .touch .control-deck #joystickKnob{position:absolute;left:16%;top:13%;width:68%;height:68%;margin:0;border:1px solid #79707e;border-radius:50%;background:radial-gradient(ellipse at 34% 23%,#6a626f,#45404a 34%,#2c2831 64%,#151218 95%);box-shadow:inset 0 2px 3px #d5c9df70,inset -2px -4px 6px #000b,0 2px 0 #393241,0 5px 0 #1b1620,0 8px 8px #000c;transition:filter .08s;pointer-events:none;will-change:transform}
.control-deck .deck-knob::before,body.plane-controls .touch .control-deck #joystickKnob::before{display:block;content:'';position:absolute;inset:7%;width:auto;height:auto;border-radius:50%;border:1px solid #26202c;background:radial-gradient(ellipse at 30% 16%,#d3c5dc26,transparent 67%),repeating-radial-gradient(circle closest-side,#8a81934a 0 .55px,#211d26 1px 1.8px,#5b53616b 2.3px 3px);box-shadow:inset 0 2px 4px #0008,inset 0 -2px 4px #b3a8be33;pointer-events:none}
.control-deck .deck-knob::after,body.plane-controls .touch .control-deck #joystickKnob::after{display:block;content:'';position:absolute;inset:8%;width:auto;height:auto;border-radius:50%;background:radial-gradient(ellipse at 30% 15%,#eee1ff20,transparent 65%);pointer-events:none}
.control-deck .deck-stick.active .deck-knob,body.plane-controls .touch .control-deck #joystick.active #joystickKnob{filter:brightness(1.09)}
.control-deck .deck-a,.control-deck .deck-b,.control-deck .deck-esc,body.plane-controls .touch .control-deck #flightActions button,body.plane-controls .touch .control-deck #controllerEsc{display:block;position:absolute;z-index:3;min-height:0;margin:0;padding:0;border:0;outline:0;background:transparent;box-shadow:none;border-radius:50%;color:transparent;transform:none;pointer-events:auto;touch-action:none;transition:background .06s}
.control-deck .deck-a,body.plane-controls .touch .control-deck #flightActions #fire,body.plane-controls .touch .control-deck #flightActions #mazePause{left:52%;top:31.8%;width:23%;height:auto;aspect-ratio:1}
.control-deck .deck-b,body.plane-controls .touch .control-deck #flightActions #eject,body.plane-controls .touch .control-deck #flightActions #reverse,body.plane-controls .touch .control-deck #flightActions #mazeRestart{left:72.2%;top:8%;width:23%;height:auto;aspect-ratio:1}
.control-deck .deck-esc,body.plane-controls .touch .control-deck #controllerEsc{left:7%;top:8%;width:13%;height:13%;border-radius:8%;font-size:0}
.control-deck button:active,body.plane-controls .touch .control-deck #flightActions button:active,body.plane-controls .touch .control-deck #controllerEsc:active{background:#ffffff22;box-shadow:inset 0 3px 10px #0008;transform:none}
.control-deck button:focus-visible{outline:2px solid #f4d5ff;outline-offset:3px}
body.plane-controls .touch .control-deck #flightActions button::before,body.plane-controls .touch .control-deck #flightActions button::after,body.plane-controls .touch .control-deck #controllerEsc::before{display:none}
body.plane-controls .touch .control-deck #flightActions button span{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap}
body.plane-controls .touch{top:auto;bottom:0;height:var(--deck-height);padding:0;display:block;border:0;background:repeating-conic-gradient(from 45deg,#211e27 0% 25%,#14131a 0% 50%) 0 0/8px 8px;box-shadow:0 -3px 7px #0008;overflow:hidden}
body.plane-controls .touch::before,body.plane-controls .touch::after,body.plane-controls .touch .controller-inlay,body.plane-controls .touch .joystick-hint{display:none}
body.plane-controls .touch .control-deck #joystick{position:absolute;inset:0;width:100%;height:100%;padding:0;margin:0;border:0;outline:0;border-radius:50%;background:none;box-shadow:none}
body.plane-controls .touch .control-deck .joystick-axis{display:none}
body.plane-controls .touch .control-deck #flightActions{position:absolute;inset:0;width:100%;height:100%;margin:0;padding:0;transform:none;pointer-events:none;display:block}
body.plane-controls .game-wrap{height:calc(100dvh - var(--deck-height));border:7px solid #322b3a;border-bottom-width:5px;border-radius:14px 14px 0 0;box-shadow:inset 0 0 0 1px #bdadca,0 0 0 1px #998aa5}
body.plane-controls #game{border-radius:5px 5px 0 0}
body.playing .hud{max-width:calc(100% - 28px)}
body.plane-controls #controllerEsc:disabled{opacity:.45;background:#0008}
@media(orientation:landscape){
 :root{--deck-height:36dvh}
 #home.console-shell{width:min(100%,1100px)}
 .console-display{padding:7px;gap:6px}
 .console-header{min-height:22px}
 .console-card{flex-direction:row;gap:5px;min-height:32px}
 .console-tab-icon{width:36px}
 .console-scene{min-height:50px}
 .console-mode{height:clamp(34px,6dvh,50px)}
 .scene-heading{top:6px;font-size:clamp(21px,6dvh,42px)}
 .console-scene[data-game="rally"] .scene-heading{max-width:none}
 .console-hint{font-size:7px}
}
@media(max-height:650px) and (orientation:portrait){
 .console-display{gap:6px;padding:7px}
 .console-header{min-height:22px}
 .console-card{min-height:45px}
 .console-tab-icon{width:44px}
 .console-mode{height:42px}
}
body.plane-controls .touch .control-deck #flightActions button:disabled{background:#07051066;opacity:1}
@supports(padding:env(safe-area-inset-top)){#home.console-shell{padding-top:env(safe-area-inset-top);padding-bottom:env(safe-area-inset-bottom)}body.plane-controls .touch{height:calc(var(--deck-height) + env(safe-area-inset-bottom));padding-bottom:env(safe-area-inset-bottom)}body.plane-controls .game-wrap{height:calc(100dvh - var(--deck-height) - env(safe-area-inset-bottom))}}
/* One outer casing and one recessed bezel, shared by menus and play. */
#home.console-shell, body.plane-controls #gameScreen {
  border: 1px solid var(--console-edge);
  border-radius: var(--console-radius);
  background: var(--shell-finish);
  box-shadow: inset 0 1px #c9b7da, inset 1px 0 #a695b35c, inset -1px 0 #08060c;
}
.console-display, .battle-display {
  border: 5px solid #15121c;
  border-radius: 16px;
  background: linear-gradient(145deg,#201b2a,#0e0d15 70%);
  box-shadow: 0 0 0 1px #80718d, inset 0 0 0 1px #62566e, inset 0 2px 9px #08060d;
}
body.plane-controls #gameScreen {
  --shell-gutter: var(--display-gutter);
  --frame-pad: clamp(5px,1.7vw,10px);
  --glass-inset: calc(var(--shell-gutter) + var(--frame-pad) + 5px);
}
.battle-display {
  position: absolute;
  top: calc(var(--shell-gutter) + env(safe-area-inset-top));
  left: var(--shell-gutter);
  right: var(--shell-gutter);
  bottom: calc(var(--deck-height) + env(safe-area-inset-bottom) + var(--display-joint));
  padding: var(--frame-pad);
  min-height: 0;
}
body.plane-controls .battle-display .game-wrap{position:relative;inset:auto;width:100%;height:100%;max-width:none;margin:0;border:1px solid #887292;border-radius:9px;box-shadow:inset 0 0 20px #000;overflow:hidden}
body.plane-controls .battle-display #game{display:block;width:100%;height:100%;border-radius:7px;aspect-ratio:auto}
body.plane-controls .hud{top:calc(env(safe-area-inset-top) + var(--glass-inset) + 9px);max-width:calc(100% - 2*var(--glass-inset) - 12px)}
body.plane-controls #tankScores{top:calc(env(safe-area-inset-top) + var(--glass-inset) + 43px);max-width:calc(100% - 2*var(--glass-inset) - 12px)}
body.plane-controls .touch,.menu-deck-wrap{display:grid;place-items:end center}
.control-deck{height:auto;aspect-ratio:1024/528;max-height:100%;flex-shrink:0}

body.plane-controls .touch,.menu-deck-wrap{grid-template-columns:minmax(0,1fr);grid-template-rows:minmax(0,1fr)}

/* The deck meets the bezel on a single straight joint. */
.menu-deck-wrap, body.plane-controls .touch {
  border-radius: 0;
  background: var(--deck-finish);
  box-shadow: none;
}
.control-deck {
  border-radius: 0;
  background: var(--deck-finish);
  box-shadow: inset 0 1px #aa9ab5, inset 0 2px #18151e, inset 0 -1px #5d5068;
  overflow: hidden;
}
.control-deck::before {
  content: '';
  position: absolute;
  inset: 4% 3% 12%;
  z-index: 0;
  border: 1px solid #17121e;
  border-radius: 12px;
  background: var(--carbon-finish);
  box-shadow: inset 0 2px 5px #08060dbc, inset 0 -1px #8f7a9d80, 0 1px #aaa0b16e;
}
.deck-hardware{position:absolute;inset:0;pointer-events:none;z-index:1}
.deck-screw{position:absolute;width:3.2%;aspect-ratio:1;border-radius:50%;background:radial-gradient(circle,#3f3a45 0 39%,transparent 43% 64%,#1b1620 69% 100%),conic-gradient(from 25deg,#c5bdc9,#544a5c,#9c8fa4,#38313f,#ded2e3,#c5bdc9);box-shadow:0 1px 2px #050408, inset 0 1px #dfd7e67d}
.deck-screw::after{content:'';position:absolute;left:25%;right:25%;top:45%;height:10%;background:#16111c;box-shadow:0 1px #a699af86;transform:rotate(-40deg)}
.deck-screw.tl{top:4%;left:3%}.deck-screw.tr{top:4%;right:3%}.deck-screw.bl{bottom:5%;left:3%}.deck-screw.br{bottom:5%;right:3%}
.deck-speaker{position:absolute;left:42%;bottom:3%;width:20%;height:9%;background:radial-gradient(circle,#040307 0 24%,#17131e 25% 29%,#76677f 31% 34%,transparent 37%) 0 0/8px 8px}
.deck-led{position:absolute;bottom:5%;width:12%;height:2.3%;transform:skew(-35deg);background:repeating-linear-gradient(90deg,#d6a8ff 0 10%,transparent 10% 21%);filter:drop-shadow(0 0 1.5px #bd8ce5)}
.deck-led.left{left:9%}.deck-led.right{right:9%;transform:skew(35deg)}
.deck-power{position:absolute;bottom:6%;left:66%;width:4%;height:2%;border-radius:9px;background:#ffdc7d;box-shadow:inset 0 1px #fff7ca,0 0 4px #ecad58}
/* Fixed coloured bezel; only the ribbed inner cap and its letter move. */
.control-deck :is(#menuA,#menuB).rebuilt-key,body.plane-controls .touch .control-deck #flightActions :is(#fire,#eject,#reverse,#mazePause,#mazeRestart).rebuilt-key{--rim-light:#f7d99a;--rim-mid:#c48125;--rim-dark:#744214;display:block;isolation:isolate;overflow:visible;padding:0;margin:0;border:0;outline:none;border-radius:50%;background:conic-gradient(from 28deg,var(--rim-light),var(--rim-mid) 21%,var(--rim-dark) 43%,var(--rim-light) 61%,var(--rim-dark) 78%,var(--rim-light) 100%);box-shadow:inset 0 0 0 1px #25202b,inset 0 2px 3px #fff5,0 2px 5px #050407ad;opacity:1;transform:none;filter:none;color:transparent;font-size:0}
.control-deck :is(#menuA,#menuB).rebuilt-key[data-tone="purple"],body.plane-controls .touch .control-deck #flightActions :is(#eject,#reverse,#mazeRestart).rebuilt-key{--rim-light:#e0b9ff;--rim-mid:#9b65c4;--rim-dark:#50316c}
.control-deck :is(#menuA,#menuB).rebuilt-key::before,body.plane-controls .touch .control-deck #flightActions :is(#fire,#eject,#reverse,#mazePause,#mazeRestart).rebuilt-key::before{display:block;content:'';position:absolute;inset:8%;width:auto;height:auto;border:1px solid #5c5066;border-radius:50%;clip-path:none;opacity:1;z-index:0;background:radial-gradient(ellipse at 33% 21%,#decfe032,transparent 69%),repeating-linear-gradient(0deg,#81758b38 0 .55px,transparent .55px 2px),linear-gradient(#37313c,#201b28 83%,#141018);box-shadow:inset 1px 2px 2px #c9bad270,inset 0 -3px 5px #08060d,0 0 0 1px #211a28;filter:none;transform:none;transition:transform .07s ease-out,filter .07s ease-out;pointer-events:none}
.control-deck :is(#menuA,#menuB).rebuilt-key::after,body.plane-controls .touch .control-deck #flightActions :is(#fire,#eject,#reverse,#mazePause,#mazeRestart).rebuilt-key::after{display:grid;content:attr(data-letter);position:absolute;inset:8%;width:auto;height:auto;border-radius:50%;place-items:center;background:none;opacity:1;z-index:1;color:#eddbba;font:900 italic clamp(24px,9vw,78px)/1 Arial,sans-serif;font:900 italic clamp(24px,9cqw,78px)/1 Arial,sans-serif;text-shadow:0 2px 1px #0008;clip-path:none;transform:none;transition:transform .07s ease-out;pointer-events:none}
.control-deck :is(#menuA,#menuB).rebuilt-key:is(:active,.pressed)::before,body.plane-controls .touch .control-deck #flightActions :is(#fire,#eject,#reverse,#mazePause,#mazeRestart).rebuilt-key:is(:active,.pressed)::before{transform:translateY(4%) scale(.96);filter:brightness(.84);opacity:1}
.control-deck :is(#menuA,#menuB).rebuilt-key:is(:active,.pressed)::after,body.plane-controls .touch .control-deck #flightActions :is(#fire,#eject,#reverse,#mazePause,#mazeRestart).rebuilt-key:is(:active,.pressed)::after{transform:translateY(4%) scale(.96)}
.control-deck :is(#menuA,#menuB).rebuilt-key:disabled::before,body.plane-controls .touch .control-deck #flightActions :is(#fire,#eject,#reverse,#mazePause,#mazeRestart).rebuilt-key:disabled::before{opacity:1;filter:none;transform:none}
:is(.control-deck #menuEsc,body.plane-controls .touch .control-deck #controllerEsc).rebuilt-esc{display:block;isolation:isolate;overflow:hidden;background:linear-gradient(145deg,#bcb1c6,#736579 28%,#3b3245 71%,#62536d);border:0;border-radius:10%;box-shadow:inset 0 0 0 2px #21162b;outline:none;transform:none;font-size:0}
:is(.control-deck #menuEsc,body.plane-controls .touch .control-deck #controllerEsc).rebuilt-esc::before{display:block;content:'';position:absolute;inset:12% 7%;width:auto;height:auto;border:1px solid #8a7796;border-radius:8%;background:linear-gradient(#4d434f,#2e2734 46%,#211b29 85%,#19151f);opacity:1;box-shadow:inset 0 1px #c2adc73d;transform:none;filter:none;transition:transform .07s ease-out;pointer-events:none}
:is(.control-deck #menuEsc,body.plane-controls .touch .control-deck #controllerEsc).rebuilt-esc::after{display:grid;content:'ESC';position:absolute;inset:12% 7%;place-items:center;color:#eddbba;font:800 clamp(8px,3.2vw,24px)/1 Arial,sans-serif;font:800 clamp(8px,3.2cqw,24px)/1 Arial,sans-serif;letter-spacing:1px;transform:none;transition:transform .07s ease-out;pointer-events:none}
:is(.control-deck #menuEsc,body.plane-controls .touch .control-deck #controllerEsc).rebuilt-esc:is(:active,.pressed)::before,:is(.control-deck #menuEsc,body.plane-controls .touch .control-deck #controllerEsc).rebuilt-esc:is(:active,.pressed)::after{transform:translateY(4%) scale(.97)}

/* Keep Spark Hunter scores within the outer stone border, clear of the passages. */
body.rally-controls .hud{top:calc(env(safe-area-inset-top) + var(--glass-inset) + 1px);padding:1px 6px;font-size:clamp(7px,1.1vw,9px);line-height:1.2;border-radius:3px;gap:8px}

#mazeMapPreviews[hidden]{display:none}#mazeMapPreviews{display:flex;justify-content:center;gap:12px;margin:14px auto 4px;max-width:480px}#mazeMapPreviews figure{margin:0;padding:7px;border:2px solid #526171;border-radius:10px;background:#111e2b;flex:1;min-width:0;opacity:.62}#mazeMapPreviews figure.console-selected{border-color:#e6ba67;box-shadow:0 0 14px #d7a85e44;opacity:1}#mazeMapPreviews canvas{display:block;width:auto;height:min(28dvh,240px);max-width:100%;margin:auto;image-rendering:pixelated}#mazeMapPreviews figcaption{font-size:11px;color:#ead9ba;text-align:center;padding-top:7px}#overlay.maze-picker>div{width:min(100%,620px)}#overlay.maze-picker h2{font-size:clamp(22px,5vw,36px);margin:8px 0}#overlay.maze-picker #overlayText{font-size:12px;margin:6px 0}#overlay.maze-picker .primary{padding:12px 24px;font-size:18px;margin-top:8px}@media(max-height:520px){#mazeMapPreviews{margin:4px auto;gap:8px}#mazeMapPreviews canvas{height:80px}#mazeMapPreviews figure{padding:3px}#mazeMapPreviews figcaption{font-size:9px;padding-top:2px}#overlay.maze-picker #overlayLabel,#overlay.maze-picker #overlayText{display:none}#overlay.maze-picker h2{font-size:18px;margin:2px}#overlay.maze-picker .primary{padding:5px 18px;margin-top:2px;font-size:14px}#overlay.maze-picker #overlayHint{margin:4px 0;font-size:8px}}

/* Rally timing stays readable on compact phone displays. */
body.rally-controls .hud{font-size:clamp(10px,2.7vw,13px);gap:4px 10px;flex-wrap:wrap;padding:7px 10px;max-width:calc(100% - 64px);background:#14281fe8;color:#f5e5ba}

body.rally-garage #gameScreen .hud{display:none}

/* The pause screen and room form share the console's graphite cards. */
body.tank-mode-select .hud,body.tank-mode-select #tankScores{visibility:hidden}
#overlay{background:#0a071281}
#overlay>div,.network-card{
 --metal-fill:repeating-linear-gradient(145deg,#f8e7ff08 0 1px,transparent 1px 4px),linear-gradient(155deg,#49404f,#342b3c 58%,#211a2a);
 --metal-edge:polygon(10px 0,calc(100% - 10px) 0,100% 10px,100% calc(100% - 10px),calc(100% - 10px) 100%,10px 100%,0 calc(100% - 10px),0 10px);
 position:relative;isolation:isolate;clip-path:var(--metal-edge);
 border:0;border-radius:0;padding:clamp(16px,4vw,29px);
 background:linear-gradient(135deg,#aa95b4,#54465d 48%,#86718e);
 box-shadow:none;
}
#overlay>div::before,.network-card::before{
 content:"";position:absolute;z-index:-1;inset:2px;clip-path:var(--metal-edge);
 background:var(--metal-fill);pointer-events:none;
}
#overlay>div{width:min(100%,360px)}
#overlay h2,.network-card h2{
 color:#f5eddf;text-transform:uppercase;letter-spacing:.045em;margin:0 0 14px;
 text-shadow:0 2px #1c1422;
}
#overlayLabel:empty,#overlayText:empty,#roomIntro:empty,#roomMessage:empty{display:none}
#overlay p,.network-card p{color:#ddd1de}
#overlay .pause-actions{display:grid;gap:8px;margin-top:0}
#overlay .pause-actions button,
.network-card :is(.primary,#joinRoom,#copyRoomLink){
 position:relative;isolation:isolate;clip-path:var(--metal-edge);
 border:0;border-radius:0;background:linear-gradient(#88798d,#615365 60%,#806c85);
 box-shadow:none;color:#f5eddf;text-transform:uppercase;letter-spacing:.025em;font-weight:800;
}
#overlay .pause-actions button::before,
.network-card :is(.primary,#joinRoom,#copyRoomLink)::before{
 content:"";position:absolute;inset:2px;z-index:-1;clip-path:var(--metal-edge);
 background:var(--metal-fill);pointer-events:none;
}
#overlay .pause-actions button{min-height:42px;padding:8px 12px;pointer-events:none}
#overlay .pause-actions button.console-selected,
.network-card :is(.primary,#joinRoom,#copyRoomLink).room-selected{
 background:linear-gradient(140deg,#fff0bc,#cf9b52 48%,#ffe6a5);color:#fff4d7;
}
#overlay .pause-actions button.console-selected::before,
.network-card :is(.primary,#joinRoom,#copyRoomLink).room-selected::before{inset:3px}
#overlay .console-overlay-hint{margin:12px 0 0;font-size:clamp(9px,2.4vw,12px);font-weight:700;color:#ebc887}
.network-card .network-eyebrow{display:block;margin-bottom:4px;color:#ebc887}
.network-card h2{font-size:clamp(18px,5vw,25px);line-height:1.05;margin:0 0 10px}
.network-card .room-controls-hint{font:700 clamp(8px,2.3vw,11px)/1.3 monospace;color:#ebc887;margin:10px 0 0}
.room-flight-scene.room-selected select,.join-room input.room-selected{outline:2px solid #f2cc81;outline-offset:-2px}
.console-utilities .utility-selected{outline:2px solid #f2cc81;outline-offset:1px}
.console-utilities,.battle-display,.game-toolbar button{pointer-events:none}
@media(max-height:620px){
 .network-dialog{padding:5px}
 .network-card{padding:10px 12px}
 .network-card .primary,.join-room button,#copyRoomLink{padding:5px 8px;min-height:28px}
 .join-room input{height:34px}
 .network-card h2{margin-bottom:6px}
 #roomSetup,#roomWaiting,.join-room{gap:5px}
}
.network-card :is(input,select),#createdCode{border:1px solid #86768d;background:#16111c;color:#f7d394;border-radius:4px}
#createdCode{box-shadow:inset 0 2px 5px #0a080d}
.network-card #rallyJoinStep{background:linear-gradient(#88798d,#615365 60%,#806c85)}
.network-card #rallyJoinStep.room-selected{background:linear-gradient(140deg,#fff0bc,#cf9b52 48%,#ffe6a5)}
@media(max-height:520px){#overlay>div{padding:10px 15px}#overlay h2{margin-bottom:8px;font-size:20px}#overlay .pause-actions{gap:4px}#overlay .pause-actions button{min-height:25px;padding:4px 10px}#overlay .console-overlay-hint{margin-top:5px;font-size:8px}}

body.tank-teams #teamScore0{color:#86d5ff}body.tank-teams #teamScore1{color:#ffaaa1}

/* Anchor the portrait controller to the viewport without adding a lower casing section. */
@media (max-width: 650px) and (orientation: portrait) {
  body:not(.playing) {
    background: radial-gradient(ellipse at top,#29232e,var(--bg) 72%);
  }

  body.plane-controls {
    background: var(--bg);
  }

  #home.console-shell {
    padding-bottom: 0;
  }

  body.plane-controls #gameScreen {
    height: auto;
  }

  body.plane-controls .battle-display {
    bottom: calc(var(--deck-height) + var(--display-joint));
  }

  body.plane-controls .touch {
    height: var(--deck-height);
    padding-bottom: 0;
  }

  .menu-deck-wrap .control-deck,
  body.plane-controls .touch .control-deck {
    width: 100%;
    height: 100%;
    aspect-ratio: auto;
  }

  body.plane-controls .touch .control-deck::before {
    inset: 3% 3% 0;
    border-radius: 12px 12px 0 0;
    border-bottom: 0;
    box-shadow: inset 0 1px 3px #08060d;
  }
}

#tankMineHud{display:none}
body.tank-controls:not(.tank-mode-select) #tankMineHud{
  display:flex;align-items:center;gap:5px;position:absolute;z-index:3;
  top:calc(env(safe-area-inset-top,0px) + var(--glass-inset) + 66px);
  left:calc(var(--glass-inset) + 6px);padding:2px 6px;border:1px solid #9c875e;
  border-radius:5px;color:#ffe3aa;background:linear-gradient(#393829,#21261e);box-shadow:inset 0 1px #dbc49b33,0 2px 3px #161e17b3;font:700 12px monospace;pointer-events:none;
}
#tankMineBadge{
  display:block;width:24px;height:17.25px;image-rendering:pixelated;
  filter:drop-shadow(0 1px 1px #131812);
}

@media(max-width:650px) and (orientation:portrait){
  :root{
    --phone-safe-top:env(safe-area-inset-top,0px);
    --phone-safe-bottom:env(safe-area-inset-bottom,0px);
    --phone-height:calc(var(--visible-height,100vh) - var(--phone-safe-top) - var(--phone-safe-bottom) - 8px);
  }
  @supports(height:100dvh){
    :root{--phone-height:calc(var(--visible-height,100dvh) - var(--phone-safe-top) - var(--phone-safe-bottom) - 8px)}
  }
  #home.console-shell,body.plane-controls #gameScreen{
    --deck-height:min(32vh,52vw);
    box-sizing:border-box;position:fixed;top:calc(var(--visible-top,0px) + var(--phone-safe-top) + 4px);
    bottom:auto;left:2px;right:2px;width:auto;height:var(--phone-height);margin:0;padding:0;
  }
  body.plane-controls .battle-display{top:var(--shell-gutter)}
  body.plane-controls .hud{top:calc(var(--glass-inset) + 9px)}
  body.rally-controls .hud{top:calc(var(--glass-inset) + 1px)}
  body.plane-controls #tankScores{top:calc(var(--glass-inset) + 43px)}
  body.tank-controls:not(.tank-mode-select) #tankMineHud{top:calc(var(--glass-inset) + 66px)}
  body.plane-controls #updateStatus{top:calc(var(--glass-inset) + 80px)}
}

@media(max-width:650px) and (orientation:portrait){
  #home.console-shell,body.plane-controls #gameScreen{
    --deck-height:min(32vh,52vw,calc(var(--phone-height)*.32));
  }
  .control-deck .deck-stick,body.plane-controls .touch .control-deck #joystickGroup{
    width:min(33%,calc(var(--deck-height)*.68));
  }
  .control-deck .deck-a,body.plane-controls .touch .control-deck #flightActions #fire{
    width:min(23%,calc(var(--deck-height)*.58));
  }
}

#copyRoomLink{width:100%;min-height:42px;margin-top:10px;background:#414052;color:#f5e5c9;border-radius:8px}
#roomInviteLink{width:100%;margin-top:8px;padding:8px;color:#f5e5c9;background:#10151d;border:1px solid #797087;border-radius:8px;user-select:text;touch-action:manipulation}
