body { margin: 0; background: #111; color: white; font-family: 'Hiragino Kaku Gothic ProN', sans-serif; overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none; min-height: 100svh; -webkit-tap-highlight-color: transparent; }
        
        #game-container {
            position: absolute;
            width: 1000px;
            height: 600px;
            margin: 0;
            border-left: 10px solid #555; 
            box-shadow: 0 0 20px black;
            background-color: #000;
            overflow: hidden;
            transform-origin: top left;
            will-change: transform;
        }

        canvas { display: block; position: absolute; top: 0; left: 0; z-index: 2; }
        
        #bg-layer {
            position: absolute; top: 0; left: 0; width: 100%; height: 100%;
            background-size: cover; background-position: center;
            opacity: 0.6; 
            z-index: 0;
        }
        #bg-filter {
            position: absolute; top: 0; left: 0; width: 100%; height: 100%;
            background: rgba(0, 0, 0, 0.6); 
            z-index: 1;
        }

        #ui { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); width: 800px; box-sizing: border-box; pointer-events: none; text-shadow: 2px 2px 0 #000; z-index: 10; }
        .hp-bar-wrapper { width: 100%; height: 25px; position: relative; }
.hp-bar-bg { width: 100%; height: 25px; background: #333; border: 2px solid #fff; border-radius: 12px; overflow: hidden; position: relative; }
        #hp-bar { width: 100%; height: 100%; background: linear-gradient(to right, #ff4500 0%, #ffd700 45%, #32cd32 100%); background-size: 800px 100%; background-repeat: no-repeat; background-position: left center; transition: width 0.2s; }
        #barrier-bar { position: absolute; top:0; left:0; width: 0%; height: 100%; background: rgba(0, 191, 255, 0.7); z-index: 2; transition: width 0.2s; }
        #hp-text { position: absolute; top: 0; width: 100%; text-align: center; line-height: 25px; font-weight: bold; font-size: 14px; z-index: 5; }
        #wall-bomb-info { display: none; align-items: center; gap: 6px; font-weight: bold; font-size: 18px; color: #fff; background: rgba(0,0,0,0.35); padding: 0 8px; border-radius: 8px; }
        #wall-bomb-info .bomb-icon{ font-size:18px; }
        #wall-bomb-count{ font-size:16px; }
        #status-info { display: flex; justify-content: space-between; margin-top: 5px; font-size: 18px; font-weight: bold; }
        
        #skill-panel {
           position: absolute; top: 10px; left: 10px;
           display: flex; 
           flex-direction: column;
           flex-wrap: wrap;
           align-content: flex-start;
           gap: 5px;
           row-gap: 5px;
           column-gap: 6px;
           height: 535px; /* v448h: 12 slots per column: 40*12 + 5*11 */
           max-height: calc(100% - 64px);
           z-index: 20;
           pointer-events: none;
       }
        .skill-slot {
           position: relative; 
           width: 40px; height: 40px;
           border-radius: 8px; border: 2px solid #fff;
           background: #000; overflow: hidden;
           box-shadow: 0 0 5px #000;
       }
        .skill-lv{ position:absolute; right:2px; bottom:0px; font-size:12px; font-weight:bold; color:#ffb6c1; text-shadow:1px 1px 0 #000; z-index:30; }

        /* Sprite Sheet: 4 cols x 3 rows */
        .icon-base {
            width: 100%; height: 100%;
            background-image: url('../assets/img/icons.png');
            background-size: 400% 300%; 
            background-repeat: no-repeat;
        }
        
        

.icon-overlay {
            position: absolute;
            inset: 0;
            width: 100%;
            height: 100%;
            object-fit: cover;
            pointer-events: none;
        }
/* Row 1 */
        .icon-0 { background-position: 0% 0%; }     /* Anoko */
        .icon-1 { background-position: 33.33% 0%; } /* Kanimoge */
        .icon-2 { background-position: 66.66% 0%; } /* Dokumoge */
        .icon-3 { background-position: 100% 0%; }   /* Seimoge */
        
        /* Row 2 */
        .icon-4 { background-position: 0% 50%; }     /* Burumoge */
        .icon-5 { background-position: 33.33% 50%; } /* Pikasan */
        .icon-6 { background-position: 66.66% 50%; } /* Yamimoge */
        .icon-7 { background-position: 100% 50%; }   /* Ebinaifu */
        
        /* Row 3 */
        .icon-8 { background-position: 0% 100%; }     /* Aimoge (Player) */
        .icon-9 { background-position: 33.33% 100%; } /* Shiran */
        .icon-10 { background-position: 66.66% 100%; }/* Burukani */
        .icon-11 { background-position: 100% 100%; }  /* Buff/Wall */

        .cooldown-overlay {
            position: absolute; top: 0; left: 0; width: 100%; height: 100%;
            background: conic-gradient(rgba(0,0,0,0.8) 0% 100%);
        }

        #loading { position: fixed; top:0; left:0; width:100%; height:100%; background:#000; display:flex; align-items:center; justify-content:center; z-index: 200; font-size:24px;}

        .overlay-screen {
            position: absolute; top: 0; left: 0; width: 100%; height: 100%;
            background: rgba(0, 0, 0, 0.85);
            display: none; flex-direction: column;
            align-items: center; justify-content: center;
            z-index: 150; pointer-events: all;
            text-align: center;
        }
        .overlay-title { font-size: 40px; color: #ffb6c1; margin-bottom: 20px; font-weight: bold; }
        .overlay-desc { font-size: 18px; color: white; line-height: 1.8; margin-bottom: 20px; white-space: normal; }
        .btn-start {
            padding: 15px 40px; font-size: 24px; font-weight: bold;
            background: #ff4500; color: white; border: 2px solid white;
            border-radius: 30px; cursor: pointer; transition: transform 0.1s;
        }
        .btn-start:hover { transform: scale(1.1); background: #ff6347; }

        .start-actions { display:flex; gap:14px; align-items:center; justify-content:center; margin-top: 6px; }
        .btn-start.btn-sub { background:#444; font-size:20px; padding: 12px 30px; }
        .btn-start.btn-sub:hover { background:#666; }
        #start-version{ position:absolute; right:16px; bottom:12px; font-size:16px; color:rgba(255,255,255,0.9); text-shadow: 1px 1px 0 #000; }
        .help-desc{ max-width: 760px; white-space: normal; }

        #upgrade-screen { 
            position: absolute; top: 0; left: 0; width: 100%; height: 100%; 
            background: rgba(0,0,0,0.95); display: none; flex-direction: column; 
            align-items: center; justify-content: center; z-index: 100; pointer-events: all;
        }
        .card-container { display: flex; gap: 15px; flex-wrap: wrap; justify-content: center; max-width: 900px; }
        .upgrade-card { 
            background: #222; border: 2px solid #555; padding: 8px; 
            width: 140px; cursor: pointer; text-align: center; border-radius: 10px;
            transition: transform 0.2s, background 0.2s;
            display: flex; flex-direction: column; align-items: center;
            position: relative; overflow: hidden;
            box-shadow: 0 4px 8px rgba(0,0,0,0.5);
        }
        .upgrade-card:hover { background: #444; transform: scale(1.05); border-color: #ffb6c1; }
        .upgrade-card.selected { background: #444; transform: scale(1.05); border-color: #ffb6c1; box-shadow: 0 0 0 4px rgba(255,182,193,0.35); }
        .upgrade-card.evo { border-color: #ffd700; background: #332b00; }

        #message-overlay {
            position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
            padding: 30px 50px;
            background: rgba(0, 0, 0, 0.95);
            border: 4px solid #fff;
            border-radius: 20px;
            box-shadow: 0 0 20px #ff00de;
            text-align: center; font-size: 28px; font-weight: bold;
            color: #fff;
            pointer-events: none; z-index: 160;
            display: none;
            opacity: 0; transition: opacity 0.3s;
        }

        .card-icon {
            width: 60px; height: 60px;
            margin-bottom: 5px;
            border-radius: 50%;
            border: 2px solid #000;
            background-color: #000;
        }

        .card-title { font-size: 14px; font-weight: bold; margin-bottom: 4px; min-height: 32px; display:flex; align-items:center; justify-content:center; }
        .card-desc { font-size: 11px; color: #ccc; margin-bottom: 5px; height: 50px; overflow: hidden; line-height: 1.2; }
        .card-lv { font-size: 14px; font-weight: bold; color: #ffb6c1; }
        .evo-text { color: #ffd700; text-shadow: 0 0 5px #ff4500; }
        
        .global-card { border-color: #87ceeb; }
        .upgrade-actions { display:flex; gap:12px; margin-top: 14px; }
        .upgrade-btn { padding: 10px 18px; font-size: 18px; font-weight: bold; border-radius: 12px; border: 2px solid #fff; background: #333; color: #fff; cursor: pointer; }
        .upgrade-btn:hover { background: #555; }
        .upgrade-btn:disabled { opacity: 0.35; cursor: default; }

        
    
        /* Bonus sheet overlay (every 10 waves) */
        #bonus-overlay{
            position:absolute; top:0; left:0; width:100%; height:100%;
            background: rgba(0,0,0,0.88);
            display:none; flex-direction:column;
            align-items:center; justify-content:center;
            z-index: 170; pointer-events: all;
            text-align:center;
        }
        #bonus-title{ font-size:28px; font-weight:bold; margin-bottom:10px; color:#ffb6c1; }
        #bonus-img{
            width: 645px; height: 360px;
            border: 4px solid #fff;
            border-radius: 18px;
            box-shadow: 0 0 18px rgba(255,182,193,0.35);
            background-image: url('../assets/img/icons.png');
            background-size: 200% 400%;
            background-repeat:no-repeat;
            background-position: 0% 0%;
            margin: 8px 0 14px;
        }
        #bonus-msg{ font-size:18px; margin-bottom:14px; white-space:pre-wrap; }


/* Game Over: upgrade list layout */
.go-summary{
  display: grid;
  grid-template-columns: 1fr 1fr;
  column-gap: 18px;
  row-gap: 4px;
  margin-bottom: 12px;
}
.go-upgrades-title{
  margin: 6px 0 10px;
  font-weight: bold;
}
.upgrade-grid{
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px 14px;
  max-height: 40vh;
  overflow: auto;
  padding-right: 6px;
}
.upgrade-item{
  font-size: 16px;
  line-height: 1.35;
  word-break: break-word;
  opacity: 0.95;
}
@media (max-width: 700px){
  .go-summary{ grid-template-columns: 1fr; }
  .upgrade-grid{ grid-template-columns: repeat(2, minmax(0, 1fr)); }
}


/* Wave forecast (icon-only) */
#wave-roadmap.wave-roadmap{
    margin-top: 4px;
    display: flex;
    align-items: center;
    gap: 6px;
    pointer-events: none;
    user-select: none;
    opacity: 0.95;
    filter: drop-shadow(0 1px 2px rgba(0,0,0,0.7));
}
#wave-roadmap .wave-roadmap-slot{
    image-rendering: pixelated;
    width: 28px;
    height: 28px;
    border-radius: 4px;
    background-color: rgba(0,0,0,0.25);
    background-position: 0 0;
}
#wave-roadmap .wave-roadmap-arrow{
    font-size: 18px;
    line-height: 18px;
    opacity: 0.9;
    margin-right: 2px;
}


button, .upgrade-card, .upgrade-btn, .btn-start, input[type="radio"], label { touch-action: manipulation; }

@media (pointer: coarse) {
  .overlay-title { font-size: 34px; }
  .overlay-desc { font-size: 19px; line-height: 1.7; padding: 0 16px; }
  .btn-start { padding: 16px 28px; font-size: 24px; min-height: 52px; }
  .btn-start.btn-sub { font-size: 22px; }
  .upgrade-btn { min-height: 50px; }
  .upgrade-card { width: 150px; }
  .card-title { font-size: 15px; }
  .card-desc { font-size: 12px; }
  #status-info { font-size: 20px; }
  #start-version { font-size: 18px; }
}


#shop-panel{ box-sizing:border-box; }

@media (max-width: 900px), (max-height: 720px){
  .overlay-screen{
    padding: 14px;
    box-sizing: border-box;
    justify-content: flex-start;
    overflow: auto;
  }
  .overlay-title{ font-size: 30px; margin: 6px 0 14px; }
  .overlay-desc{ font-size: 15px; line-height: 1.6; max-width: min(92vw, 760px); }
  .start-actions{ flex-wrap: wrap; gap: 10px; }
  .btn-start{ font-size: 20px; padding: 12px 26px; }
  .btn-start.btn-sub{ font-size: 18px; padding: 11px 22px; }

  #upgrade-screen{
    justify-content: flex-start;
    overflow: auto;
    padding: 14px 12px 18px;
    box-sizing: border-box;
  }
  .card-container{
    width: 100%;
    max-width: 100%;
    gap: 10px;
    align-items: stretch;
  }
  .upgrade-card{
    width: min(138px, calc(50vw - 28px));
  }
  .upgrade-actions{
    width: 100%;
    justify-content: center;
    flex-wrap: wrap;
    padding-bottom: 4px;
  }
  .upgrade-btn{ font-size: 16px; }

  #shop-panel,
  #options-panel,
  #wave-result-overlay > div{
    width: min(94vw, 760px) !important;
    max-height: 88vh !important;
    overflow: auto !important;
  }
  #shop-items{ grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
  #options-top{ gap: 8px !important; }
  #options-panel > div:nth-of-type(3){
    grid-template-columns: 1fr !important;
  }
}

@media (max-width: 560px), (max-height: 620px){
  #ui{
    width: calc(100% - 28px);
    top: 8px;
  }
  #status-info{
    font-size: 14px;
    gap: 6px;
    flex-wrap: wrap;
    justify-content: center;
  }
  #wall-bomb-info{ font-size: 14px; }
  #wall-bomb-info .bomb-icon{ font-size: 14px; }
  #wall-bomb-count{ font-size: 13px; }
  #skill-panel{
    top: 8px;
    left: 8px;
    gap: 4px;
    row-gap: 4px;
    column-gap: 5px;
    height: 452px; /* 34*12 + 4*11 */
  }
  #options-ally-panel{
    gap: 4px;
    row-gap: 4px;
    column-gap: 5px;
    height: 452px;
  }
  .skill-slot{ width: 34px; height: 34px; }
  #options-ally-panel .skill-slot{ width:34px; height:34px; }
  .skill-lv{ font-size: 10px; }

  .overlay-title{ font-size: 26px; }
  .overlay-desc{ font-size: 14px; }
  .btn-start{ width: min(280px, 90vw); }

  .upgrade-card{
    width: min(150px, calc(50vw - 24px));
    padding: 7px;
  }
  .card-title{ font-size: 13px; min-height: 28px; }
  .card-desc{ font-size: 10px; height: 44px; }
  .card-icon{ width: 52px; height: 52px; }

  #shop-items,
  #opt-relics,
  #opt-upgrades,
  .upgrade-grid{
    grid-template-columns: 1fr !important;
  }
  #bonus-img{
    width: min(92vw, 645px);
    height: min(52vw, 360px);
  }
}


