/*
 * Don Quixote RPG - Stylesheet
 * Combines medieval parchment aesthetics with cyberpunk neon accents that emerge as sanity drops.
 */

@import url('https://fonts.googleapis.com/css2?family=Almendra:ital,wght@0,400;0,700;1,400&family=Cinzel:wght@400;700;900&family=Outfit:wght@300;400;600&display=swap');

:root {
    --parchment-bg: #f2e6ce;
    --parchment-border: #8b5a2b;
    --dark-bg: #121214;
    --neon-magenta: #ff00ff;
    --neon-cyan: #00ffff;
    --neon-green: #39ff14;
    --font-heading: 'Cinzel', serif;
    --font-dialog: 'Almendra', serif;
    --font-ui: 'Outfit', sans-serif;
    
    /* Sanity warp variables (controlled dynamically via JS) */
    --sanity-glow: 0px 0px 5px rgba(0,0,0,0.5);
    --sanity-filter: none;
    --sanity-pulse: 1s;
}

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

body, html {
    position: relative;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: var(--dark-bg);
    font-family: var(--font-ui);
    color: #e0e0e0;
}

#canvas-container {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 1;
    filter: var(--sanity-filter);
    overflow: hidden;
}

#canvas-container canvas {
    display: block;
    width: 100% !important;
    height: 100% !important;
}

/* UI Wrapper */
#ui-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10;
    pointer-events: none; /* Let clicks pass through to canvas */
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 20px;
}

/* Let interactive elements receive pointer events */
.interactive {
    pointer-events: auto;
}

/* HUD Top Bar */
.hud-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    width: 100%;
}

.player-stats {
    background: rgba(18, 18, 20, 0.85);
    border: 2px solid var(--parchment-border);
    border-radius: 8px;
    padding: 15px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 320px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.6), var(--sanity-glow);
    transition: all 0.3s ease;
}

.stat-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-weight: 600;
    font-size: 14px;
    letter-spacing: 1px;
}

.stat-label {
    font-family: var(--font-heading);
    color: var(--parchment-bg);
}

.bar-container {
    width: 180px;
    height: 16px;
    background: #252528;
    border: 1px solid #45454a;
    border-radius: 4px;
    overflow: hidden;
    position: relative;
}

.bar-fill {
    height: 100%;
    width: 100%;
    transform-origin: left;
    transition: transform 0.2s ease;
}

#health-fill {
    background: linear-gradient(90deg, #8b0000, #ff2e2e);
}

#sanity-fill {
    background: linear-gradient(90deg, #104e8b, #00bfff);
    box-shadow: 0 0 8px rgba(0, 191, 255, 0.5);
}

/* Quest Tracker */
.quest-tracker {
    background: rgba(18, 18, 20, 0.85);
    border: 2px solid var(--parchment-border);
    border-radius: 8px;
    padding: 15px;
    width: 280px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.6);
}

.quest-title {
    font-family: var(--font-heading);
    color: #e5c158;
    font-size: 14px;
    margin-bottom: 6px;
    border-bottom: 1px solid #4a3e2b;
    padding-bottom: 4px;
    letter-spacing: 1px;
}

.quest-text {
    font-size: 13px;
    color: #cccccc;
    line-height: 1.4;
}

/* HUD Bottom - Dialogue & Interaction */
.hud-footer {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    width: 100%;
    margin-bottom: 10px;
}

/* Interaction Prompt */
#interaction-prompt {
    background: rgba(229, 193, 88, 0.9);
    color: #121214;
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 16px;
    padding: 8px 20px;
    border-radius: 20px;
    box-shadow: 0 0 15px rgba(229, 193, 88, 0.5);
    opacity: 0;
    transform: translateY(10px);
    transition: all 0.2s ease;
    letter-spacing: 1.5px;
}

#interaction-prompt.visible {
    opacity: 1;
    transform: translateY(0);
}

/* Dialogue Box (Parchment Styled) */
.dialogue-box {
    background-color: var(--parchment-bg);
    background-image: radial-gradient(rgba(0,0,0,0.02) 1px, transparent 0),
                      radial-gradient(rgba(0,0,0,0.02) 2px, transparent 0);
    background-size: 8px 8px;
    border: 6px double var(--parchment-border);
    border-radius: 4px;
    padding: 15px 25px;
    width: 80%;
    max-width: 800px;
    min-height: 110px;
    box-shadow: 0 8px 25px rgba(0,0,0,0.7);
    display: none; /* hidden by default */
    flex-direction: column;
    justify-content: space-between;
    transition: all 0.3s ease;
}

