:root {
    --primary-color: #5A67D8; /* Soft Indigo */
    --primary-dark: #434190;
    --primary-light: #EBF4FF;
    --accent-color: #ED8936; /* Warm Orange for highlights */
    --text-primary: #2D3748;
    --text-secondary: #718096;
    --bg-body: #F7FAFC;
    --bg-panel: #FFFFFF;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-full: 9999px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif;
    background-color: var(--bg-body);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.container {
    background: var(--bg-panel);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 1200px;
    padding: 40px;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.main-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
}

@media (max-width: 1000px) {
    .main-layout {
        grid-template-columns: 1fr;
    }
}

header {
    text-align: center;
    padding-bottom: 24px;
    border-bottom: 1px solid var(--primary-light);
}

header h1 {
    font-size: 2em;
    color: var(--primary-color);
    font-weight: 700;
    letter-spacing: -0.5px;
}

/* Chat Interface */
.chat-container {
    background: #F8FAFC;
    border: 1px solid #E2E8F0;
    border-radius: var(--radius-md);
    padding: 24px;
    min-height: 400px;
    max-height: 500px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.chat-messages {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.message {
    display: flex;
    gap: 12px;
    animation: fadeIn 0.3s ease-in;
    max-width: 100%;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.ai-message {
    flex-direction: row;
}

.user-message {
    flex-direction: row-reverse;
}

.avatar {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5em;
    flex-shrink: 0;
    background-color: white;
    box-shadow: var(--shadow-sm);
    border: 1px solid #E2E8F0;
}

.ai-message .avatar {
    color: var(--primary-color);
}

.user-message .avatar {
    background-color: var(--primary-color);
    color: white;
}

.message-content {
    max-width: 75%;
    padding: 12px 16px;
    border-radius: var(--radius-md);
    line-height: 1.6;
    font-size: 0.95em;
    box-shadow: var(--shadow-sm);
}

.ai-message .message-content {
    background: white;
    border: 1px solid #E2E8F0;
    border-top-left-radius: 2px;
    color: var(--text-primary);
}

.user-message .message-content {
    background: var(--primary-color);
    color: white;
    border-top-right-radius: 2px;
}

.message-content p {
    margin: 0;
}

/* Controls */
.controls {
    display: flex;
    flex-direction: column;
    gap: 20px;
    padding: 24px;
    background: #F8FAFC;
    border-radius: var(--radius-md);
    border: 1px solid #E2E8F0;
}

.status-indicator {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    font-weight: 500;
    color: var(--text-secondary);
    font-size: 0.9em;
}

.recording-indicator {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #F56565;
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.5; transform: scale(1.2); }
}

.hidden {
    display: none !important;
}

.button-group {
    display: flex;
    gap: 12px;
    justify-content: center;
    flex-wrap: wrap;
}

/* Buttons - Unified Style */
.btn {
    padding: 12px 24px;
    border: none;
    border-radius: var(--radius-md);
    font-size: 0.95em;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s ease;
    outline: none;
}

.btn:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn:active {
    transform: translateY(0);
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.btn-icon {
    font-size: 1.2em;
}

/* Primary Button (Start, Record) */
.btn-primary, .btn-record {
    background-color: var(--primary-color);
    color: white;
}

.btn-primary:hover, .btn-record:hover {
    background-color: var(--primary-dark);
}

/* Record Active State */
.btn-record.recording {
    background-color: #F56565;
    animation: pulse-shadow 1.5s infinite;
}

@keyframes pulse-shadow {
    0% { box-shadow: 0 0 0 0 rgba(245, 101, 101, 0.7); }
    70% { box-shadow: 0 0 0 10px rgba(245, 101, 101, 0); }
    100% { box-shadow: 0 0 0 0 rgba(245, 101, 101, 0); }
}

/* Secondary Button (Stop, Settings, Close, Cancel) */
.btn-secondary {
    background-color: white;
    color: var(--text-primary);
    border: 1px solid #CBD5E0;
}

.btn-secondary:hover {
    background-color: #F7FAFC;
    border-color: #A0AEC0;
}

/* Test/Action Buttons (Small actions) */
.btn-test {
    padding: 5px 10px; /* Even more reduced padding */
    background-color: var(--primary-light);
    color: var(--primary-dark);
    border: 1px solid transparent;
    font-size: 0.75em; /* Even smaller font */
}

.btn-test:hover {
    background-color: #E2E8F0;
}

/* Bookshelf Panel */
.bookshelf-panel {
    background: #F8FAFC;
    border-radius: var(--radius-md);
    border: 1px solid #E2E8F0;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.bookshelf-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 12px;
    border-bottom: 1px solid #E2E8F0;
}

.bookshelf-header h3 {
    margin: 0;
    color: var(--primary-color);
    font-size: 1.1em;
    font-weight: 600;
}

.bookshelf-container {
    position: relative;
    width: 100%;
    background: #EDF2F7;
    border-radius: var(--radius-md);
    overflow: hidden;
    border: 1px solid #E2E8F0;
}

/* 主页显示：与对话框高度一致 */
.bookshelf-default-display {
    min-height: 400px;
    max-height: 500px;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

.bookshelf-default-display .bookshelf-container {
    max-height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.bookshelf-default-display .bookshelf-container img {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
    display: block;
}

.bookshelf-edit-layout {
    display: grid;
    grid-template-columns: minmax(600px, 1fr) 420px;
    gap: 24px;
    align-items: start;
    margin-top: 10px;
}

.bookshelf-container-edit {
    position: relative;
    background: #EDF2F7;
    border-radius: var(--radius-md);
    overflow: hidden;
    border: 1px solid #E2E8F0;
    min-height: 500px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.bookshelf-container-edit img {
    max-width: 100%;
    max-height: 80vh;
    width: auto;
    height: auto;
    display: block;
    border-radius: 8px;
}

.bookshelf-container-edit canvas {
    position: absolute;
    pointer-events: auto;
    cursor: crosshair;
    /* 位置和尺寸由JS动态设置，确保完全覆盖图片 */
}

.book-editor-panel {
    padding: 24px;
    background: white;
    border-radius: var(--radius-md);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    position: sticky;
    top: 20px;
    max-height: calc(100vh - 40px);
    overflow-y: auto;
    border: 1px solid #E2E8F0;
}

@media (max-width: 1200px) {
    .bookshelf-edit-layout {
        grid-template-columns: 1fr;
    }
    
    .book-editor-panel {
        position: relative;
        top: 0;
        max-height: none;
    }
}

/* Settings Panel */
.settings-panel {
    position: fixed;
    top: 0;
    right: 0;
    width: 380px; /* Reduced width */
    height: 100vh;
    background: linear-gradient(to bottom, #FFFFFF 0%, #F8FAFC 100%);
    box-shadow: -8px 0 40px rgba(90, 103, 216, 0.12), -2px 0 10px rgba(0, 0, 0, 0.06);
    padding: 12px; /* Even more reduced padding */
    display: flex;
    flex-direction: column;
    z-index: 1000;
    transform: translateX(0); /* Controlled by JS */
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border-left: 1px solid rgba(90, 103, 216, 0.1);
}

.settings-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px; /* Even more reduced margin */
    padding-bottom: 6px; /* Even more reduced padding */
    border-bottom: 2px solid #E2E8F0;
    position: relative;
}

.settings-header::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 0;
    width: 60px;
    height: 2px;
    background: linear-gradient(to right, var(--primary-color), transparent);
}

.settings-header h3 {
    margin: 0;
    color: var(--primary-color);
    font-size: 1.1em; /* Further reduced */
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 6px; /* Reduced gap */
}

.settings-header h3::before {
    content: '⚙️';
    font-size: 1.1em;
    margin-right: 4px;
}

.settings-content {
    flex-grow: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 6px; /* Even more reduced gap */
    padding-right: 4px;
}

.settings-content::-webkit-scrollbar {
    width: 6px;
}

.settings-content::-webkit-scrollbar-track {
    background: transparent;
    margin: 8px 0;
}

.settings-content::-webkit-scrollbar-thumb {
    background: linear-gradient(to bottom, var(--primary-color), var(--primary-dark));
    border-radius: 10px;
    border: 2px solid transparent;
    background-clip: padding-box;
}

.settings-content::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(to bottom, var(--primary-dark), var(--primary-color));
    background-clip: padding-box;
}

.settings-section {
    padding: 6px; /* Even more reduced padding */
    background: white;
    border: 1px solid #E2E8F0;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.settings-section::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 3px; /* Slightly thinner */
    height: 100%;
    background: linear-gradient(to bottom, var(--primary-color), var(--accent-color));
    opacity: 0;
    transition: opacity 0.3s ease;
}

.settings-section:hover {
    border-color: var(--primary-light);
    box-shadow: var(--shadow-md);
    transform: translateX(-1px);
}

.settings-section:hover::before {
    opacity: 1;
}

.settings-section h4 {
    margin: 0 0 4px 0; /* Even more reduced margin */
    color: var(--text-primary);
    font-size: 0.85em; /* Even smaller font */
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 4px; /* Reduced gap */
}

.settings-section h4::before {
    content: '';
    width: 6px;
    height: 6px;
    background: var(--primary-color);
    border-radius: 50%;
    box-shadow: 0 0 0 3px var(--primary-light);
}

.settings-section label {
    display: flex;
    align-items: center;
    color: var(--text-primary);
    font-size: 0.9em; /* Slightly smaller */
    gap: 8px;
    cursor: pointer;
    padding: 4px 0; /* Reduced padding */
    transition: color 0.2s ease;
}

.settings-section label:hover {
    color: var(--primary-color);
}

.settings-section p {
    margin: 8px 0 0 0; /* Reduced margin */
    color: var(--text-secondary);
    font-size: 0.8em;
    line-height: 1.4;
}

/* Settings Section Title */
.settings-section-title {
    margin: 0 0 4px 0; /* Even more reduced margin */
    color: var(--text-primary);
    font-size: 0.8em; /* Even smaller font */
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 4px; /* Reduced gap */
}

/* Settings Row */
.settings-row {
    margin-bottom: 4px; /* Even more reduced margin */
    display: flex;
    align-items: center;
}

.settings-row:last-child {
    margin-bottom: 0;
}

/* Settings Label */
.settings-label {
    display: flex;
    align-items: center;
    gap: 5px; /* Even more reduced gap */
    width: 100%;
    color: var(--text-primary);
    font-size: 0.8em; /* Even smaller font */
    cursor: pointer;
    padding: 3px 0; /* Even more reduced padding */
}

.settings-icon {
    font-size: 0.9em; /* Even smaller icon */
    width: 18px; /* Even smaller width */
    text-align: center;
    flex-shrink: 0;
}

.settings-text {
    flex: 1;
    font-weight: 500;
    color: var(--text-primary);
}

/* Settings Select */
.settings-select {
    flex: 1;
    min-width: 120px;
    padding: 4px 6px; /* Even more reduced padding */
    border: 1px solid #E2E8F0;
    border-radius: 6px;
    font-size: 0.8em; /* Even smaller font */
    background: white;
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.2s ease;
}

.settings-select:hover {
    border-color: var(--primary-light);
}

.settings-select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(90, 103, 216, 0.1);
}

/* Greeting Display */
.greeting-display {
    width: 100%;
    padding: 4px 8px; /* Even more reduced padding */
    background: #F8FAFC;
    border: 1px solid #E2E8F0;
    border-radius: 6px;
    font-size: 0.75em; /* Even smaller font */
    color: #666;
    min-height: 24px; /* Even more reduced height */
    max-height: 40px; /* Even more reduced max height */
    overflow-y: auto;
    line-height: 1.3; /* Even tighter line height */
    word-wrap: break-word;
}

.greeting-input {
    width: 100%;
    padding: 4px 8px; /* Even more reduced padding */
    border: 1px solid #E2E8F0;
    border-radius: 6px;
    font-size: 0.75em; /* Even smaller font */
    min-height: 40px; /* Even more reduced height */
    resize: vertical;
    font-family: inherit;
    line-height: 1.3; /* Even tighter line height */
}

.greeting-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(90, 103, 216, 0.1);
}

/* Opacity Slider */
.opacity-slider {
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: #E2E8F0;
    outline: none;
    -webkit-appearance: none;
    appearance: none;
}

.opacity-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--primary-color);
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    transition: all 0.2s ease;
}

.opacity-slider::-webkit-slider-thumb:hover {
    background: var(--primary-dark);
    transform: scale(1.1);
}

.opacity-slider::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--primary-color);
    cursor: pointer;
    border: none;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    transition: all 0.2s ease;
}