#opt-relics, #opt-upgrades { align-content: start; }

@media (orientation: landscape) and (max-height: 640px){
  #ui{
    left: 78px;
    transform: none;
    width: calc(100% - 118px);
    top: 6px;
  }
  .hp-bar-wrapper,
  .hp-bar-bg{ height: 20px; }
  #hp-text{ line-height: 20px; font-size: 12px; }
  #status-info{
    margin-top: 3px;
    font-size: 14px;
    gap: 8px;
    flex-wrap: wrap;
  }
  #wall-bomb-info{ font-size: 13px; padding: 0 6px; }
  #wall-bomb-info .bomb-icon{ font-size: 13px; }
  #wall-bomb-count{ font-size: 12px; }
  #wave-roadmap{ margin-top: 3px; gap: 4px; }
  #wave-roadmap .wave-roadmap-slot{
    width: 22px;
    height: 22px;
    background-size: 88px 22px !important;
  }
  #wave-roadmap .wave-roadmap-arrow{
    font-size: 14px;
    line-height: 14px;
    margin-right: 1px;
  }
  #skill-panel{
    top: 6px;
    left: 6px;
    gap: 3px;
    row-gap: 3px;
    column-gap: 4px;
    height: 393px; /* 30*12 + 3*11 */
  }
  #options-ally-panel{
    gap: 3px;
    row-gap: 3px;
    column-gap: 4px;
    height: 393px;
  }
  .skill-slot{ width: 30px; height: 30px; }
  #options-ally-panel .skill-slot{ width:30px; height:30px; }
  .skill-lv{ font-size: 9px; }

  #options-panel{
    width: min(96vw, 900px) !important;
    height: auto !important;
    max-height: calc(100svh - 20px) !important;
    padding: 12px !important;
    gap: 8px !important;
  }
  #options-top{
    font-size: 13px !important;
    gap: 10px !important;
  }
  #options-panel > div:nth-of-type(3){
    display: block !important;
    flex: none !important;
    min-height: auto !important;
  }
  #options-panel > div:nth-of-type(3) > div{
    min-height: auto !important;
  }
  #options-panel > div:nth-of-type(3) > div + div{
    margin-top: 10px;
  }
  #opt-relics,
  #opt-upgrades{
    grid-template-columns: 1fr !important;
    max-height: none !important;
  }
  #btn-options-close{
    padding: 7px 12px !important;
    font-size: 15px !important;
  }
}


