/* ============================================================================
   Freedom TD full-bleed layout: two side rails + scenic bleed.  Over style.css.
   ----------------------------------------------------------------------------
   The world runs edge to edge: a full-viewport procedural backdrop (#bleed,
   painted by bleed.js) with the framed 22×16 board floating between two vertical
   button rails (Kingdom-Rush side rails). Left rail = build/economy, right rail =
   info/meta. Board is inset behind the rails so they never overlap play.
   game.js is untouched except compact odds/bazaar labels + an odds "attention"
   badge; every control keeps its original id, so all handlers still fire.
   ============================================================================ */

:root{--rail:76px;--railR:76px;--barH:10px}
/* --rail (left) and --railR (right) are recomputed in game.js/fitRails. On wide
   screens the right rail widens into a content dock (html.dock-mode) that persistently
   shows Scout + the tower Inspector; on narrow screens both rails just hug the board. */
html,body{overflow:hidden}
#wrap{height:100dvh}

body{background:radial-gradient(1400px 1000px at 50% 42%, #221a10 0%, var(--bg) 62%),var(--bg)}
#stagevignette{position:fixed;inset:0;z-index:1;pointer-events:none;
  background:radial-gradient(120% 120% at 50% 50%, transparent 56%, rgba(4,2,14,.55) 100%)}
#bleed{position:fixed;inset:0;z-index:0;width:100vw;height:100dvh;display:block;pointer-events:none}

/* ---- board sits between the rails, filling the middle column ---- */
#stage{position:fixed;left:var(--rail);right:var(--railR);top:0;bottom:0;padding:0;gap:0;display:block;z-index:2}
#boardwrap{position:absolute;inset:0;display:block;flex:none;gap:0}
#board{position:absolute;inset:0;flex:none;width:auto;height:auto;max-width:none;
  display:flex;align-items:center;justify-content:center;overflow:visible}
#game{border:1px solid rgba(220,196,160,.30);border-radius:16px;
  box-shadow:0 0 0 5px rgba(40,32,20,.5),
             0 30px 100px rgba(0,0,0,.7),
             0 0 120px rgba(200,150,70,.22),
             inset 0 0 60px rgba(12,8,4,.45)}
/* neutralise the old very-wide desktop aspect-box rule */
@media(min-width:1360px){
  #stage{justify-content:initial}
  #boardwrap{flex:none}
  #board{height:auto;width:auto;aspect-ratio:auto;max-width:none;inset:0}
}

/* ---- stats + speed HUD: moved out of the old translucent top bar (which dimmed the
   board's top row) into the top of the right rail. ---- */
.railhud{display:flex;flex-direction:column;align-items:stretch;gap:8px;
  padding:0 0 10px;margin-bottom:2px;border-bottom:1px solid var(--line)}
#railR .stats{position:static;transform:none;left:auto;margin:0;
  display:flex;flex-wrap:wrap;justify-content:center;gap:6px 9px}
#railR .stat{flex:0 0 auto;align-items:center;text-align:center}
#railR .stat .lbl{font-size:8px;letter-spacing:.4px}
#railR .stat .val{font-size:15px;text-shadow:none}
.rail-foot .speedwrap{margin:0;justify-content:center;gap:5px;font-size:11px}
.rail-foot .speedwrap #speed{width:100%;justify-content:center;margin:0}

/* ---- side rails ---- */
/* --rail is recomputed in game.js (fitRails) so the middle column exactly frames the
   board, the old side letterbox becomes rail width. Buttons spread over the full
   height (space-evenly) so nothing clumps in the middle. */
/* No backdrop-filter on the rails: it would make them the containing block for their
   position:fixed children (the docked panels double as narrow-screen overlays), which
   would clip the overlays inside the rail. Opaque gradients carry the frosted look. */
.rail{position:fixed;top:0;bottom:0;width:var(--rail);z-index:35;
  display:flex;flex-direction:column;align-items:stretch;justify-content:space-evenly;gap:8px;
  padding:12px 8px;overflow-y:auto;overflow-x:hidden}
/* no border line between the rails and the board: clean junction (the board's own
   soft frame is the only edge) */
