/* style.css */
:root {
    --color-bg-overlay: rgba(255, 255, 255, 0.4);
    --color-text-main: #4a3b32;
    --color-text-dim: #7a6b5c;
    --color-primary: #ffb703;
    --color-secondary: #8ecae6;
    --color-accent: #ff8fab;
    --color-mana: #06d6a0;
    --color-error: #ef476f;
    
    --font-main: 'Nunito', 'Noto Sans TC', sans-serif;
    
    --shadow-soft: 0 8px 25px rgba(100, 70, 40, 0.15);
    --glass-border: 2px solid rgba(255, 255, 255, 0.8);
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
    --runtime-safe-bottom: 0px;
    --app-visible-height: 100dvh;
    --input-console-height: 0px;
    --content-side-padding: clamp(16px, 4vw, 22px);
    --global-header-height: 112px;
    --game-header-height: 152px;
}

* { box-sizing: border-box; user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent; }
html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    min-height: 100%;
    font-family: var(--font-main);
    color: var(--color-text-main);
    overflow: hidden;
    overscroll-behavior: none;
    touch-action: none; /* Prevent browser gestures */
    background:
        radial-gradient(circle at top, rgba(255, 226, 202, 0.92), rgba(252, 232, 219, 0) 46%),
        linear-gradient(180deg, #f6dfcf 0%, #fce8db 55%, #f4d9c8 100%);
}

body {
    min-height: 100vh;
    min-height: 100svh;
    min-height: 100dvh;
    display: flex;
    justify-content: center;
    align-items: stretch;
    overscroll-behavior: none;
    overscroll-behavior-y: none;
    -webkit-overflow-scrolling: touch;
}

#app-container {
    position: relative;
    width: 100%;
    max-width: 500px;
    min-height: var(--app-visible-height);
    height: var(--app-visible-height);
    margin: 0 auto;
    padding-left: var(--safe-left);
    padding-right: var(--safe-right);
    display: flex;
    background-color: #fce8db; /* Solid fallback for PWA */
    background-image: url('../assets/bg_magic_lab.png');
    background-size: cover;
    background-position: center;
    overflow: hidden;
    overscroll-behavior: none;
    touch-action: pan-x pan-y; /* Allow internal scrolling but not body rubber-band */
    isolation: isolate;
    z-index: 2;
    box-shadow: 0 28px 90px rgba(105, 74, 48, 0.18);
}

#app-container::before,
#app-container::after {
    content: '';
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 0;
}

#app-container::before {
    inset: -20% -15%;
    background:
        radial-gradient(circle at 18% 24%, rgba(255, 238, 163, 0.36), transparent 26%),
        radial-gradient(circle at 76% 18%, rgba(190, 150, 255, 0.24), transparent 22%),
        radial-gradient(circle at 52% 82%, rgba(143, 241, 226, 0.25), transparent 28%);
    mix-blend-mode: screen;
    animation: auroraFloat 18s ease-in-out infinite alternate;
}

#app-container::after {
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.3) 0%, rgba(255, 255, 255, 0.08) 32%, rgba(74, 59, 50, 0.06) 100%),
        radial-gradient(circle at center, rgba(255, 255, 255, 0.08), transparent 68%);
}

#app-container[data-view="hub"]::before {
    background:
        radial-gradient(circle at 18% 22%, rgba(255, 238, 163, 0.4), transparent 26%),
        radial-gradient(circle at 80% 14%, rgba(255, 143, 171, 0.2), transparent 20%),
        radial-gradient(circle at 50% 84%, rgba(142, 202, 230, 0.22), transparent 30%);
}

#app-container[data-view="map"]::before {
    background:
        radial-gradient(circle at 14% 18%, rgba(255, 215, 130, 0.34), transparent 24%),
        radial-gradient(circle at 82% 24%, rgba(180, 166, 255, 0.22), transparent 20%),
        radial-gradient(circle at 46% 88%, rgba(168, 240, 226, 0.18), transparent 32%);
}

#app-container[data-view="shop"]::before {
    background:
        radial-gradient(circle at 24% 18%, rgba(255, 193, 127, 0.38), transparent 24%),
        radial-gradient(circle at 80% 26%, rgba(166, 213, 255, 0.26), transparent 22%),
        radial-gradient(circle at 50% 82%, rgba(255, 248, 190, 0.14), transparent 28%);
}

#app-container[data-view="game"]::before {
    background:
        radial-gradient(circle at 18% 18%, rgba(171, 230, 255, 0.26), transparent 24%),
        radial-gradient(circle at 82% 24%, rgba(202, 255, 191, 0.18), transparent 20%),
        radial-gradient(circle at 56% 84%, rgba(190, 151, 255, 0.28), transparent 30%);
}

#app-container > * {
    z-index: 1;
}

[hidden] {
    display: none !important;
}

/* ================= PARTICLES ================= */
#particles-container {
    position: fixed; top:0; left:0; width:100vw; height:100dvh; 
    pointer-events: none; z-index: 1000; overflow: hidden;
}
.particle {
    position: absolute; border-radius: 50%; opacity: 1;
    transform: translate(-50%, -50%);
    animation: var(--particle-animation, particleFade) var(--particle-duration, 1000ms) cubic-bezier(0.175, 0.885, 0.32, 1) forwards;
    box-shadow: 0 0 14px rgba(255, 255, 255, 0.3);
}
@keyframes particleFade {
    0% { transform: translate(-50%, -50%) scale(0.5); opacity: 1; }
    100% { transform: translate(var(--tx), var(--ty)) scale(var(--particle-scale, 1.5)) rotate(var(--rot)); opacity: 0; }
}

.particle-burst {
    border-radius: 999px;
}

.particle-spark {
    --particle-animation: sparkleFloat;
    clip-path: polygon(50% 0%, 63% 36%, 100% 50%, 63% 64%, 50% 100%, 37% 64%, 0% 50%, 37% 36%);
}

.particle-rune {
    --particle-animation: runeSpiral;
    border-radius: 10px;
}

.particle-ambient,
.particle-mist {
    --particle-animation: particleRise;
}

.particle-mist {
    filter: blur(1px);
}

@keyframes sparkleFloat {
    0% { transform: translate(-50%, -50%) scale(0.5) rotate(0deg); opacity: 0.9; }
    40% { opacity: 1; }
    100% { transform: translate(var(--tx), var(--ty)) scale(1.8) rotate(180deg); opacity: 0; }
}

@keyframes runeSpiral {
    0% { transform: translate(-50%, -50%) scale(0.35) rotate(0deg); opacity: 0.85; }
    100% { transform: translate(var(--tx), var(--ty)) scale(1.35) rotate(var(--rot)); opacity: 0; }
}

@keyframes particleRise {
    0% { transform: translate(-50%, -50%) scale(0.75); opacity: 0; }
    18% { opacity: 0.7; }
    100% { transform: translate(var(--tx), var(--ty)) scale(1.15); opacity: 0; }
}

/* ================= TOASTS & QUEST WIDGET ================= */
#save-toast {
    position: absolute; top: calc(var(--safe-top) + 18px); left: 50%; transform: translateX(-50%) translateY(-100px);
    background: rgba(255, 255, 255, 0.95); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
    color: #4db6ac; font-weight: 800; font-size: 14px; padding: 10px 20px; border-radius: 30px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1); z-index: 7000; transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    display: flex; align-items: center; gap: 8px; border: 1px solid #e0f2f1;
}
#save-toast.show { transform: translateX(-50%) translateY(0); }
.toast-icon { font-size: 18px; }

#quest-widget {
    position: absolute; top: calc(var(--safe-top) + 88px); right: calc(-1 * min(82vw, 300px)); width: min(300px, 82vw);
    background: rgba(255, 255, 255, 0.95); border: var(--glass-border); border-radius: 20px 0 0 20px;
    padding: 10px 15px; display: flex; align-items: center; gap: 10px; box-shadow: -4px 4px 15px rgba(0,0,0,0.1);
    z-index: 800; transition: right 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
#quest-widget.show { right: 0; }
.quest-icon { font-size: 24px; }
.quest-info { display: flex; flex-direction: column; }
.quest-title { font-size: 12px; font-weight: 900; color: var(--color-accent); margin-bottom: 2px; }
.quest-desc { font-size: 11px; font-weight: 800; color: var(--color-text-main); }
.quest-claim {
    background: var(--color-primary); color: white; font-weight: 900; font-size: 12px;
    padding: 6px 12px; border-radius: 12px; cursor: pointer; animation: pulseReward 1.5s infinite;
}
.quest-claim.disabled { background: #ccc; animation: none; cursor: not-allowed; pointer-events: none;}
@keyframes pulseReward { 0%, 100% {transform: scale(1); box-shadow: 0 0 0 0 rgba(255, 183, 3, 0.7);} 50% {transform: scale(1.05); box-shadow: 0 0 0 8px rgba(255, 183, 3, 0);} }


/* ================= DIALOGUE OVERLAY ================= */
#dialogue-overlay { position: absolute; top:0; left:0; right:0; bottom:0; background:rgba(0,0,0,0.4); z-index:500; display:flex; flex-direction:column; justify-content:flex-end; opacity:0; pointer-events:none; transition:opacity 0.3s; }
#dialogue-overlay.show { opacity:1; pointer-events:all; }
.dialogue-character { position:absolute; bottom:0; left:0; width:100%; height:60%; display:flex; justify-content:center; align-items:flex-end; z-index:501; pointer-events:none; }
.dialogue-character img { height:100%; object-fit:contain; transform:translateY(40px) scale(0.9); transition:transform 0.6s cubic-bezier(0.34, 1.56, 0.64, 1); opacity:0; mix-blend-mode:normal; }
#dialogue-overlay.show .dialogue-character img { transform:translateY(0) scale(1.0); opacity:1; }
.dialogue-box { background:rgba(255,255,255,0.95); backdrop-filter:blur(15px); -webkit-backdrop-filter:blur(15px); padding:20px 25px; padding-bottom:calc(var(--safe-bottom) + 20px); border-top-left-radius:30px; border-top-right-radius:30px; box-shadow:0 -10px 40px rgba(0,0,0,0.15); z-index:502; cursor:pointer; position:relative; border-top:var(--glass-border); transform:translateY(100%); transition:transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1); }
#dialogue-overlay.show .dialogue-box { transform:translateY(0); }
.dialogue-name { margin:0 0 10px 0; color:var(--color-secondary); font-size:18px; font-weight:900; text-shadow:0 1px 2px rgba(0,0,0,0.05); }
.dialogue-text { margin:0; font-size:16px; line-height:1.6; color:var(--color-text-main); font-weight:700; min-height:50px; }
.dialogue-continue { position:absolute; bottom:calc(var(--safe-bottom) + 15px); right:25px; font-size:12px; color:var(--color-text-dim); font-weight:800; animation:bounce 1.5s infinite; }

/* ================= VIEWS ================= */
.view-section {
    position:relative;
    width:100%;
    display:none;
    flex-direction:column;
    flex:1 1 auto;
    height:100%;
    max-height:100%;
    min-height:0;
    pointer-events:none;
    z-index:1;
    overflow:hidden;
}
.view-section.active-view {
    display:flex;
    pointer-events:all;
    z-index:10;
}

/* === Professional View Transition Animations === */
.view-section.view-exit {
    display: flex;
    animation: viewFadeOut 0.35s ease-in forwards;
    pointer-events: none;
    z-index: 5;
}
.view-section.view-enter {
    animation: viewFadeIn 0.35s ease-out forwards;
}
@keyframes viewFadeOut {
    0% { opacity: 1; transform: scale(1); }
    100% { opacity: 0; transform: scale(0.96); }
}
@keyframes viewFadeIn {
    0% { opacity: 0; transform: translateY(18px); }
    100% { opacity: 1; transform: translateY(0); }
}

/* ===== Transition Overlay (cinematic wipe) ===== */
#transition-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    pointer-events: none;
    background: radial-gradient(ellipse at center, rgba(255,248,240,0.98), rgba(240,228,210,0.96));
    opacity: 0;
}
#transition-overlay.transition-in {
    animation: transitionFadeIn 0.3s ease-out forwards;
    pointer-events: all;
}
#transition-overlay.transition-out {
    animation: transitionFadeOut 0.5s ease-in forwards;
}
@keyframes transitionFadeIn {
    0% { opacity: 0; }
    100% { opacity: 1; }
}
@keyframes transitionFadeOut {
    0% { opacity: 1; }
    100% { opacity: 0; }
}

/* ===== Hub Panel Slide Transitions ===== */
.hub-panel.panel-exit {
    animation: panelSlideOut 0.3s ease-in forwards;
    pointer-events: none;
}
.hub-panel.panel-enter {
    animation: panelSlideIn 0.3s ease-out forwards;
}
@keyframes panelSlideOut {
    0% { opacity: 1; transform: translateX(0); }
    100% { opacity: 0; transform: translateX(-24px); }
}
@keyframes panelSlideIn {
    0% { opacity: 0; transform: translateX(24px); }
    100% { opacity: 1; transform: translateX(0); }
}

/* ===== Title Card Disabled State ===== */
.title-card button:disabled {
    opacity: 0.5;
    filter: grayscale(0.6);
    cursor: not-allowed;
}

/* Start screen exit animation */
.hub-content.home-screen-exit {
    animation: startScreenExit 0.4s ease-in forwards;
}
@keyframes startScreenExit {
    0% { opacity: 1; transform: scale(1); }
    100% { opacity: 0; transform: scale(1.06); filter: blur(6px); }
}

