/* ═══════════════════════════════════════════════════════════════════
   THE OATHLESS — main.css
   ═══════════════════════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Germania+One&display=swap');


/* ─── 1. DESIGN TOKENS ─────────────────────────────────────────────── */

:root {
    /* Palette */
    --black: #000000;
    --white: #ffffff;
    --steel: #333333;
    --steel-dark: #1a1a1a;
    --steel-light: #555555;
    --gold: #f2c66e;
    --gold-dark: #d4a547;
    --parchment: #e6d2b5;
    --parchment-dark: #c2a886;
    --text: #e0e0e0;
    --text-dark: #2b1d0e;
    --danger: #8b0000;
    --danger-dark: #660000;
    --border: #3a3a3a;
    --bg: #111111;
    --hp: #8b0000;
    --mana: #00008b;
    --patina: #60976c;
    --inv-tint: #b4b4d240;

    /* Button variants */
    --btn-primary-bg: linear-gradient(180deg, var(--gold), var(--gold-dark));
    --btn-primary-border: var(--patina);
    --btn-primary-text: var(--steel-dark);
    --btn-secondary-bg: linear-gradient(180deg, var(--steel-light), var(--steel));
    --btn-secondary-border: var(--steel-dark);
    --btn-secondary-text: var(--parchment);
    --btn-danger-bg: linear-gradient(180deg, var(--danger), var(--danger-dark));
    --btn-danger-border: #3a0000;
    --btn-danger-text: var(--parchment);

    /* Modals */
    --modal-bg-start: #1f1f1f;
    --modal-bg-end: #1a1a1a;
    --modal-border: var(--border);
    --modal-shadow: 0 0 3rem rgba(0, 0, 0, 0.9);
    --modal-header-color: var(--gold);

    /* Typography */
    --font-main: 'Germania One', cursive;
    --font-size-header: 1.6rem;
    --font-size-label: 0.9rem;
    --font-size-small: 0.75rem;

    /* Spacing */
    --spacing-xs: 0.2rem;
    --spacing-sm: 0.5rem;
    --spacing-md: 1rem;
    --spacing-lg: 1.5rem;
    --spacing-xl: 2rem;

    /* Adaptive scaling */
    --base-font-size: clamp(16px, 1.2vw, 30px);
    --panel-width: clamp(260px, 20vw, 420px);
    --slot-size: clamp(48px, 4.5vw, 80px);
    --equipment-slot-size: clamp(42px, 5.5vw, 70px);
    --item-icon-size: calc(var(--slot-size) * 0.85);
}


/* ─── 2. RESET & BASE ──────────────────────────────────────────────── */

*,
*::before,
*::after {
    box-sizing: border-box;
}

body,
html {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: var(--black);
    font-family: var(--font-main);
    color: var(--text);
    user-select: none;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: var(--base-font-size);
}

.hidden {
    display: none !important;
}


/* ─── 3. TYPOGRAPHY ───────────────────────────────────────────────── */

h1,
h2,
h3,
button,
.header-font {
    font-family: var(--font-main);
}

h1 {
    font-size: 3rem;
}

h2 {
    font-size: 2.2rem;
}

h3 {
    font-size: 1.8rem;
}


/* ─── 4. LAYOUT & GAME CANVAS ─────────────────────────────────────── */

#game-canvas {
    display: block;
    background-color: var(--black);
}

#ui-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 10;
}

#ui-layer>* {
    pointer-events: auto;
}


/* ─── 5. BUTTONS & INPUTS ─────────────────────────────────────────── */

/* Base button — defaults to the secondary (steel) variant */
button {
    background: var(--btn-secondary-bg);
    border: 0.15rem solid var(--btn-secondary-border);
    border-bottom: 0.25rem solid var(--btn-secondary-border);
    color: var(--btn-secondary-text);
    padding: 0.6rem 1.2rem;
    font-size: 1.1rem;
    text-transform: capitalize;
    cursor: pointer;
    border-radius: 0.3rem;
    transition: transform 0.1s, filter 0.1s;
    box-shadow: 0 0.25rem 0.4rem rgba(0, 0, 0, 0.5);
    text-shadow: 0.1rem 0.1rem 0 var(--black);
    touch-action: manipulation;
    max-width: 100%;
    margin: 0;
}