/* ================================================================
   v415 UI foundation: non-battle interlude background
   - Uses assets/img/ui/interlude_bg.webp for menu / shop / event / upgrade / result overlays.
   - Battle background is unchanged.
   ================================================================ */
:root{
  --interlude-bg: url('../assets/img/ui/interlude_bg.webp');
  --ui-panel-bg: rgba(18, 18, 20, 0.88);
  --ui-panel-border: rgba(255, 255, 255, 0.16);
  --ui-shadow-strong: 0 18px 48px rgba(0,0,0,0.58);
}

/* Full-screen non-battle surfaces */
.overlay-screen,
#upgrade-screen,
#bonus-overlay,
#wave-result-overlay,
[id^="evt-"]{
  background-image:
    linear-gradient(rgba(0,0,0,0.48), rgba(0,0,0,0.68)),
    var(--interlude-bg) !important;
  background-size: cover !important;
  background-position: center center !important;
  background-repeat: no-repeat !important;
}

/* Dark veil to make text and cards readable */
.overlay-screen::before,
#upgrade-screen::before,
#bonus-overlay::before,
#wave-result-overlay::before,
[id^="evt-"]::before{
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at center, rgba(0,0,0,0.12), rgba(0,0,0,0.54) 72%),
    linear-gradient(rgba(0,0,0,0.18), rgba(0,0,0,0.34));
  z-index: -1;
}

/* Ensure overlays can host the pseudo-layer safely */
.overlay-screen,
#upgrade-screen,
#bonus-overlay,
#wave-result-overlay,
[id^="evt-"]{
  position: fixed;
  overflow: hidden;
}

/* Main panels: slightly more deliberate card look */
.overlay-screen > *,
#upgrade-screen > *,
#bonus-overlay > *,
#wave-result-overlay > div,
[id^="evt-"] > div{
  position: relative;
  z-index: 1;
}

/* Event and result cards created by JS use inline styles, so only gentle overrides here. */
[id^="evt-"] > div,
#wave-result-overlay > div,
#bonus-overlay,
#upgrade-screen{
  box-shadow: var(--ui-shadow-strong) !important;
}

/* Upgrade screen readability on the new background */
#upgrade-screen{
  background-color: rgba(0,0,0,0.55) !important;
  border: 1px solid var(--ui-panel-border);
}

/* Start/help/gameover cards gain a subtle panel treatment without changing layout. */
.overlay-screen{
  text-shadow: 0 2px 6px rgba(0,0,0,0.75);
}

/* Small reusable HUD strip for later UI work. Added now as a stable style hook. */
.ui-mini-hud{
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  align-items: center;
  justify-content: center;
  padding: 8px 12px;
  margin: 0 auto 12px;
  border: 1px solid rgba(255,255,255,0.14);
  border-radius: 14px;
  background: rgba(0,0,0,0.44);
  box-shadow: 0 8px 22px rgba(0,0,0,0.35);
  font-weight: 700;
  line-height: 1.35;
}

.ui-value-pop{
  animation: uiValuePopV415 0.42s ease-out;
}

@keyframes uiValuePopV415{
  0% { transform: scale(1); filter: brightness(1); }
  35% { transform: scale(1.16); filter: brightness(1.55); }
  100% { transform: scale(1); filter: brightness(1); }
}


/* ================================================================
   v416 Interlude shutter + overlay background fix
   - Non-battle overlays use a shared shutter background layer.
   - Event/shop overlays keep their panels, but the battlefield is covered by the interlude shutter.
   ================================================================ */
#interlude-shutter{
  position: fixed;
  inset: 0;
  z-index: 9000;
  pointer-events: none;
  background-image:
    radial-gradient(circle at center, rgba(0,0,0,0.10), rgba(0,0,0,0.58) 76%),
    linear-gradient(rgba(0,0,0,0.26), rgba(0,0,0,0.52)),
    var(--interlude-bg);
  background-size: cover;
  background-position: center center;
  background-repeat: no-repeat;
  transform: translateY(-105%);
  opacity: 0;
  transition:
    transform 920ms cubic-bezier(.18,.78,.22,1),
    opacity 320ms ease-out;
  box-shadow: 0 16px 32px rgba(0,0,0,0.65);
}

#interlude-shutter::after{
  content:"";
  position:absolute;
  left:0;
  right:0;
  bottom:-18px;
  height:36px;
  background: linear-gradient(to bottom, rgba(0,0,0,.78), rgba(0,0,0,0));
  pointer-events:none;
}

body.interlude-active #interlude-shutter,
body.interlude-leaving #interlude-shutter{
  opacity: 1;
}

body.interlude-active #interlude-shutter{
  transform: translateY(0);
}

body.interlude-leaving #interlude-shutter{
  transform: translateY(-105%);
}

/* Keep the shared background visible behind event/shop panels.
   Inline JS styles use background: rgba(...), so we override only full-screen overlay backgrounds. */
#shop-overlay,
#event-overlay,
#gamble-overlay,
#catpick-overlay,
#anemoge-overlay,
#event-debug-picker-overlay,
[id^="evt-"],
#upgrade-screen,
#bonus-overlay,
#wave-result-overlay,
.overlay-screen{
  background-color: rgba(0,0,0,0.30) !important;
}

/* Prevent duplicate full overlay backgrounds fighting the shutter layer. */
#shop-overlay,
#event-overlay,
#gamble-overlay,
#catpick-overlay,
#anemoge-overlay,
#event-debug-picker-overlay,
[id^="evt-"]{
  background-image: none !important;
}

/* Upgrade/start/result screens can still use their direct background when the shutter layer is not ready. */
#upgrade-screen,
#bonus-overlay,
#wave-result-overlay,
.overlay-screen{
  background-image:
    linear-gradient(rgba(0,0,0,0.44), rgba(0,0,0,0.64)),
    var(--interlude-bg) !important;
}

/* Panels should always sit above the shutter layer. */
#shop-panel,
#event-panel,
#gamble-overlay > div,
#catpick-overlay > div,
#anemoge-overlay > div,
[id^="evt-"] > div,
#wave-result-overlay > div,
#bonus-overlay > *,
#upgrade-screen > *,
.overlay-screen > *{
  position: relative;
  z-index: 1;
}

/* Give shop/event panels the same weight as other interlude cards. */
#shop-panel,
#event-panel,
#gamble-overlay > div,
#catpick-overlay > div,
#anemoge-overlay > div,
[id^="evt-"] > div{
  box-shadow: var(--ui-shadow-strong) !important;
  border: 1px solid var(--ui-panel-border) !important;
}


/* ================================================================
   v417 Wave presentation
   ================================================================ */