.opacity-slider::-moz-range-thumb:hover {
    background: var(--primary-dark);
    transform: scale(1.1);
}

/* Settings Hint */
.settings-hint {
    font-size: 0.75em; /* Smaller font */
    color: #718096;
    margin: 4px 0 0 0; /* Reduced margin */
    line-height: 1.3; /* Tighter line height */
}

/* Info Panel */
.info-panel {
    display: flex;
    justify-content: center;
    gap: 30px;
    padding: 16px;
    background: #F8FAFC;
    border-top: 1px solid #E2E8F0;
    border-radius: var(--radius-md);
    font-size: 0.9em;
    color: var(--text-secondary);
}

.info-item span:last-child {
    color: var(--primary-color);
    font-weight: 600;
    margin-left: 6px;
}

/* Form Elements */
input[type="text"],
input[type="number"],
textarea,
select {
    border: 2px solid #E2E8F0;
    border-radius: var(--radius-md);
    padding: 10px 14px;
    font-family: inherit;
    font-size: 0.95em;
    transition: all 0.3s ease;
    background: white;
    width: 100%;
}

input:hover,
textarea:hover,
select:hover {
    border-color: #CBD5E0;
}

input:focus,
textarea:focus,
select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 4px var(--primary-light);
    background: white;
}

input[type="checkbox"] {
    width: 20px;
    height: 20px;
    border: 2px solid #CBD5E0;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
    appearance: none;
    background: white;
    position: relative;
}

