@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap');

:root {
    --bg: #008080;
    --window-bg: #c0c0c0;
    --window-border-light: #ffffff;
    --window-border-dark: #808080;
    --title-bg: linear-gradient(90deg, #000080, #1084d0);
    --title-text: #ffffff;
    --text: #000000;
    --accent: #000080;
    --button-face: #c0c0c0;
    --input-bg: #ffffff;
    --danger: #ff0000;
    --glow: #00ff00;
}

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

body {
    background: var(--bg);
    font-family: 'Press Start 2P', monospace;
    overflow: hidden;
    height: 100vh;
    width: 100vw;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    transition: background 0.5s;
}

#scanlines {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 9999;
    background: repeating-linear-gradient(
        0deg,
        transparent,
        transparent 2px,
        rgba(0, 0, 0, 0.03) 2px,
        rgba(0, 0, 0, 0.03) 4px
    );
}

#app {
    width: 100%;
    max-width: 660px;
    padding: 16px;
    z-index: 1;
}

/* === RETRO WINDOW === */
.retro-window {
    background: var(--window-bg);
    border: 2px solid;
    border-color: var(--window-border-light) var(--window-border-dark) var(--window-border-dark) var(--window-border-light);
    box-shadow: 4px 4px 0px rgba(0, 0, 0, 0.5);
    opacity: 0;
    transform: scale(0.8);
    transition: opacity 0.5s, transform 0.5s;
}

.retro-window.visible {
    opacity: 1;
    transform: scale(1);
}

.title-bar {
    background: var(--title-bg);
    color: var(--title-text);
    padding: 4px 6px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    user-select: none;
}

.title-text {
    font-size: 10px;
    font-family: 'Press Start 2P', monospace;
}

.title-buttons {
    display: flex;
    gap: 2px;
}

.title-buttons span {
    width: 18px;
    height: 18px;
    background: var(--button-face);
    border: 2px solid;
    border-color: var(--window-border-light) var(--window-border-dark) var(--window-border-dark) var(--window-border-light);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    font-family: monospace;
    color: #000;
    cursor: pointer;
    line-height: 1;
}

.title-buttons span:active {
    border-color: var(--window-border-dark) var(--window-border-light) var(--window-border-light) var(--window-border-dark);
}

.window-body {
    padding: 16px;
    max-height: 80vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* === CHARACTER === */
#character-container {
    text-align: center;
    min-height: 140px;
    display: flex;
    align-items: center;
    justify-content: center;
}

#character {
    font-family: 'Courier New', 'Lucida Console', monospace;
    font-size: 10px;
    line-height: 1.15;
    color: var(--text);
    white-space: pre;
    transition: color 0.3s;
    display: inline-block;
}

/* === DIALOGUE === */
#dialogue-container {
    min-height: 80px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

#dialogue {
    font-family: 'Press Start 2P', monospace;
    font-size: 10px;
    line-height: 1.8;
    color: var(--text);
    min-height: 40px;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

#dialogue .line {
    margin-bottom: 2px;
    opacity: 1;
}

/* === INPUT === */
#input-area {
    display: flex;
    gap: 4px;
    align-items: center;
}

#name-input {
    flex: 1;
    font-family: 'Press Start 2P', monospace;
    font-size: 10px;
    padding: 6px 8px;
    border: 2px solid;
    border-color: var(--window-border-dark) var(--window-border-light) var(--window-border-light) var(--window-border-dark);
    background: var(--input-bg);
    outline: none;
}

#name-submit, .action-btn {
    font-family: 'Press Start 2P', monospace;
    font-size: 9px;
    padding: 6px 12px;
    background: var(--button-face);
    border: 2px solid;
    border-color: var(--window-border-light) var(--window-border-dark) var(--window-border-dark) var(--window-border-light);
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.1s;
}

#name-submit:hover, .action-btn:hover {
    background: #d4d4d4;
}

#name-submit:active, .action-btn:active {
    border-color: var(--window-border-dark) var(--window-border-light) var(--window-border-light) var(--window-border-dark);
}

#button-area {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.hidden {
    display: none !important;
}

/* === OVERLAY === */
#overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0);
    z-index: 100;
    transition: background 1s;
    pointer-events: none;
}

/* === DARKNESS (ACT 4) === */
#darkness {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #000;
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
}

#dark-text {
    font-family: 'Press Start 2P', monospace;
    font-size: 11px;
    color: #888;
    text-align: center;
    line-height: 2.5;
    padding: 20px;
}

#dark-text .dark-line {
    opacity: 0;
    animation: fadeInSlow 2s forwards;
}

@keyframes fadeInSlow {
    to { opacity: 1; }
}

/* === SOUND PROMPT === */
#sound-prompt {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    z-index: 300;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sound-prompt-box {
    background: var(--window-bg);
    border: 2px solid;
    border-color: var(--window-border-light) var(--window-border-dark) var(--window-border-dark) var(--window-border-light);
    padding: 28px;
    text-align: center;
    max-width: 320px;
}

