/* ── Loop Warrior — Dark Space Theme (M2) ── */

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

:root {
    --bg-dark: #0a0a1a;
    --bg-mid: #111128;
    --text-primary: #e0e0f0;
    --text-dim: rgba(255,255,255,0.5);
    --accent: #00e5ff;
    --accent-dim: rgba(0,229,255,0.3);
    --danger: #f44336;
    --success: #4caf50;
    --gold: #d4af37;
}

html, body {
    background: var(--bg-dark);
    color: var(--text-primary);
    font-family: 'Segoe UI', system-ui, sans-serif;
    min-height: 100vh;
    overflow-x: hidden;
    -webkit-tap-highlight-color: transparent;
}

/* ── Header ── */

.game-header {
    text-align: center;
    padding: 16px 12px 8px;
}

.game-header h1 {
    font-family: monospace;
    font-size: 1.4em;
    letter-spacing: 2px;
    color: var(--accent);
    text-shadow: 0 0 20px var(--accent-dim);
}

.game-header .subtitle {
    font-size: 0.85em;
    color: var(--text-dim);
    margin-top: 4px;
}

/* ── Map Container ── */

.map-container {
    display: flex;
    justify-content: center;
    padding: 8px 12px;
}

#map-canvas {
    max-width: 100%;
    border-radius: 12px;
    border: 1px solid rgba(255,255,255,0.08);
    background: var(--bg-dark);
    touch-action: manipulation;
}

/* ── World Page ── */

.world-container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.scene-wrapper {
    position: relative;
    width: 100%;
    flex-shrink: 0;
}

#scene-canvas {
    display: block;
    width: 100%;
    border-bottom: 2px solid rgba(255,255,255,0.1);
}

/* HUD overlay */
.hud-overlay {
    position: absolute;
    top: 8px;
    left: 8px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    pointer-events: none;
}

.hud-item {
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(4px);
    padding: 4px 10px;
    border-radius: 8px;
    font-size: 0.75em;
    font-family: monospace;
    white-space: nowrap;
}

/* ── Story Panel ── */

.story-panel {
    flex: 1;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-width: 700px;
    margin: 0 auto;
    width: 100%;
    touch-action: manipulation;
    cursor: pointer;
    -webkit-user-select: none;
    user-select: none;
}

.story-dialogue {
    display: flex;
    align-items: flex-start;
    gap: 16px;
}

.story-text-col {
    flex: 1;
    min-width: 0;
}

.speaker-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 0.75em;
    font-weight: bold;
    letter-spacing: 1px;
    text-transform: uppercase;
}

.speaker-badge.ellie {
    background: linear-gradient(135deg, #7c4dff, #448aff);
    color: #fff;
}

.speaker-badge.isaac {
    background: linear-gradient(135deg, #ff9800, #ffc107);
    color: #1a1a2a;
}

.speaker-badge.narrator {
    background: rgba(255,255,255,0.12);
    color: var(--text-dim);
}

.story-text {
    font-size: 1.25em;
    line-height: 1.6;
    min-height: 3em;
    padding: 4px 0;
    cursor: pointer;
}

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

@keyframes blink {
    50% { opacity: 0; }
}

.story-progress {
    display: flex;
    gap: 6px;
    justify-content: center;
    padding: 4px 0;
}

.story-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: rgba(255,255,255,0.2);
    transition: background 0.3s, transform 0.3s;
}

.story-dot.done {
    background: var(--accent);
}

.story-dot.active {
    background: #fff;
    transform: scale(1.3);
}

.tap-hint {
    text-align: center;
    font-size: 0.7em;
    color: var(--text-dim);
    padding: 2px 0;
}

/* ── Character Portraits ── */

.portrait-container {
    width: 0;
    height: 0;
    border-radius: 50%;
    overflow: hidden;
    border: 4px solid rgba(255,255,255,0.35);
    flex-shrink: 0;
    opacity: 0;
    transform: scale(0.8);
    transition: opacity 0.3s, transform 0.3s, width 0.3s, height 0.3s;
    box-shadow: 0 3px 12px rgba(0,0,0,0.4);
}

.portrait-container.visible {
    width: 140px;
    height: 140px;
    opacity: 1;
    transform: scale(1);
}

.portrait-container .portrait-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Portrait emotion animations */
@keyframes portrait-bounce {
    0% { transform: scale(1); }
    30% { transform: scale(1.08); }
    100% { transform: scale(1); }
}

.portrait-bounce {
    animation: portrait-bounce 0.3s ease-out;
}

@keyframes portrait-shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-2px); }
    75% { transform: translateX(2px); }
}

.portrait-worried .portrait-img {
    animation: portrait-shake 0.4s ease-in-out;
}

@keyframes portrait-glow {
    0%, 100% { box-shadow: 0 0 4px var(--accent); }
    50% { box-shadow: 0 0 12px var(--accent); }
}

