/* --- Base and Theme --- */
:root {
    --bg-color: #1a1b26;
    --panel-bg: #24283b;
    --text-color: #a9b1d6;
    --accent-color: #7aa2f7;
    --accent-alt: #ff9e64;
    --success-color: #9ece6a;
    --error-color: #f7768e;
    --border-color: #414868;
    --input-bg: #1f2335;
    --highlight-bg: rgba(122, 162, 247, 0.1);
    --narrative-bg: rgba(31, 35, 53, 0.3);
    --font-narrative: 'Noto Serif SC', serif;
    --font-ui: 'Roboto', sans-serif;
    --shadow-sm: 0 2px 4px rgba(0,0,0,0.2);
    --shadow-md: 0 4px 8px rgba(0,0,0,0.3);
    --shadow-lg: 0 6px 12px rgba(0,0,0,0.35);
    --transition-speed: 0.25s;
}

/* --- Performance Optimizations --- */
* {
    box-sizing: border-box;
}

/* GPU加速优化 */
.container, .game-log, .interaction-area, .settings-panel {
    transform: translateZ(0);
    will-change: transform;
}

/* 减少重绘 */
img {
    image-rendering: optimizeQuality;
    transform: translateZ(0);
}

/* 优化动画性能 */
.logo, button, input, select, textarea {
    will-change: transform, opacity;
}

/* 滚动优化 */
.game-log {
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-ui);
    line-height: 1.6;
    margin: 0;
    padding: 15px;
    background-color: var(--bg-color);
    color: var(--text-color);
    display: flex;
    justify-content: center;
    align-items: flex-start;
    min-height: 100vh;
}

.container.game-container {
    max-width: 750px;
    width: 100%;
    margin: 20px auto;
    background: var(--panel-bg);
    padding: 25px;
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    max-height: 95vh; /* Limit height on desktop */
}

/* --- Focus Visible --- */
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible {
    outline: 2px solid var(--accent-color);
    outline-offset: 2px;
    box-shadow: 0 0 0 4px var(--highlight-bg);
}


/* --- Headers --- */
.game-header { text-align: center; margin-bottom: 25px; padding-bottom: 15px; border-bottom: 1px solid var(--border-color); flex-shrink: 0; }
.game-header h1 { color: var(--accent-color); margin: 5px 0 8px 0; font-family: var(--font-narrative); font-weight: 700; font-size: 2.1em; }
.game-header p { margin: 0; color: #787c99; font-size: 0.95em; }

/* --- Game Start Screen --- */
#game-start-screen { padding: 30px; text-align: center; flex-grow: 1; display: flex; flex-direction: column; justify-content: center; }
.start-header { border-bottom: none; margin-bottom: 15px; padding-bottom: 10px; }
#game-logo {
    display: block;
    max-width: 130px;
    height: auto;
    margin: 0 auto 25px auto;
    border-radius: 8px;
    transition: transform 0.3s ease, filter 0.3s ease;
    filter: drop-shadow(0 0 10px rgba(122, 162, 247, 0.6)) drop-shadow(0 0 20px rgba(122, 162, 247, 0.3));
    animation: logoGlow 3s ease-in-out infinite alternate, logoFloat 6s ease-in-out infinite;
    background: transparent;
}
#game-logo:hover { 
    transform: scale(1.05); 
    filter: drop-shadow(0 0 15px rgba(122, 162, 247, 0.8)) drop-shadow(0 0 30px rgba(122, 162, 247, 0.4));
    animation-play-state: paused;
}

@keyframes logoGlow {
    0% {
        filter: drop-shadow(0 0 10px rgba(122, 162, 247, 0.6)) drop-shadow(0 0 20px rgba(122, 162, 247, 0.3));
    }
    100% {
        filter: drop-shadow(0 0 15px rgba(154, 122, 247, 0.8)) drop-shadow(0 0 30px rgba(154, 122, 247, 0.4));
    }
}

@keyframes logoFloat {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-10px);
    }
}

.start-form {
    width: 90%;
    margin: 15px auto 0 auto;
    padding: 35px;
    background-color: var(--input-bg);
    border-radius: 10px;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-md);
}
.start-form .form-group label { display: block; margin-bottom: 8px; color: var(--accent-alt); font-weight: bold; text-align: left; font-size: 0.95em; }
.start-form input[type="text"]#game-name-input { 
    background-color: #2a2f41; 
    border: 1px solid var(--border-color); 
    color: var(--text-color); 
    width: 100%; 
    padding: 12px 15px; 
    border-radius: 6px; 
    font-size: 1.1em; 
    margin-bottom: 15px; 
    text-align: center; 
    box-sizing: border-box; 
    transition: border-color var(--transition-speed) ease, box-shadow var(--transition-speed) ease;
    white-space: normal;
    overflow: visible;
    word-wrap: break-word;
}
.start-form input[type="text"]#game-name-input:focus { border-color: var(--accent-color); box-shadow: 0 0 0 3px var(--highlight-bg); }
.start-form input[type="text"]#game-name-input::placeholder { color: #5f657e; }

