:root {
    /* Color Palette */
    --bg-dark: #0f1115;
    --bg-panel: #161b22;
    --accent-color: #d4a373;
    /* Gold/Bronze */
    --accent-glow: rgba(212, 163, 115, 0.2);
    --primary-color: #d4a373;
    /* Aligning with accent-color */

    --text-main: #e6edf3;
    --text-muted: #8b949e;
    --text-dim: #6e7681;
    --border-color: #30363d;

    /* Stat Colors */
    --health-color: #f85149;
    --stamina-color: #d29922;
    --power-color: #58a6ff;
    --hunger-color: #d29922;

    /* Effect Colors */
    --paralysis-color: #00ff00;
    --invulnerable-color: #00ffff;
    --pox-color: #9b59b6;

    /* Typography */
    --font-heading: 'Cinzel', serif;
    --font-body: 'Outfit', sans-serif;

    --grid-size: 32px;
}

/* 1. BASE & UTILS */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background-color: var(--bg-dark);
    color: var(--text-main);
    font-family: var(--font-body);
    height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.hidden {
    display: none !important;
}

.highlight {
    color: var(--accent-color);
}

.flavor-text {
    font-style: italic;
    color: var(--text-dim);
    margin-top: 1rem;
}

/* 2. LAYOUT COMPONENTS */
.app-container {
    height: 100%;
    display: flex;
    flex-direction: column;
    max-width: 1400px;
    margin: 0 auto;
    width: 100%;
    padding: 1rem;
}

header {
    text-align: center;
    margin-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 1rem;
}

header h1 {
    font-family: var(--font-heading);
    color: var(--accent-color);
    text-shadow: 0 0 10px var(--accent-glow);
    font-size: 2.5rem;
    letter-spacing: 2px;
}

.subtitle {
    color: var(--text-muted);
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 3px;
}

.game-interface {
    display: flex;
    flex: 1;
    gap: 1.5rem;
    overflow: hidden;
}

.sidebar {
    width: 300px;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    flex-shrink: 0;
}

/* 3. GAME WORLD (GRID, TILES, FOG) */
.viewport-container {
    flex: 1;
    background: #000;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.game-grid {
    display: grid;
    gap: 0;
    background-color: #222;
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 100%;
    margin: auto;
    font-family: 'Courier New', Courier, monospace;
    font-weight: bold;
    image-rendering: pixelated;
    -webkit-font-smoothing: none;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: geometricPrecision;
}

.tile {
    width: 100%;
    height: 100%;
    background-color: #1a1a1a;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    position: relative;
    cursor: default;
    user-select: none;
}

.tile.wall {
    background-color: #555;
    border: 1px solid #333;
    box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.5);
}

.tile.floor {
    background-color: #1a1a1a;
}

.tile.visited {
    background-color: #222;
}

.fog-explored {
    opacity: 0.3;
    filter: grayscale(100%);
}

.fog-unexplored {
    background-color: #000 !important;
    border: none;
    box-shadow: none;
}

/* 4. ENTITIES & EFFECTS */
.entity-player {
    z-index: 10;
    animation: bounce 1s infinite;
}

.entity-monster {
    z-index: 5;
    color: var(--health-color);
}

.entity-treasure {
    color: var(--accent-color);
    animation: pulse 2s infinite;
}

.entity-potion {
    color: var(--health-color);
    filter: drop-shadow(0 0 2px var(--health-color));
}

