:root {
    --bg-color: #0d0a0f;
    --primary-text: #e8e6e3;
    --secondary-text: #a8a29e;
    --border-color: #3f364a;
    --accent-color: #e3d9ff;
    --accent-hover: #ffffff;
    --card-bg: #1d1724;
    --card-bg-light: #2c2536;
    --log-bg: #0d0a0f;
    --hp-color: #fca5a5;
    --hp-bg: #441f1f;
    --mp-color: #93c5fd;
    --mp-bg: #1e3a5f;
    --en-color: #fde047;
    --en-bg: #5f541e;
    --xp-color: #d8b4fe;
    --xp-bg: #3c1e5f;
    --shield-color: rgba(147, 197, 253, 0.4);
    --heal-color: var(--log-heal);
    --font-display: 'Caesar Dressing', cursive;
    --font-title: 'Montserrat', sans-serif;
    --font-body: 'Open Sans', sans-serif;
    --rank-normal: #a8a29e;
    --rank-rare: #60a5fa;
    --rank-elite: #c084fc;
    --rank-epic: #f59e0b;
    --rank-legend: #ef4444;
    --rank-mysterious: #ffffff;
    --item-equipment: #60a5fa;
    --item-consumable: #4ade80;
    --item-material: #a8a29e;
    --item-skilltome: #c084fc;
    --item-petegg: #facc15;
    --item-questitem: #22d3ee;
    --req-met: #4ade80;
    --req-not-met: #f87171;
    --log-gold: #fbbf24;
    --log-damage: #ef4444;
    --log-heal: #4ade80;
    --log-xp: #a855f7;
    --log-quest: #60a5fa;
    --log-levelup: #f59e0b;
    --log-skill: #c084fc;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-body);
    background-color: var(--bg-color);
    color: var(--primary-text);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 1rem;
    -webkit-user-select: none; /* Safari */
    -ms-user-select: none; /* IE 10+ */
    user-select: none; /* Standard syntax */
    overflow: hidden;
}

#background-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: var(--bg-color); /* Fallback color */
    z-index: -1;
    overflow: hidden;
}

#video-background {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transform: translate(-50%, -50%);
    filter: brightness(0.6);
}

#background-container::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(ellipse at center, rgba(0,0,0,0) 50%, rgba(0,0,0,0.8) 100%);
    pointer-events: none;
}


#app {
    width: 100%;
    max-width: 1400px;
    height: 95vh;
    max-height: 850px;
}

#main-menu {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    height: 100%;
    width: 100%;
    padding: 2rem;
}

#main-menu-logo {
    margin-bottom: 4rem;
}


h1, h2 {
    font-family: var(--font-display);
    color: var(--primary-text);
    font-weight: 400; /* Caesar Dressing only has 400 weight */
    letter-spacing: 2px;
}

h3, h4 {
    font-family: var(--font-title);
    color: var(--primary-text);
    font-weight: 600;
}

h1 {
    font-size: 5rem;
}

#main-menu h1 {
    font-size: 7rem;
    color: var(--accent-color);
    animation: menu-title-glow 4s infinite alternate;
}

@keyframes menu-title-glow {
    from { 
        text-shadow: 0 0 10px rgba(227, 217, 255, 0.3), 0 0 20px rgba(227, 217, 255, 0.3), 0 0 30px rgba(124, 58, 237, 0.3);
        letter-spacing: 2px;
    }
    to { 
        text-shadow: 0 0 20px rgba(227, 217, 255, 0.5), 0 0 40px rgba(227, 217, 255, 0.5), 0 0 60px rgba(124, 58, 237, 0.5);
        letter-spacing: 3px;
    }
}


h2 {
    font-size: 2.8rem;
}

h3 {
    font-size: 1.2rem;
}

.tagline {
    font-family: var(--font-body);
    color: var(--secondary-text);
    font-size: 1.2rem;
    max-width: 450px;
    text-align: center;
    margin-top: 0;
    margin-bottom: 1rem;
    font-style: italic;
    opacity: 0.8;
}


#game-container {
    display: flex;
    height: 100%;
    border-radius: 12px;
    overflow: hidden;
    background-color: var(--card-bg);
    border: 1px solid var(--border-color);
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
}

/* Intro Storyline */
#intro-storyline {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: var(--bg-color);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 200;
    opacity: 1;
    transition: opacity 1.5s ease-in-out;
}

#story-text {
    font-family: var(--font-body);
    font-size: 1.5rem;
    color: var(--secondary-text);
    max-width: 600px;
    text-align: center;
    line-height: 1.8;
    opacity: 0;
}

#skip-intro-btn {
    position: absolute;
    bottom: 2rem;
    right: 2rem;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background-color: rgba(29, 23, 36, 0.7);
    border: 1px solid var(--border-color);
    color: var(--secondary-text);
    font-size: 1.2rem;
    cursor: pointer;
    transition: all 0.2s ease;
    opacity: 0;
    animation: fadeIn 0.5s ease forwards;
    padding: 0;
}

#skip-intro-btn:hover {
    background-color: var(--card-bg-light);
    color: var(--primary-text);
    transform: scale(1.1);
}

