:root {
    color-scheme: dark;
    --bg: #020617;
    --panel: #0f172a;
    --panel-strong: #111827;
    --panel-soft: #162033;
    --surface: #1e293b;
    --surface-soft: #253247;
    --text: #e5eefc;
    --muted: #93a4bf;
    --line: rgba(148, 163, 184, 0.22);
    --line-strong: rgba(148, 163, 184, 0.34);
    --danger: #fb7185;
    --warning: #f59e0b;
    --safe: #34d399;
    --accent: #60a5fa;
    --radius: 18px;
    --radius-sm: 14px;
}

*,
*::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;
}

button,
input,
textarea {
    font: inherit;
}

.app-shell {
    min-height: 100dvh;
    padding: calc(12px + env(safe-area-inset-top)) 12px calc(12px + env(safe-area-inset-bottom));
    display: flex;
    align-items: center;
    justify-content: center;
}

.game-panel {
    width: min(100%, 1080px);
    height: min(calc(100dvh - 24px - env(safe-area-inset-top) - env(safe-area-inset-bottom)), 860px);
    display: flex;
    flex-direction: column;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 24px;
    overflow: hidden;
}

.battle-topbar {
    padding: 12px 14px 10px;
    border-bottom: 1px solid var(--line);
    background: #0b1220;
    display: grid;
    gap: 10px;
}

.battle-topbar__main,
.battle-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.battle-topbar__main {
    gap: 14px;
}

.mode-chip,
.turn-chip,
.runtime-pill {
    border: 1px solid var(--line);
    border-radius: 999px;
}

.mode-chip {
    padding: 6px 10px;
    font-size: 0.72rem;
    font-weight: 700;
    color: #fca5a5;
    background: #22121f;
    letter-spacing: 0.04em;
}

.mini-button {
    width: 32px;
    height: 32px;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: transparent;
    color: var(--muted);
    cursor: pointer;
}

.turn-chip {
    min-width: 72px;
    padding: 7px 11px;
    background: #09101d;
    text-align: right;
}

.turn-chip__label {
    display: block;
    font-size: 0.65rem;
    color: var(--muted);
}

.turn-chip__value {
    display: block;
    margin-top: 1px;
    font-size: 1rem;
    font-weight: 800;
}

.meter-strip {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

.compact-meter {
    min-width: 0;
}

.compact-meter__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 5px;
    font-size: 0.76rem;
    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: 9px;
    padding: 2px;
    border-radius: 999px;
    background: #020617;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.meter-fill {
    height: 100%;
    width: 0;
    border-radius: 999px;
    transition: width 140ms linear;
}

.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: 0;
    padding: 7px 10px;
    border-radius: 12px;
    border: 1px solid rgba(167, 139, 250, 0.18);
    background: #211633;
    color: #ddd6fe;
    font-size: 0.75rem;
}

.battle-layout {
    flex: 1;
    min-height: 0;
    display: grid;
    grid-template-rows: minmax(0, 1fr) auto;
}

.partner-stage {
    min-height: 0;
    overflow: auto;
    padding: 14px;
    display: grid;
    align-content: start;
    gap: 14px;
}

.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: 14px;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 12px;
    align-items: start;
}

.avatar-shell {
    position: relative;
    width: 58px;
    height: 58px;
    border-radius: 18px;
    background: #081121;
    border: 1px solid var(--line);
    display: grid;
    place-items: center;
    flex-shrink: 0;
}

.avatar-emoji {
    font-size: 1.7rem;
}

.partner-status {
    position: absolute;
    right: -4px;
    top: -4px;
    width: 20px;
    height: 20px;
    border-radius: 999px;
    background: #3f111b;
    border: 1px solid rgba(251, 113, 133, 0.2);
    display: grid;
    place-items: center;
    font-size: 0.7rem;
}

.partner-copy {
    min-width: 0;
}

.scene-label {
    margin: 0;
    color: var(--muted);
    font-size: 0.76rem;
    font-weight: 700;
    letter-spacing: 0.02em;
}

.partner-opener {
    margin: 6px 0 0;
    font-size: 1rem;
    line-height: 1.45;
    font-weight: 700;
}

.clue-panel {
    padding: 12px;
}

.section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 10px;
}

.section-title {
    margin: 0;
    font-size: 0.82rem;
    color: var(--muted);
    letter-spacing: 0.04em;
}

.tags-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.tag {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 34px;
    padding: 8px 10px;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: var(--surface);
    font-size: 0.82rem;
    line-height: 1.2;
}

.tag--hidden {
    color: var(--muted);
    border-style: dashed;
}

.tag--risk,
.tag--warning {
    background: #2a141a;
}

.tag--safe {
    background: #0f2622;
}

.tag--constraint {
    background: #171328;
}

.tag--caution {
    background: #241f13;
}

