:root {
    --bg-base: #EBE5D9;
    --text-main: #0F0F0F;
    --text-muted: #4A4A4A;
    --border-main: #0F0F0F;

    --accent-red: #8A0303;
    --accent-orange: #A04000;
    --accent-blue: #2A3439;

    --font-narrative: 'Courier Prime', monospace;
    --font-header: 'Special Elite', cursive;
}

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

body {
    background-color: var(--bg-base);
    color: var(--text-main);
    font-family: var(--font-narrative);
    line-height: 1.5;
    height: 100vh;
    overflow: hidden;
    position: relative;
}

/* Gritty Noise Overlay */
.noise-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    z-index: 9999;
    background: transparent;
    opacity: 0.7;
    mix-blend-mode: multiply;
}

.noise-overlay::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    filter: url(#noiseFilter);
}

#app {
    width: 100%;
    height: 100%;
    display: flex;
    position: relative;
    z-index: 1;
}

/* Intro Screen */
.intro-screen {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    overflow-y: auto;
    background-color: var(--bg-base);
}

.intro-panel-container {
    width: 100%;
    max-width: 1200px;
    border: 6px solid var(--border-main);
    background: #fff;
    box-shadow: 8px 8px 0 rgba(0, 0, 0, 1);
    display: flex;
    flex-direction: column;
    animation: stampIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
    transform: rotate(0.5deg);
    margin-bottom: 2rem;
}

.intro-panel-img-wrapper {
    width: 100%;
    border-bottom: 4px solid var(--border-main);
}

.intro-panel-img-wrapper img {
    width: 100%;
    display: block;
    aspect-ratio: 3/1;
    object-fit: cover;
    filter: contrast(1.2);
    mix-blend-mode: multiply;
}

.intro-text-box {
    padding: 2rem;
    font-family: var(--font-narrative);
    font-size: 1.4rem;
    font-weight: bold;
    color: var(--text-main);
    background-image: repeating-linear-gradient(0deg, transparent, transparent 27px, rgba(0, 0, 0, 0.05) 28px);
    background-size: 100% 28px;
    line-height: 1.6;
}

.intro-actions {
    margin-top: 1rem;
    display: flex;
    justify-content: flex-end;
    width: 100%;
    max-width: 1200px;
}


/* Character Select Screen */
.char-select-screen {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    padding: 2rem;
    overflow-y: auto;
}


.char-cards-container {
    display: flex;
    gap: 2rem;
    width: 100%;
    max-width: 1200px;
    height: 100%;
    max-height: 800px;
    margin: 0 auto;
    justify-content: center;
    flex-wrap: wrap;
    align-items: stretch;
}

.char-card {
    flex: 1;
    min-width: 300px;
    max-width: 350px;
    background-color: var(--bg-base);
    border: 3px solid var(--border-main);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
    box-shadow: 4px 4px 0px rgba(0, 0, 0, 0.8), inset 0 0 10px rgba(0, 0, 0, 0.1);
    transition: transform 0.1s, box-shadow 0.1s;
    height: 100%;
    min-height: 500px;
}

.char-card:hover {
    transform: translate(-2px, -2px);
    box-shadow: 6px 6px 0px rgba(0, 0, 0, 0.9), inset 0 0 10px rgba(0, 0, 0, 0.1);
}

.char-card:active {
    transform: translate(2px, 2px);
    box-shadow: 1px 1px 0px rgba(0, 0, 0, 0.9), inset 0 0 5px rgba(0, 0, 0, 0.1);
}

.char-card:hover .char-portrait {
    filter: contrast(1.2) grayscale(0%);
}

.char-portrait {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    object-fit: cover;
    object-position: top center;
    border-bottom: none;
    filter: contrast(1.2) grayscale(100%);
    mix-blend-mode: multiply;
    z-index: 1;
    transition: filter 0.3s ease;
}

.char-info-box {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 400px;
    z-index: 2;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    background: rgba(235, 229, 217, 0.9);
    border-top: 3px solid var(--border-main);
    box-shadow: 0 -4px 10px rgba(0, 0, 0, 0.1);
    backdrop-filter: blur(2px);
}

.char-name {
    font-family: var(--font-header);
    font-size: 1.5rem;
    font-weight: 700;
    text-transform: uppercase;
    margin-bottom: 0.25rem;
    line-height: 1.1;
}

