/* ==================== 0. CSS Variables & Font ==================== */
@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+KR:wght@400;500;700;900&display=swap');

:root {
    /* Colors */
    --c-bg: #0a0a14;
    --c-surface: rgba(22, 24, 40, 0.95);
    --c-surface-light: rgba(255, 255, 255, 0.06);
    --c-surface-dark: rgba(0, 0, 0, 0.4);
    --c-border: rgba(255, 255, 255, 0.08);
    --c-border-light: rgba(255, 255, 255, 0.12);

    --c-primary: #8b5cf6;
    --c-primary-dim: rgba(139, 92, 246, 0.3);
    --c-primary-glow: rgba(139, 92, 246, 0.4);
    --c-accent: #a78bfa;

    --c-gold: #fbbf24;
    --c-red: #ef4444;
    --c-red-dark: #991b1b;
    --c-green: #10b981;
    --c-green-dark: #047857;
    --c-blue: #60a5fa;
    --c-blue-solid: #3b82f6;
    --c-blue-dark: #1d4ed8;
    --c-cyan: #06b6d4;
    --c-cyan-light: #22d3ee;
    --c-purple: #8b5cf6;
    --c-purple-dark: #5b21b6;
    --c-amber: #a16207;
    --c-amber-dark: #713f12;
    --c-gray: #4b5563;
    --c-gray-dark: #374151;
    --c-text: #f0f0f0;
    --c-text-dim: #9ca3af;
    --c-text-muted: #6b7280;

    /* Typography */
    --font: 'Noto Sans KR', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;

    /* Spacing */
    --gap: 12px;
    --radius: 12px;
    --radius-sm: 8px;
    --radius-full: 9999px;

    /* Safe area */
    --sat: env(safe-area-inset-top, 0px);
    --sab: env(safe-area-inset-bottom, 0px);
    --sal: env(safe-area-inset-left, 0px);
    --sar: env(safe-area-inset-right, 0px);
}

/* ==================== 1. Reset & Base ==================== */
html { height: 100%; }
* { margin: 0; padding: 0; box-sizing: border-box; }

/* Scrollbar */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--c-border-light); border-radius: var(--radius-full); }
::-webkit-scrollbar-thumb:hover { background: var(--c-text-muted); }

/* Selection */
::selection { background: var(--c-primary-dim); color: var(--c-text); }

/* Focus visible */
:focus-visible { outline: 2px solid var(--c-primary); outline-offset: 2px; }
button:focus-visible { outline: 2px solid var(--c-accent); outline-offset: 2px; }

body {
    font-family: var(--font);
    background-color: var(--c-bg);
    color: var(--c-text);
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100%;
    overflow: hidden;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
    padding: var(--sat) var(--sar) var(--sab) var(--sal);
}

/* ==================== 2. Start Menu ==================== */
#start-menu {
    text-align: center;
    padding: 20px;
    animation: fadeIn 0.6s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

#volume-controls {
    position: fixed;
    top: max(16px, var(--sat));
    right: max(16px, var(--sar));
    display: flex;
    gap: 8px;
    z-index: 101;
}

.volume-btn {
    background: var(--c-surface-light);
    border: 1px solid var(--c-border-light);
    border-radius: 50%;
    width: 44px;
    height: 44px;
    font-size: 20px;
    padding: 0;
    box-shadow: none;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.volume-btn.off {
    opacity: 0.4;
    text-decoration: line-through 3px var(--c-red);
}

/* Title Area */
.title-area {
    margin-bottom: 8px;
}

.title-icon {
    font-size: clamp(40px, 10vw, 64px);
    margin-bottom: 4px;
    animation: titlePulse 3s ease-in-out infinite;
    filter: drop-shadow(0 0 12px var(--c-primary-glow));
}

@keyframes titlePulse {
    0%, 100% { transform: scale(1); filter: drop-shadow(0 0 12px var(--c-primary-glow)); }
    50% { transform: scale(1.08); filter: drop-shadow(0 0 20px var(--c-primary-glow)); }
}

.game-title {
    font-size: clamp(36px, 8vw, 56px);
    font-weight: 900;
    color: var(--c-accent);
    text-shadow: 0 0 20px var(--c-primary-glow), 0 2px 4px rgba(0,0,0,0.5);
    margin-bottom: 4px;
    letter-spacing: 6px;
}

.game-subtitle {
    font-size: clamp(13px, 3vw, 16px);
    color: var(--c-text-dim);
    font-weight: 400;
    letter-spacing: 3px;
    margin-bottom: 0;
}

.version-tag {
    margin-top: 16px;
    font-size: 11px;
    color: var(--c-text-muted);
    letter-spacing: 1px;
}

#start-menu div {
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: center;
}

.start-btn {
    padding: 14px 24px;
    font-size: 15px;
    width: 260px;
    background: var(--c-surface);
    border: 1px solid var(--c-border-light);
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
    position: relative;
    transition: background 0.2s, transform 0.1s, border-color 0.2s;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    text-align: left;
}

.start-btn:active {
    background: var(--c-surface-light);
    transform: scale(0.97);
}

.start-btn--primary {
    background: var(--c-primary-dim);
    border-color: var(--c-primary);
}

