/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

:root {
    --bg-darkest: #0d0f13;
    --bg-dark: #13161c;
    --bg-card: #1a1e27;
    --bg-input: #1e2230;
    --bg-hover: #252a36;
    --border: #2a2f3d;
    --border-light: #353b4d;
    --text: #e2e4e9;
    --text-muted: #8b8fa3;
    --text-dim: #5a5f73;
    --accent: #5ebd7a;
    --accent-dim: #3a8f55;
    --accent-glow: rgba(94, 189, 122, 0.15);
    --success: #4ade80;
    --warning: #fbbf24;
    --danger: #f87171;
    --radius: 8px;
    --radius-lg: 12px;
    --sidebar-w: 280px;
    --topbar-h: 56px;
    --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-mono: 'SF Mono', 'Fira Code', 'Consolas', monospace;
}

html, body {
    height: 100%;
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg-darkest);
    -webkit-font-smoothing: antialiased;
}
/* Dynamic viewport height — shrinks when iOS keyboard appears so chat reflows correctly */
@supports (height: 100dvh) {
    body { height: 100dvh; }
}

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

.accent { color: var(--accent); }
.muted { color: var(--text-muted); font-size: 13px; }

/* === Buttons === */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius);
    font-family: var(--font);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-dim); }
.btn-secondary { background: var(--bg-hover); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover:not(:disabled) { background: var(--border); }
.btn-ghost { background: none; color: var(--text-muted); }
.btn-ghost:hover { color: var(--text); }
.btn-danger { background: none; color: #e05252; border-color: #e05252; }
.btn-danger:hover { background: #e05252; color: #fff; }
.btn-small { padding: 6px 12px; font-size: 12px; }
.btn-icon { background: none; border: none; color: var(--text-muted); font-size: 20px; cursor: pointer; padding: 4px 8px; }
.btn-icon:hover { color: var(--text); }

/* === Screens === */
.screen { width: 100%; height: 100%; }

/* === Auth Screen === */
#auth-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    overflow-y: auto;
    background: radial-gradient(ellipse at 50% 20%, rgba(94,189,122,0.07) 0%, transparent 60%),
                var(--bg-darkest);
}

.auth-hero {
    width: 100%;
    max-width: 640px;
    padding: 24px 20px 0;
}

.auth-splash {
    width: 100%;
    height: auto;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-light);
    display: block;
    box-shadow: 0 6px 32px rgba(0,0,0,0.6);
}

.auth-container {
    width: 100%;
    max-width: 380px;
    padding: 24px;
}

.auth-logo {
    text-align: center;
    margin-bottom: 32px;
}

.auth-logo h1 {
    font-size: 28px;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.auth-tagline {
    color: var(--text-muted);
    margin-top: 4px;
    margin-bottom: 20px;
    font-size: 14px;
    text-align: center;
}

.auth-form { display: flex; flex-direction: column; gap: 16px; }

.form-group { display: flex; flex-direction: column; gap: 4px; }
.form-group label { font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; }
.form-group input {
    padding: 10px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 14px;
    font-family: var(--font);
    outline: none;
    transition: border-color 0.15s;
}
.form-group input:focus { border-color: var(--accent); }
.form-group input::placeholder { color: var(--text-dim); }

.auth-error {
    padding: 10px 12px;
    background: rgba(248, 113, 113, 0.1);
    border: 1px solid rgba(248, 113, 113, 0.3);
    border-radius: var(--radius);
    color: var(--danger);
    font-size: 13px;
}

.auth-toggle { text-align: center; color: var(--text-muted); font-size: 13px; }
.auth-help { text-align: center; color: var(--text-dim); font-size: 12px; margin-top: 20px; }
.auth-help a { color: var(--text-dim); text-decoration: underline; }

/* === Top Bar === */
.topbar {
    height: var(--topbar-h);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    background: var(--bg-dark);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.topbar-left { display: flex; align-items: center; gap: 12px; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.topbar-title { font-size: 18px; font-weight: 700; letter-spacing: -0.3px; }

/* === Deck Settings Dropdown (topbar) === */
.deck-settings-menu-wrap {
    position: relative;
}

.deck-settings-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    margin-top: 8px;
    width: 240px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    z-index: 150;
    padding: 14px 16px;
}

/* === Settings Dropdown === */
.settings-menu-wrap {
    position: relative;
}

.settings-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 8px;
    width: 260px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    z-index: 150;
    overflow: hidden;
}

.settings-section {
    padding: 14px 16px;
}

.settings-section-title {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-dim);
    margin-bottom: 10px;
}

.settings-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 5px 0;
    font-size: 13px;
    gap: 8px;
}
.settings-item-stack {
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
}

.settings-label { color: var(--text-muted); white-space: nowrap; }
.settings-value { color: var(--text); font-weight: 500; text-align: right; overflow: hidden; text-overflow: ellipsis; }
.settings-edit-row { display: flex; gap: 6px; align-items: center; width: 100%; }
.settings-audio-row {
    display: flex;
    align-items: center;
    gap: 6px;
}
.settings-slider {
    flex: 1;
    height: 4px;
    accent-color: var(--accent);
    cursor: pointer;
}
.btn-icon-sm {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 16px;
    padding: 2px;
    line-height: 1;
}
.btn-icon-sm:hover { color: var(--text); }
.btn-icon-sm.muted { color: var(--text-dim); opacity: 0.5; }

.settings-edit-input {
    flex: 1;
    min-width: 0;
    background: var(--bg-hover);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    padding: 5px 8px;
    font-size: 13px;
}

.settings-tier-badge {
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.settings-tier-free { background: var(--bg-hover); color: var(--text-muted); }
.settings-tier-god_mode { background: rgba(167, 139, 250, 0.15); color: var(--accent); }
.settings-tier-monthly { background: rgba(74, 222, 128, 0.15); color: var(--success); }

.settings-divider {
    height: 1px;
    background: var(--border);
}

.settings-help-link {
    display: block;
    padding: 10px 16px;
    color: var(--text-muted);
    font-size: 13px;
    text-decoration: none;
}
.settings-help-link:hover { background: var(--bg-hover); color: var(--text); }

.settings-logout {
    display: block;
    width: 100%;
    padding: 12px 16px;
    background: none;
    border: none;
    color: var(--danger);
    font-family: var(--font);
    font-size: 13px;
    font-weight: 500;
    text-align: left;
    cursor: pointer;
}
.settings-logout:hover { background: var(--bg-hover); }

.usage-badge {
    padding: 4px 10px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 99px;
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 500;
}

/* === App Layout === */
#app-screen { display: flex; flex-direction: column; }
.app-body { display: flex; flex: 1; overflow: hidden; }

/* === Sidebar === */
.sidebar {
    width: var(--sidebar-w);
    flex-shrink: 0;
    background: var(--bg-dark);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 0;
    overflow-y: auto;
    padding: 16px;
}

.coach-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 8px 0 12px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 8px;
}

.coach-avatar-wrap {
    width: 100%;
    aspect-ratio: 1;
    border-radius: var(--radius-lg);
    overflow: hidden;
    border: 3px solid var(--accent);
    box-shadow: 0 0 20px var(--accent-glow);
    flex-shrink: 0;
    transition: border-color 0.3s, box-shadow 0.3s;
}

.coach-avatar {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.coach-info { text-align: center; }
.coach-name { display: block; font-weight: 600; font-size: 16px; }
.coach-title { display: block; color: var(--text-muted); font-size: 12px; font-style: italic; }

.sidebar-section { padding: 8px 0; border-bottom: 1px solid var(--border); }
.sidebar-section:last-child { border-bottom: none; }
.sidebar-section h3 {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-dim);
    margin-bottom: 8px;
}


