/* CSS Variables */
:root {
    --primary-color: #6366f1;
    --primary-hover: #4f46e5;
    --secondary-color: #64748b;
    --secondary-hover: #475569;
    --success-color: #22c55e;
    --danger-color: #ef4444;
    --warning-color: #f59e0b;
    --background: #0f172a;
    --surface: #1e293b;
    --surface-light: #334155;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --border-color: #475569;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
    --radius: 8px;
    --radius-lg: 12px;
}

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

html {
    font-size: 16px;
}

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

/* App Container */
.app-container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 1rem;
}

/* Header */
.header {
    text-align: center;
    padding: 2rem 1rem;
    border-bottom: 1px solid var(--border-color);
}

.logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    margin-bottom: 0.5rem;
}

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

.header h1 {
    font-size: 1.75rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary-color), #a855f7);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.tagline {
    color: var(--text-secondary);
    font-size: 0.95rem;
}

/* Tab Navigation */
.tab-navigation {
    display: flex;
    gap: 0.5rem;
    padding: 1rem 0;
    overflow-x: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--surface-light) transparent;
}

.tab-navigation::-webkit-scrollbar {
    height: 4px;
}

.tab-navigation::-webkit-scrollbar-track {
    background: transparent;
}

.tab-navigation::-webkit-scrollbar-thumb {
    background: var(--surface-light);
    border-radius: 2px;
}

.tab-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.25rem;
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

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

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

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

/* Main Content */
.main-content {
    flex: 1;
    padding: 1.5rem 0;
}

.tab-content {
    display: none;
    animation: fadeIn 0.3s ease;
}

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

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

.section-header {
    margin-bottom: 1.5rem;
}

.section-header h2 {
    font-size: 1.5rem;
    margin-bottom: 0.25rem;
}

.section-header p {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* Form Elements */
.form-group {
    margin-bottom: 1.25rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--text-primary);
}

.form-group small {
    display: block;
    margin-top: 0.25rem;
    color: var(--text-secondary);
    font-size: 0.8rem;
}