.new-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: var(--c-red);
    color: white;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    font-size: 11px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 0 8px rgba(239, 68, 68, 0.6);
    line-height: 1;
}

.welcome-msg {
    font-size: 17px;
    color: var(--c-gold);
    margin-bottom: 4px;
    font-weight: 500;
}

/* ==================== 3. Game Layout ==================== */
#game-wrapper {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    padding: var(--sat) var(--sar) var(--sab) var(--sal);
}

.game-container {
    width: 100%;
    height: 100%;
    max-width: 1200px;
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: var(--gap);
}

/* Header (home, floor, turn, gold, buffs) */
.header {
    padding-bottom: 8px;
    border-bottom: 1px solid var(--c-border);
    display: flex;
    align-items: center;
    gap: 8px;
}

.header-home-btn {
    background: var(--c-surface-light);
    border: 1px solid var(--c-border-light);
    border-radius: var(--radius-sm);
    width: 36px;
    height: 36px;
    min-height: 36px;
    padding: 0;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    box-shadow: none;
    transition: background 0.15s;
}

.header-home-btn:active {
    background: var(--c-surface-dark);
}

.header-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    flex: 1;
    justify-content: center;
}

.floor-badge {
    background: var(--c-primary);
    padding: 5px 12px;
    border-radius: var(--radius-full);
    font-size: 13px;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    gap: 2px;
    white-space: nowrap;
}

.badge-gray { background: var(--c-gray); }
.badge-gold { background: var(--c-gold); color: #000; }
.badge-red { background: var(--c-red); }
.badge-purple { background: var(--c-purple); }
.badge-dark { background: #111; color: #fff; border: 1px solid rgba(255,255,255,0.3); }
.badge-crown { background: #ca8a04; }

/* ==================== 4. Battle Field ==================== */
.battle-field {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 16px 8px;
    flex: 1;
    gap: 24px;
    position: relative;
    min-height: 0;
    background: radial-gradient(ellipse at center, rgba(139, 92, 246, 0.04) 0%, transparent 70%);
    border: 1px solid var(--c-border);
    border-radius: var(--radius-sm);
}

.vs-divider {
    font-size: 24px;
    color: var(--c-text-muted);
    opacity: 0.4;
    text-shadow: 0 0 12px var(--c-primary-glow);
    flex-shrink: 0;
    user-select: none;
    pointer-events: none;
}

#monster-area {
    display: flex;
    gap: 16px;
    align-items: flex-end;
}

.monster-wrapper {
    position: relative;
    transition: transform 0.2s ease;
    cursor: pointer;
}
.monster-wrapper.targeted { transform: translateY(-8px); }
.monster-wrapper.dead { cursor: not-allowed; }

.target-indicator {
    position: absolute;
    top: -36px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 24px;
    color: var(--c-red);
    display: none;
}
@keyframes bounce-indicator {
    0%, 100% { transform: translateX(-50%) translateY(0); }
    50% { transform: translateX(-50%) translateY(-8px); }
}

.monster-wrapper.targeted .target-indicator {
    display: block;
    animation: bounce-indicator 0.8s ease-in-out infinite;
}
.monster-wrapper.dead .character { opacity: 0.35; filter: grayscale(1); }

/* ==================== 5. Character & UI Elements ==================== */
.character {
    text-align: center;
    position: relative;
    transition: transform 0.15s ease-out, opacity 0.5s, filter 0.5s;
}

.emoji {
    font-size: 100px;
    filter: drop-shadow(0 0 8px rgba(255,255,255,0.3));
    transition: 0.2s;
    line-height: 1.1;
}

.name {
    font-size: 16px;
    margin-top: 6px;
    color: var(--c-text-dim);
    font-weight: 700;
}

.hp-bar-bg {
    width: 120px;
    height: 14px;
    background: rgba(255,255,255,0.08);
    border-radius: var(--radius-full);
    margin: 6px auto;
    overflow: hidden;
}

.hp-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, #dc2626, var(--c-red));
    width: 100%;
    transition: width 0.3s ease;
    border-radius: var(--radius-full);
}

.hp-text {
    font-size: 13px;
    color: var(--c-text-muted);
    margin-top: 2px;
    font-weight: 500;
}

/* Player character effects */
@keyframes idle-float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-4px); }
}

#player-character {
    animation: idle-float 3s ease-in-out infinite;
}

#player-character .emoji {
    filter: drop-shadow(0 0 12px rgba(96, 165, 250, 0.3));
}

.character .name {
    background: rgba(0, 0, 0, 0.3);
    padding: 2px 10px;
    border-radius: var(--radius-full);
    display: inline-block;
}

/* ==================== 6. Animations ==================== */
@keyframes shake {
    0% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    50% { transform: translateX(5px); }
    75% { transform: translateX(-5px); }
    100% { transform: translateX(0); }
}
.hit { animation: shake 0.3s; color: red !important; }

@keyframes stun-effect {
    0%, 100% { transform: rotate(0deg); }
    25% { transform: rotate(-5deg); }
    75% { transform: rotate(5deg); }
}
.stunned .emoji { animation: stun-effect 0.5s infinite; }
.stunned .target-indicator { display: none; }

