:root {
    --bg-color-dark: #121212;
    --bg-color-medium: #1e1e1e;
    --bg-color-light: #2a2a2a;
    --text-color-primary: #e0e0e0;
    --text-color-secondary: #a0a0a0;
    --accent-color: #00aaff;
    --accent-color-hover: #0088cc;
    --border-color: #383838;
    --error-color: #ff4d4d;
    --font-family: 'Inter', sans-serif;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-family);
    background-color: var(--bg-color-dark);
    color: var(--text-color-primary);
    font-size: 14px;
    line-height: 1.5;
    overflow: hidden;
}

.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 24px;
    background-color: var(--bg-color-medium);
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.app-header h1 {
    font-size: 18px;
    font-weight: 600;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.save-button {
    background-color: #4a4a4a; /* Gray when disabled */
    color: #888;
    border: none;
    padding: 10px 20px;
    border-radius: 6px;
    cursor: not-allowed;
    font-size: 14px;
    font-weight: 500;
    transition: background-color 0.2s ease, color 0.2s ease, cursor 0.2s ease;
    display: flex;
    align-items: center;
    gap: 8px;
}

.save-button:not(:disabled) {
    background-color: #28a745; /* Green when enabled */
    color: white;
    cursor: pointer;
}

.save-button:not(:disabled):hover {
    background-color: #218838;
}

.save-button.saved {
    background-color: #dc3545; /* Red when saved */
    color: white;
    cursor: default;
}

.generate-button {
    background-color: var(--accent-color);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: background-color 0.2s ease;
    display: flex;
    align-items: center;
    gap: 8px;
}

.generate-button:hover {
    background-color: var(--accent-color-hover);
}

.sound-toggle-button {
    background-color: #ffc107; /* 黄色 */
    color: #212529;
    border: none;
    padding: 10px;
    border-radius: 6px;
    cursor: pointer;
    width: 40px;
    height: 40px;
    transition: background-color 0.2s ease, opacity 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sound-toggle-button:hover {
    background-color: #e0a800;
}

.sound-toggle-button.disabled {
    background-color: #6c757d;
    opacity: 0.6;
}

.sound-toggle-button.disabled:hover {
    background-color: #5a6268;
}

.main-content {
    display: grid;
    grid-template-columns: 50fr 50fr;
    grid-template-rows: auto;
    flex-grow: 1;
    height: calc(100vh - 65px);
}

.settings-panel-left {
    background-color: var(--bg-color-medium);
    padding: 20px;
    overflow-y: auto;
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.content-area {
    display: grid;
    grid-template-rows: 55fr 45fr; /* 调整比例，为底部面板提供更多空间 */
    overflow: hidden;
}

.video-panel {
    background-color: var(--bg-color-dark);
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    position: relative;
    overflow: hidden;
}

.video-container {
    width: 100%;
    height: 100%;
    background-color: #000;
    border-radius: 8px;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    overflow: hidden;
}

#generated-video { /* This ID is now deprecated */
    display: none;
}

.carousel {
    display: flex;
    transition: transform 0.5s ease-in-out;
    height: 100%;
}

.carousel-item {
    min-width: 100%;
    height: 100%;
    box-sizing: border-box;
    display: flex;
    justify-content: center;
    align-items: center;
}

.carousel-item video {
    width: 100%;
    height: 100%;
    object-fit: contain;
    border-radius: 8px;
}

.carousel-btn {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background-color: rgba(0, 0, 0, 0.4);
    color: white;
    border: none;
    cursor: pointer;
    padding: 10px;
    border-radius: 50%;
    z-index: 10;
    transition: background-color 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.carousel-btn:hover {
    background-color: rgba(0, 0, 0, 0.7);
}

.carousel-btn.prev {
    left: 16px;
}

.carousel-btn.next {
    right: 16px;
}

.carousel-dots {
    position: absolute;
    bottom: 0px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 8px;
    z-index: 10;
}

.carousel-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background-color: rgba(255, 255, 255, 0.4);
    cursor: pointer;
    transition: background-color 0.3s;
}

.carousel-dot.active {
    background-color: white;
}

.placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    color: var(--text-color-secondary);
}

.placeholder i {
    color: var(--text-color-secondary);
}

.loader {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 10;
    color: white;
    backdrop-filter: blur(5px);
}

.spinner {
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top: 4px solid var(--accent-color);
    width: 50px;
    height: 50px;
    animation: spin 1s linear infinite;
    margin-bottom: 16px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.hidden {
    display: none !important;
}

.settings-panel-bottom {
   background-color: var(--bg-color-medium);
   padding: 20px;
   border-top: 1px solid var(--border-color);
   display: flex; /* Make it a flex container */
   flex-direction: column;
}

.error-message {
    position: absolute;
    bottom: 20px;
    left: 20px;
    right: 20px;
    background-color: var(--error-color);
    color: white;
    padding: 12px;
    border-radius: 6px;
    font-size: 14px;
    z-index: 20;
}

/* Form Styles */
.panel {
   background-color: var(--bg-color-light);
   border-radius: 8px;
   padding: 20px;
   border: 1px solid var(--border-color);
   transition: all 0.3s ease;
   display: flex; /* Added */
   flex-direction: column; /* Added */
   flex-grow: 1; /* Added to make panel fill its parent */
   overflow: visible; /* Allow dropdowns to overflow */
}

.panel:hover {
    border-color: #4a4a4a;
}

.panel-title {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 16px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border-color);
}

.form-group {
    margin-bottom: 16px;
}

.grid-2-col > .form-group,
.grid-3-col > .form-group {
    margin-bottom: 0;
}

.form-group:last-child {
    margin-bottom: 0;
}

.form-group label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 8px;
    color: var(--text-color-secondary);
}