/* Hub enter animation */
.hub-content.hub-enter .hub-hero-container,
.hub-content.hub-enter .hub-panel-stack,
.hub-content.hub-enter .hub-bottom-nav {
    animation: hubSlideIn 0.5s ease-out backwards;
}
.hub-content.hub-enter .hub-hero-container { animation-delay: 0.05s; }
.hub-content.hub-enter .hub-panel-stack { animation-delay: 0.15s; }
.hub-content.hub-enter .hub-bottom-nav { animation-delay: 0.25s; }
@keyframes hubSlideIn {
    0% { opacity: 0; transform: translateY(24px); }
    100% { opacity: 1; transform: translateY(0); }
}

/* Start screen fade-in on load */
.hub-content.home-screen .home-shell {
    animation: startScreenIn 0.6s ease-out backwards;
    animation-delay: 0.1s;
}
@keyframes startScreenIn {
    0% { opacity: 0; transform: translateY(20px) scale(0.95); }
    100% { opacity: 1; transform: translateY(0) scale(1); }
}

.hidden { display: none !important; }
.real-hidden { display: none !important; }

/* Global Header */
#global-header {
    position:absolute;
    top:0;
    left:0;
    right:0;
    display:grid;
    grid-template-columns:auto minmax(0, 1fr) auto;
    grid-template-areas:"back title stats";
    align-items:center;
    gap:12px;
    padding:calc(var(--safe-top) + 14px) var(--content-side-padding) 14px;
    background:#fff;
    background:rgba(255,255,255,1.0); /* Fully opaque for Safari stability */
    backdrop-filter:blur(20px);
    -webkit-backdrop-filter:blur(20px);
    border-bottom:var(--glass-border);
    z-index:3000;
    box-shadow:0 8px 25px rgba(0,0,0,0.1);
    transform: translateZ(0); /* Force GPU layer */
    -webkit-transform: translateZ(0);
}
.header-title {
    grid-area:title;
    min-width:0;
    padding:0 6px;
    font-size:clamp(18px, 4.8vw, 26px);
    font-weight:900;
    color:var(--color-text-main);
    text-align:center;
    line-height:1.12;
    text-wrap:balance;
    text-shadow:0 2px 12px rgba(255,255,255,0.4);
}
#btn-global-back {
    grid-area:back;
    background:white;
    border:none;
    min-height:46px;
    padding: 10px 16px;
    border-radius:18px;
    box-shadow:var(--shadow-soft);
    font-size:14px;
    font-weight:900;
    cursor:pointer;
    color: var(--color-accent);
    display:inline-flex;
    align-items:center;
    z-index: 1000;
    justify-content:center;
    gap:6px;
    white-space:nowrap;
}
.stats-combo {
    grid-area:stats;
    position:static;
    display:flex;
    justify-self:end;
    gap:10px;
    z-index:900;
}
.coin-display, .stamina-display {
    display:flex;
    align-items:center;
    min-height:46px;
    background:rgba(255,255,255,0.9);
    padding:8px 12px;
    border-radius:22px;
    box-shadow:inset 0 2px 4px rgba(0,0,0,0.05), var(--shadow-soft);
    font-weight:800;
    font-size:13px;
    border:1px solid rgba(255,255,255,0.85);
}
.coin-display { color:#e09f00; }
.stamina-display { color:#ef476f; }
.coin-display img, .stamina-display img { width:18px; height:18px; margin-right:4px; }

/* Hub */
#view-hub .hub-content {
    flex:1;
    width:100%;
    height:100%;
    max-height:100%;
    min-height:0;
    display:flex;
    flex-direction:column;
    justify-content:flex-start;
    align-items:center;
    overflow-y:auto;
    overflow-x:hidden;
    padding:calc(var(--safe-top) + 24px) 20px calc(var(--safe-bottom) + 20px);
    scroll-padding-bottom:calc(var(--safe-bottom) + 32px);
    background: #fdf6f0; /* Solid base to prevent bleed */
    background:rgba(255,255,255,0.15);
    gap:16px;
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
}
#view-hub .hub-content:not([data-active-panel="home"]):not(.home-screen) {
    padding-top: calc(var(--safe-top) + var(--global-header-height, 100px) + 8px) !important;
}
.logo-box {
    position:relative;
    width:min(100%, 340px);
    text-align:center;
    background:rgba(255,255,255,0.92);
    padding:24px 22px;
    border-radius:28px;
    border:var(--glass-border);
    box-shadow:var(--shadow-soft);
    backdrop-filter:blur(12px);
    -webkit-backdrop-filter:blur(12px);
}
.logo-box h1 { margin:0 0 10px; font-size:26px; color:var(--color-secondary); line-height:1.3; }
.logo-box h1 .sub-title { font-size:32px; color:var(--color-accent); text-shadow:0 2px 0px white, 0 4px 6px rgba(255, 143, 171, 0.3); }
.logo-box p { font-size:14px; color:var(--color-text-dim); margin-top:10px; font-weight:700;}
.menu-buttons { display:flex; flex-direction:column; gap:15px; width:min(320px, 100%); transition: opacity 0.3s; margin:0 auto; }
.menu-btn { position:relative; overflow:hidden; width:100%; padding:18px 22px; border-radius:20px; font-size:16px; font-weight:800; border:var(--glass-border); color:var(--color-text-main); display:flex; align-items:center; justify-content:center; box-shadow:var(--shadow-soft); transition:transform 0.18s ease, box-shadow 0.22s ease; background:rgba(255,255,255,0.92); text-align:center; appearance:none; -webkit-appearance:none; }
.logo-box > *,
.menu-btn > *,
.level-card > *,
.shop-item > *,
.history-row > *,
.modal-panel > * {
    position:relative;
    z-index:1;
}
.menu-btn::after, .level-card::after, .shop-item::after, .history-row::after {
    content:'';
    position:absolute;
    inset:-55% auto auto 48%;
    width:55%;
    height:180%;
    background:linear-gradient(180deg, rgba(255,255,255,0.42), rgba(255,255,255,0));
    transform:rotate(22deg);
    pointer-events:none;
    z-index:0;
}
.menu-btn:active { transform:translateY(1px) scale(0.97); }
.menu-btn.primary-btn { background:linear-gradient(135deg, #ffd6a5, #fdffb6); }
.menu-btn.endless-btn { background:linear-gradient(135deg, #caffbf, #9bf6ff); }
.menu-btn.shop-btn { background:linear-gradient(135deg, #a0c4ff, #bdb2ff); }
.btn-icon { font-size:24px; margin-right:15px; }
.hub-tip {
    width:min(320px, 100%);
    display:flex;
    flex-direction:column;
    gap:10px;
    padding:14px 16px;
    background:rgba(255, 255, 255, 0.9);
    border:var(--glass-border);
    border-radius:20px;
    box-shadow:var(--shadow-soft);
    backdrop-filter:blur(14px);
    -webkit-backdrop-filter:blur(14px);
    text-align:center;
    font-size:13px;
    line-height:1.6;
    font-weight:800;
    color:var(--color-text-main);
}
.hub-tip-btn {
    align-self:center;
    min-height:42px;
    padding:10px 16px;
    border:none;
    border-radius:999px;
    background:linear-gradient(135deg, #ffd166, #ffb703);
    color:white;
    font-family:var(--font-main);
    font-size:13px;
    font-weight:900;
    box-shadow:0 8px 18px rgba(255, 183, 3, 0.28);
    cursor:pointer;
}
.auth-user-row {
    display:flex;
    align-items:center;
    gap:12px;
    margin-bottom:12px;
}
.auth-avatar {
    width:44px;
    height:44px;
    border-radius:50%;
    object-fit:cover;
    border:2px solid rgba(255,255,255,0.8);
    box-shadow:0 6px 16px rgba(0,0,0,0.12);
    flex-shrink:0;
}
.auth-user-meta {
    display:flex;
    flex-direction:column;
    gap:4px;
    text-align:left;
    min-width:0;
}
.auth-user-meta strong {
    font-size:14px;
    color:var(--color-text-main);
}
.auth-user-meta span {
    font-size:12px;
    color:var(--color-text-dim);
    word-break:break-word;
}
.cloud-save-status {
    font-size:12px;
    line-height:1.5;
    color:var(--color-text-dim);
}
.cloud-save-status.is-busy {
    color:#8a5a00;
}
.cloud-save-status.is-success {
    color:#2f8f77;
}
.cloud-save-status.is-error {
    color:var(--color-error);
}
.map-cloud-status {
    display:block;
    margin:0 auto 18px;
    text-align:center;
}
.install-note {
    font-size:12px;
    line-height:1.5;
    color:var(--color-text-dim);
}
#auth-guest,
#auth-user,
#install-card {
    display:flex;
    flex-direction:column;
    gap:12px;
}

/* Boot */
.boot-overlay {
    position: fixed;
    inset: 0;
    z-index: 1500;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: calc(var(--safe-top) + 24px) 22px calc(var(--safe-bottom) + 24px);
    background:
        radial-gradient(circle at 20% 18%, rgba(255, 236, 167, 0.3), transparent 28%),
        radial-gradient(circle at 82% 12%, rgba(211, 173, 255, 0.24), transparent 22%),
        linear-gradient(180deg, rgba(61, 40, 32, 0.18), rgba(252, 232, 219, 0.88));
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    opacity: 1;
    pointer-events: all;
    transition: opacity 0.4s ease;
}
.boot-overlay:not(.active) {
    opacity: 0;
    pointer-events: none;
}
.boot-layer {
    width: min(100%, 420px);
    border-radius: 34px;
    border: var(--glass-border);
    background: rgba(255, 251, 247, 0.92);
    box-shadow: 0 24px 80px rgba(81, 57, 38, 0.22);
}
.boot-loader,
.boot-cinematic {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 18px;
    padding: 30px 24px;
    text-align: center;
}
.boot-rune {
    width: 88px;
    height: 88px;
    border-radius: 28px;
    background:
        radial-gradient(circle at center, rgba(255, 243, 188, 0.95), rgba(255, 183, 3, 0.18) 58%, transparent 72%),
        linear-gradient(135deg, rgba(255, 183, 3, 0.4), rgba(142, 202, 230, 0.45));
    box-shadow:
        0 0 0 10px rgba(255, 255, 255, 0.55),
        0 18px 36px rgba(255, 183, 3, 0.2);
    position: relative;
    animation: bootRuneSpin 3.8s linear infinite;
}
.boot-rune::before,
.boot-rune::after {
    content: '';
    position: absolute;
    inset: 18px;
    border-radius: 18px;
    border: 2px solid rgba(97, 72, 57, 0.28);
}
.boot-rune::after {
    inset: 28px;
    border-radius: 14px;
    transform: rotate(45deg);
}
.boot-title-mini {
    font-size: 14px;
    font-weight: 900;
    color: #ae7a00;
    letter-spacing: 0.18em;
}
.boot-status {
    font-size: 15px;
    line-height: 1.8;
    font-weight: 800;
    color: var(--color-text-main);
}
.boot-cast {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
}
.boot-portrait {
    min-height: 148px;
    border-radius: 24px;
    overflow: hidden;
    background:
        radial-gradient(circle at top, rgba(255, 245, 209, 0.88), rgba(255, 228, 220, 0.92)),
        rgba(255, 255, 255, 0.82);
    border: 1px solid rgba(255,255,255,0.9);
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.85), 0 12px 24px rgba(92, 65, 41, 0.12);
}
.boot-portrait img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    object-position: center bottom;
    mix-blend-mode: normal;
}
.boot-game-title {
    margin: 0 0 40px;
    font-size: clamp(48px, 12vw, 64px);
    color: var(--color-text-main);
    letter-spacing: 0.1em;
    text-shadow: 0 10px 20px rgba(0,0,0,0.1);
}
.btn-main-game {
    font-family: inherit;
    font-weight: 900;
    font-size: 22px;
    padding: 18px 48px;
    border-radius: 999px;
    border: none;
    background: linear-gradient(135deg, var(--color-primary), #ffb703);
    color: white;
    box-shadow: 0 15px 30px rgba(255, 183, 3, 0.3);
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}
.btn-main-game:active {
    transform: scale(0.96);
}
.boot-auth-card {
    margin-top: 60px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    width: min(100%, 320px);
}
.btn-google-small {
    background: white;
    border: 1px solid #ddd;
    border-radius: 12px;
    padding: 8px 16px;
    font-size: 14px;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    box-shadow: 0 4px 10px rgba(0,0,0,0.05);
}
.btn-google-small img {
    width: 16px;
    height: 16px;
}
.btn-text-only {
    background: none;
    border: none;
    color: var(--color-text-dim);
    font-size: 13px;
    text-decoration: underline;
    cursor: pointer;
}
.auth-small-row {
    font-size: 13px;
    color: var(--color-text-dim);
    display: flex;
    align-items: center;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
}
.boot-user-row {
    justify-content: center;
    width: 100%;
}
.home-screen {
    justify-content:center;
    padding:calc(var(--safe-top) + 24px) 20px calc(var(--safe-bottom) + 28px);
}
#view-hub .hub-content.home-screen {
    justify-content:center;
    padding:calc(var(--safe-top) + 24px) 20px calc(var(--safe-bottom) + 28px);
}
/* Start screen mode: hide all game hub elements */
.hub-content.home-screen .hub-hero-container,
.hub-content.home-screen .hub-panel-stack,
.hub-content.home-screen .hub-utility-row,
.hub-content.home-screen .hub-bottom-nav {
    display: none !important;
}
.hub-content.home-screen .home-shell {
    padding: 32px 24px;
    gap: 18px;
}
.hub-content.home-screen .home-brand h1 {
    font-size: clamp(38px, 12vw, 54px);
}
.hub-content.home-screen .home-kicker {
    margin-bottom: 8px;
    font-size: 12px;
}
/* Hub mode: hide the start screen card */
.hub-content.hub-hero-layout > .hub-top-card {
    display: none;
}
/* Hide NPC bubble when active panel is not home */
#view-hub .hub-content:not([data-active-panel="home"]) .hub-hero-container {
    display: none;
}
.home-shell {
    width:min(100%, 360px);
    display:flex;
    flex-direction:column;
    align-items:center;
    gap:12px;
    padding:18px 18px;
    border-radius:32px;
    background:rgba(255, 251, 247, 0.86);
    border:var(--glass-border);
    box-shadow:0 24px 60px rgba(81, 57, 38, 0.18);
    backdrop-filter:blur(14px);
    -webkit-backdrop-filter:blur(14px);
}
.home-brand {
    text-align:center;
}
.home-kicker {
    display:block;
    margin-bottom:4px;
    font-size:11px;
    font-weight:900;
    letter-spacing:0.32em;
    color:#ae7a00;
}
.home-brand h1 {
    margin:0;
    font-size:clamp(28px, 8vw, 38px);
    line-height:1;
    letter-spacing:0.12em;
    color:var(--color-text-main);
}
.home-start-btn {
    width:100%;
    min-height:64px;
    font-size:20px;
}
.home-auth-card {
    width:100%;
    display:flex;
    flex-direction:column;
    align-items:center;
    gap:14px;
}
.home-save-note {
    margin: -2px 0 4px;
    font-size: 12px;
    line-height: 1.65;
    text-align: center;
    color: var(--color-text-dim);
    font-weight: 800;
}
.home-auth-card #auth-guest,
.home-auth-card #auth-user {
    width:100%;
    display: flex;
    flex-direction: column;
    align-items:center;
    gap: 10px;
}
.home-auth-card #auth-email {
    display:none;
}
.btn-google-small {
    background: rgba(255,255,255,0.7);
    border: 1px solid rgba(200,180,160,0.3);
    border-radius: 999px;
    padding: 8px 18px;
    font-size: 13px;
    font-weight: 700;
    color: var(--color-text-dim);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s;
    opacity: 0.75;
}
.btn-google-small:hover,
.btn-google-small:active {
    opacity: 1;
    background: rgba(255,255,255,0.9);
    transform: scale(1.02);
}
.auth-user-chip {
    width:100%;
    justify-content:center;
    padding:10px 12px;
    margin:0;
    border-radius:999px;
    background:rgba(255,255,255,0.82);
    border:1px solid rgba(255,255,255,0.9);
}
.google-mark {
    width:18px;
    height:18px;
    display:inline-flex;
    align-items:center;
    justify-content:center;
    border-radius:50%;
    background:linear-gradient(135deg, #4285f4, #34a853);
    color:white;
    font-size:11px;
    font-weight:900;
}

/* Hub Hero Layout */
.hub-content.hub-hero-layout {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    min-height: 100%;
    padding: calc(var(--safe-top) + 12px) 16px calc(var(--safe-bottom) + 20px);
    scroll-padding-bottom: calc(var(--safe-bottom) + 32px);
    gap: 14px;
    position: relative;
}
.hub-home-return {
    position: absolute;
    top: calc(var(--safe-top) + 8px);
    right: 16px;
    z-index: 20;
    min-height: 38px;
    padding: 8px 14px;
    border: 1px solid rgba(255,255,255,0.9);
    border-radius: 999px;
    background: rgba(255,255,255,0.92);
    color: var(--color-accent);
    font-family: var(--font-main);
    font-size: 12px;
    font-weight: 900;
    box-shadow: var(--shadow-soft);
    cursor: pointer;
}
.hub-mode-orbit {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}
.mode-orb {
    border: none;
    border-radius: 24px;
    padding: 16px;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
    text-align: left;
    box-shadow: var(--shadow-soft);
    background: rgba(255,255,255,0.9);
    cursor: pointer;
    transition: transform 0.18s ease, box-shadow 0.18s ease;
}
.mode-orb span {
    font-size: 18px;
    font-weight: 900;
    color: var(--color-text-main);
}
.mode-orb small {
    font-size: 12px;
    line-height: 1.55;
    color: var(--color-text-dim);
    font-weight: 800;
}
.mode-story {
    background: linear-gradient(135deg, rgba(255, 242, 201, 0.96), rgba(255, 232, 215, 0.92));
}
.mode-daily {
    background: linear-gradient(135deg, rgba(233, 248, 255, 0.98), rgba(236, 255, 244, 0.92));
}
.mode-orb.active {
    transform: translateY(-2px);
    box-shadow: 0 18px 30px rgba(88, 62, 40, 0.16);
}
.hub-hero-container {
    width: 100%;
    min-height: 248px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(132px, 42%);
    align-items: end;
    gap: 12px;
    position: relative;
    padding: 18px 18px 0;
    border-radius: 30px;
    background:
        linear-gradient(135deg, rgba(255, 249, 237, 0.94), rgba(255, 239, 226, 0.9)),
        rgba(255,255,255,0.84);
    border: 1px solid rgba(255,255,255,0.88);
    box-shadow: var(--shadow-soft);
    overflow: hidden;
}
.hero-portrait-wrap {
    width: 100%;
    max-width: 240px;
    height: min(62vw, 290px);
    min-height: 212px;
    position: relative;
    cursor: pointer;
    justify-self: end;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.hero-portrait-wrap:active {
    transform: scale(0.92);
}
.hero-img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    object-position: center bottom;
    filter: drop-shadow(0 18px 32px rgba(91, 58, 37, 0.22));
    transform: scale(1.5);
    transform-origin: center bottom;
}
.hero-bubble {
    position: relative;
    align-self: start;
    background: rgba(255,255,255,0.92);
    padding: 14px 16px;
    border-radius: 22px;
    box-shadow: 0 10px 24px rgba(0,0,0,0.08);
    width: 100%;
    z-index: 5;
    animation: bubbleFloat 3s ease-in-out infinite;
    text-align: left;
}
.hero-bubble::after {
    content: '';
    position: absolute;
    bottom: 18px;
    right: -10px;
    transform: none;
    border-left: 10px solid transparent;
    border-right: 10px solid transparent;
    border-top: 10px solid rgba(255,255,255,0.92);
    rotate: -90deg;
}
.bubble-kicker {
    font-size: 11px;
    font-weight: 900;
    color: var(--color-primary);
    text-transform: uppercase;
    display: block;
    margin-bottom: 4px;
}
.hero-bubble p {
    margin: 0;
    font-size: 14px;
    font-weight: 700;
    color: var(--color-text-main);
    line-height: 1.55;
}
.hero-guide-meta {
    display: block;
    margin-top: 10px;
    font-size: 11px;
    line-height: 1.6;
    color: var(--color-text-dim);
    font-weight: 800;
}
@keyframes bubbleFloat {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-5px); }
}