/* Advanced Options Styling */
#advanced-options-wrapper {
    margin: 20px 0 25px 0;
    padding-top: 15px;
    border-top: 1px dashed var(--border-color);
}

.toggle-advanced-button {
    background: none;
    border: none;
    color: var(--accent-alt);
    cursor: pointer;
    padding: 5px 0;
    font-size: 0.9em;
    width: 100%;
    text-align: left;
    margin-bottom: 15px;
    transition: color var(--transition-speed);
}
.toggle-advanced-button:hover {
    color: #ffbb96;
}

#advanced-options-content {
    transition: all var(--transition-speed) ease-out;
    overflow: hidden;
}
#advanced-options-content .form-group { margin-bottom: 15px; }
#advanced-options-content label { font-size: 0.9em; color: #a9b1d6; font-weight: normal; text-align: left;}
#advanced-options-content textarea {
    background-color: #2a2f41; 
    border: 1px solid var(--border-color); 
    color: var(--text-color); 
    width: 100%; 
    padding: 10px 12px; 
    border-radius: 6px; 
    font-size: 0.95em; 
    box-sizing: border-box; 
    resize: vertical; 
    word-wrap: break-word;
    white-space: pre-wrap;
    min-height: 80px;
    line-height: 1.5;
    max-height: 300px;
    overflow-y: auto;
}
#advanced-options-content textarea:focus,
#advanced-options-content input[type="text"]:focus { border-color: var(--accent-color); box-shadow: 0 0 0 3px var(--highlight-bg); }
#advanced-options-content textarea::placeholder,
#advanced-options-content input[type="text"]::placeholder { color: #5f657e; font-size: 0.9em; }

/* Game Name Recommendations */
.game-name-recommendations {
    margin: 15px 0;
    padding: 15px;
    background-color: var(--input-bg);
    border-radius: 8px;
    border: 1px dashed var(--border-color);
}

.game-name-recommendations h3 {
    font-size: 1em;
    color: var(--accent-color);
    margin: 0 0 12px 0;
    text-align: center;
    font-weight: 500;
}

.recommended-names-container {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    max-height: 90px;
    overflow-y: auto;
    padding: 5px;
}

.recommended-name-item {
    padding: 5px 10px;
    background-color: var(--panel-bg);
    color: var(--accent-alt);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    font-size: 0.85em;
    cursor: pointer;
    transition: all var(--transition-speed) ease;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 150px;
}

.recommended-name-item:hover {
    background-color: #303650;
    border-color: var(--accent-alt);
    color: #fff;
    transform: translateY(-1px);
}

.recommended-name-item:active {
    transform: scale(0.97);
    opacity: 0.9;
    transition: transform 0.1s ease, opacity 0.1s ease;
}

/* 状态消息容器样式 */
.status-container {
    margin: 12px 0;
    display: none; /* 默认隐藏状态容器 */
    align-items: center;
    justify-content: center;
    min-height: 28px;
    background-color: rgba(26, 27, 38, 0.3);
    border-radius: 6px;
    padding: 8px 12px;
    position: relative;
}

.status-container .spinner-small {
    margin-right: 8px;
}

.start-status-message { 
    font-size: 0.95em; 
    color: var(--accent-color); 
    transition: color var(--transition-speed) ease; 
    font-weight: 500;
    text-align: center;
    margin: 0;
}
.start-status-message.error { color: var(--error-color); } 
.start-status-message.success { color: var(--success-color); } 
.start-status-message.loading { color: var(--accent-color); }

/* 调整开始按钮样式 */
.start-buttons { display: flex; gap: 12px; margin-top: 15px; justify-content: center; }
.start-buttons button {
    padding: 13px 25px;
    border-radius: 10px;
    font-size: 1.1em;
    font-weight: bold;
    cursor: pointer;
    transition: all var(--transition-speed) ease;
    border: none;
    box-shadow: var(--shadow-md);
    position: relative;
    overflow: hidden;
}

/* 生成游戏按钮美化 */
#generate-game-button {
    background: linear-gradient(135deg, #7aa2f7 0%, #9d7cd8 100%);
    color: white;
    border: none;
    transform: translateY(0);
    position: relative;
    transition: all 0.3s ease;
}

#generate-game-button:hover {
    transform: translateY(-3px);
    box-shadow: 0 7px 14px rgba(0, 0, 0, 0.25);
    background: linear-gradient(135deg, #88b0ff 0%, #ab8ae6 100%);
}

#generate-game-button:active:not(:disabled) {
    transform: translateY(1px);
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}

#generate-game-button:disabled {
    background: linear-gradient(135deg, #4a5674 0%, #626084 100%);
    color: #9aa0bc;
    cursor: not-allowed;
    box-shadow: none;
    transform: none;
}

/* 添加发光动画 */
#generate-game-button::after {
    content: "";
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle, rgba(255,255,255,0.2) 0%, rgba(255,255,255,0) 60%);
    transform: scale(0);
    opacity: 0;
    transition: transform 0.6s, opacity 0.6s;
}

#generate-game-button:hover::after {
    transform: scale(1);
    opacity: 1;
}

