/* OpenDungeon Stylesheet */

/* Custom Font Definitions & Root CSS Variables */
:root {
    --bg-dark: #07090d;
    --bg-panel: rgba(13, 20, 30, 0.45);
    --border-light: rgba(56, 189, 248, 0.2);
    --border-glow: rgba(56, 189, 248, 0.6);
    --text-neon: #38bdf8;
    --text-log: #4ade80;
    --text-log-dim: rgba(74, 222, 128, 0.75);
    --text-user: #e0f2fe;
    --text-muted: rgba(224, 242, 254, 0.45);
    
    --panel-blur: blur(10px);
    --transition-fast: 0.15s ease-out;
    --transition-smooth: 0.3s cubic-bezier(0.4, 0, 0.2, 1);

    /* Mobile viewport geometry tokens (mobile-viewport-safari-fidelity).
       --safe-* indirections let tests inject literal insets (headless
       Chromium reports env(safe-area-inset-*) as 0px).
       --tab-h is the interactive tab touch target (44px).
       --tab-bar-h is the canonical total height: 44px tab + 1px top border. */
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
    --tab-h: 44px;
    --tab-bar-h: calc(var(--tab-h) + 1px);
}

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

body {
    background-color: var(--bg-dark);
    color: var(--text-user);
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    height: 100vh;
    height: 100dvh;
    width: 100%;
    overflow: hidden;
    position: relative;
}

/* CRT Screen Effects & Overlay Filter */
.crt-effect {
    position: relative;
    overflow: hidden;
}

.scanlines {
    pointer-events: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    z-index: 9999;
    background: linear-gradient(
        rgba(18, 16, 16, 0) 50%,
        rgba(0, 0, 0, 0.25) 50%
    );
    background-size: 100% 4px;
    opacity: 0.85;
}

.screen-flicker {
    pointer-events: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 9998;
    background: rgba(18, 16, 16, 0.01);
    opacity: 0.15;
    animation: flicker 0.15s infinite;
}

@keyframes flicker {
    0% { opacity: 0.15; }
    50% { opacity: 0.18; }
    100% { opacity: 0.15; }
}

/* Helper code/monospace font style */
.code-font {
    font-family: 'JetBrains Mono', 'Courier New', Courier, monospace;
}

/* App Main Container Grid */
.app-container {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 1.5rem;
    padding-left: max(1.5rem, var(--safe-left));
    padding-right: max(1.5rem, var(--safe-right));
    position: relative;
    z-index: 10;
}

/* UI Panel styles with Glassmorphism */
.glass-panel {
    background: var(--bg-panel);
    border: 1px solid var(--border-light);
    border-radius: 8px;
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
    backdrop-filter: var(--panel-blur);
    -webkit-backdrop-filter: var(--panel-blur);
    padding: 2rem;
    transition: border-color var(--transition-smooth), box-shadow var(--transition-smooth);
}

.glass-panel:hover {
    border-color: var(--border-glow);
    box-shadow: 0 8px 32px 0 rgba(56, 189, 248, 0.15);
}

.hidden {
    display: none !important;
}

/* Screen visibility controller */
#startup-screen {
    max-width: 480px;
    width: 100%;
    text-align: center;
}

.startup-header h1 {
    font-family: 'VT323', monospace;
    font-size: 3rem;
    color: var(--text-neon);
    text-shadow: 0 0 10px rgba(56, 189, 248, 0.6);
    margin-bottom: 0.5rem;
    letter-spacing: 2px;
}

.startup-header .subtitle {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 2rem;
}

/* LLM Status Pill */
.llm-pill {
    display: inline-block;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.72rem;
    padding: 0.15rem 0.55rem;
    border-radius: 3px;
    border: 1px solid currentColor;
    letter-spacing: 0.05em;
    vertical-align: middle;
    transition: color 0.3s, border-color 0.3s;
}

