/* ═══════════════════════════════════════════════════════════════════════════
 * main.css — Core layout & theme for The Wandering Ledger SPA
 *
 * Medieval parchment aesthetic with warm dark tones.
 * Uses CSS Grid for the game screen layout (1280x720 reference).
 * ═══════════════════════════════════════════════════════════════════════════ */

/* ── CSS Custom Properties (Theme) ─────────────────────────────────────── */
:root {
    /* Background palette — warm parchment darks */
    --bg-deep:        #1a1410;
    --bg-dark:        #231e17;
    --bg-medium:      #2e2620;
    --bg-warm:        #3a3028;
    --bg-parchment:   #4a3e32;
    --bg-highlight:   #5a4e3e;

    /* Text palette */
    --text-primary:   #e8dcc8;
    --text-secondary: #c4b59a;
    --text-muted:     #8a7d6b;
    --text-dim:       #6a5f50;

    /* Accent colors (matching the game's terminal palette) */
    --gold:           #daa520;
    --gold-light:     #f0c850;
    --gold-dim:       #a07818;
    --red:            #cb5b5b;
    --red-dark:       #8b3a3a;
    --green:          #72c472;
    --green-dark:     #4a8a4a;
    --blue:           #75b5e8;
    --blue-dark:      #4a7aaa;
    --violet:         #b48ede;
    --violet-dark:    #7a5aaa;
    --teal:           #50cccc;
    --teal-dark:      #3a8a8a;
    --orange:         #d08040;
    --pink:           #da9aba;
    --silver:         #c0b8a8;
    --brown:          #8a6a30;
    --cream:          #dfc89a;
    --amber:          #d6a030;

    /* UI metrics */
    --hud-height:     48px;
    --action-height:  64px;
    --portrait-width: 240px;
    --info-width:     380px;
    --border-radius:  6px;
    --border-radius-sm: 4px;

    /* Typography */
    --font-heading:   'Cinzel', 'Georgia', serif;
    --font-body:      'Cormorant Garamond', 'Palatino', serif;
    --font-prose:     'IM Fell English', 'Georgia', serif;
    --font-mono:      'Consolas', 'Courier New', monospace;

    /* Shadows & effects */
    --shadow-soft:    0 2px 8px rgba(0, 0, 0, 0.4);
    --shadow-hard:    0 4px 16px rgba(0, 0, 0, 0.6);
    --glow-gold:      0 0 12px rgba(218, 165, 32, 0.3);
    --glow-violet:    0 0 12px rgba(180, 142, 222, 0.3);
    --border-subtle:  1px solid rgba(200, 180, 140, 0.15);
    --border-accent:  1px solid rgba(218, 165, 32, 0.3);
}


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

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: var(--font-body);
    font-size: 16px;
    line-height: 1.5;
    color: var(--text-primary);
    background: var(--bg-deep);
    /* Prevent pull-to-refresh and rubber-banding on mobile */
    overscroll-behavior: none;
    -webkit-tap-highlight-color: transparent;
}

html {
    /* Use dvh for mobile browsers that have dynamic viewport
       dvh MUST come after 100% so it overrides on supporting browsers */
    height: 100%;
    height: 100dvh;
}

body {
    /* Subtle parchment grain texture via gradient noise */
    background-image:
        radial-gradient(ellipse at 20% 30%, rgba(60, 45, 25, 0.4) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 70%, rgba(45, 35, 20, 0.3) 0%, transparent 50%),
        linear-gradient(180deg, var(--bg-deep) 0%, #1e1812 50%, var(--bg-deep) 100%);
}

a { color: var(--gold); text-decoration: none; }
a:hover { color: var(--gold-light); text-decoration: underline; }

::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: var(--bg-dark); }
::-webkit-scrollbar-thumb { background: var(--bg-parchment); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--bg-highlight); }


/* ── Screens ───────────────────────────────────────────────────────────── */
.screen {
    position: absolute;
    inset: 0;
    display: none;
    opacity: 0;
    transition: opacity 0.5s ease;
    /* dvh after 100% so it overrides on supporting browsers */
    height: 100%;
    height: 100dvh;
    /* Support CSS var set by Visual Viewport API (JS fallback for keyboard) */
    height: var(--app-height, 100dvh);
}

.screen.active {
    display: flex;
    opacity: 1;
}


/* ══════════════════════════════════════════════════════════════════════════
 * TITLE SCREEN
 * ═════════════════════════════════════════════════════════════════════════ */
#title-screen {
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background:
        radial-gradient(ellipse at center, rgba(60, 45, 20, 0.6) 0%, transparent 60%),
        linear-gradient(170deg, #1a1208 0%, #2a1e10 40%, #1e1610 80%, #120e08 100%);
}

.title-overlay {
    position: absolute;
    inset: 0;
    background:
        repeating-linear-gradient(0deg,   transparent, transparent 3px, rgba(0,0,0,0.03) 3px, rgba(0,0,0,0.03) 4px),
        repeating-linear-gradient(90deg,  transparent, transparent 3px, rgba(0,0,0,0.02) 3px, rgba(0,0,0,0.02) 4px);
    pointer-events: none;
}

.title-content {
    position: relative;
    z-index: 1;
    text-align: center;
    animation: fadeInUp 1.2s ease-out;
}

.title-heading {
    font-family: var(--font-heading);
    font-size: 4rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    margin-bottom: 0.2em;
    text-shadow: 0 0 40px rgba(218, 165, 32, 0.3), 0 2px 4px rgba(0, 0, 0, 0.8);
}

.title-spice { color: var(--gold-light); }
.title-and {
    color: var(--text-muted);
    font-size: 0.6em;
    margin: 0 0.3em;
    vertical-align: middle;
}
.title-wolf { color: var(--cream); }

.title-subtitle {
    font-family: var(--font-prose);
    font-size: 1.6rem;
    font-weight: 400;
    font-style: italic;
    color: var(--text-secondary);
    margin-bottom: 1.2em;
    letter-spacing: 0.12em;
}

.title-motto {
    font-family: var(--font-prose);
    font-size: 1.1rem;
    font-style: italic;
    color: var(--text-muted);
    margin-bottom: 3em;
}

.title-menu {
    display: flex;
    flex-direction: column;
    gap: 0.8em;
    align-items: center;
}

.title-btn {
    min-width: 280px;
    font-size: 1.1rem;
    letter-spacing: 0.06em;
}

.title-version {
    margin-top: 3em;
    font-size: 0.8rem;
    color: var(--text-dim);
}


/* ══════════════════════════════════════════════════════════════════════════
 * GAME SCREEN — CSS Grid Layout
 * ═════════════════════════════════════════════════════════════════════════ */
