@import url('https://fonts.googleapis.com/css2?family=VT323&family=Share+Tech+Mono&family=Inter:wght@400;600&display=swap');

/* ============================
   DESIGN TOKENS
   ============================ */
:root {
    --bg: #050505;
    --green: #33ff33;
    --green-dim: #1db91d;
    --green-ghost: rgba(51, 255, 51, 0.08);
    --green-glow: rgba(51, 255, 51, 0.35);
    --red: #ff4444;
    --red-dim: rgba(255, 68, 68, 0.25);
    --amber: #ffbb33;
    --panel-bg: rgba(5, 5, 5, 0.75);
    --panel-border: 1px solid rgba(51, 255, 51, 0.2);
    --glass: rgba(8, 8, 8, 0.65);
    --glass-heavy: rgba(5, 5, 5, 0.85);
    --font-mono: 'VT323', monospace;
    --font-tech: 'Share Tech Mono', monospace;
    --font-sans: 'Inter', sans-serif;
    --radius: 6px;
    --radius-lg: 12px;
    --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-top: env(safe-area-inset-top, 0px);
}

/* ============================
   RESET & BASE
   ============================ */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

html,
body {
    height: 100%;
    overflow: hidden;
    overscroll-behavior: none;
}

body {
    background: var(--bg);
    color: var(--green);
    font-family: var(--font-mono);
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    touch-action: manipulation;
}

/* ============================
   APP CONTAINER – fullscreen
   ============================ */
#app-container {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 1;
}

/* ============================
   SCENE BACKGROUND (fullscreen image)
   ============================ */
#scene-bg {
    position: absolute;
    inset: 0;
    z-index: 0;
    overflow: hidden;
}

#scene-bg img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    filter: brightness(0.55) contrast(1.15) saturate(0.7);
    transition: opacity 0.6s ease, filter 0.6s ease;
    animation: slowZoom 30s ease-in-out infinite alternate;
}

#scene-bg img.fade-out {
    opacity: 0;
}

@keyframes slowZoom {
    0% {
        transform: scale(1.0);
    }

    100% {
        transform: scale(1.08);
    }
}

/* Vignette */
#scene-vignette {
    position: absolute;
    inset: 0;
    background: radial-gradient(ellipse at center, transparent 30%, rgba(0, 0, 0, 0.7) 100%);
    pointer-events: none;
}

/* Noise texture */
#scene-noise {
    position: absolute;
    inset: 0;
    opacity: 0.04;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
    pointer-events: none;
    mix-blend-mode: overlay;
}

/* ============================
   CRT OVERLAY
   ============================ */
#crt-overlay {
    position: fixed;
    inset: 0;
    z-index: 100;
    pointer-events: none;
    background:
        repeating-linear-gradient(0deg,
            transparent,
            transparent 2px,
            rgba(0, 0, 0, 0.06) 2px,
            rgba(0, 0, 0, 0.06) 4px);
}

#crt-overlay::after {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(to bottom, transparent, rgba(51, 255, 51, 0.03), transparent);
    height: 120px;
    animation: scanline 6s linear infinite;
}

@keyframes scanline {
    0% {
        transform: translateY(-120px);
    }

    100% {
        transform: translateY(100vh);
    }
}

/* ============================
   TERMINAL LINE
   ============================ */
#terminal-line-container {
    position: relative;
    z-index: 50;
    margin: 0.5rem 1rem;
    padding: 0.4rem 0.8rem;
    background: var(--glass-light);
    border: 1px solid rgba(51, 255, 51, 0.1);
    border-radius: var(--radius);
    font-family: var(--font-tech);
    font-size: 0.75rem;
    color: var(--green-dim);
    letter-spacing: 1px;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    pointer-events: none;
    /* Don't block clicks */
    text-transform: uppercase;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}

#terminal-prompt {
    color: var(--green);
    font-weight: bold;
    animation: blink 1s step-end infinite;
}

@keyframes blink {
    50% {
        opacity: 0;
    }
}

#terminal-text {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ============================
   HUD BAR (top)
   ============================ */