.llm-pill-checking { color: var(--text-muted); animation: pill-blink 1.1s infinite; }
.llm-pill-online   { color: #4ade80; }
.llm-pill-mock     { color: #facc15; }
.llm-pill-offline  { color: #ef4444; }

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

/* Keyboard hint bar shown under wizard screens */
.kbd-hint {
    text-align: center;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-top: 0.65rem;
    letter-spacing: 0.03em;
    opacity: 0.7;
}


.menu-choices {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

/* Styled Button Design */
.btn {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.9rem;
    padding: 0.8rem 1rem;
    border-radius: 4px;
    border: 1px solid var(--border-light);
    background: rgba(13, 20, 30, 0.6);
    color: var(--text-user);
    cursor: pointer;
    position: relative;
    overflow: hidden;
    white-space: nowrap;
    transition: all var(--transition-fast);
}

.btn:hover {
    background: rgba(56, 189, 248, 0.1);
    border-color: var(--border-glow);
    text-shadow: 0 0 5px var(--text-neon);
}

.btn:focus {
    outline: none;
}

.btn.menu-focus {
    background: rgba(56, 189, 248, 0.15);
    border-color: var(--text-neon);
    box-shadow: 0 0 10px rgba(56, 189, 248, 0.3);
    text-shadow: 0 0 5px var(--text-neon);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background: rgba(13, 20, 30, 0.4) !important;
    border-color: var(--border-light) !important;
    pointer-events: none;
    box-shadow: none !important;
    text-shadow: none !important;
}

.btn-primary {
    border-color: var(--text-neon);
    background: rgba(56, 189, 248, 0.15);
    box-shadow: 0 0 10px rgba(56, 189, 248, 0.2);
}

.btn-primary:hover {
    background: rgba(56, 189, 248, 0.3);
    box-shadow: 0 0 15px rgba(56, 189, 248, 0.45);
}

.btn-back {
    color: var(--text-muted);
}

.btn-block {
    width: 100%;
}

.btn-sm {
    padding: 0.4rem 0.8rem;
    font-size: 0.8rem;
}

/* Forms layout styling */
.form-container {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    text-align: left;
}

.form-group label {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.8rem;
    color: var(--text-neon);
}

.form-group input, .form-group textarea, .form-group select {
    background: rgba(7, 9, 13, 0.7);
    border: 1px solid var(--border-light);
    border-radius: 4px;
    color: var(--text-user);
    padding: 0.75rem;
    font-family: inherit;
    font-size: 0.95rem;
    width: 100%;
    outline: none;
    transition: all var(--transition-fast);
}

.form-group input:focus, .form-group textarea:focus, .form-group select:focus {
    border-color: var(--border-glow);
    box-shadow: 0 0 8px rgba(56, 189, 248, 0.3);
}

/* Progress Indicator for Setup Wizard */
.progress-indicator {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    margin-bottom: 1.25rem;
    padding: 0.6rem 1rem;
    background: rgba(7, 9, 13, 0.5);
    border: 1px solid var(--border-light);
    border-radius: 4px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.72rem;
}

.progress-step {
    color: var(--text-muted);
    padding: 0.15rem 0.4rem;
    border-radius: 2px;
    transition: all var(--transition-fast);
}

.progress-step.active {
    color: var(--text-neon);
    background: rgba(56, 189, 248, 0.12);
    text-shadow: 0 0 4px rgba(56, 189, 248, 0.4);
}

.progress-step.completed {
    color: var(--text-log);
}

.progress-arrow {
    color: var(--text-muted);
    opacity: 0.4;
    font-size: 0.8rem;
}

/* Preset Manager Screen */
#preset-manager-screen, #preset-editor-screen {
    max-width: 800px;
    width: 100%;
}

.manager-toolbar {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 1rem;
}

/* Editor Scrollable Container */
.editor-scroll-container {
    max-height: 55vh;
    overflow-y: auto;
    padding-right: 0.5rem;
}

/* Character sub-form in editor */
.editor-character-form {
    background: rgba(7, 9, 13, 0.35);
    border: 1px solid var(--border-light);
    border-radius: 4px;
    padding: 0.75rem;
    margin-bottom: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.editor-character-form .char-form-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.editor-character-form .char-form-header h5 {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.8rem;
    color: var(--text-neon);
}

.editor-character-form .char-form-row {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.editor-character-form .char-form-row .form-group {
    flex: 1;
    min-width: 120px;
}

.editor-character-form .char-form-row .form-group label {
    font-size: 0.7rem;
}

.editor-character-form .char-form-row .form-group input,
.editor-character-form .char-form-row .form-group textarea {
    font-size: 0.82rem;
    padding: 0.4rem 0.6rem;
}

.btn-remove-character {
    background: transparent;
    border: 1px solid #ef4444;
    color: #ef4444;
    font-size: 0.7rem;
    padding: 0.2rem 0.5rem;
    border-radius: 3px;
    cursor: pointer;
    font-family: 'JetBrains Mono', monospace;
    transition: all var(--transition-fast);
}

.btn-remove-character:hover {
    background: rgba(239, 68, 68, 0.15);
}

/* Preset card action buttons for manager */
.preset-card-actions {
    display: flex;
    gap: 0.4rem;
    margin-top: 0.75rem;
}

.btn-edit-preset, .btn-delete-preset, .btn-icon-action {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.72rem;
    padding: 0.25rem 0.6rem;
    border-radius: 3px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    transition: all var(--transition-fast);
}

.btn-edit-preset {
    background: rgba(56, 189, 248, 0.08);
    border: 1px solid var(--border-light);
    color: var(--text-neon);
}

.btn-edit-preset:hover {
    background: rgba(56, 189, 248, 0.2);
    border-color: var(--border-glow);
    box-shadow: 0 0 6px rgba(56, 189, 248, 0.3);
}

.btn-delete-preset {
    background: rgba(239, 68, 68, 0.08);
    border: 1px solid rgba(239, 68, 68, 0.4);
    color: #ef4444;
}

.btn-delete-preset:hover {
    background: rgba(239, 68, 68, 0.2);
    border-color: #ef4444;
    box-shadow: 0 0 6px rgba(239, 68, 68, 0.3);
}

.btn-delete-preset:hover {
    background: rgba(239, 68, 68, 0.15);
}

/* Preset Screen & Grid Cards */
#preset-screen, #custom-preset-screen, #character-screen {
    max-width: 800px;
    width: 100%;
}

.panel-header {
    margin-bottom: 1.5rem;
    text-align: left;
    border-bottom: 1px solid var(--border-light);
    padding-bottom: 1rem;
}

.panel-header h2 {
    font-family: 'VT323', monospace;
    font-size: 2.2rem;
    color: var(--text-neon);
}

.panel-header p {
    font-size: 0.9rem;
    color: var(--text-muted);
}

.preset-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1.25rem;
    margin-bottom: 2rem;
}

.preset-card {
    background: rgba(7, 9, 13, 0.4);
    border: 1px solid var(--border-light);
    border-radius: 6px;
    padding: 1.25rem;
    cursor: pointer;
    text-align: left;
    transition: all var(--transition-fast);
}

.preset-card:hover {
    border-color: var(--border-glow);
    background: rgba(56, 189, 248, 0.05);
    transform: translateY(-2px);
}

.preset-card.active {
    border-color: var(--text-neon);
    box-shadow: 0 0 10px rgba(56, 189, 248, 0.25);
    background: rgba(56, 189, 248, 0.08);
}

.preset-card h3 {
    font-family: 'JetBrains Mono', monospace;
    font-size: 1rem;
    color: var(--text-neon);
    margin-bottom: 0.5rem;
}

.preset-card p {
    font-size: 0.8rem;
    color: var(--text-muted);
    line-height: 1.4;
}

.panel-footer-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
    border-top: 1px solid var(--border-light);
    padding-top: 1.25rem;
    margin-top: 1.5rem;
}

.footer-actions-left {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.footer-actions-right {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.secondary-actions-group {
    display: flex;
    align-items: center;
    gap: 1rem;
}

/* Character Selection Layout */
.character-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1.25rem;
    margin-bottom: 1.5rem;
}

.char-card {
    background: rgba(7, 9, 13, 0.4);
    border: 1px solid var(--border-light);
    border-radius: 6px;
    padding: 1.25rem;
    cursor: pointer;
    text-align: left;
    transition: all var(--transition-fast);
}

.char-card:hover {
    border-color: var(--border-glow);
    background: rgba(56, 189, 248, 0.05);
    transform: translateY(-2px);
}

.char-card.active {
    border-color: var(--text-neon);
    box-shadow: 0 0 10px rgba(56, 189, 248, 0.25);
    background: rgba(56, 189, 248, 0.08);
}

.char-card h4 {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.95rem;
    color: var(--text-user);
    margin-bottom: 0.25rem;
}

.char-card .char-type {
    font-size: 0.75rem;
    color: var(--text-neon);
    margin-bottom: 0.5rem;
    font-family: 'JetBrains Mono', monospace;
}

.char-card p {
    font-size: 0.8rem;
    color: var(--text-muted);
    line-height: 1.4;
}

/* Saved games lists */
.saves-container {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    max-height: 400px;
    overflow-y: auto;
    padding-right: 0.5rem;
    margin-bottom: 1.5rem;
}

.save-item {
    background: rgba(7, 9, 13, 0.4);
    border: 1px solid var(--border-light);
    border-radius: 6px;
    padding: 1.25rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    text-align: left;
    transition: all var(--transition-fast);
}

.save-item:hover {
    border-color: var(--border-glow);
    background: rgba(56, 189, 248, 0.03);
}

.save-details h4 {
    font-family: 'JetBrains Mono', monospace;
    font-size: 1rem;
    color: var(--text-neon);
    margin-bottom: 0.25rem;
}

.save-details p {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 0.25rem;
}

.save-meta {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.75rem;
    color: var(--text-log-dim);
}

.save-actions {
    display: flex;
    gap: 0.5rem;
}

/* CORE GAMEPLAY MAIN UI */
.game-dashboard {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

/* Top Status bar */
.status-bar {
    display: flex;
    background: rgba(13, 20, 30, 0.8);
    border: 1px solid var(--text-neon);
    border-radius: 4px;
    padding: 0.5rem 1rem;
    font-family: 'VT323', monospace;
    font-size: 1.3rem;
    color: var(--text-neon);
    text-shadow: 0 0 5px rgba(56, 189, 248, 0.4);
    justify-content: space-between;
}

.status-item .label {
    color: var(--text-muted);
    margin-right: 0.25rem;
}

.status-item.quota #val-quota.quota-exhausted {
    color: #ef4444;
    text-shadow: 0 0 5px rgba(239, 68, 68, 0.5);
}

.auth-banner {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    margin-top: 0.75rem;
    min-height: 2rem;
}

.auth-banner .auth-user {
    color: var(--text-muted);
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.85rem;
}

.auth-banner .auth-signin,
.auth-banner .auth-signout {
    font-size: 0.85rem;
}

.dashboard-body {
    display: grid;
    grid-template-columns: 1fr 340px;
    gap: 1rem;
    flex: 1;
    min-height: 0; /* Important for scroll sizing */
}

/* Main Console Area */
.console-panel {
    display: flex;
    flex-direction: column;
    min-height: 0;
    padding: 1.25rem;
}

.console-log {
    flex: 1;
    overflow-y: auto;
    padding-right: 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.85rem;
    line-height: 1.6;
    margin-bottom: 1rem;
}

/* Game turns logs formatting */
.log-turn {
    animation: fade-in 0.2s ease-out;
}

.log-turn-user {
    color: var(--text-user);
    font-weight: 700;
}

.log-turn-assistant {
    color: var(--text-log);
    line-height: 1.75;
    white-space: pre-wrap;
    text-shadow: 0 0 4px rgba(74, 222, 128, 0.3);
}

.log-turn-system {
    color: var(--text-neon);
    background: rgba(56, 189, 248, 0.05);
    padding: 0.4rem 0.75rem;
    border-radius: 4px;
    border-left: 3px solid var(--text-neon);
}

.log-turn-error {
    color: #ef4444;
    background: rgba(239, 68, 68, 0.05);
    padding: 0.4rem 0.75rem;
    border-radius: 4px;
    border-left: 3px solid #ef4444;
}

@keyframes fade-in {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Suggestion Chips */
.suggestions-box {
    margin-bottom: 0.75rem;
    text-align: left;
    background: rgba(56, 189, 248, 0.02);
    border: 1px solid var(--border-light);
    padding: 0.5rem 0.75rem;
    border-radius: 6px;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.suggestions-label {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.7rem;
    color: var(--text-muted);
    white-space: nowrap;
}

.suggestions-list {
    display: flex;
    gap: 0.5rem;
    overflow-x: auto;
    flex: 1;
}

.suggestion-chip {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.72rem;
    padding: 0.25rem 0.65rem;
    background: rgba(13, 20, 30, 0.8);
    border: 1px solid var(--border-light);
    color: var(--text-log-dim);
    border-radius: 12px;
    cursor: pointer;
    white-space: nowrap;
    transition: all var(--transition-fast);
}

.suggestion-chip:hover {
    border-color: var(--border-glow);
    background: rgba(74, 222, 128, 0.08);
    color: var(--text-log);
}

.revealed-text {
    position: relative;
    z-index: 2;
}

/* Streaming reveal placeholder — hidden chars shown as green highlight blocks */
.hidden-placeholder {
    position: relative;
    z-index: 1;
    background-color: rgba(74, 222, 128, 0.22);
    color: transparent !important;
    text-shadow: none !important;
    border-radius: 2px;
}

/* Streaming state display */
.streaming-box {
    text-align: left;
    font-family: 'JetBrains Mono', monospace;
    color: var(--text-log);
    padding: 0.5rem 0;
    margin-bottom: 0.5rem;
    line-height: 1.6;
}

.blinking-cursor {
    animation: blink 0.9s infinite;
}

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

/* Command console row */
.console-input-row {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    border-top: 1px solid var(--border-light);
    padding-top: 0.5rem;
    margin-bottom: 0.5rem;
}

.prompt-marker {
    font-family: 'JetBrains Mono', monospace;
    font-size: 1rem;
    color: var(--text-neon);
    font-weight: 700;
}

#console-input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-user);
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.82rem;
    padding: 0.4rem 0;
}

.console-utilities {
    display: flex;
    gap: 0.5rem;
    justify-content: flex-start;
}

.btn-utility {
    font-size: 0.72rem;
    padding: 0.25rem 0.6rem;
    background: transparent;
    border-color: transparent;
    color: var(--text-muted);
    transition: color var(--transition-fast), text-shadow var(--transition-fast);
}

.btn-utility:hover {
    color: var(--text-neon);
    background: rgba(56, 189, 248, 0.05);
}

.btn-utility.active {
    color: var(--text-neon);
    text-shadow: 0 0 5px var(--text-neon);
}

.btn-utility:disabled {
    background: transparent !important;
    border-color: transparent !important;
    opacity: 0.4 !important;
    text-shadow: none !important;
    cursor: not-allowed;
}

/* Sidebar detail panel layout */
.sidebar-panel {
    display: flex;
    flex-direction: column;
    padding: 1rem;
    min-height: 0;
}

.tab-header {
    display: flex;
    border-bottom: 1px solid var(--border-light);
    margin-bottom: 1rem;
}

.tab-btn {
    flex: 1;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    padding: 0.75rem 0.5rem;
    font-family: 'VT323', monospace;
    font-size: 1.3rem;
    color: var(--text-muted);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.tab-btn:hover {
    color: var(--text-neon);
}

.tab-btn.active {
    color: var(--text-neon);
    border-bottom-color: var(--text-neon);
    text-shadow: 0 0 5px rgba(56, 189, 248, 0.3);
}

.tab-body {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
}

.tab-content {
    display: none;
    height: 100%;
}

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

/* Lore Cards styling */
.lore-actions {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 0.75rem;
}

.lore-cards-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    overflow-y: auto;
    flex: 1;
    padding-right: 0.25rem;
}

.lore-card {
    background: rgba(7, 9, 13, 0.6);
    border: 1px solid var(--border-light);
    border-radius: 4px;
    padding: 0.85rem;
    text-align: left;
    transition: all var(--transition-fast);
}

.lore-card:hover {
    border-color: var(--border-glow);
}

.lore-card.inactive {
    opacity: 0.4;
}

.lore-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.25rem;
}

.lore-card-header h5 {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.85rem;
    color: var(--text-neon);
}

.lore-card-badge {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.65rem;
    padding: 0.15rem 0.4rem;
    border-radius: 3px;
    text-transform: uppercase;
}

.lore-card-badge.character { background: rgba(56, 189, 248, 0.15); color: var(--text-neon); }
.lore-card-badge.location { background: rgba(168, 85, 247, 0.15); color: #a855f7; }
.lore-card-badge.item { background: rgba(234, 179, 8, 0.15); color: #eab308; }
.lore-card-badge.lore { background: rgba(244, 63, 94, 0.15); color: #f43f5e; }

.lore-card p {
    font-size: 0.8rem;
    color: var(--text-user);
    line-height: 1.4;
    margin-bottom: 0.5rem;
}

.lore-card-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.lore-card-triggers {
    font-family: 'JetBrains Mono', monospace;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 150px;
}

.lore-card-buttons {
    display: flex;
    gap: 0.4rem;
}

.lore-card-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-family: inherit;
    font-size: 0.75rem;
}

.lore-card-btn:hover {
    color: var(--text-neon);
}

.summary-container {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    height: 100%;
}

.help-text {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.summary-editor {
    flex: 1;
    background: rgba(7, 9, 13, 0.6);
    border: 1px solid var(--border-light);
    border-radius: 4px;
    color: var(--text-user);
    padding: 0.75rem;
    font-size: 0.85rem;
    line-height: 1.5;
    outline: none;
    resize: none;
}

.summary-editor:focus {
    border-color: var(--border-glow);
}

/* Modal styling configurations */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(7, 9, 13, 0.7);
    z-index: 1000;
    display: flex;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(4px);
    animation: fade-in 0.15s ease-out;
}

.modal-content {
    max-width: 600px;
    width: 100%;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    padding: 1.5rem;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-light);
    padding-bottom: 0.75rem;
    margin-bottom: 1rem;
}

.modal-header h3 {
    font-family: 'VT323', monospace;
    font-size: 1.5rem;
    color: var(--text-neon);
}

.btn-close {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    cursor: pointer;
    line-height: 1;
}

.btn-close:hover {
    color: var(--text-neon);
}

.modal-body {
    flex: 1;
    overflow-y: auto;
    margin-bottom: 1.25rem;
}

.modal-body textarea {
    width: 100%;
    background: rgba(7, 9, 13, 0.7);
    border: 1px solid var(--border-light);
    border-radius: 4px;
    color: var(--text-user);
    padding: 0.75rem;
    font-size: 0.85rem;
    line-height: 1.5;
    outline: none;
    resize: vertical;
}

.modal-body textarea:focus {
    border-color: var(--border-glow);
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    border-top: 1px solid var(--border-light);
    padding-top: 0.75rem;
}

/* Custom terminal scrollbars */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: rgba(7, 9, 13, 0.2);
}

::-webkit-scrollbar-thumb {
    background: var(--border-light);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--border-glow);
}

/* In-page Toast Notification */
#toast-notification {
    position: fixed;
    bottom: 1.5rem;
    left: 50%;
    transform: translateX(-50%) translateY(60px);
    z-index: 9997;
    background: rgba(13, 20, 30, 0.92);
    border: 1px solid var(--text-neon);
    border-radius: 4px;
    padding: 0.65rem 1.4rem;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.85rem;
    color: var(--text-log);
    box-shadow: 0 0 18px rgba(56, 189, 248, 0.25);
    opacity: 0;
    pointer-events: none;
    transition: transform 0.25s ease, opacity 0.25s ease;
}

#toast-notification.toast-show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

#toast-notification.toast-error {
    border-color: #ef4444;
    color: #ef4444;
    box-shadow: 0 0 18px rgba(239, 68, 68, 0.25);
}