#game-screen {
    flex-direction: column;
    max-width: 100vw;
    overflow-x: hidden;
}

/* HUD BAR ─────────────────────────────────────────────────────────────── */
#hud-bar {
    height: var(--hud-height);
    display: flex;
    align-items: center;
    gap: 1em;
    padding: 0 1em;
    background: linear-gradient(180deg, var(--bg-warm) 0%, var(--bg-medium) 100%);
    border-bottom: var(--border-accent);
    font-size: 0.85rem;
    flex-shrink: 0;
    z-index: 10;
}

.hud-section {
    display: flex;
    align-items: center;
    gap: 0.3em;
    white-space: nowrap;
}

.hud-label {
    color: var(--text-secondary);
    font-weight: 600;
}

.hud-value {
    color: var(--text-primary);
    font-weight: 600;
    font-family: var(--font-mono);
}

.hud-unit {
    color: var(--text-muted);
    font-size: 0.75em;
}

.hud-sep {
    color: var(--text-dim);
    margin: 0 0.2em;
}

.hud-icon {
    font-size: 1em;
}

.hud-badge {
    background: var(--bg-parchment);
    color: var(--gold);
    padding: 0.1em 0.5em;
    border-radius: var(--border-radius-sm);
    font-size: 0.75rem;
    font-family: var(--font-heading);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.hud-day-counter {
    font-family: var(--font-heading);
    color: var(--gold);
    font-weight: 600;
}

.hud-identity {
    flex: 0 0 auto;
}

.hud-economy .hud-value {
    color: var(--gold);
    min-width: 40px;
    text-align: right;
}

.hud-pool-sep {
    color: var(--text-dim);
    margin: 0 0.15em;
    font-size: 0.8em;
}

.hud-pool-icon {
    font-size: 0.85em;
}

.hud-controls {
    margin-left: auto;
    gap: 0.4em;
}

.hud-btn {
    background: none;
    border: var(--border-subtle);
    color: var(--text-muted);
    width: 32px;
    height: 32px;
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    font-size: 1em;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.hud-btn:hover {
    background: var(--bg-parchment);
    color: var(--text-primary);
    border-color: var(--gold-dim);
}

.hud-btn.active {
    background: var(--gold-dim);
    color: var(--bg-deep);
}


/* MAIN CONTENT — 3-column grid ─────────────────────────────────────────── */
#main-content {
    flex: 1;
    display: grid;
    grid-template-columns: var(--portrait-width) 1fr var(--info-width);
    grid-template-rows: 1fr;
    gap: 0;
    overflow: hidden;
    min-height: 0;
}


/* PORTRAIT AREA (left) ─────────────────────────────────────────────────── */
#portrait-area {
    background: linear-gradient(180deg, var(--bg-medium) 0%, var(--bg-dark) 100%);
    border-right: var(--border-subtle);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 1em 0.5em;
    overflow-y: auto;
}

#portrait-frame {
    width: 200px;
    height: 200px;
    border-radius: var(--border-radius);
    border: 2px solid var(--bg-parchment);
    overflow: hidden;
    position: relative;
    background: var(--bg-dark);
    box-shadow: var(--shadow-soft);
    flex-shrink: 0;
}

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

.portrait-placeholder {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--bg-parchment), var(--bg-warm));
}

.portrait-initial {
    font-family: var(--font-heading);
    font-size: 4rem;
    color: var(--text-dim);
}

.portrait-name {
    text-align: center;
    font-family: var(--font-heading);
    font-size: 0.9rem;
    color: var(--gold);
    margin-top: 0.6em;
    letter-spacing: 0.05em;
}

.portrait-emotion {
    text-align: center;
    font-family: var(--font-prose);
    font-style: italic;
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 0.2em;
}

.portrait-gallery {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5em;
    justify-content: center;
    margin-top: 0.5em;
}

.portrait-gallery .gallery-thumb {
    width: 80px;
    height: 80px;
    border-radius: var(--border-radius-sm);
    border: 2px solid var(--bg-parchment);
    overflow: hidden;
    cursor: pointer;
    transition: border-color 0.2s;
}

.portrait-gallery .gallery-thumb.speaking {
    border-color: var(--gold);
    box-shadow: var(--glow-gold);
}

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

/* Gallery items (populated by Components.showPortraitGallery) */
.gallery-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 90px;
}

.gallery-portrait {
    width: 80px;
    height: 80px;
    border-radius: var(--border-radius-sm);
    border: 2px solid var(--bg-parchment);
    object-fit: cover;
    transition: border-color 0.2s;
}

.gallery-portrait:hover {
    border-color: var(--gold);
    box-shadow: var(--glow-gold);
}

.gallery-name {
    font-family: var(--font-heading);
    font-size: 0.7rem;
    color: var(--text-muted);
    text-align: center;
    margin-top: 0.2em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 90px;
}

.gallery-fallback {
    width: 80px;
    height: 80px;
    border-radius: var(--border-radius-sm);
    border: 2px solid var(--bg-parchment);
    background: var(--bg-dark);
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-heading);
    font-size: 1.6rem;
    color: var(--gold);
}

.npc-meters {
    width: 100%;
    margin-top: 1em;
    padding: 0 0.5em;
}

.meter-row {
    display: flex;
    align-items: center;
    gap: 0.5em;
    margin-bottom: 0.4em;
    font-size: 0.8rem;
}

.meter-row label {
    width: 28px;
    color: var(--text-muted);
    font-family: var(--font-heading);
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.meter-bar {
    flex: 1;
    height: 8px;
    background: var(--bg-dark);
    border-radius: 4px;
    overflow: hidden;
}

.meter-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.5s ease;
}

.rel-fill { background: linear-gradient(90deg, var(--teal-dark), var(--teal)); }
.rom-fill { background: linear-gradient(90deg, var(--pink), #e8a0c0); }

.meter-val {
    width: 28px;
    text-align: right;
    color: var(--text-secondary);
    font-family: var(--font-mono);
    font-size: 0.75rem;
}


/* NARRATIVE AREA (center) ───────────────────────────────────────────────── */
#narrative-area {
    display: flex;
    flex-direction: column;
    background: var(--bg-dark);
    overflow: hidden;
    min-height: 0;
}

#narrative-panel {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

#narrative-log {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 1em 1.5em;
    font-family: var(--font-prose);
    font-size: 1rem;
    line-height: 1.7;
    overflow-wrap: break-word;
    word-break: break-word;
}

.narrative-line {
    margin-bottom: 0.4em;
    animation: fadeIn 0.3s ease;
    overflow-wrap: break-word;
    word-break: break-word;
}

.narrative-line.speaker-line {
    color: var(--cream);
}