/* 重新生成按钮 */
#regenerate-button {
    background-color: var(--input-bg);
    color: var(--accent-alt);
    border: 1px solid var(--border-color);
    margin-left: 10px;
    padding: 10px 15px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-size: 0.95em;
}

#regenerate-button:hover {
    background-color: #303650;
    border-color: var(--accent-alt);
    color: #fff;
    transform: translateY(-2px);
}

#regenerate-button svg {
    width: 16px;
    height: 16px;
    animation: rotate 1.5s ease infinite paused;
}

#regenerate-button:hover svg {
    animation-play-state: running;
}

@keyframes rotate {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

/* 旧按钮样式 - 保留向后兼容性 */
#ai-generate-button { background-color: var(--input-bg); color: var(--accent-alt); border: 1px solid var(--border-color); }
#ai-generate-button:hover { background-color: #303650; border-color: var(--accent-alt); color: #fff;}
#start-game-button { background-color: var(--success-color); color: var(--bg-color); }
#start-game-button:hover { background-color: #b9f2ae; filter: brightness(1.1); }
#start-game-button:disabled, #ai-generate-button:disabled { background-color: #414868; color: #787c99; cursor: not-allowed; border-color: #414868; box-shadow: none; transform: none; filter: brightness(0.8); }
#ai-generate-button:active, #start-game-button:active:not(:disabled) { transform: scale(0.97); box-shadow: none; }

/* --- Main Game Area Styling --- */
#main-game-area { display: flex; flex-direction: column; flex-grow: 1; overflow: hidden; position: relative; }
#game-log-container { flex-grow: 1; overflow-y: auto; padding: 15px 20px; margin-bottom: 20px; background-color: rgba(26, 27, 38, 0.3); border-radius: 8px; border: 1px solid var(--border-color); scroll-behavior: smooth; }
.log-entry { margin-bottom: 30px; padding-bottom: 25px; border-bottom: 1px dashed var(--border-color); opacity: 0; transform: translateY(15px); transition: opacity 0.5s ease-out, transform 0.4s ease-out; }
.log-entry:last-child { margin-bottom: 0; border-bottom: none; }
.log-entry.fade-in { opacity: 1; transform: translateY(0); }
.log-entry.error { background-color: rgba(247, 118, 142, 0.05); padding: 15px; border-radius: 5px; border-left: 4px solid var(--error-color); margin-top: 10px; }
.log-entry.error p { color: var(--error-color); }

/* User Action Display */
.user-action-display {
    font-style: italic;
    color: var(--accent-alt);
    margin-bottom: 15px;
    padding: 8px 15px 8px 20px;
    border-left: 4px solid var(--accent-alt);
    font-size: 1.05em;
    background: var(--highlight-bg);
    border-radius: 0 4px 4px 0;
    line-height: 1.5;
}
.user-action-display.error-context {
    border-left-color: var(--error-color);
    color: var(--error-color);
    background: rgba(247, 118, 142, 0.08);
    margin-bottom: 10px;
}

/* Narrative & Audio Wrapper Styling */
.narrative-container {
    padding: 15px 20px;
    border: 1px solid var(--border-color);
    background-color: var(--narrative-bg);
    border-radius: 8px;
    margin-bottom: 15px;
    position: relative;
    transition: background-color var(--transition-speed) ease;
}
.narrative-text {
    font-family: var(--font-narrative);
    color: var(--text-color);
    font-size: 1.15em;
    line-height: 1.85;
    margin-bottom: 15px;
}
.narrative-text p { margin-top: 0; margin-bottom: 0.8em; }
.narrative-text p:last-child { margin-bottom: 0; }

/* Audio Control Wrapper (Label + Button) */
.narrative-audio-wrapper {
    display: flex;
    justify-content: space-between; /* Pushes button right */
    align-items: center;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid rgba(65, 72, 104, 0.5);
}
.audio-label {
    font-size: 0.75em;
    color: #787c99;
    font-family: var(--font-ui);
    margin-right: 8px;
    display: inline;
}

/* Significantly Smaller Audio Button */
.audio-control-button {
    flex-shrink: 0;
    padding: 1px 2px; /* Tiny padding */
    border: 1px solid var(--border-color); /* Thinner border */
    background-color: var(--panel-bg);
    color: var(--accent-color);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: none;
    line-height: 1;
    border-radius: 3px; /* Sharper corners */
    box-shadow: none;
    vertical-align: middle;
    min-width: 1.2em; /* Adjusted */
    min-height: 1.2em; /* Adjusted */
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}
.audio-control-button svg.icon { /* Target the icon specifically */
    width: 0.6em; /* Smaller icon */
    height: 0.6em; /* Smaller icon */
    fill: currentColor;
    display: inline-block; /* Ensure it shows */
}
.audio-control-button:hover {
     background-color: var(--panel-bg);
     border-color: var(--border-color);
     color: var(--accent-color);
     box-shadow: none;
     transform: none;
}
.audio-control-button:active {
    transform: none;
    box-shadow: none;
    opacity: 1.0;
}
.audio-control-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    filter: grayscale(50%);
}
.audio-control-button[data-state="loading"] .spinner-audio { display: block; }
.audio-control-button[data-state="loading"] svg.icon { display: none; } /* Hide icon when loading */
.audio-control-button:not([data-state="loading"]) .spinner-audio { display: none; }

