/* ===== TSEVARIN — Design System ===== */

:root {
    /* Palette Steampunk */
    --lava-red: #c0392b;
    --lava-glow: #e74c3c;
    --lava-deep: #7b241c;
    --copper: #b87333;
    --copper-light: #d4956a;
    --brass: #c9a84c;
    --dark-steel: #1a1a2e;
    --steel: #2d2d44;
    --steel-light: #3d3d5c;
    --fog-white: rgba(200, 210, 220, 0.15);
    --fog-blue: rgba(120, 160, 200, 0.1);
    --text-light: #e8dcc8;
    --text-dim: #8a7e6e;
    --text-glow: #f5d89a;
    --shadow-dark: rgba(0, 0, 0, 0.7);
    --steam-blue: rgba(130, 170, 210, 0.3);
}

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

body {
    background: #0a0a14;
    overflow: hidden;
    font-family: 'Inter', sans-serif;
    color: var(--text-light);
    user-select: none;
    -webkit-user-select: none;
}

/* ===== GAME CONTAINER ===== */
#game-container {
    width: 100vw;
    height: 100vh;
    position: relative;
    overflow: hidden;
}

.screen {
    position: absolute;
    inset: 0;
    display: none;
    justify-content: center;
    align-items: center;
}
.screen.active {
    display: flex;
}

/* ===== TITLE SCREEN ===== */
#title-screen {
    flex-direction: column;
    background: linear-gradient(180deg, #0a0a14 0%, #1a0a0a 40%, #2a0e0e 70%, #0a0a14 100%);
}

.title-bg {
    position: absolute;
    inset: 0;
    background:
        radial-gradient(ellipse at 50% 90%, rgba(192, 57, 43, 0.25) 0%, transparent 60%),
        radial-gradient(ellipse at 30% 70%, rgba(184, 115, 51, 0.1) 0%, transparent 40%),
        radial-gradient(ellipse at 70% 80%, rgba(231, 76, 60, 0.15) 0%, transparent 50%);
    animation: lavaAmbient 8s ease-in-out infinite;
}

@keyframes lavaAmbient {
    0%, 100% { opacity: 0.7; }
    50% { opacity: 1; }
}

.title-content {
    position: relative;
    z-index: 2;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3rem;
}

.title-logo {
    animation: titleFloat 4s ease-in-out infinite;
}

@keyframes titleFloat {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-8px); }
}

.title-main {
    font-family: 'Cinzel', serif;
    font-weight: 900;
    font-size: clamp(3rem, 8vw, 7rem);
    letter-spacing: 0.3em;
    background: linear-gradient(180deg, var(--text-glow) 0%, var(--copper) 40%, var(--lava-red) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-shadow: 0 0 60px rgba(192, 57, 43, 0.5);
    filter: drop-shadow(0 0 30px rgba(192, 57, 43, 0.3));
}

.title-subtitle {
    font-family: 'MedievalSharp', cursive;
    font-size: clamp(1rem, 2.5vw, 1.6rem);
    color: var(--text-dim);
    letter-spacing: 0.15em;
    margin-top: 0.5rem;
    opacity: 0;
    animation: fadeInUp 1s ease 0.5s forwards;
}

@keyframes fadeInUp {
    to { opacity: 1; transform: translateY(0); }
    from { opacity: 0; transform: translateY(15px); }
}

.title-menu {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    opacity: 0;
    animation: fadeInUp 1s ease 1s forwards;
}

.menu-btn {
    font-family: 'Cinzel', serif;
    font-weight: 700;
    font-size: 1.1rem;
    padding: 0.9rem 2.8rem;
    background: linear-gradient(135deg, rgba(184, 115, 51, 0.15), rgba(184, 115, 51, 0.05));
    border: 1px solid rgba(184, 115, 51, 0.3);
    color: var(--copper-light);
    cursor: pointer;
    letter-spacing: 0.1em;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
    min-width: 240px;
}

.menu-btn::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(184, 115, 51, 0.2), transparent);
    opacity: 0;
    transition: opacity 0.3s;
}

.menu-btn:hover {
    border-color: var(--copper);
    color: var(--text-glow);
    transform: translateY(-2px);
    box-shadow: 0 4px 20px rgba(184, 115, 51, 0.2), inset 0 0 20px rgba(184, 115, 51, 0.05);
}