#hud-bar {
    position: relative;
    z-index: 100;
    /* Ensure it's above everything */
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.6rem 1.2rem;
    /*padding-top: calc(0.6rem + var(--safe-top));*/
    background: linear-gradient(to bottom,
            rgba(5, 5, 5, 0.95) 0%,
            rgba(5, 5, 5, 0.8) 70%,
            transparent 100%);
    backdrop-filter: blur(4px);
    gap: 0.5rem;
    flex-shrink: 0;
    border-bottom: 1px solid rgba(51, 255, 51, 0.05);
}

.hud-left,
.hud-center,
.hud-right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.hud-center {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
}

.hud-logo {
    font-family: var(--font-tech);
    font-size: 1rem;
    letter-spacing: 3px;
    color: var(--green);
    text-shadow: 0 0 8px var(--green-glow);
    opacity: 0.7;
}

.hud-logo-dim {
    opacity: 0.4;
    margin-left: 2px;
}

.hud-group {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.hud-icon {
    font-size: 0.85rem;
    line-height: 1;
}

.hud-number {
    font-family: var(--font-tech);
    font-size: 0.85rem;
    color: var(--green);
    letter-spacing: 1px;
}

.hud-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 28px;
    /* stała wysokość */
    padding: 0 0.6rem;
    /* tylko poziomy padding */
    font-family: var(--font-tech);
    font-size: 0.8rem;
    color: var(--green-dim);
    border: 1px solid rgba(51, 255, 51, 0.15);
    border-radius: var(--radius);
    background: rgba(51, 255, 51, 0.04);
    line-height: 1;
    /* zapobiega dodatkowym odstępom */
}

/* Badge-style buttons */
.hud-badge-btn {
    cursor: pointer;
    transition: all var(--transition);
    border: 1px solid rgba(51, 255, 51, 0.15);
}

.hud-badge-btn:hover {
    background: rgba(51, 255, 51, 0.1);
    border-color: rgba(51, 255, 51, 0.3);
    color: var(--green);
    box-shadow: 0 0 8px rgba(51, 255, 51, 0.2);
}

.hud-badge-btn:active {
    transform: scale(0.95);
    box-shadow: 0 0 4px rgba(51, 255, 51, 0.15);
}

/* Sanity Bar */
.sanity-bar {
    width: 70px;
    height: 6px;
    background: rgba(51, 255, 51, 0.1);
    border-radius: 3px;
    overflow: hidden;
    border: 1px solid rgba(51, 255, 51, 0.2);
}

#sanity-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--red), var(--amber), var(--green));
    border-radius: 3px;
    transition: width 0.5s var(--transition);
    box-shadow: 0 0 6px var(--green-glow);
}

/* HUD Buttons */
.hud-btn {
    background: none;
    border: 1px solid rgba(51, 255, 51, 0.2);
    color: var(--green-dim);
    font-size: 1.1rem;
    width: 38px;
    height: 22px;
    border-radius: var(--radius);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
    padding: 0;
    font-family: var(--font-mono);
}

.hud-btn:hover,
.hud-btn:active {
    background: rgba(51, 255, 51, 0.1);
    border-color: var(--green);
    color: var(--green);
    box-shadow: 0 0 8px var(--green-glow);
}

/* ============================
   SETTINGS PANEL
   ============================ */
.settings-panel {
    position: absolute;
    top: calc(3rem + var(--safe-top));
    right: 1rem;
    z-index: 20;
    background: var(--glass-heavy);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: var(--panel-border);
    border-radius: var(--radius-lg);
    padding: 1rem 1.2rem;
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.7);
    transition: opacity var(--transition), transform var(--transition);
    min-width: 200px;
}

.settings-panel.hidden {
    opacity: 0;
    pointer-events: none;
    transform: translateY(-8px) scale(0.97);
}

.settings-title {
    font-family: var(--font-tech);
    font-size: 0.75rem;
    letter-spacing: 2px;
    color: var(--green-dim);
    opacity: 0.6;
    text-transform: uppercase;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.control-group label {
    font-family: var(--font-tech);
    font-size: 0.75rem;
    color: var(--green-dim);
    letter-spacing: 1px;
}

/* Range Input */
input[type=range] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 4px;
    background: rgba(51, 255, 51, 0.15);
    border-radius: 2px;
    outline: none;
}