.dialogue-speaker {
    font-family: var(--font-heading);
    color: var(--parchment-border);
    font-weight: 900;
    font-size: 18px;
    margin-bottom: 5px;
    border-bottom: 1px dashed rgba(139, 90, 43, 0.3);
    padding-bottom: 2px;
}

.dialogue-text {
    font-family: var(--font-dialog);
    color: #2c1d11;
    font-size: 20px;
    line-height: 1.5;
    font-style: italic;
}

.dialogue-next {
    align-self: flex-end;
    font-size: 11px;
    color: var(--parchment-border);
    letter-spacing: 2px;
    font-weight: 700;
    animation: blink 1.2s infinite;
}

/* Start / Menu / Game Over Screens (Full screen overlays) */
.screen-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 100;
    background: radial-gradient(#1e1e24, #0a0a0c);
    display: flex;
    justify-content: center;
    align-items: center;
    transition: opacity 0.8s ease;
}

.screen-content {
    background: var(--parchment-bg);
    border: 10px double var(--parchment-border);
    border-radius: 8px;
    padding: 40px;
    max-width: 650px;
    max-height: 90%;
    overflow-y: auto;
    width: 90%;
    text-align: center;
    color: #2c1d11;
    box-shadow: 0 15px 40px rgba(0,0,0,0.8);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

.screen-title {
    font-family: var(--font-heading);
    font-size: 32px;
    font-weight: 900;
    color: var(--parchment-border);
    border-bottom: 3px double var(--parchment-border);
    padding-bottom: 10px;
    margin-bottom: 10px;
    line-height: 1.2;
}

.screen-subtitle {
    font-family: var(--font-dialog);
    font-size: 20px;
    font-style: italic;
    color: #5c3a21;
    margin-top: -10px;
}

.screen-description {
    font-size: 14px;
    line-height: 1.6;
    color: #4a3321;
    text-align: justify;
    margin: 10px 0;
}

.btn-medieval {
    font-family: var(--font-heading);
    background: var(--parchment-border);
    color: var(--parchment-bg);
    border: 2px solid #5c3a21;
    padding: 12px 30px;
    font-size: 16px;
    font-weight: 700;
    letter-spacing: 2px;
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.2s ease;
    box-shadow: 0 4px 8px rgba(0,0,0,0.3);
}

.btn-medieval:hover {
    background: #a86d34;
    color: #ffffff;
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(0,0,0,0.4);
}

.btn-medieval:active {
    transform: translateY(1px);
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

/* Audio Controls & UI Overlays */
.top-right-controls {
    display: flex;
    gap: 10px;
}

.btn-round {
    background: rgba(18, 18, 20, 0.85);
    border: 2px solid var(--parchment-border);
    color: var(--parchment-bg);
    width: 44px;
    height: 44px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 0 4px 8px rgba(0,0,0,0.5);
    transition: all 0.2s ease;
}

.btn-round:hover {
    background: var(--parchment-border);
    color: #ffffff;
}

/* Help panel (under the round button) */
#help-modal {
    position: absolute;
    top: 80px;
    right: 20px;
    background: rgba(18, 18, 20, 0.9);
    border: 2px solid var(--parchment-border);
    border-radius: 8px;
    padding: 20px;
    width: 260px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.8);
    display: none;
    pointer-events: auto;
}

#help-modal h3 {
    font-family: var(--font-heading);
    color: #e5c158;
    margin-bottom: 10px;
    font-size: 14px;
    border-bottom: 1px solid #4a3e2b;
    padding-bottom: 4px;
}

.control-item {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    margin-bottom: 8px;
    color: #cccccc;
}

.control-key {
    background: #333;
    padding: 2px 6px;
    border-radius: 3px;
    font-family: monospace;
    color: #fff;
    border: 1px solid #555;
}

/* Animations */
@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

@keyframes glitch-shake {
    0% { transform: translate(0, 0) skew(0deg); }
    10% { transform: translate(-2px, 2px) skew(-1deg); }
    20% { transform: translate(2px, -2px) skew(1deg); }
    30% { transform: translate(-1px, -1px) skew(0deg); }
    40% { transform: translate(3px, 1px) skew(2deg); }
    50% { transform: translate(-2px, -2px) skew(-2deg); }
    60% { transform: translate(2px, 2px) skew(0deg); }
    70% { transform: translate(-1px, 2px) skew(1deg); }
    80% { transform: translate(1px, -2px) skew(-1deg); }
    90% { transform: translate(-2px, 1px) skew(0deg); }
    100% { transform: translate(0, 0) skew(0deg); }
}