.narrative-line .speaker-name {
    color: var(--gold);
    font-weight: 600;
    font-family: var(--font-heading);
    font-size: 0.85em;
}

.narrative-line.system-line {
    color: var(--text-muted);
    font-style: italic;
    font-size: 0.9em;
}

/* System narrative entries (inner thoughts, probabilities, meters) */
.narrative-entry {
    margin-bottom: 0.4em;
    animation: fadeIn 0.3s ease;
    overflow-wrap: break-word;
    word-break: break-word;
    line-height: 1.6;
}

.narrative-entry .narrative-text {
    display: block;
}

.narrative-entry.narrative-system {
    color: var(--text-muted);
    font-size: 0.88em;
    line-height: 1.5;
    padding: 0.3em 0.6em;
    border-left: 2px solid rgba(138, 125, 107, 0.3);
    margin-left: 0.2em;
    background: rgba(30, 26, 20, 0.3);
    border-radius: 0 4px 4px 0;
}

.narrative-entry.narrative-system strong {
    color: var(--silver);
    font-weight: 600;
}

.narrative-entry.narrative-system em {
    font-style: italic;
    color: var(--text-secondary);
}

.narrative-line.action-line {
    color: var(--silver);
    font-style: italic;
}

.narrative-line.important-line {
    color: var(--gold);
    font-weight: 600;
    border-left: 3px solid var(--gold-dim);
    padding-left: 0.8em;
}

.narrative-line.danger-line {
    color: var(--red);
    border-left: 3px solid var(--red-dark);
    padding-left: 0.8em;
}

.narrative-line.success-line {
    color: var(--green);
}


/* ── Chat-style bubbles (scene NPC dialogue) ──────────────────────────── */
.chat-bubble {
    display: flex;
    align-items: flex-start;
    gap: 0.6em;
    margin-bottom: 0.8em;
    padding: 0.6em 0.8em;
    background: rgba(74, 62, 50, 0.4);
    border-left: 3px solid var(--gold-dim);
    border-radius: 0 var(--border-radius) var(--border-radius) 0;
    animation: fadeIn 0.3s ease;
}

.chat-avatar {
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    overflow: hidden;
    border: 2px solid var(--bg-highlight);
    background: var(--bg-warm);
}

.chat-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.chat-avatar-fallback {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-heading);
    font-size: 1.1rem;
    color: var(--gold);
    background: linear-gradient(135deg, var(--bg-warm), var(--bg-highlight));
}

.chat-content {
    flex: 1;
    min-width: 0;
}

.chat-speaker {
    font-family: var(--font-heading);
    font-size: 0.8rem;
    color: var(--gold);
    font-weight: 600;
    margin-bottom: 0.15em;
}

.chat-text {
    font-family: var(--font-prose);
    font-size: 0.95rem;
    line-height: 1.6;
    color: var(--cream);
    overflow-wrap: break-word;
}

.chat-text em {
    color: var(--silver);
}

.chat-text strong {
    color: var(--gold-light);
}

.chat-bubble.chat-player {
    background: rgba(55, 65, 50, 0.45);
    border-left: none;
    border-right: 3px solid var(--silver);
    border-radius: var(--border-radius) 0 0 var(--border-radius);
    flex-direction: row-reverse;
}

.chat-bubble.chat-player .chat-content {
    text-align: right;
}

.chat-bubble.chat-player .chat-speaker {
    color: var(--silver);
}


/* INPUT AREA ─────────────────────────────────────────────────────────────── */
#input-area {
    flex-shrink: 0;
    padding: 0.8em 1.5em;
    background: linear-gradient(0deg, var(--bg-medium) 0%, var(--bg-dark) 100%);
    border-top: var(--border-subtle);
    min-height: 60px;
}

.input-mode {
    display: none;
}

.input-mode.active {
    display: block;
    animation: fadeIn 0.2s ease;
}

.input-prompt {
    font-family: var(--font-prose);
    color: var(--text-secondary);
    margin-bottom: 0.5em;
    font-size: 0.95rem;
}

.menu-options {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4em;
}

.menu-option {
    background: var(--bg-parchment);
    border: var(--border-subtle);
    color: var(--text-primary);
    padding: 0.4em 1em;
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    font-family: var(--font-body);
    font-size: 0.9rem;
    transition: all 0.15s;
    display: flex;
    align-items: center;
    gap: 0.4em;
}

.menu-option:hover {
    background: var(--bg-highlight);
    border-color: var(--gold-dim);
    color: var(--gold-light);
}

.menu-option:active {
    transform: scale(0.97);
}

.menu-option .option-key {
    color: var(--gold);
    font-family: var(--font-mono);
    font-size: 0.8em;
    background: var(--bg-dark);
    padding: 0.1em 0.4em;
    border-radius: 3px;
    min-width: 1.5em;
    text-align: center;
}

.menu-option.disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.text-input-row {
    display: flex;
    gap: 0.5em;
}

.text-input {
    flex: 1;
    background: var(--bg-dark);
    border: var(--border-subtle);
    color: var(--text-primary);
    padding: 0.5em 0.8em;
    border-radius: var(--border-radius-sm);
    font-family: var(--font-body);
    font-size: 0.95rem;
    outline: none;
    transition: border-color 0.2s;
}

.text-input:focus {
    border-color: var(--gold-dim);
}

.text-input::placeholder {
    color: var(--text-dim);
}

.yn-buttons {
    display: flex;
    gap: 0.6em;
}


/* ── Dynamic menu/input elements (rendered by components.js) ────────── */
.menu-prompt,
.input-prompt {
    font-family: var(--font-prose);
    color: var(--text-secondary);
    margin-bottom: 0.6em;
    font-size: 0.95rem;
    max-height: 50vh;
    overflow-y: auto;
    line-height: 1.5;
    white-space: pre-wrap;
}

.menu-container {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5em;
}

.menu-btn,
.btn-menu {
    background: var(--bg-parchment);
    border: 1px solid rgba(200, 180, 140, 0.25);
    color: var(--text-primary);
    padding: 0.5em 1.2em;
    border-radius: var(--border-radius);
    cursor: pointer;
    font-family: var(--font-body);
    font-size: 0.9rem;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 0.4em;
    line-height: 1.4;
}

.menu-btn:hover,
.btn-menu:hover {
    background: var(--bg-highlight);
    border-color: var(--gold-dim);
    color: var(--gold-light);
    box-shadow: 0 0 8px rgba(218, 165, 32, 0.15);
    transform: translateY(-1px);
}

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

.text-input-container {
    display: flex;
    flex-direction: column;
    gap: 0.4em;
}

.input-row {
    display: flex;
    gap: 0.5em;
    align-items: center;
}