.entity-potion_clarity {
    color: #4db6ac;
    filter: drop-shadow(0 0 2px #4db6ac);
}

/* Player States */
.entity-player.invulnerable {
    --glow-color: var(--invulnerable-color);
    animation: bounce 1s infinite, pulse-glow 1s infinite;
}

.entity-player.paralyzed {
    --glow-color: var(--paralysis-color);
    animation: bounce 1s infinite, pulse-glow 1s infinite;
}

.entity-player.poxed {
    --glow-color: var(--pox-color);
    animation: bounce 1s infinite, pulse-glow 1s infinite;
}

.entity-player.critical {
    --flash-color: var(--health-color);
    animation: bounce 1s infinite, flash-status 0.3s infinite;
}

.entity-player.starving {
    --flash-color: var(--hunger-color);
    animation: bounce 1s infinite, flash-status 0.5s infinite;
}

/* Debug Highlights */
.highlight-monster,
.highlight-treasure,
.highlight-stairs {
    color: white;
    border: 1px solid white;
    border-radius: 0;
    box-shadow: none;
}

.highlight-monster {
    background: #d32f2f;
}

.highlight-treasure {
    background: #fbc02d;
    color: black;
}

.highlight-stairs {
    background: #00acc1;
}

/* 5. HUD / UI PANELS */
.stat-block {
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
}

.stat-row,
.stat-info {
    display: flex;
    justify-content: space-between;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.stat-info {
    font-size: 0.85rem;
    margin-bottom: 4px;
    color: var(--text-main);
}

.stat-bar-container {
    display: flex;
    flex-direction: column;
}

.progress-bar {
    width: 100%;
    height: 8px;
    background-color: #222;
    border-radius: 4px;
    overflow: hidden;
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.5);
}

.progress-bar div {
    height: 100%;
    transition: width 0.3s ease;
}

.flat-red div {
    background-color: var(--health-color);
}

.flat-orange div {
    background-color: var(--stamina-color);
}

.flat-blue div {
    background-color: var(--power-color);
}

.stat-value-large {
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--power-color);
    text-align: right;
}

/* Status Icons */
.stats-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.status-effects {
    display: flex;
    gap: 5px;
    align-items: center;
}

.status-icon {
    font-size: 1.2rem;
    padding: 2px 5px;
    border-radius: 4px;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.2);
    animation: pulse-status 1.5s infinite;
}

.status-icon.paralyzed {
    color: var(--paralysis-color);
    border-color: var(--paralysis-color);
    background: rgba(0, 255, 0, 0.1);
}

.status-icon.invulnerable {
    color: var(--invulnerable-color);
    border-color: var(--invulnerable-color);
    background: rgba(0, 255, 255, 0.1);
}

.status-icon.poxed {
    color: var(--pox-color);
    border-color: var(--pox-color);
    background: rgba(155, 89, 182, 0.1);
}