button:hover {
    filter: brightness(1.2);
}

button:active {
    transform: translateY(0.15rem);
    border-bottom-width: 0.15rem;
}

/* Primary variant — gold. Used in both lobby and pause contexts. */
.lobby-btn-primary,
.pause-btn-primary {
    background: var(--btn-primary-bg) !important;
    border-color: var(--btn-primary-border) !important;
    color: var(--btn-primary-text) !important;
    text-shadow: -0.04rem -0.04rem 0.1rem rgba(0, 0, 0, 0.5), 0.04rem 0.04rem 0.04rem rgba(255, 255, 255, 0.5);
}

.lobby-btn-primary:hover,
.pause-btn-primary:hover {
    filter: brightness(1.15) drop-shadow(0 0 0.4vh rgba(242, 198, 110, 0.6));
}

/* Secondary variant — steel. */
.lobby-btn-secondary,
.pause-btn-secondary {
    background: var(--btn-secondary-bg) !important;
    border-color: var(--btn-secondary-border) !important;
    color: var(--btn-secondary-text) !important;
}

.lobby-btn-secondary:hover,
.pause-btn-secondary:hover {
    filter: brightness(1.1);
}

/* Danger variant — crimson. */
.lobby-btn-danger,
.pause-btn-danger {
    background: var(--btn-danger-bg) !important;
    border-color: var(--btn-danger-border) !important;
    color: var(--btn-danger-text) !important;
}

.lobby-btn-danger:hover,
.pause-btn-danger:hover {
    filter: brightness(1.15);
}

/* Pause buttons override lobby-panel's viewport-relative scaling */
.pause-btn-primary {
    padding: 0.8rem 1.2rem !important;
    font-size: 1.1rem !important;
}

.pause-btn-secondary,
.pause-btn-danger {
    padding: 0.7rem 1rem !important;
    font-size: 1rem !important;
}

/* Inputs & selects */
input,
select {
    background: rgba(0, 0, 0, 0.6);
    border: 0.1rem solid var(--steel-light);
    color: var(--parchment);
    padding: 0.6rem;
    font-family: var(--font-main);
    font-size: 1rem;
    border-radius: 0.15rem;
    max-width: 100%;
    margin: 0;
}


/* ─── 6. LOBBY & GAME-OVER SCREENS ───────────────────────────────── */

#lobby-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: row;
    align-items: stretch;
    justify-content: flex-end;
    background-color: var(--bg);
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    z-index: 100;
}

#lobby-bg-video {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    z-index: 0;
}

.lobby-panel {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    width: 55vh;
    height: 100%;
    padding: 2vh 4vh;
    z-index: 101;
    gap: 1.5vh;
}

.menu-container {
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
    width: 100%;
    flex: 0 1 auto;
    justify-content: flex-start;
}

.join-row {
    display: flex;
    gap: 2vh;
    width: 100%;
}

.join-row input,
.join-row button {
    flex: 1 1 0;
    min-width: 0;
}

/* Viewport-relative scaling for lobby inputs and buttons */
.lobby-panel input,
.lobby-panel select {
    font-size: 3.5vh;
    padding: 1vh;
    border-width: 0.5vh;
    box-shadow: 0 1vh 2vh rgba(0, 0, 0, 0.6);
}

.lobby-panel button {
    font-size: 3vh;
    padding: 0.8vh 1.2vh;
    border-width: 0.4vh;
    box-shadow: 0 0.5vh 1.5vh rgba(0, 0, 0, 0.6);
    transition: all 0.2s ease;
}

.lobby-button-row {
    display: flex;
    gap: 1.2vh;
    width: 100%;
}

.lobby-button-row button {
    flex: 1;
    min-width: 0;
}

.lobby-status {
    color: var(--gold);
    text-align: center;
    min-height: 1.8vh;
    font-size: 2.5vh;
    text-shadow: 0.1rem 0.1rem 0 var(--black);
    margin: 0.5vh 0;
    line-height: 1.2;
}

.lobby-form-group {
    display: flex;
    flex-direction: column;
    width: 100%;
    gap: 0.3vh;
}

.lobby-form-group label {
    font-size: 1.8vh;
    color: var(--parchment-dark);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    opacity: 0.9;
}