.action-dock {
    border-radius: 0;
    border-left: 0;
    border-right: 0;
    border-bottom: 0;
    padding: 12px;
    background: #0b1220;
    display: grid;
    gap: 10px;
}

.tool-row {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
}

.tool-button {
    min-height: 56px;
    padding: 10px 12px;
    text-align: left;
    color: inherit;
    cursor: pointer;
    display: grid;
    gap: 4px;
}

.tool-button__label {
    font-size: 0.78rem;
    color: var(--muted);
}

.tool-button__value {
    font-size: 1rem;
}

.tool-button__note {
    color: var(--text);
    font-size: 0.72rem;
    line-height: 1.3;
}

.tool-button:disabled,
.button:disabled,
.chat-option:disabled,
.mini-button:disabled,
.icon-button:disabled {
    cursor: not-allowed;
    opacity: 0.56;
}

.button {
    position: relative;
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: var(--surface-soft);
    color: inherit;
    cursor: pointer;
    min-height: 50px;
    padding: 10px 12px;
    display: grid;
    align-content: center;
    gap: 3px;
    text-align: left;
}

.button-label {
    display: block;
    font-size: 0.92rem;
    font-weight: 800;
}

.button-note {
    display: block;
    color: var(--muted);
    font-size: 0.72rem;
    line-height: 1.2;
}

.button--chat {
    background: #172338;
}

.button--ghost {
    background: transparent;
}

.button--primary {
    background: #1d4ed8;
    border-color: rgba(96, 165, 250, 0.36);
}

.button--primary-alt {
    background: #be185d;
    border-color: rgba(244, 114, 182, 0.32);
}

.button--secondary {
    background: #162033;
}

.action-button--mild {
    background: #14283d;
}

.action-button--safe {
    background: #11291d;
}

.action-button--risk {
    background: #302312;
}

.action-button--danger {
    background: #34101b;
}

.chat-panel {
    padding: 10px;
    display: grid;
    gap: 10px;
}

.chat-panel__hint {
    margin: 0;
    color: var(--muted);
    font-size: 0.72rem;
}

.chat-panel__grid,
.action-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
}

.chat-panel__grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.chat-option {
    min-height: 64px;
    padding: 10px 8px;
    border-radius: 14px;
    border: 1px solid var(--line);
    background: var(--surface);
    color: inherit;
    text-align: left;
    display: grid;
    gap: 2px;
    cursor: pointer;
}

.chat-option strong {
    font-size: 0.82rem;
}

.chat-option span {
    font-size: 0.7rem;
    color: var(--muted);
}

.action-lock {
    position: absolute;
    inset: auto 8px 8px auto;
    padding: 2px 8px;
    border-radius: 999px;
    background: rgba(15, 23, 42, 0.92);
    border: 1px solid rgba(251, 113, 133, 0.24);
    color: #fecdd3;
    font-size: 0.66rem;
}

.is-empty {
    color: var(--muted);
}

.panic-mode .tag--hidden {
    opacity: 0.72;
}

.modal {
    position: fixed;
    inset: 0;
    z-index: 20;
    padding: calc(16px + env(safe-area-inset-top)) 16px calc(16px + env(safe-area-inset-bottom));
    display: grid;
    place-items: center;
    background: rgba(2, 6, 23, 0.82);
}

.modal-panel {
    width: min(100%, 720px);
    max-height: min(92dvh, 860px);
    padding: 18px;
    display: grid;
    gap: 14px;
}

.intro-panel {
    width: min(100%, 440px);
}

.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: #fda4af;
    font-size: 0.76rem;
    font-weight: 800;
    letter-spacing: 0.08em;
}

.modal-title,
.modal-section-title,
.feedback-title {
    margin: 0;
    font-size: clamp(1.35rem, 2vw, 1.8rem);
    line-height: 1.1;
}

.runtime-pill {
    display: inline-flex;
    align-items: center;
    width: fit-content;
    padding: 5px 10px;
    background: #162033;
    color: var(--muted);
    font-size: 0.72rem;
}

.runtime-note,
.intro-line {
    color: var(--muted);
    line-height: 1.5;
}

.mode-actions,
.modal-actions,
.feedback-actions {
    display: grid;
    gap: 10px;
}