.char-subtitle {
    font-family: var(--font-header);
    font-weight: bold;
    font-size: 1.1rem;
    color: var(--text-main);
    margin-bottom: 0.75rem;
}

.char-summary {
    font-size: 0.95rem;
    font-weight: bold;
    flex-grow: 1;
    margin-bottom: 1.5rem;
}

.char-stats-preview {
    margin-top: auto;
    padding-top: 0.75rem;
    font-family: var(--font-header);
    font-weight: bold;
    font-size: 0.95rem;
    text-align: center;
}

/* Game Screen Layout */
.game-screen {
    display: flex;
    width: 100%;
    height: 100%;
    position: relative;
}

.room-roster {
    position: absolute;
    top: 20px;
    bottom: 20px;
    /* Provides a lower bound to enforce scrolling */
    /* Below the pinned location header */
    left: 20px;
    display: flex;
    flex-direction: column;
    gap: 15px;
    z-index: 10;
    overflow-y: auto;
    padding-right: 15px;
    /* Gap for scrollbar */
    padding-bottom: 20px;
    /* So the bottom item isn't flush */
    scrollbar-width: thin;
    /* Firefox */
    scrollbar-color: var(--border-main) transparent;
}

.room-roster::-webkit-scrollbar {
    width: 6px;
}

.room-roster::-webkit-scrollbar-track {
    background: transparent;
    border-left: none;
}

.room-roster::-webkit-scrollbar-thumb {
    background: var(--border-main);
    border-radius: 3px;
}


.roster-portrait {
    width: 70px;
    height: 70px;
    object-fit: cover;
    border: 3px solid var(--border-main);
    filter: contrast(1.2);
    mix-blend-mode: multiply;
    background-color: #fff;
    box-shadow: 2px 2px 0 rgba(0, 0, 0, 0.9);
    transition: transform 0.1s, box-shadow 0.1s;
}

.roster-portrait:hover {
    transform: translate(-1px, -1px);
    box-shadow: 3px 3px 0 rgba(0, 0, 0, 1);
}

.roster-active {
    filter: contrast(1.2);
    box-shadow: 3px 3px 0 var(--accent-red);
    border-color: var(--accent-red);
}

.roster-disabled {
    filter: contrast(1.5) brightness(0.3);
    opacity: 0.5;
    box-shadow: none;
    border-style: dashed;
    pointer-events: none;
}

.main-column {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    border-right: 4px solid var(--border-main);
    background: #FFF;
    background-image: repeating-linear-gradient(0deg, transparent, transparent 27px, rgba(0, 0, 0, 0.05) 28px);
    background-size: 100% 28px;
    position: relative;
}

.sidebar-column {
    width: 320px;
    flex-shrink: 0;
    background-color: var(--bg-base);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    border-left: 2px dashed var(--border-main);
    margin-left: -4px;
    /* overlap border intentionally for grimy offset */
}

/* History Area */
.history-area {
    flex-grow: 1;
    overflow-y: auto;
    padding: 0;
    display: flex;
    flex-direction: column;
    scroll-behavior: smooth;
    position: relative;
}

/* Location Header Pinned at Top */
.location-header-pinned {
    width: 100%;
    border-bottom: 4px solid var(--border-main);
    position: relative;
    background: #000;
    display: flex;
    flex-shrink: 0;
}

.location-header-pinned img {
    width: 100%;
    height: 200px;
    object-fit: cover;
    opacity: 0.9;
    filter: contrast(1.5);
    display: block;
}

.location-img-wrapper {
    width: 70%;
    position: relative;
    border-right: 4px solid var(--border-main);
}

.location-pinned-info {
    width: 30%;
    background: var(--bg-base);
    padding: 1rem;
    display: flex;
    flex-direction: column;
}

.location-title {
    font-family: var(--font-header);
    font-size: 1.8rem;
    font-weight: bold;
    text-transform: uppercase;
    margin-bottom: 0.5rem;
    border-bottom: 2px dashed var(--border-main);
    padding-bottom: 0.5rem;
}

.location-connections-label {
    font-size: 0.8rem;
    font-weight: bold;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-top: 0.5rem;
}

.location-connections-list {
    list-style: none;
    margin-top: 0.5rem;
    font-size: 0.9rem;
    font-weight: bold;
    flex-grow: 1;
}

.location-connections-list li {
    padding: 0.2rem 0;
    cursor: pointer;
}

.location-connections-list li::before {
    content: ">> ";
    color: var(--accent-red);
}