.hub-panel-stack {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 12px;
    flex: 1 0 auto;
}
.hub-panel {
    display: none;
    flex-direction: column;
    gap: 14px;
    width: 100%;
    padding: 18px;
    border-radius: 28px;
    background: rgba(255,255,255,0.88);
    border: var(--glass-border);
    box-shadow: var(--shadow-soft);
}
.hub-panel.active {
    display: flex;
}
.hub-home-panel {
    min-height: 184px;
    background:
        linear-gradient(135deg, rgba(255, 250, 239, 0.94), rgba(239, 250, 255, 0.88)),
        rgba(255,255,255,0.86);
}
.home-story-summary {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 16px;
    border-radius: 22px;
    background: rgba(255,255,255,0.72);
    border: 1px solid rgba(255,255,255,0.86);
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.84);
}
.home-story-summary h3 {
    margin: 0;
    font-size: 17px;
    line-height: 1.35;
    color: var(--color-text-main);
}
.home-story-summary p {
    margin: 0;
    font-size: 13px;
    line-height: 1.7;
    color: var(--color-text-dim);
    font-weight: 800;
}
.hub-panel-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 14px;
}
.hub-panel-head h2,
.hub-panel-head h3 {
    margin: 4px 0 8px;
    font-size: 22px;
    line-height: 1.2;
    color: var(--color-text-main);
}
.hub-panel-head p {
    margin: 0;
    font-size: 13px;
    line-height: 1.65;
    color: var(--color-text-dim);
    font-weight: 800;
}
.hub-panel-kicker {
    font-size: 11px;
    font-weight: 900;
    color: #b87900;
    letter-spacing: 0.12em;
}
.hub-panel-badge {
    padding: 8px 12px;
    border-radius: 999px;
    background: rgba(255, 183, 3, 0.14);
    color: #b87900;
    font-size: 11px;
    font-weight: 900;
    white-space: nowrap;
}
.hub-large-action {
    width: 100%;
    background: white;
    border: none;
    border-radius: 22px;
    padding: 16px 22px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: var(--shadow-soft);
    cursor: pointer;
    transition: transform 0.2s, background 0.2s;
}
.hub-large-action:active {
    transform: scale(0.98);
}
.action-info {
    text-align: left;
}
.action-info span {
    display: block;
    font-size: 18px;
    font-weight: 900;
    color: var(--color-text-main);
}
.action-info small {
    display: block;
    font-size: 12px;
    color: var(--color-text-dim);
    margin-top: 2px;
}
.hub-large-action img {
    width: 42px;
    height: 42px;
    opacity: 0.9;
}
.daily-action {
    background: linear-gradient(135deg, rgba(233, 248, 255, 0.98), rgba(236, 255, 244, 0.92));
}
.endless-action {
    background: linear-gradient(135deg, rgba(227, 245, 255, 0.96), rgba(241, 245, 255, 0.92));
}
.hub-interaction-hint {
    font-size: 12px;
    color: var(--color-text-dim);
    font-weight: 700;
    opacity: 0.6;
}
.daily-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}
.daily-meta span,
.daily-meta strong {
    padding: 7px 10px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.64);
    font-size: 11px;
    font-weight: 900;
}
.daily-meta strong {
    color: #2f8f77;
}
.hub-cast-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}
.inventory-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
}
.cast-card,
.inventory-card,
.feed-card {
    display: flex;
    gap: 12px;
    padding: 14px;
    border-radius: 22px;
    background: rgba(255, 255, 255, 0.78);
    border: 1px solid rgba(255, 255, 255, 0.84);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.76);
}
.cast-card {
    align-items: center;
}
.portrait-frame {
    width: 78px;
    min-width: 78px;
    height: 96px;
    border-radius: 20px;
    overflow: hidden;
    background:
        radial-gradient(circle at top, rgba(255, 245, 209, 0.88), rgba(255, 228, 220, 0.92)),
        rgba(255, 255, 255, 0.72);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.85), 0 12px 24px rgba(92, 65, 41, 0.1);
}
.portrait-frame img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    object-position: center bottom;
    mix-blend-mode: normal;
}
.cast-meta,
.inventory-meta {
    min-width: 0;
}
.cast-meta h3,
.inventory-meta h3,
.feed-card h3 {
    margin: 0 0 4px;
    font-size: 15px;
    line-height: 1.3;
}
.cast-role,
.inventory-label,
.feed-kicker {
    display: inline-flex;
    margin-bottom: 8px;
    padding: 5px 9px;
    border-radius: 999px;
    background: rgba(255, 183, 3, 0.12);
    color: #b87900;
    font-size: 10px;
    font-weight: 900;
}
.cast-meta p,
.inventory-meta p,
.feed-card p {
    margin: 0;
    font-size: 12px;
    line-height: 1.6;
    color: var(--color-text-dim);
    font-weight: 800;
}
.story-feed {
    display: grid;
    gap: 10px;
}
.weekly-card {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 16px;
    border-radius: 24px;
    background: linear-gradient(135deg, rgba(255, 249, 232, 0.95), rgba(255, 241, 223, 0.92));
    border: 1px solid rgba(255,255,255,0.85);
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.85);
}
.weekly-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
}
.weekly-head h3 {
    margin: 4px 0 0;
    font-size: 18px;
    color: var(--color-text-main);
}
.weekly-calendar {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 8px;
}
.weekly-day {
    min-height: 92px;
    padding: 10px 6px;
    border-radius: 18px;
    background: rgba(255,255,255,0.7);
    border: 1px solid rgba(255,255,255,0.85);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    text-align: center;
}
.weekly-day-label {
    font-size: 9px;
    font-weight: 900;
    color: #b87900;
    letter-spacing: 0.08em;
}
.weekly-day strong {
    font-size: 14px;
    color: var(--color-text-main);
}
.weekly-day small {
    font-size: 11px;
    color: var(--color-text-dim);
    font-weight: 800;
}
.weekly-day em {
    font-style: normal;
    font-size: 10px;
    font-weight: 900;
    color: #b9a89a;
}
.weekly-day.today {
    box-shadow: 0 0 0 2px rgba(255, 183, 3, 0.18);
}
.weekly-day.stamped {
    background: linear-gradient(180deg, rgba(255, 230, 183, 0.95), rgba(255, 210, 126, 0.9));
    transform: translateY(-2px);
}
.weekly-day.stamped em {
    color: #915800;
}
.weekly-reward-text {
    margin: 0;
    font-size: 12px;
    line-height: 1.65;
    color: var(--color-text-dim);
    font-weight: 800;
}
.feed-card {
    flex-direction: column;
}
.feed-card .cloud-save-status {
    display: block;
    margin-top: 2px;
}
.inventory-card {
    flex-direction: column;
}
.inventory-card.cast-card {
    flex-direction: row;
    align-items: center;
}
.inventory-section {
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.full-span {
    grid-column: 1 / -1;
}
.inventory-section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}
.inventory-section-head strong {
    font-size: 12px;
    color: var(--color-text-main);
}
.character-select-grid,
.title-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}
.playable-card,
.title-card {
    position: relative;
    border: 2px solid rgba(255, 255, 255, 0.7);
}
.playable-card.selected,
.title-card.selected {
    border-color: rgba(255, 183, 3, 0.72);
    box-shadow: 0 14px 26px rgba(177, 111, 0, 0.14), inset 0 1px 0 rgba(255,255,255,0.86);
}
.playable-frame {
    width: 100%;
    min-width: 0;
    height: 168px;
    border-radius: 18px;
}
.stage-track {
    display: flex;
    gap: 6px;
    margin-top: 10px;
}
.stage-track span {
    width: 22px;
    height: 22px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    background: rgba(0,0,0,0.08);
    color: rgba(74, 59, 50, 0.42);
    font-size: 11px;
    font-weight: 900;
}
.stage-track span.unlocked {
    background: rgba(255, 183, 3, 0.18);
    color: #b87900;
}
.mini-action-btn {
    width: 100%;
    min-height: 38px;
    margin-top: 12px;
    border: none;
    border-radius: 14px;
    background: var(--color-primary);
    color: white;
    font-weight: 900;
    font-size: 12px;
    box-shadow: 0 8px 16px rgba(255, 183, 3, 0.24);
}
.mini-action-btn:disabled {
    background: rgba(168, 153, 139, 0.36);
    color: rgba(74, 59, 50, 0.58);
    box-shadow: none;
}
.inventory-value {
    font-size: 20px;
    font-weight: 900;
    color: var(--color-text-main);
}
.settings-stack {
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.settings-btn {
    width: 100%;
    justify-content: center;
    min-height: 54px;
}
.settings-stack .feed-card,
.settings-stack .hub-tip {
    width: 100%;
    align-self: stretch;
}
.settings-stack .auth-action-row {
    justify-content: stretch;
}
.settings-stack .auth-action-row .hub-tip-btn {
    width: 100%;
}
.settings-btn.muted {
    filter: saturate(0.7);
    opacity: 0.8;
}
.btn-danger {
    background: linear-gradient(135deg, #ff8fab, var(--color-error)) !important;
    color: white !important;
    box-shadow: 0 8px 18px rgba(239, 71, 111, 0.28) !important;
    border-color: rgba(255,255,255,0.4) !important;
}
.hub-utility-row {
    display: grid;
    gap: 12px;
}
.hub-utility-row .hub-tip,
.hub-utility-row .auth-card {
    width: 100%;
}
.compact-tip {
    text-align: left;
}
.auth-action-row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
}
.hub-tip-btn.secondary {
    background: linear-gradient(135deg, #ffffff, #f6ebe1);
    color: var(--color-text-main);
    box-shadow: 0 8px 18px rgba(110, 78, 52, 0.14);
}
.hub-bottom-nav {
    margin-top: auto;
    position: relative;
    left: auto;
    right: auto;
    bottom: auto;
    display: flex;
    justify-content: space-around;
    align-items: flex-end;
    width: 100%;
    flex-shrink: 0;
    min-height: 92px;
    padding: 10px 8px calc(var(--safe-bottom) + 10px);
    border-radius: 28px 28px 0 0;
    background:
        linear-gradient(180deg, rgba(255,252,248,0.97) 0%, rgba(255,249,240,0.99) 100%);
    box-shadow:
        0 -8px 32px rgba(120,80,40,0.10),
        inset 0 1px 0 rgba(255,255,255,0.95);
    z-index: 100;
    border-top: 1.5px solid rgba(255,220,170,0.45);
}
.hub-nav-btn {
    flex: 1;
    border: none;
    background: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    gap: 5px;
    color: var(--color-text-dim);
    font-size: 10px;
    font-weight: 900;
    cursor: pointer;
    transition: transform 0.25s cubic-bezier(0.34,1.56,0.64,1), color 0.2s;
    padding: 8px 4px 6px;
    position: relative;
    letter-spacing: 0.02em;
    min-height: 64px;
}
.hub-nav-btn::before {
    content: '';
    position: absolute;
    top: 2px;
    left: 50%;
    transform: translateX(-50%) scale(0);
    width: 42px;
    height: 42px;
    border-radius: 14px;
    background: rgba(255,183,3,0.08);
    transition: transform 0.3s cubic-bezier(0.34,1.56,0.64,1), background 0.2s;
    z-index: 0;
}
.hub-nav-btn img {
    width: 24px;
    height: 24px;
    filter: grayscale(0.8) opacity(0.45);
    transition: filter 0.25s, opacity 0.25s, transform 0.3s cubic-bezier(0.34,1.56,0.64,1);
    position: relative;
    z-index: 1;
}
.hub-nav-btn span {
    position: relative;
    z-index: 1;
    line-height: 1.15;
    text-align: center;
}
.hub-nav-btn.active {
    color: #b87900;
}
.hub-nav-btn.active::before {
    transform: translateX(-50%) scale(1);
    background: rgba(255,183,3,0.12);
}
.hub-nav-btn.active img {
    filter: drop-shadow(0 2px 6px rgba(255,183,3,0.35));
    opacity: 1;
    transform: scale(1.15) translateY(-1px);
}
/* Center story orb — elevated golden button */
.main-orb-btn {
    transform: translateY(-22px);
    padding-bottom: 0 !important;
}
.main-orb-btn::before {
    display: none !important;
}
.main-orb-btn img {
    width: 66px;
    height: 66px;
    padding: 13px;
    background: linear-gradient(145deg, #ffd166, #ffb703, #e6a000);
    border-radius: 50%;
    filter: none !important;
    opacity: 1 !important;
    box-shadow:
        0 6px 20px rgba(255,183,3,0.45),
        0 2px 8px rgba(255,183,3,0.3),
        inset 0 1px 2px rgba(255,255,255,0.6);
    border: 3.5px solid white;
    animation: orbPulse 2.8s ease-in-out infinite;
}
.main-orb-btn span {
    margin-top: 0;
    font-size: 12px;
    color: #b87900;
    font-weight: 900;
}
.main-orb-btn.active img {
    transform: scale(1.08);
    box-shadow:
        0 8px 28px rgba(255,183,3,0.55),
        0 3px 10px rgba(255,183,3,0.35),
        inset 0 1px 2px rgba(255,255,255,0.6);
}
@keyframes orbPulse {
    0%, 100% { box-shadow: 0 6px 20px rgba(255,183,3,0.45), 0 2px 8px rgba(255,183,3,0.3), inset 0 1px 2px rgba(255,255,255,0.6); }
    50% { box-shadow: 0 8px 28px rgba(255,183,3,0.6), 0 3px 12px rgba(255,183,3,0.4), inset 0 1px 2px rgba(255,255,255,0.6); }
}

/* Greeting overlay for boot animation */
#greeting-overlay {
    position: absolute;
    inset: 0;
    z-index: 400;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: rgba(0,0,0,0.35);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.5s;
}
#greeting-overlay.show {
    opacity: 1;
    pointer-events: all;
}
.greeting-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    max-width: min(88%, 340px);
    padding: 28px 24px;
    background: rgba(255,251,247,0.95);
    border-radius: 32px;
    border: var(--glass-border);
    box-shadow: 0 24px 60px rgba(81,57,38,0.22);
    transform: scale(0.85) translateY(20px);
    transition: transform 0.5s cubic-bezier(0.34,1.56,0.64,1);
    text-align: center;
}
#greeting-overlay.show .greeting-card {
    transform: scale(1) translateY(0);
}
.greeting-portrait {
    width: 140px;
    height: 160px;
    border-radius: 24px;
    overflow: hidden;
    background:
        radial-gradient(circle at top, rgba(255,245,209,0.88), rgba(255,228,220,0.92)),
        rgba(255,255,255,0.72);
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.85), 0 12px 24px rgba(92,65,41,0.12);
}
.greeting-portrait img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    object-position: center bottom;
}
.greeting-name {
    font-size: 18px;
    font-weight: 900;
    color: var(--color-secondary);
}
.greeting-text {
    font-size: 15px;
    font-weight: 700;
    color: var(--color-text-main);
    line-height: 1.6;
    margin: 0;
}
.greeting-tap {
    font-size: 12px;
    color: var(--color-text-dim);
    font-weight: 800;
    animation: bounce 1.5s infinite;
}