/* Token Limit Slider */
.token-limit-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-top: 1rem;
    padding-top: 0.85rem;
    border-top: 1px solid var(--border-light);
}

.token-limit-row label {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.78rem;
    color: var(--text-neon);
    white-space: nowrap;
    flex-shrink: 0;
}

.token-limit-row input[type="range"] {
    flex: 1;
    accent-color: var(--text-neon);
    cursor: pointer;
    height: 4px;
}

.token-limit-row .token-val {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.82rem;
    color: var(--text-user);
    min-width: 2.5rem;
    text-align: right;
}

/* Model Selection Row */
.model-selection-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-top: 1rem;
    padding-top: 0.85rem;
    border-top: 1px solid var(--border-light);
}

.model-selection-row label {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.78rem;
    color: var(--text-neon);
    white-space: nowrap;
    flex-shrink: 0;
}

.model-selection-row select {
    flex: 1;
    background: rgba(7, 9, 13, 0.7);
    border: 1px solid var(--border-light);
    border-radius: 4px;
    color: var(--text-user);
    padding: 0.35rem 0.5rem;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.82rem;
    outline: none;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.model-selection-row select:focus {
    border-color: var(--border-glow);
    box-shadow: 0 0 8px rgba(56, 189, 248, 0.3);
}

/* Retro Loading Spinner & Indicators */
.loader-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem 0;
    gap: 1rem;
    font-family: 'JetBrains Mono', monospace;
}