.location-connections-list li:hover {
    color: var(--accent-red);
}

.beat {
    padding: 0 15%;
    margin-top: 2rem;
    margin-bottom: 2rem;
    animation: stampIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

@keyframes stampIn {
    0% {
        transform: scale(0.95) rotate(-1deg);
        opacity: 0;
    }

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

/* Player Input Echo */
.player-input-echo {
    padding: 0 15%;
    margin-top: 2rem;
    margin-bottom: -1rem;
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--text-main);
    font-family: var(--font-narrative);
    animation: stampIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
    position: relative;
    z-index: 5;
}

.player-input-caret {
    color: var(--accent-red);
    font-family: var(--font-header);
    margin-right: 0.5rem;
    font-weight: bold;
    font-size: 1.4rem;
}

.player-action {
    color: var(--text-main);
}

.player-dialogue {
    color: var(--accent-red);
    font-family: var(--font-header);
    font-size: 1.3rem;
    text-shadow: 1px 1px 0px rgba(0, 0, 0, 0.2);
}

.npc-dialogue {
    font-family: var(--font-header);
    font-size: 1.15rem;
    color: var(--text-main);
    font-weight: bold;
}

/* Typewriter text styling for narration */
.beat-narration {
    font-size: 1.1rem;
    color: var(--text-main);
    font-weight: 600;
}

.beat-narration p {
    margin-bottom: 1.2rem;
}

.beat-narration p:last-child {
    margin-bottom: 0;
}

.beat-suggestion {
    display: inline-block;
    font-family: var(--font-header);
    font-size: 0.85rem;
    color: var(--accent-blue);
    border: 2px solid var(--accent-blue);
    padding: 0.4rem 0.75rem;
    margin-top: 1rem;
    /* simulated stamp effect */
    transform: rotate(-1deg);
    background: rgba(255, 255, 255, 0.8);
    box-shadow: 2px 2px 0px rgba(0, 0, 0, 0.1);
}

.roll-banner {
    background-color: var(--bg-base);
    border: 3px solid var(--border-main);
    padding: 1rem 1.5rem;
    font-family: var(--font-narrative);
    font-size: 0.95rem;
    font-weight: bold;
    margin-top: 1.5rem;
    margin-bottom: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    box-shadow: 4px 4px 0 rgba(0, 0, 0, 1);
    transform: rotate(0.5deg);
}

.roll-banner.success {
    border-color: var(--border-main);
    background: #eee;
}

.roll-banner.failure {
    border-color: var(--accent-red);
    background: rgba(138, 3, 3, 0.1);
}

.roll-banner.critical {
    border-color: var(--border-main);
    background: #000;
    color: #fff;
}

.roll-banner.critical .stat-name,
.roll-banner.critical .target-val,
.roll-banner.critical .roll-val {
    color: #fff;
}

.roll-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.roll-row .stat-name {
    text-transform: uppercase;
    font-family: var(--font-header);
}

.roll-row .target-val {
    opacity: 0.7;
}

.roll-row .roll-val {
    background: rgba(0, 0, 0, 0.1);
    padding: 0.1rem 0.4rem;
    border: 1px solid currentColor;
}

.roll-row .result-bad {
    color: var(--accent-red);
    font-family: var(--font-header);
    font-size: 1.2rem;
}

.roll-row .result-good {
    font-family: var(--font-header);
    font-size: 1.2rem;
}

.roll-row .result-crit {
    color: #fff;
    text-shadow: 1px 1px 0 red, -1px -1px 0 blue;
    font-family: var(--font-header);
    font-size: 1.2rem;
    letter-spacing: 2px;
}


/* Input Area */
.input-area-container {
    border-top: 4px solid var(--border-main);
    background-color: var(--bg-base);
    padding: 1.5rem 15%;
    flex-shrink: 0;
    box-shadow: 0 -5px 0px rgba(0, 0, 0, 1);
    z-index: 10;
}

.input-prompt-label {
    font-family: var(--font-header);
    font-size: 1rem;
    font-weight: bold;
    text-transform: uppercase;
    margin-bottom: 0.75rem;
    display: flex;
    justify-content: space-between;
    border-bottom: 2px solid var(--border-main);
    padding-bottom: 0.5rem;
}

.action-input-wrapper {
    display: flex;
    gap: 1rem;
    align-items: stretch;
}

.input-field-container {
    flex-grow: 1;
    display: flex;
    align-items: center;
    background-color: #fff;
    border: 3px solid var(--border-main);
    padding: 0 1rem;
    box-shadow: inset 2px 2px 5px rgba(0, 0, 0, 0.2);
}

.prompt-caret {
    font-family: var(--font-header);
    color: var(--accent-red);
    margin-right: 0.75rem;
    font-weight: bold;
    font-size: 1.2rem;
}

.action-input {
    flex-grow: 1;
    background: transparent;
    border: none;
    color: var(--text-main);
    font-family: var(--font-narrative);
    font-size: 1.1rem;
    font-weight: bold;
    padding: 1rem 0;
    outline: none;
}

.action-input::placeholder {
    color: #888;
    font-style: italic;
}

.btn {
    font-family: var(--font-header);
    font-size: 1rem;
    text-transform: uppercase;
    padding: 0 1.5rem;
    border: 3px solid var(--border-main);
    background: #fff;
    color: var(--text-main);
    cursor: pointer;
    font-weight: bold;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: 3px 3px 0 rgba(0, 0, 0, 1);
    transition: transform 0.1s, box-shadow 0.1s;
}

.btn:hover {
    background: var(--text-main);
    color: #fff;
}

.btn:active {
    transform: translate(2px, 2px);
    box-shadow: 1px 1px 0 rgba(0, 0, 0, 1);
}

.btn-wait {
    font-style: italic;
    background: #eee;
}

.btn-continue {
    width: 100%;
    background: var(--border-main);
    color: #fff;
    font-size: 1.2rem;
}

.btn-continue:hover {
    background: #fff;
    color: var(--border-main);
}

/* Hints / Suggestions */
.input-hints {
    font-family: var(--font-narrative);
    font-size: 0.9rem;
    color: var(--text-main);
    margin-bottom: 1rem;
    padding: 0.75rem;
    border: 2px dashed var(--border-main);
    background: rgba(255, 255, 255, 0.5);
}

.hints-title {
    font-family: var(--font-header);
    font-weight: bold;
    color: var(--accent-red);
    margin-right: 0.5rem;
}

.hint-text {
    font-style: italic;
    color: #000;
    text-decoration: underline;
    cursor: pointer;
}

.hint-bracket {
    font-style: normal;
    color: var(--text-main);
}



.hint-divider {
    color: var(--border-main);
    margin: 0 0.5rem;
    font-weight: bold;
}

/* Sidebar Character Sheet */
.sheet-header {
    padding: 1.5rem;
    border-bottom: 4px solid var(--border-main);
    background: var(--bg-base);
    position: sticky;
    top: 0;
    z-index: 10;
    overflow: hidden;
}

.sheet-name {
    position: relative;
    z-index: 1;
    font-family: var(--font-header);
    font-size: 1.6rem;
    font-weight: bold;
    text-transform: uppercase;
    margin-bottom: 0.25rem;
    line-height: 1.2;
}

.sheet-portrait {
    position: absolute;
    top: 0;
    right: 0;
    height: 100%;
    width: 110px;
    object-fit: cover;
    object-position: center 20%;
    filter: contrast(1.2) grayscale(100%);
    mix-blend-mode: multiply;
    opacity: 0.25;
    z-index: 0;
    pointer-events: none;
    -webkit-mask-image: linear-gradient(to right, transparent 0%, black 70%);
    mask-image: linear-gradient(to right, transparent 0%, black 70%);
}

.sheet-concept {
    position: relative;
    z-index: 1;
    font-weight: bold;
    font-style: italic;
    font-size: 0.9rem;
}

.sheet-section {
    padding: 1.5rem;
    border-bottom: 2px dashed var(--border-main);
}

.sheet-section:last-child {
    border-bottom: none;
}

.sheet-section-title {
    font-family: var(--font-header);
    font-size: 1.1rem;
    font-weight: bold;
    text-transform: uppercase;
    margin-bottom: 1rem;
    background: var(--border-main);
    color: #fff;
    padding: 0.2rem 0.5rem;
    display: inline-block;
    transform: rotate(-1deg);
}

.stat-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.5rem;
    font-weight: bold;
}