.menu-btn:hover::before {
    opacity: 1;
}

.menu-btn:active {
    transform: translateY(0);
}

.btn-icon {
    margin-right: 0.5rem;
    font-size: 1.2rem;
}

.title-credit {
    font-size: 0.8rem;
    color: var(--text-dim);
    opacity: 0.5;
    font-style: italic;
}

/* Steam particles on title */
.steam-particles {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 1;
}

/* ===== CONTROLS MODAL ===== */
.modal {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    justify-content: center;
    align-items: center;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(10px);
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: linear-gradient(145deg, var(--steel) 0%, var(--dark-steel) 100%);
    border: 1px solid rgba(184, 115, 51, 0.3);
    padding: 2.5rem;
    max-width: 500px;
    width: 90%;
    text-align: center;
}

.modal-content h2 {
    font-family: 'Cinzel', serif;
    font-size: 1.8rem;
    color: var(--copper-light);
    margin-bottom: 1.5rem;
    letter-spacing: 0.1em;
}

.controls-grid {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-bottom: 2rem;
}

.control-item {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    font-size: 0.95rem;
}

.control-item span {
    color: var(--text-dim);
    margin-left: 0.5rem;
}

kbd {
    background: linear-gradient(180deg, var(--steel-light), var(--steel));
    border: 1px solid rgba(184, 115, 51, 0.2);
    border-bottom: 3px solid rgba(184, 115, 51, 0.3);
    padding: 0.3rem 0.6rem;
    font-family: 'Inter', sans-serif;
    font-size: 0.85rem;
    color: var(--text-glow);
    border-radius: 4px;
    min-width: 2rem;
    display: inline-block;
    text-align: center;
}

/* ===== GAME SCREEN ===== */
#game-screen {
    background: #0a0a14;
}

#game-canvas {
    display: block;
    width: 100%;
    height: 100%;
    image-rendering: pixelated;
}

/* ===== HUD ===== */
#hud {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 1rem 1.5rem;
    pointer-events: none;
    z-index: 10;
}

#hud-location {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    background: linear-gradient(135deg, rgba(10, 10, 20, 0.85), rgba(10, 10, 20, 0.6));
    border: 1px solid rgba(184, 115, 51, 0.2);
    padding: 0.6rem 1.2rem;
    backdrop-filter: blur(8px);
}

#hud-chapter {
    font-family: 'MedievalSharp', cursive;
    font-size: 0.75rem;
    color: var(--copper);
    letter-spacing: 0.15em;
    text-transform: uppercase;
}

#hud-place {
    font-family: 'Cinzel', serif;
    font-size: 1.1rem;
    color: var(--text-glow);
    letter-spacing: 0.08em;
}

#hud-inventory {
    display: flex;
    gap: 0.5rem;
    pointer-events: auto;
}

.inv-slot {
    width: 48px;
    height: 48px;
    background: linear-gradient(135deg, rgba(10, 10, 20, 0.85), rgba(10, 10, 20, 0.6));
    border: 1px solid rgba(184, 115, 51, 0.2);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.5rem;
    transition: all 0.3s;
    backdrop-filter: blur(8px);
}

.inv-slot.has-item {
    border-color: var(--copper);
    box-shadow: 0 0 10px rgba(184, 115, 51, 0.15);
}

.inv-slot.has-item:hover {
    border-color: var(--text-glow);
    transform: scale(1.1);
}

#hud-hint {
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    top: auto;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: linear-gradient(135deg, rgba(10, 10, 20, 0.85), rgba(10, 10, 20, 0.6));
    border: 1px solid rgba(130, 170, 210, 0.2);
    padding: 0.4rem 1rem;
    backdrop-filter: blur(8px);
    opacity: 0;
    transition: opacity 0.5s;
    margin-bottom: 5.5rem;
}

#hud-hint.visible {
    opacity: 1;
}

#tsevarin-indicator {
    font-size: 1.2rem;
    animation: pawPulse 2s ease-in-out infinite;
}

@keyframes pawPulse {
    0%, 100% { opacity: 0.5; transform: scale(1); }
    50% { opacity: 1; transform: scale(1.15); }
}

#hint-text {
    font-size: 0.85rem;
    color: var(--steam-blue);
    font-style: italic;
}