#stage-title{
  min-width: min(760px, 84vw);
  max-width: 90vw;
  text-align: center;
  padding: 18px 26px !important;
  border-radius: 18px !important;
  border: 1px solid rgba(255,255,255,0.24);
  background:
    linear-gradient(120deg, rgba(255,255,255,0.10), rgba(255,255,255,0.02)),
    rgba(0,0,0,0.72) !important;
  box-shadow:
    0 18px 52px rgba(0,0,0,0.55),
    inset 0 0 26px rgba(255,255,255,0.06);
  font-size: 34px !important;
  letter-spacing: 0.08em !important;
  line-height: 1.2;
  white-space: pre-line;
}

#stage-title.stage-title-normal::before,
#stage-title.stage-title-clear::before{
  content:"";
  position:absolute;
  left:18px;
  right:18px;
  top:50%;
  height:1px;
  background: linear-gradient(to right, transparent, rgba(255,255,255,0.42), transparent);
  transform: translateY(-50%);
  opacity:.38;
  pointer-events:none;
}

#stage-title.stage-title-normal{
  color:#fff !important;
  text-shadow:
    0 2px 0 rgba(0,0,0,0.65),
    0 0 18px rgba(120,190,255,0.42) !important;
}

#stage-title.stage-title-clear{
  color:#fff8c9 !important;
  text-shadow:
    0 2px 0 rgba(0,0,0,0.7),
    0 0 18px rgba(255,220,120,0.48) !important;
}

#stage-title.stage-title-warning{
  color:#ffe2e2 !important;
  border-color: rgba(255,80,80,0.74) !important;
  background:
    repeating-linear-gradient(-45deg, rgba(255,40,40,.16) 0 12px, rgba(0,0,0,.00) 12px 24px),
    linear-gradient(120deg, rgba(120,0,0,.58), rgba(0,0,0,.82)) !important;
  text-shadow:
    0 2px 0 rgba(0,0,0,0.8),
    0 0 18px rgba(255,40,40,0.78) !important;
  animation: stageWarningPulseV417 0.72s ease-in-out infinite alternate;
}

#stage-title.stage-title-unknown{
  color:#d8fff8 !important;
  border-color: rgba(80,255,220,0.62) !important;
  background:
    repeating-linear-gradient(0deg, rgba(80,255,220,.10) 0 2px, rgba(0,0,0,0) 2px 5px),
    linear-gradient(120deg, rgba(0,40,38,.64), rgba(0,0,0,.88)) !important;
  text-shadow:
    2px 0 0 rgba(255,0,120,0.28),
    -2px 0 0 rgba(0,255,255,0.32),
    0 0 20px rgba(80,255,220,0.62) !important;
  animation: stageUnknownGlitchV417 0.36s steps(2,end) infinite;
}

.stage-title-sub{
  display:block;
  margin-bottom:8px;
  font-size:16px;
  letter-spacing:.24em;
  opacity:.92;
}

.stage-title-main{
  display:block;
  font-size:34px;
  font-weight:900;
}

@keyframes stageWarningPulseV417{
  0% { filter: brightness(1); transform: translate(-50%,-50%) scale(1); }
  100% { filter: brightness(1.28); transform: translate(-50%,-50%) scale(1.018); }
}

@keyframes stageUnknownGlitchV417{
  0% { filter: hue-rotate(0deg); transform: translate(-50%,-50%) skewX(0deg); }
  50% { filter: hue-rotate(12deg); transform: translate(calc(-50% + 2px),-50%) skewX(-1.2deg); }
  100% { filter: hue-rotate(-8deg); transform: translate(calc(-50% - 2px),-50%) skewX(1.2deg); }
}


/* ================================================================
   v418 Interlude shutter z-index hotfix
   - The shutter is a background layer only.
   - Buttons/panels must always be above it.
   ================================================================ */
#interlude-shutter{
  z-index: 9000 !important;
  pointer-events: none !important;
}

.overlay-screen,
#upgrade-screen,
#bonus-overlay,
#wave-result-overlay,
#shop-overlay,
#event-overlay,
#gamble-overlay,
#catpick-overlay,
#anemoge-overlay,
#event-debug-picker-overlay,
#ending-overlay,
#relic-overlay,
#options-overlay,
#settings-overlay,
[id^="evt-"]{
  z-index: 9500 !important;
}

/* The stage title is independent from interlude overlays and should remain on top during battle. */
#stage-title{
  z-index: 9800 !important;
}

/* Extra guard: any direct child panel/button area of non-battle surfaces stays above the shutter visually. */
.overlay-screen > *,
#upgrade-screen > *,
#bonus-overlay > *,
#wave-result-overlay > *,
#shop-overlay > *,
#event-overlay > *,
#gamble-overlay > *,
#catpick-overlay > *,
#anemoge-overlay > *,
[id^="evt-"] > *{
  position: relative;
  z-index: 1;
}


/* ================================================================
   v419 Interlude shutter container hotfix
   - Shutter must live inside #game-container.
   - It is a background layer, below START / CLEAR / SHOP / EVENT panels.
   ================================================================ */
#game-container{
  overflow: hidden;
}

#interlude-shutter{
  position: absolute !important;
  inset: 0 !important;
  z-index: 80 !important;
  pointer-events: none !important;
  transform: translateY(-105%);
  opacity: 0;
  transition:
    transform 920ms cubic-bezier(.18,.78,.22,1),
    opacity 320ms ease-out;
}

body.interlude-active #interlude-shutter,
body.interlude-leaving #interlude-shutter{
  opacity: 1;
}

body.interlude-active #interlude-shutter{
  transform: translateY(0);
}

body.interlude-leaving #interlude-shutter{
  transform: translateY(-105%);
}

/* Game-container native overlays are above the shutter. */
.overlay-screen{
  z-index: 150 !important;
}
#upgrade-screen{
  z-index: 160 !important;
}
#bonus-overlay{
  z-index: 170 !important;
}
#wave-result-overlay{
  z-index: 180 !important;
}

/* Body-level overlays are naturally above the game-container. */
#shop-overlay,
#event-overlay,
#gamble-overlay,
#catpick-overlay,
#anemoge-overlay,
#event-debug-picker-overlay,
#ending-overlay,
#relic-overlay,
#options-overlay,
#settings-overlay,
[id^="evt-"]{
  z-index: 9999 !important;
}

/* The shutter should never hide interactive children. */
.overlay-screen > *,
#upgrade-screen > *,
#bonus-overlay > *,
#wave-result-overlay > *,
#shop-overlay > *,
#event-overlay > *,
#gamble-overlay > *,
#catpick-overlay > *,
#anemoge-overlay > *,
[id^="evt-"] > *{
  position: relative;
  z-index: 1;
}


/* ================================================================
   v420 Interlude shutter timing tweak
   - Closing/down motion is slightly slower.
   - Opening/up motion keeps the v419 speed.
   ================================================================ */
body.interlude-active #interlude-shutter{
  transition:
    transform 1120ms cubic-bezier(.18,.78,.22,1),
    opacity 300ms ease-out;
}

body.interlude-leaving #interlude-shutter{
  transition:
    transform 920ms cubic-bezier(.18,.78,.22,1),
    opacity 320ms ease-out;
}


/* ================================================================
   v423d Combat-like interlude HUD
   - Mirrors the battle HUD position using canvas coordinates.
   - Discount tickets are shown in the related shop/upgrade/reroll UIs, not here.
   ================================================================ */