#game-logo {
    height: 20vh;
    width: auto;
    filter: drop-shadow(0 0 1vh rgba(0, 0, 0, 0.8));
    align-self: center;
    margin-bottom: 0.5vh;
}

#lobby-footer {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    display: flex;
    justify-content: space-between;
    padding: 1.5vh;
    color: var(--text);
    font-size: 2.5vh;
    text-transform: capitalize;
    letter-spacing: 0.1rem;
    z-index: 102;
}

#game-over-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    pointer-events: auto;
    z-index: 100;
}


/* ─── 7. HUD (HEADS-UP DISPLAY) ───────────────────────────────────── */

#game-timer {
    position: absolute;
    top: 2rem;
    left: 50%;
    transform: translateX(-50%);
    font-size: 1.4rem;
    text-shadow: 0.2rem 0.2rem 0 var(--black);
    background: rgba(0, 0, 0, 0.6);
    border: 0.1rem solid var(--steel-light);
    border-radius: 0.4rem;
}

#loot-notification {
    position: absolute;
    top: 10rem;
    left: 50%;
    transform: translateX(-50%);
    color: var(--gold);
    font-size: 2.2rem;
    text-shadow: 0.15rem 0.15rem 0 var(--black);
    pointer-events: none;
    transition: opacity 0.5s;
    opacity: 0;
    z-index: 20;
}

#bottom-hud {
    position: absolute;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: row;
    align-items: flex-end;
    gap: 1.5rem;
    justify-content: center;
    width: auto;
    max-width: 98%;
    pointer-events: none;
    z-index: 100;
}

#hud-panel {
    display: flex;
    flex-direction: column;
    background: linear-gradient(180deg, rgba(20, 20, 20, 0.95) 0%, rgba(10, 10, 10, 0.98) 100%);
    border: 0.2rem solid var(--border);
    border-top: 0.25rem solid var(--steel-light);
    border-radius: 0.6rem;
    pointer-events: auto;
    box-shadow: 0 1.5rem 3rem rgba(0, 0, 0, 0.95), inset 0 0 1rem rgba(255, 255, 255, 0.05);
}

/* Resource bars */
#resource-bars {
    display: flex;
    flex-direction: column;
    width: 100%;
    min-width: clamp(300px, 25vw, 600px);
    background: var(--black);
    border: 0.2rem solid var(--steel);
    padding: 0.2rem;
    gap: 0.1rem;
    pointer-events: auto;
}

.bar-row {
    position: relative;
    width: 100%;
    height: 1.6rem;
    background: var(--bg);
    border-radius: 0.2rem;
    overflow: hidden;
    box-shadow: inset 0 0.2rem 0.5rem rgba(0, 0, 0, 0.8);
    border: 0.1rem solid var(--steel-dark);
}

.bar-fill {
    height: 100%;
    transition: width 0.1s;
}

.hp-fill {
    background: linear-gradient(to bottom, var(--hp), var(--danger), var(--danger-dark));
    box-shadow: inset 0 0.2rem 0.2rem rgba(255, 255, 255, 0.2), 0 0 1rem rgba(179, 0, 0, 0.3);
}

.mana-fill {
    background: linear-gradient(to bottom, #0055ff, #0033aa, #002288);
    box-shadow: inset 0 0.2rem 0.2rem rgba(255, 255, 255, 0.2), 0 0 1rem rgba(0, 85, 255, 0.3);
}

.bar-text {
    position: absolute;
    inset: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1rem;
    color: var(--white);
    text-shadow: 0.1rem 0.1rem 0 var(--black);
    font-family: sans-serif;
    /* intentional: sans-serif for legibility in tight bars */
    font-weight: bold;
}

/* Action bar */
#action-bar {
    display: flex;
    justify-content: center;
    flex-wrap: nowrap;
    pointer-events: auto;
}

.action-slot {
    flex: 0 0 var(--slot-size);
    width: var(--slot-size);
    height: var(--slot-size);
    background: linear-gradient(135deg, var(--steel-dark) 0%, var(--black) 100%);
    border: 0.15rem solid var(--steel);
    border-radius: 0.2rem;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    cursor: pointer;
    transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: inset 0 0 0.8rem rgba(0, 0, 0, 0.8), 0 0.2rem 0.4rem rgba(0, 0, 0, 0.5);
}