input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none;
    height: 16px;
    width: 6px;
    background: var(--green);
    border-radius: 2px;
    cursor: pointer;
    box-shadow: 0 0 6px var(--green-glow);
}

input[type=range]::-moz-range-thumb {
    height: 16px;
    width: 6px;
    background: var(--green);
    border: none;
    border-radius: 2px;
    cursor: pointer;
}

/* ============================
   GAME VIEWPORT (narrative)
   ============================ */
#game-viewport {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    position: relative;
    z-index: 5;
    min-height: 0;
    overflow: hidden;
}

/* Narrative Panel - glass footer over the image */
#narrative-panel {
    background: linear-gradient(to top, var(--glass-heavy) 40%, var(--glass) 80%, transparent 100%);
    padding: 2.5rem 1.5rem 1rem;
    position: relative;
}

#narrative-panel::before {
    content: "";
    position: absolute;
    top: 0;
    left: 1.5rem;
    right: 1.5rem;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--green-dim), transparent);
    opacity: 0.3;
}

#room-title {
    font-family: var(--font-mono);
    font-size: 1.6rem;
    letter-spacing: 3px;
    color: var(--green);
    text-shadow: 0 0 12px var(--green-glow), 0 0 30px rgba(51, 255, 51, 0.1);
    margin-bottom: 0.6rem;
    line-height: 1.2;
}

#room-desc {
    font-family: var(--font-mono);
    font-size: 1.15rem;
    line-height: 1.5;
    color: rgba(51, 255, 51, 0.85);
    max-height: 30vh;
    overflow-y: auto;
}

.interactable-desc {
    margin-top: 0.8rem;
    font-family: var(--font-mono);
    font-size: 1rem;
    color: var(--amber);
    opacity: 0.9;
    font-style: italic;
    line-height: 1.4;
    padding-left: 0.8rem;
    border-left: 2px solid rgba(255, 187, 51, 0.3);
}

/* ============================
   ACTIONS CONTAINER
   ============================ */
#actions-container {
    position: relative;
    z-index: 10;
    padding: 0.8rem 1rem;
    padding-bottom: calc(0.8rem + var(--safe-bottom));
    background: var(--glass-heavy);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
    border-top: 1px solid rgba(51, 255, 51, 0.1);
    flex-shrink: 0;
}

/* ============================
   BUTTONS
   ============================ */
button {
    appearance: none;
    -webkit-appearance: none;
    background: rgba(51, 255, 51, 0.06);
    border: 1px solid rgba(51, 255, 51, 0.25);
    color: var(--green);
    font-family: var(--font-tech);
    font-size: 0.9rem;
    letter-spacing: 1px;
    padding: 0.7rem 1.2rem;
    cursor: pointer;
    border-radius: var(--radius);
    transition: all var(--transition);
    text-transform: uppercase;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    flex: 1 1 auto;
    min-width: 0;
    position: relative;
    overflow: hidden;
    white-space: normal;
    text-align: center;
    line-height: 1.1;
    height: auto;
    min-height: 3.5rem;
}

button::before {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(51, 255, 51, 0.1) 0%, transparent 60%);
    opacity: 0;
    transition: opacity var(--transition);
}

button:hover::before,
button:active::before {
    opacity: 1;
}

button:hover {
    border-color: var(--green);
    box-shadow: 0 0 12px var(--green-glow), inset 0 0 12px rgba(51, 255, 51, 0.05);
    transform: translateY(-1px);
}

button:active {
    transform: translateY(0px) scale(0.98);
    box-shadow: 0 0 6px var(--green-glow);
}

/* Interaction buttons */
button.interaction-btn {
    background: rgba(255, 68, 68, 0.08);
    border-color: rgba(255, 68, 68, 0.35);
    color: var(--red);
    flex: 1 1 calc(33.333% - 0.4rem);
    min-width: 90px;
    font-size: 0.8rem;
    padding: 0.6rem 0.4rem;
    text-align: center;
}

