/* Castle Workshop ("Illuminated Aerie"): tokens, fonts and the 9-slice .ui-frame come from theme.css.
   Display type only in Title Case at 28px or more; Pixelify Sans body at 12px or more; Silkscreen labels at 8px. */
#builder-panel{--bw-caret:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 5' shape-rendering='crispEdges' fill='%23f4c67b'%3E%3Crect x='0' y='0' width='10' height='1'/%3E%3Crect x='1' y='1' width='8' height='1'/%3E%3Crect x='2' y='2' width='6' height='1'/%3E%3Crect x='3' y='3' width='4' height='1'/%3E%3Crect x='4' y='4' width='2' height='1'/%3E%3C/svg%3E");--bw-orbit:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12' shape-rendering='crispEdges' fill='%23fff3cd'%3E%3Crect x='4' y='1' width='5' height='1'/%3E%3Crect x='2' y='2' width='9' height='1'/%3E%3Crect x='1' y='3' width='3' height='1'/%3E%3Crect x='9' y='3' width='3' height='1'/%3E%3Crect x='1' y='4' width='2' height='1'/%3E%3Crect x='10' y='4' width='2' height='1'/%3E%3Crect x='1' y='5' width='2' height='1'/%3E%3Crect x='10' y='5' width='2' height='1'/%3E%3Crect x='0' y='6' width='6' height='1'/%3E%3Crect x='10' y='6' width='2' height='1'/%3E%3Crect x='1' y='7' width='4' height='1'/%3E%3Crect x='9' y='7' width='3' height='1'/%3E%3Crect x='2' y='8' width='2' height='1'/%3E%3Crect x='7' y='8' width='4' height='1'/%3E%3Crect x='7' y='9' width='3' height='1'/%3E%3C/svg%3E");--bw-well:#16203b;--bw-line:#3a4c78;
 --ws-edge:16px;--ws-pt:max(var(--ws-edge),env(safe-area-inset-top,0px));--ws-pb:max(var(--ws-edge),env(safe-area-inset-bottom,0px));
 position:fixed;inset:0;z-index:10;display:grid;place-items:center;padding:var(--ws-pt) max(var(--ws-edge),env(safe-area-inset-right,0px)) var(--ws-pb) max(var(--ws-edge),env(safe-area-inset-left,0px));background:#1b2442c7;backdrop-filter:blur(3px);font-family:var(--ui-body);color:var(--ui-parchment);font-variant-ligatures:none}
#builder-panel *{box-sizing:border-box}
.builder-shell{width:min(1340px,100%);max-height:calc(100dvh - var(--ws-pt) - var(--ws-pb));overflow:auto;overscroll-behavior:contain;scroll-padding-top:120px;scroll-padding-bottom:110px;scrollbar-color:var(--ui-gold-lo) var(--ui-night)}
.builder-shell.ui-frame{background:none}

/* Controls */
#builder-panel button,#builder-panel select{font:400 13px/1.2 var(--ui-body);color:var(--ui-parchment);letter-spacing:.01em;border:2px solid var(--ui-ink);border-radius:0;padding:8px 11px;background:linear-gradient(var(--ui-raise) 0 50%,var(--ui-raise-lo) 50%);box-shadow:inset 0 2px #ffffff1f,inset 0 -2px #00000038,2px 2px 0 var(--ui-ink);cursor:pointer;touch-action:manipulation;text-shadow:1px 1px 0 var(--ui-ink)}
#builder-panel button:not(.build-cell):hover:not(:disabled),#builder-panel select:hover{background:linear-gradient(#35507e 0 50%,#2b416b 50%);color:#fff}
#builder-panel button:not(.build-cell):active:not(:disabled){transform:translate(1px,1px);box-shadow:inset 0 2px #00000038,1px 1px 0 var(--ui-ink)}
#builder-panel button:disabled{opacity:.5;cursor:default}
#builder-panel button:focus-visible,#builder-panel select:focus-visible,#builder-panel input:focus-visible,#builder-panel summary:focus-visible{outline:2px solid var(--ui-gold-hi);outline-offset:2px}
#builder-panel [aria-pressed=true]{background:linear-gradient(#3c5a8a 0 50%,#30487a 50%);color:var(--ui-gold-hi);box-shadow:inset 0 0 0 2px var(--ui-gold),2px 2px 0 var(--ui-ink)}
#builder-panel select{appearance:none;-webkit-appearance:none;padding-right:28px;background:var(--bw-caret) right 10px center/10px 5px no-repeat,linear-gradient(var(--ui-raise) 0 50%,var(--ui-raise-lo) 50%)}
#builder-panel select:hover{background:var(--bw-caret) right 10px center/10px 5px no-repeat,linear-gradient(#35507e 0 50%,#2b416b 50%)}
#builder-panel option{background:var(--ui-panel-solid);color:var(--ui-parchment)}
#builder-panel input[type=range]{accent-color:var(--ui-gold);height:18px}
#builder-panel output{color:var(--ui-gold-hi)}
#builder-panel h3,#builder-panel label,#builder-panel summary,.builder-header small,.builder-footer>div>strong,#build-count,.preview-caption,.plan-caption,.build-auto b,.build-architect b,.build-route-check b,.template-tradeoff b,.beauty-total span{font-family:var(--ui-label);font-size:12px;font-weight:400;letter-spacing:.08em;text-transform:uppercase;line-height:1.6}
#builder-panel p,#builder-panel li{font-size:12px;line-height:1.5;color:var(--ui-parchment-dim)}

