* {
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: #f4f7f6;
    color: #333;
    line-height: 1.6;
    margin: 0;
    height: 100vh;
    overflow: hidden;
}

.app-shell {
    width: 100%;
    height: 100%;
    padding: 20px;
    display: flex;
    flex-direction: column;
}

.top-box {
    background: #fff;
    border-radius: 8px;
    padding: 16px 20px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.08);
    margin-bottom: 16px;
}

.top-box-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.top-box h1 {
    margin: 0;
    text-align: left;
    font-size: 24px;
}

.top-menu {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: nowrap;
    gap: 16px;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid #e7edf2;
}

.top-menu-left {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    min-width: 0;
}

.top-menu-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 0 0 auto;
    margin-left: auto;
    white-space: nowrap;
}

.language-switcher {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.menu-label {
    font-size: 13px;
    font-weight: 700;
    color: #34495e;
    margin: 0;
}

.language-options {
    display: inline-flex;
    gap: 8px;
}

.lang-option,
.menu-link {
    width: auto;
    margin: 0;
    padding: 10px 14px;
    font-size: 14px;
    line-height: 1;
}

.lang-option {
    background: #edf6fb;
    color: #225f8f;
    border: 1px solid #bfd9ec;
}

.lang-option:hover {
    background: #e1f0fa;
}

.lang-option.active {
    background: #2d7fbf;
    border-color: #2d7fbf;
    color: #fff;
}

.menu-link {
    background: #f5f7fa;
    color: #2c3e50;
    border: 1px solid #d9e0e7;
    border-radius: 4px;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

#download-btn {
    background: #edf6fb;
    color: #225f8f;
    border-color: #bfd9ec;
}

.menu-link:hover {
    background: #e9eef3;
}

#download-btn:hover {
    background: #e1f0fa;
}

.compact-actions {
    position: relative;
    display: none;
}

.menu-icon-btn {
    width: 40px;
    min-width: 40px;
    height: 36px;
    padding: 8px;
}

.menu-icon-btn svg {
    width: 18px;
    height: 18px;
}

.menu-actions-popup {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    min-width: 170px;
    background: #fff;
    border: 1px solid #d9e0e7;
    border-radius: 6px;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.12);
    padding: 6px;
    z-index: 30;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.menu-actions-item {
    width: 100%;
    margin: 0;
    text-align: left;
    padding: 10px 12px;
    border-radius: 4px;
    border: 1px solid transparent;
    background: #f8fafc;
    color: #2c3e50;
    font-size: 14px;
    line-height: 1.1;
}

.menu-actions-item:hover {
    background: #eef3f7;
}

.main-layout {
    display: grid;
    grid-template-columns: 280px minmax(0, 1fr);
    gap: 16px;
    flex: 1;
    min-height: 0;
}

.scene-sidebar {
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.08);
    padding: 16px;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.admin-panel {
    border: 1px solid #dbe5eb;
    border-radius: 6px;
    padding: 12px;
    margin-bottom: 16px;
    background: #fdfefe;
}

.admin-panel h2 {
    margin: 0 0 12px;
    font-size: 18px;
    color: #2c3e50;
}

#admin-process-btn {
    margin: 0;
}

.scene-sidebar h2 {
    margin: 0 0 12px;
    font-size: 18px;
    color: #2c3e50;
}

.scene-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
}

.scene-item {
    border: 1px solid #dbe5eb;
    border-radius: 6px;
    padding: 10px;
    background: #fdfefe;
}

.scene-item.active {
    background: #f1f3f5;
    border: 3px solid #9aa3ad;
}

.scene-item-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 8px;
}

.scene-item-title {
    font-weight: 700;
    color: #2c3e50;
    margin-bottom: 4px;
}

.scene-item-link {
    color: inherit;
    text-decoration: none;
    outline: none;
    box-shadow: none;
    border: none;
}

.scene-item-link:hover {
    text-decoration: underline;
}

.scene-item-link:focus,
.scene-item-link:focus-visible,
.scene-item-link:active {
    outline: none;
    box-shadow: none;
    border: none;
}

.scene-item-meta {
    font-size: 12px;
    color: #6c7b88;
}

.scene-delete-btn {
    width: 28px;
    height: 28px;
    margin: 0;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    color: #c0392b;
    border: 1px solid #e0b4b0;
    border-radius: 4px;
    cursor: pointer;
    flex: 0 0 auto;
}

.scene-delete-btn:hover {
    background-color: #fcebea;
    color: #a93226;
}

.scene-empty {
    color: #7f8c8d;
    font-size: 14px;
}

.workspace {
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.08);
    padding: 20px;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.processing-panel {
    border: 1px solid #e7edf2;
    border-radius: 6px;
    padding: 14px;
    margin-bottom: 16px;
    background: #fbfdff;
}

h1 {
    color: #2c3e50;
    text-align: center;
    margin-bottom: 10px;
}

p {
    text-align: center;
    color: #7f8c8d;
    margin-bottom: 20px;
}

.form-group {
    margin-bottom: 20px;
}

.action-row {
    display: flex;
    align-items: center;
    gap: 12px;
}

.action-row #process-btn {
    flex: 1;
    margin: 0;
}

.debug-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    font-weight: 700;
    color: #2c3e50;
    white-space: nowrap;
}

.debug-toggle input[type="checkbox"] {
    width: 16px;
    height: 16px;
}

label {
    display: block;
    margin-bottom: 8px;
    font-weight: bold;
    color: #34495e;
}

