/*
 * 九州修仙录 - 仙剑风 CSS 主题
 * 配色: 宣纸米黄 + 墨黑 + 朱砂红 + 石青
 */

/* === CSS Reset === */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* === CSS Variables (仙剑·九州主题) === */
:root {
    --bg-paper: #F5F0E1;
    --text-ink: #2C2416;
    --border-wood: #8B7355;
    --accent-cinnabar: #A62424;
    --accent-azurite: #365E74;
    --success-pine: #5D8037;
    --failure-blood: #8B2323;
    --light-gray: #E6DFD0;
    --shadow: rgba(44, 36, 22, 0.15);

    /* 字体 */
    --font-title: "Noto Serif SC", "Songti SC", "STSong", serif;
    --font-body: "Noto Sans SC", "PingFang SC", "Heiti SC", sans-serif;
    --font-mono: "Noto Sans Mono", monospace;
}

/* === Base Styles === */
html {
    height: 100%;
    -webkit-text-size-adjust: 100%;
}

body {
    min-height: 100vh;
    /* 适配 iPhone 底部安全区域，避免被系统工具栏挡住 */
    padding-bottom: env(safe-area-inset-bottom);
    font-family: var(--font-body);
    background-color: var(--bg-paper);
    color: var(--text-ink);
    line-height: 1.6;
    background-image:
        linear-gradient(rgba(44, 36, 22, 0.03) 1px, transparent 1px),
        linear-gradient(90deg, rgba(44, 36, 22, 0.03) 1px, transparent 1px);
    background-size: 20px 20px;
}

/* === Game Container with Wooden Border === */
.game-container {
    height: 100vh;
    display: flex;
    flex-direction: column;
    margin: 8px;
    border: 3px double var(--border-wood);
    border-radius: 8px;
    background-color: var(--bg-paper);
    box-shadow: 2px 2px 8px var(--shadow);
    overflow: hidden;
}

/* === Header === */
.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 16px;
    border-bottom: 2px solid var(--border-wood);
    background-color: var(--bg-paper);
}

.game-title {
    font-family: var(--font-title);
    font-size: 1.4rem;
    color: var(--accent-cinnabar);
    font-weight: 600;
    letter-spacing: 0.1em;
}

.menu-toggle {
    background: none;
    border: 1px solid var(--border-wood);
    border-radius: 4px;
    padding: 4px 10px;
    font-size: 1.2rem;
    color: var(--text-ink);
    cursor: pointer;
}

.menu-toggle:hover {
    background-color: var(--light-gray);
}

/* === Main Content Area === */
.game-content {
    flex: 1;
    overflow-y: auto;
    padding: 12px 16px;
    -webkit-overflow-scrolling: touch;
}

/* 纸张纹理效果 */
.game-content::-webkit-scrollbar {
    width: 8px;
}

.game-content::-webkit-scrollbar-track {
    background: var(--light-gray);
}

.game-content::-webkit-scrollbar-thumb {
    background: var(--border-wood);
    border-radius: 4px;
}

/* === Story Area === */
.story-area {
    font-size: 1rem;
    line-height: 1.8;
}

.story-paragraph {
    margin-bottom: 1em;
    text-indent: 2em;
}

.story-paragraph:first-child {
    text-indent: 0;
}

/* === 场景图（AI 素材） === */
.scene-image {
    margin: 12px 0 16px;
    border: 1px solid var(--border-wood);
    border-radius: 6px;
    overflow: hidden;
    box-shadow: 0 2px 8px var(--shadow);
}

.scene-image img {
    display: block;
    width: 100%;
    height: auto;
    aspect-ratio: 1 / 1;
    object-fit: cover;
}

.event-card {
    margin: 16px 0;
    padding: 12px;
    border: 1px solid var(--border-wood);
    border-radius: 6px;
    background-color: rgba(255, 255, 255, 0.3);
}

.event-title {
    font-family: var(--font-title);
    font-size: 1.2rem;
    color: var(--accent-azurite);
    margin-bottom: 8px;
    border-bottom: 1px solid var(--light-gray);
    padding-bottom: 4px;
}

/* === Dice Result === */
.dice-result {
    margin: 12px 0;
    text-align: center;
    min-height: 40px;
}

.dice-roll {
    display: inline-block;
    padding: 8px 24px;
    border: 2px solid var(--border-wood);
    border-radius: 8px;
    background-color: var(--light-gray);
    font-family: var(--font-mono);
    font-size: 1.5rem;
    animation: roll 0.5s ease-out;
}

.dice-result.critical-success .dice-roll {
    background-color: var(--success-pine);
    color: white;
    border-color: var(--success-pine);
    animation: pulse 1s ease-in-out infinite;
}

.dice-result.critical-failure .dice-roll {
    background-color: var(--failure-blood);
    color: white;
    border-color: var(--failure-blood);
}

.dice-result.success .dice-roll {
    background-color: var(--accent-azurite);
    color: white;
    border-color: var(--accent-azurite);
}

@keyframes roll {
    0% { transform: rotate(0deg) scale(0.8); opacity: 0.5; }
    50% { transform: rotate(180deg) scale(1.2); opacity: 1; }
    100% { transform: rotate(360deg) scale(1); }
}

@keyframes pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(93, 128, 55, 0.4); }
    50% { box-shadow: 0 0 0 10px rgba(93, 128, 55, 0); }
}