.floating-text {
    position: absolute;
    font-size: 24px;
    font-weight: 700;
    text-shadow: 1px 1px 3px rgba(0,0,0,0.8);
    pointer-events: none;
    animation: float-up-and-fade 1.2s ease-out forwards;
    z-index: 100;
    white-space: nowrap;
}

@keyframes float-up-and-fade {
    0% { transform: translateY(0) scale(1); opacity: 1; }
    15% { transform: translateY(-10px) scale(1.15); opacity: 1; }
    100% { transform: translateY(-60px) scale(0.9); opacity: 0; }
}

.floating-text.damage { color: #fff; }
.floating-text.crit { color: #ffdd44; font-size: 32px; font-weight: 900; }
.floating-text.black-flash { color: red; font-size: 36px; font-weight: 900; text-shadow: 0 0 5px black, 0 0 10px red; }
.floating-text.miss { color: #777; font-size: 20px; }
.floating-text.stun { color: #fde047; font-size: 32px; font-weight: 700; }
.floating-text.heal { color: #22c55e; font-size: 28px; }
.floating-text.mp-heal { color: var(--c-blue); font-size: 28px; }
.floating-text.buff { color: #a855f7; font-size: 24px; }
.floating-text.level-up { color: var(--c-gold); font-size: 42px; font-weight: 900; text-shadow: 0 0 5px black, 0 0 10px var(--c-gold); }

.stun-indicator {
    position: absolute;
    top: -28px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 26px;
    display: none;
}

@keyframes stun-spin {
    from { transform: translateX(-50%) rotate(0deg); }
    to { transform: translateX(-50%) rotate(360deg); }
}

.stun-indicator.visible {
    display: block;
    animation: stun-spin 1.5s linear infinite;
}

/* ==================== 7. Bottom UI (Log, Bars, Controls) ==================== */
.log-box {
    background: var(--c-surface-dark);
    height: 120px;
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    overflow-y: auto;
    font-size: 13px;
    line-height: 1.6;
    border: 1px solid var(--c-border);
    box-shadow: inset 3px 0 0 var(--c-primary-dim);
    overscroll-behavior: contain;
    touch-action: pan-y;
    -webkit-overflow-scrolling: touch;
}
.log-msg { margin-bottom: 3px; }
.log-player { color: var(--c-blue); }
.log-monster { color: #f87171; }
.log-system { color: var(--c-gold); font-weight: 700; }

/* MP Bar */
.mp-bar-container {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: var(--c-surface-dark);
    border-radius: var(--radius-sm);
    border: 1px solid var(--c-border);
}

.mp-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, #3b82f6, var(--c-blue));
    width: 100%;
    transition: width 0.5s ease;
    border-radius: var(--radius-full);
}

/* XP Bar */
.xp-bar-container {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: var(--c-surface-dark);
    border-radius: var(--radius-sm);
    border: 1px solid var(--c-border);
}

.level-badge {
    font-size: 13px;
    font-weight: 700;
    color: var(--c-gold);
    white-space: nowrap;
}

.xp-bar-bg {
    flex-grow: 1;
    height: 14px;
    background: rgba(255,255,255,0.08);
    border-radius: var(--radius-full);
    overflow: hidden;
}

.xp-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, #7c3aed, var(--c-purple));
    width: 0%;
    transition: width 0.5s ease;
    border-radius: var(--radius-full);
}

.xp-text {
    font-size: 13px;
    color: var(--c-text-dim);
    min-width: 120px;
    text-align: right;
    white-space: nowrap;
}

/* Controls */
.controls {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

button {
    padding: 16px;
    border: none;
    border-radius: var(--radius);
    font-weight: 700;
    font-family: var(--font);
    cursor: pointer;
    transition: transform 0.1s, filter 0.1s;
    color: white;
    font-size: 16px;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    min-height: 48px;
}
button:active { transform: scale(0.96); }
button:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

.btn-inventory { background: var(--c-blue-solid); box-shadow: 0 3px 0 var(--c-blue-dark); }
.btn-attack { background: var(--c-red); box-shadow: 0 3px 0 var(--c-red-dark); }
.btn-buff { background: var(--c-purple); box-shadow: 0 3px 0 var(--c-purple-dark); }
.btn-heal { background: var(--c-green); box-shadow: 0 3px 0 var(--c-green-dark); }
.btn-armor { background: var(--c-amber); box-shadow: 0 3px 0 var(--c-amber-dark); }
.btn-defend { background: var(--c-cyan); box-shadow: 0 3px 0 #0891b2; }
.btn-defend-active { background: var(--c-cyan-light); box-shadow: 0 3px 0 var(--c-cyan); }

.skill-desc {
    font-size: 12px;
    font-weight: 400;
    color: rgba(255,255,255,0.7);
    display: block;
    margin-top: 2px;
}

.btn-back { grid-column: 1 / -1; }

/* ==================== 8. Game Modals (In-game overlays) ==================== */

/* Level Up */
#levelup-modal {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.85);
    display: none;
    justify-content: center; align-items: center; flex-direction: column; text-align: center;
    z-index: 10;
}

.levelup-text {
    font-size: 24px;
    color: var(--c-gold);
    margin-bottom: 16px;
    font-weight: 700;
}

@keyframes level-up-effect {
    0% { transform: scale(1) translateY(20px); opacity: 0; }
    50% { transform: scale(1.5) rotate(-5deg); opacity: 1; text-shadow: 0 0 20px #fff, 0 0 30px var(--c-gold); }
    100% { transform: scale(1.2); opacity: 1; }
}
.levelup-text.animated { animation: level-up-effect 0.8s ease-out forwards; }

/* Shop Modal */
#shop-modal {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.9);
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding: max(3vh, var(--sat)) 12px;
    z-index: 20;
    overflow-y: auto;
}

.shop-title {
    font-size: 28px;
    color: var(--c-gold);
    margin-bottom: 16px;
    font-weight: 700;
}

.shop-container {
    display: flex;
    flex-direction: column;
    gap: 16px;
    width: 100%;
    max-width: 1200px;
    max-height: 78vh;
    overflow-y: auto;
    padding-bottom: 20px;
}

.shop-row {
    display: flex;
    gap: 12px;
    width: 100%;
}

.shop-section {
    flex: 1;
    background: var(--c-surface-light);
    padding: 12px;
    margin-bottom: 8px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--c-border);
}

.shop-section h3 {
    text-align: center;
    color: var(--c-text-dim);
    margin-bottom: 12px;
    font-size: 16px;
    font-weight: 700;
    border-bottom: 1px solid var(--c-border);
    padding-bottom: 8px;
}

.shop-items {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.shop-btn {
    background: var(--c-gray);
    padding: 12px;
    font-size: 14px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    border: 1px solid transparent;
    transition: background 0.15s, border-color 0.15s;
}
.shop-btn span { color: var(--c-gold); }
.shop-btn .armor-emoji { font-size: 28px; line-height: 1; }
.shop-btn:hover, .shop-btn:active { background: var(--c-text-muted); border-color: var(--c-border-light); }

/* Old Inventory Modal (unused) */
#inventory-modal {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.92);
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 20;
}

.inventory-list {
    width: 90%;
    max-width: 500px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.inventory-item {
    background: var(--c-gray-dark);
    padding: 14px;
    border-radius: var(--radius-sm);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    border: 1px solid var(--c-border);
}

.item-info { font-size: 15px; }

.btn-use {
    padding: 10px 20px;
    font-size: 14px;
    background: var(--c-green);
    box-shadow: 0 3px 0 var(--c-green-dark);
    white-space: nowrap;
    flex-shrink: 0;
}

.item-passive-effect {
    color: #f59e0b;
    font-weight: 700;
    font-size: 14px;
    border: 1px solid #f59e0b;
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    white-space: nowrap;
}

/* Potion Modal */
#item-select-modal {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.9);
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding: max(3vh, var(--sat)) 12px;
    z-index: 15;
    overflow-y: auto;
}

.potion-container {
    display: flex;
    gap: 12px;
    width: 100%;
    max-width: 1200px;
    margin-bottom: 16px;
}

.potion-section {
    flex: 1;
    background: var(--c-surface-dark);
    padding: 14px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--c-border);
}

.potion-section h3 {
    text-align: center;
    color: var(--c-text-dim);
    margin-bottom: 12px;
    font-size: 15px;
    font-weight: 700;
    border-bottom: 1px solid var(--c-border);
    padding-bottom: 8px;
}

.potion-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 50vh;
    overflow-y: auto;
}

#item-select-modal .inventory-item { padding: 10px; }
#item-select-modal .item-info { font-size: 14px; }
#item-select-modal .btn-use { padding: 8px 14px; font-size: 13px; }

/* Equipment & Stat Modal */
#equipment-modal {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.92);
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding: max(3vh, var(--sat)) 16px;
    z-index: 20;
    overflow-y: auto;
}

#current-equipment-display {
    background: var(--c-surface-dark);
    padding: 14px;
    border-radius: var(--radius-sm);
    margin-bottom: 16px;
    border: 1px solid var(--c-border);
    text-align: center;
}

.current-equipment-item {
    font-size: 15px;
    color: var(--c-gold);
}
.current-equipment-item:not(:last-child) { margin-bottom: 8px; }

.equipment-container {
    display: flex;
    gap: 12px;
    width: 100%;
}

.equipment-section {
    flex: 1;
    background: var(--c-surface-light);
    padding: 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--c-border);
}