/* Character Selection Screen */
#character-selection-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
    padding: 2rem;
    width: 100%;
    height: 100%;
    text-align: center;
    background-color: rgba(13, 10, 15, 0.8);
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
}

#character-selection-intro {
    max-width: 600px;
    color: var(--secondary-text);
    line-height: 1.6;
}

#character-selection-cards {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1.5rem;
    width: 100%;
    max-width: 1000px;
    margin: 0 auto;
    overflow-y: auto;
    flex-grow: 1;
    padding: 1rem;
}

.selection-card {
    background-color: var(--card-bg);
    border: 2px solid var(--border-color);
    border-radius: 12px;
    padding: 1.5rem;
    cursor: pointer;
    transition: all 0.2s ease-in-out;
    text-align: center;
    display: flex;
    flex-direction: column;
    position: relative;
}

.selection-card:hover {
    transform: translateY(-5px);
    border-color: var(--accent-hover);
    box-shadow: 0 10px 20px rgba(0,0,0,0.2);
}

.selection-card.selected {
    border-color: var(--accent-color);
    box-shadow: 0 0 20px rgba(227, 217, 255, 0.4);
    transform: translateY(-5px) scale(1.02);
}

.selection-card .character-portrait {
    width: 100px;
    height: 100px;
    margin: 0 auto 1rem auto;
}

.selection-card .character-description {
    font-size: 0.9rem;
    color: var(--secondary-text);
    margin-top: 1rem;
    line-height: 1.5;
    flex-grow: 1;
}

.selection-card .passive-skill {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
    text-align: left;
}

.selection-card .passive-skill h4 {
    font-size: 0.9rem;
    color: var(--accent-hover);
    margin-bottom: 0.25rem;
}

.selection-card .passive-skill p {
    font-size: 0.85rem;
    color: var(--secondary-text);
    margin-top: 0;
    line-height: 1.4;
}

.selection-card .generate-portrait-btn {
    position: absolute;
    top: 1rem;
    right: 1rem;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background-color: rgba(29, 23, 36, 0.7);
    border: 1px solid var(--border-color);
    color: var(--secondary-text);
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0;
}

.selection-card .generate-portrait-btn:hover {
    background-color: var(--card-bg-light);
    color: var(--primary-text);
    transform: scale(1.1);
}

.generate-portrait-btn.loading i {
    animation: spin 1s linear infinite;
}

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

.portrait-loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10;
    border-radius: 50%;
}


/* Character Panel */
#character-panel {
    width: 320px;
    background-color: var(--log-bg);
    padding: 1rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    transition: filter 0.3s ease;
    border-right: 1px solid var(--border-color);
}

#character-panel.disabled {
    filter: grayscale(80%) brightness(0.7);
    pointer-events: none;
}

.character-card {
    background: linear-gradient(145deg, var(--card-bg) 0%, var(--card-bg-light) 100%);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 1rem;
    cursor: pointer;
    transition: border-color 0.2s, box-shadow 0.2s, transform 0.2s;
    display: flex;
    align-items: center;
    gap: 1rem;
    position: relative;
    box-shadow: 0 4px 10px rgba(0,0,0,0.3);
}

.character-card:hover {
    transform: translateY(-2px);
    border-color: var(--accent-hover);
}

.character-card.selected {
    border-color: var(--accent-color);
    box-shadow: 0 0 15px rgba(227, 217, 255, 0.3);
}

.character-portrait {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: 3px solid var(--border-color);
    background-color: var(--bg-color);
    display: flex;
    justify-content: center;
    align-items: center;
    flex-shrink: 0;
    overflow: hidden;
    padding: 2px;
}

.character-portrait svg {
    width: 65%;
    height: 65%;
}

.character-portrait img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}

.character-card-info {
    flex-grow: 1;
    overflow: hidden;
}

.character-card h3 {
    margin-bottom: 0.25rem;
}

.character-role-title {
    font-size: 0.8rem;
    color: var(--secondary-text);
    margin-top: 0.1rem;
    font-weight: 600;
    font-family: var(--font-title);
    text-shadow: 0 0 5px currentColor;
}

.character-card p {
    font-size: 0.85rem;
    color: var(--secondary-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.character-pet-info {
    font-size: 0.8rem !important;
    margin-top: 4px;
    font-style: italic;
}

.character-resource-type {
    font-size: 0.75rem !important;
    color: var(--secondary-text) !important;
    margin-top: 4px;
    font-style: italic;
}

.character-equipped {
    font-size: 0.75rem;
    color: var(--secondary-text);
    margin-top: 0.25rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.character-equipped span {
    display: block;
}

.character-card-settings-btn, .character-card-quest-btn {
    position: absolute;
    top: 4px;
    width: 32px;
    height: 32px;
    padding: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: transparent;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    transition: background-color 0.2s;
    z-index: 5;
}

.character-card-settings-btn { right: 4px; }
.character-card-quest-btn { right: 40px; }

.character-card-settings-btn:hover, .character-card-quest-btn:hover {
    background-color: var(--card-bg-light);
}

.character-card-settings-btn i,
.character-card-quest-btn i {
    font-size: 18px;
    color: var(--secondary-text);
    transition: color 0.2s;
}

.character-card-settings-btn:hover i,
.character-card-quest-btn:hover i {
    color: var(--primary-text);
}


/* Main Content */
#main-content {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    position: relative;
}

#game-board {
    flex-grow: 1;
    padding: 2rem;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    position: relative; /* Needed for exploration overlay */
    overflow: hidden; /* Contain the fog */
}

#pre-combat-display, #combat-display {
    width: 100%;
    height: 100%;
    position: relative;
    z-index: 1;
}