/* === Actions Area === */
.actions-area {
    padding: 8px 12px;
    border-top: 2px solid var(--border-wood);
    background-color: var(--bg-paper);
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
}

.btn {
    font-family: var(--font-body);
    padding: 10px 16px;
    border: 2px solid var(--border-wood);
    border-radius: 6px;
    background-color: var(--light-gray);
    color: var(--text-ink);
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s ease;
    min-height: 44px;
    min-width: 80px;
}

.btn:hover {
    background-color: var(--border-wood);
    color: white;
}

.btn.primary {
    background-color: var(--accent-cinnabar);
    border-color: var(--accent-cinnabar);
    color: white;
}

.btn.primary:hover {
    background-color: #8A1C1C;
    border-color: #8A1C1C;
}

.btn.secondary {
    background-color: var(--accent-azurite);
    border-color: var(--accent-azurite);
    color: white;
}

.btn.secondary:hover {
    background-color: #2A4A5C;
    border-color: #2A4A5C;
}

/* === Footer Status Bar === */
.game-footer {
    padding: 8px 12px;
    border-top: 1px solid var(--border-wood);
    background-color: var(--light-gray);
}

.status-info {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    justify-content: center;
    font-size: 0.9rem;
}

.stat-item {
    white-space: nowrap;
}

.stat-name {
    color: var(--accent-azurite);
}

.stat-value {
    font-family: var(--font-mono);
    font-weight: 600;
    margin-left: 4px;
}

/* === Login Screen === */
.login-screen {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 300px;
}

.login-card {
    text-align: center;
    max-width: 320px;
    padding: 24px;
    border: 2px double var(--border-wood);
    border-radius: 8px;
    background-color: rgba(255, 255, 255, 0.4);
}

.login-card h2 {
    font-family: var(--font-title);
    color: var(--accent-cinnabar);
    margin-bottom: 16px;
}

.login-card p {
    margin-bottom: 16px;
    color: var(--text-ink);
}

.login-card input {
    width: 100%;
    padding: 10px;
    margin-bottom: 16px;
    border: 1px solid var(--border-wood);
    border-radius: 4px;
    font-size: 1rem;
    font-family: var(--font-body);
    background-color: white;
}

/* === Side Menu === */
.menu-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 100;
    display: none;
}

.menu-overlay.open {
    display: block;
}

.side-menu {
    position: fixed;
    top: 0;
    right: -280px;
    width: 280px;
    height: 100vh;
    background-color: var(--bg-paper);
    border-left: 3px double var(--border-wood);
    z-index: 101;
    transition: right 0.3s ease;
    padding: 16px;
}

.side-menu.open {
    right: 0;
}

.side-menu h3 {
    font-family: var(--font-title);
    color: var(--accent-cinnabar);
    margin-bottom: 16px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border-wood);
}

.side-menu ul {
    list-style: none;
}

.side-menu li {
    margin-bottom: 8px;
}

.side-menu button {
    width: 100%;
    text-align: left;
}

/* === Modal (Attribute Panel) === */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 200;
    display: none;
    justify-content: center;
    align-items: center;
    padding: 16px;
}

.modal-overlay.open {
    display: flex;
}

.modal-content {
    background-color: var(--bg-paper);
    border: 3px double var(--border-wood);
    border-radius: 8px;
    padding: 20px;
    max-width: 360px;
    width: 100%;
    max-height: 80vh;
    overflow-y: auto;
}

.modal-content h3 {
    font-family: var(--font-title);
    color: var(--accent-cinnabar);
    margin-bottom: 16px;
    text-align: center;
}

.attribute-table {
    margin-bottom: 16px;
}

.attribute-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid var(--light-gray);
}

.attribute-row:last-child {
    border-bottom: none;
}

.attr-label {
    font-weight: 500;
    color: var(--accent-azurite);
}

.attr-value {
    font-family: var(--font-mono);
    font-size: 1.1rem;
    font-weight: 600;
}

.attr-grade-super {
    color: var(--accent-cinnabar);
}

.attr-grade-good {
    color: var(--success-pine);
}

.attr-grade-medium {
    color: var(--accent-azurite);
}

.attr-grade-bad {
    color: var(--border-wood);
}

.modal-content .btn.close {
    width: 100%;
}

/* === Attribute Generation Screen === */
.stats-generation {
    text-align: center;
}

.stats-generation h3 {
    font-family: var(--font-title);
    color: var(--accent-cinnabar);
    margin-bottom: 16px;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin: 16px 0;
}

.stat-roll {
    padding: 8px;
    border: 1px solid var(--border-wood);
    border-radius: 4px;
    background-color: rgba(255, 255, 255, 0.3);
}

.stat-roll-name {
    font-size: 0.9rem;
    color: var(--accent-azurite);
}

.stat-roll-value {
    font-family: var(--font-mono);
    font-size: 1.5rem;
    font-weight: 700;
}

/* === Reactive: Mobile First === */
@media (max-width: 480px) {
    .game-container {
        margin: 4px;
    }

    .game-title {
        font-size: 1.2rem;
    }

    .game-content {
        padding: 8px 12px;
    }

    .stats-grid {
        grid-template-columns: 1fr;
    }

    .status-info {
        gap: 6px;
        font-size: 0.8rem;
    }
}

/* === Loading === */
.loading {
    text-align: center;
    padding: 32px;
    color: var(--border-wood);
    font-style: italic;
}
