:root {
    --bg-color: #0f1115;
    --card-bg: #181b20;
    --accent-color: #7289da;
    --text-color: #e1e3e6;
    --text-muted: #8a8e95;
    --hp-color: #e53935;
    --hp-bg: #4a1313;
    --border-color: #2a2e35;
    --success-color: #43a047;
    --fail-color: #e53935;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

html {
    height: 100%;
}

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    height: var(--tg-viewport-height, 100dvh);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#app {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    position: relative;
}

.screen {
    display: none;
    flex: 1;
    min-height: 0;
    flex-direction: column;
    width: 100%;
}

.screen.active {
    display: flex;
}

#screen-game {
    overflow: hidden; /* Запрещаем экрану вылезать за рамки */
}

/* Loader Screen */
.loader-content {
    margin: auto;
    text-align: center;
}
.game-title {
    font-size: 2rem;
    letter-spacing: 2px;
    margin-bottom: 10px;
}
.spinner {
    margin: 20px auto;
    width: 30px;
    height: 30px;
    border: 3px solid var(--border-color);
    border-top: 3px solid var(--accent-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}
@keyframes spin { 100% { transform: rotate(360deg); } }

/* Character Creation Screen */
.creation-box {
    padding: 20px;
    max-width: 500px;
    margin: auto;
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.creation-box label { font-weight: bold; color: var(--text-muted); }
.creation-box textarea, .creation-box select {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    color: var(--text-color);
    padding: 10px;
    border-radius: 6px;
    resize: none;
}
.creation-box textarea { height: 80px; }

/* Top Bar */
.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 15px;
    background: var(--card-bg);
    border-bottom: 1px solid var(--border-color);
}
.hp-bar-outer {
    width: 100px;
    height: 16px;
    background: var(--hp-bg);
    border-radius: 8px;
    position: relative;
    overflow: hidden;
}
.hp-bar-inner {
    height: 100%;
    background: var(--hp-color);
    transition: width 0.3s ease;
}
.hp-text {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    font-size: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
}

/* Location Banner */
.location-banner {
    display: flex;
    justify-content: space-between;
    padding: 8px 15px;
    background: #131519;
    font-size: 0.85rem;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border-color);
}
.loc-name { font-weight: bold; color: var(--text-color); }

/* Story Feed */
.story-feed {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
    padding: 15px;
    display: flex;
    flex-direction: column;
    gap: 15px;
    scrollbar-width: thin;
    scrollbar-color: var(--accent-color) transparent;
}
.story-feed::-webkit-scrollbar {
    width: 6px;
}
.story-feed::-webkit-scrollbar-track {
    background: transparent;
}
.story-feed::-webkit-scrollbar-thumb {
    background-color: var(--accent-color);
    border-radius: 3px;
}
.story-block {
    background: var(--card-bg);
    padding: 12px 15px;
    border-radius: 8px;
    line-height: 1.5;
    font-size: 0.95rem;
    border-left: 3px solid var(--accent-color);
}
.player-action-msg {
    align-self: flex-end;
    background: #232730;
    color: var(--accent-color);
    font-style: italic;
    border-left: none;
    border-right: 3px solid var(--accent-color);
}

/* Индикатор "ИИ думает" перед началом стриминга текста */
.thinking-block {
    display: flex;
    align-items: center;
    padding: 14px 18px;
    width: fit-content;
}
.thinking-dots {
    display: flex;
    gap: 5px;
}
.thinking-dots span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--text-muted);
    animation: thinking-bounce 1.1s infinite ease-in-out both;
}
.thinking-dots span:nth-child(2) { animation-delay: 0.15s; }
.thinking-dots span:nth-child(3) { animation-delay: 0.3s; }
@keyframes thinking-bounce {
    0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
    40% { transform: translateY(-5px); opacity: 1; }
}

/* Dice Overlay */
.dice-overlay {
    position: absolute;
    top: 60px;
    right: 20px;
    background: rgba(0,0,0,0.85);
    border: 1px solid var(--border-color);
    padding: 10px 15px;
    border-radius: 8px;
    transition: opacity 0.3s ease;
}
.dice-overlay.hidden { opacity: 0; pointer-events: none; }

/* Универсальный утилитарный класс скрытия — используется там, где не нужен
   специфичный переход/opacity, как у .dice-overlay.hidden. */
.hidden { display: none !important; }
.dice-num { font-size: 1.2rem; font-weight: bold; color: #ffca28; margin-right: 8px; }
.dice-text { font-size: 0.85rem; font-weight: bold; }

/* Expandable Panel */
.expandable-panel {
    background: var(--card-bg);
    border-top: 1px solid var(--border-color);
    font-size: 0.85rem;
}
.expandable-panel summary { padding: 8px 15px; cursor: pointer; color: var(--text-muted); }
.panel-content { padding: 10px 15px; display: flex; gap: 20px; }

/* Controls Footer */
.controls-bar {
    padding: 10px 15px;
    background: var(--card-bg);
    border-top: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.actions-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}
.btn-action {
    background: #232730;
    border: 1px solid var(--border-color);
    color: var(--text-color);
    padding: 8px 10px;
    border-radius: 6px;
    font-size: 0.85rem;
    cursor: pointer;
    text-align: center;
}
.btn-action:active { background: var(--accent-color); }

.custom-input-box {
    display: flex;
    gap: 8px;
}
.custom-input-box input {
    flex: 1;
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    color: var(--text-color);
    padding: 10px;
    border-radius: 6px;
}
.btn-send {
    background: var(--accent-color);
    border: none;
    color: #fff;
    padding: 0 15px;
    border-radius: 6px;
    cursor: pointer;
}
.btn-primary {
    background: var(--accent-color);
    color: #fff;
    border: none;
    padding: 12px;
    border-radius: 6px;
    font-weight: bold;
    cursor: pointer;
}

.top-bar-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto; /* Прижимает всю группу кнопок к правому краю */
}