.portrait-excited {
    animation: portrait-glow 1.5s ease-in-out infinite;
    border-color: var(--accent) !important;
}

.portrait-triumphant {
    border-color: var(--gold) !important;
}

.portrait-mysterious {
    border-color: #7c4dff !important;
}

/* ── Choice Buttons ── */

.choices {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 12px 0;
}

.choice-btn {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 18px;
    border: 2px solid rgba(255,255,255,0.15);
    border-radius: 14px;
    background: rgba(255,255,255,0.04);
    color: var(--text-primary);
    font-size: 1em;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
    touch-action: manipulation;
    min-height: 48px;
}

.choice-btn:hover, .choice-btn:focus {
    border-color: var(--accent);
    background: rgba(0, 229, 255, 0.08);
    transform: translateX(4px);
}

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

/* Hypothetical choice — golden glow */
.choice-hypothetical {
    border-color: var(--gold);
    background: rgba(212, 175, 55, 0.06);
}

.choice-hypothetical:hover, .choice-hypothetical:focus {
    border-color: var(--gold);
    background: rgba(212, 175, 55, 0.15);
}

.choice-hypothetical .choice-label::before {
    content: 'What if: ';
    color: var(--gold);
    font-size: 0.8em;
    font-weight: bold;
}

.choice-emoji {
    font-size: 1.6em;
}

.choice-label {
    flex: 1;
}

.choice-arrow {
    font-size: 1.2em;
    color: var(--text-dim);
}

/* Hidden until story complete */
.choices.hidden {
    display: none;
}

/* ── Back to Map button ── */

.nav-bar {
    display: flex;
    align-items: center;
    padding: 8px 12px;
    gap: 12px;
}

.back-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    border-radius: 8px;
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.12);
    color: var(--accent);
    font-size: 0.85em;
    text-decoration: none;
    transition: background 0.2s;
}

.back-btn:hover {
    background: rgba(255,255,255,0.1);
}

.node-title {
    font-family: monospace;
    font-size: 1em;
    color: var(--text-primary);
    letter-spacing: 1px;
}

.node-mya {
    font-size: 0.8em;
    color: var(--text-dim);
    margin-left: 8px;
}

/* ── Creature Tooltip ── */

.creature-tooltip {
    position: absolute;
    background: rgba(0,0,0,0.85);
    backdrop-filter: blur(6px);
    border: 1px solid rgba(255,255,255,0.15);
    border-radius: 10px;
    padding: 10px 14px;
    max-width: 260px;
    font-size: 0.85em;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s;
    z-index: 10;
}

.creature-tooltip.visible {
    opacity: 1;
}

.creature-tooltip .name {
    font-weight: bold;
    color: var(--accent);
    margin-bottom: 4px;
}

.creature-tooltip .fact {
    color: var(--text-dim);
    line-height: 1.4;
}

/* ── Collected Badge (tooltip) ── */

.collected-badge {
    display: none;
    padding: 3px 8px;
    border-radius: 10px;
    font-size: 0.7em;
    font-weight: bold;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    margin-bottom: 4px;
    background: rgba(212, 175, 55, 0.15);
    color: var(--gold);
    border: 1px solid rgba(212, 175, 55, 0.3);
}

.collected-badge.visible {
    display: inline-block;
}

.collected-badge.new {
    background: rgba(212, 175, 55, 0.3);
    border-color: var(--gold);
    animation: badge-flash 0.6s ease-out;
}

@keyframes badge-flash {
    0% { transform: scale(1.3); opacity: 0.5; }
    100% { transform: scale(1); opacity: 1; }
}

/* ── Footer ── */

.game-footer {
    text-align: center;
    padding: 12px;
    font-size: 0.85em;
    color: var(--text-dim);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.field-guide-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    border-radius: 12px;
    background: rgba(212, 175, 55, 0.08);
    border: 1.5px solid rgba(212, 175, 55, 0.25);
    color: var(--gold);
    font-size: 1em;
    font-family: inherit;
    text-decoration: none;
    transition: all 0.2s;
    cursor: pointer;
}

.field-guide-btn:hover {
    background: rgba(212, 175, 55, 0.15);
    border-color: var(--gold);
    transform: translateY(-1px);
}

.guide-pill {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    background: rgba(212, 175, 55, 0.2);
    font-size: 0.8em;
    font-weight: bold;
    min-width: 20px;
    text-align: center;
}

.footer-hint {
    font-size: 0.85em;
    color: var(--text-dim);
}

/* ── Field Guide Page ── */

.guide-container {
    max-width: 800px;
    margin: 0 auto;
    padding: 0 16px 32px;
    min-height: 100vh;
}

.guide-nav {
    display: flex;
    align-items: center;
    padding: 12px 0;
    gap: 12px;
}

.guide-title {
    font-family: monospace;
    font-size: 1.1em;
    color: var(--gold);
    letter-spacing: 1px;
    flex: 1;
}