.equipment-section h3 {
    text-align: center;
    color: var(--c-text-dim);
    margin-bottom: 12px;
    font-size: 16px;
    font-weight: 700;
    border-bottom: 1px solid var(--c-border);
    padding-bottom: 8px;
}

.equipment-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 40vh;
    overflow-y: auto;
}

.management-container {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    width: 100%;
}

.management-section {
    background: var(--c-surface-dark);
    padding: 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--c-border);
    display: flex;
    flex-direction: column;
}

/* Stat Distribution */
#stat-points-display {
    font-size: 16px;
    margin-bottom: 12px;
    text-align: center;
    font-weight: 500;
}
#stat-points-display span {
    color: var(--c-gold);
    font-size: 20px;
    font-weight: 700;
}

.stat-up-list {
    width: 100%;
    gap: 8px;
    margin-bottom: 16px;
}

.stat-up-item {
    background: var(--c-gray-dark);
    padding: 12px;
    border-radius: var(--radius-sm);
    display: flex;
    justify-content: space-between;
    align-items: center;
    text-align: left;
    border: 1px solid var(--c-border);
}

.stat-info h4 { font-size: 15px; margin-bottom: 3px; font-weight: 700; }
.stat-info p { font-size: 12px; color: var(--c-text-dim); }
#stat-current-values { text-align: center; margin-bottom: 12px; font-size: 14px; color: var(--c-text-dim); }