/* Low Sanity Glitch Classes (Applied dynamically) */
.sanity-warp-ui {
    animation: glitch-shake var(--sanity-pulse) infinite linear alternate-reverse;
}

.sanity-bar-neon {
    background: linear-gradient(90deg, var(--neon-magenta), var(--neon-cyan)) !important;
    box-shadow: 0 0 15px var(--neon-magenta) !important;
}

.sanity-hud-neon {
    border-color: var(--neon-magenta) !important;
    box-shadow: 0 0 20px rgba(255, 0, 255, 0.4) !important;
}

.sanity-text-neon {
    color: var(--neon-cyan) !important;
    text-shadow: 0 0 5px var(--neon-cyan) !important;
}

/* Books / Inventory items in HUD */
.inventory-container {
    display: flex;
    gap: 8px;
    margin-top: 5px;
}

.inventory-slot {
    width: 42px;
    height: 42px;
    background: #1e1e20;
    border: 1px solid #4a3e2b;
    border-radius: 4px;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    cursor: help;
}

.inventory-slot.filled {
    border-color: #e5c158;
    background: #322b20;
}

.inventory-icon {
    font-size: 20px;
}

.inventory-tooltip {
    visibility: hidden;
    background-color: #121214;
    color: #fff;
    text-align: center;
    border-radius: 4px;
    padding: 5px 8px;
    position: absolute;
    z-index: 101;
    bottom: 125%;
    left: 50%;
    transform: translateX(-50%);
    width: 120px;
    font-size: 10px;
    border: 1px solid var(--parchment-border);
    opacity: 0;
    transition: opacity 0.2s;
}

.inventory-slot:hover .inventory-tooltip {
    visibility: visible;
    opacity: 1;
}

/* Home Screen Custom Styles */
.interactive-select {
    font-family: var(--font-dialog);
    font-size: 16px;
    padding: 10px 15px;
    border: 2px solid var(--parchment-border);
    background: rgba(255, 252, 240, 0.9);
    color: #2c1d11;
    border-radius: 4px;
    outline: none;
    cursor: pointer;
    width: 280px;
    box-shadow: inset 0 1px 3px rgba(0,0,0,0.1);
    transition: border-color 0.2s ease;
}

.interactive-select:focus {
    border-color: #a86d34;
}

.menu-group {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    width: 100%;
}

.menu-label {
    font-family: var(--font-heading);
    font-size: 16px;
    font-weight: bold;
    color: #4a3321;
    letter-spacing: 1px;
}

.chapter-buttons {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 100%;
    max-width: 400px;
}

.btn-medieval.locked {
    background: #cbd3cf !important;
    color: #7f8a84 !important;
    border-color: #9da8a2 !important;
    cursor: not-allowed !important;
    box-shadow: none !important;
    pointer-events: none !important;
}

.home-menu-section {
    background: rgba(255, 252, 240, 0.4);
    border: 2px dashed var(--parchment-border);
    border-radius: 6px;
    padding: 20px;
    width: 100%;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

.home-credits {
    font-family: var(--font-dialog);
    font-size: 12px;
    font-style: italic;
    color: #665544;
    margin-top: 10px;
    text-align: center;
}

.interactive-link {
    color: #8b5a2b;
    text-decoration: none;
    font-weight: bold;
    transition: color 0.2s ease;
}

.interactive-link:hover {
    color: #b87d4b;
    text-decoration: underline;
}

.donation-section {
    margin-top: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    width: 100%;
}

.donation-links {
    display: flex;
    gap: 12px;
    justify-content: center;
    flex-wrap: wrap;
    margin-top: 5px;
}

.donation-link {
    font-family: var(--font-heading);
    font-size: 11px;
    font-style: normal;
    font-weight: bold;
    text-decoration: none;
    padding: 8px 16px;
    border-radius: 4px;
    color: #fff !important;
    transition: opacity 0.2s ease, transform 0.1s ease;
    box-shadow: 0 2px 4px rgba(0,0,0,0.15);
}

.donation-link:hover {
    opacity: 0.9;
    transform: translateY(-1px);
}

.donation-link:active {
    transform: translateY(0);
}

.donation-link.patreon {
    background-color: #ff4500;
}

.donation-link.bmac {
    background-color: #ffdd00;
    color: #000 !important;
}

.donation-link.kofi {
    background-color: #29abe2;
}