.action-slot:hover {
    border-color: var(--gold);
    background-color: var(--steel-dark);
    box-shadow: inset 0 0 0.4rem rgba(0, 0, 0, 0.4), 0 0 0.6rem rgba(242, 198, 110, 0.5);
}

.action-slot:active,
.action-slot.pressed {
    transform: scale(0.93);
    border-color: var(--gold);
    background-color: rgba(242, 198, 110, 0.15);
    box-shadow: inset 0 0 0.8rem rgba(0, 0, 0, 0.6), 0 0 1rem rgba(255, 215, 0, 0.7);
}

.action-slot.active {
    border-color: var(--gold);
    box-shadow: 0 0 0.8rem var(--gold);
}

.action-slot .key-label {
    position: absolute;
    top: 0.15rem;
    left: 0.2rem;
    font-size: 0.75rem;
    color: var(--steel-light);
    pointer-events: none;
    z-index: 5;
    text-shadow: 0.1rem 0.1rem 0.2rem var(--black);
    opacity: 0.8;
}

.action-slot .item-icon {
    width: 90%;
    height: 90%;
    object-fit: contain;
}

.cooldown-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: bold;
    font-size: 1.1rem;
    text-shadow: 0 0 0.5rem var(--black), 0 0 1rem var(--black);
    pointer-events: none;
    z-index: 10;
}

/* HUD icon buttons (inventory toggle, map, etc.) */
.hud-btn {
    width: var(--slot-size);
    height: var(--slot-size);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border-radius: 0.5rem;
    background: rgba(0, 0, 0, 0.6);
    border: 0.2rem solid var(--steel-light);
    color: var(--parchment);
    cursor: pointer;
    pointer-events: auto;
    box-shadow: 0 0.4rem 0.8rem rgba(0, 0, 0, 0.5);
}

.hud-btn svg {
    width: 60%;
    height: 60%;
}

.hud-btn:hover {
    background: rgba(0, 0, 0, 0.8);
    border-color: var(--gold);
}

.hud-btn.active {
    border-color: var(--gold);
    box-shadow: 0 0 1.2rem var(--gold);
}

/* Tooltip */
#game-tooltip {
    position: absolute;
    display: none;
    padding: 2rem;
    background: rgba(10, 10, 10, 0.98);
    color: var(--text);
    border: 0.3rem solid var(--gold);
    border-radius: 0.8rem;
    pointer-events: none;
    z-index: 9999;
    font-size: 1.3rem;
    box-shadow: 0 1.5rem 3rem rgba(0, 0, 0, 1);
    max-width: 40rem;
    white-space: normal;
}

.tooltip-title {
    font-size: 1.6rem;
    color: var(--gold);
    margin-bottom: 0.8rem;
    border-bottom: 0.1rem solid var(--steel);
}

.tooltip-body {
    font-size: 1.2rem;
    line-height: 1.5;
}

/* Stat rows (game-over screen / character sheet) */
#stats-bar {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    font-size: 1.4rem;
    color: var(--parchment);
    text-shadow: 0.1rem 0.1rem 0 var(--black);
}


/* ─── 8. MODALS & PANELS ──────────────────────────────────────────── */

/* Slide-in side panels */
.gothic-panel {
    position: absolute;
    top: 0;
    bottom: 0;
    width: var(--panel-width);
    background: rgba(15, 15, 15, 0.95);
    border: 0.2rem solid var(--border);
    box-shadow: inset 0 0 3rem var(--black), 0 0 1.5rem var(--black);
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease;
    z-index: 1500;
    padding: 0.8rem;
    pointer-events: auto;
    overflow: hidden;
}

#left-panel {
    left: 0;
    transform: translateX(-100%);
    border-left: none;
}

#right-panel {
    right: 0;
    transform: translateX(100%);
    border-right: none;
}

#left-panel.open,
#right-panel.open {
    transform: translateX(0);
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 0.15rem solid var(--border);
    margin-bottom: 0.6rem;
    padding-bottom: 0.5rem;
    flex-shrink: 0;
}

.panel-header h2 {
    margin: 0;
    font-size: 1.4rem;
    color: var(--gold);
    text-shadow: 0.1rem 0.1rem 0 var(--black);
}

