:root {
    --rpg-bg: #09280f;
    --rpg-panel: rgba(12, 33, 11, 0.96);
    --rpg-panel-2: rgba(8, 24, 9, 0.9);
    --rpg-border: rgba(2, 255, 119, 0.16);
    --rpg-text: #b6ffd8;
    --rpg-title: #7af78f;
    --rpg-accent: #d400b1;
    --rpg-hp: #02ff77;
    --rpg-hp-low: #ff4444;
    --rpg-gold: #ffd166;
}

body {
    background-color: var(--rpg-bg);
    color: #02ff77;
    font-family: '04b_03', Lato, sans-serif;
    background-image: url(https://img.itch.zone/aW1nLzI1ODUwMjE5LnBuZw==/original/Gbn3z7.png);
    background-repeat: repeat-x;
    background-position: 50% 0;
    background-attachment: fixed;
}

.wrapper {
    background-color: #09280f;
    background-image: url(https://img.itch.zone/aW1nLzI1ODUwMjE5LnBuZw==/original/Gbn3z7.png);
    background-repeat: repeat-x;
    background-position: 50% 0;
    background-attachment: fixed;
}

.inner_column {
    color: #02ff77;
    font-family: '04b_03', Lato, sans-serif;
    background-color: transparent;
    padding: 0;
}

.center {
    max-width: 1100px;
    margin: 22px auto 28px;
    background:
        linear-gradient(90deg, rgba(2, 255, 119, 0.07) 1px, transparent 1px),
        linear-gradient(rgba(2, 255, 119, 0.05) 1px, transparent 1px),
        rgba(12, 33, 11, 0.95);
    background-size: 16px 16px;
    padding: 24px;
    border: 1px solid var(--rpg-border);
    box-shadow: 5px 5px 0 rgba(0, 0, 0, 0.4);
}

.rpg-head { text-align: center; margin-bottom: 14px; }
.rpg-head h1 { margin: 0 0 8px; color: var(--rpg-title); }
.rpg-head p { margin: 0; color: var(--rpg-text); }

.page-actions {
    display: flex;
    justify-content: center;
    gap: 10px;
    flex-wrap: wrap;
    margin: 14px 0 20px;
}

.music-embed {
    max-width: 420px;
    margin: 0 auto 14px;
}
.music-embed iframe { display: block; border-radius: 4px; }

.inner_column .button {
    background-color: #d400b1;
    color: #ffffff;
    text-shadow: 0 1px 0 #ed19ca;
    border: 0;
    display: inline-block;
    padding: 9px 14px;
    line-height: 1.2;
    font-size: 0.95rem;
    font-family: inherit;
    font-weight: 700;
    text-decoration: none;
    cursor: pointer;
}
.inner_column .button:hover { filter: brightness(1.06); }
.inner_column .button:disabled { opacity: 0.4; cursor: not-allowed; filter: none; }
.inner_column .button.secondary { background-color: #1a5c2a; text-shadow: none; }
.inner_column .button.danger { background-color: #9c1c1c; text-shadow: none; }

/* ----- Screens ----- */
.rpg-screen { display: none; }
.rpg-screen.active { display: block; }

/* ----- HUD ----- */
.rpg-hud {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 14px;
    padding: 8px 12px;
    border: 1px solid var(--rpg-border);
    background: rgba(0,0,0,0.2);
}
.rpg-hud .stat { color: var(--rpg-text); font-size: 0.95rem; }
.rpg-hud .stat strong { color: var(--rpg-title); }

/* ----- Stage banner (FNaF-World-style zone title card) ----- */
.stage-banner {
    text-align: center;
    margin: 0 0 12px;
    padding: 6px 10px;
    font-size: 1rem;
    letter-spacing: 0.5px;
    color: #fff;
    background: linear-gradient(90deg, #1a5c2a, #0c2b12);
    border: 1px solid var(--rpg-border);
    text-shadow: 1px 1px 0 #000;
}
.stage-banner.boss-banner {
    background: linear-gradient(90deg, #9c1c1c, #4a0c0c);
    border-color: #ff8a4a;
    animation: boss-pulse 1.6s ease-in-out infinite;
}
@keyframes boss-pulse {
    0%, 100% { box-shadow: 0 0 0 rgba(255, 138, 74, 0); }
    50% { box-shadow: 0 0 14px rgba(255, 138, 74, 0.6); }
}

/* ----- Battlefield: FNaF-World style formation (enemies up top, squad on the ground) ----- */
.battlefield {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 16px;
    padding: 16px 12px;
    border: 1px solid var(--rpg-border);
    background-size: cover;
    background-position: center;
    transition: background 300ms ease;
}
.battlefield.arena-forest { background-image: radial-gradient(circle at 50% 0%, rgba(29,74,36,0.55), rgba(9,40,15,0.8) 75%), url('../maps/World1.webp'); }
.battlefield.arena-desert { background-image: radial-gradient(circle at 50% 0%, rgba(107,82,35,0.55), rgba(42,31,12,0.8) 75%), url('../maps/World2.webp'); }
.battlefield.arena-city { background-image: radial-gradient(circle at 50% 0%, rgba(58,63,71,0.55), rgba(19,21,25,0.8) 75%), url('../maps/Citynew.webp'); }
.battlefield.arena-quick { background-image: radial-gradient(circle at 50% 0%, rgba(74,58,29,0.55), rgba(28,20,9,0.8) 75%), url('../maps/QuickLevels.webp'); }
.battlefield.arena-doors { background-image: radial-gradient(circle at 50% 0%, rgba(36,26,46,0.6), rgba(12,8,16,0.85) 75%), url('../maps/Pre-final.webp'); }
.battlefield.arena-final { background-image: radial-gradient(circle at 50% 0%, rgba(92,20,20,0.55), rgba(26,5,5,0.8) 75%), url('../maps/finalShowdown.webp'); }

.ground-line {
    height: 3px;
    margin: 8px auto;
    max-width: 90%;
    background: repeating-linear-gradient(90deg, rgba(2, 255, 119, 0.5) 0 10px, transparent 10px 20px);
}

.rpg-side { min-width: 280px; }
.rpg-side h3 { color: var(--rpg-title); text-align: center; margin: 0 0 10px; }
.rpg-row { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }

.mode-select { display: flex; gap: 12px; justify-content: center; margin: 14px 0; flex-wrap: wrap; }
.mode-btn { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 10px 18px; cursor: pointer; opacity: 0.7; }
.mode-btn .mode-desc { font-size: 0.65rem; color: var(--rpg-text); opacity: 0.85; }
.mode-btn.active { opacity: 1; border-color: var(--rpg-accent); box-shadow: 0 0 0 3px rgba(212,0,177,0.6); transform: scale(1.04); }

.unit-card {
    width: 118px;
    background: linear-gradient(180deg, rgba(20, 60, 22, 0.65), var(--rpg-panel-2));
    border: 1px solid var(--rpg-border);
    padding: 8px;
    text-align: center;
    position: relative;
    transition: transform 120ms ease, box-shadow 120ms ease, opacity 120ms ease;
}
.unit-card.shielded::before {
    content: "";
    position: absolute;
    inset: -6px;
    border: 2px solid rgba(120, 210, 255, 0.95);
    box-shadow: 0 0 0 3px rgba(120, 210, 255, 0.25), 0 0 18px rgba(120, 210, 255, 0.7);
    border-radius: 18px;
    pointer-events: none;
}
.unit-card img { width: 64px; height: 64px; object-fit: contain; image-rendering: pixelated; }
.unit-card .u-name { font-size: 0.78rem; color: var(--rpg-title); margin-top: 4px; min-height: 1.4em; }
.unit-card .u-hpbar { height: 8px; background: rgba(0,0,0,0.4); margin-top: 5px; border: 1px solid rgba(2,255,119,0.3); }
.unit-card .u-hpfill { height: 100%; background: var(--rpg-hp); transition: width 200ms ease; }
.unit-card .u-hpfill.low { background: var(--rpg-hp-low); }
.unit-card .u-hptext { font-size: 0.68rem; color: var(--rpg-text); margin-top: 2px; }
.unit-card .u-shield { font-size: 0.65rem; color: #6ecbff; }
.unit-card .u-burn { font-size: 0.65rem; color: #ff8a4a; }
.unit-card .u-buff { font-size: 0.65rem; color: #6effa0; }
.unit-card .u-debuff { font-size: 0.65rem; color: #ff6e6e; }
.unit-card .u-tag { position: absolute; top: 2px; right: 2px; font-size: 0.6rem; background: var(--rpg-accent); color: #fff; padding: 1px 4px; }
.unit-card .u-role {
    display: inline-block;
    font-size: 0.55rem;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    border: 1px solid currentColor;
    border-radius: 2px;
    padding: 1px 4px;
    margin-top: 3px;
}
.reward-result .u-role { margin: 2px 0 6px; }

.unit-card.selectable { cursor: pointer; }
.unit-card.selectable:hover { transform: translate(-1px, -1px); box-shadow: 3px 3px 0 rgba(212,0,177,0.34); }
.unit-card.acted { opacity: 0.45; }
.unit-card.dead { opacity: 0.25; filter: grayscale(1); }
.unit-card.active-turn { border-color: var(--rpg-accent); box-shadow: 0 0 0 2px rgba(212,0,177,0.5); }
.unit-card.targetable { cursor: crosshair; border-color: #ffd166; }
.unit-card.targetable:hover { box-shadow: 3px 3px 0 rgba(255,209,102,0.5); }
.unit-card.empty-slot { opacity: 0.3; border-style: dashed; display: flex; align-items: center; justify-content: center; }
.unit-card.empty-slot.turret-slot { opacity: 0.45; border-color: #ffb347; color: #ffb347; font-size: 0.75rem; }
.unit-card.turret-unit { border-color: #ffb347; box-shadow: 0 0 0 1px rgba(255, 179, 71, 0.35); cursor: default; }
.unit-card.turret-unit .u-tag { background: #ffb347; color: #1a0f00; }

.unit-card.anim-attack { animation: anim-lunge 450ms ease; }
.unit-card.anim-hit { animation: anim-shake 450ms ease; }
.unit-card.anim-heal { animation: anim-glow 650ms ease; }
.unit-card.anim-shield { animation: anim-shield-ring 650ms ease; }
.unit-card.anim-crit { animation: anim-crit-flash 550ms ease; }
#enemy-row.anim-aoe-flash { animation: anim-aoe-bg 500ms ease; }
@keyframes anim-lunge {
    0% { transform: translateY(0); }
    35% { transform: translateY(-10px) scale(1.06); }
    100% { transform: translateY(0) scale(1); }
}
@keyframes anim-shake {
    0%, 100% { transform: translateX(0); filter: brightness(1); }
    20% { transform: translateX(-6px); filter: brightness(2) saturate(3) hue-rotate(-30deg); }
    40% { transform: translateX(6px); }
    60% { transform: translateX(-4px); }
    80% { transform: translateX(4px); }
}
@keyframes anim-glow {
    0%, 100% { box-shadow: none; }
    50% { box-shadow: 0 0 16px 4px rgba(110, 203, 255, 0.8); }
}
@keyframes anim-shield-ring {
    0% { box-shadow: 0 0 0 0 rgba(110, 203, 255, 0.9); }
    60% { box-shadow: 0 0 0 8px rgba(110, 203, 255, 0.15); }
    100% { box-shadow: 0 0 0 0 rgba(110, 203, 255, 0); }
}
@keyframes anim-crit-flash {
    0%, 100% { transform: scale(1); filter: brightness(1); }
    30% { transform: scale(1.14); filter: brightness(2.4) saturate(3); }
    55% { transform: scale(0.97); }
}
@keyframes anim-aoe-bg {
    0%, 100% { background-color: transparent; }
    40% { background-color: rgba(255, 209, 102, 0.18); }
}

/* ----- Floating combat numbers ----- */
.float-num {
    position: absolute;
    left: 50%;
    top: 14px;
    transform: translate(-50%, 0);
    font-size: 0.8rem;
    font-weight: 700;
    text-shadow: 1px 1px 0 #000;
    pointer-events: none;
    opacity: 0;
    animation: float-up 460ms ease-out forwards;
    animation-delay: calc(var(--fi, 0) * 90ms);
    z-index: 6;
}
@keyframes float-up {
    0% { opacity: 0; transform: translate(-50%, 0) scale(0.8); }
    20% { opacity: 1; transform: translate(-50%, -8px) scale(1.08); }
    100% { opacity: 0; transform: translate(-50%, -30px) scale(1); }
}
.float-num.float-dmg { color: #ff6e6e; }
.float-num.float-crit { color: #ffd166; font-size: 1rem; }
.float-num.float-heal { color: #6ecbff; }
.float-num.float-shield { color: #6effa0; }
.float-num.float-block { color: #9fd8ff; font-size: 0.68rem; }

/* ----- Next-to-act enemy indicator ----- */
.unit-card.next-turn { border-color: var(--rpg-gold); box-shadow: 0 0 0 2px rgba(255, 209, 102, 0.45); }
.unit-card .next-badge {
    position: absolute;
    bottom: 2px;
    left: 2px;
    font-size: 0.58rem;
    background: var(--rpg-gold);
    color: #000;
    padding: 1px 4px;
}

.rpg-log {
    height: 130px;
    overflow-y: auto;
    background: rgba(0,0,0,0.3);
    border: 1px solid var(--rpg-border);
    padding: 8px 10px;
    font-size: 0.82rem;
    color: var(--rpg-text);
    margin-bottom: 14px;
}
.rpg-log div { margin-bottom: 3px; }
.rpg-log .l-crit { color: #ffd166; }
.rpg-log .l-dmg { color: #ff8a8a; }
.rpg-log .l-heal { color: #6ecbff; }
.rpg-log .l-sys { color: var(--rpg-title); }

.action-bar { text-align: center; margin-bottom: 10px; color: var(--rpg-text); min-height: 1.4em; }
.ability-panel {
    text-align: center;
    margin-bottom: 14px;
    padding: 10px;
    border: 1px solid var(--rpg-border);
    background: rgba(0,0,0,0.2);
    display: none;
}
.ability-panel.show { display: block; }
.ability-panel .a-name { color: var(--rpg-title); font-weight: 700; }
.ability-panel .a-desc { color: var(--rpg-text); font-size: 0.85rem; margin: 4px 0 8px; }
.ability-panel .move-option {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    flex-wrap: wrap;
    margin: 6px 0;
}
.ability-panel .move-option .a-desc { margin: 0; text-align: left; flex: 1 1 220px; }
.move-tag {
    font-size: 0.62rem;
    font-weight: 700;
    padding: 2px 6px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    border: 1px solid currentColor;
}
.move-tag-single { color: #ff8a8a; }
.move-tag-aoe { color: #ffd166; }
.move-tag-support { color: #6ecbff; }
.a-name .move-tag { margin-left: 6px; vertical-align: middle; }

/* ----- How to Play modal ----- */
.help-modal-overlay {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.7);
    z-index: 50;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.help-modal-overlay.show { display: flex; }
.help-modal {
    max-width: 560px;
    max-height: 80vh;
    overflow-y: auto;
    background: var(--rpg-panel);
    border: 1px solid var(--rpg-border);
    box-shadow: 5px 5px 0 rgba(0,0,0,0.5);
    padding: 18px 20px;
}
.help-modal h3 { color: var(--rpg-title); margin: 14px 0 6px; }
.help-modal h3:first-child { margin-top: 0; }
.help-modal p, .help-modal li { color: var(--rpg-text); font-size: 0.85rem; line-height: 1.5; }
.help-modal ul { margin: 4px 0 0 18px; padding: 0; }
.help-btn { position: fixed; top: 10px; right: 10px; z-index: 40; }

/* ----- Squad build / start screen ----- */
.roster-grid, .squad-slots {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
    margin: 14px 0;
}

/* ----- Wheel ----- */
.wheel-wrap { display: flex; flex-direction: column; align-items: center; gap: 16px; margin: 20px 0; }
.wheel-outer { position: relative; width: 300px; height: 300px; }
.wheel-pointer {
    position: absolute; top: -14px; left: 50%; transform: translateX(-50%);
    width: 0; height: 0; border-left: 14px solid transparent; border-right: 14px solid transparent;
    border-top: 22px solid var(--rpg-accent); z-index: 5;
}
.wheel {
    width: 300px; height: 300px; border-radius: 50%;
    border: 4px solid var(--rpg-border);
    position: relative;
    transition: transform 4s cubic-bezier(0.15, 0.85, 0.25, 1);
    box-shadow: 0 0 24px rgba(2,255,119,0.15);
}
.wheel-seg-label {
    position: absolute; top: 50%; left: 50%;
    width: 0; height: 0;
    transform-origin: center center;
    pointer-events: none;
}
.wheel-seg-inner {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 66px; height: 66px;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    transform: translate(-50%, -50%);
}
.leaderboard-box {
    margin: 16px auto 10px;
    padding: 12px 16px;
    max-width: 320px;
    border: 1px solid var(--rpg-border);
    background: rgba(0,0,0,0.2);
}
.leaderboard-box h3 {
    margin: 0 0 8px;
    color: var(--rpg-title);
    text-align: center;
}
.leaderboard-box h3 + h3 { margin-top: 14px; }
#leaderboard-list-story, #leaderboard-list-infinite {
    margin: 0;
    padding-left: 18px;
    color: var(--rpg-text);
    font-size: 0.85rem;
}
#leaderboard-list-story li, #leaderboard-list-infinite li {
    margin: 4px 0;
}
#leaderboard-list-story li span, #leaderboard-list-infinite li span {
    color: var(--rpg-title);
    font-weight: 700;
}
.player-name-input {
    background: rgba(0,0,0,0.3);
    border: 1px solid var(--rpg-border);
    color: var(--rpg-text);
    font-family: inherit;
    padding: 7px 10px;
    max-width: 200px;
}
.wheel-seg-inner img { width: 32px; height: 32px; object-fit: contain; image-rendering: pixelated; }
.wheel-seg-inner span { font-size: 0.6rem; color: #fff; text-shadow: 1px 1px 0 #000; max-width: 62px; text-align: center; }
.wheel-center-dot {
    position: absolute; top: 50%; left: 50%; width: 18px; height: 18px; margin: -9px 0 0 -9px;
    background: var(--rpg-panel); border: 2px solid var(--rpg-accent); border-radius: 50%; z-index: 4;
}

.reward-result {
    text-align: center;
    padding: 14px;
    border: 1px solid var(--rpg-border);
    background: rgba(0,0,0,0.25);
    max-width: 360px;
    display: none;
}
.reward-result.show { display: block; }
.reward-result img { width: 72px; height: 72px; object-fit: contain; image-rendering: pixelated; }
.reward-result h3 { color: var(--rpg-title); margin: 8px 0 4px; }
.reward-result p { color: var(--rpg-text); font-size: 0.85rem; margin: 0 0 10px; }
.reward-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

.swap-picker { text-align: center; }
.swap-picker p { color: var(--rpg-text); }

/* ----- Doors (pre-final corridor) ----- */
.doors-wrap {
    display: flex;
    gap: 18px;
    justify-content: center;
    flex-wrap: wrap;
    margin: 20px 0;
}
.door {
    width: 110px;
    height: 160px;
    background: linear-gradient(180deg, #3a2415, #1a0f08);
    border: 3px solid #6b4a2a;
    border-radius: 6px 6px 0 0;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 120ms ease, box-shadow 120ms ease;
}
.door:hover { transform: translate(-1px, -1px); box-shadow: 4px 4px 0 rgba(212, 0, 177, 0.34); }
.door.acted { pointer-events: none; opacity: 0.55; }
.door.active-turn { border-color: var(--rpg-accent); box-shadow: 0 0 0 2px rgba(212, 0, 177, 0.5); }
.door-face { color: #d9b98a; font-size: 0.85rem; text-shadow: 1px 1px 0 #000; }

#screen-doors.active {
    background-image: radial-gradient(circle at 50% 0%, rgba(36,26,46,0.6), rgba(12,8,16,0.85) 75%), url('../maps/Pre-final.webp');
    background-size: cover;
    background-position: center;
    padding: 10px;
    border: 1px solid var(--rpg-border);
}

/* ----- Overlays ----- */
.overlay {
    position: fixed; inset: 0; background: rgba(2, 8, 3, 0.85);
    display: none; align-items: center; justify-content: center; z-index: 50; padding: 16px;
}
.overlay.show { display: flex; }
.overlay-box {
    max-width: 480px; width: 100%;
    background: var(--rpg-panel);
    border: 1px solid var(--rpg-border);
    box-shadow: 5px 5px 0 rgba(0,0,0,0.5);
    padding: 20px; text-align: center;
}
.overlay-box h2 { color: var(--rpg-title); margin-top: 0; }
.overlay-box p { color: var(--rpg-text); }

html, body { overflow-x: hidden; }

@media (max-width: 800px) {
    .center { padding: 14px; margin: 12px auto 18px; }
    .battlefield { gap: 12px; }
    .wheel, .wheel-outer { width: 240px; height: 240px; }
}

/* ----- Phones ----- */
@media (max-width: 480px) {
    .center { padding: 10px; margin: 8px auto 14px; }
    .rpg-head h1 { font-size: 1.3rem; }
    .help-btn { top: 6px; right: 6px; padding: 8px 10px; font-size: 0.8rem; }

    /* Bigger, easier-to-tap buttons everywhere. */
    .inner_column .button { padding: 12px 14px; font-size: 0.9rem; min-height: 44px; }

    /* Smaller unit cards so squad + enemy rows fit more per line without
       forcing lots of vertical scrolling on a narrow screen. */
    .unit-card { width: 88px; padding: 6px; }
    .unit-card img { width: 46px; height: 46px; }
    .unit-card .u-name { font-size: 0.68rem; min-height: 1.2em; }
    .unit-card .u-hptext { font-size: 0.6rem; }
    .unit-card .u-shield, .unit-card .u-burn, .unit-card .u-buff, .unit-card .u-debuff { font-size: 0.58rem; }
    .rpg-row { gap: 6px; }

    /* Ability panel: stack move choices instead of squeezing them sideways. */
    .ability-panel .move-option { flex-direction: column; align-items: stretch; gap: 4px; }
    .ability-panel .move-option .button { width: 100%; }
    .ability-panel .move-option .a-desc { flex: 1 1 auto; text-align: center; }

    .wheel, .wheel-outer { width: 210px; height: 210px; }
    .wheel-seg-inner { width: 52px; height: 52px; }
    .wheel-seg-inner img { width: 24px; height: 24px; }
    .wheel-seg-inner span { font-size: 0.52rem; max-width: 50px; }

    .door { width: 88px; height: 130px; }
    .doors-wrap { gap: 10px; }

    .reward-result, .overlay-box { padding: 14px; }
    .reward-actions .button, .page-actions .button { flex: 1 1 auto; }
}