.guide-counter {
    padding: 4px 12px;
    border-radius: 12px;
    background: rgba(212, 175, 55, 0.15);
    border: 1px solid rgba(212, 175, 55, 0.3);
    color: var(--gold);
    font-size: 0.85em;
    font-weight: bold;
    font-family: monospace;
}

.guide-progress-bar {
    width: 100%;
    height: 6px;
    background: rgba(255,255,255,0.08);
    border-radius: 3px;
    overflow: hidden;
    margin-bottom: 20px;
}

.guide-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--gold), #f0d060);
    border-radius: 3px;
    transition: width 0.5s ease-out;
}

.guide-section {
    margin-bottom: 24px;
}

.guide-era-header {
    display: flex;
    align-items: baseline;
    gap: 10px;
    padding: 8px 0 6px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    margin-bottom: 12px;
}

.guide-era-name {
    font-family: monospace;
    font-size: 0.95em;
    color: var(--text-primary);
    letter-spacing: 0.5px;
}

.guide-era-mya {
    font-size: 0.75em;
    color: var(--text-dim);
}

.guide-era-count {
    margin-left: auto;
    font-size: 0.75em;
    color: var(--gold);
    font-family: monospace;
}

.guide-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 12px;
}

.guide-card {
    background: rgba(255,255,255,0.03);
    border: 1.5px solid rgba(255,255,255,0.08);
    border-radius: 12px;
    padding: 12px;
    text-align: center;
    transition: all 0.2s;
}

.guide-card.collected {
    border-color: rgba(212, 175, 55, 0.35);
    background: rgba(212, 175, 55, 0.04);
}

.guide-card.undiscovered {
    opacity: 0.6;
}

.guide-sprite {
    width: 80px;
    height: 80px;
    margin: 0 auto 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 3em;
}

.guide-sprite img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.guide-card.undiscovered .guide-sprite {
    filter: brightness(0) opacity(0.3);
}

.guide-card.undiscovered .guide-sprite img {
    filter: brightness(0) opacity(0.3);
}

.guide-name {
    font-size: 0.85em;
    font-weight: bold;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.guide-card.collected .guide-name {
    color: var(--gold);
}

.guide-fact {
    font-size: 0.7em;
    color: var(--text-dim);
    line-height: 1.4;
}

.guide-hint {
    font-size: 0.7em;
    color: var(--text-dim);
    font-style: italic;
    line-height: 1.4;
}

.guide-empty {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-dim);
    font-size: 0.95em;
}

/* ── Collection Tray ── */

.collection-tray {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 5;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 8px;
    background: rgba(0, 0, 0, 0.45);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

.collection-tray::-webkit-scrollbar {
    display: none;
}

.tray-slots {
    display: flex;
    gap: 8px;
    flex: 1;
    min-width: 0;
}

.tray-slot {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    transition: border-color 0.3s;
}

.tray-slot.empty {
    border: 2px dashed rgba(212, 175, 55, 0.3);
    background: rgba(255, 255, 255, 0.02);
}

.tray-slot.empty::after {
    content: '?';
    font-size: 1.1em;
    font-weight: bold;
    color: rgba(212, 175, 55, 0.3);
}

.tray-slot.filled {
    border: 2px solid var(--gold);
    background: rgba(212, 175, 55, 0.08);
}

.tray-slot.filled img {
    width: 28px;
    height: 28px;
    object-fit: contain;
}

.tray-slot.filled .tray-emoji {
    font-size: 1.3em;
    line-height: 1;
}

.tray-slot.pop {
    animation: tray-pop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes tray-pop {
    0%   { transform: scale(0); }
    50%  { transform: scale(1.3); }
    70%  { transform: scale(0.9); }
    100% { transform: scale(1.0); }
}

.tray-counter {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    background: rgba(212, 175, 55, 0.2);
    color: var(--gold);
    font-size: 0.8em;
    font-weight: bold;
    font-family: monospace;
    min-width: 36px;
    text-align: center;
    flex-shrink: 0;
}

/* ── Fly Sprite ── */

.fly-sprite {
    position: fixed;
    z-index: 100;
    pointer-events: none;
}

.fly-sprite img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.fly-sprite .fly-emoji {
    font-size: inherit;
    line-height: 1;
}

/* ── Mini Timeline Strip ── */

.mini-timeline {
    width: 100%;
    background: rgba(0, 0, 0, 0.4);
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

#mini-timeline-canvas {
    display: block;
    width: 100%;
    height: 64px;
}

/* ── Responsive ── */

@media (max-width: 500px) {
    .game-header h1 { font-size: 1.1em; }
    .story-text { font-size: 1em; }
    .choice-btn { padding: 12px 14px; }
    .hud-item { font-size: 0.65em; }
    .portrait-container.visible { width: 100px; height: 100px; border-width: 3px; }
}