/* Log & Inventory */
.log-block,
.inventory-block {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.log-container,
.inventory-block ul {
    flex: 1;
    overflow-y: auto;
    font-size: 0.9rem;
    scrollbar-width: thin;
    scrollbar-color: var(--border-color) var(--bg-panel);
}

.log-container {
    color: var(--text-muted);
    font-family: monospace;
    display: flex;
    flex-direction: column;
}

.log-container::-webkit-scrollbar,
.inventory-block ul::-webkit-scrollbar {
    width: 8px;
}

.log-container::-webkit-scrollbar-track,
.inventory-block ul::-webkit-scrollbar-track {
    background: var(--bg-panel);
}

.log-container::-webkit-scrollbar-thumb,
.inventory-block ul::-webkit-scrollbar-thumb {
    background-color: var(--border-color);
    border-radius: 4px;
}

.log-entry {
    margin-bottom: 0.5rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid rgba(48, 54, 61, 0.5);
    animation: fadeIn 0.3s ease;
}

.log-entry.combat {
    color: var(--health-color);
}

.log-entry.loot {
    color: var(--accent-color);
}

.log-entry.good {
    color: #56d364;
}

.inventory-block ul {
    list-style: none;
    padding: 0;
}

.inventory-block li {
    padding: 0.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
}

.item-info {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Buttons */
.btn-primary,
.danger-btn,
.action-btn {
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.2s;
    font-family: var(--font-body);
}

.btn-primary {
    background: var(--primary-color);
    color: #000;
    font-weight: 700;
    padding: 1rem 2rem;
    border: none;
    font-size: 1.2rem;
    text-transform: uppercase;
    margin-top: 1rem;
}

.btn-primary:hover {
    background: #fff;
    box-shadow: 0 0 15px var(--primary-color);
}

.danger-btn {
    background: rgba(248, 81, 73, 0.1);
    border: 1px solid rgba(248, 81, 73, 0.4);
    color: var(--health-color);
    padding: 0.5rem 1rem;
    width: 100%;
}

.danger-btn:hover {
    background: rgba(248, 81, 73, 0.2);
}

.action-btn {
    background: transparent;
    border: 1px solid var(--accent-color);
    color: var(--accent-color);
    padding: 0.2rem 0.5rem;
    font-size: 0.8rem;
}

.action-btn:hover {
    background: var(--accent-color);
    color: #000;
}

.action-btn:hover {
    background: var(--accent-color);
    color: #000;
}

.equip-slot.spacer {
    display: none;
}

/* Equipment Grid */
.equipment-grid {
    display: grid;
    grid-template-areas:
        ".        head     ."
        "l_arm    chest    r_arm"
        "l_weapon chest    r_weapon"
        ".        pubis    ."
        "l_leg    .        r_leg"
        "l_shoe   .        r_shoe";
    gap: 8px;
    margin-top: 1rem;
    justify-content: center;
}

.equip-slot {
    width: 48px;
    height: 48px;
    background-color: rgba(255, 255, 255, 0.05);
    border: 1px dashed var(--text-muted);
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    color: var(--text-muted);
    position: relative;
    cursor: help;
}

.equip-slot:hover {
    border-color: var(--accent-color);
    background-color: rgba(255, 255, 255, 0.1);
}

.equip-slot[data-slot="head"] {
    grid-area: head;
}

.equip-slot[data-slot="chest"] {
    grid-area: chest;
}

.equip-slot[data-slot="l_arm"] {
    grid-area: l_arm;
}

.equip-slot[data-slot="r_arm"] {
    grid-area: r_arm;
}

.equip-slot[data-slot="l_weapon"] {
    grid-area: l_weapon;
}

.equip-slot[data-slot="r_weapon"] {
    grid-area: r_weapon;
}

.equip-slot[data-slot="pubis"] {
    grid-area: pubis;
}

.equip-slot[data-slot="l_leg"] {
    grid-area: l_leg;
}

.equip-slot[data-slot="r_leg"] {
    grid-area: r_leg;
}

.equip-slot[data-slot="l_shoe"] {
    grid-area: l_shoe;
}

.equip-slot[data-slot="r_shoe"] {
    grid-area: r_shoe;
}

.equip-badge {
    position: absolute;
    bottom: -4px;
    right: -4px;
    background: var(--accent-color);
    color: #000;
    font-size: 0.7rem;
    font-weight: bold;
    padding: 1px 3px;
    border-radius: 3px;
}

/* 6. SCREENS & OVERLAYS */
.overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    backdrop-filter: blur(4px);
}

.modal {
    background: var(--bg-panel);
    padding: 2rem;
    border: 2px solid var(--accent-color);
    border-radius: 12px;
    text-align: center;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.7);
}

.modal h2 {
    font-family: var(--font-heading);
    color: var(--health-color);
    margin-bottom: 1rem;
    font-size: 2rem;
}

.modal button {
    background: var(--accent-color);
    border: none;
    color: #000;
    padding: 0.8rem 1.5rem;
    font-weight: bold;
    cursor: pointer;
    border-radius: 4px;
    margin-top: 1rem;
    font-family: var(--font-heading);
}

.modal button:hover {
    background: #eac6a2;
}

/* Welcome Screen */
.screen-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.95);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(10px);
}

.game-title {
    font-family: var(--font-heading);
    font-size: 4rem;
    color: var(--primary-color);
    text-shadow: 0 0 20px var(--primary-color);
    margin-bottom: 2rem;
    text-align: center;
}

.class-card {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    padding: 2rem;
    border-radius: 12px;
    text-align: center;
    max-width: 400px;
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.5);
    transition: transform 0.3s;
}

.class-card:hover {
    transform: translateY(-5px);
    border-color: var(--primary-color);
}

.card-image img {
    width: 200px;
    height: 200px;
    border-radius: 50%;
    border: 4px solid var(--primary-color);
    margin-bottom: 1rem;
    object-fit: cover;
    image-rendering: pixelated;
}

.stats-group {
    background: rgba(0, 0, 0, 0.3);
    padding: 1rem;
    border-radius: 8px;
    margin: 1.5rem 0;
    text-align: left;
}

.stats-group p {
    margin: 0.5rem 0;
    font-size: 1.1rem;
}