.panel-body {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow-y: auto;
    gap: 0.5rem;
    min-height: 0;
}

/* Close button — shared across all panels and modals */
.close-btn {
    background: none;
    border: 0.1rem solid var(--border);
    color: var(--steel-light);
    cursor: pointer;
    padding: 0.3rem 0.6rem;
    font-size: 1.2rem;
    line-height: 1;
    border-radius: 0.2rem;
    transition: all 0.2s;
}

.close-btn:hover {
    color: var(--gold);
    border-color: var(--gold);
    background: rgba(242, 198, 110, 0.1);
}

.close-btn:active {
    transform: scale(0.9);
}

/* Parchment-style modals (inventory) */
#inventory-modal {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--parchment);
    border: 0.6rem solid var(--steel);
    border-radius: 1rem;
    padding: 2.5rem;
    color: var(--text-dark);
    box-shadow: 0 0 0 0.3rem var(--danger), 0 3rem 8rem rgba(0, 0, 0, 1);
    min-width: var(--panel-width);
    max-width: 90%;
    z-index: 2500;
    pointer-events: auto;
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

/* Ground loot — dark style anchored above the action bar, matching chest modal */
#ground-loot-modal {
    position: absolute;
    bottom: calc(var(--slot-size) + 3rem);
    left: 50%;
    transform: translateX(-50%);
    background: linear-gradient(135deg, var(--modal-bg-start), var(--modal-bg-end));
    border: 0.2rem solid var(--modal-border);
    border-radius: 0.8rem;
    padding: 1.5rem;
    color: var(--text);
    box-shadow: var(--modal-shadow);
    max-width: 90%;
    z-index: 2500;
    pointer-events: auto;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

#inventory-modal {
    max-height: 90vh;
    overflow-y: auto;
}

/* Dark-style modals (pause menu, settings) */
#pause-menu,
#settings-modal {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: linear-gradient(135deg, var(--modal-bg-start), var(--modal-bg-end));
    border: 0.2rem solid var(--modal-border);
    border-radius: 0.8rem;
    color: var(--text);
    box-shadow: var(--modal-shadow);
    max-width: 90%;
    z-index: 2500;
    pointer-events: auto;
    display: flex;
    flex-direction: column;
    padding: 1.5rem;
}

#pause-menu {
    min-width: clamp(300px, 35vw, 500px);
    gap: 1rem;
}

#settings-modal {
    min-width: clamp(320px, 40vw, 540px);
    gap: 0;
}

/* Chest loot — anchored above the action bar */
#chest-loot-modal {
    position: absolute;
    bottom: calc(var(--slot-size) + 3rem);
    left: 50%;
    transform: translateX(-50%);
    background: linear-gradient(135deg, var(--modal-bg-start), var(--modal-bg-end));
    border: 0.2rem solid var(--modal-border);
    border-radius: 0.8rem;
    padding: 1.5rem;
    color: var(--text);
    box-shadow: var(--modal-shadow);
    max-width: 90%;
    z-index: 2500;
    pointer-events: auto;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

/* Modal header — shared base */
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.2rem;
    border-bottom: 0.1rem solid var(--border);
    padding-bottom: 0.8rem;
}

.modal-header h3 {
    margin: 0;
    font-size: var(--font-size-header);
    color: var(--modal-header-color);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-family: var(--font-main);
}

/* Parchment modals use inv-tint for the header divider */
#inventory-modal .modal-header {
    border-bottom-color: var(--inv-tint);
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
}

/* Settings modal internals */
.settings-content {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    overflow-y: visible;
    flex: 0 1 auto;
}

.settings-section-label {
    font-size: var(--font-size-small);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--gold);
    margin: 0.3rem 0;
    opacity: 0.8;
}