/* Portrait Variants */
.portrait-iris img,
img.portrait-iris {
    filter:none;
}
.portrait-mentor img,
img.portrait-mentor {
    filter:none;
}
.portrait-scout img,
img.portrait-scout {
    filter:none;
}
.portrait-broker img,
img.portrait-broker {
    filter:none;
}
.portrait-rival img,
img.portrait-rival {
    filter:none;
}
.portrait-client img,
img.portrait-client {
    filter:none;
}

/* Map */
#view-map .map-container, #view-shop .shop-container {
    flex:1;
    width:100%;
    min-height:0;
    overflow-y:auto;
    padding:calc(var(--global-header-height) + 16px) var(--content-side-padding) calc(var(--safe-bottom) + 32px);
    scroll-padding-top:calc(var(--global-header-height) + 20px);
    overscroll-behavior:contain;
}
.map-tools {
    display:flex;
    flex-wrap:wrap;
    justify-content:center;
    gap:10px;
    margin-bottom:12px;
}
.map-mini-btn {
    min-height:42px;
    padding:10px 16px;
    border:1px solid rgba(255,255,255,0.92);
    border-radius:999px;
    background:rgba(255,255,255,0.9);
    color:var(--color-text-main);
    font-family:var(--font-main);
    font-size:13px;
    font-weight:900;
    box-shadow:var(--shadow-soft);
    cursor:pointer;
}
.map-mini-btn-secondary {
    background:linear-gradient(135deg, rgba(233, 248, 255, 0.98), rgba(236, 255, 244, 0.92));
}
.section-heading { text-align:center; font-size:16px; color:var(--color-text-main); background:rgba(255,255,255,0.78); padding:12px 14px; border-radius:18px; margin-bottom:20px; box-shadow:var(--shadow-soft); backdrop-filter:blur(12px); -webkit-backdrop-filter:blur(12px); }
.level-grid { display:grid; grid-template-columns:1fr; gap:15px; }
.level-card { position:relative; overflow:hidden; background:rgba(255,255,255,0.9); border:var(--glass-border); border-radius:24px; padding:18px 16px; text-align:center; box-shadow:var(--shadow-soft); cursor:pointer; transition:transform 0.18s ease, box-shadow 0.18s ease; animation:cardEntrance 0.45s ease both; animation-delay:var(--stagger-delay, 0ms); backdrop-filter:blur(12px); -webkit-backdrop-filter:blur(12px); }
.level-card:active { transform:translateY(1px) scale(0.97); }
.level-card-top { display:flex; justify-content:space-between; gap:8px; margin-bottom:12px; }
.level-tag { display:inline-flex; align-items:center; justify-content:center; padding:6px 10px; border-radius:999px; background:rgba(255, 183, 3, 0.16); color:#b87900; font-size:11px; font-weight:900; }
.level-tag.alt { background:rgba(142, 202, 230, 0.16); color:#25718d; }
.level-card h3 { margin:0 0 8px; font-size:15px; line-height:1.35; }
.level-client { margin:0 0 6px; font-size:12px; font-weight:800; color:var(--color-text-main); }
.level-rule { margin:0 0 10px; font-size:11px; line-height:1.5; color:var(--color-text-dim); font-weight:700; }
.level-meta { margin:0 0 14px; font-size:11px; font-weight:800; color:#b87900; }
.level-stars { display:flex; justify-content:center; gap:5px; }
.level-stars img { width: 18px; height: 18px; filter: grayscale(1) opacity(0.3); }
.level-stars img.earned { filter: none; }

.new-level-glow {
    animation: goldGlow 2s infinite alternate, slideInUp 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
    border: 3px solid var(--color-primary); box-shadow: 0 0 20px rgba(255, 183, 3, 0.5);
}
@keyframes slideInUp { from {opacity:0; transform:translateY(30px) scale(0.8);} to {opacity:1; transform:translateY(0) scale(1);} }
@keyframes goldGlow { from {box-shadow: 0 0 10px rgba(255, 183, 3, 0.2);} to {box-shadow: 0 0 25px rgba(255, 183, 3, 0.8);} }

/* Shop */
.shop-npc { display:flex; align-items:center; background:rgba(255,255,255,0.8); padding:16px; border-radius:24px; margin-bottom:20px; box-shadow:var(--shadow-soft); backdrop-filter:blur(14px); -webkit-backdrop-filter:blur(14px); }
.npc-avatar { width:60px; height:60px; margin-right:15px; filter:drop-shadow(0 4px 6px rgba(0,0,0,0.1)); }
.npc-dialogue { font-size:14px; font-weight:700; line-height:1.6; }
.shop-items { display:flex; flex-direction:column; gap:15px; }
.shop-item { position:relative; overflow:hidden; background:rgba(255,255,255,0.94); border-radius:24px; padding:16px; display:flex; flex-wrap:wrap; align-items:center; gap:12px; box-shadow:var(--shadow-soft); backdrop-filter:blur(14px); -webkit-backdrop-filter:blur(14px); animation:cardEntrance 0.45s ease both; animation-delay:var(--stagger-delay, 0ms); }
.shop-item-icon { font-size:30px; margin-right:0; width:50px; text-align:center; }
.shop-item-info { flex:1; min-width:0; }
.shop-item-info h4 { margin:0 0 5px; font-size:16px; }
.shop-item-info p { margin:0; font-size:12px; color:var(--color-text-dim); line-height:1.5; }
.shop-item-meta { margin-top:6px !important; font-size:11px !important; color:#b87900 !important; font-weight:800 !important; }
.buy-btn { background:var(--color-primary); border:none; border-radius:14px; padding:12px 16px; font-weight:800; color:white; display:flex; align-items:center; justify-content:center; box-shadow:0 4px 10px rgba(255, 183, 3, 0.4); min-height:46px; margin-left:auto; flex-shrink:0; min-width:112px; appearance:none; -webkit-appearance:none; }
.buy-btn img { width:16px; height:16px; margin-right:5px; }
.buy-btn:disabled { background:#ccc; box-shadow:none; pointer-events:none;}

/* Game */
#view-game { position:relative; min-height:0; height:100%; max-height:100%; padding-bottom:var(--input-console-height); overflow:hidden; background:#fce8db; transform: translateZ(0); -webkit-transform: translateZ(0); }
.game-header { position:sticky; top:0; z-index:3000; flex:0 0 auto; padding:calc(var(--safe-top) + 14px) var(--content-side-padding) 16px; background:#fff; background:rgba(255,255,255,1.0); border-bottom:var(--glass-border); box-shadow:0 8px 25px rgba(0,0,0,0.1); backdrop-filter:blur(20px); -webkit-backdrop-filter:blur(20px); transform: translateZ(0); -webkit-transform: translateZ(0); }
.header-main { display:flex; align-items:center; gap:14px; margin-bottom:14px; }
.quit-btn { background:white; border:none; min-height:46px; padding:10px 14px; border-radius:16px; font-weight:800; color:var(--color-error); box-shadow:var(--shadow-soft); white-space:nowrap; }
.game-info { min-width:0; }
.game-info h1 { margin:0; font-size:18px; color:var(--color-text-main); }
.game-info p { margin:2px 0 0; font-size:12px; color:var(--color-text-dim); font-weight:700;}

/* Mana */
.mana-container { width:100%; }
.mana-label { display:flex; justify-content:space-between; font-size:12px; font-weight:800; margin-bottom:6px; color:#4db6ac; }
.mana-bar { height:12px; background:rgba(0,0,0,0.08); border-radius:6px; overflow:hidden; box-shadow:inset 0 2px 4px rgba(0,0,0,0.05); }
#mana-fill { height:100%; background:linear-gradient(90deg, #48cae4, #06d6a0); transition:width 0.3s, background 0.3s; }
#mana-fill.danger-fill { background:linear-gradient(90deg, #ffb703, #ef476f); }

.feedback-legend {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 9px var(--content-side-padding);
    background: rgba(255, 252, 248, 0.72);
    border-bottom: 1px solid rgba(255,255,255,0.65);
    overflow-x: auto;
    scrollbar-width: none;
}
.feedback-legend::-webkit-scrollbar {
    display: none;
}
.feedback-legend span {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 5px 8px;
    border-radius: 999px;
    background: rgba(255,255,255,0.7);
    font-size: 10px;
    font-weight: 900;
    color: var(--color-text-dim);
    white-space: nowrap;
}
.feedback-legend .legend-title {
    background: rgba(255, 183, 3, 0.16);
    color: #b87900;
}
.feedback-legend img {
    width: 13px;
    height: 13px;
}
.legend-token {
    width: 12px;
    height: 12px;
    border-radius: 999px;
    background: linear-gradient(135deg, #8ecae6, #06d6a0);
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.8);
}

.combat-stage {
    flex: 0 0 auto;
    display: grid;
    grid-template-columns: minmax(92px, 1fr) minmax(104px, 1.05fr) minmax(92px, 1fr);
    gap: 8px;
    align-items: stretch;
    padding: 10px var(--content-side-padding) 0;
}
.combat-actor,
.combat-center {
    min-width: 0;
    border-radius: 20px;
    background: rgba(255,255,255,0.78);
    border: 1px solid rgba(255,255,255,0.76);
    box-shadow: 0 8px 18px rgba(92, 65, 41, 0.08);
}
.combat-actor {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    overflow: hidden;
}
.combat-portrait-frame {
    width: 100%;
    height: 104px;
    display: flex;
    justify-content: center;
    align-items: flex-end;
    background:
        linear-gradient(180deg, rgba(255,255,255,0.48), rgba(255,232,219,0.52));
}
.combat-portrait-frame img {
    max-width: 100%;
    max-height: 112px;
    object-fit: contain;
    object-position: center bottom;
    filter: drop-shadow(0 10px 18px rgba(70, 44, 28, 0.18));
}
.enemy-frame img {
    transform: scale(0.94);
}
.combat-actor-meta {
    width: 100%;
    padding: 8px 9px 10px;
    text-align: center;
}
.combat-actor-meta strong,
.combat-actor-meta span {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.combat-actor-meta strong {
    font-size: 12px;
    color: var(--color-text-main);
}
.combat-actor-meta span {
    margin-top: 2px;
    font-size: 10px;
    font-weight: 900;
    color: var(--color-text-dim);
}
.combat-center {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 8px;
    padding: 10px;
}
.combat-mode-tag {
    padding: 7px 8px;
    border-radius: 12px;
    background: rgba(255, 183, 3, 0.13);
    color: #b87900;
    font-size: 10px;
    line-height: 1.3;
    font-weight: 900;
    text-align: center;
}
.combat-timer,
.combat-hp {
    display: flex;
    flex-direction: column;
    gap: 5px;
}
.combat-timer-label,
.combat-hp-label {
    display: flex;
    justify-content: space-between;
    gap: 6px;
    font-size: 10px;
    font-weight: 900;
    color: var(--color-text-dim);
}
.combat-timer-label strong,
.combat-hp-label strong {
    color: var(--color-text-main);
}
.combat-timer-bar,
.combat-hp-bar {
    height: 8px;
    border-radius: 999px;
    overflow: hidden;
    background: rgba(0,0,0,0.09);
}
#combat-timer-fill {
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, #06d6a0, #ffb703, #ef476f);
    transition: width 0.35s linear;
}
#combat-hp-fill {
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, #ef476f, #ff8fab);
    transition: width 0.25s ease;
}
.combat-enemy.defeated {
    animation: enemyDefeated 0.7s ease forwards;
}
.combat-enemy.attacking {
    animation: enemyBounceAttack 0.5s ease-in-out;
}
#view-game.endless-battle {
    background:
        linear-gradient(180deg, rgba(45, 43, 68, 0.24), rgba(255,255,255,0.18) 58%),
        rgba(255,255,255,0.12);
}
#view-game.endless-battle .game-header {
    padding: calc(var(--safe-top) + 8px) var(--content-side-padding) 10px;
    background: #fff;
    background: rgba(255, 252, 248, 1.0);
}
#view-game.endless-battle .header-main {
    margin-bottom: 8px;
}
#view-game.endless-battle .game-info h1 {
    font-size: 16px;
}
#view-game.endless-battle .game-info p {
    max-width: 100%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
#view-game.endless-battle .feedback-legend {
    padding-top: 7px;
    padding-bottom: 7px;
    background: rgba(33, 32, 48, 0.38);
}
#view-game.endless-battle .feedback-legend span {
    background: rgba(255,255,255,0.86);
}
#view-game.endless-battle .combat-stage {
    position: relative;
    flex: 0 0 clamp(130px, 20dvh, 170px);
    min-height: clamp(130px, 20dvh, 170px);
    max-height: 170px;
    display: block;
    align-items: stretch;
    padding: 0 var(--content-side-padding) 12px;
    overflow: hidden;
    background:
        radial-gradient(circle at 50% 55%, rgba(255, 230, 159, 0.36), transparent 28%),
        radial-gradient(circle at 52% 42%, rgba(134, 217, 255, 0.22), transparent 38%),
        linear-gradient(180deg, rgba(53, 48, 82, 0.68), rgba(91, 72, 98, 0.42) 62%, rgba(255, 242, 225, 0.28));
    border-bottom: 1px solid rgba(255,255,255,0.58);
    box-shadow: inset 0 -18px 30px rgba(65, 42, 34, 0.1);
    transition: background 0.8s ease;
}
#view-game.endless-battle.abyssal-theme .combat-stage {
    background:
        radial-gradient(circle at 50% 45%, rgba(123, 75, 255, 0.25), transparent 35%),
        radial-gradient(circle at 48% 60%, rgba(255, 87, 153, 0.18), transparent 42%),
        linear-gradient(180deg, #1a1625, #2d243a 65%, #3d304a);
    border-bottom-color: rgba(255, 255, 255, 0.25);
    box-shadow: inset 0 -22px 40px rgba(0, 0, 0, 0.4);
}
#view-game.endless-battle.abyssal-theme .combat-stage::after {
    opacity: 0.4;
    mix-blend-mode: overlay;
}
#view-game.endless-battle.abyssal-theme #history-display {
    background: rgba(25, 22, 35, 0.88);
    border-color: rgba(255, 255, 255, 0.15);
    color: #e0e0e0;
}
#view-game.endless-battle.abyssal-theme .history-row {
    background: rgba(255, 255, 255, 0.05);
}
#view-game.endless-battle.abyssal-theme .history-row strong {
    color: #fff;
}
#view-game.endless-battle .combat-enemy.is-boss {
    filter: drop-shadow(0 0 15px rgba(255, 215, 0, 0.4));
}
#view-game.endless-battle .combat-enemy.is-boss .combat-portrait-frame img {
    transform: scale(1.35) translateY(-5px);
    filter: drop-shadow(0 20px 30px rgba(0, 0, 0, 0.5)) brightness(1.1) saturate(1.2);
}
#view-game.endless-battle .combat-enemy.is-boss .combat-actor-meta {
    background: rgba(255, 245, 200, 0.98);
    border: 2px solid #ffca28;
}
#view-game.endless-battle .combat-enemy.is-boss .combat-actor-meta strong {
    color: #d32f2f;
    font-size: 13px;
}
#view-game.endless-battle .combat-stage::before {
    content: '';
    position: absolute;
    left: 50%;
    bottom: 12px;
    width: min(60%, 240px);
    height: 20px;
    transform: translateX(-50%);
    border-radius: 50%;
    background: radial-gradient(ellipse, rgba(38, 30, 48, 0.32), rgba(38, 30, 48, 0));
    pointer-events: none;
}
#view-game.endless-battle .combat-stage::after {
    content: '';
    position: absolute;
    inset: 0;
    background-image:
        linear-gradient(rgba(255,255,255,0.08) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255,255,255,0.07) 1px, transparent 1px);
    background-size: 42px 42px;
    opacity: 0.32;
    pointer-events: none;
}
#view-game.endless-battle .combat-center {
    position: absolute;
    inset: 10px var(--content-side-padding) 12px;
    z-index: 5;
    display: block;
    padding: 0;
    border: none;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
    pointer-events: none;
}
#view-game.endless-battle .combat-mode-tag {
    display: none;
}
#view-game.endless-battle .combat-hp {
    position: relative;
    top: auto;
    left: auto;
    right: auto;
    width: 100%;
    min-width: 0;
    gap: 6px;
    margin-top: 4px;
    padding: 6px 8px;
    border-radius: 12px;
    background: rgba(255, 252, 248, 0.95);
    box-shadow: 0 4px 10px rgba(43, 30, 42, 0.1);
    border-top: none;
    z-index: 12;
}
#view-game.endless-battle .combat-hp-bar {
    height: 8px;
}
#view-game.endless-battle .combat-timer {
    position: absolute;
    top: 45px;
    right: 0;
    left: auto;
    bottom: auto;
    width: auto;
    min-width: 120px;
    transform: none;
    gap: 6px;
    padding: 6px 12px 10px 12px;
    border-radius: 12px;
    background: rgba(255, 252, 248, 0.95);
    box-shadow: 0 8px 18px rgba(43, 30, 42, 0.16);
    border: var(--glass-border);
    border-top: 1px solid rgba(0,0,0,0.05);
    display: flex;
    flex-direction: column;
    z-index: 12;
    pointer-events: auto;
}
#view-game.endless-battle .combat-timer-label {
    font-size: 12px;
}
#view-game.endless-battle .combat-timer-bar {
    height: 8px;
    width: 100%;
}
#view-game.endless-battle .combat-player {
    position: absolute;
    left: 4px;
    top: 24px;
    bottom: auto;
    z-index: 10;
    width: 90px;
    border-radius: 18px;
    background: rgba(255,255,255,0.84);
    overflow: visible;
    box-shadow: 0 8px 18px rgba(43, 30, 42, 0.12);
}
#view-game.endless-battle .combat-player .combat-portrait-frame {
    height: 74px;
}
#view-game.endless-battle .combat-player .combat-portrait-frame img {
    max-height: 142px;
    transform: scale(1.2) translateY(-10px);
    transform-origin: bottom center;
}
#view-game.endless-battle .combat-player .combat-actor-meta {
    padding: 6px 7px 8px;
}
#view-game.endless-battle .combat-enemy {
    position: absolute;
    inset: 10px var(--content-side-padding) 12px;
    z-index: 10;
    width: auto;
    border: none;
    background: transparent;
    box-shadow: none;
    transform: none;
    overflow: visible;
    pointer-events: none;
}
#view-game.endless-battle .combat-enemy .combat-portrait-frame {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    width: min(70%, 285px);
    top: 24px;
    height: clamp(88px, 14dvh, 120px);
    background: transparent;
}
#view-game.endless-battle .combat-enemy .combat-portrait-frame img {
    max-height: clamp(124px, 19.2dvh, 170px);
    filter: drop-shadow(0 18px 22px rgba(28, 20, 38, 0.35));
    animation: enemyBreathing 3s ease-in-out infinite;
    transform-origin: bottom center;
}
#view-game.endless-battle .combat-enemy .combat-actor-meta {
    position: absolute;
    top: 0;
    right: 0;
    width: auto;
    min-width: 120px;
    margin: 0;
    padding: 6px 12px;
    border-radius: 12px;
    background: rgba(255, 252, 248, 0.95);
    box-shadow: 0 8px 18px rgba(43, 30, 42, 0.16);
    border: var(--glass-border);
    z-index: 12;
    pointer-events: auto;
}
#view-game.endless-battle .combat-enemy .combat-actor-meta strong {
    font-size: 11px;
}
#view-game.endless-battle .combat-enemy .combat-actor-meta span {
    font-size: 10px;
}
#view-game.endless-battle #history-display {
    flex: 1 1 auto;
    min-height: 160px;
    max-height: none;
    margin: 12px var(--content-side-padding) 24px;
    padding: 16px;
    background: rgba(255, 252, 248, 0.85);
    border-radius: 20px;
    border: var(--glass-border);
    box-shadow: var(--shadow-soft);
    display: flex;
    flex-direction: column-reverse;
    gap: 10px;
    overflow-y: auto;
}
#view-game.endless-battle #history-display .empty-hint {
    margin: auto;
    font-size: 13px;
    line-height: 1.5;
    color: var(--color-text-dim);
}
#view-game.endless-battle .history-row {
    padding: 10px 12px;
    border-radius: 18px;
}
#view-game.endless-battle .turn-number {
    min-width: 48px;
    font-size: 14px;
}
#view-game.endless-battle .mini-symbol {
    width: 26px;
    height: 26px;
}
#view-game.endless-battle #input-console {
    gap: 11px;
    padding-top: 13px;
    padding-bottom: calc(max(var(--safe-bottom), var(--runtime-safe-bottom)) + 13px);
    border-radius: 26px 26px 0 0;
    background:
        linear-gradient(180deg, rgba(255,255,255,0.96), rgba(255, 246, 237, 0.98));
    box-shadow: 0 -16px 34px rgba(35, 25, 30, 0.14);
}
#view-game.endless-battle .cauldron-label {
    color: #9f6a00;
}
#view-game.endless-battle .slots-container {
    gap: 8px;
    padding: 12px 10px;
    border-radius: 20px;
    background:
        linear-gradient(180deg, rgba(255,255,255,0.78), rgba(246, 234, 220, 0.74));
    border: 1px solid rgba(255,255,255,0.88);
}
#view-game.endless-battle .slot {
    width: clamp(44px, 11vw, 56px);
    max-width: 56px;
    border-radius: 14px;
}
#view-game.endless-battle .palette-container {
    padding: 2px 4px;
}
#view-game.endless-battle .token {
    width: clamp(40px, 10.5vw, 50px);
    height: clamp(40px, 10.5vw, 50px);
}
#view-game.endless-battle .action-container {
    gap: 8px;
}
#view-game.endless-battle .btn {
    min-height: 48px;
    padding-top: 13px;
    padding-bottom: 13px;
}
@keyframes enemyDefeated {
    0% { opacity: 1; transform: scale(1); filter: brightness(1); }
    100% { opacity: 0.35; transform: scale(0.78) translateY(10px); filter: brightness(1.35) saturate(0.5); }
}
@keyframes enemyAttack {
    0%, 100% { transform: translateX(-50%); }
    50% { transform: translateX(-50%) translateX(-10px); }
}
@keyframes enemyBounceAttack {
    0% { transform: translateX(-50%) translateY(0) scale(1); }
    15% { transform: translateX(-50%) translateY(8px) scale(1.02, 0.96); }
    35% { transform: translateX(-50%) translateY(-28px) scale(0.96, 1.06); filter: brightness(1.15); }
    55% { transform: translateX(-50%) translateY(0) scale(1.04, 0.94); }
    70% { transform: translateX(-50%) translateY(-10px) scale(0.98, 1.03); }
    85% { transform: translateX(-50%) translateY(0) scale(1.01, 0.99); }
    100% { transform: translateX(-50%) translateY(0) scale(1); }
}
@keyframes enemyBreathing {
    0%, 100% { transform: translateY(0) scale(1); }
    50% { transform: translateY(-12px) scale(1.04); }
}
@keyframes playerAttack {
    0%, 100% { transform: translateX(0) scale(1); }
    50% { transform: translateX(20px) scale(1.1); filter: brightness(1.2); }
}
@keyframes playerSuccess {
    0%, 100% { transform: translateY(0); filter: brightness(1); }
    30% { transform: translateY(-10px); filter: brightness(1.3) drop-shadow(0 0 10px rgba(255,215,0,0.8)); }
    50% { transform: translateY(0); }
    70% { transform: translateY(-5px); filter: brightness(1.3) drop-shadow(0 0 10px rgba(255,215,0,0.8)); }
}
@keyframes takeDamage {
    0%, 100% { transform: translateX(0); filter: brightness(1); }
    15% { transform: translateX(-6px) scale(0.96); filter: brightness(1.8) sepia(1) hue-rotate(-50deg) saturate(3); }
    30% { transform: translateX(6px); }
    45% { transform: translateX(-6px); }
    60% { transform: translateX(6px); }
    75% { transform: translateX(-6px); }
}
.combat-player.attacking { animation: playerAttack 0.32s ease-in-out; }
.combat-player.taking-damage { animation: takeDamage 0.4s ease-in-out; }
.combat-player.success { animation: playerSuccess 0.6s ease-in-out; }
.combat-enemy.taking-damage { animation: takeDamage 0.4s ease-in-out; }

