/* Preparation composition. Background, portrait, paper and controls stay separate. */
#setup,#prepDialog {
 --prep-ink:#34291c; --prep-sage:#35583d; --prep-gold:#ab8033;
 --prep-paper-frame:url('assets/preparation/frames/paper-gold.png');
 --prep-paper-texture:url('assets/preparation/textures/ivory-paper.png');
 --prep-wood:url('assets/preparation/textures/dark-walnut.png');
 --prep-scene:url('assets/home/animation/workshop-empty-q80.jpg');
}
#setup {
 --prep-hero-height:clamp(137px,17.5dvh,165px);
 --prep-scroll-offset:0px;--prep-portrait-overhang:28px;
 border:0; color:var(--prep-ink); position:relative; isolation:isolate;
 background:#49301f var(--prep-wood) center/256px 256px repeat;
}
/* One backdrop spans the title, character and tabs without a header shadow overlay. */
#setup::before {
 content:'';position:absolute;inset:0 0 auto;height:calc(var(--prep-header-height,61px) + var(--prep-hero-height) + 44px);
 z-index:-1;pointer-events:none;
 background:var(--prep-scene) center 40%/100% auto no-repeat;
}
#setup button:focus:not(:focus-visible),#prepDialog button:focus:not(:focus-visible){outline:none}
#setup button:focus-visible,#prepDialog button:focus-visible,#setup select:focus-visible {
 outline:2px solid #315a42; outline-offset:3px; box-shadow:0 0 0 5px #fff7df;
}
#setup [hidden]{display:none!important}
#setup .prep-header {
 min-height:61px; padding:6px 12px; padding-top:max(6px,env(safe-area-inset-top));
 grid-template-columns:1fr 1.3fr 1fr; align-items:center; z-index:4; position:relative;
 background:none;border-bottom:0;box-shadow:none;
}
/* Wood ends at the header edge, without an overhang, fade or cast shadow. */
#setup .prep-header::before {
 content:'';position:absolute;inset:0;z-index:-1;pointer-events:none;
 background:var(--prep-wood) center/256px 256px repeat;
}
#setup #prepBackMount{display:flex;align-items:center;min-height:44px}
#setup .prep-header h2{position:relative;display:flex;align-items:center;justify-content:center;min-height:44px;margin:0}
#setup .prep-header .prep-label{display:block;height:31px;filter:brightness(0) invert(.95) sepia(.25)}
#setup #homeBack {display:inline-flex;align-items:center;justify-content:center;line-height:1;min-height:44px;padding:5px 9px;font-size:14px;background:transparent;border:0;border-radius:0;box-shadow:none}
#setup .prep-scroll {padding:0 0 14px;scrollbar-width:none;scroll-padding-block:36px 16px}
#setup .prep-character {position:relative;height:var(--prep-hero-height);overflow:hidden;background:none}
/* The portrait mask extends above the scroll viewport; its bottom follows the hero. */
.prep-portrait-mask {position:absolute;z-index:5;pointer-events:none;left:0;right:0;top:calc(var(--prep-header-height,61px) - var(--prep-portrait-overhang));height:max(0px,calc(var(--prep-hero-height) - var(--prep-scroll-offset) + var(--prep-portrait-overhang)));overflow:hidden}
.prep-portrait {position:absolute;top:calc(-27px + var(--prep-portrait-overhang) - var(--prep-scroll-offset));left:calc(24% - min(42.75%,var(--prep-hero-height)*1.13625));width:min(85.5%,calc(var(--prep-hero-height)*2.2725));height:auto;max-width:none;pointer-events:none;filter:drop-shadow(2px 4px 3px #33231560)}
#setup .prep-stats {position:absolute;isolation:isolate;right:3%;top:50%;transform:translateY(-50%);width:clamp(202px,55%,242px);min-height:0;display:grid;grid-template-columns:minmax(65px,.78fr) minmax(92px,1fr);align-items:center;gap:8px;padding:13px 12px;margin:0;border:0;border-radius:5px;background:none;box-shadow:0 3px 5px #36221033}
#setup .prep-stats::before,#setup .prep-paper::before,#setup .prep-gear::before,
#setup .prep-bag::before,#setup .prep-item::before,#setup .shop-bar::before,
#prepDialog .prep-candidate::before,#prepDialog #prepComparison::before {
 content:'';position:absolute;z-index:-1;pointer-events:none;border-style:solid;border-color:transparent;
 border-image-source:var(--prep-paper-frame);border-image-slice:240;border-image-repeat:stretch;
 background-color:#fffdf8;
 background-image:radial-gradient(ellipse,var(--prep-paper-highlight,transparent),transparent 75%),var(--prep-paper-texture);
 background-position:center;background-size:100% 100%,256px 256px;background-repeat:no-repeat,repeat;background-clip:padding-box;
}
#setup .prep-stats::before{inset:-6px -2px -6px;border-width:20px 18px 18px}
.prep-identity{display:flex;flex-direction:column;align-items:flex-start;justify-content:center;gap:7px;padding:0 8px 0 0;border-right:1px solid #ba975759}
.prep-identity strong{font-family:'Yu Mincho','Noto Serif CJK JP',serif;font-size:20px;line-height:1.5;white-space:nowrap;color:#2f261c}
#setup #prepLevel{display:flex;flex-wrap:wrap;align-items:baseline;gap:2px 4px;padding:0;min-width:0;font-family:Georgia,serif;font-size:12px;line-height:1.3;color:#645037;white-space:normal}
.prep-level-value{white-space:nowrap}
.prep-level-value b{font-size:21px;font-weight:700;color:#34291c;margin-left:2px}
.prep-level-note{font-size:10px;letter-spacing:.02em;white-space:nowrap;color:#786144}
#setup #setupStats{display:grid;grid-template-columns:1fr;gap:0;width:100%;min-width:0;margin:0}
#setup #setupStats>.prep-stat{display:grid;grid-template-columns:21px minmax(0,1fr) auto;align-items:center;gap:4px;min-height:27px;border:0;padding:0 1px;color:#4d3b27}
#setup #setupStats>.prep-stat+.prep-stat{border-top:1px solid #ba975735}
#setup #setupStats .prep-stat-label{display:block;border:0;padding:0;font-size:12px;line-height:1.4;color:#645037;white-space:nowrap}
.prep-stat-icon{display:block;width:21px;height:22px;object-fit:contain}
#setup #setupStats b{font:700 19px/1.2 Georgia,serif;font-variant-numeric:lining-nums tabular-nums;color:#2f291f;margin:0;text-align:right}
.prep-compact {position:absolute;z-index:3;top:var(--prep-header-height,58px);left:0;right:0;height:30px;display:grid;place-items:center;pointer-events:none;
 background:#453321;color:#ffefd0;border-bottom:1px solid #c7a358;box-shadow:0 2px 5px #25170e55;
 font-size:11px;font-variant-numeric:tabular-nums;opacity:0;transform:translateY(-8px);transition:opacity .15s,transform .15s}
.prep-compact.is-visible{opacity:1;transform:none}
#setup .prep-tabs {position:relative;padding:0 15px;gap:0;border:0;margin-top:-1px;z-index:1}
#setup .prep-tabs button {display:flex;align-items:center;justify-content:center;gap:8px;min-height:44px;padding:7px;border:1px solid #bd9654;border-bottom:0;border-radius:9px 9px 0 0;box-shadow:inset 0 0 0 2px #f0dfb2,0 -2px 3px #311a1633;position:relative;background:#f9eed5 var(--prep-paper-texture) center/256px repeat}
#setup .prep-tabs button:first-child{border-top-right-radius:0}
#setup .prep-tabs button:last-child{border-top-left-radius:0}
#setup .prep-tabs button[aria-selected=true]{background:linear-gradient(130deg,#496d43e8,#254b35ed 65%,#153c2df2),var(--prep-paper-texture) center/256px repeat;border-color:#c5a058;box-shadow:inset 0 0 0 2px #c5a058,0 -2px 3px #211d0f33}
#setup .prep-tabs .prep-label{height:27px;width:auto;max-width:50%}
.prep-tab-icon{width:27px;height:29px;object-fit:contain}
#setup .prep-paper{position:relative;isolation:isolate;margin:-6px 6px 0;padding:13px 12px 16px;min-height:320px}
#setup .prep-paper::before {inset:-6px -2px -8px;border-width:24px}
#setup .prep-group h3{margin:9px 0 7px;gap:8px;height:23px}
#setup .prep-group:first-of-type h3{margin-top:0}
#setup .prep-group h3::before {content:'✦';font-size:17px;color:#9c7539}
#setup .prep-group h3::after {height:1px;background:linear-gradient(90deg,#aa854b,#c8b37b55);margin-right:3px}
#setup .prep-group h3 .prep-label {height:24px}
#setup .prep-grid{gap:7px 6px}
#setup .prep-gear {
 isolation:isolate;min-height:70px;padding:5px 12px 5px 2px;gap:1px;border:0;border-radius:6px;
 background:none;box-shadow:0 2px 2px #7a4b2726;transition:filter .12s;
}
#setup .prep-gear::before,#setup .prep-bag::before,#setup .prep-item::before,#setup .shop-bar::before,
#prepDialog .prep-candidate::before,#prepDialog #prepComparison::before{inset:-6px -1px -6px;border-width:20px 18px 18px}
#setup .prep-gear:active:not(:disabled){transform:translateY(1px);filter:brightness(.97)}
@media(hover:none){#setup .prep-gear:hover:not(:active):not(:disabled){filter:none}}
#setup .prep-gear.is-empty::before{opacity:1}
#setup .prep-gear.is-empty>.prep-icon {filter:sepia(.8) saturate(.75) contrast(1.06);opacity:1}
#setup .prep-gear>.prep-icon {width:clamp(52px,15cqw,76px);height:55px;margin:0;object-fit:contain;filter:drop-shadow(0 2px 1px #68471e28)}
#setup .prep-weapons .prep-gear{min-height:73px}
#setup .prep-weapons .prep-gear>.prep-icon{height:63px}
#setup .prep-gear>span{gap:3px;position:relative}
#setup .prep-gear b{font-family:'Yu Mincho','Noto Serif CJK JP',serif;font-size:14px;line-height:1.35;color:#30291e;overflow-wrap:anywhere}
#setup .prep-gear small {color:#725d3f;font-size:10px;line-height:1.35}
#setup .prep-gear .prep-summary {color:#574831;font-size:11px;letter-spacing:-.3px}
#setup .prep-gear i{right:4px;top:50%;transform:translateY(-50%);font:25px Georgia,serif;color:#aa8239}
.prep-add{position:relative;display:inline-block;flex:0 0 19px;width:19px;height:19px;background:#a08351;color:#fff7e4;border-radius:50%;font-size:0}
.prep-add::before,.prep-add::after{content:'';position:absolute;left:50%;top:50%;transform:translate(-50%,-50%);background:currentColor;border-radius:1px}
.prep-add::before{width:11px;height:1.5px}
.prep-add::after{width:1.5px;height:11px}
#setup .prep-gear.is-empty b{display:flex;align-items:center;gap:4px;font-size:12px;font-weight:500}
#setup .prep-gear:disabled {opacity:.62;color:#796950;cursor:default;filter:grayscale(.6);box-shadow:none}
#setup .prep-locked{margin:0 0 10px;padding:8px 10px;font-size:11px;line-height:1.7;border:1px solid #c1a569;border-radius:5px;background:#fff7e3}
#setup .prep-footer {gap:8px;padding:10px 12px max(12px,env(safe-area-inset-bottom));border-top:1px solid #aa8544;
 background:linear-gradient(#3b210e30,#27140750),var(--prep-wood) center/256px 256px repeat;box-shadow:0 -2px 5px #291a134d;z-index:4}
#setup #prepStartMount {flex:1}
#setup #startButton {position:relative;isolation:isolate;gap:4px;min-height:54px;padding:5px 8px;border:0;border-radius:8px;background:none;box-shadow:0 3px 5px #22130866}
#setup #startButton::before {content:'';position:absolute;z-index:-1;inset:-10px -8px -14px;border:solid transparent;border-width:0 49px;
 border-image:url('assets/home/frames/adventure-button.png') 0 180 fill / 0 49px / 0 stretch;pointer-events:none}
#setup #startButton .prep-compass{width:34px;height:34px;object-fit:contain;flex:none}
#setup #startButton .prep-label{width:auto;min-width:0;height:26px;max-width:calc(100% - 52px);object-fit:contain}
#setup .qty-controls button,#setup .shop-bar button{background:linear-gradient(#4d704c,#2e5037);border-color:#c5ab72}
#setup .qty-controls button:disabled{background:#b6afa0;border-color:#c9bfad}
#setup .prep-bag,#setup .prep-item,#setup .shop-bar {position:relative;isolation:isolate;background:none;border:0;color:#3d3021;box-shadow:0 2px 2px #7a4b2726}
#setup .prep-bag{padding:12px;margin-bottom:14px}
#setup .prep-item{padding:12px;gap:7px 10px;grid-template-columns:50px minmax(0,1fr)}
#setup .prep-item>.prep-icon{grid-row:1/3;width:50px;height:66px}
#setup .prep-item .qty-controls{grid-column:2;justify-content:flex-end;gap:6px}
#setup .prep-item b{font-family:'Yu Mincho','Noto Serif CJK JP',serif;font-size:15px}
#setup .prep-item small{font-size:12px;line-height:1.6}
#setup #carryChoices{gap:12px}
#setup .shop-bar{padding:10px;flex-wrap:wrap}
#setup .campaign-prep-note{font-size:12px;line-height:1.7;padding:8px 4px;margin:0}
#setup .qty-controls button,#setup .shop-bar button{border:1px solid #c5a058;border-radius:6px;box-shadow:inset 0 0 0 2px #d4b97466}
#setup .qty-controls button:disabled{box-shadow:none}
#prepDialog {background:#faf3e2 var(--prep-paper-texture) center/256px repeat;color:#34291c;border:1px solid #b18b42;box-shadow:0 8px 30px #1c100d99,inset 0 0 0 3px #e2c997;border-radius:10px}
#prepDialog>header {background:linear-gradient(#27130670,#27130670),var(--prep-wood) center/256px 256px repeat}
#prepDialog .prep-confirm {position:relative;isolation:isolate;background:none;color:#fff4d8;border:0;min-height:52px;font-family:'Yu Mincho','Noto Serif CJK JP',serif;font-size:18px}
#prepDialog .prep-confirm::before{content:'';position:absolute;inset:-10px -7px -14px;z-index:-1;border-style:solid;border-color:transparent;border-width:0 49px;border-image:url('assets/home/frames/adventure-button.png') 0 180 fill / 0 49px / 0 stretch;pointer-events:none}
#prepDialog .prep-confirm:disabled{background:#ded6c4;color:#786b56;border:1px solid #b5a585;opacity:1;cursor:default;box-shadow:inset 0 0 0 2px #eee6d5}
#prepDialog .prep-confirm:disabled::before,#prepDialog .prep-confirm.is-remove::before{display:none}
#prepDialog .prep-confirm.is-remove{background:#f6e8cc var(--prep-paper-texture) center/256px repeat;color:#594024;border:1px solid #b79757;box-shadow:inset 0 0 0 2px #ddc18c}
#prepDialog .prep-candidate {position:relative;isolation:isolate;background:none;border:0;border-radius:6px;padding:13px 12px;box-shadow:0 2px 2px #7a4b2726}
#prepDialog .prep-candidate b{font-family:'Yu Mincho','Noto Serif CJK JP',serif;font-size:16px;padding-right:42px}
#prepDialog .prep-candidate small{font-size:12px;line-height:1.6}
#prepDialog .prep-candidate em{font-size:10px;right:8px;top:9px;background:#35583d;color:#fff3d6;padding:2px 6px;border:1px solid #b79757;border-radius:9px}
#prepDialog .prep-candidate[aria-pressed=true]{--prep-paper-highlight:#66844944;background:none;box-shadow:0 0 0 2px #aa8439}
#prepDialog #prepCandidates{gap:10px;padding:7px;scroll-padding-block:8px}
#prepDialog #prepComparison{position:relative;isolation:isolate;margin:12px 3px;padding:13px 6px;border:0}
#prepDialog #prepComparison span{font-size:12px}
#prepDialog #prepComparison b{font-family:Georgia,serif;font-size:18px}
#prepDialog .prep-sort select{min-height:44px;background:#fbf4e2;border-color:#b79757;color:#594024}
#prepDialog .prep-picker-help{color:#665236;margin-bottom:8px}
#prepDialog.is-gear[open]{display:flex;flex-direction:column;height:min(740px,calc(100dvh - 24px));max-height:calc(100dvh - 24px);overflow:hidden}
#prepDialog.is-gear>header{flex:none;position:relative}
#prepDialog.is-gear #prepDialogBody{display:flex;flex-direction:column;min-height:0;flex:1;padding:12px 14px}
#prepDialog.is-gear .prep-picker-help,#prepDialog.is-gear .prep-sort{flex:none}
#prepDialog.is-gear #prepCandidates{flex:1;min-height:48px;max-height:none;align-content:start}
.prep-picker-footer{flex:none;padding-top:8px}
.prep-comparison-title{margin:0;text-align:center;color:#59472d;font-size:12px;font-weight:700}
#prepDialog.is-gear #prepComparison{margin-block:8px 12px}
@media(min-width:420px){
 #setup .prep-gear{min-height:70px;gap:3px}
 #setup .prep-gear b{font-size:15px}
 #setup .prep-gear small{font-size:11px}
 #setup .prep-gear>.prep-icon{height:60px}
}
@media(max-width:359px){
 #setup .prep-header{padding-inline:8px;min-height:54px}
 #setup .prep-header .prep-label{height:27px}
 #setup #homeBack{font-size:11px;padding-inline:5px}
 #setup .prep-stats{right:3%;padding-inline:10px}
 #setup .prep-identity strong{font-size:17px}
 #setup .prep-paper{padding:12px 8px 15px;margin-inline:4px}
 #setup .prep-gear{min-height:65px;padding-right:10px}
 #setup .prep-gear>.prep-icon{width:46px;height:55px}
 #setup .prep-gear b{font-size:12px}
 #setup .prep-gear .prep-summary{font-size:10px}
 #setup .prep-gear.is-empty b{font-size:11px}
 #setup .prep-footer{padding-inline:8px;gap:7px}
 #setup #startButton .prep-compass{width:25px;height:30px}
 #setup #startButton .prep-label{max-width:calc(100% - 38px)}
 .prep-compact{font-size:10px}
}
@media(max-height:420px){
 #prepDialog .prep-candidate{padding-block:10px}
 #prepDialog.is-gear>header{padding:3px 10px}
 #prepDialog.is-gear #prepDialogBody{padding:5px 12px 9px}
 #prepDialog.is-gear .prep-picker-help,.prep-comparison-title{display:none}
 #prepDialog.is-gear .prep-sort{margin-bottom:2px}
 #prepDialog.is-gear .prep-sort select{padding-block:4px}
 .prep-picker-footer{padding-top:0}
 #prepDialog.is-gear #prepComparison{margin:5px 3px 7px;padding:5px 6px}
 #prepDialog.is-gear #prepComparison span{gap:0;font-size:10px}
 #prepDialog.is-gear #prepComparison b{font-size:15px}
 #prepDialog.is-gear .prep-confirm{min-height:44px}
}
@media(prefers-reduced-motion:reduce){.prep-compact,#setup .prep-gear{transition:none}}