input[type="text"] {
    width: 100%;
    padding: 12px;
    border: 1px solid #ccc;
    border-radius: 4px;
    box-sizing: border-box;
    font-size: 16px;
}

textarea {
    width: 100%;
    padding: 12px;
    border: 1px solid #ccc;
    border-radius: 4px;
    box-sizing: border-box;
    font-size: 14px;
    font-family: Consolas, "Courier New", monospace;
    resize: vertical;
    background: #fcfcfc;
}

button {
    width: 100%;
    background-color: #3498db;
    color: white;
    padding: 14px 20px;
    margin: 8px 0;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 16px;
    transition: background-color 0.3s;
}

button:hover {
    background-color: #2980b9;
}

button:disabled {
    background-color: #95a5a6;
    cursor: not-allowed;
}

.player-controls {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 8px;
    margin-bottom: 12px;
}

.player-controls button {
    margin: 0;
    padding: 8px;
    min-height: 56px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.player-controls button svg {
    width: 30px;
    height: 30px;
}

.hidden {
    display: none !important;
}

#loader {
    text-align: center;
    margin-top: 20px;
}

.spinner {
    border: 4px solid rgba(0, 0, 0, 0.1);
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border-left-color: #3498db;
    animation: spin 1s linear infinite;
    margin: 0 auto;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

#result {
    margin-top: 0;
    border-top: 1px solid #eee;
    padding-top: 20px;
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

#scene-meta {
    background: #f9fcff;
    border: 1px solid #d8edf8;
    border-radius: 6px;
    padding: 12px;
    margin-bottom: 12px;
    font-size: 14px;
}

.scene-title,
.scene-characters,
.scene-count {
    margin-bottom: 4px;
}

audio {
    display: none;
}

#scene-meta {
    background: #f9fcff;
    border: 1px solid #d8edf8;
    border-radius: 6px;
    padding: 12px;
    margin-bottom: 12px;
    font-size: 14px;
}

.scene-meta-layout {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
}

.scene-meta-main {
    min-width: 0;
    flex: 1;
}

.scene-character-row {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin-top: 8px;
}

.scene-character-links {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 10px;
}

.scene-character-link {
    color: #225f8f;
    text-decoration: none;
    font-weight: 400;
    cursor: pointer;
}

.scene-character-link:hover {
    text-decoration: underline;
}

.scene-character-link.active {
    color: #2d7fbf;
    text-decoration: none;
}

.scene-selected-character {
    margin-top: 8px;
    font-size: 13px;
    color: #4f6479;
}

.scene-meta-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex: 0 0 auto;
    align-items: stretch;
}

.scene-meta-btn {
    width: auto;
    margin: 0;
    padding: 10px 14px;
    min-width: 120px;
    font-size: 14px;
    line-height: 1;
}

.scene-download-btn {
    background: #f5f7fa;
    color: #2c3e50;
    border: 1px solid #d9e0e7;
}

.scene-download-btn:hover {
    background: #e9eef3;
}

.scene-speed-control {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 10px 12px;
    min-width: 180px;
    border: 1px solid #d9e0e7;
    border-radius: 6px;
    background: #f5f7fa;
    color: #2c3e50;
}

.scene-speed-control-label {
    font-size: 12px;
    font-weight: 600;
    line-height: 1;
    color: #4f6479;
}

.scene-speed-input {
    width: 100%;
    margin: 0;
    color: #d9e0e7;
    accent-color: #9aa3ad;
}

.scene-speed-value {
    font-size: 13px;
    line-height: 1;
    font-weight: 600;
    text-align: right;
    color: #2c3e50;
}

.scene-turn-prompt {
    margin-left: 10px;
    font-size: 14px;
    font-weight: 700;
    color: #c0392b;
}

.error {
    color: #e74c3c;
    background-color: #fadbd8;
    padding: 15px;
    border-radius: 4px;
    margin-top: 20px;
    border: 1px solid #e74c3c;
    white-space: pre-line;
}

#parsed-text {
    flex: 1;
    min-height: 0;
    max-height: none;
    overflow-y: auto;
    background: #f9f9f9;
    padding: 10px;
    border-radius: 4px;
    border: 1px solid #ddd;
    font-size: 14px;
}

.dialogue-line {
    margin-bottom: 8px;
    padding: 8px;
    border-radius: 4px;
    display: flex;
    gap: 8px;
    align-items: flex-start;
}

.dialogue-line.active {
    background: #ebf5ff;
    border: 1px solid #bfddff;
}

.dialogue-line.active.own-speaker {
    background: #fff6c9;
    border: 1px solid #ead98a;
}

.speaker {
    font-weight: bold;
    color: #2980b9;
}

.line-play-btn {
    width: auto;
    margin: 0;
    padding: 6px 10px;
    font-size: 12px;
    background-color: #5f9ea0;
    border-radius: 4px;
    flex: 0 0 auto;
}

.line-play-btn:hover {
    background-color: #4f8a8c;
}

.dialogue-text {
    flex: 1;
}

@media (max-width: 980px) {
    body {
        height: auto;
        overflow: auto;
    }

    .app-shell {
        height: auto;
    }

    .main-layout {
        grid-template-columns: 1fr;
        flex: 0 0 auto;
    }

    .scene-sidebar {
        min-height: auto;
    }

    .workspace {
        min-height: auto;
    }

    .top-box-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .top-menu {
        align-items: flex-start;
    }

    .top-box h1 {
        font-size: 22px;
    }
}

@media (max-width: 560px) {
    #download-btn,
    #login-btn {
        display: none;
    }

    .compact-actions {
        display: block;
    }
}

