﻿@import url('https://fonts.googleapis.com/css2?family=Merriweather:ital,wght@0,400;0,700;1,400&family=Inter:wght@400;500;600&display=swap');

:root {
    --bg-dark: #0a0a0c;
    --bg-panel: #121214;
    --bg-card: #16161a;
    --bg-input: #242430;
    --border: #2a2a36;
    --border-light: #3a3a4a;
    --text: #e0ddd5;
    --text-dim: #8a8693;
    --text-muted: #5a5666;
    --accent: #c9a84c;
    --accent-dim: #a08530;
    --accent-glow: rgba(201, 168, 76, 0.15);
    --player: #6eb5ff;
    --danger: #e05555;
    --danger-dim: #a03030;
    --success: #55b870;
    --info: #7b8cde;
    --gm-accent: #ff4444;
    --gm-glow: rgba(255, 68, 68, 0.12);
    --scrollbar: #2a2a36;
    --scrollbar-thumb: #4a4a5a;
}

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

html {
    height: 100%;
    overflow: hidden;
    overscroll-behavior: none;
}

body {
    background: var(--bg-dark);
    color: var(--text);
    font-family: 'Inter', sans-serif;
    height: 100%;
    height: 100dvh;
    overflow: hidden;
    overscroll-behavior: none;
    position: fixed;
    inset: 0;
    width: 100%;
}

/* в”Ђв”Ђ Layout в”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђ */

.app {
    display: flex;
    flex-direction: column;
    height: 100%;
    height: 100dvh;
    min-height: 0;
}

.header {
    background: var(--bg-panel);
    border-bottom: 1px solid var(--border);
    padding: 10px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-shrink: 0;
}

.header h1 {
    font-family: 'Merriweather', serif;
    font-size: 18px;
    color: var(--accent);
    letter-spacing: 1px;
}

.header-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.app-tabs {
    display: flex;
    gap: 4px;
    margin-left: 8px;
}
.app-tab {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-dim);
    padding: 4px 12px;
    border-radius: 6px;
    font-size: 12px;
    cursor: pointer;
    font-family: inherit;
}
.app-tab:hover { border-color: var(--border-light); color: var(--text); }
.app-tab.active {
    background: var(--accent-glow);
    border-color: var(--accent-dim);
    color: var(--accent);
}

.app-panel { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-height: 0; }
#rpgApp { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-height: 0; }
#rpgApp > .screen { flex: 1; }

.auth-user-pill {
    font-size: 11px;
    padding: 4px 10px;
    border-radius: 999px;
    background: var(--bg-card);
    color: var(--text-dim);
    border: 1px solid var(--border);
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tokenator-balance-pill {
    font-size: 11px;
    padding: 4px 10px;
    border-radius: 999px;
    background: var(--accent-glow);
    color: var(--accent);
    border: 1px solid var(--accent-dim);
    max-width: 160px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-screen, .tokenator-screen { flex: 1; min-height: 0; display: flex; flex-direction: column; }

.chat-sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    z-index: 40;
}
.chat-sidebar-backdrop.open { display: block; }

.chat-layout {
    display: flex;
    flex: 1;
    min-height: 0;
    position: relative;
}
.chat-sidebar {
    width: 260px;
    flex-shrink: 0;
    border-right: 1px solid var(--border);
    background: #0d0d0f;
    display: flex;
    flex-direction: column;
    padding: 8px;
    gap: 8px;
    z-index: 50;
}
.chat-new-btn { width: 100%; border-radius: 8px; }
.chat-thread-list { flex: 1; overflow-y: auto; min-height: 0; }

.chat-thread-row {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-bottom: 2px;
    border-radius: 8px;
}
.chat-thread-row.active { background: var(--accent-glow); }
.chat-thread-row:hover .chat-thread-del { opacity: 1; }

.chat-thread-item {
    flex: 1;
    min-width: 0;
    padding: 10px 12px;
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-dim);
    text-align: left;
    border-radius: 8px;
    font-family: inherit;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.chat-thread-row.active .chat-thread-item { color: var(--accent); }
.chat-thread-item:hover { color: var(--text); }

.chat-thread-del {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: 6px;
    opacity: 0;
    font-size: 18px;
    line-height: 1;
}
.chat-thread-del:hover { background: rgba(224, 85, 85, 0.2); color: var(--danger); }

.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    background: var(--bg-dark);
}
.chat-topbar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.btn-icon { min-width: 40px; padding: 8px; }
.chat-model-select {
    flex: 1;
    min-width: 0;
    max-width: 420px;
    padding: 8px 10px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg-input);
    color: var(--text);
    font-size: 13px;
}
.chat-model-select:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}
.chat-model-select optgroup,
#cfgModel optgroup {
    font-weight: 600;
    color: var(--accent-dim);
    background: var(--bg-input);
}
.chat-model-select option,
#cfgModel option {
    font-weight: 400;
    color: var(--text);
    padding: 4px 0;
}

.chat-log-wrap {
    flex: 1;
    min-height: 0;
    overflow: hidden;
    position: relative;
}
.chat-log {
    height: 100%;
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
    padding: 16px 16px 32px;
}
.chat-scroll-fab {
    position: absolute;
    right: 16px;
    bottom: 16px;
    z-index: 5;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text);
    box-shadow: 0 4px 16px rgba(0,0,0,0.45);
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
}
.chat-scroll-fab:not([hidden]) { display: flex; align-items: center; justify-content: center; }
.chat-messages-inner {
    max-width: 768px;
    margin: 0 auto;
    width: 100%;
}
.chat-welcome {
    text-align: center;
    padding: 48px 16px;
    color: var(--text-dim);
}
.chat-welcome h3 {
    font-family: 'Merriweather', serif;
    color: var(--text);
    font-size: 22px;
    margin-bottom: 8px;
    font-weight: 400;
}