button.interaction-btn.active {
    background: rgba(255, 68, 68, 0.8);
    border-color: var(--red);
    color: #fff;
    box-shadow: 0 0 15px var(--red);
    text-shadow: 0 0 5px rgba(0, 0, 0, 0.5);
}

button.interaction-btn::before {
    background: linear-gradient(135deg, rgba(255, 68, 68, 0.12) 0%, transparent 60%);
}

button.interaction-btn:hover {
    border-color: var(--red);
    box-shadow: 0 0 12px var(--red-dim), inset 0 0 12px rgba(255, 68, 68, 0.05);
    color: #ff6666;
}

button.interaction-btn:active {
    box-shadow: 0 0 6px var(--red-dim);
}

/* Exit buttons */
button.exit-btn {
    flex: 1 1 calc(50% - 0.3rem);
    min-width: 120px;
}

/* Continue button */
button.continue-btn {
    flex: 1 1 100%;
    border-color: var(--amber);
    color: var(--amber);
    background: rgba(255, 187, 51, 0.06);
    font-size: 1rem;
    padding: 1rem;
}

button.continue-btn::before {
    background: linear-gradient(135deg, rgba(255, 187, 51, 0.12) 0%, transparent 60%);
}

button.continue-btn:hover {
    border-color: var(--amber);
    box-shadow: 0 0 12px rgba(255, 187, 51, 0.3);
    color: #ffd180;
}

/* ============================
   SCROLLBAR
   ============================ */
::-webkit-scrollbar {
    width: 4px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--green-dim);
    border-radius: 2px;
}

/* ============================
   GLITCH FLASH
   ============================ */
.glitch-flash {
    animation: glitchFlash 0.08s steps(2) 2;
}

@keyframes glitchFlash {
    0% {
        filter: hue-rotate(0deg) brightness(1);
    }

    25% {
        filter: hue-rotate(90deg) brightness(1.5);
    }

    50% {
        filter: hue-rotate(-30deg) brightness(0.8);
    }

    100% {
        filter: hue-rotate(0deg) brightness(1);
    }
}

/* ============================
   IMAGE TRANSITION
   ============================ */
#scene-bg img.fade-out {
    opacity: 0;
}

/* ============================
   RESPONSIVE – TABLETS
   ============================ */
@media (min-width: 600px) and (max-width: 1024px) {
    #room-title {
        font-size: 1.8rem;
    }

    #room-desc {
        font-size: 1.2rem;
    }

    #actions-container {
        padding: 1rem 1.5rem;
    }

    button {
        padding: 0.8rem 1.5rem;
        font-size: 0.95rem;
    }

    #narrative-panel {
        padding: 3rem 2rem 1.2rem;
    }
}

/* ============================
   RESPONSIVE – DESKTOP
   ============================ */
@media (min-width: 1025px) {
    #app-container {
        max-width: 100%;
    }

    #hud-bar {
        padding: 0.8rem 2rem;
    }

    .sanity-bar {
        width: 100px;
    }

    #narrative-panel {
        padding: 3rem 3rem 1.5rem;
        max-width: 800px;
    }

    #room-title {
        font-size: 2rem;
    }

    #room-desc {
        font-size: 1.3rem;
    }

    #actions-container {
        padding: 1rem 3rem;
        max-width: 800px;
    }

    button {
        padding: 0.9rem 2rem;
        font-size: 1rem;
    }

    button.exit-btn {
        flex: 0 1 auto;
        min-width: 160px;
    }
}

/* ============================
   RESPONSIVE – SMALL PHONES
   ============================ */
