/* Interactive Stories — Stylesheet */
* {
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    margin: 0;
    padding: 0;
    background: linear-gradient(135deg, #1e1b4b 0%, #312e81 50%, #1e3a8a 100%);
    min-height: 100vh;
    color: #1f2937;
}

.app-header {
    text-align: center;
    padding: 2rem 1rem 1.5rem;
    color: #f1f5f9;
}

.app-header h1 {
    margin: 0;
    font-size: 2.25rem;
    letter-spacing: -0.02em;
}

.app-header .subtitle {
    margin: 0.25rem 0 0;
    opacity: 0.85;
    font-size: 1rem;
}

.app-main {
    max-width: 960px;
    margin: 0 auto;
    padding: 0 1rem 3rem;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.card {
    background: #ffffff;
    border-radius: 14px;
    padding: 1.5rem;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.25);
}

.card h2 {
    margin: 0;
    font-size: 1.25rem;
    color: #1f2937;
}

.step-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.step-header h2 {
    flex: 1;
}

.step-help {
    margin: 0 0 0.75rem;
    color: #6b7280;
    font-size: 0.9rem;
}

.step-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 28px;
    height: 28px;
    border-radius: 50%;
    font-weight: 600;
    font-size: 0.85rem;
    padding: 0 0.5rem;
}

.step-badge.pending {
    background: #e5e7eb;
    color: #6b7280;
}

.step-badge.running {
    background: #fde68a;
    color: #92400e;
    animation: pulse 1.5s infinite;
}

.step-badge.done {
    background: #bbf7d0;
    color: #166534;
}

.step-badge.error {
    background: #fecaca;
    color: #991b1b;
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.55;
    }
}

/* Form elements */
label {
    display: block;
    font-weight: 600;
    margin-bottom: 0.35rem;
    color: #374151;
    font-size: 0.875rem;
}

select,
textarea,
input[type="text"] {
    width: 100%;
    padding: 0.625rem 0.75rem;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font-size: 0.95rem;
    font-family: inherit;
    background: #ffffff;
    color: #111827;
}

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

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

.model-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

@media (max-width: 600px) {
    .model-grid {
        grid-template-columns: 1fr;
    }
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.55rem 1.1rem;
    border: none;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
    font-family: inherit;
}

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

.btn-primary {
    background: #6366f1;
    color: #ffffff;
}

.btn-primary:hover:not(:disabled) {
    background: #4f46e5;
    transform: translateY(-1px);
}

.btn-secondary {
    background: #e5e7eb;
    color: #1f2937;
}

.btn-secondary:hover:not(:disabled) {
    background: #d1d5db;
}

.btn-icon {
    background: transparent;
    color: #6b7280;
    padding: 0.35rem 0.55rem;
    font-size: 1rem;
}

.btn-icon:hover:not(:disabled) {
    background: #f3f4f6;
    color: #1f2937;
}

.actions {
    display: flex;
    gap: 0.6rem;
    align-items: center;
    flex-wrap: wrap;
    margin-top: 0.75rem;
}

.status-msg {
    font-size: 0.875rem;
    color: #6b7280;
}

.status-msg.success {
    color: #166534;
}

.status-msg.error {
    color: #991b1b;
}

.status-msg.info {
    color: #1e40af;
}

/* Choice buttons */
.choice-actions {
    margin-top: 1.25rem;
    padding-top: 1.25rem;
    border-top: 1px solid #e5e7eb;
}

.choice-prompt {
    margin: 0 0 0.75rem;
    font-weight: 600;
    color: #374151;
}

.choice-buttons {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.75rem;
}

@media (max-width: 600px) {
    .choice-buttons {
        grid-template-columns: 1fr;
    }
}

.btn-choice {
    flex-direction: column;
    gap: 0.35rem;
    padding: 1rem 0.75rem;
    background: #f3f4f6;
    color: #1f2937;
    border: 2px solid transparent;
    text-align: center;
}

.btn-choice:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.1);
}

.btn-choice .choice-letter {
    font-size: 1.5rem;
    font-weight: 700;
}

.btn-choice .choice-label {
    font-size: 0.85rem;
    opacity: 0.85;
}