.stat-label {
    text-transform: uppercase;
}

.stat-val {
    font-family: var(--font-header);
    font-size: 1.2rem;
}

/* Stat Categories */
.stat-category-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.5rem;
    margin-top: 1rem;
    font-weight: bold;
    border-bottom: 2px solid var(--border-main);
    padding-bottom: 0.2rem;
}

.stat-category-row:first-child {
    margin-top: 0;
}

.stat-category-label {
    text-transform: uppercase;
    font-family: var(--font-header);
    font-size: 1.1rem;
}

.stat-category-val {
    font-family: var(--font-header);
    font-size: 1.2rem;
}

.skill-row {
    padding-left: 1.5rem;
    margin-bottom: 0.25rem;
}

.special-skill {
    font-family: var(--font-header);
    color: var(--text-main);
    cursor: help;
    border-bottom: 2px dotted var(--text-main);
    position: relative;
}

.custom-tooltip {
    position: fixed;
    background: #000;
    color: #fff;
    padding: 0.75rem;
    font-family: var(--font-narrative);
    font-size: 0.9rem;
    max-width: 250px;
    z-index: 10000;
    pointer-events: none;
    display: none;
    box-shadow: 4px 4px 0 rgba(0, 0, 0, 0.5);
    border: 1px solid #444;
    line-height: 1.4;
}