.submit-btn {
    flex-shrink: 0;
}

/* ── Dialogue Suggestions ─────────────────────────────────────────────── */
.dialogue-suggestions {
    display: flex;
    flex-wrap: nowrap;
    gap: 0.35em;
    margin-bottom: 0.4em;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: var(--bg-highlight) transparent;
    padding-bottom: 0.2em;
}
.dialogue-suggestions::-webkit-scrollbar {
    height: 4px;
}
.dialogue-suggestions::-webkit-scrollbar-thumb {
    background: var(--bg-highlight);
    border-radius: 2px;
}

.suggestion-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4em;
    padding: 0.35em 0.75em;
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 1em;
    font-family: var(--font-body);
    font-size: 0.78rem;
    line-height: 1.3;
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s, transform 0.1s;
    text-align: left;
    white-space: nowrap;
    flex-shrink: 0;
}
.suggestion-btn .suggestion-label {
    font-size: 0.6rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    opacity: 0.7;
    font-weight: 600;
}

.suggestion-btn:hover {
    transform: translateY(-1px);
    border-color: rgba(255, 255, 255, 0.35);
}

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

/* Friendship — warm amber */
.suggestion-friendship {
    background: rgba(140, 110, 60, 0.35);
    color: var(--cream);
    border-color: rgba(180, 140, 70, 0.3);
}
.suggestion-friendship:hover {
    background: rgba(160, 130, 70, 0.5);
}

/* Romance — soft rose */
.suggestion-romance {
    background: rgba(140, 60, 80, 0.35);
    color: #e8b4b8;
    border-color: rgba(180, 80, 100, 0.3);
}
.suggestion-romance:hover {
    background: rgba(160, 70, 90, 0.5);
}

/* Info — cool silver/blue */
.suggestion-info {
    background: rgba(60, 90, 130, 0.35);
    color: var(--silver);
    border-color: rgba(80, 120, 160, 0.3);
}
.suggestion-info:hover {
    background: rgba(70, 100, 150, 0.5);
}

/* Sexual — deep purple/magenta */
.suggestion-sexual {
    background: rgba(120, 40, 110, 0.35);
    color: #d4a0d0;
    border-color: rgba(160, 60, 140, 0.3);
}
.suggestion-sexual:hover {
    background: rgba(140, 50, 130, 0.5);
}

/* Degen — dark crimson/blood */
.suggestion-degen {
    background: rgba(100, 20, 30, 0.4);
    color: #c87070;
    border-color: rgba(140, 30, 40, 0.35);
}
.suggestion-degen:hover {
    background: rgba(120, 30, 40, 0.55);
}

/* Provoke — sharp amber/red */
.suggestion-provoke {
    background: rgba(140, 70, 40, 0.35);
    color: #e8a870;
    border-color: rgba(180, 90, 50, 0.3);
}
.suggestion-provoke:hover {
    background: rgba(160, 80, 50, 0.5);
}


/* INFO PANEL (right) ────────────────────────────────────────────────────── */
#info-panel {
    background: linear-gradient(180deg, var(--bg-medium) 0%, var(--bg-dark) 100%);
    border-left: var(--border-subtle);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.info-tabs {
    display: flex;
    border-bottom: var(--border-subtle);
    flex-shrink: 0;
}

.info-tab {
    flex: 1;
    padding: 0.5em 0;
    background: none;
    border: none;
    color: var(--text-muted);
    font-family: var(--font-heading);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    cursor: pointer;
    transition: all 0.2s;
    border-bottom: 2px solid transparent;
}

.info-tab:hover {
    color: var(--text-secondary);
    background: rgba(255, 255, 255, 0.02);
}

.info-tab.active {
    color: var(--gold);
    border-bottom-color: var(--gold);
}

.info-tab-content {
    display: none;
    flex: 1;
    overflow-y: auto;
    padding: 0.8em;
}

.info-tab-content.active {
    display: flex;
    flex-direction: column;
}

.info-heading {
    font-family: var(--font-heading);
    font-size: 0.85rem;
    color: var(--gold);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 0.6em;
    padding-bottom: 0.3em;
    border-bottom: var(--border-subtle);
}

.scroll-list {
    flex: 1;
    overflow-y: auto;
}

.empty-state {
    color: var(--text-dim);
    font-style: italic;
    text-align: center;
    padding: 2em 0;
    font-family: var(--font-prose);
}

/* Map canvas container */
#tab-map {
    padding: 0.5em;
}

.map-container {
    position: relative;
}

#map-canvas {
    width: 100%;
    height: auto;
    aspect-ratio: 6 / 5;
    border-radius: var(--border-radius);
    background: var(--bg-deep);
    cursor: grab;
}

#map-canvas:active {
    cursor: grabbing;
}

/* Sidebar fullscreen expand button */
.map-fullscreen-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 28px;
    height: 28px;
    background: rgba(58, 48, 40, 0.85);
    border: 1px solid rgba(218, 165, 32, 0.3);
    border-radius: var(--border-radius-sm);
    color: var(--gold);
    font-size: 1rem;
    cursor: pointer;
    z-index: 5;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    line-height: 1;
}

.map-fullscreen-btn:hover {
    background: var(--gold-dim);
    color: var(--bg-deep);
}

.map-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5em;
    padding: 0.4em 0;
    font-size: 0.7rem;
    color: var(--text-muted);
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.25em;
}

.legend-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
}

.legend-dot.village  { background: var(--green); }
.legend-dot.town     { background: var(--blue); }
.legend-dot.city     { background: var(--gold); }
.legend-dot.port     { background: var(--teal); }
.legend-dot.religious { background: var(--violet); }
.legend-dot.mining   { background: var(--orange); }

.legend-sep {
    width: 1px;
    height: 12px;
    background: rgba(200, 180, 140, 0.2);
    margin: 0 0.15em;
    align-self: center;
}

.legend-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    font-size: 0.6rem;
    font-weight: 700;
    line-height: 1;
    flex-shrink: 0;
}

