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, #32cd32); 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: inline-flex; 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;
           gap: 5px;
           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 #888;
            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;
  }
  .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;
  }
  .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;
  }
}