.btn-choice-a {
    border-color: #818cf8;
}

.btn-choice-a:hover:not(:disabled) {
    background: #e0e7ff;
    border-color: #6366f1;
}

.btn-choice-b {
    border-color: #34d399;
}

.btn-choice-b:hover:not(:disabled) {
    background: #d1fae5;
    border-color: #10b981;
}

.btn-choice-c {
    border-color: #fbbf24;
}

.btn-choice-c:hover:not(:disabled) {
    background: #fef3c7;
    border-color: #f59e0b;
}

/* Story tree */
.story-tree {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.9rem;
    max-height: 300px;
    overflow-y: auto;
    padding: 0.5rem;
    background: #f9fafb;
    border-radius: 8px;
    border: 1px solid #e5e7eb;
}

.tree-node {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.35rem 0.5rem;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.1s;
}

.tree-node:hover {
    background: #e0e7ff;
}

.tree-node.active {
    background: #6366f1;
    color: #ffffff;
    font-weight: 600;
}

.tree-indent {
    color: #9ca3af;
    user-select: none;
     white-space: pre;
     font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.tree-status {
    margin-left: auto;
    font-size: 0.75rem;
    opacity: 0.75;
}

.empty-state {
    color: #9ca3af;
    font-style: italic;
    text-align: center;
    margin: 1.5rem 0;
}

/* Markdown preview */
.markdown-preview {
    padding: 1rem 1.25rem;
    background: #fafafa;
    border-radius: 10px;
    border: 1px solid #e5e7eb;
    max-height: 600px;
    overflow-y: auto;
    line-height: 1.7;
}

.markdown-preview h1,
.markdown-preview h2,
.markdown-preview h3 {
    color: #1e3a8a;
    margin-top: 1rem;
}

.markdown-preview h1:first-child,
.markdown-preview h2:first-child {
    margin-top: 0;
}

.markdown-preview code {
    background: #e5e7eb;
    padding: 0.1rem 0.35rem;
    border-radius: 4px;
    font-size: 0.9em;
}

.markdown-preview pre {
    background: #1e293b;
    color: #f1f5f9;
    padding: 1rem;
    border-radius: 8px;
    overflow-x: auto;
}

.markdown-preview blockquote {
    border-left: 4px solid #6366f1;
    margin-left: 0;
    padding-left: 1rem;
    color: #4b5563;
    font-style: italic;
}

code {
    background: #f3f4f6;
    padding: 0.1rem 0.4rem;
    border-radius: 4px;
    font-size: 0.875em;
}
/* Node toolbar (read aloud controls) */
.node-toolbar {
     display: flex;
     align-items: center;
     gap: 1rem;
     flex-wrap: wrap;
     margin-bottom: 0.75rem;
}
.auto-read-toggle {
     display: inline-flex;
     align-items: center;
     gap: 0.4rem;
     font-size: 0.875rem;
     color: #374151;
     font-weight: 500;
     cursor: pointer;
     user-select: none;
}
.auto-read-toggle input[type="checkbox"] {
     width: auto;
     margin: 0;
     cursor: pointer;
}
/* Node image */
.node-image-container {
     margin-bottom: 1rem;
     padding: 0.75rem;
     background: #f9fafb;
     border: 1px solid #e5e7eb;
     border-radius: 10px;
     text-align: center;
}
.node-image {
     max-width: 100%;
     max-height: 480px;
     border-radius: 8px;
     box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
     display: block;
     margin: 0 auto;
}
.node-image-container .status-msg {
     display: block;
     margin-top: 0.5rem;
}


/* Activity log */
.activity-log {
    max-height: 240px;
    overflow-y: auto;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.8rem;
    background: #1e293b;
    color: #e2e8f0;
    padding: 0.75rem;
    border-radius: 8px;
    line-height: 1.5;
}

.activity-log .log-entry {
    padding: 0.15rem 0;
}

.activity-log .log-entry.success {
    color: #86efac;
}

.activity-log .log-entry.error {
    color: #fca5a5;
}

.activity-log .log-entry.warning {
    color: #fcd34d;
}

.activity-log .log-entry.info {
    color: #93c5fd;
}

.activity-log .log-time {
    color: #64748b;
    margin-right: 0.5rem;
}

/* Session links */
.session-link-container {
    margin-top: 0.75rem;
    display: flex;
    gap: 0.6rem;
    flex-wrap: wrap;
}

.session-link-container a {
    font-size: 0.85rem;
    color: #6366f1;
    text-decoration: none;
    padding: 0.25rem 0.6rem;
    background: #eef2ff;
    border-radius: 6px;
}

.session-link-container a:hover {
    background: #e0e7ff;
    text-decoration: underline;
}

/* Toast container */
#toast-container {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.toast {
    padding: 0.75rem 1rem;
    border-radius: 8px;
    background: #1f2937;
    color: #ffffff;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
    animation: slideIn 0.25s;
    font-size: 0.9rem;
    max-width: 320px;
}