#interlude-common-hud{
  position:fixed;
  width:800px;
  box-sizing:border-box;
  z-index:10050;
  pointer-events:none;
  text-shadow:2px 2px 0 #000;
  color:#fff;
}
#interlude-common-hud .ih-hpwrap{
  width:100%;
  height:25px;
  position:relative;
}
#interlude-common-hud .hp-bar-bg{
  width:100%;
  height:25px;
  background:#333;
  border:2px solid #fff;
  border-radius:12px;
  overflow:hidden;
  position:relative;
  box-sizing:border-box;
}
#interlude-common-hud .ih-hp-bar{
  height:100%;
  background:linear-gradient(to right, #ff4500 0%, #ffd700 45%, #32cd32 100%);
  background-size:800px 100%;
  background-repeat:no-repeat;
  background-position:left center;
  transition:width .2s;
}
#interlude-common-hud .ih-hp-text{
  position:absolute;
  inset:0;
  text-align:center;
  line-height:25px;
  font-weight:bold;
  font-size:14px;
  z-index:5;
}
#interlude-common-hud .ih-status-info{
  display:flex;
  justify-content:space-between;
  align-items:center;
  margin-top:5px;
  font-size:18px;
  font-weight:bold;
  gap:10px;
}
#interlude-common-hud .ih-status-info > span{
  white-space:nowrap;
}
#interlude-common-hud .ih-enemy-slot{
  min-width:150px;
  text-align:right;
  opacity:0;
}
#interlude-common-hud #interlude-wave-roadmap{
  margin-top:4px;
}
#interlude-common-hud .wave-roadmap{
  display:flex;
  align-items:center;
  gap:6px;
  pointer-events:none;
  user-select:none;
  opacity:0.95;
  filter:drop-shadow(0 1px 2px rgba(0,0,0,0.7));
}
#interlude-common-hud .wave-roadmap-slot{
  image-rendering:pixelated;
  width:28px;
  height:28px;
  border-radius:4px;
  background-color:rgba(0,0,0,0.25);
  background-position:0 0;
}
#interlude-common-hud .wave-roadmap-arrow{
  font-size:18px;
  line-height:18px;
  opacity:0.9;
  margin-right:2px;
}
@media (max-width: 560px), (max-height: 620px){
  #interlude-common-hud .ih-status-info{
    font-size:14px;
    gap:6px;
  }
  #interlude-common-hud .ih-enemy-slot{
    min-width:120px;
  }
  #interlude-common-hud .wave-roadmap{
    margin-top:3px;
    gap:4px;
  }
  #interlude-common-hud .wave-roadmap-slot{
    width:22px;
    height:22px;
    background-size:88px 22px !important;
  }
  #interlude-common-hud .wave-roadmap-arrow{
    font-size:14px;
    line-height:14px;
    margin-right:1px;
  }
}



/* v424: Discount visibility in the actual shop/upgrade/reroll UI. */
.price-old{ opacity:.65; text-decoration:line-through; margin-right:4px; white-space:nowrap; }
.price-new{ color:#ffe680; font-weight:900; margin-right:6px; white-space:nowrap; }
.discount-badge{ display:inline-block; margin-left:4px; padding:1px 6px; border-radius:999px; background:rgba(255,230,128,.18); border:1px solid rgba(255,230,128,.55); color:#fff2a8; font-size:11px; font-weight:800; white-space:nowrap; }
.upgrade-price-line{ font-size:12px; color:#ffb6c1; font-weight:bold; }

/* ================================================================
   v425 Event UI normalization
   - Old custom event overlays and standard event overlays share the same card/choice style.
   - Keeps the battle/non-battle HUD area clear by starting event panels below the HUD.
   ================================================================ */
#event-overlay,
#gamble-overlay,
#catpick-overlay,
[id^="evt-"]{
  align-items: flex-start !important;
  justify-content: center !important;
  box-sizing: border-box !important;
  padding: 112px 14px 18px !important;
}

#event-panel,
#gamble-overlay > .evt-panel,
#catpick-overlay > .evt-panel,
[id^="evt-"] > .evt-panel,
[id^="evt-"] > div{
  width: min(620px, 94vw) !important;
  max-height: calc(100vh - 138px) !important;
  overflow: auto !important;
  box-sizing: border-box !important;
  padding: 16px !important;
  color: #fff !important;
  background: linear-gradient(180deg, rgba(24,24,30,.96), rgba(12,12,16,.94)) !important;
  border: 1px solid rgba(255,255,255,.18) !important;
  border-radius: 18px !important;
  box-shadow: 0 18px 54px rgba(0,0,0,.62) !important;
}

.evt-title,
#event-title,
#gamble-title,
#catpick-overlay .evt-title{
  font-size: 20px !important;
  line-height: 1.25 !important;
  font-weight: 900 !important;
  letter-spacing: .02em !important;
  margin: 0 0 12px !important;
  padding: 0 0 8px !important;
  border-bottom: 1px solid rgba(255,255,255,.14) !important;
  color: #fff !important;
  text-shadow: 0 2px 5px rgba(0,0,0,.75) !important;
}

.evt-img,
#event-illus,
#gamble-illus,
#catpick-illus{
  display: block !important;
  width: 100% !important;
  max-height: 300px !important;
  object-fit: contain !important;
  box-sizing: border-box !important;
  margin: 0 0 12px !important;
  border-radius: 14px !important;
  border: 1px solid rgba(255,255,255,.16) !important;
  background: rgba(0,0,0,.28) !important;
}

.evt-desc,
#event-desc,
#gamble-desc,
#catpick-desc{
  margin: 0 0 12px !important;
  padding: 10px 12px !important;
  border-radius: 12px !important;
  background: rgba(0,0,0,.25) !important;
  border: 1px solid rgba(255,255,255,.10) !important;
  color: rgba(255,255,255,.96) !important;
  font-size: 14px !important;
  line-height: 1.55 !important;
  white-space: pre-wrap !important;
}

.evt-result,
#event-result{
  margin: 10px 0 0 !important;
  padding: 10px 12px !important;
  border-radius: 12px !important;
  background: rgba(255,255,255,.07) !important;
  border: 1px solid rgba(255,255,255,.14) !important;
  color: #fff !important;
  font-size: 14px !important;
  line-height: 1.55 !important;
  white-space: pre-wrap !important;
}

.evt-choices,
#event-choice-wrap,
#event-list-wrap,
#gamble-overlay .evt-panel > div:nth-last-child(1),
#catpick-overlay .evt-panel > div{
  gap: 8px !important;
}

.evt-choices{
  display: grid !important;
  grid-template-columns: 1fr !important;
}

.evt-choices button,
#event-choice-wrap button,
#event-list-wrap button,
#gamble-overlay button,
#catpick-overlay button,
.evt-footer button{
  width: 100% !important;
  box-sizing: border-box !important;
  padding: 10px 12px !important;
  border-radius: 12px !important;
  border: 1px solid rgba(255,255,255,.18) !important;
  background: rgba(255,255,255,.085) !important;
  color: #fff !important;
  cursor: pointer !important;
  text-align: left !important;
  font: 700 14px/1.35 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif !important;
  transition: background .12s ease, transform .08s ease, border-color .12s ease !important;
}

.evt-choices button:hover:not(:disabled),
#event-choice-wrap button:hover:not(:disabled),
#event-list-wrap button:hover:not(:disabled),
#gamble-overlay button:hover:not(:disabled),
#catpick-overlay button:hover:not(:disabled),
.evt-footer button:hover:not(:disabled){
  background: rgba(255,255,255,.14) !important;
  border-color: rgba(255,255,255,.34) !important;
  transform: translateY(-1px) !important;
}

.evt-choices button:disabled,
#event-choice-wrap button:disabled,
#event-list-wrap button:disabled,
#gamble-overlay button:disabled,
#catpick-overlay button:disabled{
  opacity: .48 !important;
  cursor: not-allowed !important;
  transform: none !important;
}

.evt-choice-good{ border-color: rgba(120,220,150,.34) !important; background: rgba(80,190,120,.13) !important; }
.evt-choice-special{ border-color: rgba(130,200,255,.34) !important; background: rgba(90,170,230,.13) !important; }
.evt-choice-danger{ border-color: rgba(255,130,130,.34) !important; background: rgba(190,80,80,.16) !important; }

.evt-footer{
  display: flex !important;
  justify-content: flex-end !important;
  gap: 10px !important;
  margin-top: 12px !important;
}
.evt-footer button,
.evt-ok,
.evt-cancel{
  width: auto !important;
  min-width: 88px !important;
  text-align: center !important;
}

/* The old cat-pick leave button was absolutely positioned. Keep it inside the common flow. */
#catpick-btn-leave{
  position: static !important;
  right: auto !important;
  bottom: auto !important;
  margin-top: 10px !important;
}
#catpick-overlay .catpick-panel{
  padding: 16px !important;
}

