/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg-deep: #0a0c14;
    --bg-panel: #111827;
    --bg-card: #1a2236;
    --text-primary: #c8d6e5;
    --text-dim: #5c6b7a;
    --accent: #e8a838;
    --accent-glow: rgba(232, 168, 56, 0.3);
    --danger: #e84040;
    --danger-glow: rgba(232, 64, 64, 0.3);
    --sanity-high: #38b2ac;
    --sanity-mid: #e8a838;
    --sanity-low: #e84040;
    --font-main: "Noto Serif SC", "Source Han Serif SC", serif;
    --font-ui: "Noto Sans SC", "Source Han Sans SC", sans-serif;
}

html, body {
    height: 100%;
    overflow: hidden;
    background: var(--bg-deep);
    color: var(--text-primary);
    font-family: var(--font-main);
    font-size: 16px;
    line-height: 1.8;
    -webkit-font-smoothing: antialiased;
}

/* ===== Screens ===== */
.screen {
    display: none;
    position: absolute;
    inset: 0;
    flex-direction: column;
}
.screen.active { display: flex; }

/* ===== Title Screen ===== */
#title-screen {
    justify-content: center;
    align-items: center;
    background: radial-gradient(ellipse at 50% 30%, #0f1a2e 0%, var(--bg-deep) 70%);
    overflow: hidden;
}

.title-content {
    text-align: center;
    z-index: 1;
    animation: fadeIn 2s ease;
}

.game-title {
    font-size: clamp(2.5rem, 8vw, 4rem);
    font-weight: 700;
    color: var(--accent);
    text-shadow: 0 0 30px var(--accent-glow), 0 0 60px rgba(232, 168, 56, 0.1);
    letter-spacing: 0.15em;
    margin-bottom: 0.2em;
}

.game-subtitle {
    font-family: var(--font-ui);
    font-size: clamp(0.8rem, 2.5vw, 1rem);
    color: var(--text-dim);
    letter-spacing: 0.5em;
    margin-bottom: 2em;
}

.game-tagline {
    font-size: 0.9rem;
    color: var(--text-dim);
    margin-bottom: 3em;
    opacity: 0.7;
}

.title-buttons {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

/* Glitch overlay */
.title-glitch {
    position: absolute;
    inset: 0;
    background: repeating-linear-gradient(
        0deg,
        transparent,
        transparent 2px,
        rgba(232, 168, 56, 0.015) 2px,
        rgba(232, 168, 56, 0.015) 4px
    );
    pointer-events: none;
    animation: glitch 8s infinite;
}

/* ===== Game Screen ===== */
#game-screen {
    background: var(--bg-deep);
}

/* Status Bar */
#status-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    background: var(--bg-panel);
    border-bottom: 1px solid rgba(232, 168, 56, 0.15);
    flex-shrink: 0;
}

.sanity-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
}

.sanity-label {
    font-family: var(--font-ui);
    font-size: 0.75rem;
    color: var(--text-dim);
    white-space: nowrap;
}

.sanity-track {
    flex: 1;
    height: 6px;
    background: rgba(255,255,255,0.08);
    border-radius: 3px;
    overflow: hidden;
}

.sanity-fill {
    height: 100%;
    width: 80%;
    background: var(--sanity-high);
    border-radius: 3px;
    transition: width 0.5s ease, background 0.5s ease;
}

.sanity-value {
    font-family: var(--font-ui);
    font-size: 0.75rem;
    color: var(--sanity-high);
    min-width: 2em;
    text-align: right;
    transition: color 0.5s ease;
}

.btn-icon {
    background: none;
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 6px;
    color: var(--text-dim);
    font-size: 1rem;
    padding: 4px 8px;
    cursor: pointer;
    transition: all 0.2s;
}
.btn-icon:hover {
    border-color: var(--accent);
    color: var(--accent);
}

/* Text Area */
#text-area {
    flex: 1;
    overflow-y: auto;
    padding: 24px 20px;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
}

.speaker {
    font-family: var(--font-ui);
    font-size: 0.8rem;
    color: var(--accent);
    margin-bottom: 6px;
    letter-spacing: 0.1em;
}

.story-text {
    white-space: pre-wrap;
    word-break: break-word;
}

.story-text .cursor {
    display: inline-block;
    width: 2px;
    height: 1.1em;
    background: var(--accent);
    margin-left: 2px;
    animation: blink 0.8s step-end infinite;
    vertical-align: text-bottom;
}

/* Low sanity glitch effect */
.story-text.glitch-active {
    animation: textGlitch 0.3s steps(2) infinite;
}