/* Tier badge in character sheet */
.char-health-row {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 4px;
}
.char-health-icon {
    color: #e74c3c;
    font-size: 12px;
}
.char-health-bar-wrap {
    flex: 1;
    height: 6px;
    background: var(--bg-hover);
    border-radius: 3px;
    overflow: hidden;
}
.char-health-bar {
    height: 100%;
    background: #e74c3c;
    border-radius: 3px;
    transition: width 0.5s ease, background-color 0.5s ease;
}
.char-health-bar.low { background: #c0392b; }
.char-health-bar.critical { background: #ff0000; animation: pulse-health 1s ease-in-out infinite; }
@keyframes pulse-health {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}
.char-health-bar.overheal { background: #9b59b6; }
.char-health-text {
    font-size: 9px;
    color: var(--text-dim);
    white-space: nowrap;
}
.char-level-row {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 4px;
}
.char-level-label {
    font-size: 12px;
    font-weight: 700;
    color: var(--accent);
    white-space: nowrap;
}
.char-xp-bar-wrap {
    flex: 1;
    height: 6px;
    background: var(--bg-hover);
    border-radius: 3px;
    overflow: hidden;
}
.char-xp-bar {
    height: 100%;
    background: var(--accent);
    border-radius: 3px;
    transition: width 0.5s ease;
}
.char-xp-text {
    font-size: 9px;
    color: var(--text-dim);
    white-space: nowrap;
}
.char-tier {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 6px;
}
.char-tier-free { color: var(--text-muted); }
.char-tier-god_mode { color: #D4A017; }
.char-tier-monthly { color: var(--accent); }

.collection-status { margin-bottom: 8px; }
.collection-status .stat { display: flex; justify-content: space-between; font-size: 13px; padding: 2px 0; }
.collection-status .stat-value { color: var(--accent); font-weight: 500; }

.upload-btn { width: 100%; cursor: pointer; text-align: center; }

/* === Deck Constraint Controls === */
.constraint-group { margin-bottom: 10px; }
.constraint-label {
    display: block;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 4px;
}
.radio-group { display: flex; gap: 2px; flex-wrap: wrap; }
.radio-option {
    font-size: 12px;
    color: var(--text-muted);
    cursor: pointer;
    padding: 3px 8px;
    border-radius: 4px;
    border: 1px solid var(--border);
    background: var(--bg-dark);
    transition: all 0.15s;
    display: flex;
    align-items: center;
    gap: 4px;
}
.radio-option:hover { border-color: var(--accent-dim); color: var(--text); }
.radio-option input[type="radio"] { display: none; }
.radio-option:has(input:checked) {
    background: var(--accent-dim);
    border-color: var(--accent);
    color: #fff;
}
.constraint-slider {
    width: 100%;
    -webkit-appearance: none;
    appearance: none;
    height: 6px;
    border-radius: 3px;
    background: var(--bg-hover);
    outline: none;
    margin: 6px 0 2px;
}
.constraint-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
}
.slider-labels {
    display: flex;
    justify-content: space-between;
    font-size: 10px;
    color: var(--text-dim);
}

/* === Saved Decks === */
.saved-deck-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 0;
    border-bottom: 1px solid var(--border);
    font-size: 12px;
}
.saved-deck-item:last-child { border-bottom: none; }

.saved-deck-info {
    flex: 1;
    min-width: 0;
    cursor: pointer;
}
.saved-deck-info:hover { color: var(--accent); }

.saved-deck-name {
    display: block;
    font-weight: 600;
    font-size: 12px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.saved-deck-meta {
    font-size: 10px;
    color: var(--text-dim);
}

.saved-deck-delete {
    background: none;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    font-size: 14px;
    padding: 2px 4px;
    flex-shrink: 0;
}
.saved-deck-delete:hover { color: var(--danger); }

.saved-decks-empty { font-size: 12px; color: var(--text-dim); font-style: italic; }

/* Dice roll display */
.dice-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 12px 0;
    gap: 8px;
}
.dice-split {
    display: flex;
    align-items: flex-end;
    justify-content: center;
    width: 100%;
}
.dice-half {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    flex: 1;
}
.dice-half-label {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--text-dim);
}
.dice-divider {
    width: 1px;
    height: 52px;
    background: var(--border);
    margin: 0 4px;
    flex-shrink: 0;
    align-self: flex-end;
}
.dice-face {
    width: 52px;
    height: 52px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    font-weight: 800;
    border-radius: 10px;
    background: var(--bg-hover);
    border: 2px solid var(--border);
    color: var(--text-dim);
    user-select: none;
    transition: border-color 0.2s, box-shadow 0.2s, transform 0.1s;
}
.dice-face-dc {
    background: var(--bg-card) !important;
    border-style: dashed !important;
    color: var(--text-muted) !important;
}
.dice-area.roll-success .dice-face {
    border-color: #4ADE80 !important;
    border-style: solid !important;
    box-shadow: 0 0 10px #4ADE8055;
}
.dice-area.roll-fail .dice-face {
    border-color: #F87171 !important;
    border-style: solid !important;
    box-shadow: 0 0 10px #F8717155;
}

/* Rolling animation */
.dice-face.rolling {
    animation: dice-roll 0.6s ease-out;
}
@keyframes dice-roll {
    0% { transform: rotateX(0deg) rotateZ(0deg) scale(1); }
    20% { transform: rotateX(180deg) rotateZ(90deg) scale(1.1); }
    40% { transform: rotateX(360deg) rotateZ(180deg) scale(0.95); }
    60% { transform: rotateX(540deg) rotateZ(270deg) scale(1.05); }
    80% { transform: rotateX(680deg) rotateZ(340deg) scale(1); }
    100% { transform: rotateX(720deg) rotateZ(360deg) scale(1); }
}
/* Result landed — brief glow */
.dice-face.landed {
    animation: dice-land 0.3s ease-out;
}
@keyframes dice-land {
    0% { box-shadow: 0 0 20px var(--accent); transform: scale(1.15); }
    100% { box-shadow: none; transform: scale(1); }
}

.dice-result {
    text-align: center;
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 8px;
    line-height: 1.4;
}
.dice-result .dice-success { color: #4ADE80; }
.dice-result .dice-fail { color: #F87171; }

/* Spacer pushes character sheet to bottom */
.sidebar-spacer { flex: 1; }

/* Player Character Sheet */
.character-sheet {
    border-top: 1px solid var(--border);
    padding: 14px 0 4px;
    flex-shrink: 0;
}
.char-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}
.char-avatar-wrap {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    overflow: hidden;
    border: 2px solid var(--accent-dim);
    flex-shrink: 0;
    background: var(--bg-hover);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    font-weight: 700;
    color: var(--text-muted);
}
.char-avatar-wrap[data-initial]:not([data-initial=""])::after {
    content: attr(data-initial);
}
.char-avatar {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.char-identity {
    display: flex;
    flex-direction: column;
    gap: 3px;
    min-width: 0;
}
.char-name {
    font-weight: 600;
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.char-gold {
    font-size: 12px;
    color: #D4A017;
    font-weight: 600;
}
.char-gold::before {
    content: "\1FA99 ";
}
.char-stats-line {
    font-size: 12px;
    color: var(--text);
    line-height: 1.8;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0;
    margin-bottom: 2px;
}
.stat-inline-entry {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    white-space: nowrap;
}
.stat-inline-entry b {
    color: var(--text-muted);
    font-size: 10px;
    letter-spacing: 0.4px;
}
.stat-inline-bonus {
    color: var(--accent);
    font-size: 11px;
}
.stat-inline-sep {
    color: var(--border);
    margin: 0 3px;
}
.char-stat-points {
    text-align: center;
    margin-bottom: 6px;
}
.stat-points-label {
    font-size: 11px;
    font-weight: 600;
    color: #D4A017;
    animation: pulse-gold 1.5s ease-in-out infinite;
}
@keyframes pulse-gold {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}
.stat-assign-btn {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 1px solid var(--accent);
    background: transparent;
    color: var(--accent);
    font-size: 11px;
    font-weight: 700;
    cursor: pointer;
    padding: 0;
    line-height: 1;
}
.stat-assign-btn:hover {
    background: var(--accent);
    color: var(--bg-dark);
}
/* Status Effect Badges */
.char-status-effects {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--border);
}
.status-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 6px;
    font-size: 14px;
    cursor: default;
    border: 1px solid;
    transition: transform 0.15s, box-shadow 0.15s;
}
.status-badge:hover {
    transform: scale(1.15);
    box-shadow: 0 0 8px rgba(255,255,255,0.15);
}
.status-badge-negative {
    background: rgba(180, 30, 30, 0.18);
    border-color: rgba(220, 60, 60, 0.5);
}
.status-badge-positive {
    background: rgba(30, 140, 80, 0.18);
    border-color: rgba(60, 200, 100, 0.5);
}

.sfx-note {
    display: block;
    margin-top: 6px;
    font-size: 11px;
    font-style: italic;
    color: var(--text-muted, #888);
    opacity: 0.75;
}

.char-equipped {
    margin-top: 6px;
    padding-top: 6px;
    border-top: 1px solid var(--border);
}
.char-equipped-item {
    font-size: 10px;
    color: var(--text-muted);
    padding: 1px 6px;
    background: var(--bg-hover);
    border-radius: var(--radius);
    display: flex;
    justify-content: space-between;
    gap: 4px;
}
.char-equipped-slot {
    color: var(--text-dim);
    font-size: 9px;
    text-transform: uppercase;
    flex-shrink: 0;
    min-width: 58px;
}
.char-equipped-bonus {
    color: var(--text-dim);
    font-size: 9px;
}
.char-inventory {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--border);
}
.char-inventory-label {
    font-size: 9px;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--text-muted);
    letter-spacing: 0.5px;
}
.char-inventory-items {
    margin-top: 4px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.char-inventory-item {
    font-size: 11px;
    color: #D4A017;
    padding: 2px 6px;
    background: var(--bg-hover);
    border-radius: var(--radius);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.char-inventory-item::before {
    content: "\2726 ";
    opacity: 0.6;
}
.char-inventory-usable {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 4px;
}
.char-inventory-usable::before { content: "\1F9EA "; }
.inv-use-btn {
    padding: 1px 8px;
    border: 1px solid var(--accent-dim);
    border-radius: var(--radius);
    background: transparent;
    color: var(--accent);
    font-size: 10px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    flex-shrink: 0;
}
.inv-use-btn:hover { background: var(--accent); color: var(--bg-dark); }
.inv-use-done { color: #4ADE80; border-color: #4ADE80; pointer-events: none; }
.inv-stack-count { font-size: 10px; color: #a89fc0; font-weight: 600; }

.char-inventory-wearable {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 4px;
}
.inv-wear-btn {
    padding: 1px 8px;
    border: 1px solid var(--accent-dim);
    border-radius: var(--radius);
    background: transparent;
    color: var(--accent);
    font-size: 10px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    flex-shrink: 0;
}
.inv-wear-btn:hover { background: var(--accent); color: var(--bg-dark); }

.account-avatar-row { display: flex; align-items: center; gap: 10px; }
.account-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--bg-hover);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    overflow: hidden;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-muted);
}
.account-avatar img { width: 100%; height: 100%; object-fit: cover; }

/* === Chat Area === */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: var(--bg-darkest);
    position: relative;
}

.chat-area-bg {
    position: absolute;
    inset: 0;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center center;
    pointer-events: none;
    z-index: 0;
    opacity: 0;
    transition: opacity 0.5s ease;
}

.chat-area-bg.active {
    opacity: 0.20;
    filter: brightness(0.6);
}
.chat-area-bg.active--dark {
    opacity: 0.06;
    filter: brightness(0.4);
}
.chat-bg-video {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

/* ── Witch mode ──────────────────────────────────────────── */
.chat-area-bg.witch-bg {
    opacity: 0.55;
    filter: brightness(0.7);
    background-size: cover;
    background-position: center top;
}
.chat-area-bg.witch-bg .chat-bg-video {
    object-fit: cover;
}
.witch-mode .msg-assistant .msg-avatar {
    display: none;
}
.witch-mode .msg-assistant .msg-bubble {
    background: rgba(8, 5, 18, 0.28) !important;
    border-color: rgba(139, 92, 246, 0.15) !important;
    color: #e8e0ff;
    text-shadow: 0 1px 4px rgba(0, 0, 0, 0.95);
}
.witch-mode .msg-user .msg-bubble {
    background: rgba(60, 20, 120, 0.32) !important;
    color: #fff;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.85);
}
.witch-mode .action-btn {
    background: rgba(15, 8, 30, 0.7) !important;
    border-color: rgba(139, 92, 246, 0.6) !important;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
}

/* ── Barmaid mode ────────────────────────────────────────── */
.chat-area-bg.barmaid-bg {
    opacity: 1 !important;
    filter: brightness(1) !important;
    background-size: cover;
    background-position: center top;
}
.chat-area-bg.barmaid-bg .chat-bg-video {
    object-fit: cover;
}
.barmaid-mode .msg-assistant .msg-avatar {
    display: none;
}
.barmaid-mode .msg-assistant .msg-bubble {
    background: rgba(10, 8, 5, 0.22) !important;
    border-color: rgba(255, 220, 180, 0.12) !important;
    color: #fff;
    text-shadow: 0 1px 4px rgba(0, 0, 0, 0.9);
}
.barmaid-mode .msg-user .msg-bubble {
    background: rgba(180, 100, 40, 0.3) !important;
    color: #fff;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.85);
}
.barmaid-mode .action-btn {
    background: rgba(20, 12, 5, 0.65) !important;
    border-color: rgba(200, 121, 65, 0.65) !important;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
}

.chat-messages, .chat-input-wrap {
    position: relative;
    z-index: 1;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* Message bubbles */
.msg {
    display: flex;
    gap: 12px;
    max-width: 85%;
    animation: fadeIn 0.2s ease;
}
.msg-user { align-self: flex-end; flex-direction: row-reverse; }
.msg-assistant { align-self: flex-start; }

.msg-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    flex-shrink: 0;
    object-fit: cover;
}
.msg-user .msg-avatar { display: none; }

.msg-bubble {
    padding: 10px 14px;
    border-radius: var(--radius-lg);
    font-size: 14px;
    line-height: 1.6;
    word-break: break-word;
}

.msg-user .msg-bubble {
    background: var(--accent-dim);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.msg-assistant .msg-bubble {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
}

.inline-npc-media {
    display: block;
    width: 100%;
    max-width: 320px;
    border-radius: var(--radius-lg);
    margin-bottom: 10px;
}

/* 4-across grid wrapper for menu-style action buttons */
.action-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 4px;
}
.action-grid .action-btn {
    flex: 1 1 calc(25% - 6px);
    min-width: 100px;
    margin: 0;
    text-align: center;
}

/* Action buttons in chat (adventure choices, retry/flee) */
.action-btn {
    display: inline-block;
    margin: 4px 4px 4px 0;
    padding: 8px 16px;
    background: var(--bg-hover);
    border: 1px solid var(--advisor-accent, var(--accent-dim));
    border-radius: var(--radius-lg);
    color: var(--text);
    font-family: var(--font);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
}
.action-btn:hover {
    background: var(--advisor-accent, var(--accent));
    color: var(--bg-dark);
    border-color: var(--advisor-accent, var(--accent));
    transform: translateY(-1px);
}
.action-btn:active {
    transform: translateY(0);
}
.action-btn-selected {
    background: var(--advisor-accent, var(--accent)) !important;
    color: var(--bg-dark) !important;
    border-color: var(--advisor-accent, var(--accent)) !important;
}
.action-btn-used {
    opacity: 0.4;
    cursor: default;
    pointer-events: none;
}
.action-btn-lunatic {
    opacity: 0.25;
    cursor: not-allowed;
    pointer-events: none;
    filter: grayscale(1);
}
.lunatic-chosen-indicator {
    display: inline-block;
    font-size: 12px;
    color: #a78bfa;
    font-style: italic;
    margin-left: 8px;
    vertical-align: middle;
}
.action-btn[data-action="4"],
.action-btn[data-action="flee"],
.action-btn[data-action="cancel"] {
    border-color: var(--text-dim);
    color: var(--text-muted);
    font-size: 12px;
}
.action-btn[data-action="4"]:hover,
.action-btn[data-action="flee"]:hover,
.action-btn[data-action="cancel"]:hover {
    background: var(--text-dim);
    color: var(--bg-dark);
}

.action-btn[data-action^="sell all"] {
    border-color: rgba(200, 60, 60, 0.7);
    color: rgba(220, 100, 100, 0.9);
}
.action-btn[data-action^="sell all"]:hover {
    background: rgba(200, 60, 60, 0.15);
    border-color: rgba(220, 80, 80, 1);
    color: #ff9999;
}

.chat-link {
    color: var(--accent);
    text-decoration: underline;
    text-underline-offset: 2px;
}
.chat-link:hover {
    color: #a78bfa;
}

/* Deck block inside messages */
.deck-block {
    margin: 8px 0;
    padding: 12px;
    background: var(--bg-dark);
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
    font-family: var(--font-mono);
    font-size: 12px;
    line-height: 1.7;
    position: relative;
}

.deck-block .deck-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
}

.deck-block .deck-name {
    font-weight: 700;
    color: var(--accent);
    font-family: var(--font);
    font-size: 14px;
}

.deck-block .deck-class {
    color: var(--text-muted);
    font-family: var(--font);
    font-size: 12px;
}

.deck-block .deck-cards {
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.deck-card-line {
    font-family: var(--font-mono);
    font-size: 12px;
    line-height: 1.6;
    padding: 1px 0;
    color: var(--text-muted);
}

.deck-card-name {
    color: #fff;
    transition: color 0.2s;
}

.deck-card-unowned {
    text-decoration: underline wavy rgba(251, 191, 36, 0.5);
    text-underline-offset: 3px;
}

.deck-dust-missing { color: var(--warning); font-weight: 600; }

.deck-complete-tip {
    display: block;
    margin-top: 6px;
    padding: 5px 8px;
    background: rgba(167, 139, 250, 0.08);
    border: 1px solid rgba(167, 139, 250, 0.2);
    border-radius: 4px;
    font-size: 11px;
    color: var(--accent);
    line-height: 1.4;
}

.deck-card-missing-tag {
    font-size: 10px;
    color: var(--warning);
    margin-left: 6px;
    font-style: italic;
}

.deck-code-area {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--border);
}

.deck-code-row {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.deck-code-text {
    flex: 1;
    font-size: 11px;
    font-family: var(--font-mono);
    color: var(--text-dim);
    word-break: break-all;
    min-width: 0;
}

.btn-copy-code.copied { background: var(--success); border-color: var(--success); }
.btn-save-deck { background: var(--bg-hover); border: 1px solid var(--border); color: var(--text-muted); }
.btn-save-deck:hover { border-color: var(--accent); color: var(--text); }
.btn-save-deck.saved { color: var(--success); border-color: var(--success); }

.deck-code-loading { font-size: 11px; }

.deck-meta-row {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    margin-top: 4px;
    font-size: 11px;
}

.deck-dust { color: var(--warning); }

.deck-warning {
    padding: 4px 8px;
    margin-bottom: 6px;
    background: rgba(251, 191, 36, 0.1);
    border: 1px solid rgba(251, 191, 36, 0.3);
    border-radius: 4px;
    color: var(--warning);
    font-size: 11px;
    font-weight: 600;
}

.deck-padded { color: var(--warning); }

.deck-missing {
    color: var(--danger);
}

/* Greeting message */
.msg-greeting .msg-bubble {
    background: linear-gradient(135deg, var(--bg-card), rgba(167,139,250,0.08));
    border-color: var(--accent-dim);
}

/* Typing indicator */
.typing-indicator span {
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-muted);
    margin: 0 2px;
    animation: bounce 1.2s infinite;
}
.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes bounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-6px); }
}

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

