:root {
    color-scheme: dark;
    --bg: #09090b;
    --panel: #18181b;
    --panel-strong: #27272a;
    --panel-soft: #3f3f46;
    --surface: #3f3f46;
    --surface-soft: #52525b;
    --text: #f4f4f5;
    --muted: #a1a1aa;
    --line: rgba(255, 255, 255, 0.08);
    --line-strong: rgba(255, 255, 255, 0.15);
    --danger: #f87171;
    --warning: #fbbf24;
    --safe: #34d399;
    --accent: #60a5fa;
    --radius: 16px;
    --radius-sm: 12px;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

html,
body {
    min-height: 100%;
}

body {
    margin: 0;
    font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    overflow-x: hidden;
    line-height: 1.6;
    letter-spacing: 0.02em;
}

button,
input,
textarea {
    font: inherit;
    /* 低功耗：仅对颜色和透明度应用过渡，避免 transform 引起的重绘/重排 */
    transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
}

.app-shell {
    min-height: 100dvh;
    padding: calc(8px + env(safe-area-inset-top)) 8px calc(8px + env(safe-area-inset-bottom));
    display: flex;
    align-items: center;
    justify-content: center;
}

.game-panel {
    width: min(100%, 1080px);
    height: min(calc(100dvh - 32px - env(safe-area-inset-top) - env(safe-area-inset-bottom)), 880px);
    display: flex;
    flex-direction: column;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 28px;
    overflow: hidden;
}

.battle-topbar {
    padding: 8px 12px 6px;
    border-bottom: 1px solid var(--line);
    /* 低功耗：去除了 backdrop-filter: blur()，改用不透明的纯色背景 */
    background: #18181b;
    display: grid;
    gap: 6px;
}

.battle-topbar__main,
.battle-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.battle-topbar__main {
    gap: 6px;
}

.mode-chip,
.turn-chip,
.runtime-pill {
    border: 1px solid var(--line);
    border-radius: 999px;
}

.mode-chip {
    padding: 6px 12px;
    font-size: 0.7rem;
    font-weight: 700;
    color: #fca5a5;
    background: rgba(244, 63, 94, 0.1);
    letter-spacing: 0.05em;
}

.mini-button {
    width: 34px;
    height: 34px;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    display: grid;
    place-items: center;
}

.mini-button:hover {
    background: var(--surface);
    color: var(--text);
}

.turn-chip {
    min-width: 76px;
    padding: 6px 14px;
    background: rgba(255, 255, 255, 0.03);
    text-align: right;
}

.turn-chip__label {
    display: block;
    font-size: 0.55rem;
    color: var(--muted);
    line-height: 1;
}

.turn-chip__value {
    display: block;
    margin-top: 4px;
    font-size: 0.9rem;
    font-weight: 800;
    line-height: 1;
}

.meter-strip {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
}

.compact-meter {
    min-width: 0;
}

.compact-meter__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    margin-bottom: 6px;
    font-size: 0.7rem;
    font-weight: 700;
}

.compact-meter[data-tone="urge"] .compact-meter__head span {
    color: var(--danger);
}

.compact-meter[data-tone="anxiety"] .compact-meter__head span {
    color: #a78bfa;
}