.toast.success {
    background: #059669;
}

.toast.error {
    background: #dc2626;
}

.toast.warning {
    background: #d97706;
}

.toast.info {
    background: #2563eb;
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }

    to {
        transform: translateX(0);
        opacity: 1;
    }
}
/* ----------------------------------------------------------------------- */
/* Immersive / fullscreen mode                                             */
/* ----------------------------------------------------------------------- */
body.immersive {
     overflow: hidden;
}
body.immersive .app-header,
body.immersive .app-main > .card:not(#node-card) {
     display: none;
}
body.immersive .app-main {
     max-width: none;
     padding: 0;
     margin: 0;
     height: 100vh;
}
body.immersive #node-card {
     position: fixed;
     inset: 0;
     border-radius: 0;
     padding: 2rem clamp(1rem, 6vw, 4rem);
     overflow-y: auto;
     display: flex;
     flex-direction: column;
     background: linear-gradient(135deg, #1e1b4b 0%, #312e81 50%, #1e3a8a 100%);
     color: #f1f5f9;
     z-index: 100;
     box-shadow: none;
}
body.immersive #node-card .step-header h2,
body.immersive #node-card .choice-prompt {
     color: #f1f5f9;
}
body.immersive #node-card .step-header code {
     background: rgba(255, 255, 255, 0.15);
     color: #e0e7ff;
}
body.immersive #node-card .auto-read-toggle {
     color: #e2e8f0;
}
body.immersive #toggle-immersive {
     position: absolute;
     top: 1rem;
     right: 1rem;
     background: rgba(255, 255, 255, 0.1);
     color: #f1f5f9;
     font-size: 1.2rem;
     padding: 0.5rem 0.75rem;
     z-index: 101;
}
body.immersive #toggle-immersive:hover {
     background: rgba(255, 255, 255, 0.2);
}
body.immersive #node-card .markdown-preview {
     flex: 1 1 auto;
     max-height: none;
     background: rgba(255, 255, 255, 0.1);
     font-size: 1.1rem;
     line-height: 1.8;
     padding: 1.75rem 2rem;
     margin: 0 auto 1rem;
     width: 100%;
     max-width: 900px;
}
body.immersive #node-card .node-image-container {
     background: transparent;
     border: none;
     padding: 0;
     margin: 0 auto 1.25rem;
     max-width: 900px;
     width: 100%;
}
body.immersive #node-card .node-image {
     max-height: 60vh;
     box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
}
body.immersive #node-card .node-toolbar {
     justify-content: center;
     max-width: 900px;
     margin: 0 auto 1rem;
     width: 100%;
}
body.immersive #node-card .choice-actions {
     border-top-color: rgba(255, 255, 255, 0.2);
     max-width: 900px;
     margin: 0 auto;
     width: 100%;
}
body.immersive #node-card .session-link-container {
     justify-content: center;
     max-width: 900px;
     margin: 0.75rem auto 0;
     width: 100%;
}
body.immersive #node-card .session-link-container a {
     background: rgba(255, 255, 255, 0.15);
     color: #e0e7ff;
}
body.immersive #node-card .session-link-container a:hover {
     background: rgba(255, 255, 255, 0.25);
}
body.immersive #node-card .btn-choice {
     background: rgba(255, 255, 255, 0.95);
     padding: 1.25rem 0.75rem;
}
body.immersive #node-card .btn-choice:hover:not(:disabled) {
     background: #ffffff;
}