/* Scoreboard */
#scoreboard-overlay {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    left: 20px;
    width: 250px;
    height: 60vh;
    background: rgba(0, 0, 0, 0.6);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 1rem;
    z-index: 100;
    backdrop-filter: blur(2px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.scoreboard-container {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.scoreboard-container h3 {
    text-align: center;
    color: var(--accent-color);
    font-family: var(--font-heading);
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.5rem;
    margin-bottom: 1rem;
}

.scoreboard-scroll {
    flex: 1;
    overflow: hidden;
    position: relative;
    mask-image: linear-gradient(to bottom, transparent, black 10%, black 90%, transparent);
    -webkit-mask-image: linear-gradient(to bottom, transparent, black 10%, black 90%, transparent);
}

.score-list {
    display: flex;
    flex-direction: column;
    animation: scrollList 15s linear infinite;
}

.score-entry {
    font-size: 0.9rem;
    padding: 0.5rem 0;
    border-bottom: 1px dashed rgba(255, 255, 255, 0.1);
}

.scoreboard-scroll:hover .score-list {
    animation-play-state: paused;
}

.score-entry .rank {
    font-weight: bold;
    color: var(--accent-color);
    margin-right: 5px;
}

.score-entry .name {
    color: var(--text-main);
    font-weight: bold;
    display: block;
}

.score-entry .details {
    color: var(--text-muted);
    font-size: 0.8rem;
    display: block;
}

.score-entry .cause {
    color: var(--health-color);
    font-size: 0.75rem;
    font-style: italic;
    display: block;
}

/* 7. ANIMATIONS */
@keyframes bounce {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-2px);
    }
}

@keyframes pulse {

    0%,
    100% {
        opacity: 0.7;
    }

    50% {
        opacity: 1;
    }
}

@keyframes pulse-glow {

    0%,
    100% {
        box-shadow: 0 0 10px 2px var(--glow-color);
        background-color: rgba(0, 255, 255, 0.1);
    }

    50% {
        box-shadow: 0 0 20px 5px var(--glow-color);
        background-color: rgba(0, 255, 255, 0.3);
    }
}

@keyframes flash-status {

    0%,
    100% {
        background-color: rgba(255, 0, 0, 0.3);
    }

    50% {
        background-color: rgba(255, 0, 0, 0.7);
    }
}

/* Re-applying variable to flash correctly */
.entity-player.critical {
    --status-color: var(--health-color);
}

.entity-player.starving {
    --status-color: var(--hunger-color);
}

@keyframes flash-status {

    0%,
    100% {
        background-color: rgba(255, 255, 255, 0.1);
        box-shadow: 0 0 0 0 var(--status-color);
    }

    50% {
        background-color: rgba(var(--status-color), 0.5);
        box-shadow: 0 0 0 2px var(--status-color);
    }
}

/* Wait, I can't use rgba with hex variables easily in CSS without rgb units. 
   I'll stick to the simpler flash animations but combine the logic. */

@keyframes flash-critical {

    0%,
    100% {
        background-color: rgba(248, 81, 73, 0.3);
    }

    50% {
        background-color: rgba(248, 81, 73, 0.7);
    }
}

@keyframes flash-starving {

    0%,
    100% {
        background-color: rgba(210, 153, 34, 0.3);
    }

    50% {
        background-color: rgba(210, 153, 34, 0.7);
    }
}

@keyframes pulse-status {

    0%,
    100% {
        opacity: 0.8;
        transform: scale(1);
    }

    50% {
        opacity: 1;
        transform: scale(1.1);
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(5px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes scrollList {
    0% {
        transform: translateY(60vh);
    }

    100% {
        transform: translateY(-100%);
    }
}

/* Toggle Switches */
.toggles-container {
    display: flex;
    flex-direction: row;
    justify-content: space-around;
    align-items: center;
    gap: 8px;
    margin-bottom: 1rem;
    padding: 0.5rem;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.toggle-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.toggle-label {
    font-family: var(--font-heading);
    font-size: 0.75rem;
    color: var(--text-main);
    letter-spacing: 1px;
    text-transform: uppercase;
    opacity: 0.8;
}

.toggle-switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 22px;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #333;
    transition: .4s;
    border-radius: 22px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 16px;
    width: 16px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}

input:checked+.slider {
    background-color: var(--accent-color);
}

input:checked+.slider:before {
    transform: translateX(22px);
}