.retro-spinner {
    width: 24px;
    height: 24px;
    border: 2px solid var(--border-light);
    border-top: 2px solid var(--text-neon);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    box-shadow: 0 0 8px rgba(56, 189, 248, 0.4);
}

.loader-text {
    font-size: 0.8rem;
    color: var(--text-muted);
    letter-spacing: 0.1em;
    animation: pulse 1.2s ease-in-out infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

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

/* Hide native scrollbars globally but keep scroll functionality */
::-webkit-scrollbar {
    display: none;
}
* {
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* IE/Edge */
}

/* Control scanline/flicker display */
body:not(.crt-effect) .scanlines,
body:not(.crt-effect) .screen-flicker {
    display: none;
}

/* Memory tab sub-sections styling */
.memory-section-divider {
    height: 1px;
    background: var(--border-light);
    margin: 1.5rem 0;
    box-shadow: 0 0 2px rgba(56, 189, 248, 0.2);
}

.memory-subsection {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.memory-subsection h4 {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.8rem;
    color: var(--text-neon);
    margin: 0 0 0.5rem 0;
    letter-spacing: 0.05em;
    text-shadow: 0 0 3px rgba(74, 222, 128, 0.3);
}

.inventory-list, .event-log-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.inventory-item-card {
    background: rgba(13, 20, 30, 0.5);
    border: 1px solid var(--border-light);
    border-radius: 4px;
    padding: 0.5rem 0.75rem;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.75rem;
    animation: fade-in 0.2s ease-out;
}

.inventory-item-header {
    display: flex;
    justify-content: space-between;
    font-weight: bold;
    color: var(--text-log);
    margin-bottom: 0.25rem;
}

.inventory-item-type {
    color: var(--text-muted);
    font-size: 0.65rem;
    text-transform: uppercase;
}

.inventory-item-desc {
    color: var(--text-log-dim);
    line-height: 1.4;
    margin-top: 0.25rem;
}

.event-log-card {
    background: rgba(13, 20, 30, 0.5);
    border: 1px solid var(--border-light);
    border-left: 3px solid var(--border-glow);
    border-radius: 4px;
    padding: 0.5rem 0.75rem;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.75rem;
    animation: fade-in 0.2s ease-out;
}

.event-log-header {
    display: flex;
    justify-content: space-between;
    color: var(--text-neon);
    font-weight: bold;
    margin-bottom: 0.25rem;
}

.event-log-meta {
    color: var(--text-muted);
    font-size: 0.65rem;
}

.event-log-summary {
    color: var(--text-log);
    line-height: 1.4;
    margin-top: 0.25rem;
}

.memory-stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5rem;
    background: rgba(13, 20, 30, 0.3);
    border: 1px dashed var(--border-light);
    border-radius: 4px;
    padding: 0.5rem 0.75rem;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.75rem;
    color: var(--text-log-dim);
}

.memory-stat-item {
    display: flex;
    justify-content: space-between;
}

.memory-stat-item .stat-label {
    color: var(--text-muted);
}

.memory-stat-item .stat-val {
    color: var(--text-neon);
    font-weight: bold;
}

/* Debug Menu Layout & Elements */
.debug-container {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    padding-bottom: 2rem;
}

.debug-section h4 {
    font-family: 'VT323', monospace;
    font-size: 1.1rem;
    color: var(--text-neon);
    letter-spacing: 1px;
    margin-bottom: 0.5rem;
    border-bottom: 1px dashed rgba(56, 189, 248, 0.15);
    padding-bottom: 0.25rem;
}

.llm-calls-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-height: 250px;
    overflow-y: auto;
}