/* Smaller Spinner for Audio Button */
.spinner-audio {
    display: none;
    border: 1.5px solid rgba(169, 177, 214, 0.5);
    border-radius: 50%;
    border-top: 1.5px solid var(--accent-color);
    width: 0.5em; /* Adjusted spinner size */
    height: 0.5em;
    animation: spin 0.8s linear infinite;
    /* Ensure spinner is centered if needed, though flex align should handle it */
    /* margin: auto; */
}


/* Image Container */
.scene-image-container {
    width: 100%;
    margin-top: 20px;
    position: relative;
    background-color: var(--input-bg);
    border-radius: 8px;
    border: 1px solid var(--border-color);
    aspect-ratio: 16 / 9;
    max-height: 450px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    box-shadow: var(--shadow-md);
}
#game-log-container .scene-image-container img { 
    display: block; 
    width: 100%; 
    height: 100%; 
    object-fit: cover; 
    border-radius: 7px; 
    transition: opacity 0.6s ease-in-out, filter 0.3s ease, transform 0.3s ease; 
    background-color: #000; 
}

/* 添加图片悬停效果 */
#game-log-container .scene-image-container img.viewable-image:hover {
    transform: scale(1.02);
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

/* 图片点击提示 */
.image-view-info {
    position: absolute;
    bottom: 10px;
    right: 10px;
    background-color: rgba(0, 0, 0, 0.6);
    color: white;
    padding: 5px 10px;
    border-radius: 4px;
    font-size: 0.8em;
    z-index: 5;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none; /* 不阻止点击事件传递到图片 */
}

.scene-image-container:hover .image-view-info {
    opacity: 1;
}

/* 图片视图器自定义样式 */
.viewer-container {
    background-color: rgba(0, 0, 0, 0.9);
}

.viewer-footer {
    background-color: rgba(0, 0, 0, 0.7);
}

.viewer-toolbar {
    background-color: rgba(0, 0, 0, 0.7);
}

.viewer-toolbar li {
    background-color: rgba(45, 45, 45, 0.8);
    border-radius: 4px;
    margin: 0 2px;
}

.viewer-toolbar li:hover {
    background-color: rgba(70, 70, 70, 0.9);
}

/* 确保原始加载和错误覆盖层显示正常 */
#game-log-container .image-loading-overlay { 
    position: absolute; 
    top: 0; 
    left: 0; 
    width: 100%; 
    height: 100%; 
    background-color: rgba(0, 0, 0, 0.85); 
    display: none; 
    flex-direction: column; 
    align-items: center; 
    justify-content: center; 
    color: white; 
    border-radius: 8px; 
    text-align: center; 
    z-index: 10; 
    transition: opacity var(--transition-speed) ease; 
}

.image-error-overlay { 
    position: absolute; 
    top: 0; 
    left: 0; 
    width: 100%; 
    height: 100%; 
    background-color: rgba(31, 35, 53, 0.95); 
    display: none; 
    flex-direction: column; 
    align-items: center; 
    justify-content: center; 
    color: var(--error-color); 
    border-radius: 8px; 
    text-align: center; 
    padding: 20px; 
    box-sizing: border-box; 
    z-index: 11; 
    transition: opacity var(--transition-speed) ease;
}

.image-error-overlay .error-text { 
    margin: 0 0 15px 0; 
    font-size: 0.95em; 
    font-weight: bold; 
    max-width: 90%; 
}