#pre-combat-display {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    position: relative; /* For town background */
}

#location-info {
    text-align: center;
    margin-bottom: 2rem;
}

#location-description {
    max-width: 600px;
    margin: 1rem auto;
    color: var(--secondary-text);
    line-height: 1.6;
}

#action-buttons {
    display: flex;
    justify-content: center;
    gap: 1rem;
    flex-wrap: wrap;
    width: 100%;
}

/* Town & Crossroads Background */
#town-background,
#crossroads-background {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    z-index: 0;
    filter: brightness(0.6);
}

.in-town #location-info,
.in-town #action-buttons,
.at-crossroads #location-info,
.at-crossroads #action-buttons {
    position: relative;
    z-index: 1;
    background-color: rgba(13, 10, 15, 0.7);
    padding: 1.5rem;
    border-radius: 12px;
    backdrop-filter: blur(5px);
    border: 1px solid var(--border-color);
}

.at-crossroads #action-buttons {
    padding: 0;
    background-color: transparent;
    border: none;
    backdrop-filter: none;
}

.in-town #location-info,
.at-crossroads #location-info {
    margin-bottom: 1rem; /* Adjust margin since padding is added */
}


/* Exploration Overlay */
#exploration-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(13, 10, 15, 0.85);
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    z-index: 10;
    backdrop-filter: blur(4px);
    text-align: center;
    border-radius: 12px;
}

#exploration-text {
    font-size: 1.5rem;
    color: var(--secondary-text);
}

.walk-animation span {
    font-size: 3rem;
    color: var(--primary-text);
    animation: walk-dots 1.4s infinite;
}

.walk-animation span:nth-child(2) {
    animation-delay: 0.2s;
}

.walk-animation span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes walk-dots {
    0%, 20% {
        color: rgba(232, 230, 227, 0.2);
        transform: translateY(0);
    }
    50% {
        color: var(--primary-text);
        transform: translateY(-5px);
    }
}


/* Location Film Strip */
.location-strip-container {
    display: flex;
    overflow-x: auto;
    gap: 1.5rem;
    padding: 1.5rem;
    width: 100%;
    scrollbar-color: var(--border-color) var(--bg-color);
}
.location-card {
    flex: 0 0 180px;
    height: 200px;
    border: 2px solid var(--border-color);
    border-radius: 12px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s ease-in-out;
    position: relative;
    overflow: hidden;
    background-color: var(--card-bg);
}
.location-card-content {
    width: 100%;
    height: 100%;
    padding: 1.5rem 1rem;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 0.5rem;
    transition: filter 0.2s ease-in-out;
}
.location-card:not(.disabled):hover {
    transform: translateY(-5px);
    border-color: var(--accent-color);
    box-shadow: 0 5px 20px rgba(0,0,0,0.3);
}
.location-card.disabled {
    cursor: not-allowed;
}
.location-card.disabled:hover {
    transform: none;
    box-shadow: none;
}
.location-card.disabled .location-card-content {
    filter: grayscale(1) brightness(0.6) blur(2.5px);
}
.location-card-lock-icon {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 50px;
    height: 50px;
    fill: rgba(232, 230, 227, 0.8);
    z-index: 2;
}

.location-card-icon {
    height: 50px;
    width: 50px;
    margin: 0 auto;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 2.5rem;
    color: var(--secondary-text);
    transition: color 0.2s ease;
}
.location-card.disabled .location-card-icon {
    color: #555;
}
.location-card:not(.disabled):hover .location-card-icon {
    color: var(--accent-color);
}
.location-card-name {
    font-size: 1.1rem;
    font-weight: 600;
}
.location-card-level {
    font-size: 0.9rem;
    color: var(--secondary-text);
}
.location-card.disabled .location-card-level {
    color: var(--req-not-met);
    font-weight: 600;
}


#combat-controls-container {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    display: flex;
    justify-content: center;
    gap: 1rem;
    flex-wrap: wrap;
    padding: 1.5rem;
    background: linear-gradient(to top, rgba(13,10,15, 0.9) 20%, transparent 100%);
    z-index: 20;
}


/* === NEW COMBAT DISPLAY === */
#combat-display {
    display: grid;
    grid-template-areas:
        "enemy enemy"
        "player pet";
    grid-template-columns: 2fr 1fr;
    grid-template-rows: 1fr 1fr;
    align-items: end;
    justify-items: start;
    padding: 1rem;
    gap: 1rem;
    pointer-events: none;
}

