/* CSS Variables for theming */
:root {
    --primary-color: #6366f1;
    --primary-hover: #4f46e5;
    --secondary-color: #64748b;
    --secondary-hover: #475569;
    --danger-color: #ef4444;
    --danger-hover: #dc2626;
    --success-color: #22c55e;
    --background-color: #f8fafc;
    --surface-color: #ffffff;
    --surface-secondary: #f1f5f9;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --border-color: #e2e8f0;
    --shadow-sm: 0 1px 2px 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-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --transition-fast: 150ms ease;
    --transition-normal: 200ms ease;
}

/* Reset & Base */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background-color: var(--background-color);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
}

/* App Container */
.app-container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* Header */
.header {
    background: var(--surface-color);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow-sm);
}

.header-content {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 64px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.logo-img {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
}

.logo h1 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
}

.nav-tabs {
    display: flex;
    gap: 0.5rem;
}

.nav-tab {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.625rem 1rem;
    background: transparent;
    border: none;
    border-radius: var(--radius-md);
    font-size: 0.9375rem;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.nav-tab:hover {
    background: var(--surface-secondary);
    color: var(--text-primary);
}

.nav-tab.active {
    background: var(--primary-color);
    color: white;
}

.tab-icon {
    font-size: 1.125rem;
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.tab-content {
    display: none;
    flex: 1;
}

.tab-content.active {
    display: flex;
}

/* Editor Layout */
.editor-layout {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    width: 300px;
    background: var(--surface-color);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.sidebar-header h2,
.sidebar-header h3 {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Scenes List */
.scenes-list {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem;
}

.scene-item {
    display: flex;
    align-items: center;
    padding: 0.75rem 1rem;
    background: var(--surface-secondary);
    border-radius: var(--radius-md);
    margin-bottom: 0.5rem;
    cursor: pointer;
    transition: all var(--transition-fast);
    border: 2px solid transparent;
}

.scene-item:hover {
    background: var(--border-color);
}

.scene-item.active {
    border-color: var(--primary-color);
    background: rgba(99, 102, 241, 0.1);
}

.scene-item.start-scene::before {
    content: '🚀';
    margin-right: 0.5rem;
}

.scene-item-title {
    flex: 1;
    font-size: 0.9375rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Variables Section */
.variables-section {
    border-top: 1px solid var(--border-color);
    max-height: 200px;
    display: flex;
    flex-direction: column;
}

.variables-list {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem;
}

.variable-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 0.75rem;
    background: var(--surface-secondary);
    border-radius: var(--radius-sm);
    margin-bottom: 0.375rem;
    font-size: 0.875rem;
    cursor: pointer;
    transition: background var(--transition-fast);
}

.variable-item:hover {
    background: var(--border-color);
}

.variable-name {
    font-weight: 500;
    color: var(--primary-color);
}

.variable-value {
    color: var(--text-secondary);
}

/* Story Actions */
.story-actions {
    padding: 1rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

/* Editor Main */
.editor-main {
    flex: 1;
    overflow-y: auto;
    background: var(--background-color);
}

.scene-editor,
.scene-edit-form {
    max-width: 900px;
    margin: 0 auto;
    padding: 2rem;
}

.no-scene-selected {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 400px;
}

.empty-state {
    text-align: center;
    padding: 3rem;
}

.empty-icon {
    font-size: 4rem;
    display: block;
    margin-bottom: 1rem;
}

.empty-state h3 {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

.empty-state p {
    color: var(--text-secondary);
    max-width: 300px;
    margin: 0 auto;
}

/* Form Elements */
.form-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.form-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.scene-title-input {
    font-size: 1.5rem;
    font-weight: 700;
    border: none;
    background: transparent;
    color: var(--text-primary);
    padding: 0.5rem;
    border-radius: var(--radius-md);
    flex: 1;
    min-width: 200px;
}

.scene-title-input:focus {
    outline: none;
    background: var(--surface-color);
    box-shadow: var(--shadow-sm);
}

.form-group {
    margin-bottom: 1.25rem;
}

.form-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.form-group small {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.375rem;
}

input[type="text"],
input[type="number"],
select,
textarea {
    width: 100%;
    padding: 0.75rem 1rem;
    font-size: 0.9375rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--surface-color);
    color: var(--text-primary);
    transition: all var(--transition-fast);
}

input[type="text"]:focus,
input[type="number"]:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

textarea {
    min-height: 200px;
    resize: vertical;
    line-height: 1.7;
}

.scene-content-textarea {
    font-family: 'Georgia', serif;
    font-size: 1rem;
}

/* Toggle */
.start-scene-toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    color: var(--text-secondary);
    cursor: pointer;
}

.start-scene-toggle input {
    width: auto;
    accent-color: var(--primary-color);
}

/* Choices Section */
.choices-section {
    margin-top: 2rem;
    padding-top: 2rem;
    border-top: 1px solid var(--border-color);
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}

.section-header h3,
.section-header h4 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.choices-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.choice-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem;
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.choice-item:hover {
    border-color: var(--primary-color);
    box-shadow: var(--shadow-sm);
}

.choice-text {
    font-weight: 500;
    color: var(--text-primary);
}

.choice-target {
    font-size: 0.875rem;
    color: var(--text-muted);
}

.choice-target::before {
    content: '→ ';
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.625rem 1.25rem;
    font-size: 0.9375rem;
    font-weight: 500;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-sm {
    padding: 0.375rem 0.75rem;
    font-size: 0.8125rem;
}

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

.btn-primary:hover:not(:disabled) {
    background: var(--primary-hover);
}

.btn-secondary {
    background: var(--surface-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--border-color);
}

.btn-danger {
    background: var(--danger-color);
    color: white;
}

.btn-danger:hover:not(:disabled) {
    background: var(--danger-hover);
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 200;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--surface-color);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
}

.modal-sm {
    max-width: 400px;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h3 {
    font-size: 1.125rem;
    font-weight: 600;
}

.modal-close {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    font-size: 1.5rem;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
}

.modal-close:hover {
    background: var(--surface-secondary);
    color: var(--text-primary);
}

.modal-body {
    padding: 1.5rem;
    overflow-y: auto;
}

.modal-footer {
    display: flex;
    justify-content: space-between;
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border-color);
    gap: 0.75rem;
}

/* Variable Changes List */
.var-changes-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.var-change-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem;
    background: var(--surface-secondary);
    border-radius: var(--radius-sm);
}

.var-change-item select,
.var-change-item input {
    flex: 1;
    padding: 0.5rem;
    font-size: 0.875rem;
}

.var-change-remove {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: var(--danger-color);
    cursor: pointer;
    border-radius: var(--radius-sm);
    font-size: 1.125rem;
}

.var-change-remove:hover {
    background: rgba(239, 68, 68, 0.1);
}

/* Play Mode */
.play-container {
    max-width: 800px;
    width: 100%;
    margin: 0 auto;
    padding: 2rem;
    display: flex;
    flex-direction: column;
    flex: 1;
}

.play-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.play-header h2 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
}

.play-variables {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}

.play-variable {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.875rem;
    background: var(--surface-secondary);
    border-radius: var(--radius-md);
    font-size: 0.875rem;
}

.play-variable-name {
    font-weight: 500;
    color: var(--text-secondary);
}

.play-variable-value {
    font-weight: 600;
    color: var(--primary-color);
}

.play-content {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.story-display {
    background: var(--surface-color);
    border-radius: var(--radius-lg);
    padding: 2rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow-md);
    min-height: 200px;
}

.story-display p {
    margin-bottom: 1rem;
    font-family: 'Georgia', serif;
    font-size: 1.125rem;
    line-height: 1.8;
    color: var(--text-primary);
}

.story-display p:last-child {
    margin-bottom: 0;
}

.choices-display {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.play-choice {
    width: 100%;
    padding: 1rem 1.25rem;
    background: var(--surface-color);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 1rem;
    font-weight: 500;
    color: var(--text-primary);
    cursor: pointer;
    transition: all var(--transition-fast);
    text-align: left;
}

.play-choice:hover {
    border-color: var(--primary-color);
    background: rgba(99, 102, 241, 0.05);
    transform: translateX(4px);
}

.story-end {
    text-align: center;
    padding: 3rem;
}

.end-content {
    background: var(--surface-color);
    border-radius: var(--radius-lg);
    padding: 3rem;
    box-shadow: var(--shadow-md);
}

.end-icon {
    font-size: 4rem;
    display: block;
    margin-bottom: 1rem;
}

.end-content h3 {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 0.75rem;
}

.end-content p {
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
}

/* Footer */
.footer {
    background: var(--surface-color);
    border-top: 1px solid var(--border-color);
    padding: 1rem 2rem;
    text-align: center;
}

.footer p {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.footer a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 500;
    transition: color var(--transition-fast);
}

.footer a:hover {
    color: var(--primary-hover);
    text-decoration: underline;
}

/* Notification Toast */
.notification {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--text-primary);
    color: white;
    padding: 0.875rem 1.5rem;
    border-radius: var(--radius-md);
    font-size: 0.9375rem;
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    opacity: 0;
    transition: all 0.3s ease;
    z-index: 300;
}

.notification.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

.notification.success {
    background: var(--success-color);
}

.notification.error {
    background: var(--danger-color);
}

/* Responsive Design */
@media (max-width: 1024px) {
    .editor-layout {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        max-height: 40vh;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
    }

    .scenes-list {
        max-height: 150px;
    }

    .variables-section {
        max-height: 120px;
    }

    .story-actions {
        flex-direction: row;
        flex-wrap: wrap;
    }

    .story-actions .btn {
        flex: 1;
        min-width: 120px;
    }
}

@media (max-width: 768px) {
    .header-content {
        height: auto;
        padding: 0.75rem 1rem;
        flex-direction: column;
        gap: 0.75rem;
    }

    .logo h1 {
        font-size: 1.125rem;
    }

    .nav-tabs {
        width: 100%;
        justify-content: center;
    }

    .nav-tab {
        flex: 1;
        justify-content: center;
    }

    .tab-text {
        display: none;
    }

    .tab-icon {
        font-size: 1.25rem;
    }

    .scene-editor,
    .scene-edit-form,
    .play-container {
        padding: 1rem;
    }

    .form-header {
        flex-direction: column;
        align-items: stretch;
    }

    .scene-title-input {
        font-size: 1.25rem;
    }

    .form-actions {
        justify-content: space-between;
    }

    .story-display {
        padding: 1.5rem;
    }

    .story-display p {
        font-size: 1rem;
    }

    .modal-content {
        margin: 0.5rem;
        max-height: 95vh;
    }

    .modal-body {
        padding: 1rem;
    }

    .modal-footer {
        flex-direction: column;
    }

    .modal-footer .btn {
        width: 100%;
    }
}

@media (max-width: 480px) {
    .logo h1 {
        font-size: 1rem;
    }

    .sidebar-header {
        flex-direction: column;
        gap: 0.75rem;
        align-items: stretch;
    }

    .sidebar-header .btn {
        width: 100%;
    }

    .story-actions {
        flex-direction: column;
    }

    .story-actions .btn {
        width: 100%;
    }

    .play-header {
        flex-direction: column;
        align-items: stretch;
        text-align: center;
    }

    .play-variables {
        justify-content: center;
    }
}

/* Scrollbar Styling */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--surface-secondary);
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--secondary-color);
}

/* Focus Styles for Accessibility */
:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}