@media (max-width: 700px){
  #event-overlay,
  #gamble-overlay,
  #catpick-overlay,
  [id^="evt-"]{
    padding-top: 98px !important;
  }
  #event-panel,
  #gamble-overlay > .evt-panel,
  #catpick-overlay > .evt-panel,
  [id^="evt-"] > .evt-panel,
  [id^="evt-"] > div{
    max-height: calc(100vh - 116px) !important;
    padding: 12px !important;
  }
  .evt-img,
  #event-illus,
  #gamble-illus,
  #catpick-illus{
    max-height: 230px !important;
  }
  .evt-title,
  #event-title,
  #gamble-title,
  #catpick-overlay .evt-title{
    font-size: 17px !important;
  }
}

/* v425b: selection buttons must disappear after an event choice is confirmed.
   v425 normalized .evt-choices with display:grid !important, which overrode
   inline choices.style.display='none' used by older handlers. */
.evt-choices[style*="display: none"],
.evt-choices[hidden],
.evt-choices.is-hidden{
  display: none !important;
}


/* ================================================================
   v427 Shop / upgrade UI readability
   - Discount labels are red, not yellow.
   - Shop / upgrade panels start below the combat-like HUD and wave forecast.
   - Shop cards have clearer purchased / unavailable states.
   ================================================================ */
.price-new{
  color:#ff4d4d !important;
  text-shadow:0 1px 0 #000, 0 0 8px rgba(255,60,60,.45) !important;
}
.discount-badge{
  color:#ff5a5a !important;
  background:rgba(255,60,60,.16) !important;
  border-color:rgba(255,90,90,.68) !important;
  text-shadow:0 1px 0 #000 !important;
}
.upgrade-price-line .price-new,
.card-desc .price-new{
  color:#ff6666 !important;
}
#shop-overlay{
  align-items:flex-start !important;
  justify-content:center !important;
  box-sizing:border-box !important;
  padding:116px 14px 18px !important;
}
#shop-panel{
  max-height:calc(100vh - 138px) !important;
  margin:0 auto !important;
}
#upgrade-screen{
  justify-content:flex-start !important;
  box-sizing:border-box !important;
  padding:116px 12px 18px !important;
  overflow:auto !important;
}
#upgrade-screen > h2{
  margin-top:0 !important;
}
.shop-card{
  transition:transform .12s ease, border-color .12s ease, background .12s ease, opacity .12s ease;
}
.shop-card.shop-can-buy{
  border-color:rgba(120,220,150,.42) !important;
  background:rgba(80,190,120,.09) !important;
}
.shop-card.shop-unaffordable{
  border-color:rgba(255,120,120,.38) !important;
  background:rgba(170,60,60,.10) !important;
}
.shop-card.shop-purchased{
  border-color:rgba(180,180,180,.24) !important;
  background:rgba(255,255,255,.035) !important;
  opacity:.64;
}
.shop-card.shop-limit-reached:not(.shop-purchased){
  opacity:.58;
}
.shop-card button{
  font-weight:900 !important;
  color:#222 !important;
}
.shop-card.shop-can-buy button{
  background:#ffffff !important;
}
.shop-card.shop-purchased button{
  background:#b9b9b9 !important;
}
.shop-card.shop-unaffordable button,
.shop-card.shop-limit-reached button{
  background:#d0d0d0 !important;
}
.shop-status-note{
  min-height:1.2em;
  margin-top:6px;
  font-size:11px;
  font-weight:800;
  text-align:right;
  color:rgba(255,255,255,.76);
}
.shop-status-note.warn{ color:#ff7777; }
.shop-status-note.ok{ color:#9dffb0; }
@media (max-width:700px), (max-height:620px){
  #shop-overlay{ padding-top:102px !important; }
  #shop-panel{ max-height:calc(100vh - 118px) !important; }
  #upgrade-screen{ padding-top:102px !important; }
}

/* ================================================================
   v429 Mobile / responsive UI pass
   - Keep combat-like HUD as the visual anchor.
   - Body-level panels start below the HUD/WAVE forecast using JS-set CSS vars.
   - Improve touch targets and narrow-screen card layouts without changing logic.
   ================================================================ */
:root{
  --interlude-panel-top: 116px;
  --interlude-panel-gap: 12px;
}

#shop-overlay,
#event-overlay,
#gamble-overlay,
#catpick-overlay,
#event-debug-picker-overlay,
#options-overlay,
[id^="evt-"]{
  align-items:flex-start !important;
  justify-content:center !important;
  box-sizing:border-box !important;
  padding:var(--interlude-panel-top) 12px 12px !important;
  overflow:hidden !important;
}

#options-overlay{
  display:none;
}

#shop-panel,
#event-panel,
#options-panel,
#event-debug-picker-overlay > div,
#gamble-overlay > .evt-panel,
#catpick-overlay > .evt-panel,
[id^="evt-"] > .evt-panel,
[id^="evt-"] > div{
  width:min(94vw, 920px) !important;
  max-height:calc(100svh - var(--interlude-panel-top) - 14px) !important;
  overflow:auto !important;
  -webkit-overflow-scrolling:touch;
}

#upgrade-screen{
  justify-content:flex-start !important;
  box-sizing:border-box !important;
  padding:var(--interlude-panel-top) 12px 12px !important;
  overflow:auto !important;
}
#upgrade-screen .card-container{
  max-width:min(94vw, 900px) !important;
}

#shop-items{
  align-items:stretch;
}

/* v438c: compact 4-column shop layout */
#shop-panel{
  width:min(1120px, calc(100vw - 48px)) !important;
}
#shop-items{
  grid-template-columns:repeat(4, minmax(0, 1fr)) !important;
  gap:10px !important;
}
#shop-illus{
  height:300px !important;
}
.shop-card{
  min-height:108px !important;
}
.shop-status-note{
  margin-top:4px !important;
  font-size:10px !important;
}
@media (max-width: 980px){
  #shop-panel{ width:min(96vw, 860px) !important; }
  #shop-items{ grid-template-columns:repeat(2, minmax(0, 1fr)) !important; }
  #shop-illus{ height:min(32svh, 240px) !important; }
}
.shop-card,
.upgrade-card,
.evt-choices button,
#event-choice-wrap button,
#event-list-wrap button,
#gamble-overlay button,
#catpick-overlay button,
.evt-footer button,
#shop-leave,
#btn-options-close,
#btn-open-settings{
  touch-action:manipulation;
}

@media (max-width: 760px){
  #interlude-common-hud .ih-status-info{
    font-size:16px;
    gap:7px;
  }
  #interlude-common-hud .ih-enemy-slot{
    min-width:110px;
  }
  #shop-items{
    grid-template-columns:repeat(2, minmax(0, 1fr)) !important;
  }
  #shop-illus{
    height:min(30svh, 220px) !important;
  }
  #event-panel,
  #gamble-overlay > .evt-panel,
  #catpick-overlay > .evt-panel,
  [id^="evt-"] > .evt-panel,
  [id^="evt-"] > div{
    width:min(94vw, 680px) !important;
    padding:12px !important;
  }
  .evt-img,
  #event-illus,
  #gamble-illus,
  #catpick-illus{
    max-height:min(28svh, 210px) !important;
  }
  .evt-choices button,
  #event-choice-wrap button,
  #event-list-wrap button{
    min-height:44px !important;
    font-size:14px !important;
  }
  #options-panel > div:nth-of-type(3){
    grid-template-columns:1fr !important;
  }
  #opt-relics,
  #opt-upgrades{
    grid-template-columns:1fr !important;
    max-height:32svh !important;
  }
}