input[type="text"],
input[type="email"],
textarea,
select {
    width: 100%;
    padding: 0.75rem 1rem;
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 1rem;
    font-family: inherit;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

input:focus,
textarea:focus,
select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

textarea {
    resize: vertical;
    min-height: 100px;
}

select {
    cursor: pointer;
}

input[type="checkbox"] {
    width: 18px;
    height: 18px;
    margin-right: 0.5rem;
    cursor: pointer;
    accent-color: var(--primary-color);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: var(--radius);
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

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

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

.btn-secondary {
    background: var(--surface-light);
    color: var(--text-primary);
}

.btn-secondary:hover {
    background: var(--secondary-hover);
}

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

.btn-danger:hover {
    background: #dc2626;
}

.btn-small {
    padding: 0.5rem 1rem;
    font-size: 0.85rem;
}

.action-buttons {
    display: flex;
    gap: 0.75rem;
    margin-top: 1.5rem;
    flex-wrap: wrap;
}

/* Prompt Builder */
.prompt-builder {
    display: grid;
    grid-template-columns: 300px 1fr;
    gap: 1.5rem;
    min-height: 500px;
}

.prompt-list-panel,
.prompt-editor-panel {
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

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

.panel-header h3 {
    font-size: 1rem;
    font-weight: 600;
}

.scene-list {
    padding: 0.5rem;
    max-height: 450px;
    overflow-y: auto;
}

.scene-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    margin-bottom: 0.5rem;
    background: var(--background);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.2s ease;
}

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

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

.scene-item.start {
    border-left: 3px solid var(--success-color);
}

.scene-item.ending {
    border-left: 3px solid var(--warning-color);
}

.scene-icon {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--surface-light);
    border-radius: var(--radius);
    font-size: 1rem;
}

.scene-info {
    flex: 1;
    overflow: hidden;
}

.scene-info h4 {
    font-size: 0.9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.scene-info p {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.editor-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 400px;
    color: var(--text-secondary);
}

.scene-editor-form {
    padding: 1rem;
}

/* Decision Tree */
.decision-tree-container {
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 1rem;
}

.tree-controls {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.tree-canvas-wrapper {
    position: relative;
    height: 500px;
    background: var(--background);
    border-radius: var(--radius);
    overflow: hidden;
}

.tree-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    transform-origin: center center;
    transition: transform 0.3s ease;
}

.tree-node {
    position: absolute;
    padding: 0.75rem 1rem;
    background: var(--surface);
    border: 2px solid var(--border-color);
    border-radius: var(--radius);
    cursor: move;
    min-width: 120px;
    text-align: center;
    font-size: 0.85rem;
    transition: box-shadow 0.2s ease;
    z-index: 10;
}

.tree-node:hover {
    box-shadow: var(--shadow);
}

.tree-node.start-node {
    border-color: var(--success-color);
    background: rgba(34, 197, 94, 0.1);
}

.tree-node.ending-node {
    border-color: var(--warning-color);
    background: rgba(245, 158, 11, 0.1);
}

.tree-node-title {
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.tree-node-id {
    font-size: 0.7rem;
    color: var(--text-secondary);
}

.tree-connection {
    position: absolute;
    pointer-events: none;
    z-index: 5;
}

.tree-legend {
    display: flex;
    gap: 1.5rem;
    margin-top: 1rem;
    justify-content: center;
    flex-wrap: wrap;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.legend-color {
    width: 16px;
    height: 16px;
    border-radius: 4px;
    border: 2px solid;
}

.legend-color.start {
    border-color: var(--success-color);
    background: rgba(34, 197, 94, 0.2);
}

.legend-color.normal {
    border-color: var(--border-color);
    background: var(--surface);
}

.legend-color.ending {
    border-color: var(--warning-color);
    background: rgba(245, 158, 11, 0.2);
}

/* Play Test */
.playtest-container {
    display: grid;
    grid-template-columns: 1fr 300px;
    gap: 1.5rem;
}

.playtest-controls {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.playtest-stats {
    display: flex;
    gap: 1.5rem;
    margin-left: auto;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.game-window {
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    overflow: hidden;
    min-height: 400px;
    display: flex;
    flex-direction: column;
}

.game-header {
    padding: 1rem;
    background: var(--surface-light);
    border-bottom: 1px solid var(--border-color);
    font-weight: 600;
    text-align: center;
}

.game-text {
    flex: 1;
    padding: 1.5rem;
    overflow-y: auto;
    font-size: 1.05rem;
    line-height: 1.8;
}

.game-text .placeholder-text {
    color: var(--text-secondary);
    text-align: center;
    margin-top: 2rem;
}

.game-choices {
    padding: 1rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.choice-btn {
    width: 100%;
    padding: 0.75rem 1rem;
    background: var(--surface-light);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 0.95rem;
    cursor: pointer;
    text-align: left;
    transition: all 0.2s ease;
}

.choice-btn:hover {
    background: var(--primary-color);
    border-color: var(--primary-color);
}

.playtest-log {
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 1rem;
}

.playtest-log h4 {
    margin-bottom: 0.75rem;
    font-size: 0.95rem;
    color: var(--text-secondary);
}

#decision-log {
    max-height: 350px;
    overflow-y: auto;
    font-size: 0.85rem;
}

.log-entry {
    padding: 0.5rem;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-secondary);
}

.log-entry:last-child {
    border-bottom: none;
}

.log-entry .scene-name {
    color: var(--primary-color);
    font-weight: 500;
}

.log-entry .choice-text {
    color: var(--text-primary);
}

/* Export */
.export-options {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.export-card {
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    text-align: center;
}

.export-icon {
    font-size: 2.5rem;
    margin-bottom: 1rem;
}

.export-card h3 {
    font-size: 1.1rem;
    margin-bottom: 0.5rem;
}

.export-card p {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: 1rem;
}

.export-preview {
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
}

.export-preview h3 {
    margin-bottom: 1rem;
    font-size: 1.1rem;
}

.summary-item {
    display: flex;
    justify-content: space-between;
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--border-color);
}

.summary-item:last-child {
    border-bottom: none;
}

.summary-label {
    color: var(--text-secondary);
}

.summary-value {
    font-weight: 500;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--surface);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 600px;
    max-height: 90vh;
    overflow-y: auto;
}

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

.modal-header h3 {
    font-size: 1.1rem;
}

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

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

.modal-body {
    padding: 1.5rem;
}

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

/* Choice Items in Modal */
.choice-item {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
    align-items: flex-start;
}

.choice-item input {
    flex: 1;
}

.choice-item select {
    width: 150px;
}

.choice-remove {
    width: 32px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--danger-color);
    border: none;
    border-radius: var(--radius);
    color: white;
    cursor: pointer;
    flex-shrink: 0;
}

/* Toast Notification */
.toast {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--surface-light);
    color: var(--text-primary);
    padding: 1rem 2rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    opacity: 0;
    transition: all 0.3s ease;
    z-index: 1100;
}

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

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

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

/* Footer */
.footer {
    padding: 1.5rem;
    text-align: center;
    border-top: 1px solid var(--border-color);
    color: var(--text-secondary);
    font-size: 0.9rem;
}

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

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

/* Responsive Design */
@media (max-width: 1024px) {
    .prompt-builder {
        grid-template-columns: 1fr;
    }

    .prompt-list-panel {
        order: 2;
    }

    .playtest-container {
        grid-template-columns: 1fr;
    }

    .playtest-log {
        order: -1;
    }
}

@media (max-width: 768px) {
    html {
        font-size: 14px;
    }

    .header {
        padding: 1.5rem 1rem;
    }

    .logo {
        flex-direction: column;
        gap: 0.5rem;
    }

    .header h1 {
        font-size: 1.5rem;
    }

    .tab-btn {
        padding: 0.6rem 1rem;
    }

    .tab-text {
        display: none;
    }

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

    .tree-canvas-wrapper {
        height: 350px;
    }

    .playtest-stats {
        margin-left: 0;
        width: 100%;
        justify-content: space-between;
    }

    .modal-content {
        max-height: 80vh;
    }

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

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

    .choice-item {
        flex-wrap: wrap;
    }

    .choice-item input {
        width: 100%;
    }

    .choice-item select {
        flex: 1;
        width: auto;
    }
}

@media (max-width: 480px) {
    .app-container {
        padding: 0 0.5rem;
    }

    .export-options {
        grid-template-columns: 1fr;
    }

    .action-buttons {
        flex-direction: column;
    }

    .action-buttons .btn {
        width: 100%;
    }

    .tree-controls {
        justify-content: center;
    }

    .tree-controls .btn {
        flex: 1;
        min-width: 0;
    }
}

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

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

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

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

/* Game Ending Styles */
.game-ending {
    text-align: center;
    padding: 2rem;
}

.game-ending h3 {
    font-size: 1.5rem;
    margin-bottom: 1rem;
    color: var(--warning-color);
}

.game-ending p {
    margin-bottom: 1.5rem;
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-secondary);
}

.empty-state-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

.empty-state h3 {
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}
