.detailed-rules{margin:8px 0;border:2px solid #c9b7df;border-radius:16px;padding:8px;background:#f7f3ff;color:#263c50}
.detailed-rules summary{cursor:pointer;font-weight:900;min-height:44px;display:flex;align-items:center}
.detailed-rules[open]{max-height:280px;overflow:auto;overscroll-behavior:contain}
.detailed-rules .rule-field{display:block;margin-bottom:12px}
.detailed-rules .pill-toggle,.item-toggles{display:flex;flex-wrap:wrap;gap:5px;margin:6px 0}
.detailed-rules button,.item-toggles button{min-height:44px;min-width:44px;padding:6px 10px;font-size:12px}
.item-toggles button[aria-pressed=true]{background:#6133aa;color:white}
#queue-status{font-size:20px;font-weight:900;min-height:70px;text-align:center;line-height:1.6}
#queue-dialog{width:min(460px,calc(100% - 24px))}
#queue-dialog button{min-height:44px;width:100%;margin:8px 0;white-space:normal}
.online-choices{grid-template-columns:1fr 1fr}
#random-match{grid-column:1/-1;min-height:64px;font-size:20px}
#social-open{font-size:12px}
#social-players>div{display:flex;flex-wrap:wrap;align-items:center;gap:8px;margin:12px 0}
#social-players span{flex:1;min-width:90px;overflow-wrap:anywhere}
#social-players button{min-height:44px;font-size:12px}
#spawn-shield{position:absolute;left:50%;top:45%;transform:translate(-50%,-50%);padding:8px 16px;border:2px solid #bfffff;border-radius:24px;background:#176b8399;color:white;font-weight:900;pointer-events:none;animation:spawn-shimmer .45s ease-in-out infinite alternate}
#incoming-arcs{position:absolute;inset:0;pointer-events:none;overflow:hidden}
.incoming-arc{position:absolute;width:62px;height:62px;border-right:6px solid #ff3d54;border-radius:50%;filter:drop-shadow(0 0 8px #ed233c);transform-origin:center}
@keyframes spawn-shimmer{to{opacity:.55;box-shadow:0 0 20px #80eeff}}
#buff-shimmer.spawn-active{animation:spawn-shimmer .45s ease-in-out infinite alternate}
#rules-save-status:empty{display:none}
@media(prefers-reduced-motion:reduce){#spawn-shield,#buff-shimmer.spawn-active{animation:none}}
@media(max-width:600px){#random-match{font-size:17px}.detailed-rules[open]{max-height:230px}.detailed-rules button{padding:5px 8px}#result-dialog .result-actions #random-again{font-size:11px}}
/* All solo rules share one scroll area; the start button remains in view. */
#solo-rule-panel[open]{max-height:none;overflow:visible}
#solo-rule-panel .rules-scroll{max-height:300px;overflow-y:auto;overscroll-behavior:contain;padding:0 4px 6px}
#solo-dialog .solo-mode-cards button{min-height:86px}
#solo-dialog .solo-mode-cards .card-art{height:32px;min-height:32px}
#solo-dialog .ladder-links{margin:4px 0}
#solo-dialog .difficulty-pills{margin:4px 0}
#solo-dialog .rule-field{margin-bottom:8px}
#solo-dialog:has(#solo-rule-panel[open]) .ladder-links{display:none}
@media(max-width:600px){#solo-rule-panel .rules-scroll{max-height:270px}#solo-rule-panel{padding:3px 7px}#solo-dialog .solo-mode-cards button{font-size:12px}#solo-dialog .solo-mode-cards .card-art{height:30px;min-height:30px}}

/* Primary choices stay open. Only the panel body scrolls when more options fit
   than the viewport allows; the title and play buttons remain reachable. */
#solo-dialog[open]{display:flex;flex-direction:column;max-height:calc(100cqh - 20px);overflow:hidden;box-sizing:border-box}
#solo-dialog .dialog-head,#solo-start{flex-shrink:0}
#solo-dialog .solo-options{display:flex;flex-direction:column;min-height:0;overflow:hidden}
.setup-scroll{min-height:0;overflow-y:auto;overscroll-behavior:contain;padding:2px 5px 6px;scrollbar-gutter:stable;flex:1 1 auto}
#solo-dialog .setup-scroll{max-height:calc(100cqh - 270px)}
#solo-round{gap:4px;margin:0}
.round-settings .rule-field{margin:0!important}
#solo-round>label{flex-direction:row;align-items:center;font-size:12px;min-height:24px}
.round-settings .rule-cards{display:grid;gap:3px}
.round-settings .rule-card{font-size:12px;line-height:1.4;padding:5px 8px;margin:0}
.theme-chips{margin:3px 0;gap:4px}
.theme-chips button{min-height:44px;padding:4px 6px;flex-basis:90px}
#solo-dialog .stage-picker{margin:5px 0}
#solo-dialog .stage-picker legend{font-size:12px;margin-bottom:3px}
#solo-dialog #solo-stages{display:flex;flex-wrap:wrap;gap:4px}
#solo-dialog .stage-picker button{flex:1 1 70px;min-height:44px;padding:4px 5px;font-size:11px;border-radius:18px;justify-content:center;box-shadow:none}
#solo-dialog .stage-picker .card-art,#solo-dialog .stage-picker button::before{display:none}
.stage-rule-card{font-size:12px;line-height:1.4;text-align:left;margin:5px 0}
#solo-rule-panel{margin:4px 0;padding:2px 6px}
#solo-rule-panel[open]{max-height:none;overflow:visible}
#solo-rule-panel .rules-scroll{max-height:none;overflow:visible}
#solo-dialog .solo-mode-cards button{min-height:58px;flex-direction:row;padding:4px;gap:3px;font-size:12px}
#solo-dialog .solo-mode-cards .card-art,#solo-ladder .ladder-art{display:none}
#solo-dialog .difficulty-pills button{min-height:40px}
@container ui (min-width:700px){
 #solo-dialog{width:min(700px,calc(100cqw - 24px))}
 #solo-round{grid-template-columns:1fr 1fr;column-gap:12px}
 .round-settings .rule-cards,.round-settings .theme-chips{grid-column:1/-1}
 .round-settings .rule-cards{grid-template-columns:1fr 1fr}
}
/* Put all three main choices before their cards, even on the smallest screen. */
.setup-scroll{display:flex;flex-direction:column;gap:4px}
.setup-scroll>*{flex-shrink:0}
#solo-round{display:flex;flex-direction:column;align-items:stretch;gap:4px;order:0}
#solo-round>*{flex-shrink:0}
.setup-scroll .rule-field{order:0;flex-shrink:0}
.setup-scroll .rule-field>span{position:relative;color:#244853}
.setup-scroll .theme-chips{order:2;flex-shrink:0}
.setup-scroll .stage-picker{order:1}
.setup-scroll .rule-cards{order:3;flex-shrink:0}
.setup-scroll .round-settings>label{order:4;flex-shrink:0}
.setup-scroll details{order:6}
#solo-dialog .stage-picker button{min-height:44px}
#solo-dialog:not([data-solo-mode=cpu]) .difficulty-pills{display:none}
#solo-dialog .ladder-links button{margin:0;min-height:32px}
#solo-dialog .setup-scroll{max-height:calc(100cqh - 210px)}
/* Room shell: the body is the only scroll area in every view. */
#room-dialog{width:min(740px,calc(100cqw - 24px));padding:14px 18px;box-sizing:border-box}
#room-dialog[open]{display:flex;flex-direction:column;max-height:calc(100cqh - 24px);overflow:hidden}
#room-dialog .dialog-head{flex-shrink:0;margin:0 0 10px;padding-bottom:10px}
#room-dialog .dialog-head h2{overflow-wrap:anywhere}
#room-body{flex:1 1 auto;min-height:0;overflow-y:auto;overscroll-behavior:contain;padding:2px 6px 10px;scrollbar-gutter:stable}
#room-dialog .room-footer{flex-shrink:0;border-top:2px solid var(--ink);padding:10px 0 4px;margin-top:4px}
#room-dialog button{min-height:44px;min-width:40px;white-space:normal;overflow-wrap:anywhere;height:auto}
#room-dialog .room-entry{display:flex;flex-wrap:wrap;gap:10px;margin:12px 0}
#room-dialog #room-code{flex:1 1 100px;width:45%;min-width:0;min-height:48px;box-sizing:border-box}
#room-dialog #join-room{flex:1 1 120px}
#room-dialog #start{display:none}
#room-dialog[data-view=create] .room-entry,#room-dialog[data-view=waiting] .room-entry{display:none}
#room-dialog:not([data-view=create]) .room-create-help,#room-dialog[data-view=create] .room-join-help{display:none}
#room-dialog[data-view=waiting] .room-create-help,#room-dialog[data-view=waiting] .room-join-help{display:none}
#room-dialog[data-view=join] #room-stage-picker,#room-dialog[data-view=join] #room-share,#room-dialog:not([data-view=waiting]) #room-rules-summary{display:none}
#room-share{display:flex;flex-wrap:wrap;align-items:center;justify-content:center;gap:8px;padding:12px;margin:2px 0 6px;border:3px solid var(--ink);border-radius:18px;background:#e2d2ff;font-size:13px}
#room-share>span{display:flex;align-items:center;justify-content:center;gap:12px;width:100%;font-weight:900}
#room-number{font-size:40px;letter-spacing:3px;line-height:1.2}
#room-share button{flex:1 1 70px;font-size:13px;max-width:180px;padding:6px 8px}
#room-rules-summary{font-size:13px;font-weight:800;line-height:1.5;margin:6px 0 12px;white-space:normal;overflow-wrap:anywhere}
#room-dialog #lobby-status:empty{display:none}
#room-dialog #lobby-status{font-size:12px;margin:6px 0;overflow-wrap:anywhere}
#room-count{display:block;font-size:14px;margin:10px 0 6px}
#room-roster{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:8px;margin:6px 0 16px}
.room-player{display:grid;grid-template-columns:32px minmax(0,1fr) 18px;gap:2px 6px;align-items:center;text-align:left;border:2px solid var(--player-color);border-radius:12px;padding:8px;background:#ffffffc9;min-width:0}
.room-player canvas{width:32px;height:32px;border-radius:50%;grid-row:span 2}
.room-player b{font-size:12px;overflow-wrap:anywhere;line-height:1.4}
.room-player small{font-size:10px;grid-column:2;overflow-wrap:anywhere}
.room-player>span{grid-column:3;grid-row:1/3}
#room-stage-picker{border:0;padding:0;margin:0;min-width:0;width:100%}
#room-round{display:flex;flex-direction:column;align-items:stretch;flex-wrap:nowrap;gap:12px;margin:0}
#room-round>.rule-field,#room-round>.stage-picker,#room-capacity{display:grid;grid-template-columns:64px minmax(0,1fr);gap:4px 10px;align-items:start;border:0;padding:0;margin:0;background:transparent;min-width:0}
#room-round>.rule-field>span,#room-capacity>span{font-size:13px;font-weight:900;padding-top:10px;overflow-wrap:anywhere}
#room-round>.rule-field{order:0}
#room-round .rule-hint{grid-column:2;font-size:12px;line-height:1.5;margin:4px 0 0;overflow-wrap:anywhere}
#room-round .pill-toggle,#room-max{display:flex;flex-wrap:wrap;gap:6px;padding:0;min-width:0;width:auto}
#room-round .pill-toggle button{flex:1 1 60px;padding:6px 8px;font-size:13px}
#room-round>.theme-chips{order:1;margin:0;gap:6px;display:grid;grid-template-columns:repeat(auto-fill,minmax(128px,1fr))}
#room-round>.theme-chips[hidden]{display:none}
#room-round>.theme-chips button{min-width:0;word-break:keep-all;overflow-wrap:anywhere;line-height:1.3}
#room-round>.stage-picker{order:2;position:relative;padding-left:74px;display:block}
#room-round>.stage-picker legend{position:absolute;left:0;top:9px;width:64px;font-size:13px;font-weight:900;margin:0;padding:0;overflow-wrap:anywhere}
#room-stages{display:flex;flex-wrap:wrap;gap:6px;min-width:0}
#room-dialog #room-stages button{word-break:keep-all;overflow-wrap:anywhere;flex:1 1 80px;min-height:44px;padding:6px 8px;font-size:12px;justify-content:center;box-shadow:none}
#room-dialog #room-stages .card-art,#room-dialog #room-stages button::before{display:none}
#room-stage-card{font-size:12px;line-height:1.5;margin:6px 0 0;overflow-wrap:anywhere}
#room-capacity{order:3}
#room-round>.rule-checks{order:4;display:flex;flex-wrap:wrap;gap:4px 16px;background:#eee5ff;border-radius:12px;padding:8px 10px}
#room-round .rule-checks label{display:flex;flex-direction:row;align-items:center;gap:8px;font-size:12px;min-height:40px;margin:0;max-width:100%}
#room-round .rule-checks input{flex:0 0 auto}
#room-settings{margin:14px 0 4px;padding:2px 10px}
#room-settings[open],#room-dialog .setup-scroll{max-height:none;overflow:visible}
#room-help-cards{display:flex;flex-direction:column;gap:6px}
#room-help-cards .rule-card{font-size:12px;line-height:1.6;white-space:pre-line;margin:0;padding:8px;overflow-wrap:anywhere}
#room-rules{border:0;padding:0;background:transparent}
#room-rules .rule-field{display:block}
#room-rules .pill-toggle{flex-wrap:wrap}
.room-party-actions{display:flex;flex-wrap:wrap;gap:10px;justify-content:center}
.room-party-actions button{flex:1 1 120px;font-size:15px;margin:0}
#room-ready[aria-pressed=true]{background:#b0ffb9}
#room-start{background:var(--party-yellow)}
#room-waiting{display:flex;align-items:center;justify-content:center;gap:10px;font-size:12px;font-weight:800;margin:8px 0 0;overflow-wrap:anywhere}
#invite-panel{padding:12px;background:#fff1a1;border-radius:12px;margin-bottom:12px}
@container ui (max-width:450px){#room-dialog{padding:10px 8px}#room-roster{grid-template-columns:1fr}#room-round>.rule-field,#room-capacity{grid-template-columns:54px minmax(0,1fr);column-gap:8px}#room-round>.stage-picker{padding-left:62px}#room-round>.stage-picker legend{width:54px}}
#room-dialog button{word-break:keep-all;overflow-wrap:anywhere}

/* Word book / missions: the height must come from the UI stage (its px), not from the real window. */
#ui-stage #progress-dialog{box-sizing:border-box;width:min(880px,calc(100cqw - 16px));max-height:calc(100cqh - 16px);margin:auto}
@container ui (max-width:520px){
 #ui-stage #progress-dialog{height:calc(100cqh - 16px);padding:10px}
 #progress-dialog .dialog-head{padding-bottom:6px;margin-bottom:4px}
 #progress-dialog .dialog-head h2{font-size:20px}
 #progress-dialog .dialog-head>button{min-height:40px;padding:4px 12px}
 #progress-dialog #progress-status{margin:0;font-size:11px}
 #progress-dialog .progress-meta{flex-wrap:nowrap;gap:6px;padding:2px 0;font-size:11px}
 #progress-dialog .progress-meta>b{flex:0 1 auto;min-width:0}
 #progress-dialog .progress-meta label{flex:1 1 0;min-width:0;gap:4px;white-space:nowrap}
 #progress-dialog .progress-meta select{flex:1 1 0;min-width:0;max-width:none;min-height:40px;padding:2px 6px;font-size:13px}
 #progress-dialog #progress-tabs{flex-wrap:wrap;overflow:visible;gap:4px;padding:4px 0 6px}
 #progress-dialog #progress-tabs button{flex:1 1 30%;min-width:0;min-height:40px;padding:4px 2px;font-size:12px}
 #progress-dialog #progress-content{padding:2px 2px 8px}
}
@media (max-height:500px){
 #ui-stage #progress-dialog{width:calc(100cqw - 24px);height:calc(100cqh - 16px);padding:12px 18px}
 #progress-dialog>*{zoom:1.6}
 #progress-dialog .dialog-head{padding-bottom:4px;margin-bottom:2px}
 #progress-dialog #progress-status{margin:0}
 #progress-dialog .progress-meta{padding:0}
 #progress-dialog #progress-tabs{padding:2px 0 4px}
}