/* Retry Buttons */
.retry-button { padding: 8px 15px; background-color: var(--input-bg); color: var(--accent-alt); border: 1px solid var(--border-color); border-radius: 6px; font-size: 0.9em; cursor: pointer; transition: all var(--transition-speed) ease; box-shadow: var(--shadow-sm); user-select: none; -webkit-tap-highlight-color: transparent; }
.retry-button:hover { background-color: #303650; border-color: var(--accent-alt); color: #fff; transform: translateY(-1px); }
.retry-button:active { transform: scale(0.97); box-shadow: none; }
.retry-button:disabled { opacity: 0.5; cursor: not-allowed; }


/* --- Interaction Area --- */
#interaction-area { padding: 20px 25px; background-color: var(--input-bg); border-top: 1px solid var(--border-color); flex-shrink: 0; border-radius: 0 0 10px 10px; }
#status-area { margin-bottom: 15px; text-align: center; min-height: 1.2em; font-size: 0.95em; transition: color var(--transition-speed) ease; }
#status-message { font-weight: 500; transition: color var(--transition-speed) ease, opacity var(--transition-speed) ease; }
#status-message.loading { color: var(--accent-color); }
#status-message.error { color: var(--error-color); }
#status-message.success { color: var(--success-color); }
#status-message.info { color: var(--text-color); }


/* Action Choices - Vertical Layout */
.action-choices { margin-bottom: 20px; }
.action-choices p {
    font-size: 0.95em;
    color: #787c99;
    margin-bottom: 12px;
    text-align: center;
    display: block;
    font-weight: 500;
}
.choices-wrapper {
    display: block; /* Vertical stack */
    width: 100%;
    min-height: 38px;
    transition: opacity var(--transition-speed) ease;
}

/* Suggested Action Buttons - Vertical, Shorter, Rounded */
.action-choice-button {
    display: block;
    /* Removed width: 100%; Use max-width instead */
    max-width: 85%; /* Make button shorter */
    margin-left: auto; /* Center the shorter button */
    margin-right: auto; /* Center the shorter button */
    padding: 8px 16px;
    margin-bottom: 8px;
    background-color: var(--panel-bg);
    color: var(--accent-alt);
    border: 1px solid var(--border-color);
    border-radius: 20px; /* Rounded ends */
    font-size: 0.95em;
    cursor: pointer;
    transition: none;
    box-shadow: var(--shadow-sm);
    line-height: 1.4;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: center; /* Center text in button */
}
.action-choice-button:last-child {
    margin-bottom: 0;
}
.action-choice-button:hover {
    background-color: var(--panel-bg);
    border-color: var(--border-color);
    color: var(--accent-alt);
    transform: none;
    box-shadow: var(--shadow-sm);
}
.action-choice-button:active {
    transform: none;
    opacity: 1.0;
    box-shadow: var(--shadow-sm);
}
.action-choice-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    box-shadow: none;
    transform: none;
    background-color: #2a2f41;
    border-color: #414868;
    color: #5f657e;
}
@media (hover: hover) and (pointer: fine) {
    .action-choice-button:not(:disabled):hover {
        background-color: #303650;
        border-color: var(--accent-alt);
        color: #fff;
        transform: translateY(-1px); /* Add subtle lift */
        box-shadow: var(--shadow-md);
        transition: all var(--transition-speed) ease;
    }
    .action-choice-button:not(:disabled):active {
       transform: scale(0.98) translateY(0); /* Adjusted */
       box-shadow: var(--shadow-sm);
       opacity: 0.95;
       transition: transform 0.1s ease, opacity 0.1s ease, box-shadow 0.1s ease;
    }
}
.hidden-choice {
    display: none;
}
#toggle-choices-button {
    font-size: 0.85em !important;
    padding: 5px 10px !important;
    margin-top: 10px !important;
    width: auto !important;
    display: block !important;
    margin-left: auto;
    margin-right: auto;
    text-align: center;
    background-color: var(--input-bg);
    border: 1px solid var(--border-color);
    color: var(--accent-alt);
    border-radius: 6px;
}
#toggle-choices-button:hover {
    background-color: #303650;
    border-color: var(--accent-alt);
    color: #ffbb96;
}

.choices-loading { font-size: 0.95em; color: #787c99; text-align: center; width: 100%; display: none; align-items: center; justify-content: center; padding: 10px 0;}


/* Spinners */
.spinner {
    border: 4px solid rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    border-top: 4px solid var(--accent-color);
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
    margin-bottom: 10px;
}
.spinner-small {
    display: inline-block;
    vertical-align: middle;
    border: 2px solid rgba(169, 177, 214, 0.5);
    border-radius: 50%;
    border-top: 2px solid var(--accent-alt);
    width: 14px;
    height: 14px;
    animation: spin 0.8s linear infinite;
    margin-right: 6px;
}
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }

/* Input Form */
#action-form { display: flex; gap: 10px; align-items: center; }
#action-form .form-group { flex-grow: 1; margin-bottom: 0; }
#action-form input[type="text"]#user-input { background-color: #2a2f41; border: 1px solid var(--border-color); color: var(--text-color); width: 100%; padding: 12px 15px; border-radius: 6px; font-size: 1em; box-sizing: border-box; transition: border-color var(--transition-speed) ease, box-shadow var(--transition-speed) ease; }
#action-form input[type="text"]#user-input:focus { border-color: var(--accent-color); box-shadow: 0 0 0 3px var(--highlight-bg); }
#action-form button[type="submit"]#action-button {
    background-color: var(--accent-color);
    color: var(--bg-color);
    font-weight: bold;
    margin: 0;
    padding: 11px 18px;
    border-radius: 6px;
    border:none;
    cursor: pointer;
    flex-shrink: 0;
    transition: all var(--transition-speed) ease;
    box-shadow: var(--shadow-sm);
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}
#action-form button[type="submit"]#action-button:hover { background-color: #9aaef7; filter: brightness(1.1); transform: translateY(-1px); box-shadow: 0 3px 6px rgba(0,0,0,0.25); }
#action-form button[type="submit"]#action-button:disabled { background-color: #414868; color: #787c99; cursor: not-allowed; box-shadow: none; transform: none; filter: brightness(0.8);}
#action-form button[type="submit"]#action-button:active:not(:disabled) { transform: scale(0.97); box-shadow: none; }

/* --- Footer & Settings --- */
.game-footer { margin-top: 25px; text-align: center; font-size: 0.85em; color: #787c99; display: flex; justify-content: flex-end; align-items: center; padding-top: 15px; border-top: 1px solid var(--border-color); flex-shrink: 0; }
button#toggle-settings {
    background-color: transparent;
    color: #787c99;
    border: 1px solid var(--border-color);
    padding: 6px 12px;
    font-size: 0.95em;
    cursor: pointer;
    border-radius: 6px;
    width: auto;
    margin: 0;
    transition: all var(--transition-speed) ease;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}