.chat-msg { margin-bottom: 24px; }
.chat-msg-user { display: flex; justify-content: flex-end; }
.chat-msg-user .chat-msg-body {
    background: var(--bg-input);
    color: var(--text);
    padding: 12px 16px;
    border-radius: 18px 18px 4px 18px;
    max-width: 85%;
    white-space: pre-wrap;
    line-height: 1.55;
    font-size: 15px;
}
.chat-msg-assistant .chat-msg-body {
    color: var(--text);
    line-height: 1.65;
    white-space: pre-wrap;
    font-size: 15px;
}
.chat-msg-error .chat-msg-body { color: var(--danger); }

.chat-composer {
    flex-shrink: 0;
    padding: 12px 16px 16px;
    padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    border-top: 1px solid var(--border);
    background: var(--bg-dark);
    position: relative;
    z-index: 10;
}
.chat-composer-box {
    max-width: 768px;
    margin: 0 auto;
    display: flex;
    border: none;
    padding: 0;
    background: transparent;
    align-items: flex-end;
    gap: 8px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 24px;
    padding: 8px 8px 8px 16px;
    box-shadow: 0 0 0 1px rgba(255,255,255,0.03);
}
.chat-composer-box:focus-within { border-color: var(--border-light); }
.chat-composer-box textarea {
    flex: 1;
    border: none;
    background: transparent;
    color: var(--text);
    resize: none;
    max-height: 200px;
    font-size: 15px;
    line-height: 1.45;
    padding: 6px 0;
    font-family: inherit;
}
.chat-composer-box textarea:focus { outline: none; }
.chat-send-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: var(--accent);
    color: #1a1a1a;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.chat-send-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.chat-send-btn:not(:disabled):hover { filter: brightness(1.08); }

@media (max-width: 768px) {
    .header { padding: 8px 12px; }
    .header h1 { font-size: 15px; }
    .app-tabs { margin-left: 0; max-width: 55vw; overflow-x: auto; flex-wrap: nowrap; }
    .app-tab { padding: 4px 8px; font-size: 11px; white-space: nowrap; }
    .header-actions .btn { padding: 6px 10px; font-size: 12px; }
    .tokenator-balance-pill { display: none !important; }

    .chat-sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        width: min(280px, 88vw);
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        box-shadow: 8px 0 32px rgba(0,0,0,0.5);
    }
    .chat-sidebar.open { transform: translateX(0); }
    #chatMenuBtn { display: inline-flex; }
    .chat-topbar .btn-ghost.btn-sm:last-child { display: none; }
    .chat-model-select { max-width: none; font-size: 12px; }
    .chat-composer { padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px)); }
    .chat-composer-box textarea { font-size: 16px; }
    .chat-send-btn { width: 44px; height: 44px; min-width: 44px; }
    .chat-thread-del { opacity: 1; }
    .chat-topbar { padding-top: max(8px, env(safe-area-inset-top, 0px)); }
    .header { padding-top: max(8px, env(safe-area-inset-top, 0px)); }
}
@media (min-width: 769px) {
    #chatMenuBtn { display: none; }
    .chat-sidebar-backdrop { display: none !important; }
}

.tokenator-panel { max-width: 640px; }
.tokenator-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.tokenator-balance-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 20px 24px;
    margin-bottom: 16px;
}
.tokenator-balance-main {
    font-size: 28px;
    font-weight: 600;
    color: var(--accent);
    font-family: 'Merriweather', serif;
}
.tokenator-balance-row {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
}
.tokenator-raw {
    font-size: 11px;
    color: var(--text-muted);
    max-height: 200px;
    overflow: auto;
    background: var(--bg-card);
    padding: 12px;
    border-radius: 8px;
    border: 1px solid var(--border);
}

.screen { flex: 1; overflow: hidden; }

/* в”Ђв”Ђ Hub Screen в”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђ */

.hub-screen {
    display: flex;
    justify-content: center;
    overflow-y: auto;
    padding: 40px 24px;
}

.hub-container {
    max-width: 800px;
    width: 100%;
}

.hub-title {
    font-family: 'Merriweather', serif;
    font-size: 28px;
    color: var(--accent);
    margin-bottom: 8px;
}

.hub-subtitle {
    color: var(--text-dim);
    margin-bottom: 24px;
    line-height: 1.5;
}

.hub-actions {
    display: flex;
    gap: 10px;
    margin-bottom: 32px;
}

.world-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 16px;
}

.world-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 20px;
    cursor: pointer;
    transition: all 0.2s;
}

.world-card:hover {
    border-color: var(--accent);
    background: var(--accent-glow);
}

.world-card-empty {
    border-style: dashed;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 140px;
}

.world-card-icon {
    font-size: 36px;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.world-card-title {
    font-family: 'Merriweather', serif;
    font-size: 16px;
    color: var(--accent);
    margin-bottom: 6px;
}

.world-card-desc {
    font-size: 13px;
    color: var(--text-dim);
    line-height: 1.4;
    margin-bottom: 10px;
}

.world-card-meta {
    font-size: 11px;
    color: var(--text-muted);
    display: flex;
    gap: 12px;
}

/* в”Ђв”Ђ Character Screen в”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђ */

.char-screen {
    display: flex;
    justify-content: center;
    overflow-y: auto;
    padding: 40px 24px;
}

.char-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 16px;
}