.legend-icon.event-quest      { background: rgba(255, 179, 0, 0.25); color: #FFB300; }
.legend-icon.event-festival   { background: rgba(76, 175, 80, 0.25); color: #4CAF50; }
.legend-icon.event-war        { background: rgba(229, 57, 53, 0.25); color: #E53935; }
.legend-icon.event-conspiracy { background: rgba(156, 39, 176, 0.25); color: #9C27B0; }
.legend-icon.player-marker    { background: rgba(218, 165, 32, 0.25); color: var(--gold); font-size: 0.7rem; }
.legend-icon.road-marker      { background: none; color: var(--text-muted); font-family: var(--font-mono); font-size: 0.55rem; letter-spacing: -1px; }

.legend-hint {
    font-style: italic;
    color: var(--text-dim);
    font-size: 0.65rem;
}

/* ══════════════════════════════════════════════════════════════════
 * FULLSCREEN MAP OVERLAY
 * ═════════════════════════════════════════════════════════════════ */
.map-fullscreen-overlay {
    position: fixed;
    inset: 0;
    z-index: 600;
    background: rgba(10, 8, 5, 0.96);
    display: flex;
    flex-direction: column;
    animation: fadeIn 0.25s ease;
}

.map-fullscreen-close {
    position: absolute;
    top: 12px;
    right: 16px;
    z-index: 610;
    background: rgba(58, 48, 40, 0.9);
    border: 1px solid var(--gold-dim);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    color: var(--text-primary);
    font-size: 1.5rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    line-height: 1;
}

.map-fullscreen-close:hover {
    background: var(--gold-dim);
    color: var(--bg-deep);
}

.map-fullscreen-canvas {
    flex: 1;
    width: 100%;
    cursor: grab;
    touch-action: none;
}

.map-fullscreen-canvas:active {
    cursor: grabbing;
}

/* ── Fullscreen controls (top-left) ─────────────────────────── */
.map-fullscreen-controls {
    position: absolute;
    top: 12px;
    left: 12px;
    z-index: 610;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.map-ctrl-btn {
    width: 36px;
    height: 36px;
    background: rgba(58, 48, 40, 0.9);
    border: 1px solid rgba(218, 165, 32, 0.3);
    border-radius: var(--border-radius-sm);
    color: var(--text-secondary);
    font-size: 1.1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    line-height: 1;
}

.map-ctrl-btn:hover {
    background: rgba(218, 165, 32, 0.2);
    color: var(--gold);
    border-color: var(--gold-dim);
}

.map-ctrl-sep {
    height: 1px;
    background: rgba(218, 165, 32, 0.15);
    margin: 2px 4px;
}

/* ── Filter toggle buttons ───────────────────────────────────── */
.map-filter-bar {
    display: flex;
    flex-direction: column;
    gap: 3px;
    margin-top: 4px;
}

.map-filter-btn {
    width: 36px;
    height: 32px;
    background: rgba(58, 48, 40, 0.7);
    border: 1px solid rgba(200, 180, 140, 0.15);
    border-radius: var(--border-radius-sm);
    color: var(--text-muted);
    font-size: 0.85rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    line-height: 1;
}

.map-filter-btn.active {
    background: rgba(218, 165, 32, 0.15);
    color: var(--gold);
    border-color: rgba(218, 165, 32, 0.4);
}

.map-filter-btn:hover {
    background: rgba(218, 165, 32, 0.1);
    color: var(--text-secondary);
}

/* ── Fullscreen legend (bottom) ──────────────────────────────── */
.map-fullscreen-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 0.8em;
    padding: 0.5em 1em;
    background: rgba(26, 20, 16, 0.9);
    border-top: 1px solid rgba(218, 165, 32, 0.15);
    font-size: 0.78rem;
    color: var(--text-muted);
    justify-content: center;
    flex-shrink: 0;
}

/* ── Map tooltip ─────────────────────────────────────────────── */
.map-tooltip {
    position: fixed;
    z-index: 620;
    background: var(--bg-dark);
    border: 1px solid var(--gold-dim);
    border-radius: var(--border-radius);
    padding: 0.5em 0.8em;
    pointer-events: none;
    box-shadow: var(--shadow-hard);
    max-width: 240px;
    animation: fadeIn 0.15s ease;
}

.map-tooltip.hidden {
    display: none;
}

.map-tooltip-name {
    font-family: var(--font-heading);
    font-size: 0.95rem;
    color: var(--gold);
    margin-bottom: 0.15em;
}

.map-tooltip-type {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: capitalize;
}

.map-tooltip-pop {
    font-size: 0.72rem;
    color: var(--text-muted);
}

.map-tooltip-travel {
    font-size: 0.72rem;
    color: var(--teal);
    margin-top: 0.15em;
}

.map-tooltip-events {
    display: flex;
    gap: 0.4em;
    margin-top: 0.3em;
    font-size: 0.72rem;
}

.map-tooltip-event-badge {
    padding: 0.1em 0.35em;
    border-radius: 3px;
    font-weight: 600;
    font-size: 0.65rem;
    text-transform: uppercase;
}

.map-tooltip-event-badge.quest      { background: rgba(255, 179, 0, 0.2); color: #FFB300; }
.map-tooltip-event-badge.festival   { background: rgba(76, 175, 80, 0.2); color: #4CAF50; }
.map-tooltip-event-badge.war        { background: rgba(229, 57, 53, 0.2); color: #E53935; }
.map-tooltip-event-badge.conspiracy { background: rgba(156, 39, 176, 0.2); color: #9C27B0; }

/* ── Settlement popup (on fullscreen map) ───────────────────── */
.map-settlement-popup {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--bg-dark);
    border: 2px solid var(--gold);
    border-radius: 8px;
    padding: 20px 24px;
    min-width: 280px;
    max-width: 400px;
    z-index: 620;
    color: var(--text-primary);
    font-family: inherit;
    box-shadow: 0 4px 24px rgba(0,0,0,0.7);
    animation: fadeIn 0.15s ease;
}

.map-popup-header {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--gold);
    margin-bottom: 10px;
    border-bottom: 1px solid rgba(218, 165, 32, 0.3);
    padding-bottom: 8px;
}

.map-popup-row {
    font-size: 0.85rem;
    line-height: 1.5;
    color: var(--text-secondary);
}

.map-popup-label {
    color: var(--text-muted);
    display: inline-block;
    min-width: 80px;
}

.map-popup-divider {
    height: 1px;
    background: rgba(218, 165, 32, 0.15);
    margin: 10px 0;
}

.map-popup-travel {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.map-popup-section {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--gold);
    margin-top: 2px;
    margin-bottom: 2px;
}

.map-popup-presence {
    font-size: 0.8rem;
    color: var(--text-secondary);
    line-height: 1.4;
}

.map-popup-rival {
    font-size: 0.8rem;
    color: #c07040;
    padding-left: 4px;
    line-height: 1.4;
}

.map-popup-undiscovered {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-style: italic;
    margin-top: 4px;
}

.map-popup-events {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-top: 6px;
}

.map-popup-buttons {
    display: flex;
    gap: 10px;
    margin-top: 14px;
    justify-content: flex-end;
}

.map-popup-btn {
    padding: 8px 20px;
    border-radius: var(--border-radius);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid;
    transition: all 0.2s;
}

.map-popup-btn.travel {
    background: var(--gold-dim);
    border-color: var(--gold);
    color: var(--bg-deep);
}

.map-popup-btn.travel:hover {
    background: var(--gold);
}

.map-popup-btn.close {
    background: rgba(58, 48, 40, 0.8);
    border-color: var(--text-muted);
    color: var(--text-secondary);
}

.map-popup-btn.close:hover {
    background: rgba(100, 88, 72, 0.8);
    color: var(--text-primary);
}

@media (max-width: 600px) {
    .map-settlement-popup {
        min-width: auto;
        width: 90vw;
        max-width: 90vw;
        padding: 16px;
    }
}

/* Cargo list items */
.cargo-item {
    display: flex;
    justify-content: space-between;
    padding: 0.3em 0;
    border-bottom: 1px solid rgba(200, 180, 140, 0.08);
    font-size: 0.85rem;
}

.cargo-item .cargo-name {
    color: var(--text-primary);
    text-transform: capitalize;
}

.cargo-item .cargo-qty {
    color: var(--gold);
    font-family: var(--font-mono);
}

.cargo-summary {
    padding: 0.5em 0;
    font-size: 0.8rem;
    color: var(--text-muted);
    border-top: var(--border-subtle);
    margin-top: auto;
}

/* Companion cards */
.companion-card {
    background: var(--bg-parchment);
    border-radius: var(--border-radius-sm);
    padding: 0.6em;
    margin-bottom: 0.5em;
}

.companion-card .comp-name {
    font-family: var(--font-heading);
    font-size: 0.85rem;
    color: var(--gold);
}

.companion-card .comp-info {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.companion-card .comp-mood {
    display: flex;
    align-items: center;
    gap: 0.3em;
    margin-top: 0.3em;
    font-size: 0.75rem;
}


/* ACTION BAR (bottom) ────────────────────────────────────────────────────── */
#action-bar {
    height: var(--action-height);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 2em;
    padding: 0 1.5em;
    padding-bottom: env(safe-area-inset-bottom, 0);
    background: linear-gradient(0deg, var(--bg-warm) 0%, var(--bg-medium) 100%);
    border-top: var(--border-accent);
    flex-shrink: 0;
    z-index: 10;
}

.action-group {
    display: flex;
    gap: 0.3em;
}

.action-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.1em;
    padding: 0.3em 0.8em;
    background: none;
    border: var(--border-subtle);
    border-radius: var(--border-radius);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
    min-width: 64px;
}

.action-btn:hover {
    background: var(--bg-parchment);
    border-color: var(--gold-dim);
    color: var(--gold-light);
    transform: translateY(-2px);
    box-shadow: var(--shadow-soft);
}

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

.action-icon {
    font-size: 1.3em;
    line-height: 1;
}

.action-label {
    font-family: var(--font-heading);
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}


/* ══════════════════════════════════════════════════════════════════════════
 * ENDING SCREEN
 * ═════════════════════════════════════════════════════════════════════════ */
#ending-screen {
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    background: radial-gradient(ellipse at center, rgba(40, 30, 15, 0.8), var(--bg-deep));
}

.ending-overlay {
    position: absolute;
    inset: 0;
    background: radial-gradient(ellipse at center, transparent 40%, rgba(0, 0, 0, 0.6) 100%);
    pointer-events: none;
}

.ending-content {
    position: relative;
    z-index: 1;
    max-width: 600px;
    animation: fadeInUp 1s ease-out;
}

.ending-heading {
    font-family: var(--font-heading);
    font-size: 3rem;
    color: var(--gold);
    margin-bottom: 1em;
    text-shadow: var(--glow-gold);
    animation: pulse 3s ease-in-out infinite;
}

.ending-text {
    font-family: var(--font-prose);
    font-size: 1.1rem;
    color: var(--text-secondary);
    margin-bottom: 2em;
    line-height: 1.8;
}

.ending-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.8em;
    margin-bottom: 2em;
    text-align: left;
}

.ending-stat {
    background: rgba(255, 255, 255, 0.04);
    padding: 0.6em 1em;
    border-radius: var(--border-radius-sm);
    border-left: 3px solid var(--gold-dim);
}

.ending-stat .stat-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    font-family: var(--font-heading);
    letter-spacing: 0.06em;
}

.ending-stat .stat-value {
    font-size: 1.1rem;
    color: var(--gold);
    font-family: var(--font-mono);
}


/* ══════════════════════════════════════════════════════════════════════════
 * NOTIFICATIONS / TOASTS
 * ═════════════════════════════════════════════════════════════════════════ */
.toast-container {
    position: fixed;
    top: 60px;
    right: 16px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 0.5em;
    pointer-events: none;
}

.toast {
    background: var(--bg-warm);
    border: var(--border-accent);
    border-radius: var(--border-radius);
    padding: 0.6em 1em;
    color: var(--text-primary);
    font-size: 0.85rem;
    box-shadow: var(--shadow-hard);
    pointer-events: auto;
    animation: slideInRight 0.3s ease, fadeOut 0.3s ease 3.7s forwards;
    max-width: 360px;
}

.toast.toast-warning {
    border-color: var(--orange);
    color: var(--orange);
}

.toast.toast-danger {
    border-color: var(--red);
    color: var(--red);
}

.toast.toast-success {
    border-color: var(--green);
    color: var(--green);
}


/* ══════════════════════════════════════════════════════════════════════════
 * MODAL
 * ═════════════════════════════════════════════════════════════════════════ */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
    z-index: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
}

.modal-overlay.hidden {
    display: none;
}

.modal-content {
    background: var(--bg-medium);
    border: var(--border-accent);
    border-radius: var(--border-radius);
    padding: 2em;
    max-width: 600px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: var(--shadow-hard);
    position: relative;
    animation: fadeInUp 0.3s ease;
}

.modal-close {
    position: absolute;
    top: 0.5em;
    right: 0.7em;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    cursor: pointer;
    transition: color 0.2s;
}

.modal-close:hover {
    color: var(--text-primary);
}


/* ══════════════════════════════════════════════════════════════════════════
 * UTILITY CLASSES
 * ═════════════════════════════════════════════════════════════════════════ */
.hidden { display: none !important; }

.text-gold { color: var(--gold); }
.text-red { color: var(--red); }
.text-green { color: var(--green); }
.text-blue { color: var(--blue); }
.text-violet { color: var(--violet); }
.text-teal { color: var(--teal); }
.text-pink { color: var(--pink); }
.text-orange { color: var(--orange); }
.text-muted { color: var(--text-muted); }

.font-heading { font-family: var(--font-heading); }
.font-prose { font-family: var(--font-prose); }
.font-mono { font-family: var(--font-mono); }


/* ══════════════════════════════════════════════════════════════════════════
 * KEYFRAME ANIMATIONS
 * ═════════════════════════════════════════════════════════════════════════ */
@keyframes fadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

@keyframes fadeOut {
    from { opacity: 1; }
    to   { opacity: 0; }
}

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

@keyframes slideInRight {
    from { opacity: 0; transform: translateX(40px); }
    to   { opacity: 1; transform: translateX(0); }
}

@keyframes pulse {
    0%, 100% { text-shadow: 0 0 20px rgba(218, 165, 32, 0.3); }
    50%      { text-shadow: 0 0 40px rgba(218, 165, 32, 0.6); }
}

@keyframes shimmer {
    0%   { background-position: -200% center; }
    100% { background-position: 200% center; }
}


/* ══════════════════════════════════════════════════════════════════════════
 * MOBILE DRAWER TOGGLE BUTTONS
 * ═════════════════════════════════════════════════════════════════════════ */
.mobile-toggles {
    position: fixed;
    right: 8px;
    top: calc(var(--hud-height) + 8px);
    z-index: 50;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.mobile-toggle-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--bg-warm);
    border: 1px solid var(--gold-dim);
    color: var(--text-primary);
    font-size: 1.1rem;
    cursor: pointer;
    box-shadow: var(--shadow-soft);
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.mobile-toggle-btn:hover,
.mobile-toggle-btn.active {
    background: var(--gold-dim);
    color: var(--bg-deep);
}


/* ══════════════════════════════════════════════════════════════════════════
 * RESPONSIVE — Collapse side panels on narrow screens
 * ═════════════════════════════════════════════════════════════════════════ */

/* ── Tablets & small laptops (≤1200px) ────────────────────────────────── */
@media (max-width: 1200px) {
    :root {
        --portrait-width: 180px;
        --info-width: 300px;
    }
}

/* Drawer close buttons: hidden by default, shown on mobile */
.drawer-close-btn { display: none; }

/* ── Tablets (≤900px) — Mobile layout with drawers ───────────────────── */
@media (max-width: 900px) {
    .mobile-toggles {
        display: flex !important;
    }

    #main-content {
        grid-template-columns: 1fr;
        grid-template-rows: 1fr; /* single row, narrative-area fills */
        position: relative;
        overflow: hidden; /* prevent horizontal overflow on mobile */
        max-width: 100vw;
    }

    /* ── Portrait drawer (slides from left) ── */
    #portrait-area {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: 260px;
        z-index: 40;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        border-right: var(--border-accent);
        box-shadow: 4px 0 16px rgba(0, 0, 0, 0.5);
    }

    #portrait-area.drawer-open {
        transform: translateX(0);
    }

    /* ── Info panel drawer (slides from right) ── */
    #info-panel {
        position: fixed;
        top: 0;
        right: 0;
        bottom: 0;
        width: 320px;
        max-width: 85vw;
        z-index: 40;
        transform: translateX(100%);
        transition: transform 0.3s ease;
        border-left: var(--border-accent);
        box-shadow: -4px 0 16px rgba(0, 0, 0, 0.5);
    }

    #info-panel.drawer-open {
        transform: translateX(0);
    }

    /* ── Backdrop overlay when drawer is open ── */
    .drawer-backdrop {
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 35;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.3s ease;
    }

    .drawer-backdrop.active {
        opacity: 1;
        pointer-events: auto;
    }

    /* Hide mobile toggles when a drawer is open (avoid overlap) */
    .drawer-backdrop.active ~ #mobile-toggles,
    .mobile-toggles.drawer-active {
        display: none !important;
    }

    /* Drawer close button (visible only on mobile) */
    .drawer-close-btn {
        display: block;
        position: absolute;
        top: 6px;
        right: 8px;
        z-index: 45;
        background: rgba(58, 42, 26, 0.6);
        color: var(--parchment);
        border: 1px solid var(--gold-dim);
        border-radius: 50%;
        width: 32px;
        height: 32px;
        font-size: 1.2rem;
        line-height: 1;
        cursor: pointer;
        padding: 0;
    }

    #portrait-area .drawer-close-btn {
        right: auto;
        left: 8px;
    }

    /* ── Action bar: compact single row ── */
    .action-label {
        display: none;
    }

    .action-btn {
        min-width: 42px;
        padding: 0.3em 0.5em;
    }

    #action-bar {
        height: auto;
        gap: 0.4em;
        padding: 0.3em 0.5em;
        flex-wrap: nowrap;
        justify-content: space-evenly;
    }

    .action-group {
        gap: 0.15em;
    }

    .action-icon {
        font-size: 1.2em;
    }

    /* ── HUD: single line, compact ── */
    #hud-bar {
        flex-wrap: nowrap;
        height: var(--hud-height);
        padding: 0 0.6em;
        gap: 0.4em;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
    }

    .hud-calendar .hud-value {
        font-size: 0.8rem;
    }

    .hud-calendar .hud-badge {
        display: none;
    }

    /* ── Narrative: ensure input area always visible ── */
    #narrative-area {
        min-height: 0;
        display: flex;
        flex-direction: column;
        overflow: hidden; /* contain all children within viewport width */
        max-width: 100vw;
    }

    #narrative-panel {
        flex: 1;
        min-height: 0;
        overflow-y: auto; /* scroll narrative, don't clip siblings */
        overflow-x: hidden;
    }

    #narrative-log {
        padding: 0.8em 1em;
        overflow-wrap: break-word;
        word-break: break-word;
    }

    /* ── Input area: always visible, never squeezed ── */
    #input-area {
        flex-shrink: 0;
        padding: 0.6em 0.8em;
        max-height: 40vh;
        overflow-y: auto;
        overflow-x: hidden; /* prevent suggestions from pushing layout */
        /* Must be ABOVE action bar (z-index 10) so inputs aren't hidden */
        z-index: 15;
        position: relative;
        /* Always reserve space so it's never 0-height */
        min-height: 60px;
        /* Visual separation from narrative */
        border-top: 1px solid rgba(139, 119, 82, 0.3);
        background: var(--bg-warm);
    }

    /* ── Menu options: stack vertically on mobile for visibility ── */
    .menu-options,
    .menu-container {
        flex-direction: column;
    }

    .menu-option {
        width: 100%;
        justify-content: flex-start;
        padding: 0.6em 1em;
        font-size: 1rem;
    }

    /* ── Menu buttons (from components.js): full-width tap targets ── */
    .menu-btn,
    .btn-menu {
        width: 100%;
        justify-content: flex-start;
        padding: 0.6em 1em;
        font-size: 1rem;
    }

    /* ── Text input: prevent iOS zoom ── */
    .text-input {
        font-size: 1rem;
    }
}