.combatant-hud {
    transition: transform 0.3s ease, filter 0.3s ease;
    width: 100%;
    position: relative;
    pointer-events: all;
}

.combatant-hud.inactive {
    filter: brightness(0.6);
}
.combatant-hud.active {
    transform: scale(1.03);
}

#player-combatant-card { grid-area: player; }
#pet-combatant-card { grid-area: pet; }
#enemy-combatant-card {
    grid-area: enemy;
    justify-self: end;
    align-self: start;
}

.combatant-hud-content {
    background-color: rgba(29, 23, 36, 0.7);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    backdrop-filter: blur(5px);
    padding: 1rem;
    display: flex;
    gap: 1.5rem;
    align-items: center;
    box-shadow: 0 5px 20px rgba(0,0,0,0.3);
    max-width: 450px;
}

#enemy-combatant-card .combatant-hud-content {
    flex-direction: row-reverse;
}

.combatant-portrait-wrapper {
    width: 100px;
    height: 100px;
    flex-shrink: 0;
    position: relative;
    clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
}
.combatant-portrait-wrapper::before {
    content: '';
    position: absolute;
    top: -4px; left: -4px;
    right: -4px; bottom: -4px;
    background: var(--border-color);
    z-index: 0;
    clip-path: inherit;
    transition: background 0.3s ease;
}
#player-combatant-card .combatant-portrait-wrapper::before {
    background: var(--accent-color);
}
#enemy-combatant-card .combatant-portrait-wrapper::before {
    background: var(--rank-normal); /* Will be overridden by inline style */
}

.combatant-portrait-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    position: relative;
    z-index: 1;
    clip-path: inherit;
}

.combatant-info {
    flex-grow: 1;
    min-width: 0;
}
#enemy-combatant-card .combatant-info {
    text-align: right;
}
.combatant-info h3 {
    font-family: var(--font-display);
    font-size: 2rem;
    letter-spacing: 1px;
}
.combatant-info p {
    font-size: 0.9rem;
    color: var(--secondary-text);
    margin-top: 0.25rem;
}

/* Pet Card Specifics */
#pet-combatant-card .combatant-hud-content {
    padding: 0.75rem;
    max-width: 300px;
    gap: 1rem;
}
#pet-combatant-card .combatant-portrait-wrapper {
    width: 60px;
    height: 60px;
}
#pet-combatant-card .combatant-info h3 {
    font-size: 1.2rem;
}
#pet-combatant-card .combatant-info p {
    font-size: 0.8rem;
}

/* Buffs */
.buff-container {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.5rem;
}
#enemy-combatant-card .buff-container {
    justify-content: flex-end;
}

.buff-icon {
    width: 28px;
    height: 28px;
    background-color: var(--bg-color);
    border: 1px solid var(--secondary-text);
    border-radius: 50%;
    font-size: 0.7rem;
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: bold;
    color: var(--secondary-text);
    position: relative;
    cursor: help;
}
.buff-icon[data-buff-id*="bleed"], .buff-icon[data-buff-id*="burn"] {
    animation: pulse-red 1.5s infinite;
}
@keyframes pulse-red {
    50% { box-shadow: 0 0 8px var(--log-damage); }
}


/* Health, MP & XP Bars */
.health-bar-container, .mp-bar-container, .xp-bar-container, .energy-bar-container {
    width: 100%;
    height: 24px;
    background-color: var(--hp-bg);
    border-radius: 4px;
    margin-top: 1rem;
    overflow: hidden;
    position: relative;
    border: 1px solid var(--border-color);
}

.mp-bar-container, .energy-bar-container {
    height: 16px;
    margin-top: 0.5rem;
}

.mp-bar-container { background-color: var(--mp-bg); }
.energy-bar-container { background-color: var(--en-bg); }
.xp-bar-container { background-color: var(--xp-bg); }

.mp-bar, .energy-bar, .xp-bar, .health-bar {
    height: 100%;
    transition: width 0.5s ease-in-out;
    border-radius: 3px 0 0 3px;
    position: relative;
    overflow: hidden;
}

.mp-bar { background-color: var(--mp-color); }
.energy-bar { background-color: var(--en-color); }
.xp-bar { background-color: var(--xp-color); }
.health-bar { background-color: var(--hp-color); }

.shield-bar {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    transition: width 0.5s ease-in-out;
    border-radius: 3px 0 0 3px;
    background-color: var(--shield-color);
    z-index: 2;
}

.bar-text {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--bg-color);
    text-shadow: none;
    z-index: 3;
}

.mp-bar-container .bar-text, .energy-bar-container .bar-text {
    font-size: 0.75rem;
}

#pet-combatant-card .xp-bar-container {
    height: 12px;
}
#pet-combatant-card .bar-text {
    font-size: 0.7rem;
}

/* === END NEW COMBAT DISPLAY === */


/* Action Log & Inventory */
#inventory-display {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border-color);
    background-color: rgba(13, 10, 15, 0.7);
}
.inventory-summary {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}
#items-list {
    display: flex;
    gap: 1rem;
    color: var(--secondary-text);
    font-size: 0.9rem;
    flex-wrap: wrap;
}