/* === Chat Input === */
.chat-input-wrap {
    padding: 12px 24px 20px;
    background: var(--bg-darkest);
    border-top: 1px solid var(--border);
}

.chat-form {
    display: flex;
    gap: 8px;
    align-items: flex-end;
    max-width: 800px;
    margin: 0 auto;
}

.chat-input {
    flex: 1;
    padding: 10px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    color: var(--text);
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.5;
    resize: none;
    outline: none;
    max-height: 150px;
    transition: border-color 0.15s;
}
.chat-input:focus { border-color: var(--accent); }
.chat-input::placeholder { color: var(--text-dim); }

.btn-send {
    width: 40px;
    height: 40px;
    padding: 0;
    border-radius: 50%;
    flex-shrink: 0;
}

/* === Scrollbar === */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-light); }

/* === Rate limit overlay === */
.rate-limit-msg {
    text-align: center;
    padding: 16px;
    background: rgba(251, 191, 36, 0.08);
    border: 1px solid rgba(251, 191, 36, 0.2);
    border-radius: var(--radius);
    color: var(--warning);
    font-size: 13px;
    margin: 8px 24px;
}

/* === Mobile === */

/* ── Tablet + phone (≤768px) ──────────────────────────── */
@media (max-width: 768px) {
    /* Old sidebar not used in thread layout */
    .sidebar, .sidebar-backdrop { display: none !important; }
    #sidebar-toggle { display: none; }

    /* Messages use more of the screen width */
    .msg { max-width: 95%; }

    /* Safe-area-aware input padding.
       The override at the bottom of this file uses env() correctly;
       this rule must NOT clobber it. */
    .chat-input-wrap {
        padding: 8px 12px max(12px, env(safe-area-inset-bottom));
    }

    /* Prevent iOS Safari auto-zoom when tapping into textarea */
    .chat-input { font-size: 16px; }
}