.meter-track {
    height: 10px;
    padding: 2px;
    border-radius: 999px;
    background: rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.meter-fill {
    height: 100%;
    width: 0;
    border-radius: 999px;
    /* 进度条动画较少触发，保留基础宽度过渡 */
    transition: width 0.3s ease;
}

.meter-fill--urge {
    background: linear-gradient(90deg, #10b981 0%, #f43f5e 100%);
}

.meter-fill--anxiety {
    background: linear-gradient(90deg, #38bdf8 0%, #8b5cf6 100%);
}

.panic-warning {
    margin: 4px 0 0;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    border: 1px solid rgba(167, 139, 250, 0.25);
    background: rgba(139, 92, 246, 0.1);
    color: #ddd6fe;
    font-size: 0.7rem;
    /* 低功耗：移除无限循环的 pulse 动画 */
}

.battle-layout {
    flex: 1;
    min-height: 0;
    display: grid;
    grid-template-rows: minmax(0, 1fr) auto;
}

.partner-stage {
    min-height: 0;
    overflow: auto;
    padding: 8px;
    display: grid;
    align-content: start;
    gap: 6px;
}

.partner-hero,
.clue-panel,
.action-dock,
.tool-button,
.chat-panel,
.modal-panel,
.summary-card,
.feedback-card,
.disease-card,
.unlock-card,
.history-panel {
    background: var(--panel-strong);
    border: 1px solid var(--line);
    border-radius: var(--radius);
}

.partner-hero {
    padding: 8px;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 6px;
    align-items: start;
}

.avatar-shell {
    position: relative;
    width: 44px;
    height: 44px;
    border-radius: var(--radius-sm);
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--line);
    display: grid;
    place-items: center;
    flex-shrink: 0;
}

.avatar-emoji {
    font-size: 1.4rem;
}

.partner-status {
    position: absolute;
    right: -6px;
    top: -6px;
    width: 24px;
    height: 24px;
    border-radius: 999px;
    background: #3f111b;
    border: 1px solid rgba(251, 113, 133, 0.3);
    display: grid;
    place-items: center;
    font-size: 0.7rem;
}

.partner-copy {
    min-width: 0;
}

.scene-label {
    margin: 0;
    color: var(--muted);
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.partner-opener {
    margin: 8px 0 0;
    font-size: 0.95rem;
    font-weight: 600;
}

.clue-panel {
    padding: 10px;
}

.section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 12px;
}

.section-title {
    margin: 0;
    font-size: 0.7rem;
    color: var(--muted);
    letter-spacing: 0.05em;
    font-weight: 600;
}

.tags-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.tag {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 32px;
    padding: 8px 14px;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.03);
    font-size: 0.7rem;
}

.tag--hidden {
    color: var(--muted);
    border-style: dashed;
    background: transparent;
}

.tag--risk,
.tag--warning {
    background: rgba(244, 63, 94, 0.1);
    border-color: rgba(244, 63, 94, 0.2);
    color: #fecdd3;
}

.tag--safe {
    background: rgba(16, 185, 129, 0.1);
    border-color: rgba(16, 185, 129, 0.2);
    color: #a7f3d0;
}

.tag--constraint {
    background: rgba(167, 139, 250, 0.1);
    border-color: rgba(167, 139, 250, 0.2);
    color: #ddd6fe;
}

.tag--caution {
    background: rgba(251, 191, 36, 0.1);
    border-color: rgba(251, 191, 36, 0.2);
    color: #fde68a;
}

.action-dock {
    border-radius: 0;
    border-left: 0;
    border-right: 0;
    border-bottom: 0;
    padding: 10px;
    background: #18181b;
    display: grid;
    gap: 6px;
}

.tool-row {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
}

.tool-button {
    min-height: 42px;
    padding: 8px 10px;
    text-align: left;
    color: inherit;
    cursor: pointer;
    display: grid;
    gap: 4px;
}

.tool-button:hover:not(:disabled) {
    background: var(--surface);
}

.tool-button__label {
    font-size: 0.7rem;
    color: var(--muted);
}

.tool-button__value {
    font-size: 0.9rem;
    font-weight: 700;
}

.tool-button__note {
    color: var(--text);
    font-size: 0.7rem;
}

.tool-button:disabled,
.button:disabled,
.chat-option:disabled,
.mini-button:disabled,
.icon-button:disabled {
    cursor: not-allowed;
    opacity: 0.5;
}

.button {
    position: relative;
    width: 100%;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--panel-strong);
    color: inherit;
    cursor: pointer;
    min-height: 42px;
    padding: 8px 10px;
    display: grid;
    align-content: center;
    gap: 4px;
    text-align: left;
}

.button:hover:not(:disabled) {
    background: var(--surface);
}

.button-label {
    display: block;
    font-size: 0.7rem;
    font-weight: 700;
}

.button-note {
    display: block;
    color: var(--muted);
    font-size: 0.7rem;
}

.button--chat {
    background: rgba(59, 130, 246, 0.1);
    border-color: rgba(59, 130, 246, 0.2);
}

.button--chat:hover:not(:disabled) {
    background: rgba(59, 130, 246, 0.2);
}

.button--ghost {
    background: transparent;
    border-style: dashed;
}

.button--ghost:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.03);
}

.button--primary {
    background: var(--accent);
    color: #fff;
    border-color: transparent;
    text-align: center;
}

.button--primary:hover:not(:disabled) {
    background: #2563eb;
}

.button--primary-alt {
    background: #e11d48;
}

.button--primary-alt:hover:not(:disabled) {
    background: #be123c;
}

.button--secondary {
    background: var(--panel-strong);
    text-align: center;
}

.action-button--mild {
    background: rgba(59, 130, 246, 0.08);
}
.action-button--safe {
    background: rgba(16, 185, 129, 0.08);
}
.action-button--risk {
    background: rgba(245, 158, 11, 0.08);
}
.action-button--danger {
    background: rgba(244, 63, 94, 0.08);
}

.chat-panel {
    padding: 14px;
    display: grid;
    gap: 6px;
}

.chat-panel__hint {
    margin: 0;
    color: var(--muted);
    font-size: 0.7rem;
}