#action-log {
    height: 120px;
    background-color: var(--log-bg);
    padding: 1rem 1.5rem;
    overflow-y: auto;
    font-size: 0.9rem;
    border-top: 1px solid var(--border-color);
}

#action-log p {
    line-height: 1.5;
    padding: 0.25rem 0;
    transition: all 0.3s ease;
}

@keyframes new-log-pulse {
    from { color: var(--accent-color); text-shadow: 0 0 5px var(--accent-color); }
    to { color: var(--primary-text); text-shadow: none; }
}

#action-log p:first-child {
    font-weight: 600;
    animation: new-log-pulse 1s ease-out;
}

/* Log Coloring */
#action-log .log-gold,
#action-log .log-damage,
#action-log .log-heal,
#action-log .log-xp,
#action-log .log-quest,
#action-log .log-skill,
#action-log .log-item {
    font-weight: 600;
}
#action-log .log-gold { color: var(--log-gold); }
#action-log .log-damage { color: var(--log-damage); }
#action-log .log-heal { color: var(--log-heal); }
#action-log .log-xp { color: var(--log-xp); }
#action-log .log-quest { color: var(--log-quest); }
#action-log .log-skill { color: var(--log-skill); }
#action-log .log-levelup {
    color: var(--log-levelup);
    font-weight: 700;
    text-shadow: 0 0 5px rgba(245, 158, 11, 0.5);
}

/* Buttons */
button {
    font-family: var(--font-body);
    font-size: 0.9rem;
    padding: 0.75rem 1.5rem;
    background-color: var(--card-bg-light);
    color: var(--primary-text);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    font-weight: 600;
    letter-spacing: 0.5px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}

button:hover {
    background-color: var(--border-color);
    border-color: var(--secondary-text);
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.3);
}

#action-buttons button, #combat-controls-container button, #character-selection-screen button {
     background-color: transparent;
     border-width: 2px;
     border-color: var(--accent-color);
     color: var(--accent-color);
     text-transform: uppercase;
}
#action-buttons button:hover, #combat-controls-container button:hover, #character-selection-screen button:hover {
    background-color: var(--accent-color);
    color: var(--bg-color);
    border-color: var(--accent-color);
    text-shadow: none;
}

#main-menu-nav {
    display: flex;
    flex-direction: column;
    gap: 1.2rem;
    width: 100%;
    max-width: 250px;
}

#main-menu-nav button {
    background: transparent;
    border: 2px solid var(--border-color);
    color: var(--secondary-text);
    padding: 0.8rem 1.5rem;
    font-size: 1.1rem;
    font-family: var(--font-title);
    text-transform: uppercase;
    letter-spacing: 1px;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
    box-shadow: none;
}

#main-menu-nav button::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(120deg, transparent, rgba(227, 217, 255, 0.2), transparent);
    transition: left 0.5s ease;
}

#main-menu-nav button:hover {
    color: var(--primary-text);
    border-color: var(--accent-color);
    background-color: transparent;
    box-shadow: 0 0 15px rgba(227, 217, 255, 0.2), 0 0 5px rgba(227, 217, 255, 0.1) inset;
    transform: translateY(-2px);
}

#main-menu-nav button:hover::before {
    left: 100%;
}

#main-menu-footer {
    position: absolute;
    bottom: 1rem;
    color: var(--secondary-text);
    opacity: 0.5;
    font-size: 0.8rem;
}


button:disabled {
    background-color: #2b2b2b;
    border-color: #333333;
    color: #666666;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* Modals */
.modal-background {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(13, 10, 15, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    backdrop-filter: blur(5px);
}

.modal-content {
    background-color: var(--card-bg);
    border-radius: 12px;
    border: 1px solid var(--border-color);
    max-width: 550px;
    width: 90%;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 10px 40px rgba(0,0,0,0.4);
}

.modal-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h2 {
    margin: 0;
    text-align: center;
}

.modal-content > p {
    padding: 1.5rem 1.5rem 0 1.5rem;
    color: var(--secondary-text);
}

.modal-scrollable-content {
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    overflow-y: auto;
    flex-grow: 1;
}

.modal-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.skill-option, .shop-item, .combat-item-option, .sell-item {
    background-color: var(--bg-color);
    padding: 1rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    cursor: pointer;
    transition: border-color 0.2s;
}
.skill-option:hover, .shop-item:hover, .combat-item-option:hover, .sell-item:hover {
    border-color: var(--secondary-text);
}

.skill-option.selected {
    border-color: var(--accent-color);
    box-shadow: 0 0 10px rgba(227, 217, 255, 0.2);
}
.skill-option p, .shop-item p, .sell-item p {
    color: var(--secondary-text);
    font-size: 0.9em;
    margin-top: 0.25rem;
    margin-bottom: 0;
}
.shop-item, .sell-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.shop-item-info, .sell-item-info {
    text-align: left;
}

/* Shop Modal Specifics */
.shop-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}
#shop-toggle-buttons {
    display: flex;
    gap: 0.5rem;
}
#shop-toggle-buttons button {
    background-color: var(--bg-color);
    border: 1px solid var(--border-color);
}
#shop-toggle-buttons button.active {
    background-color: var(--border-color);
    border-color: var(--secondary-text);
}