#railL{left:0;width:var(--rail);background:linear-gradient(90deg,rgba(16,12,7,.92),rgba(16,12,7,.66))}
#railR{right:0;width:var(--railR);background:linear-gradient(270deg,rgba(16,12,7,.92),rgba(16,12,7,.66))}

/* rail buttons: icon over a tiny label, chunky (KR-style), fill their rail width */
.rail .ctl,.rail .mbtn{width:100%;padding:11px 4px;font-size:11px;font-weight:700;line-height:1.14;
  border-radius:13px;white-space:normal;display:flex;flex-direction:column;align-items:center;gap:3px;
  text-align:center;min-height:0}
.rail>.ctl{min-height:52px}                            /* direct rail buttons stand tall */
.rail .railbtn{font-size:19px}                         /* emoji-forward */
.rail .railbtn>span{font-size:10px;font-weight:600;color:var(--dim)}
#modeBar{display:flex;flex-direction:column;gap:4px;background:rgba(24,20,14,.5);
  border:1px solid var(--line);border-radius:14px;padding:4px}
#modeBar .mbtn{font-size:17px;min-height:0}
#modeBar .mbtn>span{font-size:9.5px;font-weight:600}
.instr{display:none}

/* attention badges: gold glow + corner dot (fuse-ready is set by game.js; odds by the HUD refresh) */
.rail .attention,.rail .mbtn.fuse-ready{position:relative;animation:railPulse 1.8s ease-in-out infinite}
.rail .attention::after,.rail .mbtn.fuse-ready::after{content:'';position:absolute;top:3px;right:3px;
  width:8px;height:8px;border-radius:50%;background:var(--gold);box-shadow:0 0 8px var(--gold)}
@keyframes railPulse{
  0%,100%{box-shadow:0 0 0 1px rgba(255,216,77,.5),0 0 10px rgba(255,216,77,.25)}
  50%{box-shadow:0 0 0 1px rgba(255,216,77,.8),0 0 20px rgba(255,216,77,.48)}}

/* ---- primary CTA: Start Wave, docked at the BOTTOM of the right rail (out of the
   board's way, never colliding with the centred keep/confirm bar). #railR reserves
   padding-bottom so its buttons spread above this pinned button. ---- */
#startWave{position:fixed;right:0;bottom:0;left:auto;transform:none;width:var(--railR);z-index:36;
  min-height:56px;padding:11px 4px;font-size:12px;font-weight:800;line-height:1.15;
  border-radius:14px 14px 0 0;white-space:normal;
  box-shadow:0 -6px 20px rgba(0,0,0,.45),0 0 26px rgba(247,147,26,.4)}
#railR{padding-bottom:66px}
#startWave.rdy{animation:startPulse 1.6s ease-in-out infinite}
@keyframes startPulse{0%,100%{box-shadow:0 -6px 20px rgba(0,0,0,.45),0 0 18px rgba(247,147,26,.35)}
  50%{box-shadow:0 -6px 20px rgba(0,0,0,.45),0 0 34px rgba(247,147,26,.7)}}

/* ---- floating panels / drawers ---- */
/* Scout / next-wave card. Mobile portrait: a 🔭 toggle drawer that floats over the board
   only on tap (an explicit user action). Desktop: it lives IN the right rail, pinned to
   the bottom just above the Start Wave button, it never floats over the playfield. */
#nextWave{position:fixed;right:8px;bottom:72px;top:auto;left:auto;
  z-index:29;margin:0;width:min(280px,42vw);max-height:52vh;overflow:auto;
  display:none;pointer-events:auto}
#nextWave.show{display:block}
/* Docked into the rail ONLY when fitRails found room for a real dock (html.dock-mode).
   Keyed on a width media query before, which docked it into an 80px rail on a 1400px
   screen and clipped every line of the wave preview. */