.chat-panel__grid,
.action-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

.chat-panel__grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.chat-option {
    min-height: 46px;
    padding: 12px 10px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--line);
    background: var(--panel-strong);
    color: inherit;
    text-align: left;
    display: grid;
    gap: 4px;
    cursor: pointer;
}

.chat-option:hover:not(:disabled) {
    background: var(--surface);
}

.chat-option strong {
    font-size: 0.7rem;
    font-weight: 700;
}

.chat-option span {
    font-size: 0.72rem;
    color: var(--muted);
}

.action-lock {
    position: absolute;
    inset: auto 10px 10px auto;
    padding: 3px 10px;
    border-radius: 999px;
    background: rgba(24, 24, 27, 0.95);
    border: 1px solid rgba(244, 63, 94, 0.3);
    color: #fecdd3;
    font-size: 0.7rem;
    font-weight: 600;
}

.is-empty {
    color: var(--muted);
}

.panic-mode .tag--hidden {
    opacity: 0.6;
}

.modal {
    position: fixed;
    inset: 0;
    z-index: 20;
    padding: calc(20px + env(safe-area-inset-top)) 20px calc(20px + env(safe-area-inset-bottom));
    display: grid;
    place-items: center;
    /* 低功耗：移除 blur */
    background: rgba(0, 0, 0, 0.9);
}

.modal-panel {
    width: min(100%, 720px);
    max-height: min(92dvh, 860px);
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.intro-panel {
    width: min(100%, 460px);
}

.info-panel {
    width: min(100%, 720px);
}

.feedback-panel {
    width: min(100%, 760px);
}

.intro-head,
.feedback-head__copy {
    display: grid;
    gap: 6px;
}

.modal-kicker,
.runtime-note,
.intro-line,
.help-section__line,
.critical-copy {
    margin: 0;
}

.modal-kicker {
    color: #fca5a5;
    font-size: 0.7rem;
    font-weight: 800;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.modal-title,
.modal-section-title,
.feedback-title {
    margin: 0;
    font-size: clamp(1.4rem, 2.5vw, 1.9rem);
    line-height: 1.2;
    font-weight: 800;
}

.runtime-pill {
    display: inline-flex;
    align-items: center;
    width: fit-content;
    padding: 6px 12px;
    background: rgba(255, 255, 255, 0.05);
    color: var(--muted);
    font-size: 0.7rem;
    border-radius: 999px;
}

.runtime-note,
.intro-line {
    color: var(--muted);
}

.mode-actions,
.modal-actions,
.feedback-actions {
    display: grid;
    gap: 6px;
    margin-top: 8px;
}

.modal-actions--spread {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.modal-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
}

.icon-button {
    width: 38px;
    height: 38px;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    font-size: 1.2rem;
    display: grid;
    place-items: center;
}

.icon-button:hover {
    background: var(--surface);
    color: var(--text);
}

.modal-scroll,
.feedback-copy {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    display: grid;
    gap: 6px;
    align-content: start;
}

.help-section,
.summary-card,
.feedback-card,
.disease-card,
.unlock-card,
.casebook-section {
    padding: 10px;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
}

.help-section__title,
.casebook-section__title,
.summary-stats__title {
    margin: 0 0 10px;
    font-size: 0.8rem;
    color: var(--muted);
    font-weight: 700;
}

.casebook-sections {
    display: grid;
    gap: 6px;
}

.casebook-list {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.casebook-chip {
    display: inline-flex;
    align-items: center;
    min-height: 32px;
    padding: 6px 12px;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(0, 0, 0, 0.2);
    font-size: 0.7rem;
}

.casebook-empty {
    color: var(--muted);
    font-size: 0.7rem;
    font-style: italic;
}

.feedback-head {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 6px;
    align-items: start;
}

.feedback-icon {
    width: 54px;
    height: 54px;
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--line);
    display: grid;
    place-items: center;
    font-size: 1.5rem;
}

.feedback-card,
.disease-card,
.unlock-card {
    display: grid;
    gap: 10px;
}

.feedback-line {
    margin: 0;
    font-size: 0.95rem;
}

.feedback-line--danger,
.feedback-title[data-tone="danger"],
.critical-copy {
    color: #fecdd3;
}

.feedback-line--warning {
    color: #fde68a;
}

.feedback-line--success,
.feedback-title[data-tone="success"] {
    color: #a7f3d0;
}

.feedback-line--muted {
    color: var(--muted);
}

.critical-copy {
    font-size: 0.7rem;
}

.unlock-card__title {
    font-size: 0.7rem;
    color: var(--muted);
    font-weight: 700;
}

.history-panel {
    padding: 0;
    overflow: hidden;
    background: transparent;
    border: none;
}

.history-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    padding: 10px 12px;
    cursor: pointer;
    list-style: none;
    background: var(--panel-strong);
    border-radius: var(--radius-sm);
    border: 1px solid var(--line);
}

.history-toggle:hover {
    background: var(--surface);
}

.history-toggle::-webkit-details-marker {
    display: none;
}

.history-title {
    font-weight: 700;
}

.history-toggle__meta {
    color: var(--muted);
    font-size: 0.7rem;
}

.history-list {
    max-height: min(52vh, 520px);
    overflow: auto;
    padding: 12px 0 0;
    display: grid;
    gap: 6px;
}

.history-entry {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 6px;
    padding: 14px;
    border-radius: var(--radius-sm);
    background: var(--panel-strong);
    border: 1px solid var(--line);
}

.history-avatar {
    position: relative;
    width: 48px;
    height: 48px;
    border-radius: 16px;
    display: grid;
    place-items: center;
    background: rgba(0, 0, 0, 0.3);
    font-size: 1.2rem;
}

.history-status {
    position: absolute;
    right: -4px;
    top: -4px;
    font-size: 0.7rem;
}

.history-copy {
    min-width: 0;
    display: grid;
    gap: 6px;
}

.history-scene {
    font-weight: 700;
    font-size: 0.7rem;
}

.history-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.history-tag {
    display: inline-flex;
    padding: 4px 10px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--line);
    font-size: 0.7rem;
}