button#toggle-settings:hover { background-color: var(--input-bg); color: var(--text-color); border-color: var(--accent-color);}
button#toggle-settings:active { transform: scale(0.97); }

/* Settings Panel */
.settings-panel {
    position: absolute;
    bottom: 60px; right: 25px;
    z-index: 20;
    width: 320px;
    padding: 20px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background-color: var(--input-bg);
    box-shadow: var(--shadow-md);
    opacity: 0;
    transform: translateY(10px) scale(0.98);
    transition: opacity 0.2s ease-out, transform 0.2s ease-out, visibility 0s 0.2s;
    visibility: hidden;
    transform-origin: bottom right;
}
.settings-panel.visible {
    opacity: 1;
    transform: translateY(0) scale(1);
    visibility: visible;
    transition: opacity 0.2s ease-out, transform 0.2s ease-out, visibility 0s 0s;
}
.settings-panel h3 { margin: 0 0 18px 0; text-align: left; color: var(--accent-color); font-family: var(--font-ui); font-size: 1.15em;}
.settings-panel .form-group { margin-bottom: 15px; }
.settings-panel label { font-size: 0.95em; display: block; margin-bottom: 6px; color: #a9b1d6;}
.settings-panel select, .settings-panel input[type="text"] { background-color: #2a2f41; border: 1px solid #414868; color: var(--text-color); width: 100%; padding: 10px 12px; border-radius: 6px; box-sizing: border-box; transition: border-color var(--transition-speed) ease, box-shadow var(--transition-speed) ease; font-size: 0.95em; }
.settings-panel select:focus, .settings-panel input[type="text"]:focus { border-color: var(--accent-color); box-shadow: 0 0 0 3px var(--highlight-bg); }
#settings #image-style-keywords-input-settings::placeholder { color: #5f657e; font-size: 0.9em; }

/* Checkbox groups in settings */
.checkbox-group-settings { display: flex; align-items: center; margin-top: 15px; margin-bottom: 15px; padding: 10px 12px; background-color: #2a2f41; border-radius: 6px;}
.checkbox-group-settings label { display: flex; align-items: center; cursor: pointer; font-size: 0.9em; margin-bottom: 0; width: 100%; color: #a9b1d6; user-select: none; }
.checkbox-group-settings input[type="checkbox"] { margin-right: 10px; width: 18px; height: 18px; accent-color: var(--accent-color); flex-shrink: 0; cursor: pointer; }

/* Close button */
.close-settings-btn {
    display: none;
    position: absolute;
    top: 10px; right: 15px;
    background: none; border: none;
    font-size: 1.8em; color: var(--text-color);
    cursor: pointer; padding: 0 5px; line-height: 1;
    opacity: 0.7; transition: opacity var(--transition-speed) ease, color var(--transition-speed) ease;
    z-index: 21;
    user-select: none; -webkit-tap-highlight-color: transparent;
}
.close-settings-btn:hover { opacity: 1; color: var(--accent-color); }


/* --- Scrollbar Styling --- */
#game-log-container::-webkit-scrollbar { width: 10px; }
#game-log-container::-webkit-scrollbar-track { background: var(--input-bg); border-radius: 5px; }
#game-log-container::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 5px; border: 2px solid var(--input-bg); }
#game-log-container::-webkit-scrollbar-thumb:hover { background: #565f89; }

/* --- Responsive Styles --- */
@media (max-width: 768px) {
    body { padding: 0; }
    .container.game-container { max-width: 100%; width: 100%; padding: 10px; margin: 0 auto; border-radius: 0; border: none; max-height: none; min-height: 100vh; box-sizing: border-box; }
    .game-header h1 { font-size: 1.6em; }
    .game-header p { font-size: 0.85em; }
    #game-logo { 
        max-width: 110px;
        margin-bottom: 15px;
    }
    #game-log-container { padding: 10px; margin-bottom: 10px; }
    .log-entry { margin-bottom: 20px; padding-bottom: 20px;}
    .narrative-text { font-size: 1.05em; line-height: 1.7; }
    .user-action-display { font-size: 0.95em; padding-left: 12px; margin-bottom: 12px; }
    .scene-image-container { margin-top: 15px; max-height: 300px; }
    .audio-control-button { padding: 1px 2px; min-width: 1.1em; min-height: 1.1em; }
    .audio-control-button svg.icon { width: 0.5em; height: 0.5em; }
    .spinner-audio { width: 0.4em; height: 0.4em; border-width: 1px;}

    #interaction-area { padding: 12px; border-radius: 0; }
    #action-form { flex-direction: column; gap: 10px; }
    #action-form .form-group { width: 100%; }
    #action-form input[type="text"]#user-input { font-size: 1em; padding: 12px 14px; }
    #action-form button[type="submit"]#action-button {
        width: 100%;
        padding: 12px 18px;
        font-size: 1.05em;
    }

    /* Mobile Action Choices: Horizontal scrolling */
    .choices-wrapper {
        display: flex;
        flex-direction: row;
        overflow-x: auto;
        overflow-y: hidden;
        white-space: nowrap;
        padding-bottom: 10px;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none; /* Firefox */
        -ms-overflow-style: none; /* IE and Edge */
    }
    .choices-wrapper::-webkit-scrollbar {
        display: none; /* Chrome, Safari, Opera */
    }
    .action-choice-button {
        flex: 0 0 auto;
        max-width: none;
        margin-right: 10px;
        margin-bottom: 0;
        text-align: center;
        min-width: min-content; /* 确保按钮内容决定最小宽度 */
        box-sizing: border-box; /* 确保内边距计入宽度 */
    }
    .action-choice-button:last-child {
        margin-right: 10px; /* 保持与其他按钮相同的右边距 */
    }
    .action-choice-button:nth-child(n+3) {
        display: block !important; /* Show all choices */
    }
    .action-choices p { font-size: 0.9em; text-align: center; margin-bottom: 10px; }
    /* Hide the toggle button */
    #toggle-choices-button {
        display: none !important; /* Force hide on mobile */
    }

    .image-error-overlay .error-text { font-size: 0.85em; }
    .retry-button { font-size: 0.85em; padding: 6px 10px; }

    .game-footer { justify-content: center; margin-top: 15px; padding-top: 10px; font-size: 0.8em; }
    button#toggle-settings {
        width: auto;
        padding: 8px 16px;
        font-size: 1em;
        align-self: center;
    }

    /* Settings Panel Mobile */
    .settings-panel {
        position: fixed; bottom: 0; left: 0; right: 0; width: 100%;
        margin-top: 0; box-sizing: border-box; box-shadow: 0 -3px 10px rgba(0,0,0,0.3);
        border-top: 1px solid var(--border-color); border-bottom: none; border-left: none; border-right: none;
        border-radius: 15px 15px 0 0; z-index: 50; max-height: 85vh; overflow-y: auto;
        padding: 20px; padding-top: 50px; visibility: hidden; opacity: 1;
        transform: translateY(100%); transition: transform 0.3s ease-out, visibility 0s 0.3s;
        background-color: var(--panel-bg);
    }
    .settings-panel.visible { transform: translateY(0%); visibility: visible; transition: transform 0.3s ease-out, visibility 0s 0s; }
    .settings-panel h3 { font-size: 1.2em; text-align: center; margin-bottom: 15px; margin-right: 35px; }
    .settings-panel label { font-size: 0.95em; }
    .settings-panel select, .settings-panel input[type="text"] { font-size: 1em; padding: 11px 12px;}
    .close-settings-btn { display: block; top: 15px; right: 18px; font-size: 1.8em; color: #787c99; }

    /* Start screen Advanced Options button mobile */
    .toggle-advanced-button {
        font-size: 0.95em; text-align: center; background-color: var(--input-bg);
        padding: 10px 15px; border-radius: 6px; border: 1px solid var(--border-color);
        margin-bottom: 15px; color: var(--accent-alt); display: block;
        width: calc(100% - 4px); margin-left: auto; margin-right: auto; box-sizing: border-box;
    }
     .toggle-advanced-button:hover { background-color: #303650; color: #ffbb96;}
     #advanced-options-wrapper { margin-top: 15px; margin-bottom: 15px; padding-top: 10px; border-top: none; }

    /* Start screen mobile adjustments */
    #game-start-screen { padding: 20px 10px; }
    .start-form { padding: 20px; }
    .start-form input[type="text"]#game-name-input { font-size: 1.05em; }
    .start-buttons { flex-direction: column; gap: 10px; }
    .start-buttons button { width: 100%; font-size: 1.05em; padding: 12px 18px; }

    /* Mobile Action Choices: Improved Layout */
    #regenerate-button {
        margin-left: 0;  /* 移除左边距 */
        width: 100%;     /* 设置宽度为100% */
        padding: 12px 18px; /* 与开始游戏按钮相同的内边距 */
        font-size: 1.05em;  /* 与开始游戏按钮相同的字体大小 */
    }
    
    /* 调整SVG图标在移动设备下的大小 */
    #regenerate-button svg {
        width: 18px;
        height: 18px;
    }
}