/* Header, toolbar, footer */
/* style.css styles bare header/footer as fixed, click-through page chrome; the workshop's own are in-flow. */
.builder-header,.builder-footer{pointer-events:auto;left:auto;right:auto}
.builder-header{position:sticky;top:0;z-index:4;display:flex;align-items:center;gap:16px;padding:12px 20px 12px;background:var(--ui-panel-solid);border-bottom:2px solid var(--ui-ink);box-shadow:0 2px 0 var(--ui-gold-lo)}
.builder-header small{color:var(--ui-gold)}
.builder-header h2{margin:0;font-family:var(--ui-display);font-size:44px;font-weight:400;line-height:1;letter-spacing:.02em;color:var(--ui-parchment);text-shadow:3px 3px 0 var(--ui-ink)}
#builder-panel .builder-header p{margin:4px 0 0;font-size:12px;color:var(--ui-dawn)}
#builder-panel #close-builder{margin-left:auto;align-self:flex-start;width:40px;height:40px;padding:0;font-size:22px;line-height:1}
.builder-toolbar{display:flex;flex-wrap:wrap;align-items:flex-end;gap:12px 16px;padding:12px 20px 14px;background:var(--ui-night);border-bottom:2px solid var(--ui-ink)}
.builder-toolbar label{display:block;color:var(--ui-gold)}
#builder-panel .builder-toolbar select{display:block;margin-top:5px;min-width:150px}
.builder-toolbar .build-level-control{width:180px}
.build-level-control output{float:right;font-family:var(--ui-body);font-size:13px;letter-spacing:0}
.build-level-control input{display:block;width:100%;margin:6px 0 2px}
#build-plot-size{display:block;font-family:var(--ui-body);font-size:12px;letter-spacing:0;text-transform:none;color:var(--ui-parchment-dim)}
.unlock-badge{margin-left:auto;align-self:center;padding:5px 9px;font-size:12px;color:var(--ui-good);border:2px solid var(--ui-ink);background:#1f3a3d;box-shadow:inset 0 0 0 1px #9fe8a640}
.mobile-build-tools{display:none}
.builder-footer{position:sticky;bottom:0;z-index:3;display:flex;justify-content:flex-end;align-items:center;gap:10px;padding:12px 20px;background:var(--ui-panel-solid);border-top:2px solid var(--ui-ink);box-shadow:0 -2px 0 var(--ui-gold-lo)}
.builder-footer>div{margin-right:auto;display:flex;flex-direction:column;gap:3px;min-width:0}
.builder-footer>div>strong{color:var(--ui-gold)}
#build-apply-hint{font-size:12px;color:var(--ui-parchment-dim)}
#build-apply-hint[data-result=pass]{color:var(--ui-good)}
#build-apply-hint[data-result=fail]{color:#f1bd8a}
#builder-panel #build-apply{min-width:150px;padding:11px 18px;font-size:16px;font-weight:700;color:var(--ui-ink);text-shadow:none;background:linear-gradient(var(--ui-gold-hi) 0 3px,var(--ui-gold) 3px 62%,#d9a85c 62%);box-shadow:inset 0 -3px #8a5f2a,3px 3px 0 var(--ui-ink)}
#builder-panel #build-apply:hover:not(:disabled){background:linear-gradient(#fff0c8 0 3px,var(--ui-gold-hi) 3px 62%,var(--ui-gold) 62%)}

/* Three columns: parts, live plan, castle character */
.builder-body{display:grid;grid-template-columns:minmax(260px,288px) minmax(0,1fr) minmax(204px,232px);gap:16px;padding:16px 20px}
.builder-tools,.builder-plan,.builder-progress{min-width:0}
.builder-body h3{margin:0 0 8px;color:var(--ui-gold)}
#build-parts{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:5px}
#builder-panel #build-parts button{display:flex;align-items:center;gap:6px;min-width:0;min-height:44px;padding:4px 5px;text-align:left}
#build-parts .part-icon{flex:none;width:32px;height:32px;background:var(--part-icon) center/32px 32px no-repeat;image-rendering:pixelated}
#build-parts b{min-width:0;font-weight:400;font-size:12px;line-height:1.15;overflow-wrap:normal}
#builder-panel #build-rotate{width:100%;margin-top:8px;display:flex;justify-content:space-between;align-items:center}
#build-rotate span{color:var(--ui-gold-hi)}
#builder-panel #build-help{margin:10px 0 0;min-height:54px}
.builder-presets{margin-top:16px;padding-top:12px;border-top:2px solid var(--ui-ink);box-shadow:inset 0 1px 0 var(--bw-line)}
#builder-panel .builder-presets button{display:block;width:100%;margin-top:5px;padding:7px 10px;text-align:left}
/* Undo and Redo share a row in the side column (phones give them their own row below Clear draft; the pageant session row is flex). */
@media(min-width:601px){#builder-panel:not([data-session]) .builder-presets :is(#build-undo,#build-redo){display:inline-block;vertical-align:top;width:calc(50% - 3px);text-align:center}#builder-panel:not([data-session]) .builder-presets #build-redo{margin-left:6px}}
#builder-panel .legacy-starters{margin-top:14px;color:var(--ui-parchment-dim)}
#builder-panel #build-open-library{color:var(--ui-gold-hi);box-shadow:inset 0 0 0 1px var(--ui-gold-lo),2px 2px 0 var(--ui-ink)}

.builder-view-tabs{display:flex;align-items:center;gap:6px;flex-wrap:wrap;margin-bottom:10px}
#build-count{margin-left:auto;color:var(--ui-parchment-dim);white-space:nowrap}
.build-visual-row{display:block}
.build-preview-wrap{position:relative;min-width:0;border:2px solid var(--ui-ink);background:var(--bw-well);box-shadow:0 0 0 2px var(--ui-gold-lo),4px 4px 0 2px var(--ui-ink)}
.preview-caption{position:absolute;left:8px;right:8px;top:8px;display:flex;justify-content:space-between;gap:7px;pointer-events:none}
.preview-caption>span{padding:3px 7px;color:var(--ui-parchment);background:#231a2ed9;border:1px solid var(--ui-gold-lo)}
#build-preview{display:block;width:100%;height:clamp(340px,50dvh,520px);image-rendering:pixelated;touch-action:none;cursor:crosshair}
#build-preview:focus-visible{outline:2px solid var(--ui-gold-hi);outline-offset:2px}
.preview-camera{position:absolute;bottom:8px;left:50%;transform:translateX(-50%);display:flex;gap:6px;white-space:nowrap}
#builder-panel .preview-camera button{padding:6px 10px;font-size:12px}
#builder-panel .preview-camera #build-orbit-left,#builder-panel .preview-camera #build-orbit-right{width:34px;padding:6px 0;display:grid;place-items:center}
.orbit-icon{display:block;width:12px;height:12px;background:var(--bw-orbit) center/12px 12px no-repeat;image-rendering:pixelated}
#build-orbit-right .orbit-icon{transform:scaleX(-1)}
.preview-instructions{display:flex;justify-content:space-between;gap:10px;margin-top:10px;font-size:12px;color:var(--ui-parchment-dim);line-height:1.4}
.preview-instructions>span:last-child{text-align:right}
#build-selected{color:var(--ui-parchment)}
#builder-panel .build-note{font-size:12px;color:var(--ui-parchment-dim)}
#build-status{min-height:36px;margin-top:10px;font-size:13px;line-height:1.5;color:var(--ui-gold-hi)}

/* Simplified grid */
#builder-panel[data-editor-view=simple] .build-visual-row{display:flex;flex-direction:column;gap:14px}
#builder-panel[data-editor-view=simple] #build-grid-wrap{order:-1}
#builder-panel[data-editor-view=simple] #build-preview{height:clamp(220px,32dvh,320px)}
#build-grid-wrap{min-width:0}
.plan-caption{display:flex;justify-content:space-between;gap:10px;margin-bottom:8px;color:var(--ui-parchment-dim)}
.plan-caption:last-of-type{margin:8px 0}
.build-grid-scroll{overflow:auto;max-width:100%;padding:3px 8px 9px 3px}
#build-grid{display:flex;flex-direction:column;gap:2px;aspect-ratio:1;min-width:calc(var(--grid-size,12)*22px + 12px);max-width:calc(var(--grid-size,12)*40px + 12px);margin:0 auto;padding:3px;border:2px solid var(--ui-ink);background:var(--bw-well);box-shadow:0 0 0 2px var(--ui-gold-lo),3px 3px 0 2px var(--ui-ink)}
#build-grid>[role=row]{display:grid;grid-template-columns:repeat(var(--grid-size,12),minmax(0,1fr));gap:2px;flex:1;min-height:0}
#builder-panel .build-cell{min-width:0;min-height:0;padding:0;border:1px solid #2f3f66;border-radius:0;background:#1f2b4d;box-shadow:none;text-shadow:none;font-size:12px;line-height:1;color:#5b6b95;transform:none}
#builder-panel .build-cell.occupied,#builder-panel .build-cell.below{background:var(--part-icon) center/16px 16px no-repeat,#2c3d66;image-rendering:pixelated;border-color:#5a6f9c}
#builder-panel .build-cell.below{opacity:.45;background-color:#1f2b4d}
#builder-panel .build-cell:hover,#builder-panel .build-cell:focus-visible{background-color:#4a5f8f;outline:2px solid var(--ui-gold);outline-offset:0;z-index:1}
#builder-panel .build-cell[data-rotation="1"]{border-right:3px solid var(--ui-gold)}
#builder-panel .build-cell[data-rotation="2"]{border-bottom:3px solid var(--ui-gold)}
#builder-panel .build-cell[data-rotation="3"]{border-left:3px solid var(--ui-gold)}
/* Plot numbers (castle-builder.js makeGrid) show on touch screens only, pinned while the plan scrolls. */
#build-grid .grid-axis-row,#build-grid .grid-axis{display:none}

/* Inset sections */
.build-auto,.build-architect,.build-route-check,#build-adjustments,#build-library{margin-top:12px;padding:10px 12px;border:2px solid var(--ui-ink);background:var(--bw-well);box-shadow:inset 0 0 0 1px var(--bw-line)}
.build-auto{display:flex;gap:10px;align-items:baseline;font-size:12px;line-height:1.5;color:var(--ui-parchment-dim)}
.build-auto b{color:var(--ui-gold);white-space:nowrap}
#build-adjustments{margin-top:6px}
#build-adjustments summary{cursor:pointer;color:var(--ui-dawn)}
#build-adjustments summary span{font-family:var(--ui-body);font-size:12px;letter-spacing:0;text-transform:none;color:var(--ui-parchment-dim)}
#build-adjustments ul,.build-architect ul{padding-left:18px;margin:8px 0 0}
#build-adjustments li{margin-top:4px}
.build-architect{box-shadow:inset 0 0 0 1px var(--ui-gold-lo)}
.build-architect>div,.build-route-check>div:first-child{display:flex;align-items:center;gap:8px;flex-wrap:wrap}
.build-architect b{margin-right:auto;color:var(--ui-gold)}
.build-route-check b{color:var(--ui-dawn)}
.build-route-check>div:first-child{justify-content:space-between}
#builder-panel .build-architect p,#builder-panel .build-route-check p{margin:8px 0}
#builder-panel .build-ai-scope,#builder-panel .build-route-scope{margin-bottom:0;font-size:12px;color:#9ba3c9}
#build-route-summary[data-result=pass],#build-protector-status[data-result=pass]{color:var(--ui-good)!important}
#build-route-summary[data-result=fail],#build-protector-status[data-result=fail]{color:#f1bd8a!important}
#build-route-progress{height:4px;overflow:hidden;background:var(--ui-raise-lo);border:1px solid var(--ui-ink)}
#build-route-progress i{display:block;width:35%;height:100%;background:var(--ui-dawn);animation:route-scan 1.3s infinite steps(8) alternate}
#build-route-issues{list-style:none;padding:0;margin:0}
#build-route-issues li{margin-top:6px}
#builder-panel #build-route-issues button{display:block;width:100%;text-align:left;font-size:12px;line-height:1.45;color:#f3cea6;background:linear-gradient(#3e3a4f 0 50%,#35304a 50%)}
@keyframes route-scan{to{transform:translateX(186%)}}

/* Castle character */
.builder-progress{align-self:start;padding:12px;border:2px solid var(--ui-ink);background:var(--bw-well);box-shadow:inset 0 0 0 1px var(--bw-line)}
.beauty-total{display:flex;align-items:center;gap:10px;margin:8px 0 4px}
.beauty-total output{font:700 44px/1 var(--ui-body);color:var(--ui-gold-hi);text-shadow:3px 3px 0 var(--ui-ink)}
.beauty-total span{color:var(--ui-parchment-dim)}
#build-beauty-title{display:block;margin-bottom:12px;font-size:14px;font-weight:700;color:var(--ui-dawn)}
.beauty-category{margin:8px 0}
.beauty-category>div{display:flex;justify-content:space-between;gap:6px;font-size:12px;color:var(--ui-parchment)}
.beauty-category b{font-weight:400;white-space:nowrap;color:var(--ui-gold)}
.beauty-category i{display:block;height:6px;margin-top:3px;background:var(--ui-raise-lo);border:1px solid var(--ui-ink)}
.beauty-category em{display:block;height:100%;background:var(--ui-dawn)}
#build-beauty-tips{padding-left:16px;margin:12px 0}
#build-beauty-tips li{margin:6px 0}
#build-beauty-bonuses p{color:var(--ui-gold-hi)!important;border-left:2px solid var(--ui-gold-lo);padding-left:8px}
.build-progression{margin-top:12px;padding-top:10px;border-top:2px solid var(--ui-ink);box-shadow:inset 0 1px 0 var(--bw-line)}
.build-progression summary{cursor:pointer;padding:4px 0;color:var(--ui-gold)}
#build-level-layers{display:flex;gap:3px;margin:10px 0}
#build-level-layers i{flex:1;height:14px;background:var(--ui-raise-lo);border:1px solid var(--ui-ink)}
#build-level-layers i.earned{background:var(--ui-dawn);box-shadow:inset 0 2px #ffffff55}
#build-layer-rule{font-size:12px;color:var(--ui-parchment)}

/* Template atlas */
#build-library{margin:0 0 14px;padding:12px;box-shadow:inset 0 0 0 1px var(--ui-gold-lo)}
.template-heading{display:flex;justify-content:space-between;align-items:center;gap:12px}
.template-heading small{font-family:var(--ui-label);font-size:12px;letter-spacing:.08em;text-transform:uppercase;color:var(--ui-gold)}
#builder-panel .template-heading h3{margin:4px 0 0;font-family:var(--ui-display);font-size:32px;line-height:1;letter-spacing:.02em;text-transform:none;color:var(--ui-parchment);text-shadow:3px 3px 0 var(--ui-ink)}
#builder-panel .template-heading>button{width:36px;height:36px;padding:0;font-size:20px}
.template-level-label{display:flex;align-items:center;gap:12px;margin:12px 0;color:var(--ui-gold)}
#builder-panel .template-level-label select{flex:1;text-transform:none;letter-spacing:.01em}
#build-template-cards{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:10px}
.template-card{min-width:0;display:flex;flex-direction:column;border:2px solid var(--ui-ink);background:var(--ui-raise-lo);box-shadow:inset 0 0 0 1px var(--bw-line),2px 2px 0 var(--ui-ink)}
.template-card canvas{display:block;width:100%;height:auto;max-height:170px;object-fit:contain;image-rendering:pixelated;background:#16203b;border-bottom:2px solid var(--ui-ink)}
.template-card-copy{flex:1;display:flex;flex-direction:column;padding:10px}
.template-card h4{margin:0 0 6px;font-size:14px;font-weight:700;color:var(--ui-gold-hi)}
#builder-panel .template-role{margin:0 0 6px;color:var(--ui-dawn)}
#builder-panel .template-stats{margin:0 0 8px;color:var(--ui-parchment-dim)}
#builder-panel .template-tradeoff{margin:3px 0}
.template-tradeoff b{display:block;color:var(--ui-gold)}
#builder-panel .template-card button{width:100%;margin-top:auto;padding:8px 6px;color:var(--ui-gold-hi)}
#builder-panel .template-legend{margin-bottom:0}

/* Wide screens: a roomier preview */
@media(min-width:1600px){.builder-shell{width:min(1480px,100%)}.builder-body{grid-template-columns:300px minmax(0,1fr) 248px}#build-preview{height:clamp(380px,54dvh,600px)}}

/* Tablet: the character panel moves below */
@media(max-width:1100px){#build-template-cards{grid-template-columns:1fr}.template-card{display:grid;grid-template-columns:110px minmax(0,1fr)}.template-card canvas{align-self:stretch;height:100%;border-bottom:0;border-right:2px solid var(--ui-ink)}#builder-panel .template-card button{margin-top:8px}.template-tradeoff b{display:inline}}
@media(max-width:960px){.builder-body{grid-template-columns:minmax(250px,270px) minmax(0,1fr)}
 .builder-progress{grid-column:1/-1;align-self:stretch}
 .builder-progress #build-beauty-bars{display:grid;grid-template-columns:1fr 1fr;gap:0 24px}
}

/* Phone: one column, quick part picker in the toolbar */
@media(max-width:600px){#builder-panel{--ws-edge:6px}
 .builder-shell.ui-frame{border-width:8px;border-image-width:8px}
 .builder-header{padding:10px 12px;gap:10px}
 .builder-header h2{font-size:32px}
 .builder-toolbar{padding:10px 12px;gap:10px;align-items:flex-start}
 #builder-panel .builder-toolbar select{min-width:0;width:100%}
 .builder-toolbar>label{flex:1 1 140px;min-width:0}
 .builder-toolbar .build-level-control{flex:1 1 140px;width:auto}
 .unlock-badge{margin-left:0;width:100%;text-align:center}
 .mobile-build-tools{display:flex;align-items:flex-end;gap:8px;width:100%}
 .mobile-build-tools label{flex:1;min-width:0}
 #builder-panel .mobile-build-tools button{flex:none}
 .builder-body{display:flex;flex-direction:column;gap:14px;padding:12px}
 .builder-plan{order:-1}
 #build-parts{grid-template-columns:repeat(3,minmax(0,1fr))}
 #builder-panel #build-parts button{flex-direction:column;justify-content:flex-start;gap:3px;padding:6px 3px;text-align:center}
 #build-parts b{font-size:12px}
 #builder-panel #build-help{min-height:0}
 .builder-presets{display:flex;flex-wrap:wrap;gap:5px;margin-top:10px;padding-top:10px}
 .builder-presets h3{width:100%;margin:0}
 #builder-panel .builder-presets button{width:auto;margin:0;padding:7px 9px}
 /* Clear draft takes its own row so Undo and Redo always start a fresh one and split it evenly (Redo never wraps alone) */
 #builder-panel:not([data-session]) .builder-presets #build-clear{flex:1 1 100%}
 #builder-panel:not([data-session]) .builder-presets :is(#build-undo,#build-redo){flex:1 1 calc(50% - 3px);min-width:0;text-align:center}
 .builder-view-tabs{gap:5px}
 #builder-panel .builder-view-tabs button{padding:7px 9px}
 #build-preview{height:330px}
 .preview-instructions{display:block}
 .preview-instructions>span{display:block}
 .preview-instructions>span:last-child{text-align:left;margin-top:2px}
 .preview-caption{left:5px;right:5px;top:5px}
 .builder-progress #build-beauty-bars{display:block}
 .template-card{grid-template-columns:80px minmax(0,1fr)}
 .template-level-label{display:block}
 #builder-panel .template-level-label select{display:block;width:100%;margin-top:6px}
 .builder-footer{flex-wrap:wrap;gap:8px;padding:10px 12px}
 .builder-footer>div{width:100%}
 #builder-panel #build-apply{flex:1;min-width:0}}

/* Short landscape screens */
@media(max-height:600px) and (min-width:601px){#builder-panel{--ws-edge:8px}
 .builder-header{padding:8px 18px}
 .builder-header h2{font-size:32px}
 #builder-panel .builder-header p{display:none}
 .builder-toolbar{padding:8px 18px 10px}
 .builder-body{padding:12px 18px}
 .builder-footer{padding:8px 18px}
 #build-preview{height:clamp(240px,60dvh,360px)}}
/* Desktop 720p-class screens: the live preview and its camera row fit between the toolbar and the sticky footer
   (header + toolbar + tabs + footer take about 400px with the 16px edges; safe-area insets come off too), so Fit and
   the orbit buttons are never under the footer. */
@media(min-width:961px){#build-preview{height:clamp(240px,calc(100dvh - 368px - var(--ws-pt) - var(--ws-pb)),520px)}}
@media(min-width:1600px){#build-preview{height:clamp(240px,min(54dvh,calc(100dvh - 368px - var(--ws-pt) - var(--ws-pb))),600px)}}
/* Short landscape phones: one-line header, no footer hint, one-line view tabs, preview sized to the space left, its
   camera buttons in the bottom-right corner (a centred bar would cover a quarter of the castle). main.js scrolls the
   toolbar just out of view on open when the preview would still sit under the footer (it is one swipe up). */
@media(max-height:500px) and (min-width:601px){.builder-header{padding:4px 14px;gap:10px}
 .builder-header small,#builder-panel .builder-header p{display:none}
 .builder-header h2{font-size:28px}
 .unlock-badge{display:none}
 .builder-body{padding:8px 14px;gap:12px}
 .builder-view-tabs{margin-bottom:6px;flex-wrap:nowrap;gap:4px}
 #builder-panel .builder-view-tabs button{padding-left:9px;padding-right:9px;white-space:nowrap}
 #build-count{min-width:0;overflow:hidden;text-overflow:ellipsis}
 .preview-camera{left:auto;right:8px;transform:none}
 .builder-footer{padding:6px 14px}
 #build-apply-hint{display:none}
 #build-preview{height:clamp(160px,calc(100dvh - 198px - var(--ws-pt) - var(--ws-pb)),360px)}}
/* Short portrait phones: same compaction; the footer keeps only its two buttons. */
@media(max-width:600px) and (max-height:700px){.builder-header{padding:6px 12px}
 .builder-header small,#builder-panel .builder-header p{display:none}
 .builder-header h2{font-size:28px}
 .builder-footer>div{display:none}
 #build-preview{height:clamp(200px,calc(100dvh - 288px - var(--ws-pt) - var(--ws-pb)),330px)}}
/* The shell's scroll padding is the real sticky header / footer height at every width (castle-builder.js measures
   --ws-head and --ws-foot), so focus or scrollIntoView never leaves a control under the footer (a phone footer whose
   hint wraps is 122px). */
.builder-shell{scroll-padding-top:calc(var(--ws-head,112px) + 8px);scroll-padding-bottom:calc(var(--ws-foot,102px) + 8px)}
/* Side-by-side layouts: the parts column is a sticky sidebar that scrolls on its own (castle-builder.js measures
   --ws-head, --ws-foot, --ws-side and --ws-tuck), so choosing Castle heart, Protector core or Erase never scrolls the
   preview away. Until it sticks it is shorter by --ws-tuck, so it never reaches under the footer. Tabbing to a part
   scrolls the list, not the shell. */
@media(min-width:601px){.builder-tools{position:sticky;top:calc(var(--ws-head,0px) + 8px);align-self:start;max-height:max(160px,calc(var(--ws-side,100dvh) - var(--ws-tuck,0px)));overflow-y:auto;scrollbar-width:thin;margin:-2px -6px -4px -2px;padding:2px 6px 4px 2px}}
@media(min-width:601px) and (pointer:fine){.builder-tools{overscroll-behavior:contain}}
/* Touch plan: 34px plots in a box that scrolls both ways, plot numbers pinned along the top and left (its scroll padding
   keeps a focused plot clear of them); it opens centred on the castle heart. */
@media(pointer:coarse){.build-grid-scroll{max-height:min(60dvh,460px);padding:0;scroll-padding:24px 0 0 26px;border:2px solid var(--ui-ink);background:var(--bw-well);box-shadow:0 0 0 2px var(--ui-gold-lo)}
 #build-grid{width:max-content;min-width:0;max-width:none;aspect-ratio:auto;margin:0;padding:0 3px 3px 0;border:0;box-shadow:none}
 #build-grid>[role=row],#build-grid>.grid-axis-row{display:flex;gap:2px;flex:none}
 #builder-panel .build-cell{flex:0 0 34px;height:34px}
 #build-grid .grid-axis{display:grid;place-items:center;flex:0 0 26px;height:34px;position:sticky;left:0;z-index:2;font:700 12px/1 var(--ui-body);font-style:normal;color:var(--ui-parchment-dim);background:var(--bw-well);box-shadow:2px 0 0 var(--ui-ink)}
 #build-grid .grid-axis-row{position:sticky;top:0;z-index:3;background:var(--bw-well);box-shadow:0 2px 0 var(--ui-ink)}
 #build-grid .grid-axis-row .grid-axis{flex-basis:34px;height:24px;position:static;box-shadow:none}
 #build-grid .grid-axis-row .grid-axis:first-child{flex-basis:26px;position:sticky;left:0;z-index:4}}
/* Touch: every workshop control is at least 44px (plan cells excepted: they scale with the plot grid). */
@media(pointer:coarse){#builder-panel button:not(.build-cell),#builder-panel select{min-height:44px}
 #builder-panel #close-builder,#builder-panel .template-heading>button{width:44px;height:44px}
 #builder-panel .preview-camera button{min-height:44px}
 #builder-panel .preview-camera #build-orbit-left,#builder-panel .preview-camera #build-orbit-right{width:44px}
 .orbit-icon{width:16px;height:16px;background-size:16px 16px}
 #builder-panel summary{min-height:44px;padding-top:14px}
 #builder-panel input[type=range]{height:44px}
 /* The 8px Silkscreen captions (tool headings, field labels, counts, panel titles) become 12px bold body text. */
 #builder-panel h3,#builder-panel label,#builder-panel summary,.builder-header small,.builder-footer>div>strong,#build-count,.preview-caption,.plan-caption,.build-auto b,.build-architect b,.build-route-check b,.template-tradeoff b,.beauty-total span,.template-heading small{font-family:var(--ui-body);font-size:12px;font-weight:700;letter-spacing:.04em;line-height:1.35}}
/* Workshop placement feedback (castle-builder.js): a refused edit shows a red message over the bottom of the live
   preview. Absolutely placed (no layout shift), 13-14px body text, a short shake unless reduced motion is preferred. */
#builder-panel #build-error{position:absolute;left:8px;right:8px;bottom:46px;z-index:2;width:fit-content;max-width:calc(100% - 16px);margin:0 auto;padding:7px 12px;font-family:var(--ui-body);font-size:13px;line-height:1.35;color:#fff3ef;text-align:center;background:#5a1622f2;border:2px solid var(--ui-bad);box-shadow:var(--ui-shadow);text-shadow:1px 1px 0 var(--ui-ink);pointer-events:none;opacity:0;visibility:hidden;transition:opacity .15s steps(3),visibility 0s linear .15s}
#builder-panel #build-error.float{bottom:auto;z-index:30}
/* Placed / erased (.ok) and tap-to-aim (.aim) notes share the slot: gold, never shaking. Where the slot would cover the
   aimed tile, the placed piece or the refused plot, castle-builder.js moves the note to the preview top (.top, inline top). */
#builder-panel #build-error.top{bottom:auto}
#builder-panel #build-error.note{color:var(--ui-parchment);background:var(--ui-panel);border-color:var(--ui-gold)}
#builder-panel #build-error.ok{background:#5b4214f2;border-color:var(--ui-gold-hi)}
#builder-panel #build-error.show{opacity:1;visibility:visible;transition:opacity .08s steps(2)}
@media(prefers-reduced-motion:no-preference){#builder-panel #build-error.shake{animation:build-error-shake .36s steps(2,end)}}
@keyframes build-error-shake{0%,100%{transform:translateX(0)}17%{transform:translateX(-7px)}33%{transform:translateX(6px)}50%{transform:translateX(-5px)}67%{transform:translateX(4px)}83%{transform:translateX(-2px)}}
#build-count.full{color:var(--ui-bad)}
/* The hover line under the preview stays one line (it changes on every hover), so nothing below it moves. */
#build-selected{flex:1 1 auto;min-width:0;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
@media(pointer:coarse){#builder-panel #build-error{bottom:60px;font-size:14px}}
/* Short landscape phones: a gold note is one line (every part name fits at 667 px), a strip clear of its target. */
@media(pointer:coarse) and (max-height:500px){#builder-panel #build-error.note{padding:5px 10px;font-size:13px}}
/* Short screens: a red refusal is at most two lines, so it never covers most of the preview (castle-builder.js lends it the parts
   column's width when the preview is too narrow for the whole reason, and a third line, .long, where there is no column to lend);
   the shake stays and the full reason is in #build-status. The clamp clips at the padding box, so the 5px above and below the text
   are a transparent border over the note's own background (the red frame is an inset outline): no clipped line's tops show. */
@media(max-height:500px){#builder-panel #build-error:not(.note){display:-webkit-box;-webkit-box-orient:vertical;-webkit-line-clamp:2;line-clamp:2;overflow:hidden;padding:0 10px;font-size:13px;border:solid transparent;border-width:7px 2px;outline:2px solid var(--ui-bad);outline-offset:-2px}
 #builder-panel #build-error.long:not(.note){-webkit-line-clamp:3;line-clamp:3}}
/* Seamless menus (Battlefield 1 style, with game-shell.css and main.js's camera director): the Workshop fades in over the
   camera glide to the Dawn castle and leaves as an inert ghost (.shell-out, already [hidden]). Its children only fade (no
   movement), so fitWorkshop's layout measurements stay exact. Reduced motion: instant. */
@keyframes ws-fade-in{from{opacity:0}}
@keyframes ws-fade-out{to{opacity:0}}
@keyframes ws-sheet-in{from{opacity:0;translate:0 24px}}
@keyframes ws-sheet-out{to{opacity:0;translate:0 20px}}
@media (prefers-reduced-motion:no-preference){
 #builder-panel:not([hidden]){animation:ws-fade-in .5s ease-out both}
 #builder-panel:not([hidden]) .builder-shell{animation:ws-sheet-in .55s .18s cubic-bezier(.2,.8,.2,1) both}
 #builder-panel:not([hidden]) .builder-shell>*{animation:ws-fade-in .45s ease-out both;animation-delay:.3s}
 #builder-panel:not([hidden]) .builder-shell>:nth-child(2){animation-delay:.36s}#builder-panel:not([hidden]) .builder-shell>:nth-child(3){animation-delay:.42s}#builder-panel:not([hidden]) .builder-shell>:nth-child(n+4){animation-delay:.48s}
 #builder-panel.shell-out{animation:ws-fade-out .34s ease-in both}
 #builder-panel.shell-out .builder-shell{animation:ws-sheet-out .34s ease-in both}
}
/* Pageant session (castle-builder openSession, pageant DESIGN §4): the session's hide list (data-session-hide) removes the
   Dawn/Dusk choice, land level, template library, starters, architect and restore; Clear and Undo stay. The session strip
   (pageant-ui fills it) sits in the sticky header between the title and the close button, on its own row on phones; the
   Judge's notes panel tops the progress column (right column on desktop, below the preview on phones). */
#builder-panel[data-session-hide~=home] label:has(>#build-home),#builder-panel[data-session-hide~=level] :is(.build-level-control,.build-progression),#builder-panel[data-session-hide~=templates] :is(#build-view-library,#build-open-library,#build-library),#builder-panel[data-session-hide~=starters] :is(.builder-presets>:not(#build-clear,#build-undo,#build-redo),.builder-tools>p:last-child),#builder-panel[data-session-hide~=architect] .build-architect,#builder-panel[data-session-hide~=restore] #build-restore,#builder-panel[data-session] .unlock-badge{display:none!important}
#builder-panel[data-session] .builder-presets{display:flex;flex-wrap:wrap;gap:6px}
#builder-panel[data-session] .builder-presets button{flex:1 1 0;width:auto;margin:0}
#builder-panel #build-session-strip{order:1;flex:1 1 auto;min-width:0;display:flex;justify-content:flex-end;align-items:center}
#builder-panel[data-session] #close-builder{order:2;margin-left:0}
#builder-panel #build-session-panel{margin:0 0 12px}
#builder-panel #build-session-strip:empty,#builder-panel #build-session-panel:empty{display:none}
@media(max-width:600px){#builder-panel[data-session] .builder-header{flex-wrap:wrap;row-gap:6px}
 #builder-panel #build-session-strip{order:3;flex:1 1 100%;justify-content:stretch}}
/* Pageant session: the Workshop's own Design score (castle-beauty) hides so the judges' totals stay sealed until the reveal. */
#builder-panel[data-session] .builder-progress>:is(h3,.beauty-total,#build-beauty-title,#build-beauty-bars,#build-beauty-tips,#build-beauty-bonuses,.build-note){display:none!important}