/* ── Phones (≤600px) — Tighter layout ────────────────────────────────── */
@media (max-width: 600px) {
    /* ── Title screen: scale down ── */
    .title-heading {
        font-size: 2.4rem;
    }

    .title-subtitle {
        font-size: 1.1rem;
    }

    .title-motto {
        font-size: 0.9rem;
        margin-bottom: 2em;
    }

    .title-btn {
        min-width: 200px;
        width: 80vw;
        max-width: 280px;
        font-size: 0.95rem;
    }

    .title-version {
        margin-top: 2em;
    }

    /* ── HUD: compact, scrollable ── */
    #hud-bar {
        font-size: 0.75rem;
        gap: 0.3em;
        padding: 0 0.5em;
        height: 40px;
    }

    :root {
        --hud-height: 40px;
    }

    .hud-controls {
        gap: 0.15em;
    }

    .hud-btn {
        width: 26px;
        height: 26px;
        font-size: 0.8em;
    }

    .hud-economy .hud-value {
        min-width: 40px;
    }

    /* Hide less critical HUD items on small phones */
    .hud-spirit {
        display: none;
    }

    .hud-calendar .hud-badge {
        display: none;
    }

    /* ── Action bar: single row, scrollable ── */
    #action-bar {
        flex-wrap: nowrap;
        padding: 0.3em 0.4em;
        gap: 0.2em;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        justify-content: flex-start;
    }

    .action-group {
        gap: 0.1em;
        flex-shrink: 0;
    }

    .action-btn {
        min-width: 38px;
        padding: 0.3em 0.4em;
        flex-shrink: 0;
    }

    .action-icon {
        font-size: 1.1em;
    }

    /* ── Portrait drawer narrower ── */
    #portrait-area {
        width: 220px;
    }

    #portrait-frame {
        width: 150px;
        height: 150px;
    }

    /* ── Info drawer full width ── */
    #info-panel {
        width: 100vw;
        max-width: 100vw;
    }

    /* ── Fullscreen map: compact controls ── */
    .map-fullscreen-close {
        top: 8px;
        right: 8px;
        width: 36px;
        height: 36px;
        font-size: 1.3rem;
    }

    .map-ctrl-btn {
        width: 32px;
        height: 32px;
        font-size: 1rem;
    }

    .map-filter-btn {
        width: 32px;
        height: 28px;
        font-size: 0.75rem;
    }

    .map-fullscreen-legend {
        font-size: 0.7rem;
        gap: 0.5em;
        padding: 0.4em 0.6em;
    }

    /* ── Mobile toggle buttons: smaller ── */
    .mobile-toggle-btn {
        width: 34px;
        height: 34px;
        font-size: 0.95rem;
    }

    .mobile-toggles {
        right: 4px;
        top: calc(var(--hud-height) + 4px);
    }

    /* ── Narrative text smaller ── */
    #narrative-log {
        font-size: 0.9rem;
        padding: 0.5em 0.6em;
    }

    /* ── Input area: full-width, large tap targets ── */
    #input-area {
        padding: 0.5em 0.6em;
    }

    .text-input {
        font-size: 1rem; /* Prevent iOS zoom on focus */
    }

    .menu-option,
    .menu-btn,
    .btn-menu {
        padding: 0.7em 1em;
        font-size: 1rem;
    }

    /* ── Dialogue suggestions: constrained to viewport on phones ── */
    .dialogue-suggestions {
        max-width: calc(100vw - 1.2em); /* account for input-area padding */
    }

    .text-input-container {
        max-width: 100%;
        overflow: hidden;
    }

    /* ── Toasts ── */
    .toast-container {
        right: 8px;
        left: 8px;
    }

    .toast {
        max-width: none;
    }

    /* ── Ending screen ── */
    .ending-heading {
        font-size: 2rem;
    }

    .ending-stats {
        grid-template-columns: 1fr;
    }
}