/* ── Phone (≤480px) ───────────────────────────────────── */
@media (max-width: 480px) {
    /* Respect notch / Dynamic Island side insets */
    .thread-topbar {
        padding-left: max(6px, env(safe-area-inset-left));
        padding-right: max(6px, env(safe-area-inset-right));
    }

    /* Contacts modal: respect status-bar notch */
    .contacts-topbar {
        padding-top: max(14px, env(safe-area-inset-top));
    }

    /* Card picker mobile overrides */
    .card-picker-box { padding: 20px 16px; }
    .pick-card-face  { font-size: 28px; }
    .card-picker-title     { font-size: 15px; }
    .card-picker-dc        { font-size: 13px; }
    .card-picker-dc-num    { font-size: 24px; }
    .card-picker-equip,
    .card-picker-guaranteed { font-size: 12px; }

    /* Action buttons: 2-column grid instead of 4 */
    .action-grid .action-btn {
        flex: 1 1 calc(50% - 6px);
        min-width: 0;
    }

    /* Music controls: collapse to transport only; hide track name + Play Favs */
    .music-favs-btn    { display: none; }
    .music-now-playing { max-width: 72px; font-size: 9px; }
    .music-btn         { padding: 6px 7px; min-width: 30px; min-height: 30px; }

    /* Character sheet: full-width bottom sheet on phones */
    .char-sheet-panel {
        max-width: 100%;
        border-radius: 20px 20px 0 0;
    }
}

/* ── Contacts modal: slide up from bottom ─────────────── */
.contacts-modal:not([hidden]) {
    animation: contactsSlideUp 0.28s cubic-bezier(0.32, 0.72, 0, 1);
}
@keyframes contactsSlideUp {
    from { transform: translateY(100%); }
    to   { transform: translateY(0); }
}

/* ── Belt & Stash ─────────────────────────────────────── */
.char-belt { margin-top: 8px; }

.char-stash-row { margin-top: 8px; }

.char-stash-btn {
    width: 100%;
    text-align: center;
    justify-content: center;
}

/* ── Stash Modal ──────────────────────────────────────── */
.stash-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.8);
    z-index: 1000;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 40px 20px;
    overflow-y: auto;
}
.stash-modal-overlay[hidden] { display: none; }