html.dock-mode #scout{display:none}                      /* persistent card, no 🔭 toggle needed */
html.dock-mode #nextWave .drawer-x{display:none}         /* ...and nothing to close */
html.dock-mode #nextWave{position:static;right:auto;bottom:auto;left:auto;top:auto;z-index:auto;
  width:auto;max-height:none;overflow:visible;overflow-wrap:anywhere;
  margin:auto 0 0;                        /* margin-top:auto pins it to the rail bottom */
  border-top:1px solid var(--line);padding-top:12px}
html.dock-mode #nextWave:empty{display:none}
html.dock-mode #nextWave:not(:empty){display:block}
/* #gemInfo lives inside the ⓘ Info drawer now, a flowing section under the how-to,
   not a floating panel. It's shown only while the drawer is open (never on its own). */
#tips #gemInfo{position:static;width:auto;max-height:none;right:auto;top:auto;left:auto;bottom:auto;
  background:none;border:none;box-shadow:none;backdrop-filter:none;padding:0;
  margin-top:12px;border-top:1px solid var(--line);padding-top:12px}
#tips #gemInfo:not(.show){display:none;border:none}
#inspect{position:fixed;right:calc(var(--railR) + 8px);top:calc(var(--barH) + 8px);left:auto;bottom:auto;
  z-index:30;width:min(260px,34vw);max-height:70vh;overflow:auto}
#tips{position:fixed;right:calc(var(--railR) + 8px);top:calc(var(--barH) + 8px);left:auto;bottom:auto;
  z-index:31;width:min(300px,42vw);max-height:78vh;overflow:auto;
  background:rgba(24,20,14,.96);border:1px solid var(--line);border-radius:14px;
  padding:14px 16px;box-shadow:var(--shadow)}
#tips.show{display:block}
#tips:not(.show){display:none}
.tips-head{font-weight:800;font-size:14px;color:var(--ink);margin:0 0 8px}
.tips-row{font-size:12.5px;line-height:1.5;color:var(--dim);margin-bottom:8px}
.tips-row b{color:var(--ink)}
.tips-row.tips-dim{opacity:.8;font-size:11.5px;margin-top:10px;border-top:1px solid var(--line);padding-top:9px}
.tips-bonus{font-size:12.5px;line-height:1.5;color:var(--gold);background:rgba(255,216,77,.08);
  border:1px solid rgba(255,216,77,.4);border-radius:9px;padding:8px 10px;margin-bottom:8px}
.tips-bonus b{color:#ffe9a0}
#buildHint{position:fixed;left:50%;transform:translateX(-50%);top:calc(var(--barH) + 4px);right:auto;bottom:auto;
  z-index:29;max-width:min(440px,72vw);text-align:center}
/* Start Wave now lives in the right rail, so the keep/confirm bar can drop to thumb
   reach at the bottom-centre of the board instead of stacking above the old CTA. */
#combineBar{position:fixed;left:50%;transform:translateX(-50%);bottom:20px;z-index:32;width:min(440px,74vw)}
#combineBar.show{position:fixed;flex-direction:row;flex-wrap:wrap;align-items:center;justify-content:center;bottom:20px}
#combineBar.show #combineText,#combineBar.show #combineSub{flex-basis:100%;text-align:center}

/* ---- real drawer animations: right-side context panels slide + fade in ---- */
@keyframes drawerInR{from{opacity:0;transform:translateX(16px)}to{opacity:1;transform:translateX(0)}}
@keyframes drawerInL{from{opacity:.35;transform:translateX(-100%)}to{opacity:1;transform:translateX(0)}}
#nextWave.show,#tips.show{animation:drawerInR .2s ease both}
#inspect:not([hidden]){animation:drawerInR .2s ease both}

/* ---- desktop dock mode: the right rail widens into a persistent info column ----
   The tower Inspector flows INSIDE the rail (below the buttons) instead of floating over
   the board. (Scout is a bottom-right floater on every desktop, docked or not.) Toggled
   by game.js/fitRails only when the board's horizontal slack is wide enough for a column. */
html.dock-mode #railR{justify-content:flex-start;gap:10px}
html.dock-mode #railR .drawer-x{display:none}  /* docked panels are persistent, no ✕ */
html.dock-mode #railR #inspect{
  position:static;width:auto;right:auto;left:auto;top:auto;bottom:auto;margin:0;
  max-height:46vh;overflow:auto}