.history-subline {
    color: var(--muted);
    font-size: 0.7rem;
}

.history-safe {
    color: #86efac;
}

.history-disease {
    color: #fda4af;
}

.history-outcome {
    align-self: start;
    padding: 6px 12px;
    border-radius: 999px;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--line);
    font-size: 0.7rem;
    font-weight: 600;
    white-space: nowrap;
}

.history-outcome--infected {
    color: #fecdd3;
    border-color: rgba(244, 63, 94, 0.3);
}

.history-outcome--escape,
.history-outcome--leave,
.history-outcome--enjoy {
    color: #a7f3d0;
    border-color: rgba(16, 185, 129, 0.3);
}

.summary-stats {
    display: grid;
    gap: 6px;
}

.summary-stats__grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

.summary-stats__row,
.summary-stats__footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 10px 14px;
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--line);
    font-size: 0.7rem;
}

.summary-stats__row--danger {
    color: #fecdd3;
}

.custom-scroll {
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
}
.custom-scroll::-webkit-scrollbar {
    width: 6px;
}
.custom-scroll::-webkit-scrollbar-track {
    background: transparent;
}
.custom-scroll::-webkit-scrollbar-thumb {
    background-color: rgba(255, 255, 255, 0.2);
    border-radius: 10px;
}

@media (max-width: 639px) {
    .app-shell {
        padding-inline: 12px;
    }

    .game-panel {
        height: calc(100dvh - 24px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
        border-radius: 24px;
    }

    .battle-topbar {
        padding: 8px 10px;
    }

    .partner-stage {
        padding: 10px;
        gap: 6px;
    }

    .partner-hero {
        grid-template-columns: 56px minmax(0, 1fr);
        padding: 10px;
    }

    .avatar-shell {
        width: 56px;
        height: 56px;
    }

    .partner-opener {
        font-size: 0.9rem;
    }

    .action-dock {
        padding: 14px;
        gap: 10px;
    }

    .button {
        min-height: 50px;
        padding: 10px 14px;
    }

    .button-label {
        font-size: 0.8rem;
    }

    .button-note,
    .tool-button__note {
        font-size: 0.7rem;
    }

    .chat-option {
        min-height: 42px;
        padding: 10px 8px;
    }

    .chat-option strong {
        font-size: 0.7rem;
    }

    .chat-option span {
        font-size: 0.68rem;
    }

    .history-entry {
        grid-template-columns: auto minmax(0, 1fr);
    }

    .history-outcome {
        grid-column: 2;
        justify-self: start;
    }
}

@media (min-width: 940px) {
    .game-panel {
        height: min(calc(100dvh - 32px - env(safe-area-inset-top) - env(safe-area-inset-bottom)), 840px);
    }

    .battle-layout {
        grid-template-columns: minmax(0, 1.15fr) 380px;
        grid-template-rows: 1fr;
    }

    .partner-stage {
        padding: 10px;
    }

    .action-dock {
        border-top: 0;
        border-left: 1px solid var(--line);
        padding: 10px;
        align-content: start;
    }

    .tool-row {
        grid-template-columns: 1fr;
    }

    .feedback-panel {
        width: min(100%, 860px);
    }
}

.history-modal-panel {
    width: min(100%, 720px);
}
