/* ---------- Сброс ---------- */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    height: 100%;
}

body {
    background: #0f0f14;
    color: #e8e8ee;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 15px;
    line-height: 1.4;
    overflow-x: hidden;
    user-select: none;
}

#app {
    max-width: 520px;
    margin: 0 auto;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ---------- Сброс браузерных дефолтов для семантики ---------- */
h1, h2, h3, h4, p, ul, ol, li, blockquote, footer, section, figure {
    margin: 0;
    padding: 0;
    font-weight: inherit;
    font-size: inherit;
}

ul, ol {
    list-style: none;
}

/* ---------- Общие блоки ---------- */
.screen {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    padding: 16px;
    gap: 12px;
}

.screen-title {
    font-size: 20px;
    font-weight: 600;
    text-align: center;
    padding: 8px 0;
}

.screen-title small {
    display: block;
    font-size: 12px;
    color: #888;
    font-weight: 400;
    margin-top: 2px;
}

/* ---------- Карточки ---------- */
.card {
    background: #1a1a22;
    border-radius: 12px;
    padding: 14px;
    border: 1px solid #252532;
}

.card + .card {
    margin-top: 10px;
}

.card-title {
    font-size: 13px;
    color: #888;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}

.card.no-pad {
    padding: 0;
    overflow: hidden;
}

/* ---------- Аккордеон ---------- */
.accordion-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 14px;
    background: #22222e;
    cursor: pointer;
    user-select: none;
    border-bottom: 1px solid #252532;
    transition: background 0.15s;
}

.accordion-header:active {
    background: #2a2a38;
}

.accordion-title {
    flex: 1;
    font-size: 13px;
    color: #888;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 500;
}

.accordion-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 22px;
    height: 22px;
    padding: 0 7px;
    background: #4a5cd0;
    color: #fff;
    border-radius: 11px;
    font-size: 12px;
    font-weight: 600;
}

.accordion-arrow {
    color: #888;
    font-size: 14px;
    transition: transform 0.15s;
}

.accordion-body {
    padding: 12px 14px;
}

.accordion-body > * + * {
    margin-top: 8px;
}

.accordion-body[hidden] {
    display: none;
}

/* ---------- Кнопки ---------- */
button, .btn {
    font-family: inherit;
    font-size: 15px;
    font-weight: 500;
    color: #e8e8ee;
    background: #2a2a38;
    border: 1px solid #35354a;
    border-radius: 10px;
    padding: 12px 16px;
    cursor: pointer;
    transition: background 0.15s, transform 0.05s;
    width: 100%;
    text-align: center;
}

button:active, .btn:active {
    transform: scale(0.98);
}

button:disabled, .btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.btn-primary {
    background: #4a5cd0;
    border-color: #5a6ce0;
}

.btn-primary:active {
    background: #3a4cc0;
}

.btn-danger {
    background: #a03030;
    border-color: #c04040;
}

.btn-ghost {
    background: transparent;
    border-color: #35354a;
}

.btn-row {
    display: flex;
    gap: 8px;
}

.btn-row > * {
    flex: 1;
}

/* ---------- Полосы HP / энергии ---------- */
.bar {
    height: 20px;
    background: #0a0a10;
    border-radius: 10px;
    overflow: hidden;
    position: relative;
    border: 1px solid #252532;
}

.bar-fill {
    height: 100%;
    transition: width 0.25s ease;
    border-radius: 10px 0 0 10px;
}