/* ===== DIALOGUE BOX ===== */
#dialogue-box {
    position: absolute;
    bottom: 1.5rem;
    left: 50%;
    transform: translateX(-50%);
    width: min(90%, 700px);
    background: linear-gradient(145deg, rgba(10, 10, 20, 0.95), rgba(26, 26, 46, 0.95));
    border: 1px solid rgba(184, 115, 51, 0.3);
    border-top: 2px solid var(--copper);
    padding: 1.2rem 1.5rem;
    z-index: 20;
    display: flex;
    gap: 1rem;
    backdrop-filter: blur(12px);
    animation: dialogueSlideUp 0.3s ease;
}

@keyframes dialogueSlideUp {
    from { transform: translateX(-50%) translateY(20px); opacity: 0; }
    to { transform: translateX(-50%) translateY(0); opacity: 1; }
}

#dialogue-box.hidden {
    display: none;
}

#dialogue-portrait {
    width: 64px;
    height: 64px;
    border: 1px solid rgba(184, 115, 51, 0.3);
    flex-shrink: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 2rem;
    background: rgba(0, 0, 0, 0.3);
}

#dialogue-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

#dialogue-name {
    font-family: 'Cinzel', serif;
    font-weight: 700;
    font-size: 0.9rem;
    color: var(--copper-light);
    letter-spacing: 0.08em;
}

#dialogue-text {
    font-size: 0.95rem;
    line-height: 1.5;
    color: var(--text-light);
    min-height: 2.5em;
}

#dialogue-choices {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.dialogue-choice {
    background: linear-gradient(135deg, rgba(184, 115, 51, 0.08), transparent);
    border: 1px solid rgba(184, 115, 51, 0.15);
    color: var(--text-light);
    padding: 0.5rem 1rem;
    cursor: pointer;
    font-family: 'Inter', sans-serif;
    font-size: 0.9rem;
    text-align: left;
    transition: all 0.2s;
}

.dialogue-choice:hover {
    background: linear-gradient(135deg, rgba(184, 115, 51, 0.2), rgba(184, 115, 51, 0.05));
    border-color: var(--copper);
    color: var(--text-glow);
    transform: translateX(4px);
}

#dialogue-continue {
    position: absolute;
    bottom: 0.6rem;
    right: 1rem;
    font-size: 0.75rem;
    color: var(--text-dim);
    animation: continueBlink 1.5s ease-in-out infinite;
}

@keyframes continueBlink {
    0%, 100% { opacity: 0.4; }
    50% { opacity: 1; }
}

/* ===== INTERACTION PROMPT ===== */
#interact-prompt {
    position: absolute;
    z-index: 15;
    background: linear-gradient(135deg, rgba(10, 10, 20, 0.9), rgba(26, 26, 46, 0.85));
    border: 1px solid rgba(184, 115, 51, 0.3);
    padding: 0.4rem 0.8rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    backdrop-filter: blur(8px);
    animation: promptBounce 1s ease-in-out infinite;
    pointer-events: none;
}

#interact-prompt.hidden {
    display: none;
}

@keyframes promptBounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-4px); }
}

#interact-label {
    color: var(--text-dim);
}

/* ===== LEVEL TRANSITION ===== */
#level-transition {
    position: absolute;
    inset: 0;
    background: #0a0a14;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 50;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.8s ease;
}

#level-transition.active {
    opacity: 1;
    pointer-events: auto;
}

#level-transition.hidden {
    display: none;
}

.transition-content {
    text-align: center;
}

.transition-content h2 {
    font-family: 'MedievalSharp', cursive;
    font-size: 1.1rem;
    color: var(--copper);
    letter-spacing: 0.2em;
    text-transform: uppercase;
    margin-bottom: 0.8rem;
}

.transition-content p {
    font-family: 'Cinzel', serif;
    font-size: 2rem;
    color: var(--text-glow);
    letter-spacing: 0.1em;
}

/* ===== END SCREEN ===== */
#end-screen {
    flex-direction: column;
    background: linear-gradient(180deg, #0a0a14 0%, #1a0a0a 50%, #0a0a14 100%);
}

.end-content {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
}

.end-content h1 {
    font-family: 'Cinzel', serif;
    font-size: 3rem;
    color: var(--text-glow);
    letter-spacing: 0.15em;
    animation: titleFloat 4s ease-in-out infinite;
}

.end-text {
    font-size: 1.1rem;
    line-height: 1.8;
    color: var(--text-dim);
    font-style: italic;
}