/* Smaller Mobile Screens */
@media (max-width: 400px) {
    .container.game-container { padding: 5px; }
    .game-header h1 { font-size: 1.4em; }
    .narrative-text { font-size: 1em; }
    .action-choice-button { /* Adjust smaller mobile */
        max-width: none; /* 移除百分比宽度限制 */
        font-size: 0.85em;
        padding: 8px 10px;
        margin-right: 10px; /* 保持与其他按钮相同的右边距 */
        margin-bottom: 0; /* 移除底部边距 */
        border-radius: 18px; /* Adjust radius */
        min-width: min-content; /* 确保按钮内容决定最小宽度 */
        box-sizing: border-box; /* 确保内边距计入宽度 */
    }
    /* Toggle button hidden anyway */
    #action-form input[type="text"]#user-input { font-size: 0.9em; padding: 11px 12px; }
    #action-form button[type="submit"]#action-button { font-size: 1em; padding: 11px 15px; }
    #game-logo { max-width: 80px; }
    .start-form { padding: 15px; }
    .start-buttons button { font-size: 1em; padding: 12px 15px; }
    .settings-panel { padding: 15px; padding-top: 45px; }
    .settings-panel h3 { font-size: 1.1em; }
    .settings-panel label { font-size: 0.9em; }
    .settings-panel select, .settings-panel input[type="text"] { font-size: 0.95em; padding: 10px; }
    .close-settings-btn { top: 12px; right: 12px; font-size: 1.6em; }

    /* Mobile Action Choices: Improved Layout */
    #regenerate-button {
        font-size: 1em;   /* 与开始游戏按钮相同的字体大小 */
        padding: 12px 15px; /* 与开始游戏按钮相同的内边距 */
    }
}