/* History Area */
#history-display { flex:1 1 auto; min-height:0; padding:12px var(--content-side-padding); overflow-y:auto; overscroll-behavior:contain; display:flex; flex-direction:column-reverse; gap:12px; }
.empty-hint {text-align:center; font-size:12px; line-height:1.6; color:var(--color-text-main); opacity:0.6; font-weight:700; margin:auto;}
.history-row { position:relative; overflow:hidden; display:flex; align-items:center; background:rgba(255,255,255,0.86); border-radius:20px; padding:12px; box-shadow:var(--shadow-soft); animation:slideUp 0.3s ease forwards; backdrop-filter:blur(10px); -webkit-backdrop-filter:blur(10px); flex-shrink:0; }
@keyframes slideUp { from{opacity:0; transform:translateY(10px);} to{opacity:1; transform:translateY(0);} }
.turn-number { min-width:42px; text-align:center; font-size:12px; font-weight:900; color:var(--color-primary); }
.history-symbols { flex:1; display:flex; justify-content:center; gap:8px; }
.mini-symbol { width:32px; height:32px; background-size:contain; background-repeat:no-repeat; background-position:center; filter:drop-shadow(0 2px 4px rgba(0,0,0,0.1)); }
.history-feedback { display:flex; flex-direction:column; gap:4px; font-weight:800; font-size:12px; }
.feedback-item { display:flex; align-items:center; gap:4px; justify-content:flex-end;}
.feedback-icon { width:14px; height:14px; }