.end-sub {
    font-size: 0.9rem;
    color: var(--copper);
}

/* ===== TOUCH CONTROLS ===== */

/* Show/hide elements based on device type */
.touch-only { display: none; }
.desktop-only { display: inline; }

body.touch-device .touch-only { display: inline; }
body.touch-device .desktop-only { display: none; }

/* Prevent browser gestures on game canvas */
#game-canvas {
    touch-action: none;
}

body.touch-device #game-container {
    touch-action: none;
}

/* Hide keyboard-based interact prompt on touch */
body.touch-device #interact-prompt {
    display: none !important;
}

/* --- Virtual Joystick --- */
#touch-joystick-zone {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 45%;
    height: 35%;
    z-index: 30;
    touch-action: none;
}

#touch-joystick-base {
    position: absolute;
    bottom: 24px;
    left: 28px;
    width: 100px;
    height: 100px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(184,115,51,0.08) 0%, rgba(184,115,51,0.04) 100%);
    border: 2px solid rgba(184,115,51,0.2);
    transition: border-color 0.2s, background 0.2s;
}

#touch-joystick-base.active {
    border-color: rgba(184,115,51,0.5);
    background: radial-gradient(circle, rgba(184,115,51,0.15) 0%, rgba(184,115,51,0.06) 100%);
}

#touch-joystick-knob {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(184,115,51,0.4), rgba(184,115,51,0.15));
    border: 1px solid rgba(184,115,51,0.4);
    transition: transform 0.05s ease-out;
    box-shadow: 0 0 12px rgba(184,115,51,0.15);
}

.joystick-arrow {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.65rem;
    color: rgba(184,115,51,0.3);
    pointer-events: none;
}

.joystick-arrow-left { left: 6px; }
.joystick-arrow-right { right: 6px; }

/* --- Interact Button --- */
#touch-interact-btn {
    position: absolute;
    bottom: 36px;
    right: 28px;
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(184,115,51,0.2), rgba(184,115,51,0.08));
    border: 2px solid rgba(184,115,51,0.35);
    color: var(--copper-light);
    font-family: 'Cinzel', serif;
    font-size: 0.65rem;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 2px;
    z-index: 30;
    touch-action: none;
    cursor: pointer;
    box-shadow: 0 0 20px rgba(184,115,51,0.1);
    animation: interactPulse 2s ease-in-out infinite;
}

#touch-interact-btn:active {
    background: radial-gradient(circle, rgba(184,115,51,0.4), rgba(184,115,51,0.15));
    border-color: var(--copper);
    transform: scale(0.92);
}

.touch-btn-icon {
    font-size: 1.4rem;
}

.touch-btn-label {
    font-size: 0.55rem;
    letter-spacing: 0.05em;
    opacity: 0.8;
}

@keyframes interactPulse {
    0%, 100% { box-shadow: 0 0 20px rgba(184,115,51,0.1); }
    50% { box-shadow: 0 0 30px rgba(184,115,51,0.25); }
}

/* ===== RESPONSIVE ===== */
@media (max-width: 600px) {
    .title-main { letter-spacing: 0.15em; }
    .menu-btn { min-width: 200px; font-size: 1rem; padding: 0.7rem 2rem; }
    #hud { padding: 0.5rem 0.8rem; }
    .inv-slot { width: 36px; height: 36px; font-size: 1rem; }
    #dialogue-box { width: 95%; padding: 0.8rem; bottom: 1rem; }
    #dialogue-portrait { width: 40px; height: 40px; font-size: 1.5rem; }
    #dialogue-text { font-size: 0.85rem; line-height: 1.4; }
    #dialogue-name { font-size: 0.8rem; }
    .dialogue-choice { font-size: 0.8rem; padding: 0.4rem 0.8rem; }
    #hud-place { font-size: 0.9rem; }
    #hud-chapter { font-size: 0.65rem; }
    #hud-location { padding: 0.4rem 0.8rem; }
    .transition-content p { font-size: 1.4rem; }
    .end-content h1 { font-size: 2rem; }
    .end-text { font-size: 0.9rem; }
}

/* On touch devices, move dialogue box up to avoid overlapping controls */
body.touch-device #dialogue-box {
    bottom: 10rem;
    width: min(92%, 600px);
}

body.touch-device #hud-hint {
    margin-bottom: 10rem;
}