input[type="checkbox"]:hover {
    border-color: var(--primary-color);
}

input[type="checkbox"]:checked {
    background: var(--primary-color);
    border-color: var(--primary-color);
}

input[type="checkbox"]:checked::after {
    content: '✓';
    position: absolute;
    color: white;
    font-size: 14px;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

input[type="range"] {
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: #E2E8F0;
    outline: none;
    appearance: none;
}

input[type="range"]::-webkit-slider-thumb {
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--primary-color);
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    transition: all 0.2s ease;
}

input[type="range"]::-webkit-slider-thumb:hover {
    background: var(--primary-dark);
    transform: scale(1.1);
    box-shadow: 0 3px 8px rgba(90, 103, 216, 0.4);
}

input[type="range"]::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--primary-color);
    cursor: pointer;
    border: none;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    transition: all 0.2s ease;
}

input[type="range"]::-moz-range-thumb:hover {
    background: var(--primary-dark);
    transform: scale(1.1);
    box-shadow: 0 3px 8px rgba(90, 103, 216, 0.4);
}

select {
    cursor: pointer;
    padding-right: 35px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%235A67D8' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 12px;
    appearance: none;
}

textarea {
    min-height: 80px;
    resize: vertical;
    line-height: 1.5;
}

/* Scrollbars */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: #CBD5E0;
    border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
    background: #A0AEC0;
}