/* Black Flash Overlay */
#black-flash-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background-color: black;
    opacity: 0;
    z-index: 9999;
    pointer-events: none;
}

@keyframes black-flash-animation {
    0% { opacity: 0.9; background-color: red; }
    50% { opacity: 1; background-color: black; }
    100% { opacity: 0; }
}

/* ==================== 9. System Modals (Fixed overlay) ==================== */
.modal {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 100;
    opacity: 0;
    transition: opacity 0.3s ease;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}
.modal.visible { opacity: 1; }

/* Manual */
#manual-content {
    display: block;
    white-space: normal;
    font-family: var(--font);
    background: #111;
    padding: 16px 20px;
    border-radius: var(--radius-sm);
    text-align: left;
}
#manual-content h1, #manual-content h2, #manual-content h3 {
    color: var(--c-accent);
    margin-top: 18px;
    margin-bottom: 8px;
    border-bottom: 1px solid var(--c-border);
    padding-bottom: 4px;
}
#manual-content h1 { font-size: 1.6em; }
#manual-content h2 { font-size: 1.3em; }
#manual-content h3 { font-size: 1.1em; }
#manual-content p { line-height: 1.7; margin-bottom: 8px; color: #ddd; }
#manual-content blockquote { border-left: 3px solid var(--c-primary); padding-left: 12px; margin: 12px 0; color: #bbb; font-style: italic; }
#manual-content ul { list-style-position: inside; padding-left: 0; margin: 8px 0; }
#manual-content li { margin-bottom: 6px; line-height: 1.6; color: #ddd; }
#manual-content code { background-color: #222; color: #f59e0b; padding: 2px 5px; border-radius: 4px; font-family: monospace; }
#manual-content strong { color: var(--c-gold); font-weight: 700; }

/* Scoreboard */
.scoreboard-item {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 8px;
    font-size: 15px;
    border-bottom: 1px solid var(--c-border);
}
.scoreboard-item:last-child { border-bottom: none; }
.scoreboard-item .rank { font-weight: 700; color: var(--c-gold); margin-right: 8px; }
.scoreboard-item .name { color: var(--c-blue); }
.scoreboard-item .score { font-weight: 700; }
.scoreboard-header {
    text-align: center;
    color: var(--c-accent);
    margin: 12px 0 4px 0;
    font-size: 14px;
    font-weight: 500;
}
.scoreboard-item.current-run {
    background: rgba(251, 191, 36, 0.08);
    border: 1px solid var(--c-gold);
    border-radius: var(--radius-sm);
}
.scoreboard-item.top-ranker {
    background: rgba(255, 215, 0, 0.1);
    border: 1px solid #ffd700;
    border-radius: var(--radius-sm);
}
.scoreboard-item.current-user-score { background: rgba(96, 165, 250, 0.08); }
.flag-icon { vertical-align: middle; margin-right: 5px; height: 1em; }

/* Login / Register / Profile / Find Account Modals */
#login-modal,
#register-modal,
#edit-profile-modal,
#find-account-modal {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.75);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 100;
    opacity: 0;
    transition: opacity 0.3s ease;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

#login-modal.visible,
#register-modal.visible,
#edit-profile-modal.visible,
#find-account-modal.visible {
    opacity: 1;
}

.login-content {
    background: var(--c-surface);
    border: 1px solid var(--c-primary-dim);
    border-radius: 16px;
    padding: 24px;
    width: 90%;
    max-width: 380px;
    text-align: center;
    box-shadow: 0 8px 32px rgba(0,0,0,0.5), 0 0 0 1px var(--c-border);
    transform: scale(0.9);
    transition: transform 0.3s cubic-bezier(0.18, 0.89, 0.32, 1.28);
}

#login-modal.visible .login-content,
#register-modal.visible .login-content,
#edit-profile-modal.visible .login-content,
#find-account-modal.visible .login-content {
    transform: scale(1);
}

#login-form,
#register-form,
#find-account-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 16px;
}

#edit-profile-form .form-group {
    display: flex;
    align-items: center;
    gap: 10px;
}

#edit-profile-form .form-group label {
    flex-basis: 70px;
    flex-shrink: 0;
    text-align: left;
    font-size: 14px;
    color: var(--c-text-dim);
    font-weight: 700;
}

#login-form input,
#register-form input,
#edit-profile-form input,
#find-account-form input,
#login-form select,
#register-form select,
#edit-profile-form select {
    padding: 12px;
    font-size: 15px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--c-border-light);
    background: rgba(0,0,0,0.3);
    color: var(--c-text);
    font-family: var(--font);
    transition: border-color 0.2s;
}

#login-form input:focus,
#register-form input:focus,
#edit-profile-form input:focus,
#find-account-form input:focus {
    outline: none;
    border-color: var(--c-primary);
}

#login-form input[type="date"],
#register-form input[type="date"],
#edit-profile-form input[type="date"],
#find-account-form input[type="date"] { color-scheme: dark; }