.btn-icon-small {
    background: #232730;
    border: 1px solid var(--border-color);
    color: var(--text-color);
    width: 30px;
    height: 30px;
    border-radius: 6px;
    font-size: 0.9rem;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, border-color 0.2s;
}
.btn-icon-small:hover {
    border-color: var(--accent-color);
}
.btn-icon-small:active {
    background: var(--accent-color);
}

.btn-danger-small {
    background: var(--hp-bg);
    border: 1px solid var(--fail-color);
    color: var(--text-color);
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 0.75rem;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-danger-small:hover {
    background: #6a1a1a;
}

.btn-danger-small:active {
    background: var(--fail-color);
}

.currency-row {
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}
.currency-pill {
    font-weight: bold;
    color: var(--text-color);
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 2px 8px;
    font-size: 0.85rem;
}

/* Задания */
.quest-details {
    margin-top: 4px;
}
.quest-details summary {
    cursor: pointer;
    color: var(--accent-color);
    font-size: 0.85rem;
    padding: 4px 0;
}
.quest-list {
    list-style: none;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 6px;
}
.quest-item {
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 8px 10px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
}
.quest-item:active {
    border-color: var(--accent-color);
}
.quest-item.ready {
    border-color: var(--success-color);
}
.quest-item-title {
    font-size: 0.85rem;
    color: var(--text-color);
}
.quest-status-badge {
    font-size: 0.7rem;
    padding: 2px 6px;
    border-radius: 10px;
    background: #232730;
    color: var(--text-muted);
    white-space: nowrap;
}
.quest-status-badge.ready {
    background: var(--success-color);
    color: #fff;
}
.quest-modal-desc {
    font-size: 0.85rem;
    color: var(--text-muted);
}
.btn-quest-turnin {
    width: 100%;
    background: var(--accent-color);
    border: none;
    color: #fff;
    padding: 9px;
    border-radius: 6px;
    font-size: 0.85rem;
    cursor: pointer;
}
.btn-quest-turnin:disabled {
    background: #232730;
    color: var(--text-muted);
    cursor: not-allowed;
}

.story-feed {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
    padding: 15px;
    display: flex;
    flex-direction: column;
    gap: 15px;
    scrollbar-width: thin;
    scrollbar-color: var(--accent-color) transparent;
    scroll-behavior: smooth; /* Добавляет плавность скроллу */
}

/* Modal Overlay */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.75);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
    transition: opacity 0.3s ease;
}
.modal-overlay.hidden {
    display: none;
}
.modal-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    width: 100%;
    max-width: 400px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    position: relative;
    box-shadow: 0 10px 25px rgba(0,0,0,0.5);
}
.modal-close-btn {
    position: absolute;
    top: 10px; right: 15px;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    cursor: pointer;
}
.modal-close-btn:hover {
    color: var(--text-color);
}
.npc-modal-status-text {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: -6px;
}
.npc-stats-grid {
    display: flex;
    gap: 15px;
    background: var(--bg-color);
    padding: 10px;
    border-radius: 6px;
    border: 1px solid var(--border-color);
}
.npc-stat-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    font-weight: bold;
}
.npc-section {
    font-size: 0.85rem;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.npc-section ul {
    list-style-position: inside;
    color: var(--text-muted);
    padding-left: 5px;
}

.modal-card label {
    font-weight: bold;
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-top: 4px;
}
.modal-card input[type="text"],

.modal-card textarea {
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    color: var(--text-color);
    padding: 8px 10px;
    border-radius: 6px;
    resize: none;
    width: 100%;
}
.modal-card textarea {
    height: 60px;
}
.modal-card input[type="range"] {
    width: 100%;
    accent-color: var(--accent-color);
}

/* Настройки */
.settings-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 0;
    border-bottom: 1px solid var(--border-color);
}
.settings-row:last-of-type {
    border-bottom: none;
}
.settings-row-label {
    display: flex;
    flex-direction: column;
    gap: 2px;
    font-size: 0.9rem;
    font-weight: normal;
    color: var(--text-color);
    margin-top: 0;
}
.settings-row-hint {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: normal;
}

.switch {
    position: relative;
    display: inline-block;
    width: 42px;
    height: 24px;
    flex-shrink: 0;
}
.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}
.switch-slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: var(--hp-bg);
    border: 1px solid var(--border-color);
    border-radius: 24px;
    transition: background-color 0.2s;
}
.switch-slider::before {
    content: "";
    position: absolute;
    height: 16px;
    width: 16px;
    left: 3px;
    bottom: 3px;
    background-color: var(--text-color);
    border-radius: 50%;
    transition: transform 0.2s;
}
.switch input:checked + .switch-slider {
    background-color: var(--accent-color);
    border-color: var(--accent-color);
}
.switch input:checked + .switch-slider::before {
    transform: translateX(18px);
}

.turn-processing-hint {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-style: italic;
    padding: 6px 4px;
    display: inline-block;
}