.no-calls-msg, .no-logs-msg {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.72rem;
    color: var(--text-muted);
    font-style: italic;
    padding: 0.5rem 0;
}

/* Call Item Styling */
.llm-call-item {
    background: rgba(13, 20, 30, 0.4);
    border: 1px solid var(--border-light);
    border-radius: 4px;
    padding: 0.5rem;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.72rem;
    transition: all var(--transition-fast);
}

.llm-call-item:hover {
    border-color: var(--border-glow);
    background: rgba(13, 20, 30, 0.6);
}

.llm-call-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.25rem;
}

.llm-call-id {
    color: var(--text-muted);
    font-weight: bold;
}

.llm-call-type {
    text-transform: uppercase;
    font-weight: 600;
}

/* Call Status Colors */
.llm-call-status {
    padding: 0.05rem 0.35rem;
    border-radius: 2px;
    font-size: 0.65rem;
    font-weight: bold;
}

.llm-call-status.active {
    background: rgba(239, 68, 68, 0.15);
    color: #ef4444;
    border: 1px solid #ef4444;
    animation: active-pulse 1s infinite alternate;
}

.llm-call-status.completed {
    background: rgba(74, 222, 128, 0.15);
    color: #4ade80;
    border: 1px solid #4ade80;
}

.llm-call-status.failed {
    background: rgba(239, 68, 68, 0.15);
    color: #ef4444;
    border: 1px solid #ef4444;
}