/* Input Console */
#input-console { 
    width: 100%;
    position:absolute;
    left:0;
    right:0;
    bottom:0;
    flex-shrink: 0;
    margin-top: 0;
    background:rgba(255,255,255,0.9); border-top:var(--glass-border); padding:18px var(--content-side-padding); 
    padding-bottom:calc(max(var(--safe-bottom), var(--runtime-safe-bottom)) + 16px); border-radius:30px 30px 0 0; 
    box-shadow:0 -10px 30px rgba(0,0,0,0.05); display:flex; flex-direction:column; gap:15px; 
    z-index: 10; backdrop-filter:blur(16px); -webkit-backdrop-filter:blur(16px);
}
.cauldron-label { text-align:center; font-size:12px; font-weight:800; color:var(--color-text-dim); }
.slots-container { display:flex; justify-content:center; gap:8px; flex-wrap:wrap; background:rgba(0,0,0,0.03); padding:15px 10px; border-radius:20px; box-shadow:inset 0 4px 8px rgba(0,0,0,0.03); }
.slot { width:11vw; max-width:42px; aspect-ratio:1/1; border-radius:10px; background:rgba(255,255,255,0.5); border:2px dashed #d4c4b7; display:flex; justify-content:center; align-items:center; }
.slot.filled { border:2px solid transparent; background:transparent; cursor:pointer; }
.slot.hinted { border:2px solid var(--color-primary); background:rgba(255, 183, 3, 0.1); }
.slot.selected {
    border-color: #4db6ac;
    background: rgba(77, 182, 172, 0.14);
    box-shadow: 0 0 0 4px rgba(77, 182, 172, 0.14);
}
.palette-container { display:flex; justify-content:space-around; padding:5px; }
.palette-btn { background:none; border:none; padding:0; cursor:pointer; transition:transform 0.1s; }
.palette-btn:active { transform:scale(0.85); }
.token { width:45px; height:45px; background-size:contain; background-repeat:no-repeat; background-position:center; filter:drop-shadow(0 4px 6px rgba(0,0,0,0.15)); pointer-events:none; }
.slot .token { animation:popIn 0.3s forwards; }
@keyframes popIn { 0%{transform:scale(0);} 50%{transform:scale(1.2);} 100%{transform:scale(1);} }

/* Actions */
.action-container { display:flex; gap:10px; }
.btn { font-family:var(--font-main); font-weight:900; font-size:15px; padding:16px 0; border-radius:16px; border:none; cursor:pointer; box-shadow:0 4px 10px rgba(0,0,0,0.1); transition: opacity 0.2s, transform 0.16s ease; min-height:52px; }
.btn:active { transform: scale(0.98); }
.btn-primary { flex:2; background:var(--color-secondary); color:white; }
.btn-secondary { flex:1; background:white; color:var(--color-text-main); border:2px solid #e2d1c3; }
.btn-primary:disabled { background:#d4c4b7; color:white; box-shadow:none; pointer-events:none;}
.btn-secondary:disabled { opacity:0.5; pointer-events:none;}
.btn-secondary.locked-hint { background:#ef476f; color:white; border:none; }

/* Modals */
.modal-overlay { position:absolute; top:0; left:0; right:0; bottom:0; background:rgba(0,0,0,0.6); backdrop-filter:blur(5px); display:flex; justify-content:center; align-items:center; padding:calc(var(--safe-top) + 12px) 14px calc(var(--safe-bottom) + 12px); opacity:0; pointer-events:none; z-index:6000; transition:opacity 0.3s; }
.modal-overlay.active { opacity:1; pointer-events:all; }
.modal-panel { background:white; border-radius:30px; padding:30px 24px 24px; width:min(100%, 420px); max-height:100%; overflow-y:auto; text-align:center; box-shadow:0 20px 50px rgba(0,0,0,0.2); transform:scale(0.9); transition:transform 0.3s; display:flex; flex-direction:column; gap:14px; }
.modal-overlay.active .modal-panel { transform:scale(1); }
.modal-panel h2 { margin:0; color:var(--color-accent); font-size:24px; }
.modal-panel h2.error-title { color:var(--color-text-dim); }
.modal-panel p { color:var(--color-text-dim); margin:0; font-weight:700; line-height:1.6;}
#confirm-desc { white-space:pre-line; }
.modal-panel .action-container { justify-content:center; flex-wrap:wrap; }
.modal-panel .action-container .btn { flex:1 1 140px; }
.result-panel { width:min(100%, 420px); gap:14px; }
.modal-topline { align-self:center; padding:6px 12px; border-radius:999px; background:rgba(255, 183, 3, 0.12); color:#b87900; font-size:11px; font-weight:900; }
.result-panel[data-result="failure"] .modal-topline { background:rgba(239, 71, 111, 0.12); color:#c14e6c; }
.modal-story { background:rgba(255,255,255,0.72); border-radius:18px; padding:12px 14px; font-size:13px; line-height:1.6; color:var(--color-text-main); font-weight:700; }

.stars-display { margin:0; display:flex; justify-content:center; gap:10px; min-height:32px; }
.stars-display img { width: 32px; height: 32px; filter: grayscale(1) opacity(0.3); }
.stars-display img.earned { filter: none; filter: drop-shadow(0 2px 4px rgba(255, 183, 3, 0.4)); animation: starPop 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards; transform: scale(0); }
.stars-display img:nth-child(2) { animation-delay: 0.1s; }
.stars-display img:nth-child(3) { animation-delay: 0.2s; }
@keyframes starPop { to { transform: scale(1); } }

.result-stats {
    display:grid;
    grid-template-columns:repeat(2, minmax(0, 1fr));
    gap:10px;
}
.result-stat {
    text-align:left;
    background:rgba(255,255,255,0.72);
    border:1px solid rgba(255,255,255,0.8);
    border-radius:16px;
    padding:12px 14px;
}
.result-stat span {
    display:block;
    margin-bottom:6px;
    font-size:11px;
    font-weight:800;
    color:var(--color-text-dim);
}
.result-stat strong {
    display:block;
    font-size:14px;
    line-height:1.45;
    color:var(--color-text-main);
}
.result-stat.is-accent strong { color:#b97a00; }
.result-stat.is-warning strong { color:#9f5c00; }
.result-stat.is-danger strong { color:var(--color-error); }

.reward-box { display:flex; justify-content:center; align-items:center; background:#fff8e1; border-radius:15px; padding:15px; margin:0; font-size:24px; font-weight:900; color:#e09f00; }
.reward-icon { width:30px; height:30px; margin-right:0; }
#modal-coin-reward { font-size: clamp(16px, 4.6vw, 24px); line-height: 1.3; text-align: center; }
.modal-next {
    padding:12px 14px;
    border-radius:18px;
    background:rgba(255,255,255,0.72);
    color:var(--color-text-main);
    font-size:13px;
    line-height:1.6;
    font-weight:800;
}
.modal-btn { width:100%; min-height:58px; padding:16px 18px; white-space:normal; line-height:1.35; font-size:16px; }
.result-panel .modal-btn { background:var(--color-secondary); box-shadow:0 4px 10px rgba(0,0,0,0.1); }
#leaderboard-box {
    width:100%;
    margin-top:0 !important;
    background:rgba(255,255,255,0.74) !important;
    border:1px solid rgba(255,255,255,0.78);
    box-shadow:inset 0 1px 0 rgba(255,255,255,0.7);
}

@media (hover: hover) and (pointer: fine) {
    .logo-box {
        animation: floatPanel 5.5s ease-in-out infinite;
    }

    .boot-portrait {
        animation: floatPanel 6.6s ease-in-out infinite;
    }

    .mode-orb:hover,
    .hub-nav-btn:hover {
        transform: translateY(-3px);
    }

    .mode-story {
        animation: gentleSway 5.4s ease-in-out infinite;
    }

    .mode-daily {
        animation: gentleSway 5.4s ease-in-out infinite 0.7s;
    }

    .menu-btn.primary-btn,
    .menu-btn.shop-btn {
        animation: gentleSway 4.8s ease-in-out infinite;
    }

    .menu-btn.shop-btn {
        animation-delay: 0.6s;
    }

    .level-card:hover,
    .shop-item:hover {
        transform:translateY(-4px);
        box-shadow:0 18px 32px rgba(100, 70, 40, 0.18);
    }

    .buy-btn:hover,
    .result-panel .modal-btn:hover {
        transform:translateY(-2px);
        box-shadow:0 16px 28px rgba(74, 59, 50, 0.18);
    }
}

@media (hover: none), (pointer: coarse) {
    #app-container::before,
    #app-container::after {
        display:none;
    }

    .menu-btn::after,
    .level-card::before,
    .level-card::after,
    .shop-item::before,
    .shop-item::after,
    .history-row::after {
        display:none;
    }

    .view-section:not(.view-exit):not(.view-enter),
    .view-section.active-view:not(.view-exit):not(.view-enter) {
        transform: none;
    }

    #global-header,
    #view-hub .hub-content,
    .logo-box,
    .hub-tip,
    .section-heading,
    .level-card,
    .shop-npc,
    .shop-item,
    #view-game,
    .game-header,
    #input-console,
    .history-row,
    .dialogue-box,
    .modal-overlay,
    .modal-panel,
    #save-toast,
    #quest-widget,
    .coin-display,
    .stamina-display,
    #btn-global-back,
    .quit-btn {
        backdrop-filter: none !important;
        -webkit-backdrop-filter: none !important;
        backface-visibility: hidden;
        -webkit-backface-visibility: hidden;
    }

    #global-header {
        background: rgba(255, 252, 248, 0.94);
    }

    #view-hub .hub-content {
        background: transparent;
    }

    .boot-overlay,
    .boot-layer,
    .hub-panel,
    .mode-orb,
    .story-spotlight,
    .daily-card,
    .cast-card,
    .inventory-card,
    .feed-card,
    .hub-bottom-nav {
        backdrop-filter: none !important;
        -webkit-backdrop-filter: none !important;
    }

    .logo-box,
    .hub-tip,
    .section-heading,
    .level-card,
    .shop-npc,
    .shop-item,
    .history-row,
    .game-header,
    #input-console,
    .dialogue-box,
    .modal-panel,
    #save-toast,
    #quest-widget,
    .coin-display,
    .stamina-display,
    #btn-global-back,
    .quit-btn {
        background-color: rgba(255, 252, 248, 0.94);
    }

    .reward-box,
    .shop-price-box {
        background: rgba(255, 245, 214, 0.96);
    }

    .logo-box,
    .menu-btn.primary-btn,
    .menu-btn.shop-btn,
    .level-card,
    .shop-item,
    .modal-panel,
    .result-panel {
        animation: none !important;
        transform: none !important;
    }
}

#game-message { position:absolute; top:calc(var(--game-header-height) + 12px); left:50%; width:min(calc(100% - (var(--content-side-padding) * 2)), 360px); transform:translateX(-50%); background:rgba(255,255,255,0.95); border-radius:20px; padding:10px 20px; font-weight:800; font-size:14px; box-shadow:var(--shadow-soft); opacity:0; transition:opacity 0.3s; z-index:50; text-align:center; pointer-events:none; }
#game-message.show { opacity:1; }
#game-message.error { color:var(--color-error); border:2px solid var(--color-error); }

@keyframes auroraFloat {
    0% { transform: translate3d(-2%, -1%, 0) scale(1); }
    50% { transform: translate3d(2%, 2%, 0) scale(1.05); }
    100% { transform: translate3d(-1%, 3%, 0) scale(1.02); }
}

@keyframes floatPanel {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-8px); }
}

@keyframes bootRuneSpin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

@keyframes cardEntrance {
    from { opacity: 0; transform: translateY(18px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes gentleSway {
    0%, 100% { transform: translateY(0) rotate(-0.6deg); }
    50% { transform: translateY(-4px) rotate(0.6deg); }
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-4px); }
}

@media (max-width: 430px) {
    #global-header {
        grid-template-columns: auto auto;
        grid-template-areas:
            "stats back"
            "title title";
        align-items: start;
        gap: 10px;
    }

    .header-title {
        text-align: left;
        padding: 0 4px;
        font-size: clamp(19px, 5.6vw, 24px);
    }

    #btn-global-back,
    .coin-display,
    .stamina-display,
    .quit-btn {
        min-height: 44px;
    }

    #btn-global-back {
        padding: 10px 14px;
        font-size: 13px;
    }

    .stats-combo {
        gap: 8px;
    }

    .coin-display,
    .stamina-display {
        padding: 7px 10px;
        font-size: 12px;
    }

    #view-hub .hub-content {
        padding-top: calc(var(--safe-top) + 12px);
        gap: 10px;
    }

    .boot-loader,
    .boot-cinematic {
        padding: 24px 18px;
    }

    .boot-cast {
        gap: 8px;
    }

    .hub-mode-orbit,
    .hub-cast-grid,
    .inventory-grid,
    .character-select-grid,
    .title-grid {
        grid-template-columns: 1fr;
    }

    .weekly-calendar {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }

    .hub-panel {
        padding: 16px;
    }

    .hub-hero-container {
        grid-template-columns: minmax(0, 1fr) 148px;
        min-height: 224px;
        padding: 16px 16px 0;
    }

    .hero-portrait-wrap {
        height: min(58vw, 240px);
        min-height: 188px;
    }

    .hero-bubble {
        padding: 12px 14px;
    }

    .hub-panel-head {
        flex-direction: column;
        align-items: stretch;
    }

    .hub-panel-badge {
        align-self: flex-start;
    }

    .hub-bottom-nav {
        gap: 6px;
        padding-left: 8px;
        padding-right: 8px;
    }

    .hub-nav-btn {
        min-height: 60px;
        font-size: 11px;
    }

    .portrait-frame {
        width: 72px;
        min-width: 72px;
        height: 90px;
    }

    .boot-cast {
        gap: 8px;
    }

    .boot-portrait {
        min-height: 116px;
    }

    .logo-box {
        padding: 22px 20px;
    }

    .logo-box h1 {
        font-size: 24px;
    }

    .logo-box h1 .sub-title {
        font-size: 28px;
    }

    .menu-btn,
    .shop-item,
    .level-card {
        border-radius: 22px;
    }

    .menu-buttons {
        width: min(300px, 100%);
    }

    .hub-tip {
        width:min(320px, 100%);
        font-size:12px;
    }

    .auth-user-row {
        align-items:flex-start;
    }

    .header-main {
        gap: 10px;
    }

    .result-stats {
        grid-template-columns: 1fr;
    }

    .buy-btn {
        width: 100%;
        margin-left: 0;
    }

    .game-info h1 {
        font-size: 17px;
    }

    .game-info p,
    .mana-label {
        font-size: 11px;
    }

    .combat-stage {
        grid-template-columns: 86px minmax(0, 1fr) 86px;
        gap: 6px;
    }

    .combat-portrait-frame {
        height: 88px;
    }

    .combat-portrait-frame img {
        max-height: 96px;
    }

    .combat-actor-meta {
        padding: 7px 6px 8px;
    }

    #view-game.endless-battle .game-header {
        padding-top: calc(var(--safe-top) + 6px);
        padding-bottom: 8px;
    }

    #view-game.endless-battle .header-main {
        gap: 8px;
        margin-bottom: 6px;
    }

    #view-game.endless-battle .feedback-legend {
        padding-top: 6px;
        padding-bottom: 6px;
    }

    #view-game.endless-battle .feedback-legend span {
        padding: 4px 7px;
        font-size: 9px;
    }

    #view-game.endless-battle .combat-stage {
        flex-basis: clamp(130px, 20dvh, 170px);
        min-height: clamp(130px, 20dvh, 170px);
        padding-bottom: 8px;
    }

    #view-game.endless-battle .combat-hp {
        min-width: 100px;
        padding: 5px 8px;
    }

    #view-game.endless-battle .combat-timer {
        min-width: 110px;
        padding: 5px 10px 8px;
    }

    #view-game.endless-battle .combat-timer-label,
    #view-game.endless-battle .combat-hp-label {
        font-size: 11px;
    }

    #view-game.endless-battle .combat-player {
        top: 24px;
        width: 78px;
    }

    #view-game.endless-battle .combat-player .combat-portrait-frame {
        height: 64px;
    }

    #view-game.endless-battle .combat-enemy {
        top: 40px;
        width: min(66%, 240px);
    }

    #view-game.endless-battle .combat-enemy .combat-portrait-frame {
        height: clamp(76px, 11.5dvh, 102px);
    }

    #view-game.endless-battle .combat-enemy .combat-portrait-frame img {
        max-height: clamp(92px, 13dvh, 120px);
    }

    #view-game.endless-battle #history-display {
        min-height: 108px;
        margin-top: 8px;
        padding: 12px;
    }

    #view-game.endless-battle .action-container {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        align-items: stretch;
    }

    #view-game.endless-battle .action-container .btn {
        min-width: 0;
        padding-left: 8px;
        padding-right: 8px;
        font-size: 13px;
        line-height: 1.25;
        white-space: normal;
        overflow-wrap: anywhere;
    }

    #view-game.endless-battle #input-console {
        gap: 8px;
        padding-top: 10px;
        padding-bottom: calc(max(var(--safe-bottom), var(--runtime-safe-bottom)) + 8px);
    }

    #view-game.endless-battle .cauldron-label {
        font-size: 11px;
    }

    #view-game.endless-battle .slots-container {
        padding: 10px 8px;
        gap: 6px;
    }

    #view-game.endless-battle .slot {
        width: clamp(40px, 10vw, 48px);
    }

    #view-game.endless-battle .palette-container {
        padding: 0;
    }

    #view-game.endless-battle .token {
        width: clamp(34px, 9vw, 42px);
        height: clamp(34px, 9vw, 42px);
    }

    #view-game.endless-battle .btn {
        min-height: 44px;
        padding-top: 10px;
        padding-bottom: 10px;
    }
}