@media (max-width: 380px) {
    #hud-bar {
        padding: 0.4rem 0.6rem;
        gap: 0.3rem;
    }

    #terminal-line-container {
        margin: 0.3rem 0.6rem;
        font-size: 0.65rem;
        padding: 0.25rem 0.5rem;
    }

    .hud-logo {
        font-size: 0.8rem;
        letter-spacing: 2px;
    }

    .sanity-bar {
        width: 50px;
    }

    .hud-badge {
        font-size: 0.7rem;
        padding: 0.15rem 0.35rem;
    }

    .hud-btn {
        width: 28px;
        height: 28px;
        font-size: 0.9rem;
    }

    #room-title {
        font-size: 1.3rem;
        letter-spacing: 2px;
    }

    #room-desc {
        font-size: 1rem;
    }

    .interactable-desc {
        font-size: 0.9rem;
    }

    #narrative-panel {
        padding: 2rem 1rem 0.8rem;
    }

    #actions-container {
        padding: 0.6rem 0.8rem;
        gap: 0.4rem;
    }

    button {
        padding: 0.6rem 0.8rem;
        font-size: 0.8rem;
    }
}

/* ============================
   LANDSCAPE PHONE
   ============================ */
@media (max-height: 500px) and (orientation: landscape) {
    #hud-bar {
        padding: 0.3rem 1rem;
    }

    .hud-logo {
        display: none;
    }

    #narrative-panel {
        padding: 1.5rem 1.5rem 0.6rem;
    }

    #room-title {
        font-size: 1.2rem;
        margin-bottom: 0.3rem;
    }

    #room-desc {
        font-size: 0.95rem;
        max-height: 15vh;
    }

    .interactable-desc {
        font-size: 0.85rem;
    }
}

/* ============================
   MOBILE UI FIXES – PORTRAIT
   ============================ */
@media (max-width: 600px) and (orientation: portrait) {

    /* 1. HUD Optimized Grid Layout */
    #hud-bar {
        display: grid;
        grid-template-areas:
            "center center center"
            "left gap right";
        grid-template-columns: auto 1fr auto;
        gap: 0.5rem;
        padding: 0.6rem 0.8rem;
        padding-top: calc(0.5rem + var(--safe-top));
        height: auto;
        background: rgba(5, 5, 5, 0.98);
        border-bottom: 1px solid rgba(51, 255, 51, 0.15);
    }

    .hud-center {
        grid-area: center;
        position: static;
        transform: none;
        width: 100%;
        justify-content: center;
        padding-bottom: 0.4rem;
        border-bottom: 1px solid rgba(51, 255, 51, 0.08);
        margin-bottom: 0.2rem;
    }

    .hud-left {
        grid-area: left;
        justify-content: flex-start;
    }

    .hud-right {
        grid-area: right;
        justify-content: flex-end;
    }

    .hud-logo {
        font-size: 0.85rem;
        letter-spacing: 4px;
    }

    .sanity-bar {
        width: 45px;
    }

    #sanity-value {
        font-size: 0.75rem;
    }

    .hud-badge {
        font-size: 0.7rem;
        padding: 0.15rem 0.4rem;
    }

    .hud-btn {
        width: 32px;
        height: 20px;
        font-size: 0.9rem;
    }

    /* 2. Better Background Scaling (Solid Bottom Bar) */
    #scene-bg {
        height: 70%;
        /* Limit image to top 70% */
        bottom: auto;
        /* Clear absolute bottom */
        border-bottom: 1px solid var(--green-dim);
    }

    #app-container {
        justify-content: flex-end;
        /* Ensure actions are at bottom */
    }

    #game-viewport {
        flex: 1;
        margin-bottom: 0;
        z-index: 5;
        /* Position narrative within the upper area */
        justify-content: flex-end;
    }

    #actions-container {
        height: 30%;
        /* Fixed height for bottom bar */
        width: 100%;
        background: var(--bg);
        /* Solid background */
        backdrop-filter: none;
        border-top: 1px solid rgba(51, 255, 51, 0.2);
        overflow-y: auto;
        align-content: center;
        padding-bottom: max(1rem, var(--safe-bottom));
        z-index: 20;
    }

    /* Ensure narrative doesn't get hidden if it's long */
    #narrative-panel {
        max-height: 40vh;
        /* Limit narrative height */
        overflow-y: auto;
        background: linear-gradient(to top, rgba(0, 0, 0, 0.9), transparent);
    }
}

/* ============================
   ACCESSIBILITY – reduce motion
   ============================ */
@media (prefers-reduced-motion: reduce) {

    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }

    #scene-bg img {
        animation: none;
    }
}