.modal-actions--spread {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.modal-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.icon-button {
    width: 34px;
    height: 34px;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: transparent;
    color: var(--muted);
    cursor: pointer;
}

.modal-scroll,
.feedback-copy {
    min-height: 0;
    overflow: auto;
    display: grid;
    gap: 12px;
}

.help-section,
.summary-card,
.feedback-card,
.disease-card,
.unlock-card,
.casebook-section {
    padding: 12px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 14px;
}

.help-section__title,
.casebook-section__title,
.summary-stats__title {
    margin: 0 0 8px;
    font-size: 0.88rem;
    color: var(--muted);
}

.casebook-sections {
    display: grid;
    gap: 10px;
}

.casebook-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.casebook-chip {
    display: inline-flex;
    align-items: center;
    min-height: 30px;
    padding: 6px 10px;
    border-radius: 999px;
    border: 1px solid var(--line-strong);
    background: #131d30;
    font-size: 0.78rem;
}

.casebook-empty {
    color: var(--muted);
    font-size: 0.8rem;
}

.feedback-head {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 12px;
    align-items: start;
}

.feedback-icon {
    width: 48px;
    height: 48px;
    border-radius: 16px;
    background: #131d30;
    border: 1px solid var(--line);
    display: grid;
    place-items: center;
    font-size: 1.3rem;
}

.feedback-card,
.disease-card,
.unlock-card {
    display: grid;
    gap: 8px;
}

.feedback-line {
    margin: 0;
    line-height: 1.55;
}

.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.9rem;
    line-height: 1.45;
}

.unlock-card__title {
    font-size: 0.8rem;
    color: var(--muted);
}

.history-panel {
    padding: 0;
    overflow: hidden;
}

.history-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 12px;
    cursor: pointer;
    list-style: none;
}

.history-toggle::-webkit-details-marker {
    display: none;
}

.history-title {
    font-weight: 700;
}

.history-toggle__meta {
    color: var(--muted);
    font-size: 0.74rem;
}

.history-list {
    max-height: min(52vh, 520px);
    overflow: auto;
    padding: 0 12px 12px;
    display: grid;
    gap: 10px;
}

.history-entry {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 10px;
    padding: 12px;
    border-radius: 14px;
    background: var(--surface);
    border: 1px solid var(--line);
}

.history-avatar {
    position: relative;
    width: 42px;
    height: 42px;
    border-radius: 14px;
    display: grid;
    place-items: center;
    background: #0b1220;
}

.history-status {
    position: absolute;
    right: -3px;
    top: -3px;
    font-size: 0.7rem;
}

.history-copy {
    min-width: 0;
    display: grid;
    gap: 6px;
}

.history-scene {
    font-weight: 700;
}

.history-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.history-tag {
    display: inline-flex;
    padding: 4px 8px;
    border-radius: 999px;
    background: #111827;
    border: 1px solid var(--line);
    font-size: 0.74rem;
}

.history-subline {
    color: var(--muted);
    font-size: 0.74rem;
    line-height: 1.45;
}

.history-safe {
    color: #86efac;
}

.history-disease {
    color: #fda4af;
}

.history-outcome {
    align-self: start;
    padding: 6px 10px;
    border-radius: 999px;
    background: #111827;
    border: 1px solid var(--line);
    font-size: 0.72rem;
    white-space: nowrap;
}

.history-outcome--infected {
    color: #fecdd3;
}

.history-outcome--escape,
.history-outcome--leave,
.history-outcome--enjoy {
    color: #a7f3d0;
}

.summary-stats {
    display: grid;
    gap: 10px;
}

.summary-stats__grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
}

.summary-stats__row,
.summary-stats__footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 9px 10px;
    border-radius: 12px;
    background: #111827;
    border: 1px solid var(--line);
    font-size: 0.78rem;
}

.summary-stats__row--danger {
    color: #fecdd3;
}

.custom-scroll {
    scrollbar-width: thin;
}

@media (max-width: 639px) {
    .app-shell {
        padding-inline: 10px;
    }

    .game-panel {
        height: calc(100dvh - 20px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
        border-radius: 20px;
    }

    .battle-topbar {
        padding: 10px 12px 8px;
    }

    .partner-stage {
        padding: 12px;
        gap: 12px;
    }

    .partner-hero {
        grid-template-columns: 52px minmax(0, 1fr);
        padding: 12px;
    }

    .avatar-shell {
        width: 52px;
        height: 52px;
    }

    .partner-opener {
        font-size: 0.95rem;
    }

    .action-dock {
        padding: 10px;
        gap: 8px;
    }

    .button {
        min-height: 48px;
        padding: 9px 10px;
    }

    .button-label {
        font-size: 0.86rem;
    }

    .button-note,
    .tool-button__note {
        font-size: 0.68rem;
    }

    .chat-option {
        min-height: 58px;
        padding: 8px 7px;
    }

    .chat-option strong {
        font-size: 0.78rem;
    }

    .chat-option span {
        font-size: 0.66rem;
    }

    .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)), 820px);
    }

    .battle-layout {
        grid-template-columns: minmax(0, 1.12fr) 360px;
        grid-template-rows: 1fr;
    }

    .partner-stage {
        padding: 18px;
    }

    .action-dock {
        border-top: 0;
        border-left: 1px solid var(--line);
        padding: 18px;
        align-content: start;
    }

    .tool-row {
        grid-template-columns: 1fr;
    }

    .feedback-panel {
        width: min(100%, 860px);
    }
}