.bar-fill.hp     { background: linear-gradient(90deg, #c03030, #e05050); }
.bar-fill.energy { background: linear-gradient(90deg, #3060c0, #5080e0); }

.bar-label {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
    color: #fff;
    text-shadow: 0 1px 2px rgba(0,0,0,0.6);
}

.bar-icon {
    margin-right: 4px;
    opacity: 0.85;
}

/* ---------- Кубики ---------- */
.dice-row {
    display: flex;
    gap: 8px;
    justify-content: center;
    flex-wrap: wrap;
}

.die {
    width: 52px;
    height: 52px;
    border-radius: 12px;
    background: linear-gradient(145deg, #32323f 0%, #23232e 100%);
    border: 1px solid #3a3a50;
    color: #e8e8ee;
    font-size: 22px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    user-select: none;
    transition: transform 0.12s, box-shadow 0.12s, border-color 0.12s, background 0.12s;
    box-shadow:
        inset 0 -3px 0 rgba(0, 0, 0, 0.35),
        inset 0 2px 0 rgba(255, 255, 255, 0.06),
        0 2px 4px rgba(0, 0, 0, 0.3);
}

.die.empty {
    color: #555;
    cursor: default;
    box-shadow:
        inset 0 -3px 0 rgba(0, 0, 0, 0.35),
        inset 0 2px 0 rgba(255, 255, 255, 0.04);
}

.die.selected {
    border-color: #5a6ce0;
    background: linear-gradient(145deg, #454570 0%, #2f2f4a 100%);
    transform: translateY(-4px);
    box-shadow:
        inset 0 -3px 0 rgba(0, 0, 0, 0.35),
        inset 0 2px 0 rgba(255, 255, 255, 0.08),
        0 6px 12px rgba(90, 108, 224, 0.35);
}

.dice-hint {
    margin-top: 8px;
    font-size: 12px;
    color: #888;
    text-align: center;
    min-height: 16px;
}

.dice-combo {
    margin-top: 8px;
    min-height: 24px;  /* резерв под одну строку stat-row */
}

/* Анимация «выпадения» нового значения */
@keyframes die-pop {
    0% {
        transform: scale(0.6);
        opacity: 0;
    }
    60% {
        transform: scale(1.08);
        opacity: 1;
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

.die.just-rolled {
    animation: die-pop 0.28s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* ---------- Цитаты ---------- */
.quote {
    position: relative;
    padding: 16px 18px 16px 44px;
    border-left: 3px solid #3a3a50;
    font-style: italic;
}

.quote-text {
    color: #c8c8d4;
    font-size: 14px;
    line-height: 1.5;
}

.quote-author {
    margin-top: 8px;
    font-size: 12px;
    color: #6a6a80;
    font-style: normal;
    text-align: right;
}

.quote-mark {
    position: absolute;
    top: -8px;
    left: 8px;
    font-size: 48px;
    color: #2a2a38;
    font-family: Georgia, serif;
    line-height: 1;
    pointer-events: none;
    user-select: none;
}

/* ---------- Враги ---------- */
.enemies-row {
    display: flex;
    gap: 8px;
    justify-content: center;
    flex-wrap: wrap;
    list-style: none;
    padding: 0;
    margin: 0;
}

.enemy {
    flex: 1 1 0;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
    padding: 10px 8px;
    background: #1a1a22;
    border-radius: 10px;
    border: 1px solid #252532;
    transition: opacity 0.3s;
    overflow: hidden;
}

.enemy.dead {
    opacity: 0.35;
    filter: grayscale(1);
}

.enemy-icon {
    font-size: 32px;
    line-height: 1;
    text-align: center;
}

.enemy-name {
    font-size: 12px;
    font-weight: 600;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.enemy .bar {
    height: 14px;
}

.enemy .bar-label {
    font-size: 10px;
}

.enemy-damage {
    font-size: 11px;
    color: #c07070;
    text-align: center;
}

.enemy.target {
    border-color: #c05050;
    box-shadow: 0 0 0 1px #c05050, 0 0 8px rgba(192, 80, 80, 0.3);
}

/* ---------- Строки статов ---------- */
.stat-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 0;
    font-size: 14px;
}

.stat-row .stat-label {
    color: #888;
}

.stat-row .stat-value {
    font-weight: 600;
}

/* ---------- Лог ---------- */
.log {
    background: #0a0a10;
    border-radius: 10px;
    padding: 10px;
    font-size: 13px;
    max-height: 160px;
    overflow-y: auto;
    font-family: ui-monospace, 'SF Mono', Menlo, monospace;
    line-height: 1.5;
    list-style: none;
    margin: 0;
}

.log-line {
    padding: 2px 0;
    color: #b0b0c0;
}

.log-line .log-time {
    color: #555;
    margin-right: 6px;
}

/* ---------- Улучшения ---------- */
.upgrades-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.upgrade {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px;
    background: #1a1a22;
    border-radius: 10px;
    border: 1px solid #252532;
    margin-bottom: 8px;
}

.upgrade.bought {
    opacity: 0.5;
}

.upgrade-info {
    flex: 1;
    min-width: 0;
}

.upgrade-name {
    font-weight: 600;
    font-size: 14px;
}

.upgrade-stats {
    font-size: 12px;
    color: #888;
    margin-top: 2px;
}

.upgrade-price {
    font-size: 13px;
    color: #d0b060;
    font-weight: 600;
    margin-top: 4px;
}

.upgrade-buy {
    flex-shrink: 0;
    width: auto;
    padding: 8px 14px;
    font-size: 13px;
}

/* ---------- Список игроков для помощи ---------- */
.help-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.help-player {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    background: #1a1a22;
    border-radius: 10px;
    margin-bottom: 8px;
}

.help-player-info {
    flex: 1;
    min-width: 0;
}

.help-player-name {
    font-weight: 600;
    font-size: 14px;
}

.help-player-stats {
    font-size: 12px;
    color: #888;
}

/* ---------- Оверлеи ---------- */
.overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    z-index: 100;
}

.overlay-content {
    background: #1a1a22;
    border-radius: 14px;
    padding: 18px;
    width: 100%;
    max-width: 480px;
    max-height: 90vh;
    overflow-y: auto;
    border: 1px solid #35354a;
}

.overlay-title {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 14px;
    text-align: center;
}

/* ---------- Лидерборд ---------- */
.lb-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.lb-row {
    display: flex;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid #252532;
    font-size: 14px;
}

.lb-row:last-child {
    border-bottom: none;
}

.lb-rank {
    width: 32px;
    color: #888;
    font-weight: 600;
}

.lb-name {
    flex: 1;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.lb-floor {
    color: #d0b060;
    font-weight: 600;
    margin-left: 8px;
}

.lb-runs {
    color: #666;
    font-size: 12px;
    margin-left: 8px;
}

/* --- Справка --- */
.help-block {
    margin-bottom: 14px;
}

.help-block:last-child {
    margin-bottom: 0;
}

.help-block-title {
    font-size: 14px;
    font-weight: 600;
    color: #c8c8d4;
    margin-bottom: 4px;
}

.help-block-text {
    font-size: 13px;
    color: #a0a0b0;
    line-height: 1.5;
}

/* ---------- Тосты ---------- */
.toast-container {
    position: fixed;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 200;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
    width: calc(100% - 32px);
    max-width: 480px;
}

.toast {
    background: #2a2a38;
    color: #e8e8ee;
    padding: 12px 16px;
    border-radius: 10px;
    border: 1px solid #35354a;
    font-size: 14px;
    text-align: center;
    animation: toast-in 0.2s ease;
    pointer-events: auto;
}

.toast.error {
    background: #3a1a1a;
    border-color: #6a2a2a;
    color: #ffb0b0;
}

.toast.success {
    background: #1a3a1a;
    border-color: #2a6a2a;
    color: #b0ffb0;
}

@keyframes toast-in {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ---------- Формы ---------- */
.input {
    width: 100%;
    padding: 12px 14px;
    font-size: 16px;
    font-family: inherit;
    background: #0a0a10;
    color: #e8e8ee;
    border: 1px solid #35354a;
    border-radius: 10px;
    outline: none;
    user-select: text;
}

.input:focus {
    border-color: #5a6ce0;
}

/* ---------- Утилиты ---------- */
.text-center { text-align: center; }
.text-dim    { color: #888; }
.text-small  { font-size: 12px; }
.mt-8        { margin-top: 8px; }
.mt-16       { margin-top: 16px; }
.spacer      { flex: 1; }
.hidden      { display: none !important; }

/* ---------- Доступность ---------- */

/* Фокус-индикатор: только при клавиатурной навигации */
button:focus-visible,
.btn:focus-visible,
.die:focus-visible,
.input:focus-visible,
[tabindex]:focus-visible,
.accordion-header:focus-visible {
    outline: 2px solid #5a6ce0;
    outline-offset: 2px;
    border-radius: 10px;
}

/* Уважаем системную настройку «меньше анимаций» */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Скрытый текст только для скринридеров */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ---------- Скроллбар ---------- */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #35354a; border-radius: 3px; }