.char-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 18px;
    cursor: pointer;
    transition: all 0.2s;
}

.char-card:hover {
    border-color: var(--accent);
    background: var(--accent-glow);
}

.char-card-name {
    font-family: 'Merriweather', serif;
    font-size: 15px;
    color: var(--accent);
    margin-bottom: 4px;
}

.char-card-info {
    font-size: 12px;
    color: var(--text-dim);
    margin-bottom: 8px;
}

.char-card-stats {
    font-size: 11px;
    color: var(--text-muted);
    display: flex;
    gap: 10px;
}

/* в”Ђв”Ђ Game Screen в”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђ */

.game-screen {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow: hidden;
    position: relative;
}

.game-column {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    min-width: 0;
    overflow: hidden;
    position: relative;
    z-index: 1;
}

.story-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 16px;
    background: var(--bg-panel);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.story-status {
    flex: 1;
    font-size: 12px;
    color: var(--text-dim);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.story-bar-actions { display: flex; gap: 6px; flex-shrink: 0; }

.btn-ghost {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-dim);
}
.btn-ghost:hover { border-color: var(--accent-dim); color: var(--text); }

.mem-badge {
    display: inline-block;
    min-width: 18px;
    padding: 0 5px;
    margin-left: 4px;
    font-size: 10px;
    font-weight: 600;
    background: var(--accent);
    color: var(--bg-dark);
    border-radius: 10px;
}

/* в”Ђв”Ђ Sidebar в”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђ */

.sidebar-left,
.sidebar-right { display: none; }

.drawer-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    z-index: 90;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}
.drawer-backdrop.open { opacity: 1; pointer-events: auto; }

.drawer {
    position: fixed;
    top: 0;
    bottom: 0;
    right: 0;
    left: auto;
    width: min(320px, 92vw);
    max-width: 100%;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    z-index: 100;
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform 0.25s ease;
    box-shadow: -8px 0 32px rgba(0, 0, 0, 0.4);
    pointer-events: none;
}
.drawer.open {
    transform: translateX(0);
    pointer-events: auto;
}
.drawer-memory,
.drawer-lorebook {
    left: 0;
    right: auto;
    transform: translateX(-100%);
    box-shadow: 8px 0 32px rgba(0, 0, 0, 0.4);
}
.drawer-memory.open,
.drawer-lorebook.open { transform: translateX(0); }

.drawer-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
}
.drawer-head h3 {
    font-family: 'Merriweather', serif;
    font-size: 14px;
    color: var(--accent);
    margin: 0;
}
.drawer-close {
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    padding: 0 4px;
}
.drawer-actions { padding: 8px 16px; border-bottom: 1px solid var(--border); }
.drawer-body { flex: 1; overflow-y: auto; }

.memory-empty {
    padding: 16px;
    font-size: 13px;
    color: var(--text-muted);
    font-style: italic;
    line-height: 1.5;
}

.modal-wide { width: min(720px, 96vw); max-height: 90vh; overflow: hidden; display: flex; flex-direction: column; }
.form-group.form-check { margin-bottom: 12px; }
.form-group.form-check label {
    display: flex !important;
    align-items: flex-start;
    gap: 10px;
    font-size: 13px;
    color: var(--text-dim);
    cursor: pointer;
    line-height: 1.45;
    margin-bottom: 0;
}
.form-group.form-check input[type="checkbox"] {
    width: auto;
    margin-top: 3px;
    flex-shrink: 0;
    accent-color: var(--accent);
}
.form-check label, .form-check-inline { font-size: 13px; color: var(--text-dim); cursor: pointer; display: flex; align-items: center; gap: 8px; }
.form-check { margin-bottom: 8px; }

.modal-world-gen { width: min(560px, 96vw); }
.modal-section-title {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    margin: 4px 0 10px;
}
.lorebook-toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.lb-select { flex: 1; min-width: 140px; }
.lorebook-form { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; padding-bottom: 12px; border-bottom: 1px solid var(--border); }
.lb-input { width: 100%; padding: 8px 10px; border-radius: 6px; border: 1px solid var(--border); background: var(--bg-elevated); color: var(--text); font-size: 13px; }
.lorebook-form-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.lb-priority { width: 56px; margin-left: 6px; }
.lorebook-list { max-height: 40vh; overflow-y: auto; margin-bottom: 12px; }
.lorebook-item { padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; margin-bottom: 8px; background: var(--bg-elevated); }
.lorebook-item.disabled { opacity: 0.55; }
.lorebook-item-keys { font-size: 11px; color: var(--accent); margin-bottom: 4px; }
.lorebook-item-actions { margin-top: 8px; display: flex; gap: 6px; flex-wrap: wrap; }
.lorebook-active-title { font-size: 12px; color: var(--accent); padding: 8px 16px 4px; font-weight: 600; }

.sidebar-section {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
}

.sidebar-section h3 {
    font-family: 'Merriweather', serif;
    font-size: 12px;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 8px;
}

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

/* в”Ђв”Ђ Stats в”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђ */

.stat-row { display: flex; justify-content: space-between; padding: 3px 0; font-size: 13px; }
.stat-label { color: var(--text-dim); }
.stat-value { color: var(--text); font-weight: 500; }

.hp-bar { width: 100%; height: 6px; background: var(--bg-input); border-radius: 3px; margin-top: 4px; overflow: hidden; }
.hp-bar-fill { height: 100%; background: linear-gradient(90deg, var(--danger), var(--success)); border-radius: 3px; transition: width 0.5s ease; }