@keyframes active-pulse {
    from { opacity: 0.6; }
    to { opacity: 1; }
}

.llm-call-meta {
    display: flex;
    justify-content: space-between;
    color: var(--text-muted);
    font-size: 0.65rem;
    margin-bottom: 0.35rem;
}

.llm-call-prompt-toggle {
    background: transparent;
    border: none;
    color: var(--text-neon);
    cursor: pointer;
    font-family: inherit;
    font-size: 0.65rem;
    padding: 0;
    text-decoration: underline;
    display: block;
    margin-bottom: 0.25rem;
}

.llm-call-details {
    margin-top: 0.35rem;
    padding: 0.35rem;
    background: rgba(5, 7, 10, 0.8);
    border-radius: 2px;
    border-left: 2px solid var(--text-neon);
    font-size: 0.65rem;
    white-space: pre-wrap;
    max-height: 120px;
    overflow-y: auto;
    color: var(--text-user);
}

/* System Logs Panel */
.debug-logs-list {
    background: rgba(5, 7, 10, 0.6);
    border: 1px solid var(--border-light);
    border-radius: 4px;
    padding: 0.5rem;
    max-height: 250px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    font-size: 0.72rem;
    color: var(--text-log);
}

.debug-log-line {
    line-height: 1.3;
}

.debug-log-timestamp {
    color: var(--text-muted);
    margin-right: 0.35rem;
}

/* Debug pulsing animation inside tab-btn */
.debug-pulse-active {
    display: inline-block;
    width: 8px;
    height: 8px;
    background-color: #ef4444;
    border-radius: 50%;
    margin-left: 5px;
    box-shadow: 0 0 8px #ef4444;
    animation: debug-glow 1s infinite alternate;
}

.debug-pulse-inactive {
    display: none;
}

@keyframes debug-glow {
    from { opacity: 0.4; }
    to { opacity: 1; }
}

/* ==================== Spatial Map Panel ==================== */
#tab-map.active {
    overflow: hidden;
}

.map-panel {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    height: 100%;
    min-height: 260px;
    width: 100%;
    min-width: 0;
}

.map-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    flex-shrink: 0;
}

.map-toolbar-title {
    font-family: 'VT323', monospace;
    font-size: 1.2rem;
    color: var(--text-neon);
    letter-spacing: 0.05em;
}

.map-mode-toggle {
    font-family: 'VT323', monospace;
    font-size: 0.95rem;
}

