/* The field stays 9:16. Menus and touch controls use the available screen. */
:root {
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
    --view-height: 100svh;
    --field-height: min(calc(var(--view-height) - var(--safe-top) - var(--safe-bottom)), calc((100vw - var(--safe-left) - var(--safe-right)) * 16 / 9), 1066.667px);
    --field-width: calc(var(--field-height) * 9 / 16);
}
* { -webkit-tap-highlight-color: transparent; }
html, body { width: 100%; height: var(--view-height); overscroll-behavior: none; }
#game-container, #game-container:fullscreen, #game-container:-webkit-full-screen {
    width: 100%; height: var(--view-height); max-width: none; max-height: none;
    aspect-ratio: auto; background: transparent; box-shadow: none;
}
#game-canvas, #ui-layer {
    position: absolute;
    width: var(--field-width); height: var(--field-height);
    left: calc(50% + (var(--safe-left) - var(--safe-right)) / 2);
    top: calc(50% + (var(--safe-top) - var(--safe-bottom)) / 2);
    transform: translate(-50%, -50%);
}
#game-canvas { box-shadow: 0 0 48px #0009; }
#ui-layer { padding: 12px; }
.hud-top { gap: 10px; align-items: start; padding: 8px 10px; border-radius: 12px; background: linear-gradient(#080e1de8, #080e1d85); }
.score-box .label, .chain-box .label-text { opacity: .8; }
.score-box .value { font-size: clamp(14px, 4.3vw, 18px); }
.chain-box > div:nth-child(2) { max-width: 60px; margin-left: auto; }
.kredits-box { padding: 4px 6px; }
.hud-bottom { padding-bottom: 8px; gap: 8px; }
#flux-container { width: 65%; height: 18px; border-color: #46536c; background: #0b1321e8; }
#flux-label { font-size: 10px; letter-spacing: 1px; white-space: nowrap; }
.lives-display { opacity: 1; color: #d8e4f8; font-weight: 600; text-shadow: 0 1px 4px #000; }
#boss-hud { max-width: calc(100% - 32px); }
#message-overlay { left: 0; font-size: clamp(18px, 5vw, 26px); }
#pause-btn {
    width: 48px; height: 48px; min-height: 48px; padding: 0; left: 12px; bottom: 14px;
    border-radius: 14px; color: #e6efff; border-color: #778dab80; background: #101c30e8;
    box-shadow: 0 3px 14px #0005; font-size: 16px; letter-spacing: 3px;
}
#mobile-controls {
    position: fixed; right: max(calc((100% - var(--field-width)) / 2 + 12px), calc(var(--safe-right) + 12px));
    bottom: calc((var(--view-height) - var(--field-height)) / 2 + 76px);
}
.touch-btn {
    width: 68px; height: 68px; min-height: 48px; padding: 6px; margin-top: 12px;
    flex-direction: column; gap: 3px; border-radius: 20px; font-size: 10px; letter-spacing: .7px;
    background: #0b172ce8; border: 1px solid #8298b775; backdrop-filter: none;
    box-shadow: 0 4px 14px #0006; touch-action: none;
}
#btn-switch { border-color: var(--polarity-color, var(--accent-a)); }
.polarity-mark { font-size: 21px; color: var(--polarity-color, var(--accent-a)); line-height: 1; }
.break-charge { font-size: 17px; font-variant-numeric: tabular-nums; line-height: 1.2; }
#btn-break[aria-disabled="true"] { color: #a0b0c8; }
#btn-break.ready { color: white; border-color: #e8edff; background: linear-gradient(135deg, #245ec5, #913649); box-shadow: 0 0 20px #88aaff60; }
#btn-break.engaged { border-color: #fff; color: #fff; }
#mobile-controls { visibility: hidden; }
body.playing:not(.paused) #mobile-controls { visibility: visible; }
body:not(.playing) #ui-layer { visibility: hidden; }
#screens, #pause-overlay, #options-overlay, #highscores-overlay {
    position: fixed; inset: 0; width: 100%; height: 100%; box-sizing: border-box;
    padding: calc(var(--safe-top) + 20px) calc(var(--safe-right) + 20px) calc(var(--safe-bottom) + 20px) calc(var(--safe-left) + 20px);
    overflow-y: auto; overscroll-behavior: contain; touch-action: pan-y;
    background: radial-gradient(ellipse at 15% 15%, #16346655, transparent 60%), radial-gradient(ellipse at 90% 90%, #691b3550, transparent 60%), #050914;
}
.screen-content, .pause-content, .opts-content, .hs-content { margin: auto; width: 100%; max-width: 440px; flex-shrink: 0; }
h1 { font-size: clamp(28px, 8vw, 42px); line-height: 1.1; margin: 0 0 12px; letter-spacing: 2px; }
.subtitle { color: #97accb; font-size: 10px; letter-spacing: 3px; margin-bottom: 20px; }
p { color: #bdc9de; font-size: 14px; line-height: 1.55; margin: 0 0 20px; }
.controls-info { color: #cfdaec; background: #15223a90; border-color: #59719960; margin-bottom: 20px; padding: 12px; line-height: 1.8; }
#touch-controls .ctrl-row { gap: 6px; margin: 4px 0; }
.gesture { min-width: 78px; flex-shrink: 0; box-sizing: border-box; }
#touch-controls .ctrl-hint { opacity: 1; color: #a8bad6; }
button { min-height: 48px; touch-action: manipulation; }
button:focus-visible { outline: 3px solid #d4eaff; outline-offset: 4px; }
#start-btn, #restart-btn, #resume-btn { width: min(100%, 300px); border-radius: 16px; }
button.fullscreen-btn, .hs-back-btn, .pause-menu-btn { border-radius: 12px; border: 1px solid #546682; background: #142037; color: #dce7fa; padding: 10px 18px; font-size: 12px; }
.opts-title, .hs-title { margin-top: 4px; }
.opts-section-label, .hs-table th { color: #a1b3ce; }
.scheme-options { gap: 8px; margin-bottom: 20px; }
.scheme-btn, .lang-btn { box-shadow: none; font-weight: 500; letter-spacing: .3px; }
.scheme-btn { padding: 10px 12px; text-align: left; }
.scheme-label { font-size: 13px; letter-spacing: .3px; }
.lang-options { margin-bottom: 16px; }
.lang-btn { padding: 10px 8px; }
.hs-table td { overflow-wrap: anywhere; }
.hs-name { max-width: 170px; letter-spacing: 1px; }
.hs-empty { color: #879ab6; }
@media (orientation: landscape) and (min-width: 600px) {
    :root { --side-width: min(190px, calc((100vw - var(--field-width)) / 2 - 28px)); }
    .hud-top { position: fixed; width: var(--side-width); box-sizing: border-box; left: calc((var(--field-width) - 100vw) / 2 + var(--safe-left) + 14px); top: 12px; display: grid; grid-template-columns: 1fr 1fr; gap: 16px 8px; }
    .chain-box { text-align: left; }
    .chain-box > div:nth-child(2) { margin-left: 0; }
    .hud-bottom { position: fixed; width: var(--side-width); left: calc((var(--field-width) - 100vw) / 2 + var(--safe-left) + 14px); bottom: 16px; }
    #flux-container { width: 90%; }
    #pause-btn { position: fixed; left: auto; right: calc((var(--field-width) - 100vw) / 2 + var(--safe-right) + 20px); top: 12px; bottom: auto; }
    #mobile-controls { right: calc(var(--safe-right) + 22px); bottom: calc(var(--safe-bottom) + 22px); }
    .touch-btn { width: 78px; height: 70px; }
    #boss-hud { top: 14px !important; }
    #overcharge-chip { top: 50px; font-size: 9px; padding: 4px 8px; letter-spacing: 1px; }
    .screen-content:has(#start-btn) { max-width: 700px; display: grid; grid-template-columns: 1.15fr 1fr; gap: 10px 24px; align-items: center; }
    .screen-content:has(#start-btn) > br { display: none; }
    .screen-content:has(#start-btn) h1, .screen-content:has(#start-btn) .subtitle, .screen-content:has(#start-btn) p, .screen-content:has(#start-btn) .controls-info { grid-column: 1; margin: 0; }
    .screen-content:has(#start-btn) h1 { font-size: 32px; }
    .screen-content:has(#start-btn) p { font-size: 12px; }
    .screen-content:has(#start-btn) .controls-info { font-size: 11px; padding: 8px 10px; }
    .screen-content:has(#start-btn) > button, .screen-content:has(#start-btn) > .mobile-hint { grid-column: 2; width: 100%; margin: 0; }
    #start-btn { grid-row: 1 / span 2; }
    #title-hs-btn { grid-row: 3; }
    #title-opts-btn { grid-row: 4; }
    .opts-content { max-width: 650px; }
    .scheme-options { display: grid; grid-template-columns: 1fr 1fr; }
    .lang-options { grid-template-columns: repeat(4, 1fr); }
    .hs-content { max-width: 600px; }
}
@media (max-height: 650px) and (orientation: portrait) {
    #screens, #pause-overlay, #options-overlay, #highscores-overlay { padding-top: calc(var(--safe-top) + 14px); padding-bottom: calc(var(--safe-bottom) + 14px); }
    .subtitle { margin-bottom: 12px; }
    p { font-size: 12px; margin-bottom: 12px; }
    .controls-info { margin-bottom: 12px; padding: 8px; font-size: 11px; }
    h1 { font-size: 30px; }
}