.stash-modal {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 560px;
}

.stash-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px 16px;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    background: var(--bg-secondary);
    z-index: 1;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}
.stash-modal-header h2 { font-size: 18px; font-weight: 700; color: var(--accent); margin: 0; }

.stash-modal-body {
    padding: 20px 24px;
    max-height: calc(90vh - 80px);
    overflow-y: auto;
}

.stash-section { margin-bottom: 20px; }
.stash-section:last-child { margin-bottom: 0; }

.stash-item-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 0;
    border-bottom: 1px solid var(--border);
}
.stash-item-row:last-child { border-bottom: none; }

.stash-item-name {
    flex: 1;
    font-size: 13px;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.stash-item-actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

.stash-empty {
    color: var(--text-muted);
    font-size: 13px;
    text-align: center;
    padding: 32px 0;
    font-style: italic;
}

.stash-sold-note {
    background: var(--bg-hover);
    border: 1px solid var(--accent-dim);
    border-radius: var(--radius);
    color: var(--accent);
    font-size: 12px;
    padding: 6px 10px;
    margin-bottom: 12px;
    text-align: center;
}

/* Quality colors */
.quality-low    { color: var(--text-muted); }
.quality-average { color: var(--text); }
.quality-good   { color: #4ade80; }
.quality-amazing { color: #60a5fa; }
.quality-godly  { color: #f59e0b; }

/* ── Advisor Picker Modal ─────────────────────────────── */
.advisor-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.8);
    z-index: 1000;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 40px 20px;
    overflow-y: auto;
}
.advisor-modal-overlay[hidden] { display: none; }

.advisor-modal {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 960px;
}

.advisor-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px 16px;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    background: var(--bg-secondary);
    z-index: 1;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}
.advisor-modal-header h2 { font-size: 18px; font-weight: 700; color: var(--accent); margin: 0; }

.btn-modal-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 18px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: var(--radius);
    line-height: 1;
}
.btn-modal-close:hover { color: var(--text); background: var(--bg-hover); }

.advisor-modal-body { padding: 24px; }

.advisor-modal .advisor-section { margin-bottom: 32px; }
.advisor-modal .advisor-section:last-child { margin-bottom: 0; }

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

.advisor-modal .advisor-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 16px 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
    color: inherit;
    position: relative;
}
.advisor-modal .advisor-card:hover {
    border-color: var(--accent-dim);
    background: var(--bg-hover);
    transform: translateY(-2px);
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}
.advisor-modal .advisor-card.selected {
    border-color: var(--accent);
    box-shadow: 0 0 16px var(--accent-glow);
}
.advisor-modal .advisor-card .selected-badge {
    position: absolute;
    top: 6px; right: 6px;
    width: 20px; height: 20px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    display: none;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 700;
}
.advisor-modal .advisor-card.selected .selected-badge { display: flex; }
.advisor-modal .advisor-avatar-wrap {
    width: 64px; height: 64px;
    border-radius: 50%;
    overflow: hidden;
    border: 2px solid var(--border-light);
    background: var(--bg-dark);
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.advisor-modal .advisor-card.selected .advisor-avatar-wrap {
    border-color: var(--accent);
    box-shadow: 0 0 10px var(--accent-glow);
}
.advisor-modal .advisor-avatar { width: 100%; height: 100%; object-fit: cover; }
.advisor-modal .advisor-placeholder { font-size: 24px; color: var(--text-dim); }
.advisor-modal .advisor-info { text-align: center; }
.advisor-modal .advisor-name { display: block; font-weight: 600; font-size: 14px; margin-bottom: 2px; }
.advisor-modal .advisor-title { display: block; font-size: 11px; color: var(--text-muted); font-style: italic; }
.advisor-modal .advisor-class-badge {
    display: inline-block;
    padding: 2px 6px;
    background: var(--bg-dark);
    border: 1px solid var(--border);
    border-radius: 99px;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
}
.advisor-modal .advisor-catchphrase {
    font-size: 11px; color: var(--text-dim); font-style: italic;
    text-align: center; line-height: 1.4;
}
.advisor-modal .advisor-philosophy { display: none; font-size: 10px; color: var(--text-dim); text-align: center; line-height: 1.4; }
.advisor-modal .advisor-card:hover .advisor-philosophy { display: block; }
.advisor-modal .advisor-card:hover .advisor-catchphrase { display: none; }

/* ── Avatar Picker Overlay ──────────────────────────────── */
.avatar-picker-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.92);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.avatar-picker-overlay[hidden] { display: none; }
.avatar-picker-container {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 28px 24px 24px;
    max-width: 560px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 16px;
}
.avatar-picker-close {
    position: absolute;
    top: 12px;
    right: 14px;
}
.avatar-picker-title {
    font-size: 20px;
    font-weight: 700;
    margin: 0;
    text-align: center;
    color: var(--text);
}
.avatar-picker-subtitle {
    font-size: 13px;
    color: var(--text-muted);
    text-align: center;
    margin: 0;
}
.avatar-picker-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 10px;
}
.avatar-picker-item {
    cursor: pointer;
    border-radius: var(--radius);
    border: 2px solid var(--border);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-bottom: 6px;
    transition: border-color 0.15s, box-shadow 0.15s;
    background: var(--bg-dark);
}
.avatar-picker-item:hover {
    border-color: var(--text-muted);
}
.avatar-picker-item.selected {
    border-color: var(--accent);
    box-shadow: 0 0 8px var(--accent-glow);
}
.avatar-picker-item img {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    display: block;
}
.avatar-picker-label {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 4px;
    text-align: center;
}
.avatar-picker-confirm {
    width: 100%;
    margin-top: 4px;
}

/* ── Bubble tints ───────────────────────────────────────── */
.msg-tint-success .msg-bubble {
    background: rgba(0, 90, 40, 0.35);
    border-color: rgba(0, 160, 70, 0.35);
}
.msg-tint-failure .msg-bubble {
    background: rgba(100, 0, 0, 0.35);
    border-color: rgba(180, 0, 0, 0.35);
}
.msg-tint-encounter .msg-bubble {
    background: rgba(70, 0, 110, 0.35);
    border-color: rgba(140, 0, 200, 0.35);
}

/* ── Adventure mode — ghost bubbles + beast-left layout ─── */
#chat-messages.adventure-active .msg-assistant .msg-avatar {
    display: none;
}
#chat-messages.adventure-active .msg-assistant .msg-bubble {
    background: rgba(0, 0, 0, 0.50) !important;
    border-color: rgba(255, 255, 255, 0.10) !important;
    color: #f0f0f0;
    text-shadow: 0 1px 4px rgba(0, 0, 0, 0.95);
}
#chat-messages.adventure-active .msg-user .msg-bubble {
    background: rgba(20, 50, 20, 0.45) !important;
    color: #fff;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.85);
}
/* Beast video floats left; text + buttons wrap to the right */
#chat-messages.adventure-active .inline-npc-media {
    float: left;
    display: block;
    width: 42%;
    max-width: 180px;
    margin: 0 12px 8px 0;
    border-radius: 8px;
}
#chat-messages.adventure-active .msg-bubble {
    overflow: hidden;
}

/* ── Scene background bubbles (adventure challenges) ────── */
.msg-bubble.has-scene-bg {
    overflow: hidden;
    padding: 0;
    border-color: rgba(255, 255, 255, 0.08) !important;
}

/* Fixed-aspect landscape image header — always 16:7 regardless of source image shape */
.scene-bg-header {
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 7;
    overflow: hidden;
}

.scene-bg-video,
.scene-bg-img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center top;
    z-index: 0;
    border-radius: 0;
}

.scene-bg-overlay {
    position: absolute;
    inset: 0;
    background: linear-gradient(
        to bottom,
        rgba(10, 12, 18, 0.05) 40%,
        rgba(10, 12, 18, 0.88) 100%
    );
    z-index: 1;
}

.has-scene-bg .bubble-content {
    position: relative;
    z-index: 2;
    padding: 10px 14px;
}