/* Choices Area */
#choices-area {
    flex-shrink: 0;
    padding: 12px 20px 24px;
    background: linear-gradient(to top, var(--bg-deep) 60%, transparent);
}

#choices-container {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.choice-btn {
    display: block;
    width: 100%;
    padding: 14px 18px;
    background: var(--bg-card);
    border: 1px solid rgba(232, 168, 56, 0.2);
    border-radius: 8px;
    color: var(--text-primary);
    font-family: var(--font-main);
    font-size: 0.95rem;
    line-height: 1.5;
    text-align: left;
    cursor: pointer;
    transition: all 0.25s;
    opacity: 0;
    transform: translateY(10px);
}

.choice-btn.visible {
    opacity: 1;
    transform: translateY(0);
}

.choice-btn:hover {
    border-color: var(--accent);
    background: rgba(232, 168, 56, 0.08);
    box-shadow: 0 0 15px var(--accent-glow);
}

.choice-btn:active {
    transform: scale(0.98);
}

.choice-btn.locked {
    border-color: rgba(255,255,255,0.05);
    color: var(--text-dim);
    cursor: not-allowed;
    opacity: 0.4;
}

/* ===== Panels ===== */
#overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.7);
    z-index: 10;
}

.panel {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: min(90vw, 400px);
    background: var(--bg-panel);
    border: 1px solid rgba(232, 168, 56, 0.2);
    border-radius: 12px;
    z-index: 20;
    animation: panelIn 0.3s ease;
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid rgba(255,255,255,0.06);
}

.panel-header h2 {
    font-size: 1.1rem;
    color: var(--accent);
    font-weight: 600;
}

.btn-close {
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 4px 8px;
}
.btn-close:hover { color: var(--text-primary); }

.panel-body {
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

#inventory-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.inv-item {
    padding: 6px 12px;
    background: var(--bg-card);
    border: 1px solid rgba(232, 168, 56, 0.15);
    border-radius: 6px;
    font-size: 0.85rem;
    color: var(--text-primary);
}

/* ===== Buttons ===== */
.btn-primary, .btn-secondary, .btn-danger {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-family: var(--font-ui);
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-primary {
    background: var(--accent);
    color: var(--bg-deep);
    font-weight: 600;
}
.btn-primary:hover {
    box-shadow: 0 0 20px var(--accent-glow);
}

.btn-secondary {
    background: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid rgba(255,255,255,0.1);
}
.btn-secondary:hover {
    border-color: var(--accent);
}

.btn-danger {
    background: transparent;
    color: var(--danger);
    border: 1px solid var(--danger);
}
.btn-danger:hover {
    background: rgba(232, 64, 64, 0.1);
}

/* ===== Ending Screen ===== */
.ending-card {
    text-align: center;
    padding: 40px 20px;
}

.ending-title {
    font-size: 1.5rem;
    color: var(--accent);
    margin-bottom: 16px;
}

.ending-text {
    color: var(--text-primary);
    margin-bottom: 24px;
    line-height: 1.8;
}

/* ===== Animations ===== */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

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

@keyframes glitch {
    0%, 95%, 100% { opacity: 1; }
    96% { opacity: 0.8; transform: translateX(-2px); }
    97% { opacity: 1; transform: translateX(1px); }
    98% { opacity: 0.9; transform: translateX(-1px); }
}

@keyframes textGlitch {
    0% { transform: translateX(0); }
    25% { transform: translateX(-2px); }
    50% { transform: translateX(1px); }
    75% { transform: translateX(-1px); }
    100% { transform: translateX(0); }
}

@keyframes panelIn {
    from { opacity: 0; transform: translate(-50%, -50%) scale(0.95); }
    to { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

/* ===== Scrollbar ===== */
#text-area::-webkit-scrollbar { width: 4px; }
#text-area::-webkit-scrollbar-track { background: transparent; }
#text-area::-webkit-scrollbar-thumb { background: rgba(232, 168, 56, 0.2); border-radius: 2px; }

/* ===== Mobile ===== */
@media (max-width: 480px) {
    html { font-size: 15px; }
    #text-area { padding: 16px; }
    #choices-area { padding: 10px 16px 20px; }
    .choice-btn { padding: 12px 14px; font-size: 0.9rem; }
}

/* ===== Desktop ===== */
@media (min-width: 768px) {
    #game-screen {
        max-width: 600px;
        margin: 0 auto;
        border-left: 1px solid rgba(232, 168, 56, 0.08);
        border-right: 1px solid rgba(232, 168, 56, 0.08);
    }
}