.form-input, .form-select, .form-textarea {
    width: 100%;
    background-color: var(--bg-color-medium);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 10px;
    color: var(--text-color-primary);
    font-size: 14px;
    transition: border-color 0.2s, box-shadow 0.2s;
}

/* Thread count input specific styling */
.switch-group .form-input {
    width: 90px;
    text-align: center;
    padding: 8px;
    flex-shrink: 0;
}

.form-input:focus, .form-select:focus, .form-textarea:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 2px rgba(0, 170, 255, 0.2);
}

textarea.form-input {
    resize: vertical;
}

.grid-2-col {
   display: grid;
   grid-template-columns: 1fr 1fr;
   gap: 16px;
   flex-grow: 1; /* Added */
}

.grid-3-col {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 16px;
}

/* Switch */
.switch-group {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 0; /* Reduced vertical padding */
}

.grid-2-col .switch-group {
    background-color: var(--bg-color-medium);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 10px;
    margin-bottom: 0;
}

.grid-3-col .switch-group {
    background-color: var(--bg-color-medium);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 10px;
    margin-bottom: 0;
}

.switch-group > label {
    margin-bottom: 0; /* Override default label margin */
}

.switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.switch-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--border-color);
    transition: .4s;
    border-radius: 24px;
}

.switch-slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}

input:checked + .switch-slider {
    background-color: var(--accent-color);
}

input:checked + .switch-slider:before {
    transform: translateX(20px);
}


/* File Drop Zone */
.file-drop-group {
    display: flex;
    flex-direction: column;
    height: 100%; /* Ensure the group takes full height of grid cell */
}

.file-drop-zone {
    border: 2px dashed var(--border-color);
    border-radius: 8px;
    padding: 20px;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.3s, background-color 0.3s;
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    flex-grow: 1; /* Allow zone to grow and fill space */
}

.file-drop-zone.dragover {
    border-color: var(--accent-color);
    background-color: rgba(0, 170, 255, 0.1);
}

.file-drop-zone i {
    color: var(--text-color-secondary);
    margin-bottom: 8px;
}

.file-drop-zone p {
    color: var(--text-color-secondary);
    font-size: 12px;
}

.file-drop-prompt {
   display: flex;
   flex-direction: column;
   align-items: center;
   justify-content: center;
   gap: 8px;
   transition: opacity 0.3s ease;
}

.file-input {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
}

.file-preview {
   position: absolute;
   top: 0;
   left: 0;
   width: 100%;
   height: 100%;
   padding: 8px;
   display: none; /* Initially hidden */
   justify-content: center;
   align-items: center;
}

.file-preview img,
.file-preview video {
   max-width: 100%;
   max-height: 100%;
   border-radius: 4px;
   object-fit: cover;
}

.delete-file-btn {
   position: absolute;
   top: 12px;
   right: 12px;
   width: 24px;
   height: 24px;
   background-color: rgba(0, 0, 0, 0.6);
   color: white;
   border: none;
   border-radius: 50%;
   cursor: pointer;
   display: flex;
   justify-content: center;
   align-items: center;
   padding: 0;
   z-index: 10;
   transition: background-color 0.2s, transform 0.2s;
}

.delete-file-btn:hover {
   background-color: rgba(255, 77, 77, 0.9);
   transform: scale(1.1);
}

.file-drop-zone.has-file .file-drop-prompt {
   opacity: 0;
   pointer-events: none;
}

.file-drop-zone.has-file .file-preview {
   display: flex;
}

/* Scrollbar styles */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-color-medium);
}

::-webkit-scrollbar-thumb {
    background: #555;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #777;
}