/* ── NPC thumbnail portrait (Lilith farewell bubbles) ───── */
.npc-thumb {
    width: 48px;
    height: 48px;
    object-fit: cover;
    border-radius: 50%;
    border: 2px solid rgba(140, 0, 200, 0.5);
    float: left;
    margin: 0 12px 8px 0;
    shape-outside: circle();
}

/* ═══════════════════════════════════════════════════════════
   PHASE A — Thread Chat Layout (mobile-first messaging UI)
   ══════════════════════════════════════════════════════════ */

/* App screen: full-height flex column, no overflow */
#app-screen {
    overflow: hidden;
}

/* ── Thread top bar ──────────────────────────────────────── */
.thread-topbar {
    height: 60px;
    display: flex;
    align-items: center;
    padding: 0 6px;
    background: var(--bg-dark);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    position: relative;
    z-index: 10;
}

.topbar-btn {
    background: none;
    border: none;
    color: var(--accent);
    font-size: 22px;
    cursor: pointer;
    padding: 0;
    border-radius: var(--radius);
    line-height: 1;
    flex-shrink: 0;
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.topbar-btn:hover { background: var(--bg-hover); }
.topbar-back { font-size: 26px; }

.topbar-center {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    min-width: 0;
    overflow: hidden;
}

.topbar-npc-avatar-wrap {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    overflow: hidden;
    border: 2px solid var(--accent);
    box-shadow: 0 0 10px var(--accent-glow);
    flex-shrink: 0;
    transition: border-color 0.3s, box-shadow 0.3s;
}

.topbar-npc-avatar {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.topbar-npc-info {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.topbar-npc-name {
    font-weight: 700;
    font-size: 15px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.topbar-npc-title {
    font-size: 11px;
    color: var(--text-muted);
    font-style: italic;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ── Thread body: fills remaining height, clips overflow ─── */
.thread-body {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    position: relative;
    min-height: 0;
}

.thread-body .chat-messages {
    padding: 12px;
    gap: 12px;
}

/* ── Pinned player card (above composer) ─────────────────── */
.pinned-player-card {
    background: var(--bg-dark);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

.pinned-collapsed {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    cursor: pointer;
    user-select: none;
    min-height: 48px;
}
.pinned-collapsed:hover { background: var(--bg-hover); }
.pinned-collapsed:active { background: var(--bg-card); }

.pinned-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--accent-dim);
    flex-shrink: 0;
    background: var(--bg-hover);
}

.pinned-stats-row {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    flex-wrap: wrap;
    min-width: 0;
}

.pinned-stat { color: var(--text-muted); white-space: nowrap; }
.pinned-hp-val  { color: var(--danger); font-weight: 700; }
.pinned-gold-val { color: #D4A017; font-weight: 700; }
.pinned-level-val { color: var(--accent); font-weight: 700; }
.pinned-divider { color: var(--border-light); }

.pinned-effects { display: flex; gap: 3px; align-items: center; flex-wrap: nowrap; }
.pinned-effect { font-size: 11px; line-height: 1; cursor: default; }
.pinned-effect-neg { filter: drop-shadow(0 0 2px rgba(220,50,50,0.5)); }
.pinned-effect-pos { filter: drop-shadow(0 0 2px rgba(80,180,80,0.5)); }

.pinned-chevron {
    color: var(--text-dim);
    font-size: 16px;
    flex-shrink: 0;
    transition: transform 0.2s;
}
.pinned-player-card.expanded .pinned-chevron { transform: rotate(180deg); }

.pinned-expanded {
    border-top: 1px solid var(--border);
    padding: 12px;
    max-height: 55vh;
    overflow-y: auto;
}

/* ── Quick actions bar (persistent NPC service chips) ────── */
.quick-actions-bar {
    display: flex;
    flex-direction: row;
    gap: 8px;
    padding: 8px 12px;
    overflow-x: auto;
    background: var(--bg-dark);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
    scrollbar-width: none;
}
.quick-actions-bar::-webkit-scrollbar { display: none; }

.quick-action-btn {
    display: inline-flex;
    align-items: center;
    padding: 6px 16px;
    border: 1.5px solid var(--btn-color, var(--advisor-accent, var(--accent-dim)));
    border-radius: 99px;
    background: none;
    color: var(--btn-color, var(--text));
    font-family: var(--font);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    flex-shrink: 0;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.quick-action-btn:hover {
    background: var(--btn-color, var(--advisor-accent, var(--accent)));
    color: var(--bg-dark);
    border-color: var(--btn-color, var(--advisor-accent, var(--accent)));
}
.quick-action-btn:active { opacity: 0.8; }

/* ── Adventure Block Toast ───────────────────────────────── */
.adventure-block-toast {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%) translateY(12px);
    background: rgba(20, 10, 5, 0.92);
    border: 1px solid rgba(220, 120, 30, 0.5);
    color: #f5c580;
    font-size: 0.9rem;
    font-style: italic;
    padding: 12px 20px;
    border-radius: 12px;
    max-width: 320px;
    text-align: center;
    opacity: 0;
    transition: opacity 0.3s ease, transform 0.3s ease;
    z-index: 9998;
    pointer-events: none;
}
.adventure-block-toast--visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ── Abandon Adventure Dialog ────────────────────────────── */
/* ── Card Picker ─────────────────────────────────────────── */
.card-picker-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.78);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9000;
    opacity: 0;
    transition: opacity 0.25s ease;
    padding: 20px;
}
.card-picker-overlay.active { opacity: 1; }

.card-picker-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    max-width: 480px;
    width: 100%;
}
.card-picker-header { text-align: center; }
.card-picker-title {
    font-size: 16px;
    color: #e0d8ff;
    margin-bottom: 6px;
    text-shadow: 0 1px 6px rgba(0,0,0,0.8);
}
.card-picker-dc {
    font-size: 14px;
    color: #a89fc0;
    margin-top: 6px;
    text-shadow: 0 1px 4px rgba(0,0,0,0.8);
}
.card-picker-dc-num {
    font-size: 28px;
    font-weight: bold;
    color: #4ade80;
    text-shadow: 0 0 12px rgba(74, 222, 128, 0.6), 0 1px 4px rgba(0,0,0,0.9);
    line-height: 1;
    vertical-align: middle;
}
.card-picker-hint {
    font-size: 12px;
    color: rgba(255,255,255,0.4);
    letter-spacing: 0.05em;
    text-transform: uppercase;
    transition: opacity 0.3s;
}
/* Mobile-first: 2×3 portrait grid. Switches to single flex row only on clear desktop widths. */
.card-picker-cards {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    width: 100%;
}
@media (min-width: 900px) {
    .card-picker-cards {
        display: flex;
        flex-wrap: nowrap;
        justify-content: center;
        gap: 12px;
        width: auto;
        overflow-x: auto;
    }
}

/* Individual card — mobile-first: height fills viewport, aspect-ratio derives width */
.pick-card {
    height: clamp(100px, calc((100dvh - 220px) / 3), 240px);
    aspect-ratio: 2 / 3;
    width: auto;
    justify-self: center;
    perspective: 600px;
    cursor: pointer;
    flex-shrink: 0;
}
@media (min-width: 900px) {
    /* Desktop: fill available width across 6 cards, max out at 300px wide each */
    .pick-card {
        width: clamp(110px, calc((95vw - 60px) / 6), 300px);
        height: auto;
        aspect-ratio: 2 / 3;
        justify-self: unset;
        flex-shrink: 0;
    }
}
.pick-card-inner {
    width: 100%;
    height: 100%;
    position: relative;
    transform-style: preserve-3d;
    transition: transform 0.45s ease;
    border-radius: 8px;
}
.pick-card.flipped .pick-card-inner { transform: rotateY(180deg); }

.pick-card-back,
.pick-card-face {
    position: absolute;
    inset: 0;
    border-radius: 8px;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}
.pick-card-back {
    background-image: var(--card-back-url, url('/static/images/cards/back_deck_default.png'));
    background-size: cover;
    background-position: center;
    background-color: #1a1040;
    box-shadow: 0 4px 16px rgba(0,0,0,0.5);
}
.pick-card-face {
    background: linear-gradient(160deg, #2a2040 0%, #1a1530 100%);
    border: 1px solid rgba(200, 180, 255, 0.25);
    box-shadow: 0 4px 16px rgba(0,0,0,0.5);
    transform: rotateY(180deg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 36px;
    font-weight: 700;
    color: #e8e0ff;
    text-shadow: 0 0 12px rgba(139, 92, 246, 0.6);
}
.pick-card.chosen .pick-card-face {
    background: linear-gradient(160deg, #3d2f70 0%, #2a2060 100%);
    border-color: rgba(139, 92, 246, 0.7);
    box-shadow: 0 0 20px rgba(139, 92, 246, 0.4), 0 4px 16px rgba(0,0,0,0.5);
}
.pick-card:not(.flipped):hover .pick-card-inner {
    transform: translateY(-6px);
    box-shadow: 0 10px 24px rgba(139, 92, 246, 0.3);
}
.card-picker-equip {
    font-size: 13px;
    color: #b8e0a0;
    margin-top: 4px;
    text-shadow: 0 1px 4px rgba(0,0,0,0.8);
}
.card-picker-guaranteed {
    font-size: 13px;
    color: #ffd700;
    margin-top: 6px;
    font-style: italic;
    text-shadow: 0 1px 6px rgba(0,0,0,0.9);
}
.card-picker-impossible {
    font-size: 14px;
    color: #ff6b6b;
    margin-top: 12px;
    font-style: italic;
    text-align: center;
    line-height: 1.5;
    text-shadow: 0 1px 6px rgba(0,0,0,0.9);
    padding: 0 8px;
}
.card-picker-ok {
    margin-top: 24px;
    padding: 12px 48px;
    background: linear-gradient(135deg, #3d2f70, #2a2060);
    border: 1px solid rgba(139, 92, 246, 0.6);
    border-radius: 12px;
    color: #e0d8ff;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, box-shadow 0.2s;
}
.card-picker-ok:hover {
    background: linear-gradient(135deg, #4e3d88, #352870);
    box-shadow: 0 0 18px rgba(139, 92, 246, 0.4);
}

/* ── Lilith NPC Context ───────────────────────────────────── */
.chat-area-bg.lilith-bg {
    opacity: 1 !important;
    filter: brightness(1) !important;
    background-size: cover;
    background-position: center top;
}
.chat-area-bg.lilith-bg .chat-bg-video {
    object-fit: cover;
}
.lilith-mode .msg-assistant .msg-avatar { display: none; }
.lilith-mode .msg-assistant .msg-bubble {
    background: rgba(10, 0, 20, 0.22) !important;
    border-color: rgba(150, 50, 220, 0.15) !important;
    color: #f0e8ff;
    text-shadow: 0 1px 4px rgba(0,0,0,0.95);
}
.lilith-mode .msg-user .msg-bubble {
    background: rgba(80, 20, 120, 0.32) !important;
    color: #fff;
    text-shadow: 0 1px 3px rgba(0,0,0,0.85);
}
.lilith-mode .action-btn {
    background: rgba(15, 5, 30, 0.65) !important;
    border-color: rgba(150, 50, 220, 0.6) !important;
    text-shadow: 0 1px 2px rgba(0,0,0,0.8);
}

.abandon-dialog-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.72);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}
.abandon-dialog-box {
    background: var(--bg-card, #1a1a2e);
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 16px;
    padding: 28px 24px 20px;
    max-width: 340px;
    width: 90%;
    box-shadow: 0 8px 40px rgba(0,0,0,0.6);
    text-align: center;
}
.abandon-dialog-msg {
    font-size: 0.95rem;
    line-height: 1.55;
    color: var(--text-secondary, #ccc);
    margin-bottom: 20px;
}
.abandon-dialog-btns {
    display: flex;
    gap: 10px;
    justify-content: center;
}
.abandon-btn-no, .abandon-btn-yes {
    flex: 1;
    padding: 10px 14px;
    border-radius: 10px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    border: 1.5px solid;
    transition: background 0.15s, color 0.15s;
}
.abandon-btn-no {
    background: transparent;
    color: #4ade80;
    border-color: #4ade80;
}
.abandon-btn-no:hover { background: #4ade80; color: #0a0a0a; }
.abandon-btn-yes {
    background: transparent;
    color: #f87171;
    border-color: #f87171;
}
.abandon-btn-yes:hover { background: #f87171; color: #0a0a0a; }
.abandon-btn-yes:disabled { opacity: 0.35; cursor: not-allowed; border-color: #6b7280; color: #6b7280; }
.abandon-btn-yes:disabled:hover { background: transparent; color: #6b7280; }

/* ── Advisor hotlinks (inline NPC name → switch context) ─── */
.advisor-link {
    color: var(--advisor-accent, var(--accent));
    text-decoration: underline;
    cursor: pointer;
    font-weight: 600;
    background: none;
    border: none;
    padding: 0;
}
.advisor-link:hover { opacity: 0.75; }

/* Safe-area bottom padding for chat input — applied globally so notch phones
   always get the right inset regardless of screen width. The mobile media query
   also sets this; having it here ensures it wins on all viewports. */
.chat-input-wrap {
    padding-bottom: max(12px, env(safe-area-inset-bottom));
    flex-shrink: 0;
}

.chat-form { max-width: 100%; }

/* ── Contacts modal (iOS-style contacts picker) ──────────── */
.contacts-modal {
    position: fixed;
    inset: 0;
    z-index: 500;
    background: var(--bg-darkest);
    display: flex;
    flex-direction: column;
}

.contacts-screen {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

.contacts-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-dark);
    flex-shrink: 0;
}

.contacts-cancel, .contacts-done {
    background: none;
    border: none;
    color: var(--accent);
    font-size: 15px;
    font-family: var(--font);
    cursor: pointer;
    padding: 4px 0;
    min-width: 60px;
}
.contacts-cancel { text-align: left; }
.contacts-done   { text-align: right; }
.contacts-cancel:hover, .contacts-done:hover { opacity: 0.7; }

.contacts-title {
    font-weight: 700;
    font-size: 17px;
    color: var(--text);
}

.contacts-search-wrap {
    padding: 10px 16px;
    background: var(--bg-dark);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.contacts-search {
    width: 100%;
    padding: 8px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 20px;
    color: var(--text);
    font-size: 14px;
    font-family: var(--font);
    outline: none;
}
.contacts-search:focus { border-color: var(--accent); }
.contacts-search::placeholder { color: var(--text-dim); }

.contacts-section-label {
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--text-dim);
    padding: 12px 16px 6px;
}

.contacts-list {
    flex: 1;
    overflow-y: auto;
    padding-bottom: 80px;
}

.contact-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background 0.15s;
}
.contact-row:hover { background: var(--bg-hover); }
.contact-row.contact-active { background: rgba(167, 139, 250, 0.08); }

.contact-avatar-wrap {
    position: relative;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    overflow: hidden;
    border: 2px solid var(--border-light);
    flex-shrink: 0;
    background: var(--bg-hover);
    display: flex;
    align-items: center;
    justify-content: center;
}
.contact-row.contact-active .contact-avatar-wrap {
    border-color: var(--accent);
    box-shadow: 0 0 8px var(--accent-glow);
}
.contact-avatar { width: 100%; height: 100%; object-fit: cover; }

.contact-info { flex: 1; min-width: 0; }
.contact-name  { display: block; font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.contact-title { display: block; font-size: 12px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.contact-checkmark { color: var(--accent); font-size: 18px; font-weight: 700; }
.contact-passive-msg { color: #c084fc !important; font-style: italic; }
.contact-passive-dot {
    position: absolute;
    bottom: 2px; right: 2px;
    width: 10px; height: 10px;
    border-radius: 50%;
    background: #c084fc;
    border: 2px solid var(--bg-mid);
}

.contact-star {
    background: none;
    border: none;
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    color: var(--border-light);
    padding: 4px 6px;
    flex-shrink: 0;
    transition: color 0.15s, transform 0.15s;
}
.contact-star:hover      { color: var(--warning); transform: scale(1.25); }
.contact-star.contact-star-on { color: var(--warning); }

.contacts-pinned-card {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    padding-bottom: max(10px, env(safe-area-inset-bottom));
    background: var(--bg-dark);
    border-top: 1px solid var(--border);
    z-index: 10;
}

/* ── Hamburger menu panel (slides from right) ────────────── */
.menu-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 400;
}

.menu-panel {
    position: fixed;
    inset: 0;
    z-index: 401;
}

.menu-panel-inner {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: min(320px, 88vw);
    background: var(--bg-dark);
    border-left: 1px solid var(--border);
    overflow-y: auto;
    padding-bottom: env(safe-area-inset-bottom);
}

.menu-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    background: var(--bg-dark);
    z-index: 1;
}

.menu-panel-title { font-size: 18px; font-weight: 700; }

.menu-section { padding: 14px 16px; }

.menu-section-title {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-dim);
    margin-bottom: 10px;
}

/* ── Pinned card rows ─────────────────────────────────── */
.pinned-stats-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 7px 12px;
    cursor: pointer;
    user-select: none;
}
.pinned-stats-bar:hover { background: var(--bg-hover); }

.pinned-media-row {
    display: flex;
    align-items: center;
    gap: 2px;
    margin-left: auto;
    flex-shrink: 0;
}

.music-btn {
    background: none;
    border: none;
    color: #f97316;
    font-size: 14px;
    cursor: pointer;
    padding: 4px 6px;
    border-radius: var(--radius);
    line-height: 1;
    flex-shrink: 0;
    transition: color 0.15s, background 0.15s;
}
.music-btn:hover { color: #fb923c; background: rgba(249,115,22,0.1); }

.music-now-playing {
    flex: 1;
    font-size: 10px;
    color: #f97316;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
    padding: 0 2px;
}

.music-heart-btn { color: var(--text-dim); }
.music-heart-btn.music-heart-active { color: var(--danger) !important; }
.music-favs-btn.music-favs-active { color: var(--warning) !important; background: rgba(251,191,36,0.12) !important; }

/* ── Dice overlay (centered, shown during roll) ──────── */
.dice-overlay {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 300;
    background: var(--bg-card);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    padding: 12px 24px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.55);
    min-width: 200px;
    pointer-events: none;
}

/* ── Character Sheet Modal ──────────────────────────── */
.char-sheet-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    z-index: 500;
    display: flex;
    align-items: flex-end;
    justify-content: center;
}

.char-sheet-panel {
    width: 100%;
    max-width: 480px;
    background: var(--bg-dark);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    max-height: 88vh;
    overflow-y: auto;
    padding-bottom: env(safe-area-inset-bottom);
    position: relative;
}

.char-sheet-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    background: var(--bg-dark);
    z-index: 1;
}
.char-sheet-topbar-title { font-size: 17px; font-weight: 700; }

.char-sheet-panel .char-header { padding: 14px 16px 8px; }
.char-sheet-panel .char-health-row { padding: 0 16px; margin-bottom: 6px; }
.char-sheet-panel .char-level-row { padding: 0 16px 4px; margin-bottom: 6px; }
.char-sheet-panel .char-stat-points { padding: 0 16px 4px; }
.char-sheet-panel .char-stats-line { padding: 0 16px 4px; }
.char-sheet-panel .char-status-effects { padding: 0 16px 8px; border-top: none; margin-top: 0; }

.char-section-label {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-dim);
    padding: 10px 16px 6px;
    border-top: 1px solid var(--border);
    margin-top: 4px;
}
.char-sheet-panel .char-inventory { padding: 0 16px 8px; }
.char-sheet-panel .char-inventory .char-section-label { padding-left: 0; }

/* ── Equipment Grid ─────────────────────────────────── */
.equip-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    padding: 4px 16px 12px;
}
.equip-slot-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px 10px;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
    min-height: 56px;
    display: flex;
    flex-direction: column;
    gap: 3px;
}
.equip-slot-card:hover { border-color: var(--accent-dim); background: var(--bg-hover); }
.equip-slot-label {
    font-size: 9px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-dim);
    font-weight: 600;
}
.equip-slot-name {
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.equip-slot-bonus { font-size: 10px; color: var(--accent); }
.equip-slot-empty-label { color: var(--text-dim); font-size: 11px; font-style: italic; }

/* Item quality colours */
.quality-common    { color: var(--text-muted); }
.quality-uncommon  { color: #4ADE80; }
.quality-rare      { color: #60a5fa; }
.quality-epic      { color: var(--accent); }
.quality-legendary { color: #D4A017; }

/* ── Slot Picker ─────────────────────────────────────── */
.slot-picker-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.7);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    display: flex;
    align-items: flex-end;
    z-index: 2;
}
.slot-picker-panel {
    width: 100%;
    background: var(--bg-dark);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    max-height: 60vh;
    overflow-y: auto;
    padding-bottom: env(safe-area-inset-bottom);
}
.slot-picker-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    background: var(--bg-dark);
}
.slot-picker-title { font-size: 15px; font-weight: 700; }
.slot-picker-items { padding: 4px 0 12px; }
.slot-picker-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    transition: background 0.1s;
    gap: 8px;
}
.slot-picker-item:hover { background: var(--bg-hover); }
.slot-picker-item:last-child { border-bottom: none; }
.slot-picker-item-name { font-size: 14px; font-weight: 600; flex: 1; }
.slot-picker-item-bonus { font-size: 12px; color: var(--accent); flex-shrink: 0; }
.slot-picker-item-equipped { font-size: 11px; color: var(--success); margin-left: 6px; }
.slot-picker-empty {
    padding: 24px 16px;
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
    line-height: 1.6;
}

/* ── Char stash row ─────────────────────────────────── */
.char-stash-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px;
    font-size: 13px;
    color: var(--text-muted);
}

/* ── Contacts player row ─────────────────────────────── */
.contacts-player-row {
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    background: rgba(167,139,250,0.05);
}
.contacts-player-row:hover { background: var(--bg-hover); }

.menu-divider { height: 1px; background: var(--border); }

/* ── Lilith social feed ──────────────────────────────── */
.lilith-feed {
    padding: 4px 16px 20px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.lilith-dm-bubble-wrap {
    display: flex;
    align-items: flex-end;
    gap: 8px;
}
.lilith-dm-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    align-self: flex-end;
}
.lilith-dm-bubble {
    max-width: 78%;
    background: var(--bg-raised);
    border-radius: 18px 18px 18px 4px;
    overflow: hidden;
    border: 1px solid var(--border);
}
.lilith-dm-img {
    width: 100%;
    display: block;
    max-height: 260px;
    object-fit: cover;
}
.lilith-dm-caption {
    padding: 7px 12px 9px;
    font-size: 13px;
    color: var(--text-dim);
    font-style: italic;
    line-height: 1.45;
}

.lilith-post-card {
    border-radius: var(--radius-lg);
    overflow: hidden;
    border: 1px solid var(--border);
    background: var(--bg-raised);
}
.lilith-post-img {
    width: 100%;
    display: block;
    max-height: 320px;
    object-fit: cover;
}
.lilith-post-caption {
    padding: 10px 14px 12px;
    font-size: 13px;
    color: var(--text);
    line-height: 1.5;
}

/* ── Localhost debug panel ───────────────────────────── */
.debug-btn {
    padding: 5px 10px;
    background: #1a0a2e;
    color: #c084fc;
    border: 1px solid #7c3aed;
    border-radius: 6px;
    font-size: 11px;
    cursor: pointer;
    opacity: 0.75;
    white-space: nowrap;
}
.debug-btn:hover { opacity: 1; background: #2d1052; }