.login-buttons { display: flex; gap: 8px; }
.login-buttons button { flex: 1; padding: 12px; font-size: 15px; }

.switch-auth-msg { margin-top: 12px; font-size: 13px; color: var(--c-text-dim); }
.switch-auth-msg a { color: var(--c-accent); text-decoration: none; font-weight: 700; cursor: pointer; }
.switch-auth-msg a:hover { text-decoration: underline; }

#find-account-result {
    display: none;
    margin-top: 12px;
    padding: 12px;
    border-radius: var(--radius-sm);
    background: rgba(0,0,0,0.2);
    font-weight: 700;
    line-height: 1.5;
    word-break: break-all;
}

/* Scoreboard Modal */
#scoreboard-modal {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.75);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 100;
    opacity: 0;
    transition: opacity 0.3s ease;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}
#scoreboard-modal.visible { opacity: 1; }

.scoreboard-content {
    background: var(--c-surface);
    border: 1px solid var(--c-primary-dim);
    border-radius: 16px;
    padding: 24px;
    width: 90%;
    max-width: 480px;
    text-align: center;
    box-shadow: 0 8px 32px rgba(0,0,0,0.5);
    transform: scale(0.9);
    transition: transform 0.3s cubic-bezier(0.18, 0.89, 0.32, 1.28);
}
#scoreboard-modal.visible .scoreboard-content { transform: scale(1); }

#scoreboard-list {
    max-height: 60vh;
    overflow-y: auto;
    margin-top: 16px;
    background: var(--c-surface-dark);
    padding: 12px;
    border-radius: var(--radius-sm);
}

.modal-close-btn {
    margin-top: 16px;
    background: var(--c-gray);
    box-shadow: 0 3px 0 var(--c-gray-dark);
    padding: 12px 28px;
    font-size: 15px;
}

/* Notice Modal */
#notice-modal {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.75);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 100;
    opacity: 0;
    transition: opacity 0.3s ease;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}
#notice-modal.visible { opacity: 1; }

.notice-content {
    background: var(--c-surface);
    border: 1px solid var(--c-primary-dim);
    border-radius: 16px;
    padding: 24px;
    width: 90%;
    max-width: 560px;
    text-align: center;
    box-shadow: 0 8px 32px rgba(0,0,0,0.5);
    transform: scale(0.9);
    transition: transform 0.3s cubic-bezier(0.18, 0.89, 0.32, 1.28);
}
#notice-modal.visible .notice-content { transform: scale(1); }

#notice-list {
    max-height: 60vh;
    overflow-y: auto;
    margin-top: 16px;
    background: var(--c-surface-dark);
    padding: 10px;
    border-radius: var(--radius-sm);
    text-align: left;
}

.notice-item {
    padding: 12px;
    border-bottom: 1px solid var(--c-border);
    transition: background 0.2s;
    cursor: pointer;
    border-radius: var(--radius-sm);
}
.notice-item:last-child { border-bottom: none; }
.notice-item:hover, .notice-item:active { background: var(--c-surface-light); }
.notice-item.active { background: rgba(255, 255, 255, 0.08); }

.notice-details {
    display: none;
    padding: 12px;
    margin-top: 12px;
    background: var(--c-surface-dark);
    border-radius: var(--radius-sm);
    border-top: 1px solid var(--c-border);
    color: var(--c-text-dim);
    line-height: 1.7;
    white-space: pre-wrap;
    font-size: 13px;
}
.notice-item-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.notice-version { font-weight: 700; color: var(--c-accent); font-size: 1.05em; }
.notice-date { font-size: 0.85em; color: var(--c-text-muted); }
.notice-summary { color: var(--c-text-dim); }

/* Game Over Modal */
#game-over-modal {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.88);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 100;
    opacity: 0;
    transition: opacity 0.5s ease;
}
#game-over-modal.visible { opacity: 1; }

/* ==================== 9.5. Modal Components ==================== */

/* In-game & confirm modal titles */
#game-wrapper .shop-title,
#home-confirm-modal .shop-title { font-size: 24px; }

.shop-title--sm { font-size: 24px; }

/* MP badge color */
.level-badge--mp { color: var(--c-blue); }