.status-pills {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.pill {
    font-family: var(--font-header);
    font-size: 0.85rem;
    text-transform: uppercase;
    padding: 0.2rem 0.5rem;
    border: 2px solid var(--border-main);
    font-weight: bold;
    background: #fff;
    box-shadow: 2px 2px 0 rgba(0, 0, 0, 1);
}

.pill.negative {
    border-color: var(--accent-red);
    color: var(--accent-red);
}

.health-bar-container {
    background: #fff;
    height: 12px;
    border: 2px solid var(--border-main);
    margin-top: 0.5rem;
}

.health-bar-fill {
    height: 100%;
    background: var(--accent-red);
    width: 100%;
    transition: width 0.3s ease;
}

.inventory-list {
    list-style: none;
}

.inventory-list li {
    font-weight: bold;
    padding: 0.5rem 0;
    border-bottom: 1px dotted var(--border-main);
}

.inventory-list li:last-child {
    border-bottom: none;
}

.spectacle-img {
    width: 100%;
    max-height: 280px;
    object-fit: cover;
    border: 4px solid var(--border-main);
    margin: 1rem 0 2rem 0;
    filter: contrast(1.5);
    box-shadow: 6px 6px 0 rgba(0, 0, 0, 1);
    transform: rotate(1deg);
}

/* Loading overlay over input */
.input-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(235, 229, 217, 0.9);
    display: flex;
    justify-content: flex-start;
    align-items: center;
    padding: 0 15%;
    font-family: var(--font-header);
    font-size: 1.2rem;
    font-weight: bold;
    color: var(--border-main);
    z-index: 10;
    text-transform: uppercase;
}

.loading-dots::after {
    content: '';
    animation: dots 1.5s infinite steps(4);
}

@keyframes dots {
    0% {
        content: '';
    }

    25% {
        content: '.';
    }

    50% {
        content: '..';
    }

    75% {
        content: '...';
    }

    100% {
        content: '';
    }
}

::-webkit-scrollbar {
    width: 10px;
}

::-webkit-scrollbar-track {
    background: var(--bg-base);
    border-left: 2px solid var(--border-main);
}

::-webkit-scrollbar-thumb {
    background: var(--border-main);
}

.flash-red {
    animation: flashRed 1s ease;
}

@keyframes flashRed {
    0% {
        background: rgba(138, 3, 3, 0.3);
    }

    100% {
        background: transparent;
    }
}

/* Responsive Adjustments */
@media (max-width: 900px) {
    .char-select-header h1 {
        font-size: 2.5rem;
    }

    .game-screen {
        flex-direction: column;
    }

    .sidebar-column {
        width: 100%;
        height: 35vh;
        border-top: 4px solid var(--border-main);
        border-left: none;
        margin-left: 0;
    }

    .history-area,
    .input-area-container {
        padding-left: 5%;
        padding-right: 5%;
    }

    .location-header-pinned {
        flex-direction: column;
    }

    .location-img-wrapper,
    .location-pinned-info {
        width: 100%;
        border-right: none;
    }

    .room-roster {
        top: 280px;
        /* Push down more for the stacked header padding if needed */
        left: 10px;
    }

    .roster-portrait {
        width: 50px;
        height: 50px;
    }

    .input-hints {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        cursor: pointer;
    }

    .input-hints:hover,
    .input-hints:active {
        white-space: normal;
        overflow: visible;
    }
}