.map-canvas {
    position: relative;
    flex: 1;
    width: 100%;
    min-width: 0;
    min-height: 260px;
    overflow: auto;
    border: 1px solid var(--border-light);
    border-radius: 4px;
    background:
        linear-gradient(rgba(56, 189, 248, 0.05) 1px, transparent 1px) 0 0 / 100% 28px,
        linear-gradient(90deg, rgba(56, 189, 248, 0.05) 1px, transparent 1px) 0 0 / 28px 100%,
        rgba(7, 9, 13, 0.55);
}

/* Sized layer inside the scroll box. The canvas scrolls; this grows. */
.map-canvas-content {
    position: relative;
    min-width: 100%;
    min-height: 100%;
}

.map-region {
    position: absolute;
    border: 1px dashed rgba(56, 189, 248, 0.25);
    border-radius: 6px;
    background: rgba(56, 189, 248, 0.04);
    pointer-events: none;
}

.map-region-label {
    position: absolute;
    top: -0.75rem;
    left: 0.5rem;
    padding: 0 0.35rem;
    font-family: 'VT323', monospace;
    font-size: 0.8rem;
    color: var(--text-muted);
    background: var(--bg-dark);
}

.map-edges {
    position: absolute;
    top: 0;
    left: 0;
    pointer-events: none;
    overflow: visible;
}

.map-edge {
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
}

.map-edge-walk {
    stroke: #38bdf8;
}

.map-edge-portal {
    stroke: #c084fc;
    stroke-width: 2.5;
}

.map-edge-time {
    stroke: #facc15;
}

.map-edge-inferred {
    stroke-dasharray: 6 5;
    opacity: 0.85;
}

.map-edge-label {
    font-family: 'JetBrains Mono', monospace;
    font-size: 9px;
    fill: var(--text-muted);
    paint-order: stroke;
    stroke: var(--bg-dark);
    stroke-width: 3px;
    stroke-linejoin: round;
}

.map-room {
    position: absolute;
    width: 132px;
    min-height: 54px;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 2px;
    padding: 0.4rem 0.55rem;
    border: 1px solid var(--border-light);
    border-radius: 4px;
    background: rgba(7, 9, 13, 0.92);
    font-family: 'JetBrains Mono', monospace;
    z-index: 2;
}

.map-room-name {
    font-size: 0.78rem;
    color: var(--text-user);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.map-room-meta {
    font-size: 0.62rem;
    color: var(--text-muted);
    letter-spacing: 0.03em;
}

.map-room.unvisited {
    opacity: 0.65;
    border-style: dashed;
}

.map-room.visited {
    border-color: rgba(74, 222, 128, 0.5);
}

.map-room.current-room {
    border-color: var(--text-neon);
    box-shadow: 0 0 12px rgba(56, 189, 248, 0.5);
    background: rgba(56, 189, 248, 0.16);
    opacity: 1;
}

.map-room.current-room .map-room-name {
    color: var(--text-neon);
    text-shadow: 0 0 5px rgba(56, 189, 248, 0.5);
}

.map-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 220px;
    font-family: 'VT323', monospace;
    font-size: 1.2rem;
    color: var(--text-muted);
    letter-spacing: 0.05em;
}

@media (max-width: 767px) {
    .map-panel {
        min-height: 200px;
    }

    .map-canvas {
        min-height: 200px;
    }
}

/* ==================== Mobile Tab Bar ==================== */
.mobile-tab-bar {
    display: none;
}