/* Level-up subtitle */
.levelup-subtitle { font-size: 24px; color: #ccc; }

/* Shop coins indicator */
.shop-coins-badge {
    background: var(--c-gold);
    color: #000;
    margin-bottom: 15px;
}

/* Shop: My Equipment */
.shop-my-equipment { flex: 1 1 100%; }

.shop-equipment-heading {
    background: var(--c-gray-dark);
    padding: 5px;
    border-radius: 4px;
    text-align: center;
}

.shop-equipment-grid {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 10px;
}

.shop-equipment-col {
    flex: 1;
    min-width: 250px;
}

.shop-equipment-col h4 {
    color: var(--c-gold);
    margin-bottom: 5px;
}

.equipment-list--compact {
    max-height: 15vh;
    overflow-y: auto;
}

/* Button: gray variant */
.btn-gray {
    background: var(--c-text-muted);
    box-shadow: 0 4px 0 var(--c-gray);
}

/* Modal close buttons */
.btn-close-red {
    margin-top: 20px;
    background: var(--c-red);
    box-shadow: 0 4px 0 var(--c-red-dark);
}

.btn-close-gray {
    margin-top: 20px;
    background: var(--c-gray);
    box-shadow: 0 4px 0 var(--c-gray-dark);
}

.btn-close-gray--lg { margin-top: 30px; }

/* Larger form/modal buttons */
.btn-form-submit { padding: 15px; font-size: 18px; }

/* Error messages */
.error-msg {
    color: var(--c-red);
    text-align: center;
    display: none;
}

/* Form dividers */
.form-divider { border-color: #444; margin: 10px 0; }
.form-divider--lg { margin: 20px 0; }

/* Form hint text */
.form-hint { font-size: 14px; color: #ccc; text-align: left; }
.form-hint--mb { margin-bottom: 10px; }

/* Readonly input */
.input-readonly { background: #444; cursor: not-allowed; }

/* Full-width input */
.input-full { width: 100%; margin-top: 10px; }

/* Stat heading */
.stat-heading { text-align: center; margin-bottom: 15px; }

/* Stat action buttons */
.stat-actions {
    display: flex;
    gap: 10px;
    margin-top: auto;
    justify-content: center;
}

/* Adjacent auth switch messages */
.switch-auth-msg + .switch-auth-msg { margin-top: 8px; }

/* Admin link */
#admin-link {
    text-decoration: none;
    align-items: center;
    justify-content: center;
}

/* Game Over */
.game-over-content { max-width: 450px; text-align: center; }
.game-over-title { color: var(--c-red); font-size: 40px; text-shadow: 0 0 10px red; }
.game-over-score { font-size: 24px; margin: 20px 0; }
.game-over-actions { display: flex; gap: 15px; margin-top: 30px; }
.btn-modal-action { flex: 1; font-size: 18px; padding: 15px; }

/* Home Confirm overlay */
#home-confirm-modal {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.8);
    z-index: 5000;
    align-items: center;
    justify-content: center;
}

.confirm-content { max-width: 400px; text-align: center; }
.confirm-msg { margin: 20px 0; font-size: 18px; }
.confirm-hint { color: var(--c-gold); font-size: 14px; }
.confirm-actions { display: flex; gap: 10px; margin-top: 20px; }
.btn-confirm-action { flex: 1; padding: 12px; font-size: 16px; }
.btn-confirm-cancel { background: var(--c-text-muted); box-shadow: 0 3px 0 var(--c-gray); }

/* ==================== 10. Responsive ==================== */

/* Tablet (1200px) */
@media (max-width: 1200px) {
    .emoji { font-size: 90px; }
    .management-container { grid-template-columns: 1fr 1fr; }
    .potion-container { flex-direction: column; }
    .controls { grid-template-columns: repeat(2, 1fr); }
}

/* Tablet/Mobile (992px) */
@media (max-width: 992px) {
    .game-container { padding: 10px; }
    .emoji { font-size: 80px; }
    .hp-bar-bg { width: 100px; }
    .log-box { height: 100px; }
    .shop-row { flex-direction: column; }
    .management-container { grid-template-columns: 1fr; }
}

/* Mobile (768px) */
@media (max-width: 768px) {
    body { padding: 0; }

    .game-container {
        border-radius: 0;
        border: none;
        gap: 6px;
        padding: 8px;
        padding-top: max(8px, var(--sat));
        padding-bottom: max(8px, var(--sab));
    }

    .header {
        gap: 6px;
        padding-bottom: 6px;
    }

    .header-home-btn {
        width: 32px;
        height: 32px;
        min-height: 32px;
        font-size: 16px;
    }

    .header-badges {
        gap: 4px;
    }

    .floor-badge {
        font-size: 11px;
        padding: 3px 8px;
    }

    .battle-field {
        flex-direction: column;
        gap: 6px;
        padding: 4px;
    }

    .vs-divider { display: none; }
    #player-character { animation: none; }

    #monster-area {
        width: 100%;
        overflow-x: auto;
        justify-content: center;
        padding: 4px 8px;
        gap: 12px;
        -webkit-overflow-scrolling: touch;
    }

    .emoji { font-size: 56px; }
    .name { font-size: 13px; margin-top: 3px; }
    .hp-bar-bg { width: 80px; height: 10px; margin: 4px auto; }
    .hp-text { font-size: 11px; margin-top: 1px; }

    .log-box {
        height: 72px;
        font-size: 12px;
        padding: 6px 8px;
        line-height: 1.5;
    }

    .mp-bar-container, .xp-bar-container {
        padding: 6px 8px;
        gap: 6px;
    }
    .xp-bar-bg { height: 12px; }
    .xp-text { font-size: 11px; min-width: 90px; }
    .level-badge { font-size: 11px; }

    .controls {
        grid-template-columns: repeat(3, 1fr);
        gap: 4px;
    }

    .controls button {
        padding: 10px 4px;
        font-size: 14px;
        line-height: 1.3;
        min-height: 44px;
    }

    .floating-text { font-size: 20px; }
    .floating-text.crit { font-size: 28px; }
    .floating-text.level-up { font-size: 36px; }

    .shop-title { font-size: 22px; }

    .potion-container {
        flex-direction: column;
        overflow-y: auto;
        max-height: 65vh;
    }
    .potion-list { max-height: none; overflow-y: visible; }

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

    .current-equipment-item { font-size: 13px; }
    .equipment-section h3 { font-size: 14px; }
    #equipment-modal .item-info { font-size: 14px; }
    #equipment-modal .item-passive-effect { font-size: 12px; padding: 5px 8px; }
    #equipment-modal .btn-use { padding: 8px 10px; font-size: 12px; }

    #stat-points-display { font-size: 14px; }
    #stat-points-display span { font-size: 18px; }
    .stat-info h4 { font-size: 14px; }
    .stat-info p { font-size: 11px; }
    #stat-current-values { font-size: 12px; }

    .scoreboard-header { font-size: 12px; }
    .scoreboard-item { font-size: 13px; padding: 6px; }
    .scoreboard-item .score-time { font-size: 11px !important; }

    #edit-profile-form .form-group {
        flex-direction: column;
        align-items: flex-start;
        gap: 4px;
    }
    #edit-profile-form .form-group label {
        flex-basis: auto;
        font-size: 12px;
    }
    #edit-profile-form p { font-size: 11px !important; }
    #edit-profile-form button { font-size: 15px !important; }

    /* Modal content uniform sizing on mobile */
    .login-content,
    .scoreboard-content,
    .notice-content {
        width: 94%;
        max-width: none;
        border-radius: 14px;
        padding: 20px 16px;
        max-height: 85vh;
        max-height: 85dvh;
        overflow-y: auto;
    }

    #scoreboard-list,
    #notice-list {
        max-height: 55vh;
        max-height: 55dvh;
    }

    /* Modal component responsive */
    .game-over-title { font-size: 32px; }
    .game-over-score { font-size: 20px; }
    .game-over-actions { gap: 10px; margin-top: 20px; }
    .btn-modal-action { font-size: 16px; padding: 12px; }
    .confirm-msg { font-size: 16px; }
    .shop-equipment-col { min-width: 200px; }
    .btn-form-submit { font-size: 16px; padding: 12px; }
}