@media (max-width: 520px){
  #interlude-common-hud .ih-status-info{
    font-size:13px;
    gap:5px;
  }
  #interlude-common-hud .ih-enemy-slot{
    min-width:72px;
  }
  #interlude-common-hud .ih-hpwrap,
  #interlude-common-hud .hp-bar-bg{
    height:22px;
  }
  #interlude-common-hud .ih-hp-text{
    line-height:22px;
    font-size:12px;
  }
  #shop-overlay,
  #event-overlay,
  #gamble-overlay,
  #catpick-overlay,
  #event-debug-picker-overlay,
  #options-overlay,
  [id^="evt-"]{
    padding-left:8px !important;
    padding-right:8px !important;
    padding-bottom:8px !important;
  }
  #shop-panel,
  #event-panel,
  #options-panel,
  #event-debug-picker-overlay > div,
  #gamble-overlay > .evt-panel,
  #catpick-overlay > .evt-panel,
  [id^="evt-"] > .evt-panel,
  [id^="evt-"] > div{
    width:calc(100vw - 16px) !important;
    border-radius:14px !important;
  }
  #shop-items{
    grid-template-columns:1fr !important;
  }
  .shop-card{
    min-height:auto !important;
  }
  #upgrade-screen .card-container{
    gap:8px !important;
  }
  .upgrade-card{
    width:min(44vw, 158px) !important;
    min-height:170px;
  }
  .upgrade-card .card-desc{
    height:42px;
  }
  .upgrade-actions{
    gap:8px !important;
  }
  .upgrade-btn{
    min-height:44px;
    padding:9px 12px !important;
    font-size:15px !important;
  }
  #options-top{
    font-size:12px !important;
    gap:7px !important;
  }
}

@media (orientation: landscape) and (max-height: 560px){
  #shop-overlay,
  #event-overlay,
  #gamble-overlay,
  #catpick-overlay,
  #event-debug-picker-overlay,
  #options-overlay,
  [id^="evt-"]{
    padding-top:calc(var(--interlude-panel-top) - 8px) !important;
    padding-bottom:8px !important;
  }
  #shop-panel,
  #event-panel,
  #options-panel,
  #event-debug-picker-overlay > div,
  #gamble-overlay > .evt-panel,
  #catpick-overlay > .evt-panel,
  [id^="evt-"] > .evt-panel,
  [id^="evt-"] > div{
    max-height:calc(100svh - var(--interlude-panel-top) - 6px) !important;
  }
  #shop-illus,
  .evt-img,
  #event-illus,
  #gamble-illus,
  #catpick-illus{
    max-height:26svh !important;
  }
  #opt-relics,
  #opt-upgrades{
    max-height:none !important;
  }
}


/* v429b mobile HUD overlap fix
   Keep the combat HUD layout, but reserve space for the options button on narrow portrait screens. */
@media (orientation: portrait) and (max-width: 760px){
  #ui{
    width:720px;
  }
  #status-info{
    font-size:16px;
    gap:10px;
  }
  #wave-roadmap.wave-roadmap{
    margin-top:5px;
    gap:5px;
  }
}

@media (orientation: portrait) and (max-width: 520px){
  #ui{
    width:700px;
  }
  #status-info{
    font-size:15px;
    gap:8px;
  }
}

@media (orientation: landscape) and (max-height: 560px){
  #wave-roadmap.wave-roadmap{
    max-width:720px;
    overflow:visible;
  }
}

/* v440: interlude HUD ally icon row */
.ih-ally-icons{
  display:flex;
  justify-content:center;
  align-items:center;
  gap:5px;
  margin-top:4px;
  min-height:24px;
}
.ih-ally-slot{
  position:relative;
  width:24px;
  height:24px;
  border-radius:999px;
  border:1px solid rgba(0,0,0,0.9);
  overflow:hidden;
  background:#111;
  box-shadow:0 1px 3px rgba(0,0,0,0.45);
}
.ih-ally-slot .ih-ally-icon{
  width:100%;
  height:100%;
  border-radius:999px;
  border:none;
  margin:0;
}
.ih-ally-slot span{
  position:absolute;
  right:-1px;
  bottom:-1px;
  min-width:11px;
  height:11px;
  padding:0 2px;
  border-radius:999px;
  background:rgba(0,0,0,0.82);
  color:#fff;
  border:1px solid rgba(255,255,255,0.72);
  font-size:8px;
  font-weight:900;
  line-height:10px;
  text-align:center;
  pointer-events:none;
}


/* v448g: non-battle ally panel uses the same visual base as the battle skill panel. */
#options-ally-panel{
  position:fixed;
  display:flex;
  flex-direction:column;
  flex-wrap:wrap;
  align-content:flex-start;
  gap:5px;
  row-gap:5px;
  column-gap:6px;
  height:535px; /* v448h: 12 slots per column: 40*12 + 5*11 */
  max-height:calc(100vh - 96px);
  z-index:10000;
  pointer-events:none;
}
#options-ally-panel .skill-slot{
  position:relative;
  width:40px;
  height:40px;
  border-radius:8px;
  border:2px solid #fff;
  background:#000;
  overflow:hidden;
  box-shadow:0 0 5px #000;
  flex:0 0 auto;
}
#options-ally-panel .interlude-ally-slot .cooldown-overlay,
#options-ally-panel .interlude-ally-slot .skill-charge{
  display:none !important;
}
#desc-icon{
  border-radius:999px !important;
  object-fit:cover !important;
  border:2px solid #000 !important;
  background:#fff !important;
  box-sizing:border-box !important;
}


/* v443b: keep recast cooldown overlays above the new character icon images. */
.skill-slot > .icon-base{
  position:absolute;
  inset:0;
  width:100%;
  height:100%;
  z-index:1;
}
.skill-slot > .cooldown-overlay{
  z-index:12;
  border-radius:999px;
  pointer-events:none;
}
.skill-slot > .skill-lv,
.skill-slot > .skill-charge{
  z-index:30;
}


/* v448f: during non-battle overlays, use body-level cloned HUDs.
   The real battle HUD lives inside #game-container and may be hidden by fixed overlays,
   so hide it during interlude and show only the clean cloned HUD/ally panel. */
body.interlude-hud-active #ui,
body.interlude-hud-active #skill-panel{
  display:none !important;
}
body.interlude-hud-active #interlude-common-hud{
  display:block;
  z-index:10050;
}
body.interlude-hud-active #options-ally-panel{
  display:flex;
  z-index:10051;
}
body:not(.interlude-hud-active) #interlude-common-hud,
body:not(.interlude-hud-active) #options-ally-panel{
  display:none !important;
}

/* v455a: wall damage HP bar shake */
.hp-bar-wrapper.wall-hit-shake-small{ animation: wallHitShakeSmall .22s ease-out; }
.hp-bar-wrapper.wall-hit-shake-big{ animation: wallHitShakeBig .34s ease-out; }
@keyframes wallHitShakeSmall{
  0%{ transform: translateX(0); }
  25%{ transform: translateX(-3px); }
  50%{ transform: translateX(3px); }
  75%{ transform: translateX(-2px); }
  100%{ transform: translateX(0); }
}
@keyframes wallHitShakeBig{
  0%{ transform: translateX(0); filter: brightness(1.35); }
  18%{ transform: translateX(-7px); }
  36%{ transform: translateX(7px); }
  54%{ transform: translateX(-5px); }
  72%{ transform: translateX(4px); }
  100%{ transform: translateX(0); filter: brightness(1); }
}

/* v457 title/gameover background */
#start-screen{
  background-image:
    linear-gradient(rgba(0,0,0,.42), rgba(0,0,0,.62)),
    url('../assets/img/ui/title.webp') !important;
  background-size: cover !important;
  background-position: center center !important;
}
#gameover-screen{
  background-image:
    linear-gradient(rgba(0,0,0,.48), rgba(0,0,0,.72)),
    url('../assets/img/ui/gameover.webp') !important;
  background-size: cover !important;
  background-position: center center !important;
}
#start-screen .overlay-title,
#start-screen .overlay-desc,
#start-screen .start-actions,
#start-version,
#start-audio-credit,
#gameover-screen .overlay-title,
#gameover-screen .overlay-desc{
  text-shadow: 0 3px 10px rgba(0,0,0,.95), 0 0 18px rgba(0,0,0,.65);
}