@media (max-width: 380px) {
    #view-hub .hub-content {
        padding-left: 16px;
        padding-right: 16px;
    }

    .boot-copy h1 {
        font-size: 24px;
    }

    .boot-copy p,
    .boot-status {
        font-size: 13px;
    }

    .hub-title-box {
        padding: 20px 18px;
    }

    .mode-orb {
        min-height: 108px;
        padding: 16px 14px;
    }

    .weekly-calendar {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .weekly-day {
        min-height: 82px;
    }

    .hub-hero-container {
        grid-template-columns: minmax(0, 1fr) 122px;
        gap: 10px;
        min-height: 204px;
        padding: 14px 14px 0;
    }

    .hub-nav-btn {
        min-height: 54px;
        padding: 8px 4px;
        font-size: 10px;
    }

    .header-main {
        flex-direction: column;
        align-items: stretch;
    }

    .combat-stage {
        grid-template-columns: 80px minmax(0, 1fr) 80px;
    }

    .feedback-legend {
        padding-top: 7px;
        padding-bottom: 7px;
    }

    .quit-btn {
        width: fit-content;
    }

    .action-container {
        flex-direction: column;
    }

    .shop-item-head {
        flex-direction: row;
    }

    .shop-item-icon-wrap {
        width: 60px;
        height: 60px;
    }

    .slot {
        width: 13vw;
        max-width: 40px;
    }

    .modal-panel {
        width: min(92%, 400px);
        padding: 24px 18px 20px;
    }

    #view-game.endless-battle .header-main {
        flex-direction: row;
        align-items: center;
    }

    #view-game.endless-battle .combat-stage {
        min-height: 180px;
    }

    #view-game.endless-battle .combat-center {
        inset: 10px var(--content-side-padding) 10px;
    }

    #view-game.endless-battle .combat-mode-tag {
        display: none;
    }

    #view-game.endless-battle .combat-player {
        top: 8px;
        width: 82px;
    }

    #view-game.endless-battle .combat-player .combat-portrait-frame {
        min-height: 78px;
    }

    #view-game.endless-battle #history-display {
        min-height: 140px;
        max-height: none;
        margin: 10px 16px 20px;
    }

    #view-game.endless-battle .action-container .btn {
        font-size: 12px;
    }
}