.confirm-modal-buttons {
    display: flex;
    justify-content: center;
    gap: 1rem;
    padding-top: 1.5rem;
}
.confirm-modal-buttons #confirm-yes-btn {
    background-color: var(--req-met);
    border-color: var(--req-met);
    color: var(--bg-color);
}
.confirm-modal-buttons #confirm-yes-btn:hover {
    background-color: #63e89b;
    border-color: #63e89b;
}

/* Artisan Modal */
.blueprint-item {
    background-color: var(--bg-color);
    padding: 1rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}
.blueprint-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.blueprint-header h4 {
    margin: 0;
}
.blueprint-item p {
    color: var(--secondary-text);
    font-size: 0.9em;
    margin: 0;
}
.blueprint-requirements ul {
    list-style: none;
    font-size: 0.85rem;
}
.blueprint-requirements .req-met {
    color: var(--req-met);
}
.blueprint-requirements .req-not-met {
    color: var(--req-not-met);
}

/* Quest Modals */
#quest-log-list {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    text-align: left;
}

.quest-log-item {
    background-color: var(--bg-color);
    padding: 1rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
}

.quest-log-item h4 {
    margin-bottom: 0.5rem;
}

.quest-log-item p {
    color: var(--secondary-text);
    font-size: 0.9em;
    margin-bottom: 0.75rem;
}

.quest-log-item ul {
    list-style: none;
    font-size: 0.9em;
    margin-bottom: 0.75rem;
}

#quest-offer-details {
    background-color: var(--log-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 1rem;
    margin: 1rem 0;
    text-align: left;
}

#quest-offer-details h3, #quest-offer-details h4 {
    margin-bottom: 0.5rem;
}

#quest-offer-details ul {
    list-style-position: inside;
    margin-bottom: 1rem;
}


/* Tooltip */
.tooltip {
    position: fixed;
    background-color: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 1rem;
    max-width: 250px;
    z-index: 200;
    pointer-events: none;
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
    text-align: left;
}
.tooltip h4 {
    margin-bottom: 0.5rem;
    color: var(--accent-color);
}
.tooltip p {
    font-size: 0.9rem;
    color: var(--secondary-text);
    line-height: 1.4;
    margin: 0;
}

/* Inventory Modal */
.inventory-modal-content {
    max-width: 800px;
    width: 95%;
}
.inventory-container {
    display: flex;
    gap: 1.5rem;
    height: 55vh;
    padding: 1.5rem;
    text-align: left;
}
.inventory-list-section {
    flex: 1;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 1rem;
    background-color: var(--log-bg);
    overflow-y: auto;
}
.inventory-details-section {
    flex: 1;
}
#inventory-item-list .category-title {
    margin-top: 1rem;
    margin-bottom: 0.5rem;
    color: var(--secondary-text);
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 1px;
}
#inventory-item-list .category-title:first-child {
    margin-top: 0;
}
.inventory-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem;
    border-radius: 4px;
    cursor: pointer;
    border: 1px solid transparent;
}

.item-icon {
    width: 32px;
    height: 32px;
    border-radius: 4px;
    background-color: var(--bg-color);
    flex-shrink: 0;
}
.inventory-item:hover {
    background-color: var(--card-bg-light);
}
.inventory-item.selected {
    border-color: var(--accent-hover);
    background-color: var(--border-color);
}
.item-name-Equipment { color: var(--item-equipment); font-weight: 600; }
.item-name-Consumable { color: var(--item-consumable); font-weight: 600; }
.item-name-Material { color: var(--item-material); }
.item-name-SkillTome { color: var(--item-skilltome); font-weight: 600; }
.item-name-PetEgg { color: var(--item-petegg); font-weight: 600; }
.item-name-QuestItem { color: var(--item-questitem); font-weight: 600; }

.equipment-slots {
    background-color: var(--log-bg);
    border: 1px solid var(--border-color);
    padding: 1rem;
    border-radius: 8px;
    margin-bottom: 1.5rem;
}
.equipment-slots h3 {
    margin-bottom: 0.5rem;
}
.equipment-slots .slot {
    display: flex;
    justify-content: space-between;
    padding: 0.5rem 0;
    align-items: center;
    font-size: 0.9rem;
}
.equipment-slots .slot span { color: var(--primary-text); }
.equipment-slots .slot i {
    margin-right: 0.75rem;
    color: var(--secondary-text);
    width: 20px;
    text-align: center;
}

#item-details-pane, #item-details-placeholder {
    background-color: var(--log-bg);
    border: 1px solid var(--border-color);
    padding: 1rem;
    border-radius: 8px;
    min-height: 200px;
}

#item-details-icon {
    width: 64px;
    height: 64px;
    border-radius: 8px;
    background-color: var(--bg-color);
    margin-bottom: 1rem;
    overflow: hidden;
}