@media (max-width: 767px) {
    /* Single mobile scroll owner: `.app-container` (bounded by body's 100dvh)
       consumes all wizard-screen overflow. `align-items: flex-start` anchors
       the scroll origin at the top, avoiding the flex-origin centering trap
       where tall content is clipped off both edges by body { overflow: hidden }.
       Wizard panels own the end-of-scroll bottom clearance buffer instead. */
    .app-container {
        height: 100%;
        align-items: flex-start;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        padding-top: max(1.5rem, var(--safe-top));
    }

    .game-dashboard {
        padding-bottom: calc(var(--tab-bar-h) + max(8px, var(--safe-bottom)));
    }

    .dashboard-body {
        grid-template-columns: 1fr;
    }

    .mobile-tab-bar {
        display: flex;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 100;
        background: rgba(7, 9, 13, 0.98);
        border-top: 1px solid var(--border-light);
        padding-bottom: max(8px, var(--safe-bottom));
        -webkit-transform: translate3d(0, 0, 0);
        transform: translate3d(0, 0, 0);
    }

    .mobile-tab {
        flex: 1;
        background: transparent;
        border: none;
        padding: 0.5rem;
        font-family: 'VT323', monospace;
        font-size: 1.2rem;
        color: var(--text-muted);
        cursor: pointer;
        min-height: var(--tab-h);
        touch-action: manipulation;
        -webkit-tap-highlight-color: transparent;
        transition: color var(--transition-fast);
    }

    .mobile-tab.active {
        color: var(--text-neon);
    }

    .mobile-tab:hover {
        color: var(--text-user);
    }

    .sidebar-panel {
        display: none;
        max-height: 40vh;
        max-height: 40dvh;
    }

    .sidebar-panel.active {
        display: flex;
    }

    .glass-panel {
        padding: 0.75rem;
    }

    .startup-header h1 {
        font-size: 2rem;
    }

    .panel-header h2 {
        font-size: 1.4rem;
    }

    .status-bar {
        display: grid;
        grid-template-columns: 1fr 1fr;
        font-size: 1rem;
        gap: 0.15rem;
    }

    .status-item {
        min-width: auto;
    }

    .console-log {
        font-size: 0.85rem;
    }

    .console-utilities {
        flex-wrap: wrap;
        gap: 0.25rem;
    }

    .btn-utility {
        min-height: 44px;
        padding: 0.5rem;
    }

    #console-input {
        min-height: 44px;
        font-size: 16px;
    }

    .kbd-hint {
        display: none;
    }

    .suggestion-chip {
        min-height: 44px;
        padding: 0.5rem 0.75rem;
    }

    /* Action chips must meet the 44px touch target on handsets. */
    .action-chip {
        min-height: 44px;
    }

    .tab-btn {
        min-height: 44px;
        font-size: 1.1rem;
    }

    /* ─── Mobile Wizard Screen Layouts ─────────────────────────────────────────────── */
    #startup-screen,
    #preset-screen,
    #custom-preset-screen,
    #character-screen,
    #preset-manager-screen,
    #restore-screen,
    #preset-editor-screen {
        min-height: 100%;
        /* The panel must not establish its own (never-engaging) scroll context:
           `.app-container` is the single scroll owner. The panel only owns the
           bottom clearance buffer that clears floating browser chrome when the
           scroller reaches its end. `min-height: 100%` (not 100dvh) keeps short
           screens from forcing a phantom 40px scroll inside the padded scroller. */
        overflow-y: visible;
        padding-bottom: calc(var(--safe-bottom) + 1.5rem);
    }

    /* ─── Safe-Area Inset Support ──────────────────────────────────────────────────── */
    .startup-header {
        padding-top: var(--safe-top);
    }

    .panel-header {
        padding-top: var(--safe-top);
    }

    .panel-footer-nav {
        gap: 0.75rem;
    }

    /* ─── Responsive Grids ─────────────────────────────────────────────────────────── */
    .preset-grid {
        grid-template-columns: 1fr;
    }

    .character-grid {
        grid-template-columns: 1fr;
    }

    /* ─── Modal Responsiveness ─────────────────────────────────────────────────────── */
    .modal-content {
        max-width: 90vw;
        max-height: 90vh;
        max-height: 90dvh;
        overflow-y: auto;
        padding: 1rem;
        padding-bottom: calc(var(--safe-bottom) + 1rem);
    }

    .barter-layout {
        grid-template-columns: 1fr;
    }

    .barter-arrow {
        display: none;
    }

    .modal-footer {
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .modal-footer .btn {
        flex: 1 1 auto;
        min-width: 0;
    }

    .btn-close {
        min-width: 44px;
        min-height: 44px;
    }

    /* ─── Touch Target Minimum Sizes ───────────────────────────────────────────────── */
    .btn {
        min-height: 44px;
    }

    .preset-card,
    .char-card {
        min-height: 44px;
    }

    input,
    textarea,
    select {
        min-height: 44px;
    }

    /* ─── Startup Screen Refinements ───────────────────────────────────────────────── */
    .startup-header .subtitle {
        overflow-wrap: break-word;
        word-wrap: break-word;
        hyphens: auto;
    }
}

@media (max-width: 1023px) and (min-width: 768px) {
    .dashboard-body {
        grid-template-columns: 1fr;
    }

    .sidebar-panel {
        max-height: 40vh;
        overflow-y: auto;
    }

    /* Tablet grids: 2-column layout for preset and character grids */
    .preset-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .character-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* ─── Action Chips ─────────────────────────────────────────────────────── */

.action-chips {
    margin: 0.5rem 0;
    padding: 0.5rem;
    border-top: 1px solid var(--border);
}

.action-chips-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.action-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.4rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.05);
    color: var(--text);
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.15s ease;
}

.action-chip:hover {
    background: rgba(255, 255, 255, 0.12);
    border-color: var(--accent);
    color: var(--accent);
}

.action-chip-talk {
    border-color: #3b82f6;
    color: #60a5fa;
}

.action-chip-barter {
    border-color: #f59e0b;
    color: #fbbf24;
}

.action-chip-goals {
    border-color: #10b981;
    color: #34d399;
}

/* ─── Barter Modal ──────────────────────────────────────────────────────── */

.barter-modal-content {
    max-width: 700px;
    width: 90%;
}

.barter-layout {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    gap: 1rem;
    align-items: start;
    min-height: 200px;
}

.barter-panel {
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0.75rem;
    background: rgba(0, 0, 0, 0.2);
}

.barter-panel h4 {
    margin: 0 0 0.5rem 0;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    padding-bottom: 0.4rem;
}

.barter-arrow {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    color: var(--accent);
    padding: 0 0.25rem;
}

.barter-item-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-height: 250px;
    overflow-y: auto;
}

.barter-item-card {
    padding: 0.4rem;
    border: 1px solid var(--border);
    border-radius: 3px;
    background: rgba(255, 255, 255, 0.03);
}

.barter-item-name {
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--text);
}

.barter-item-type {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
}

.barter-item-desc {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.2rem;
}

.barter-offer-card {
    padding: 0.5rem;
    border: 1px solid var(--border);
    border-radius: 3px;
    background: rgba(255, 255, 255, 0.03);
}

.barter-offer-req {
    font-size: 0.8rem;
    color: #f87171;
}

.barter-offer-give {
    font-size: 0.8rem;
    color: #34d399;
}

.barter-offer-desc {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 0.2rem;
}

.barter-offer-card .btn-trade {
    margin-top: 0.4rem;
    width: 100%;
    font-size: 0.75rem;
    padding: 0.3rem 0.5rem;
}

.barter-status-text {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-family: 'JetBrains Mono', monospace;
}