.direction-list { display: flex; flex-direction: column; gap: 4px; }
.direction-btn {
    background: var(--bg-input); border: 1px solid var(--border); color: var(--text);
    padding: 6px 10px; border-radius: 6px; cursor: pointer; font-size: 12px; text-align: left; transition: all 0.2s;
}
.direction-btn:hover { border-color: var(--accent); background: var(--accent-glow); }

.npc-item { padding: 6px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.npc-item:last-child { border-bottom: none; }
.npc-name { color: var(--accent); font-weight: 600; }
.npc-role { color: var(--text-dim); font-size: 12px; }

.memory-item { padding: 6px 16px; font-size: 12px; color: var(--text-dim); border-bottom: 1px solid var(--border); }
.memory-item .mem-cat { color: var(--info); font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; }

.inventory-list { display: flex; flex-wrap: wrap; gap: 4px; }
.inv-item { padding: 3px 8px; background: var(--bg-input); border-radius: 4px; font-size: 12px; color: var(--text-dim); }
.inv-empty { font-size: 12px; color: var(--text-muted); font-style: italic; }

.inv-item-rich {
    background: var(--bg-input); border: 1px solid var(--border); border-radius: 6px;
    padding: 6px 8px; margin-bottom: 4px; width: 100%; font-size: 12px;
}
.inv-item-rich.has-ench { border-left: 3px solid; }
.inv-item-header { display: flex; align-items: center; gap: 4px; }
.inv-type-icon { font-size: 13px; flex-shrink: 0; }
.inv-item-name { font-weight: 500; color: var(--text); flex: 1; }
.inv-ench { font-weight: 700; font-size: 11px; flex-shrink: 0; }
.inv-item-desc { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.inv-effects { display: flex; flex-wrap: wrap; gap: 3px; margin-top: 3px; }
.inv-eff {
    font-size: 10px; padding: 1px 5px; border-radius: 3px;
    background: rgba(201,168,76,0.1); color: var(--accent); border: 1px solid rgba(201,168,76,0.2);
}

.ench-white { color: #ccc; border-left-color: #ccc; }
.ench-green { color: #4ade80; border-left-color: #4ade80; }
.ench-blue { color: #60a5fa; border-left-color: #60a5fa; }
.ench-purple { color: #c084fc; border-left-color: #c084fc; }
.ench-orange { color: #fb923c; border-left-color: #fb923c; }
.ench-red { color: #f87171; border-left-color: #f87171; }

/* в”Ђв”Ђ Main content в”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђ */

.main {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    min-width: 0;
    overflow: hidden;
    background: var(--bg-dark);
}

.game-log {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
    padding: 20px 20px 32px;
    display: flex;
    flex-direction: column;
    gap: 0;
    max-width: 720px;
    width: 100%;
    margin: 0 auto;
}

.message {
    max-width: 100%;
    line-height: 1.75;
    font-size: 15px;
    position: relative;
    margin-bottom: 1.25em;
}

.message-inner {
    position: relative;
    border-radius: 12px;
}

.message-body { min-height: 1em; }

.message-actions {
    position: absolute;
    top: 6px;
    right: 6px;
    display: flex;
    gap: 4px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease;
    z-index: 2;
}

.message:hover .message-actions,
.message:focus-within .message-actions {
    opacity: 1;
    pointer-events: auto;
}

.msg-action-btn {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: rgba(13, 13, 15, 0.75);
    color: var(--text-dim);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: color 0.15s, border-color 0.15s, background 0.15s;
}

.msg-action-btn:hover {
    color: var(--accent);
    border-color: var(--accent-dim);
    background: var(--accent-glow);
}

.msg-action-icon {
    font-size: 14px;
    line-height: 1;
}

.message.user .message-inner {
    color: var(--text-dim);
    padding: 0 0 0 12px;
    border-left: 2px solid var(--player);
    font-family: 'Inter', sans-serif;
    font-size: 14px;
    font-style: italic;
    background: transparent;
    border-radius: 0;
}

.message.user .message-body::before {
    content: 'Вы. ';
    color: var(--player);
    font-style: normal;
    font-weight: 500;
}

.message.user.gm-message .message-inner {
    border-left-color: var(--gm-accent);
    color: var(--gm-accent);
}
.message.user.gm-message .message-body::before { content: 'Абсолют. '; color: var(--gm-accent); }

.message.assistant .message-inner {
    font-family: 'Merriweather', serif;
    font-size: 15px;
    color: var(--text);
    padding: 0;
    background: transparent;
    border-radius: 0;
    border: none;
}

.message.assistant .message-actions { right: 0; top: 0; }

.message.editing .message-actions { display: none !important; }

.message-edit-wrap { display: flex; flex-direction: column; gap: 8px; }

.message-edit-textarea {
    width: 100%;
    min-height: 120px;
    resize: vertical;
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 8px;
    padding: 10px 12px;
    font-family: 'Inter', sans-serif;
    font-size: 14px;
    line-height: 1.5;
    outline: none;
}

.message-edit-textarea:focus { border-color: var(--accent); }

.message-edit-bar {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.btn-sm { padding: 6px 12px; font-size: 12px; border-radius: 6px; }

.message.system-event {
    align-self: center;
    color: var(--text-muted);
    font-size: 12px;
    font-style: italic;
    padding: 4px 0;
    margin-bottom: 0.75em;
    background: transparent;
}

/* в”Ђв”Ђ Input в”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђ */

.input-area {
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0px));
    border-top: 1px solid var(--border);
    background: var(--bg-panel);
    flex-shrink: 0;
}

.generating-hint {
    font-size: 12px;
    color: var(--accent-dim);
    margin-bottom: 8px;
    font-style: italic;
}
.generating-hint[hidden] { display: none !important; }

.input-toolbar {
    display: flex;
    gap: 8px;
    margin-bottom: 8px;
}

.input-area.gm-active { border-top-color: var(--gm-accent); background: rgba(255, 68, 68, 0.05); }

.input-wrapper { display: flex; gap: 10px; align-items: flex-end; }

.input-wrapper textarea {
    flex: 1; background: var(--bg-input); border: 1px solid var(--border); color: var(--text);
    padding: 12px 16px; border-radius: 10px; font-family: 'Inter', sans-serif; font-size: 16px;
    resize: none; min-height: 44px; max-height: 120px; outline: none; transition: border-color 0.2s;
}

.input-wrapper textarea:focus { border-color: var(--accent); }
.input-wrapper textarea::placeholder { color: var(--text-muted); }

.send-btn {
    background: var(--accent); color: var(--bg-dark); border: none;
    width: 44px; height: 44px; border-radius: 10px; cursor: pointer;
    font-size: 18px; font-weight: 700; display: flex; align-items: center;
    justify-content: center; transition: all 0.2s; flex-shrink: 0;
}
.send-btn:hover { background: var(--accent-dim); }
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* в”Ђв”Ђ GM Panel в”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђ */

.gm-panel {
    background: rgba(255, 68, 68, 0.04);
    border-bottom: 1px solid rgba(255, 68, 68, 0.2);
    padding: 12px 24px;
}

.gm-header {
    display: flex; align-items: center; gap: 10px; margin-bottom: 8px;
}

.gm-badge {
    background: var(--gm-accent); color: #fff; font-size: 10px; font-weight: 700;
    padding: 2px 8px; border-radius: 4px; letter-spacing: 1px;
}

.gm-label { color: var(--gm-accent); font-size: 13px; font-weight: 600; flex: 1; }

.gm-switch { position: relative; width: 40px; height: 22px; }
.gm-switch input { opacity: 0; width: 0; height: 0; }
.gm-slider {
    position: absolute; inset: 0; background: var(--bg-input); border-radius: 11px;
    cursor: pointer; transition: 0.2s;
}
.gm-slider::before {
    content: ''; position: absolute; width: 16px; height: 16px; left: 3px; top: 3px;
    background: var(--text-muted); border-radius: 50%; transition: 0.2s;
}
.gm-switch input:checked + .gm-slider { background: var(--gm-accent); }
.gm-switch input:checked + .gm-slider::before { transform: translateX(18px); background: #fff; }

.gm-overrides { margin-bottom: 8px; }
.gm-override-item {
    display: flex; align-items: center; gap: 8px; padding: 4px 0;
    font-size: 12px; color: var(--text-dim);
}
.gm-override-item .remove-btn {
    background: none; border: none; color: var(--danger); cursor: pointer;
    font-size: 14px; padding: 0 4px;
}

.gm-input-row { display: flex; gap: 8px; margin-bottom: 8px; }
.gm-input {
    flex: 1; background: var(--bg-input); border: 1px solid rgba(255,68,68,0.3);
    color: var(--text); padding: 6px 12px; border-radius: 6px; font-size: 13px;
    font-family: 'Inter', sans-serif; outline: none;
}
.gm-input:focus { border-color: var(--gm-accent); }

.btn-gm {
    background: var(--gm-accent); color: #fff; border: none; padding: 6px 12px;
    border-radius: 6px; cursor: pointer; font-weight: 700; font-size: 14px;
}
.btn-gm:hover { background: var(--danger-dim); }

.gm-quick-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.btn-gm-sm {
    background: var(--bg-input); border: 1px solid rgba(255,68,68,0.2); color: var(--gm-accent);
    padding: 4px 10px; border-radius: 4px; cursor: pointer; font-size: 11px;
    font-family: 'Inter', sans-serif; transition: all 0.2s;
}
.btn-gm-sm:hover { background: var(--gm-glow); border-color: var(--gm-accent); }

/* в”Ђв”Ђ Buttons в”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђ */

.btn {
    background: var(--bg-input); color: var(--text); border: 1px solid var(--border);
    padding: 8px 16px; border-radius: 8px; cursor: pointer; font-size: 13px;
    font-family: 'Inter', sans-serif; transition: all 0.2s;
}
.btn:hover { border-color: var(--accent); background: var(--accent-glow); }

.btn-accent { background: var(--accent); color: var(--bg-dark); border-color: var(--accent); font-weight: 600; }
.btn-accent:hover { background: var(--accent-dim); }

.btn-lg { padding: 12px 28px; font-size: 15px; border-radius: 10px; }

/* в”Ђв”Ђ Modal в”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђ */

.modal-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,0.7);
    display: none; align-items: center; justify-content: center; z-index: 100;
}
.modal-overlay.active { display: flex; }

.modal {
    background: var(--bg-panel); border: 1px solid var(--border); border-radius: 16px;
    width: 520px; max-height: 80vh; overflow-y: auto; padding: 28px;
}

.modal h2 { font-family: 'Merriweather', serif; color: var(--accent); margin-bottom: 20px; font-size: 20px; }

.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 13px; color: var(--text-dim); margin-bottom: 6px; }

.form-group input, .form-group select, .form-group textarea {
    width: 100%; background: var(--bg-input); border: 1px solid var(--border); color: var(--text);
    padding: 10px 14px; border-radius: 8px; font-family: 'Inter', sans-serif; font-size: 14px; outline: none;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus { border-color: var(--accent); }

.form-hint { font-size: 11px; color: var(--text-muted); margin-top: 6px; line-height: 1.4; }

.form-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; }

/* в”Ђв”Ђ World Gen Progress в”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђ */

.gen-progress { margin-top: 16px; }
.gen-status { font-size: 13px; color: var(--accent); margin-bottom: 8px; }
.gen-output {
    background: var(--bg-input); border: 1px solid var(--border); border-radius: 8px;
    padding: 12px; font-size: 12px; color: var(--text-dim); max-height: 200px;
    overflow-y: auto; font-family: monospace; white-space: pre-wrap;
}

/* в”Ђв”Ђ Status в”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђ */

.status-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.status-dot.connected { background: var(--success); }
.status-dot.disconnected { background: var(--danger); }

.time-badge {
    display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px;
    background: var(--bg-input); border-radius: 6px; font-size: 12px; color: var(--text-dim);
}

/* в”Ђв”Ђ Scrollbar в”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђ */

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* в”Ђв”Ђ Settings Sliders в”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђ */

.settings-divider { border-top: 1px solid var(--border); margin: 16px 0; }
.settings-section-title {
    font-family: 'Merriweather', serif; font-size: 14px; color: var(--accent);
    margin-bottom: 12px;
}

.slider-group input[type="range"] {
    width: 100%; appearance: none; height: 6px; border-radius: 3px;
    background: var(--bg-input); outline: none; margin-top: 4px;
}
.slider-group input[type="range"]::-webkit-slider-thumb {
    appearance: none; width: 16px; height: 16px; border-radius: 50%;
    background: var(--accent); cursor: pointer;
}

/* в”Ђв”Ђ GM Character Controls в”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђ */

.gm-char-controls, .gm-buff-controls {
    margin-top: 10px; padding-top: 10px; border-top: 1px solid rgba(255,68,68,0.15);
}

.gm-ctrl-title {
    font-size: 11px; color: var(--gm-accent); text-transform: uppercase;
    letter-spacing: 1px; margin-bottom: 6px; font-weight: 600;
}

.gm-ctrl-row {
    display: flex; align-items: center; gap: 6px; margin-bottom: 4px;
}

.gm-ctrl-label { font-size: 12px; color: var(--text-dim); min-width: 50px; }
.gm-ctrl-value { font-size: 14px; color: var(--text); font-weight: 600; min-width: 30px; text-align: center; }

.gm-buff-add-row {
    display: flex; gap: 6px; margin-top: 6px; align-items: center;
}
.gm-buff-add-row select {
    background: var(--bg-input); border: 1px solid rgba(255,68,68,0.3);
    color: var(--text); padding: 4px 8px; border-radius: 6px; font-size: 12px;
    font-family: 'Inter', sans-serif;
}

/* в”Ђв”Ђ Buff / Debuff display в”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђ */

.buff-item {
    display: flex; align-items: center; gap: 6px; padding: 4px 0;
    font-size: 12px; border-bottom: 1px solid var(--border);
}
.buff-item:last-child { border-bottom: none; }

.buff-icon {
    width: 18px; height: 18px; border-radius: 4px; display: flex;
    align-items: center; justify-content: center; font-size: 10px; font-weight: 700;
    flex-shrink: 0;
}
.buff-icon.buff { background: rgba(85,184,112,0.2); color: var(--success); }
.buff-icon.debuff { background: rgba(224,85,85,0.2); color: var(--danger); }

.buff-name { color: var(--text); font-weight: 500; }
.buff-desc { color: var(--text-muted); font-size: 11px; }
.buff-source { font-size: 10px; color: var(--text-muted); opacity: 0.7; }

.gm-buff-item {
    display: flex; align-items: center; gap: 6px; padding: 3px 0; font-size: 12px;
}
.gm-buff-item .remove-btn {
    background: none; border: none; color: var(--danger); cursor: pointer; font-size: 14px; padding: 0 4px;
}

/* в”Ђв”Ђ Delete buttons в”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђ */

.btn-danger {
    background: rgba(224,85,85,0.1); color: var(--danger); border: 1px solid rgba(224,85,85,0.3);
    padding: 4px 10px; border-radius: 6px; cursor: pointer; font-size: 11px;
    font-family: 'Inter', sans-serif; transition: all 0.2s;
}
.btn-danger:hover { background: rgba(224,85,85,0.25); border-color: var(--danger); }

/* в”Ђв”Ђ Responsive в”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђ */

@media (max-width: 1024px) {
    .game-log { padding: 16px 14px 24px; }
    .message { font-size: 15px; }
    .story-bar { padding: 8px 12px; }
}

@media (max-width: 768px) {
    .game-screen { min-height: 0; }

    .story-bar {
        flex-wrap: wrap;
        align-items: flex-start;
        gap: 8px;
        padding: 8px 10px;
    }

    .story-status {
        flex: 1 1 100%;
        white-space: normal;
        line-height: 1.35;
        max-height: 2.7em;
        overflow: hidden;
        font-size: 11px;
    }

    .story-bar-actions {
        flex: 1 1 100%;
        display: flex;
        gap: 6px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }
    .story-bar-actions::-webkit-scrollbar { display: none; }

    .story-bar-actions .btn-sm {
        flex-shrink: 0;
        padding: 7px 10px;
        font-size: 11px;
    }

    .game-log {
        max-width: none;
        padding: 12px 12px 20px;
        flex: 1;
        min-height: 0;
    }

    .message { font-size: 15px; line-height: 1.65; }
    .message.assistant .message-inner { font-size: 15px; }

    .input-area {
        padding: 10px 10px calc(10px + env(safe-area-inset-bottom, 0px));
    }

    .input-wrapper textarea {
        font-size: 16px;
        min-height: 44px;
        padding: 10px 12px;
    }

    .send-btn {
        width: 44px;
        height: 44px;
        min-width: 44px;
        flex-shrink: 0;
    }

    .gm-panel { padding: 10px 12px; max-height: 38vh; overflow-y: auto; }

    .drawer {
        width: 100%;
        max-width: 100%;
        left: 0;
        right: 0;
        top: 0;
        bottom: 0;
        height: 100%;
        max-height: 100dvh;
        padding-top: env(safe-area-inset-top, 0px);
        padding-bottom: env(safe-area-inset-bottom, 0px);
        border-radius: 0;
        z-index: 110;
    }

    .drawer-memory,
    .drawer-lorebook {
        transform: translateX(-100%);
    }

    .drawer-character {
        transform: translateX(100%);
    }

    .drawer-backdrop { z-index: 105; }
}

@media (hover: none) {
    .message .message-actions {
        opacity: 1;
        pointer-events: auto;
    }
}

/* ── Auth pages ─────────────────────────────────────── */

.auth-page {
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px 16px;
    background: var(--bg-dark);
}

.auth-card {
    width: min(400px, 100%);
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 28px 24px;
}

.auth-title {
    font-family: 'Merriweather', serif;
    color: var(--accent);
    font-size: 22px;
    margin-bottom: 8px;
}

.auth-sub {
    font-size: 13px;
    color: var(--text-dim);
    line-height: 1.5;
    margin-bottom: 20px;
}

.auth-form label {
    display: block;
    font-size: 12px;
    color: var(--text-muted);
    margin: 12px 0 6px;
}

.auth-form input {
    width: 100%;
    padding: 10px 12px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg-input);
    color: var(--text);
    font-size: 16px;
}

.auth-submit { width: 100%; margin-top: 20px; }

.auth-error {
    background: rgba(224, 85, 85, 0.12);
    border: 1px solid rgba(224, 85, 85, 0.35);
    color: var(--danger);
    padding: 10px 12px;
    border-radius: 8px;
    font-size: 13px;
    margin-bottom: 12px;
}

.auth-ok {
    background: rgba(85, 184, 112, 0.12);
    border: 1px solid rgba(85, 184, 112, 0.35);
    color: var(--success);
    padding: 10px 12px;
    border-radius: 8px;
    font-size: 13px;
    margin-bottom: 12px;
}

.auth-foot {
    margin-top: 16px;
    text-align: center;
    font-size: 13px;
}

.auth-foot a { color: var(--accent); }

.admin-panel { padding: 16px; max-width: 900px; margin: 0 auto; }
.admin-section { margin-bottom: 24px; }
.admin-section h3 {
    font-size: 14px;
    color: var(--accent);
    margin-bottom: 10px;
}
.admin-user-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-bottom: 8px;
    font-size: 13px;
}
.admin-user-row .meta { flex: 1; min-width: 140px; color: var(--text-dim); }
.admin-perms {
    display: flex;
    flex-wrap: wrap;
    gap: 10px 14px;
    margin-top: 8px;
}
.admin-perm {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--text);
    cursor: pointer;
}
.admin-perm input { accent-color: var(--accent); }
.admin-perm-hint { font-size: 12px; color: var(--accent); }

.impersonation-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    padding: 10px 16px;
    background: rgba(212, 175, 55, 0.12);
    border-bottom: 1px solid var(--accent);
    color: var(--accent);
    font-size: 14px;
}
.impersonation-banner[hidden] { display: none !important; }

/* ── 2026-05-24 fixes: safer remote/mobile layout ─────────────────────── */
.header > div:first-child {
    min-width: 0;
    flex: 1 1 auto;
}
.header h1,
.app-tabs,
.header-actions {
    min-width: 0;
}
.header-actions .btn,
.app-tab {
    white-space: nowrap;
}
.screen,
.app-panel,
.chat-main,
.main,
.game-column {
    min-width: 0;
}
.input-wrapper textarea,
.gm-input,
.lb-input,
.auth-form input,
select,
textarea,
input {
    max-width: 100%;
}
.message-body,
.chat-msg-body,
.world-card-desc,
.char-card-info {
    overflow-wrap: anywhere;
    word-break: break-word;
}
.modal {
    max-width: calc(100vw - 24px);
    max-height: calc(100dvh - 24px);
}
.modal.active {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}
.modal-content,
.modal-wide {
    max-height: calc(100dvh - 32px);
}

@media (max-width: 900px) {
    .header {
        padding: 8px 12px;
        align-items: flex-start;
        flex-wrap: wrap;
        gap: 8px;
    }
    .header > div:first-child {
        width: 100%;
        flex-wrap: wrap;
        gap: 8px !important;
    }
    .header h1 {
        font-size: 16px;
        flex: 0 0 auto;
    }
    .app-tabs {
        flex: 1 1 180px;
        overflow-x: auto;
        padding-bottom: 2px;
        scrollbar-width: none;
    }
    .app-tabs::-webkit-scrollbar { display: none; }
    .header-actions {
        width: 100%;
        justify-content: flex-start;
        overflow-x: auto;
        padding-bottom: 2px;
        scrollbar-width: none;
    }
    .header-actions::-webkit-scrollbar { display: none; }
    .auth-user-pill,
    .tokenator-balance-pill {
        max-width: 44vw;
        flex: 0 0 auto;
    }
}

@media (max-width: 560px) {
    body {
        position: fixed;
        min-width: 320px;
    }
    .header {
        padding-left: calc(10px + env(safe-area-inset-left, 0px));
        padding-right: calc(10px + env(safe-area-inset-right, 0px));
    }
    .app-tab,
    .header-actions .btn,
    .story-bar-actions .btn-sm,
    .input-toolbar .btn-sm {
        padding: 7px 10px;
        min-height: 36px;
    }
    .hub-screen,
    .char-screen {
        padding: 20px 12px;
    }
    .hub-title {
        font-size: 24px;
    }
    .world-grid,
    .char-grid {
        grid-template-columns: 1fr;
    }
    .gm-input-row,
    .gm-buff-add-row,
    .lorebook-toolbar,
    .lorebook-form-row {
        flex-direction: column;
        align-items: stretch;
    }
    .gm-buff-add-row select,
    .gm-buff-add-row input,
    .gm-buff-add-row button,
    .gm-input-row input,
    .gm-input-row button {
        width: 100%;
    }
    .message-actions {
        position: static;
        justify-content: flex-end;
        margin-bottom: 4px;
        opacity: 1;
        pointer-events: auto;
    }
    .msg-action-btn {
        width: 34px;
        height: 34px;
    }
}

/* RPG systems patch: memory and GM inventory controls */
.drawer-actions-stack {
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: stretch;
}

.inline-form {
    display: flex;
    gap: 8px;
    align-items: center;
}

.inline-form input {
    min-width: 0;
    flex: 1;
}

.memory-cat {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.memory-del {
    border: 0;
    border-radius: 999px;
    background: rgba(255,255,255,.08);
    color: var(--muted);
    cursor: pointer;
    width: 22px;
    height: 22px;
    line-height: 20px;
}

.memory-del:hover {
    color: var(--danger, #ff6b6b);
    background: rgba(255,107,107,.12);
}

.gm-inventory-tools {
    margin-top: 14px;
    padding-top: 14px;
    border-top: 1px solid var(--border);
}

.gm-item-form {
    display: grid;
    grid-template-columns: minmax(0, 1.2fr) minmax(0, .8fr) 72px;
    gap: 8px;
}

.gm-item-form input[type=number] {
    text-align: center;
}

@media (max-width: 640px) {
    .inline-form, .gm-item-form {
        display: flex;
        flex-direction: column;
        align-items: stretch;
    }
}


/* Legal pages */
.legal-body {
    min-height: 100vh;
    height: auto;
    overflow-y: auto;
    overflow-x: hidden;
    position: static;
    overscroll-behavior: auto;
    -webkit-overflow-scrolling: touch;
    background: radial-gradient(circle at top left, rgba(139, 92, 246, .22), transparent 34%),
                radial-gradient(circle at bottom right, rgba(34, 197, 94, .13), transparent 28%),
                #080711;
    color: #f6f0ff;
}
.legal-shell { max-width: 980px; margin: 0 auto; padding: 32px 18px 64px; }
.legal-card {
    background: linear-gradient(180deg, rgba(22, 17, 38, .92), rgba(12, 10, 20, .94));
    border: 1px solid rgba(198, 169, 255, .24);
    border-radius: 24px;
    box-shadow: 0 24px 80px rgba(0,0,0,.42), inset 0 1px 0 rgba(255,255,255,.06);
    padding: clamp(22px, 4vw, 46px);
}
.legal-kicker { color: #c9a7ff; text-transform: uppercase; letter-spacing: .18em; font-size: .78rem; font-weight: 700; }
.legal-card h1 { font-size: clamp(2rem, 5vw, 4rem); line-height: 1; margin: 10px 0 12px; }
.legal-card h2 { margin-top: 34px; color: #f5d78e; }
.legal-card p, .legal-card li { color: #ded6ef; line-height: 1.75; }
.legal-notice { border-left: 4px solid #f5d78e; background: rgba(245, 215, 142, .09); padding: 16px 18px; border-radius: 14px; margin: 22px 0; }
.legal-nav { display:flex; gap:12px; flex-wrap:wrap; margin: 0 0 18px; }
.legal-nav a, .legal-button { color:#fff; text-decoration:none; border:1px solid rgba(255,255,255,.18); padding:10px 14px; border-radius:999px; background:rgba(255,255,255,.06); }
.legal-nav a:hover, .legal-button:hover { background:rgba(201,167,255,.18); }
.legal-footer { margin-top: 30px; color:#a99cc2; font-size:.92rem; }

/* Story memory editor */
.story-memory-editor {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
    padding: 12px;
    border: 1px solid rgba(201, 167, 255, .22);
    border-radius: 14px;
    background: rgba(18, 14, 31, .74);
}
.story-memory-editor label {
    font-size: 12px;
    font-weight: 700;
    color: var(--accent, #c9a7ff);
    letter-spacing: .02em;
}
.story-memory-editor textarea {
    width: 100%;
    min-height: 92px;
    resize: vertical;
    padding: 10px 11px;
    border-radius: 10px;
    border: 1px solid rgba(255,255,255,.12);
    background: rgba(0,0,0,.28);
    color: var(--text, #f6f0ff);
    font: inherit;
    line-height: 1.45;
}
.story-memory-editor textarea:focus {
    outline: none;
    border-color: rgba(201, 167, 255, .62);
    box-shadow: 0 0 0 3px rgba(201, 167, 255, .12);
}
.story-memory-buttons {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 2px;
}
.story-memory-status {
    min-height: 16px;
    font-size: 12px;
    color: var(--text-dim, #a99cc2);
}
.story-memory-status.error {
    color: #ff9b9b;
}