@media (max-width: 820px) {
   body {
       overflow: auto; /* Allow scrolling on mobile */
   }

   .app-container {
       height: auto;
       min-height: 100vh;
   }

   .main-content {
       display: flex;
       flex-direction: column;
       height: auto;
   }

   /* 移动端：重新排列顺序 - 视频面板优先 */
   .main-content {
       order: 0; /* 确保main-content在header之后 */
   }

   .content-area {
       order: -1; /* 视频区域排在最前 */
       display: flex;
       flex-direction: column;
       overflow: visible;
   }

   .settings-panel-left {
       order: 1; /* 设置面板排在视频区域之后 */
       border-right: none;
       overflow-y: visible;
       padding-bottom: 0;
   }
   
   .video-panel {
       width: 100%;
       aspect-ratio: 16 / 9; /* Ensure a consistent aspect ratio */
       flex-shrink: 0; /* Prevent the panel from shrinking */
   }

   .settings-panel-bottom {
       border-top: 1px solid var(--border-color); /* Keep the border for separation */
   }

   .grid-2-col, .grid-3-col {
       grid-template-columns: 1fr; /* Stack columns */
   }

   .grid-2-col .switch-group {
       /* Adjust switch group to not look weird when stacked */
       justify-content: flex-start;
       gap: 16px;
   }
}
.color-picker-wrapper {
    display: flex;
    align-items: center;
    gap: 8px;
}

.color-picker-wrapper input[type="color"] {
    width: 36px;
    height: 36px;
    border: none;
    padding: 0;
    border-radius: 4px;
    cursor: pointer;
    background-color: transparent;
}

.color-picker-wrapper input[type="color"]::-webkit-color-swatch-wrapper {
    padding: 0;
}

.color-picker-wrapper input[type="color"]::-webkit-color-swatch {
    border: 1px solid var(--border-color);
    border-radius: 4px;
}

.color-picker-wrapper .color-input {
    flex-grow: 1;
}

.hidden {
    display: none !important;
}
.form-group.disabled {
    opacity: 0.5;
    pointer-events: none;
}

/* Prompt Actions */
.prompt-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.prompt-header label {
    margin-bottom: 0; /* Override default */
}

.prompt-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.icon-btn {
    background: none;
    border: none;
    color: var(--text-color-secondary);
    cursor: pointer;
    padding: 4px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s, color 0.2s;
}

.icon-btn:hover {
    background-color: var(--bg-color-light);
    color: var(--text-color-primary);
}

.icon-btn:disabled {
    color: var(--accent-color);
    opacity: 0.7;
    cursor: default;
    background-color: transparent;
}

.saved-prompts-dropdown {
    position: relative;
}

.saved-prompts-list {
    position: absolute;
    top: 100%;
    right: 0;
    background-color: var(--bg-color-light);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    width: 280px;
    max-height: 300px;
    overflow-y: auto;
    z-index: 100;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    margin-top: 8px;
}

.saved-prompts-list.hidden {
    display: none;
}

.saved-prompt-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    cursor: pointer;
    border-bottom: 1px solid var(--border-color);
    transition: background-color 0.2s;
}

.saved-prompt-item:last-child {
    border-bottom: none;
}

.saved-prompt-item:hover {
    background-color: var(--bg-color-medium);
}

.saved-prompt-text {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex-grow: 1;
    margin-right: 12px;
    font-size: 13px;
}

.delete-prompt-btn {
    background: none;
    border: none;
    color: var(--text-color-secondary);
    cursor: pointer;
    padding: 2px;
    border-radius: 4px;
    flex-shrink: 0;
    transition: color 0.2s;
}

.delete-prompt-btn:hover {
    color: var(--error-color);
}

.saved-prompts-list-empty {
    padding: 20px;
    text-align: center;
    color: var(--text-color-secondary);
    font-style: italic;
}
/* --- Key Input Container --- */
.key-input-container {
    position: relative;
    display: flex;
    align-items: center;
    z-index: 2; /* Ensure this container is above its siblings */
}

.key-input-container .form-input {
    padding-right: 80px; /* Make space for buttons */
}

.key-actions {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    gap: 4px;
}

.saved-keys-dropdown {
    position: relative;
}

/* Use the same styles as saved-prompts-list */
.saved-keys-list {
    position: absolute;
    bottom: 120%; /* Position above the button */
    right: 0;
    width: 280px;
    background-color: #3c3c3c;
    border-radius: 8px;
    border: 1px solid #555;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    z-index: 101;
    max-height: 300px;
    overflow-y: auto;
    padding: 6px;
}

.saved-keys-list.hidden {
    display: none;
}

.saved-key-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    border-radius: 6px;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.saved-key-item:hover {
    background-color: #4a4a4a;
}

.saved-key-alias {
    font-weight: 500;
    color: #e0e0e0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex-grow: 1;
}

.saved-key-value {
    font-size: 0.8em;
    color: #999;
    margin-left: 12px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100px; /* Adjust as needed */
}

.delete-key-btn {
    background: none;
    border: none;
    color: #999;
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: color 0.2s ease, background-color 0.2s ease;
}

.delete-key-btn:hover {
    color: #ff6b6b;
    background-color: #4a4a4a;
}

.saved-keys-list-empty {
    padding: 16px;
    text-align: center;
    color: #888;
    font-size: 0.9em;
}

.saved-key-item.preset {
    /* Style for preset keys, e.g., slightly different color */
    /* background-color: #414a41; */
}

.saved-key-item.preset .delete-key-btn {
    display: none; /* Hide delete button for presets */
}