/* ── Very small phones (≤375px) — Ultra compact ──────────────────────── */
@media (max-width: 375px) {
    .title-heading {
        font-size: 1.8rem;
    }

    .title-subtitle {
        font-size: 0.9rem;
    }

    .title-motto {
        margin-bottom: 1.5em;
    }

    .title-btn {
        min-width: 160px;
        width: 85vw;
        max-width: 260px;
        font-size: 0.85rem;
        padding: 0.5em 1em;
    }

    .title-version {
        margin-top: 1.5em;
    }

    /* ── HUD: 2-row layout for Flip 7 folded ── */
    #hud-bar {
        font-size: 0.7rem;
        height: auto;
        min-height: 36px;
        gap: 0.2em 0.5em;
        padding: 0.2em 0.4em;
        flex-wrap: wrap;
    }

    :root {
        --hud-height: 56px;
    }

    .hud-section {
        gap: 0.15em;
    }

    .hud-btn {
        width: 22px;
        height: 22px;
        font-size: 0.7em;
    }

    .hud-economy .hud-value {
        min-width: 28px;
    }

    /* Hide pool/spirit/unit but SHOW morale+health */
    .hud-unit,
    .hud-pool-sep,
    .hud-pool-icon,
    #hud-pool,
    .hud-spirit {
        display: none;
    }

    /* Compact date: hide season badge */
    .hud-badge {
        display: none;
    }

    /* Controls shrink to end of row */
    .hud-controls {
        margin-left: auto;
        gap: 0.2em;
    }

    /* ── Action bar: tight ── */
    .action-btn {
        min-width: 34px;
        padding: 0.25em 0.35em;
    }

    .action-icon {
        font-size: 1em;
    }

    /* ── Narrative: even tighter ── */
    #narrative-log {
        padding: 0.4em 0.5em;
        font-size: 0.85rem;
        line-height: 1.5;
    }

    /* ── Input area: compact but visible ── */
    #input-area {
        padding: 0.4em 0.5em;
    }

    /* ── Menu: compact single-column, tight spacing ── */
    .menu-options,
    .menu-container {
        gap: 0.2em;
    }

    .menu-option,
    .menu-btn,
    .btn-menu {
        padding: 0.35em 0.6em;
        font-size: 0.8rem;
    }

    .input-prompt {
        font-size: 0.85rem;
        margin-bottom: 0.3em;
    }

    /* ── Chat bubbles compact ── */
    .chat-avatar {
        width: 28px;
        height: 28px;
    }

    .chat-bubble {
        padding: 0.3em 0.5em;
        gap: 0.3em;
    }

    .chat-speaker {
        font-size: 0.65rem;
    }

    .chat-text {
        font-size: 0.8rem;
    }

    /* ── Mobile toggles: smallest ── */
    .mobile-toggle-btn {
        width: 30px;
        height: 30px;
        font-size: 0.85rem;
    }
}