#item-details-icon img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
#item-details-placeholder {
    display: flex;
    justify-content: center;
    align-items: center;
    color: var(--secondary-text);
}
#item-details-pane.hidden ~ #item-details-placeholder {
    display: flex;
}
#item-details-pane:not(.hidden) ~ #item-details-placeholder {
    display: none;
}


#item-details-description { color: var(--secondary-text); }
#item-details-stats { margin: 1rem 0; font-size: 0.9em; }
#item-details-stats p { margin-bottom: 0.5rem; }
#item-details-stats .stat-increase {
    color: var(--req-met);
    font-weight: 600;
}
#item-details-stats .stat-decrease {
    color: var(--req-not-met);
    font-weight: 600;
}

#item-details-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 1rem;
}

/* Settings Modal */
.settings-options {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    text-align: left;
    width: 100%;
    max-width: 350px;
    margin-left: auto;
    margin-right: auto;
}

.settings-option {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 1.1rem;
}
.settings-option label {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.settings-option button {
    min-width: 120px;
}

/* Animations */
@keyframes textFadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}
@keyframes textFadeOut {
    from { opacity: 1; transform: translateY(0); }
    to { opacity: 0; transform: translateY(-10px); }
}
.fade-in {
    animation: textFadeIn 1.5s ease-out forwards;
}
.fade-out {
    animation: textFadeOut 1.5s ease-in forwards;
}

@keyframes containerFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

#main-menu.fade-in-container {
    animation: containerFadeIn 1.5s ease-in forwards;
}

@keyframes attack-pulse {
    50% { filter: brightness(1.3) saturate(1.2); }
}

.animate-attack {
    animation: attack-pulse 0.4s ease-in-out;
}

@keyframes shake-horizontal {
    0%, 100% { transform: translateX(0); }
    20%, 60% { transform: translateX(-8px); }
    40%, 80% { transform: translateX(8px); }
}

@keyframes flash-hit {
    50% {
        filter: brightness(2) contrast(2);
    }
}

@keyframes float-up-damage {
    0% {
        transform: translateY(5px) scale(1.2);
        opacity: 1;
    }
    20% {
        transform: translateY(0) scale(1);
        opacity: 1;
    }
    100% {
        transform: translateY(-80px) scale(0.9);
        opacity: 0;
    }
}

@keyframes float-up-heal {
    0% {
        transform: translateY(0) scale(0.9);
        opacity: 0.9;
    }
    100% {
        transform: translateY(-90px) scale(1.1);
        opacity: 0;
    }
}

.animate-hit {
    animation: shake-horizontal 0.4s ease-in-out, flash-hit 0.2s ease;
}
.animate-heal .combatant-hud-content {
    --flash-color: rgba(74, 222, 128, 0.4);
    box-shadow: 0 0 25px 10px var(--flash-color, rgba(255,255,255,0.7));
}
.animate-shield .combatant-hud-content {
    --flash-color: rgba(96, 165, 250, 0.4);
    box-shadow: 0 0 25px 10px var(--flash-color, rgba(255,255,255,0.7));
}


/* Damage Popups */
.damage-popup-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 50;
}
.damage-popup {
    position: absolute;
    top: 30%;
    left: 50%;
    transform: translateX(-50%);
    font-family: var(--font-display);
    font-size: 3rem;
    font-weight: 400;
    text-shadow: 0 2px 5px rgba(0,0,0,0.7);
}
.damage-popup.damage {
    color: var(--primary-text);
    animation: float-up-damage 1.2s ease-out forwards;
}
.damage-popup.heal {
    color: var(--heal-color);
    animation: float-up-heal 1.4s ease-out forwards;
}
.damage-popup.shield {
    color: #60a5fa;
    animation: float-up-damage 1.2s ease-out forwards;
}
.damage-popup.miss {
    color: var(--secondary-text);
    font-size: 2rem;
    animation: float-up-damage 1.2s ease-out forwards;
}


/* Fog Effect */
#fog-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
}

.fog-layer {
    position: absolute;
    width: 150%;
    height: 150%;
    top: -25%;
    left: -25%;
    background: transparent;
    animation-timing-function: linear;
    animation-iteration-count: infinite;
    animation-direction: alternate;
    opacity: 0;
}

.fog-layer.fog-1 {
    background-image:
        radial-gradient(ellipse at 20% 80%, rgba(40, 35, 50, 0.6) 0%, transparent 40%),
        radial-gradient(ellipse at 75% 90%, rgba(45, 40, 55, 0.5) 0%, transparent 50%);
    animation-duration: 60s;
    animation-name: drift, fadeIn;
    animation-fill-mode: forwards;
    animation-delay: 0s, 0s;
}

.fog-layer.fog-2 {
    background-image:
        radial-gradient(ellipse at 10% 30%, rgba(55, 50, 65, 0.7) 0%, transparent 35%),
        radial-gradient(ellipse at 80% 20%, rgba(60, 55, 70, 0.6) 0%, transparent 45%);
    animation-duration: 45s;
    animation-name: drift-reverse, fadeIn;
    animation-fill-mode: forwards;
    animation-delay: 0s, 1s;
}