/* Small Mobile (480px) */
@media (max-width: 480px) {
    .game-title { font-size: 30px; letter-spacing: 2px; }
    .game-subtitle { font-size: 12px; letter-spacing: 2px; }
    .title-icon { font-size: 36px; }
    .start-btn { width: 220px; font-size: 14px; padding: 12px 20px; }

    .emoji { font-size: 44px; }

    .log-box { font-size: 11px; height: 64px; }
    .mp-bar-container, .xp-bar-container { padding: 4px 6px; }
    .xp-bar-bg { height: 10px; }
    .xp-text, .level-badge { font-size: 10px; }

    .controls button {
        padding: 8px 3px;
        font-size: 13px;
    }

    .stat-up-list {
        max-height: 25vh;
        overflow-y: auto;
    }

    .game-over-title { font-size: 28px; }
    .shop-equipment-col { min-width: 0; }
}

/* ==================== Shop Tabs ==================== */
.shop-tabs {
    display: flex;
    gap: 4px;
    padding: 0 8px;
    margin-bottom: 8px;
}

.shop-tab {
    flex: 1;
    padding: 8px 4px;
    border: 1px solid var(--c-border);
    border-radius: var(--radius-sm);
    background: var(--c-surface-light);
    color: var(--c-text-dim);
    font-size: 13px;
    font-family: var(--font);
    cursor: pointer;
    transition: all 0.2s;
}

.shop-tab.active {
    background: var(--c-primary-dim);
    color: var(--c-text);
    border-color: var(--c-primary);
}

.shop-tab-content { display: none; }
.shop-tab-content.active { display: block; }

/* ==================== Mobile Modal Scroll Fix ==================== */
@media (max-width: 768px) {
    #shop-modal {
        max-height: 100vh;
        max-height: 100dvh;
        overflow-y: auto;
        padding-bottom: max(16px, var(--sab));
    }

    #shop-modal .shop-container {
        max-height: 60vh;
        max-height: 60dvh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    #shop-modal .btn-close-red {
        position: sticky;
        bottom: 0;
        z-index: 10;
    }

    #equipment-modal .management-container {
        max-height: 60dvh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    #item-select-modal .potion-container {
        max-height: 55dvh;
        overflow-y: auto;
    }
}

/* ==================== Landscape mobile ==================== */
@media (max-height: 500px) and (orientation: landscape) {
    .game-container {
        display: grid;
        grid-template-columns: 1fr 1fr;
        grid-template-rows: auto 1fr auto;
        gap: 4px;
        padding: 4px;
    }

    .header { grid-column: 1 / -1; }

    .battle-field {
        grid-column: 1;
        grid-row: 2;
        flex-direction: row;
        gap: 10px;
        padding: 4px;
    }

    .log-box {
        grid-column: 2;
        grid-row: 2;
        height: auto;
        max-height: 30vh;
    }

    .mp-bar-container, .xp-bar-container {
        grid-column: 1 / -1;
        padding: 2px 8px;
    }

    .controls {
        grid-column: 1 / -1;
        grid-template-columns: repeat(4, 1fr);
    }

    .emoji { font-size: 40px; }
    .xp-bar-bg { height: 8px; }
}