/* Desktop-specific overrides */
@media (min-width: 769px) {
    .close-settings-btn { display: none; }
     /* Reset settings panel */
     .settings-panel {
        position: absolute; bottom: 60px; right: 25px; width: 320px;
        max-height: none; border-radius: 8px;
        transform: translateY(10px) scale(0.98); opacity: 0; visibility: hidden;
        transition: opacity 0.2s ease-out, transform 0.2s ease-out, visibility 0s 0.2s;
        padding: 20px; left: auto; top: auto; border: 1px solid var(--border-color);
    }
     .settings-panel.visible { transform: translateY(0) scale(1); opacity: 1; visibility: visible; transition: opacity 0.2s ease-out, transform 0.2s ease-out, visibility 0s 0s; }
    .settings-panel h3 { text-align: left; }

    /* Reset advanced options toggle button */
     .toggle-advanced-button {
        font-size: 0.9em; text-align: left; background: none;
        padding: 5px 0; border: none; margin-bottom: 15px;
        color: var(--accent-alt); display: block; width: 100%;
        transition: color var(--transition-speed); cursor: pointer;
    }
     .toggle-advanced-button:hover { background: none; color: #ffbb96; }
      #advanced-options-wrapper { margin: 20px 0 25px 0; padding-top: 15px; border-top: 1px dashed var(--border-color); }

    /* Desktop Action Choices: Improved Layout */
    .choices-wrapper {
        display: flex;
        flex-wrap: wrap;
        justify-content: center;
        gap: 10px;
    }
    .action-choice-button {
        flex: 0 1 auto;
        max-width: none;
    }
}

/* --- Additional Responsive Optimizations --- */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* High DPI Display Optimizations */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .scene-image-container img {
        image-rendering: -webkit-optimize-contrast;
        image-rendering: crisp-edges;
    }
}

/* Dark Mode Preference */
@media (prefers-color-scheme: dark) {
    :root {
        --bg-color: #0d1117;
        --panel-bg: #161b22;
        --text-color: #c9d1d9;
        --border-color: #30363d;
        --input-bg: #21262d;
    }
}

/* Performance Improvements */
.log-entry, .action-choice-button, .narrative-container {
    contain: layout style;
}

/* Touch Device Optimizations */
@media (pointer: coarse) {
    .action-choice-button {
        min-height: 44px;
        padding: 12px 18px;
    }
    
    button, input, select, textarea {
        min-height: 44px;
    }
    
    .audio-control-button {
        min-width: 44px;
        min-height: 44px;
        padding: 8px;
    }
}

/* Print Styles */
@media print {
    .settings-panel, .game-footer, #interaction-area {
        display: none !important;
    }
    
    .container.game-container {
        box-shadow: none;
        border: 1px solid #000;
    }
    
    .narrative-text {
         color: #000 !important;
         background: #fff !important;
     }
 }

 /* --- Accessibility Improvements --- */
 .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;
 }

 /* Skip to content link */
 .skip-link {
     position: absolute;
     top: -40px;
     left: 6px;
     background: var(--accent-color);
     color: white;
     padding: 8px;
     text-decoration: none;
     border-radius: 4px;
     z-index: 1000;
 }

 .skip-link:focus {
     top: 6px;
 }

 /* High contrast mode support */
 @media (prefers-contrast: high) {
     :root {
         --bg-color: #000;
         --panel-bg: #000;
         --text-color: #fff;
         --border-color: #fff;
         --accent-color: #00ff00;
     }
 }

 /* Focus indicators */
 button:focus-visible,
 input:focus-visible,
 select:focus-visible,
 textarea:focus-visible {
     outline: 2px solid var(--accent-color);
     outline-offset: 2px;
 }
        border-radius: 20px;
        text-align: center;
        font-size: 0.95em;
        padding: 9px 18px;
    }
    /* Always hide toggle button on desktop */
    #toggle-choices-button {
        display: none !important;
    }
    /* All action choices are visible */
    .action-choice-button.hidden-choice {
        display: block !important;
    }
    /* Hover effects restored via @media hover rule */
}

#advanced-options-content input[type="text"] { 
    background-color: #2a2f41; 
    border: 1px solid var(--border-color); 
    color: var(--text-color); 
    width: 100%; 
    padding: 10px 12px; 
    border-radius: 6px; 
    font-size: 0.95em; 
    box-sizing: border-box;
}