.sound-prompt-box p {
    font-family: 'Press Start 2P', monospace;
    font-size: 10px;
    margin-bottom: 20px;
    color: var(--text);
    line-height: 1.8;
}

.sound-prompt-box button {
    font-family: 'Press Start 2P', monospace;
    font-size: 9px;
    padding: 8px 16px;
    margin: 0 4px;
    background: var(--button-face);
    border: 2px solid;
    border-color: var(--window-border-light) var(--window-border-dark) var(--window-border-dark) var(--window-border-light);
    cursor: pointer;
}

.sound-prompt-box button:hover {
    background: #d4d4d4;
}

/* === GLITCH EFFECTS === */
.glitch-text {
    animation: glitchText 0.3s infinite;
}

@keyframes glitchText {
    0% { transform: translate(0); }
    20% { transform: translate(-2px, 1px); }
    40% { transform: translate(2px, -1px); }
    60% { transform: translate(-1px, -2px); }
    80% { transform: translate(1px, 2px); }
    100% { transform: translate(0); }
}

.shake {
    animation: shake 0.08s infinite;
}

@keyframes shake {
    0% { transform: translate(0); }
    25% { transform: translate(-4px, 2px); }
    50% { transform: translate(4px, -2px); }
    75% { transform: translate(-2px, -1px); }
    100% { transform: translate(0); }
}

.flicker {
    animation: flicker 0.08s infinite;
}

@keyframes flicker {
    0% { opacity: 1; }
    50% { opacity: 0.3; }
    100% { opacity: 1; }
}

.red-text #dialogue,
.red-text #character {
    color: var(--danger) !important;
}

.corrupt-bg {
    background: #000 !important;
}

.corrupt-bg .window-body {
    background: #0a0a0a;
}

.corrupt-bg .title-bar {
    background: #8b0000 !important;
}

.corrupt-bg #character {
    color: var(--danger);
    text-shadow: 0 0 5px rgba(255, 0, 0, 0.5);
}

.corrupt-bg #dialogue {
    color: var(--glow);
    text-shadow: 0 0 3px rgba(0, 255, 0, 0.3);
}

.btn-close-angry {
    background: #ff0000 !important;
    color: #fff !important;
}

/* === SOUND TOGGLE (floating) === */
.sound-toggle {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 90;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--window-bg);
    border: 3px solid;
    border-color: var(--window-border-light) var(--window-border-dark) var(--window-border-dark) var(--window-border-light);
    font-size: 20px;
    color: #000;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    box-shadow: 3px 3px 0px rgba(0, 0, 0, 0.5);
    line-height: 1;
    padding: 0;
    overflow: hidden;
    transition: opacity 0.3s, transform 0.2s;
    animation: soundBtnAppear 0.5s ease;
}

@keyframes soundBtnAppear {
    from { transform: scale(0) rotate(-90deg); opacity: 0; }
    to { transform: scale(1) rotate(0); opacity: 1; }
}

.sound-toggle.visible {
    display: flex;
}

.sound-toggle:hover {
    transform: scale(1.1);
}

.sound-toggle:active {
    transform: scale(0.95);
    border-color: var(--window-border-dark) var(--window-border-light) var(--window-border-light) var(--window-border-dark);
}

/* === CURSOR BLINK === */
.cursor::after {
    content: '█';
    animation: blink 0.6s infinite;
}

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

/* === SCROLLBAR (retro) === */
.window-body::-webkit-scrollbar {
    width: 16px;
}

.window-body::-webkit-scrollbar-track {
    background: #c0c0c0;
    border: 1px solid #808080;
}

.window-body::-webkit-scrollbar-thumb {
    background: #c0c0c0;
    border: 2px solid;
    border-color: #fff #808080 #808080 #fff;
}

/* === MOBILE === */
@media (max-width: 520px) {
    body {
        align-items: flex-start;
        padding-top: 4px;
    }

    #app {
        padding: 6px;
    }

    .window-body {
        padding: 10px;
        max-height: 85vh;
    }

    #character {
        font-size: 7px;
        line-height: 1.1;
    }

    #character-container {
        min-height: 100px;
    }

    #dialogue {
        font-size: 8px;
        line-height: 1.7;
    }

    #name-input {
        font-size: 9px;
        padding: 8px;
    }

    .action-btn, #name-submit {
        font-size: 8px;
        padding: 8px 10px;
    }

    .sound-prompt-box {
        margin: 12px;
        padding: 20px;
    }

    .sound-prompt-box p {
        font-size: 8px;
    }

    .sound-prompt-box button {
        font-size: 8px;
        padding: 10px 14px;
        margin-top: 4px;
    }

    #dark-text {
        font-size: 8px;
        padding: 12px;
    }

    .title-text {
        font-size: 8px;
    }

    #button-area {
        gap: 4px;
    }
}

@media (max-height: 600px) and (max-width: 520px) {
    #character-container {
        min-height: 80px;
    }

    #character {
        font-size: 6px;
    }

    .window-body {
        gap: 6px;
    }
}