/* …but the Bitcoin Mine menu is a CENTERED modal on every layout. Two rules fight it:
   the dock rule above (jams it into the rail → re-assert fixed centering with 2 ids +
   2 classes to outrank it), and the right-drawer slide-in animation, whose translateX
   clobbers the centering transform (→ kill the animation and own the transform here). */
html.dock-mode #railR #inspect.mine-popout{
  position:fixed;left:50%;top:50%;right:auto;bottom:auto;
  width:min(340px,90vw);margin:0;max-height:84vh;overflow:auto;z-index:60}
#inspect.mine-popout:not([hidden]){animation:none;transform:translate(-50%,-50%)}
/* desktop: chunkier buttons, all aligned to the top of each rail, FPS+speed footer
   pinned to the bottom of the left rail (fills the space under the buttons) */
html.dock-mode #railL{justify-content:flex-start}
html.dock-mode .rail>.ctl{min-height:62px}
html.dock-mode .rail .ctl,html.dock-mode .rail .mbtn{font-size:12px;padding:12px 6px}
html.dock-mode .rail .railbtn{font-size:22px}
html.dock-mode #modeBar .mbtn{font-size:19px}
/* New map + the speed-dial footer sit together at the BOTTOM of the left rail:
   #newmap grabs the free space (margin-top:auto), the footer follows right under it. */
html.dock-mode #railL #newmap{margin-top:auto}
html.dock-mode #railL .rail-foot{margin-top:0;padding-top:14px;border-top:1px solid var(--line)}

/* FPS + speed footer: column; lives in the left rail (desktop) or the HUD (narrow) */
.rail-foot{display:flex;flex-direction:column;align-items:stretch;gap:9px}
.rail-foot .fpsstat{flex-direction:row;align-items:center;justify-content:center;gap:6px}
.rail-foot .fpsstat .lbl{font-size:9px}
.rail-foot .fpsstat .val{font-size:13px}

/* ---- richer scout / wave card ---- */
#nextWave .nw-head{display:flex;align-items:center;gap:8px;flex-wrap:wrap;
  font-weight:800;color:var(--gold);font-size:14px;margin-bottom:9px}
#nextWave .nw-arch{font-size:10px;font-weight:700;text-transform:uppercase;letter-spacing:.6px;
  color:var(--dim);background:rgba(255,255,255,.06);padding:2px 8px;border-radius:7px}
#nextWave .nw-boss{color:var(--rose);font-weight:800}
#nextWave .nw-cap{color:var(--gold);font-weight:800}
/* stacked (portrait over name) so it stays readable in the narrow rail column */
#nextWave .nw-creep{display:flex;flex-direction:column;align-items:flex-start;gap:6px;margin:2px 0 4px}
#nextWave .nw-portrait{width:56px;height:56px;flex:none;border-radius:12px;
  background:radial-gradient(circle at 50% 42%,rgba(255,206,120,.16),rgba(0,0,0,0) 68%)}
#nextWave .nw-name{display:flex;flex-direction:column;font-size:14px;font-weight:800;color:#fff;line-height:1.15}
#nextWave .nw-sub{font-size:10.5px;font-weight:600;color:var(--dim);margin-top:2px}
#nextWave .nw-mods{display:flex;flex-direction:column;gap:6px;margin-bottom:11px}
#nextWave .nw-mod{display:flex;gap:7px;font-size:11.5px;line-height:1.45;color:#ece0cd}
#nextWave .nw-mod>span{flex:none;color:var(--violet);font-weight:700;min-width:14px;text-align:center}
/* compact inline stat line: small + clean, not big cards */
#nextWave .nw-stats{display:flex;flex-wrap:wrap;gap:3px 13px;margin-bottom:11px;
  font-size:11.5px;color:var(--dim);padding-bottom:10px;border-bottom:1px solid var(--line)}