.settings-group {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

/* Shared label style for settings rows and checkboxes */
.settings-group label,
.settings-checkbox label {
    font-size: var(--font-size-label);
    color: var(--text);
}

.settings-slider {
    width: 100%;
    height: 0.25rem;
    accent-color: var(--gold);
}

.slider-labels {
    display: flex;
    justify-content: space-between;
    font-size: 0.65rem;
    color: var(--steel-light);
    margin-top: 0.15rem;
}

.settings-checkbox {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    margin: 0.2rem 0;
}

.settings-checkbox input[type="checkbox"] {
    width: 0.9rem;
    height: 0.9rem;
    cursor: pointer;
}

.settings-checkbox label {
    cursor: pointer;
}

.settings-divider {
    height: 0.1rem;
    background: var(--border);
    margin: 0.3rem 0;
}

.settings-btn {
    background: linear-gradient(180deg, var(--danger-dark), var(--danger));
    border: 0.1rem solid var(--border);
    color: var(--parchment);
    padding: 0.7rem 1rem;
    font-size: 1rem;
    border-radius: 0.3rem;
    cursor: pointer;
    transition: filter 0.2s;
    margin-top: 0.5rem;
}

.settings-btn:hover {
    filter: brightness(1.15);
}

.settings-btn:active {
    transform: translateY(0.1rem);
}


/* ─── 9. INVENTORY & EQUIPMENT ────────────────────────────────────── */

#inventory-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0;
    margin: 0.4rem 0 0;
    background: var(--inv-tint);
    border: 1px solid var(--inv-tint);
    border-radius: 0.3rem;
    overflow: hidden;
}

#ground-grid,
#chest-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 0;
    margin: 0.5rem 0;
    background: var(--inv-tint);
    border: 1px solid var(--inv-tint);
    border-radius: 0.3rem;
    overflow: hidden;
}

.equipment-slots {
    display: grid;
    grid-template-areas:
        ". head ."
        "weapon torso arms"
        ". legs .";
    grid-template-columns: 1fr 1fr 1fr;
    gap: 0.3rem;
    padding: 0.3rem 0;
    justify-items: center;
    align-items: center;
    flex-shrink: 0;
}

.equip-cell {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.2rem;
}

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

.equip-cell[data-area="weapon"] {
    grid-area: weapon;
}

.equip-cell[data-area="torso"] {
    grid-area: torso;
}

.equip-cell[data-area="arms"] {
    grid-area: arms;
}

.equip-cell[data-area="legs"] {
    grid-area: legs;
}

.slot-label {
    font-size: 0.6rem;
    color: var(--gold);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    opacity: 0.6;
    pointer-events: none;
}

.inv-slot {
    aspect-ratio: 1;
    width: 100%;
    background: rgba(0, 0, 0, 0.3);
    border-right: 1px solid var(--inv-tint);
    border-bottom: 1px solid var(--inv-tint);
    border-top: none;
    border-left: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.1s;
}

#inventory-grid .inv-slot:nth-child(4n) {
    border-right: none;
}

#inventory-grid .inv-slot:nth-last-child(-n+4) {
    border-bottom: none;
}

#chest-grid .inv-slot:nth-child(5n),
#ground-grid .inv-slot:nth-child(5n) {
    border-right: none;
}

#chest-grid .inv-slot:nth-last-child(-n+5),
#ground-grid .inv-slot:nth-last-child(-n+5) {
    border-bottom: none;
}

.inv-slot:hover {
    background: rgba(255, 255, 255, 0.06);
}

.equip-slot {
    width: var(--equipment-slot-size);
    height: var(--equipment-slot-size);
    background: rgba(0, 0, 0, 0.25);
    border: 0.15rem solid var(--parchment-dark);
    border-radius: 0.3rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.1s;
}

.equip-slot:hover {
    background: rgba(0, 0, 0, 0.45);
    border-color: var(--danger);
}

.item-icon {
    width: 85%;
    height: 85%;
    object-fit: contain;
    position: relative;
    pointer-events: auto;
    image-rendering: pixelated;
}

/* Arms slot: zoomed to show only the right gauntlet */
.item-icon.slot-arms {
    background-size: 210% !important;
    background-position: -7.5% center !important;
}

.item-sprite {
    width: 100%;
    height: 100%;
    object-fit: contain;
    image-rendering: pixelated;
    pointer-events: none;
}

.item-count {
    position: absolute;
    bottom: 0.3rem;
    right: 0.4rem;
    font-size: 0.85rem;
    color: var(--white);
    text-shadow: 0.12rem 0.12rem 0 var(--black);
    font-weight: bold;
}

.inventory-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 0.5rem;
    margin-top: 0.5rem;
    border-top: 0.1rem solid var(--inv-tint);
}