/* ===== New Inventory Split Layout ===== */
.inv-split-layout {
    display: grid;
    grid-template-columns: 1fr 1.2fr;
    gap: 16px;
    align-items: start;
}
.inv-left {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    padding: 12px 8px;
    border-radius: 24px;
    background: linear-gradient(180deg, rgba(255,248,237,0.95), rgba(255,235,218,0.9));
    border: 2px solid rgba(255,255,255,0.8);
    box-shadow: 0 12px 28px rgba(92,65,41,0.1);
    transition: transform 0.2s, box-shadow 0.2s;
}
.inv-left:active {
    transform: scale(0.97);
}
.inv-character-img {
    width: 100%;
    max-height: 280px;
    object-fit: contain;
    object-position: center bottom;
    filter: drop-shadow(0 12px 22px rgba(70,44,28,0.2));
    border-radius: 16px;
}
.inv-char-tap-hint {
    font-size: 11px;
    font-weight: 900;
    color: var(--color-primary);
    padding: 6px 12px;
    border-radius: 999px;
    background: rgba(255,183,3,0.12);
}
.inv-right {
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.inv-right .inventory-card {
    flex-direction: column;
    gap: 8px;
}
.title-stat-card {
    cursor: pointer;
    border: 2px solid rgba(255,183,3,0.3) !important;
    transition: transform 0.18s, box-shadow 0.18s;
}
.title-stat-card:active {
    transform: scale(0.97);
}
.title-tap-hint {
    display: block;
    margin-top: 4px;
    font-size: 11px;
    font-weight: 900;
    color: var(--color-primary);
    text-align: right;
}

/* Character Select Modal */
.char-select-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 14px;
    padding: 8px 0;
}
.char-select-option {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 14px 10px;
    border-radius: 22px;
    background: rgba(255,255,255,0.8);
    border: 2px solid rgba(255,255,255,0.7);
    cursor: pointer;
    transition: transform 0.15s, border-color 0.2s;
}
.char-select-option:active {
    transform: scale(0.96);
}
.char-select-option.selected {
    border-color: rgba(255,183,3,0.7);
    background: linear-gradient(180deg, rgba(255,248,230,0.95), rgba(255,240,210,0.92));
}
.char-select-option img {
    width: 100%;
    max-height: 180px;
    object-fit: contain;
    object-position: center bottom;
    filter: drop-shadow(0 8px 16px rgba(70,44,28,0.15));
    border-radius: 14px;
}
.char-select-option strong {
    font-size: 15px;
    color: var(--color-text-main);
}
.char-select-option span {
    font-size: 11px;
    font-weight: 900;
    color: var(--color-text-dim);
}
.char-select-option em {
    font-style: normal;
    font-size: 10px;
    font-weight: 900;
    padding: 4px 10px;
    border-radius: 999px;
    background: rgba(255,183,3,0.16);
    color: #b87900;
}

/* Title Upgrade Grid in Modal */
.title-upgrade-grid {
    grid-template-columns: 1fr !important;
    gap: 10px !important;
}
.title-upgrade-grid .title-card {
    flex-direction: column;
    gap: 8px;
}
.title-upgrade-btn {
    margin-top: 6px !important;
    background: var(--color-secondary) !important;
    box-shadow: 0 8px 16px rgba(74,59,50,0.18) !important;
}

/* Endless Mode: Full portrait without container frame */
#view-game.endless-battle .combat-player .combat-portrait-frame {
    height: auto;
    min-height: 74px;
    background: transparent;
    overflow: visible;
}
#view-game.endless-battle .combat-player .combat-portrait-frame img {
    max-height: 142px;
    object-fit: contain;
    object-position: center bottom;
}
#view-game.endless-battle .combat-player {
    background: transparent;
    border: none;
    box-shadow: none;
}
#view-game.endless-battle .combat-player .combat-actor-meta {
    display: none;
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* ----- Stage 4 & Familiars & Boss UI ----- */
.familiar-img {
    position: absolute;
    width: clamp(70px, 10dvh, 100px);
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    z-index: 10;
    animation: familiarFloat 3.5s ease-in-out infinite;
    mix-blend-mode: multiply; /* If white background */
    border-radius: 50%;
}
#game-player-familiar {
    right: -30px;
    top: 30px;
    width: 60px;
}
@keyframes familiarFloat {
    0%, 100% { transform: translateY(-50%) scale(1); }
    50% { transform: translateY(calc(-50% - 15px)) scale(1.05); }
}

#view-game.endless-battle.void-battle {
    background: linear-gradient(180deg, #100622, #05010a 60%, #000000);
}
#view-game.endless-battle.void-battle::before {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at center, rgba(138, 43, 226, 0.1) 0%, transparent 70%);
    pointer-events: none;
}

#view-game.endless-battle .combat-enemy.boss-enemy .combat-portrait-frame img {
    max-height: clamp(140px, 22dvh, 190px);
    filter: drop-shadow(0 0 35px rgba(255, 30, 60, 0.8)) !important;
}
#view-game.endless-battle .combat-enemy.boss-enemy .combat-actor-meta {
    background: rgba(80, 10, 20, 0.8);
    border: 1px solid rgba(255, 100, 100, 0.5);
    color: #ffcccc;
}

/* ----- 100-Point Version Enhancements ----- */

/* Hub Immersive Background */
#view-hub {
    background: url('../assets/bg/hub_bg.png') no-repeat center center;
    background-size: cover;
    transition: background 1s ease-in-out;
}

#view-hub::after {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at center, transparent 0%, rgba(13, 5, 25, 0.6) 100%);
    pointer-events: none;
    z-index: 1;
}

#view-hub .hub-content {
    z-index: 2;
}

/* Master Aura for Stage 4 */
.hero-img.stage4-aura {
    filter: drop-shadow(0 0 20px rgba(255, 215, 0, 0.7)) drop-shadow(0 0 40px rgba(138, 43, 226, 0.4));
    animation: masterPulse 3s ease-in-out infinite alternate;
}

@keyframes masterPulse {
    0% { filter: drop-shadow(0 0 15px rgba(255, 215, 0, 0.5)) brightness(1); transform: scale(1); }
    100% { filter: drop-shadow(0 0 30px rgba(255, 215, 0, 0.9)) brightness(1.2); transform: scale(1.02); }
}

/* Bestiary Styles */
.bestiary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
    gap: 12px;
    margin-top: 20px;
}

.monster-card {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    padding: 8px;
    text-align: center;
    border: 1px solid rgba(255, 255, 255, 0.1);
    transition: all 0.3s ease;
    filter: grayscale(100%) opacity(0.5);
}

.monster-card.unlocked {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(169, 222, 249, 0.4);
    filter: grayscale(0%) opacity(1);
}

.monster-card img {
    width: 100%;
    aspect-ratio: 1;
    object-fit: contain;
    margin-bottom: 4px;
}

.monster-card span {
    font-size: 10px;
    color: #fff;
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Star Rating in Mission Grid */
.level-card .star-rating {
    display: flex;
    gap: 2px;
    margin-top: 4px;
}

.level-card .star-rating img {
    width: 12px;
    height: 12px;
    filter: grayscale(1);
    opacity: 0.3;
}

.level-card .star-rating img.earned {
    filter: grayscale(0);
    opacity: 1;
}

/* Familiar System */
.hub-panel[data-panel="familiar"] {
    display: none;
    flex-direction: column;
    height: 100%;
}
.hub-panel[data-panel="familiar"].active {
    display: flex;
}

.familiar-container {
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    height: 100%;
    overflow-y: auto;
    padding-bottom: 100px;
}

.gacha-section {
    background: linear-gradient(135deg, rgba(83, 76, 122, 0.4), rgba(45, 36, 58, 0.6));
    border-radius: 24px;
    padding: 24px;
    text-align: center;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: var(--shadow-soft);
    position: relative;
    overflow: hidden;
}

.gacha-section::before {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at 50% 50%, rgba(123, 75, 255, 0.1), transparent 70%);
    pointer-events: none;
}

.gacha-price {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-size: 20px;
    font-weight: 900;
    color: #ffd700;
    margin-bottom: 16px;
}

.gacha-btn {
    width: 100%;
    max-width: 280px;
    padding: 16px;
    font-size: 18px;
    font-weight: 900;
    background: var(--color-primary);
    color: white;
    border: none;
    border-radius: 50px;
    box-shadow: 0 10px 20px rgba(0,0,0,0.2);
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.gacha-btn:active {
    transform: scale(0.95);
}

.gacha-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.pet-inventory {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
    gap: 12px;
}

.pet-card {
    background: rgba(255, 255, 255, 0.08);
    border-radius: 16px;
    padding: 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    border: 2px solid transparent;
    transition: all 0.3s ease;
    cursor: pointer;
    position: relative;
    filter: grayscale(1);
    opacity: 0.6;
}

.pet-card.owned {
    filter: none;
    opacity: 1;
    background: rgba(255, 255, 255, 0.15);
}

.pet-card.active {
    border-color: var(--color-primary);
    background: rgba(123, 75, 255, 0.2);
    box-shadow: 0 0 15px rgba(123, 75, 255, 0.3);
}

.pet-card.active::after {
    content: 'E';
    position: absolute;
    top: -5px;
    right: -5px;
    background: var(--color-primary);
    color: white;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    font-size: 12px;
    font-weight: 900;
    display: flex;
    align-items: center;
    justify-content: center;
}

.pet-icon-wrap {
    width: 60px;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    border-radius: 12px;
}

.pet-icon {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.pet-name {
    font-size: 11px;
    font-weight: 700;
    color: var(--color-text-main);
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    width: 100%;
}

/* Battle & Hub Pet Positioning */
.pet-companion {
    position: absolute;
    width: 60px;
    height: 60px;
    pointer-events: none;
    z-index: 10;
    animation: petFloat 3s ease-in-out infinite;
    display: none;
}

.pet-companion.active {
    display: block;
}

@keyframes petFloat {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

.hero-portrait-wrap .pet-companion {
    top: 0;
    right: -40px;
    width: 80px;
    height: 80px;
}

.combat-player .pet-companion {
    top: -40px;
    left: 20px;
}

/* Battle Pet Positioning - Dynamic based on Mode */
.battle-pet {
    position: absolute !important;
    width: 90px;
    height: 90px;
    z-index: 100; /* Lower than headers (3000) but above content */
    filter: drop-shadow(0 0 15px rgba(255,255,255,0.4));
    transition: all 0.8s cubic-bezier(0.34, 1.56, 0.64, 1);
    display: none;
    pointer-events: none; /* Ensure it doesn't block clicks */
}

.battle-pet.active {
    display: block;
    animation: battlePetFloat 4s ease-in-out infinite !important;
}

/* Story/Daily Mode Position: Right of the Mission Info - Enlarged 1.5x */
#view-game:not(.endless-battle) .battle-pet {
    top: 150px;
    right: 20px;
    width: 140px;
    height: 140px;
}

/* Endless Mode Position: Right side area (Above Cauldron) */
#view-game.endless-battle .battle-pet {
    top: auto !important;
    bottom: 220px !important;
    right: 15px !important;
    width: 110px;
    height: 110px;
}

@keyframes battlePetFloat {
    0%, 100% { transform: translateY(0) rotate(-5deg); }
    50% { transform: translateY(-15px) rotate(5deg); }
}

/* Gacha Animation - More Dramatic & Contained */
.gacha-overlay {
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at 50% 40%, rgba(45, 36, 58, 0.98), #000);
    z-index: 5000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.5s ease;
    backdrop-filter: blur(10px);
    overflow: hidden;
}


.gacha-overlay.active {
    opacity: 1;
    pointer-events: all;
}

.gacha-burst {
    position: absolute;
    width: 300px;
    height: 300px;
    background: radial-gradient(circle, #fff, var(--color-primary), transparent 70%);
    border-radius: 50%;
    transform: scale(0);
}

.gacha-overlay.active .gacha-burst {
    animation: burst 1.5s ease-out forwards;
}

@keyframes burst {
    0% { transform: scale(0); opacity: 1; }
    50% { transform: scale(1.5); opacity: 1; }
    100% { transform: scale(2); opacity: 0; }
}

.gacha-result-wrap {
    text-align: center;
    transform: scale(0.5);
    opacity: 0;
    transition: all 0.8s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.gacha-flash {
    position: absolute;
    inset: 0;
    background: white;
    z-index: 2001;
    opacity: 0;
    pointer-events: none;
}

.gacha-overlay.reveal .gacha-flash {
    animation: flashEffect 1.2s ease-out forwards;
}

@keyframes flashEffect {
    0% { opacity: 0; }
    10% { opacity: 1; }
    100% { opacity: 0; }
}

.gacha-overlay.reveal .gacha-result-wrap {
    animation: bounceIn 1s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
    opacity: 1;
}

@keyframes bounceIn {
    0% { transform: scale(0.2); opacity: 0; }
    60% { transform: scale(1.0); opacity: 1; }
    100% { transform: scale(0.8); opacity: 1; }
}

.gacha-result-wrap img {
    width: 180px;
    height: 180px;
    object-fit: contain;
    filter: drop-shadow(0 0 30px rgba(255,255,255,0.8)) drop-shadow(0 0 10px var(--color-primary));
    animation: petEntrance 1s ease-out;
}

@keyframes petEntrance {
    from { filter: brightness(0) blur(20px); }
    to { filter: brightness(1) blur(0); }
}



.gacha-result-name {
    color: white;
    font-size: 24px;
    font-weight: 900;
    margin-top: 16px;
    text-shadow: 0 0 10px var(--color-primary);
}

.btn-gacha-close {
    margin-top: 40px;
    background: white;
    color: black;
    padding: 12px 32px;
    border-radius: 30px;
    font-weight: 900;
    border: none;
    cursor: pointer;
}