#nextWave .nw-s{display:inline-flex;align-items:center;gap:4px}
#nextWave .nw-s b{color:#fff;font-weight:700;font-variant-numeric:tabular-nums}
#nextWave .nw-weak{font-size:11.5px;line-height:1.45;color:var(--ink);
  display:flex;align-items:center;gap:5px;flex-wrap:wrap;
  background:rgba(255,216,77,.08);border:1px solid rgba(255,216,77,.32);border-radius:9px;padding:8px 10px}
#nextWave .nw-weak .sw{width:12px;height:12px;border-radius:3px;flex:none}

/* Bazaar = full-height left drawer that rides OVER the top bar (game.js no longer
   pins it to the board; the CSS owns its position). Slides in from the rail edge. */
#towerPanel.shop-menu{position:fixed;left:0;top:0;bottom:0;right:auto;
  width:min(430px,94vw);max-width:none;max-height:none;height:100dvh;
  border-radius:0 20px 20px 0;padding:16px 18px 20px;z-index:60;
  overflow-y:auto;animation:drawerInL .22s cubic-bezier(.2,.7,.25,1) both;
  box-shadow:16px 0 52px rgba(0,0,0,.55);border-left:none}

/* shared close affordance: a little ✕ pinned top-right of every animated drawer */
.drawer-x{position:absolute;top:9px;right:9px;z-index:3;width:30px;height:30px;padding:0;
  display:flex;align-items:center;justify-content:center;font-size:15px;font-weight:700;line-height:1;
  border-radius:10px;border:1px solid var(--line);background:rgba(34,28,18,.72);color:var(--dim);
  cursor:pointer;transition:.12s}
.drawer-x:hover{color:#fff;background:rgba(70,56,36,.85);transform:none}
/* the Bazaar drawer scrolls, so pin its ✕ to the viewport (stays put while scrolling) */
#towerPanel .drawer-x{position:fixed;top:12px;left:min(386px,86vw);right:auto;width:32px;height:32px}

/* ---- small landscape (phones): tighter rails ---- */
@media(orientation:landscape) and (max-height:560px){
  :root{--barH:8px}
  .rail{gap:5px;padding:7px 6px}
  .rail .ctl,.rail .mbtn{padding:7px 3px;font-size:9.5px}
  .rail>.ctl{min-height:40px}
  .rail .railbtn{font-size:16px}
  .rail .railbtn>span{font-size:8.5px}
  #bar{padding:5px 10px 16px;gap:8px}
  .brand{font-size:15px}.stats{gap:9px}
  #startWave{bottom:0;min-height:44px;padding:9px 4px;font-size:11px}
  #railR{padding-bottom:52px}
  #combineBar,#combineBar.show{bottom:14px}
}

/* ---- E1: the HUD shows Bitcoin, Lives, Wave. Score, path and momentum live in ⓘ Info. ---- */
#railR .stat:has(#pathLen),#railR .stat:has(#score),#railR .stat:has(#power),.fpsstat{display:none}

/* ---- F1: the rails unlock by wave (body[data-round], set in nextRound). ?unlock shows all. ---- */
body:not([data-unlock])[data-round="1"] .mbtn[data-mode="select"],
body:not([data-unlock])[data-round="1"] .mbtn[data-mode="fuse"]{display:none}
body:not([data-unlock]):is([data-round="1"],[data-round="2"]) #shopBtn{display:none}
body:not([data-unlock]):is([data-round="1"],[data-round="2"],[data-round="3"],[data-round="4"]) #oddsBtn,
body:not([data-unlock]):is([data-round="1"],[data-round="2"],[data-round="3"],[data-round="4"]) #autoToggle{display:none}

/* ---- L1: Start wave is a wide bar under the board, with the placement count. ---- */
#stage{bottom:64px}
#railR{padding-bottom:0}
#startWave{left:50%;right:auto;transform:translateX(-50%);bottom:8px;
  width:min(560px,calc(100vw - var(--rail) - var(--railR) - 24px));min-height:48px;
  padding:12px 18px;font-size:15px;border-radius:14px;white-space:nowrap}
#nextWave{bottom:66px}

/* the keep/confirm bar sits above the Start bar, never under it */
#combineBar{bottom:72px}
#combineBar.show{bottom:72px}