/* v458 start screen layout */
.start-screen-v458{
  align-items:center !important;
  justify-content:center !important;
}
#start-menu-panel{
  min-width:min(520px, 86vw);
  padding:28px 30px;
  border-radius:24px;
  background:rgba(0,0,0,.34);
  border:1px solid rgba(255,255,255,.14);
  box-shadow:0 18px 56px rgba(0,0,0,.42);
  backdrop-filter: blur(2px);
}
.start-actions-v458{
  display:grid !important;
  grid-template-columns:1fr 1fr;
  gap:16px !important;
  margin:0 !important;
}
.start-actions-v458 .btn-start{
  min-width:0;
  padding:16px 24px;
  font-size:24px;
}
#btn-continue-main:disabled{
  filter:grayscale(.4);
}
.modal-overlay-screen{
  z-index:10050 !important;
  background:rgba(0,0,0,.55) !important;
}
.modal-card{
  width:min(560px, 90vw);
  padding:28px;
  border-radius:22px;
  background:rgba(12,12,18,.88);
  border:1px solid rgba(255,255,255,.18);
  box-shadow:0 18px 54px rgba(0,0,0,.55);
}
.modal-title{
  font-size:32px !important;
  margin-bottom:18px !important;
}
.mode-grid{
  display:grid;
  grid-template-columns:1fr 1fr;
  gap:14px;
  margin:12px 0 18px;
}
.mode-btn{
  min-height:92px;
  line-height:1.35;
}
.mode-btn span{
  display:inline-block;
  margin-top:6px;
  font-size:14px;
  opacity:.9;
}
.modal-close{
  font-size:18px !important;
  padding:10px 28px !important;
}
.credit-desc{
  text-align:left;
  display:inline-block;
  font-size:18px !important;
  line-height:1.9 !important;
}
#start-version{
  font-size:14px !important;
}
@media (max-width: 560px){
  .start-actions-v458,
  .mode-grid{
    grid-template-columns:1fr;
  }
  #start-menu-panel{
    padding:22px 20px;
  }
}

/* v459 gameover result screen */
.gameover-v459{
  align-items:center !important;
  justify-content:center !important;
}
#gameover-panel{
  width:min(620px, 88vw);
  padding:28px;
  border-radius:24px;
  background:rgba(0,0,0,.42);
  border:1px solid rgba(255,255,255,.16);
  box-shadow:0 18px 56px rgba(0,0,0,.48);
  backdrop-filter: blur(2px);
}
.gameover-title{
  color:#ff3b3b !important;
  text-shadow:0 0 18px rgba(255,0,0,.5), 0 3px 12px #000 !important;
}
.go-main-stats{
  display:flex;
  justify-content:center;
  gap:28px;
  flex-wrap:wrap;
  margin:8px 0 22px;
  font-size:22px;
  font-weight:900;
}
.go-actions{
  display:grid;
  grid-template-columns:1fr;
  gap:12px;
  max-width:360px;
  margin:0 auto;
}
.go-actions .btn-start{
  font-size:22px;
  padding:13px 26px;
}
.gameover-detail-card{
  width:min(900px, 94vw) !important;
  max-height:92vh;
  overflow:hidden;
}
.go-detail-body{
  text-align:left;
  font-size:14px;
  line-height:1.45;
}
.go-detail-stats{
  display:flex;
  gap:18px;
  justify-content:center;
  flex-wrap:wrap;
  font-size:18px;
  margin-bottom:10px;
}
.go-detail-section{
  margin-top:10px;
}
.go-detail-heading{
  font-weight:900;
  margin-bottom:6px;
  text-align:center;
}
.go-chip-grid{
  display:flex;
  flex-wrap:wrap;
  gap:5px;
  justify-content:center;
  align-content:flex-start;
}
.go-chip{
  display:inline-block;
  padding:3px 7px;
  border-radius:999px;
  border:1px solid rgba(255,255,255,.14);
  background:rgba(255,255,255,.07);
  font-size:12px;
  white-space:nowrap;
}
.go-chip.muted{
  opacity:.65;
}
@media (max-height: 680px){
  #gameover-panel{ padding:20px; }
  .gameover-title{ font-size:34px !important; margin-bottom:10px !important; }
  .go-main-stats{ font-size:18px; margin-bottom:14px; }
  .go-actions .btn-start{ font-size:18px; padding:10px 20px; }
  .go-chip{ font-size:11px; padding:2px 6px; }
}

/* v460 keyboard smartphone polish */
.btn-start:focus-visible,
.upgrade-btn:focus-visible,
button:focus-visible{
  outline:3px solid rgba(255,230,90,.95) !important;
  outline-offset:3px !important;
  box-shadow:0 0 0 4px rgba(0,0,0,.55), 0 0 18px rgba(255,230,90,.45) !important;
}
.start-actions-v458 .btn-start,
.mode-btn,
.go-actions .btn-start{
  touch-action: manipulation;
  min-height:56px;
}
@media (max-width: 720px), (max-height: 560px){
  #start-menu-panel{
    width:min(92vw, 520px);
    padding:18px 18px !important;
  }
  .start-actions-v458{
    gap:10px !important;
  }
  .start-actions-v458 .btn-start{
    font-size:20px !important;
    padding:14px 16px !important;
    min-height:58px;
  }
  .modal-card{
    padding:20px !important;
  }
  .mode-btn{
    min-height:72px !important;
    font-size:19px !important;
  }
  .mode-btn span{
    font-size:12px !important;
  }
  #gameover-panel{
    width:min(92vw, 620px);
    padding:20px !important;
  }
}

/* v461 overlay keyboard polish */
#btn-next-phase:focus-visible,
#btn-upgrade-ok:focus-visible,
.evt-ok:focus-visible,
.evt-cancel:focus-visible,
#wave-result-overlay:focus-visible{
  outline:3px solid rgba(255,230,90,.95) !important;
  outline-offset:3px !important;
}

/* v463 wall damage shake + flash */
.hp-bar-wrapper.wall-hit-small{
  animation: wallHitSmallV463 .32s ease-out;
}
.hp-bar-wrapper.wall-hit-big{
  animation: wallHitBigV463 .50s ease-out;
}
.hp-bar-wrapper.wall-hit-small .hp-bar-bg,
.hp-bar-wrapper.wall-hit-small #hp-bar,
.hp-bar-wrapper.wall-hit-small .ih-hp-bar{
  animation: wallFlashSmallV463 .32s ease-out;
}
.hp-bar-wrapper.wall-hit-big .hp-bar-bg,
.hp-bar-wrapper.wall-hit-big #hp-bar,
.hp-bar-wrapper.wall-hit-big .ih-hp-bar{
  animation: wallFlashBigV463 .50s ease-out;
}
@keyframes wallHitSmallV463{
  0%{ transform: translateX(0); }
  20%{ transform: translateX(-3px); }
  42%{ transform: translateX(3px); }
  64%{ transform: translateX(-2px); }
  100%{ transform: translateX(0); }
}
@keyframes wallHitBigV463{
  0%{ transform: translateX(0); filter: brightness(1); }
  12%{ transform: translateX(-9px); filter: brightness(1.55); }
  26%{ transform: translateX(9px); }
  42%{ transform: translateX(-7px); }
  58%{ transform: translateX(6px); }
  78%{ transform: translateX(-3px); }
  100%{ transform: translateX(0); filter: brightness(1); }
}
@keyframes wallFlashSmallV463{
  0%{ box-shadow: inset 0 0 0 rgba(255,255,255,0); filter: brightness(1); }
  35%{ box-shadow: inset 0 0 18px rgba(255,220,140,.75); filter: brightness(1.28); }
  100%{ box-shadow: inset 0 0 0 rgba(255,255,255,0); filter: brightness(1); }
}
@keyframes wallFlashBigV463{
  0%{ box-shadow: inset 0 0 0 rgba(255,255,255,0); filter: brightness(1); }
  18%{ box-shadow: inset 0 0 28px rgba(255,90,90,.95), 0 0 18px rgba(255,80,80,.5); filter: brightness(1.65); }
  42%{ box-shadow: inset 0 0 22px rgba(255,190,80,.85), 0 0 14px rgba(255,120,60,.45); filter: brightness(1.35); }
  100%{ box-shadow: inset 0 0 0 rgba(255,255,255,0); filter: brightness(1); }
}