#btn-auto-sort {
    font-size: 0.85rem;
    padding: 0.3rem 0.7rem;
    background: rgba(0, 0, 0, 0.4);
    border: 0.12rem solid var(--parchment-dark);
    border-radius: 0.3rem;
    color: var(--parchment);
    cursor: pointer;
    transition: all 0.2s;
}

#btn-auto-sort:hover {
    border-color: var(--danger);
    background: rgba(0, 0, 0, 0.6);
    color: var(--gold);
}

.gold-display {
    font-size: var(--font-size-label);
    color: var(--gold);
    font-weight: bold;
}


/* ─── 10. ACTIVITY LOG & NOTIFICATIONS ────────────────────────────── */

#activity-log {
    position: absolute;
    top: 6rem;
    right: 2rem;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.8rem;
    pointer-events: none;
    z-index: 100;
}

.activity-msg {
    background: rgba(0, 0, 0, 0.7);
    color: var(--text);
    padding: 0.8rem 1.5rem;
    border-left: 0.4rem solid var(--danger);
    font-size: 1.4rem;
    animation: fadeOut 5s forwards;
}


/* ─── 11. MOBILE CONTROLS ──────────────────────────────────────────── */

#mobile-controls {
    display: none;
    /* Shown via JS when a touch device is detected */
}


/* ─── 12. LOGIN FORM ───────────────────────────────────────────────── */

#login-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.8);
    z-index: 5000;
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: 2rem;
    padding: 3rem;
    background: var(--steel);
    border: 0.3rem solid var(--steel-dark);
    border-radius: 1rem;
    box-shadow: 0 2rem 5rem rgba(0, 0, 0, 0.9);
    width: 100%;
    max-width: 35rem;
}

.login-form.embedded {
    background: transparent;
    box-shadow: none;
    border: none;
    padding: 0;
    max-width: 100%;
}

.login-form h2 {
    color: var(--gold);
    text-align: center;
    margin: 0 0 1.5vh;
    font-size: 4rem;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.5vh;
}

.form-group label {
    font-size: 1.4rem;
    color: var(--parchment-dark);
}

.form-group input {
    font-size: 3.5vh !important;
    padding: 1.2vh !important;
}

.form-group input::placeholder {
    font-size: 3.5vh;
    opacity: 0.6;
}

.login-buttons {
    display: flex;
    gap: var(--spacing-sm);
    margin-top: var(--spacing-sm);
}

.login-buttons button {
    flex: 1;
    font-size: 3vh;
    padding: 1vh;
}

.forgot-password {
    font-size: 2.2vh;
    text-align: center;
    margin-top: 0.5vh;
}

.forgot-password a {
    color: var(--gold);
    text-decoration: none;
    cursor: pointer;
    transition: opacity 0.2s;
}

.forgot-password a:hover {
    opacity: 0.8;
    text-decoration: underline;
}

#login-error {
    color: var(--danger);
    text-align: center;
    min-height: 2.5vh;
    font-size: 2.2vh;
    margin-bottom: 0.5vh;
}


/* ─── 13. RESPONSIVE / MEDIA QUERIES ──────────────────────────────── */

@media (max-width: 768px) {
    #lobby-screen {
        justify-content: center;
        align-items: stretch;
        background-position: 20% center;
    }

    #lobby-bg-video {
        object-position: 14%;
    }

    .lobby-panel {
        width: 100%;
        height: 100%;
        border-left: none;
        padding: 2vh 5vw 8vh 5vw;
        justify-content: flex-start;
    }

    .menu-container {
        max-height: 100%;
    }

    #game-logo {
        max-width: 100%;
        height: auto;
        max-height: 25vh;
        margin-bottom: 1vh;
    }

    .lobby-panel input,
    .lobby-panel select {
        font-size: 3vh;
        padding: 1vh;
    }

    .lobby-panel button {
        font-size: 2.5vh;
        padding: 0.8vh 1vh;
    }

    #settings-modal {
        min-width: 90%;
        max-width: 95%;
        max-height: 85vh;
    }

    #inventory-modal,
    #ground-loot-modal,
    #pause-menu {
        min-width: 90%;
        max-width: 95%;
    }
}

@media (orientation: portrait) {
    .gothic-panel {
        width: 100%;
        border: none;
        padding-top: 6rem;
    }
}