.fog-layer.fog-3 {
    background-image:
        radial-gradient(circle at 50% 50%, rgba(50, 45, 60, 0.4) 0%, transparent 30%);
    animation-duration: 75s;
    animation-name: drift, fadeIn;
    animation-fill-mode: forwards;
    animation-delay: 0s, 2s;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes drift {
    from { transform: translate(-10%, -10%) scale(1.2); }
    to { transform: translate(10%, 10%) scale(1.2); }
}

@keyframes drift-reverse {
    from { transform: translate(10%, 10%) scale(1.1); }
    to { transform: translate(-10%, -10%) scale(1.1); }
}

/* New Skill Glow Effect */
@keyframes new-skill-glow-pulse {
    0% {
        box-shadow: 0 0 15px rgba(251, 191, 36, 0.25);
        border-color: var(--accent-color);
    }
    50% {
        box-shadow: 0 0 25px 8px rgba(251, 191, 36, 0.6);
        border-color: #fbbf24;
    }
    100% {
        box-shadow: 0 0 15px rgba(251, 191, 36, 0.25);
        border-color: var(--accent-color);
    }
}

.character-card.new-skill-glow {
    animation: new-skill-glow-pulse 1.8s infinite ease-in-out;
}


/* Utility Classes */
.hidden {
    display: none !important;
}

/* Responsive Design */
@media (max-width: 1024px) {
    body {
        padding: 0;
        height: 100dvh;
        overflow: hidden;
    }
    #app, #game-container {
        height: 100%;
        max-height: none;
        flex-direction: column;
        border-radius: 0;
    }
    #main-content {
        min-height: 0; /* Critical for allowing flex children to shrink and scroll */
    }
    #character-panel {
        width: 100%;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
        flex-direction: row;
        overflow-x: auto;
        padding: 0.75rem;
        height: auto;
        flex-shrink: 0;
        align-items: center;
        gap: 1rem;
    }
    .character-card {
        flex-shrink: 0;
        width: 280px;
    }
    #game-board {
        padding: 1rem;
        min-height: 0; /* Prevents flexbox overflow issues */
    }

    #combat-display {
        grid-template-areas:
            "enemy"
            "player"
            "pet";
        grid-template-columns: 1fr;
        grid-template-rows: auto auto auto;
        align-content: space-between;
        justify-items: center;
        gap: 1rem;
    }
    #enemy-combatant-card, #player-combatant-card, #pet-combatant-card {
        justify-self: center;
        align-self: center;
    }
    #enemy-combatant-card { align-self: start; }
    #player-combatant-card { align-self: end; }
    .combatant-hud-content { max-width: 380px; }


    .modal-content {
        max-height: 90vh;
    }
    .inventory-container {
        flex-direction: column;
        height: 60vh;
    }
    #story-text {
        font-size: 1.2rem;
        max-width: 90%;
    }
    #character-selection-cards {
      grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    }
}

@media (max-width: 850px) {
    #character-selection-cards {
      grid-template-columns: repeat(2, 1fr);
      max-width: 550px;
    }
}

@media (max-width: 600px) {
    #main-menu h1 {
        font-size: 4.5rem;
    }
    h1 {
        font-size: 3.5rem;
    }
    h2 {
        font-size: 2.2rem;
    }
    #character-selection-cards {
      grid-template-columns: 1fr;
      max-width: 300px;
    }
    #character-panel {
        flex-direction: column;
        align-items: stretch;
        overflow-x: hidden;
        overflow-y: auto;
        max-height: 150px;
    }
    .character-card {
        width: 100%;
    }
    .character-card-settings-btn {
        top: 50%;
        transform: translateY(-50%);
        right: 4px;
    }
    .character-card-quest-btn {
        top: 50%;
        transform: translateY(-50%);
        right: 40px;
    }
/* Preloading Screen */
#preloading-screen {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    height: 100%;
    width: 100%;
    padding: 2rem;
}

#preloading-screen h2 {
    margin-bottom: 2rem;
}

#progress-bar-container {
    width: 100%;
    max-width: 400px;
    height: 20px;
    background-color: var(--card-bg-light);
    border-radius: 10px;
    border: 1px solid var(--border-color);
    overflow: hidden;
    margin-bottom: 1rem;
}

#progress-bar {
    width: 0%;
    height: 100%;
    background-color: var(--accent-color);
    transition: width 0.3s ease-in-out;
}

#loading-message {
    color: var(--secondary-text);
    font-size: 0.9rem;
    height: 1.2em; /* Reserve space to prevent layout shift */
}

    .combatant-portrait-wrapper {
        width: 80px;
        height: 80px;
    }
    #pet-combatant-card .combatant-portrait-wrapper {
        width: 50px;
        height: 50px;
    }
    .combatant-info h3 { font-size: 1.5rem; }
}

@media (max-height: 600px) {
    #combat-display {
        gap: 0.5rem;
        padding: 0.5rem;
    }
    .combatant-hud-content {
        padding: 0.5rem;
        gap: 0.75rem;
    }
    .combatant-info h3 {
        font-size: 1.5rem;
    }
    .combatant-portrait-wrapper {
        width: 70px;
        height: 70px;
    }
}