* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #6366f1;
    --primary-hover: #4f46e5;
    --secondary-color: #8b5cf6;
    --success-color: #10b981;
    --danger-color: #ef4444;
    --text-primary: #1f2937;
    --text-secondary: #6b7280;
    --bg-primary: #ffffff;
    --bg-secondary: #f9fafb;
    --bg-tertiary: #f3f4f6;
    --border-color: #e5e7eb;
    --shadow-sm: 0 1px 2px 0 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);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: white;
    min-height: 100vh;
    padding: 1rem;
    color: var(--text-primary);
}

.container {
    max-width: 1200px;
    margin: 0 auto;
}

header {
    text-align: center;
    margin-bottom: 1.5rem;
    color: var(--text-primary);
}

header h1 {
    font-size: 1.75rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
}

.subtitle {
    font-size: 0.95rem;
    opacity: 0.7;
    font-weight: 400;
}

main {
    background: var(--bg-primary);
    border-radius: 0.75rem;
    padding: 1.25rem;
    box-shadow: var(--shadow-xl);
}

section {
    margin-bottom: 1.25rem;
}

section:last-child {
    margin-bottom: 0;
}

.control-section {
    display: flex;
    justify-content: center;
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
    font-weight: 500;
    border: none;
    border-radius: 0.5rem;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
}

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

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

.btn-primary:hover:not(:disabled) {
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

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

.btn-secondary:hover:not(:disabled) {
    background: #7c3aed;
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.images-section {
    padding: 0.5rem 0;
}

.image-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    align-items: stretch;
}

.swm-inputs-box {
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.08) 0%, rgba(139, 92, 246, 0.08) 100%);
    border: 2px solid var(--primary-color);
    border-radius: 1rem;
    padding: 1.5rem 1rem 1rem 1rem;
    position: relative;
}

.swm-inputs-label {
    position: absolute;
    top: -0.65rem;
    left: 1rem;
    background: white;
    padding: 0.25rem 0.75rem;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--primary-color);
    border-radius: 0.25rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.swm-inputs-content {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 1rem;
    align-items: center;
}

.final-state-box {
    background: transparent;
    border: 2px solid transparent;
    border-radius: 1rem;
    padding: 0.25rem 0.75rem;
    position: relative;
}

.final-state-content {
    display: flex;
    align-items: center;
    width: 100%;
}

.final-state-content .image-card {
    flex: 1;
}

.reference-label {
    font-size: 0.75rem;
    font-weight: 400;
    color: var(--text-secondary);
    font-style: italic;
}

.image-card,
.final-state-card {
    background: var(--bg-secondary);
    border-radius: 1rem;
    padding: 0.75rem;
    border: 2px solid var(--border-color);
    margin: 0 2rem;
}

.image-card h3,
.final-state-card h3 {
    font-size: 0.95rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

.image-wrapper {
    position: relative;
    width: calc(100% + 1.5rem);
    margin: 0 -0.75rem;
    aspect-ratio: 16 / 9;
    background: var(--bg-secondary);
    /* Move border/radius from img to wrapper so canvas and image share same box */
    border: 10px solid var(--bg-secondary);
    border-radius: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.image-wrapper img {
    width: 100%;
    height: 100%;
    /* Use contain to avoid cropping that misaligns with canvas overlay */
    object-fit: contain;
    display: block;
}

.placeholder {
    color: var(--text-secondary);
    text-align: center;
    padding: 1rem;
    font-size: 0.8rem;
}

.arrow-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
    color: var(--primary-color);
}

.arrow-container svg {
    width: 32px;
    height: 32px;
}

.action-info {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.question-card {
    background: var(--bg-secondary);
    border-radius: 0.5rem;
    padding: 0.75rem;
    border: 2px solid var(--border-color);
}

.question-card h3 {
    font-size: 0.95rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

.input-group {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

#questionInput {
    flex: 1;
    padding: 0.5rem 0.75rem;
    font-size: 0.9rem;
    border: 2px solid var(--border-color);
    border-radius: 0.5rem;
    font-family: inherit;
    transition: border-color 0.2s ease;
}

#questionInput:focus {
    outline: none;
    border-color: var(--primary-color);
}

#questionInput:disabled {
    background: var(--bg-tertiary);
    cursor: not-allowed;
}

.sample-questions {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.sample-questions-label {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.sample-questions-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 0.75rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    cursor: pointer;
    font-size: 0.875rem;
    color: var(--text-secondary);
    transition: all 0.2s ease;
    margin-bottom: 0.5rem;
}

.sample-questions-toggle:hover {
    background: var(--bg-tertiary);
    border-color: var(--primary-color);
}

.sample-questions-toggle svg {
    transition: transform 0.2s ease;
    width: 16px;
    height: 16px;
}

.sample-questions-toggle.collapsed svg {
    transform: rotate(-90deg);
}

.sample-questions-content {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    overflow: hidden;
    transition: max-height 0.3s ease, opacity 0.3s ease;
    max-height: 500px;
    opacity: 1;
}

.sample-questions-content.collapsed {
    max-height: 0;
    opacity: 0;
    margin: 0;
}

.placeholder-text {
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-style: italic;
    padding: 0.5rem;
    text-align: center;
}

.placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    min-height: 300px;
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-style: italic;
    text-align: center;
    padding: 2rem;
    background: var(--bg-tertiary);
    border-radius: 8px;
}

.sample-question {
    padding: 0.4rem 0.6rem;
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 0.3rem;
    font-size: 0.8rem;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
}

.sample-question:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
    background: #f0f4ff;
}

.question-text {
    flex: 1;
}

.oracle-badge {
    font-size: 0.7rem;
    font-weight: 600;
    padding: 0.2rem 0.5rem;
    border-radius: 0.25rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    white-space: nowrap;
}

.oracle-badge.oracle-yes {
    background: #d1fae5;
    color: var(--success-color);
}

.oracle-badge.oracle-no {
    background: #fee2e2;
    color: var(--danger-color);
}

.answer-card {
    background: linear-gradient(135deg, #667eea15 0%, #764ba215 100%);
    border-radius: 0.5rem;
    padding: 0.75rem;
    border: 2px solid var(--primary-color);
}

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

.answer-header h3 {
    font-size: 0.95rem;
    font-weight: 600;
}

.answer-result {
    font-size: 1.25rem;
    font-weight: 700;
    padding: 0.4rem 0.75rem;
    border-radius: 0.5rem;
}

.answer-result.yes {
    color: var(--success-color);
    background: #d1fae5;
}

.answer-result.no {
    color: var(--danger-color);
    background: #fee2e2;
}

.confidence-bar {
    margin-bottom: 0.5rem;
    padding-top: 0.75rem;
}

.confidence-label {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.35rem;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-secondary);
}

#confidenceText {
    color: var(--text-primary);
}

.confidence-track {
    position: relative;
    height: 1.5rem;
    background: linear-gradient(to right, #fecaca 0%, #fef3c7 50%, #d1fae5 100%);
    border-radius: 0.75rem;
    overflow: visible;
    margin: 0.75rem 0;
}

.confidence-fill {
    position: absolute;
    top: 0;
    height: 100%;
    background: rgba(99, 102, 241, 0.3);
    transition: width 0.5s ease, left 0.5s ease;
    border-radius: 0.5rem;
    z-index: 1;
}

.prediction-legend {
    display: flex;
    justify-content: center;
    gap: 1.5rem;
    margin-top: 0.75rem;
    padding: 0.5rem;
    background: #f9fafb;
    border-radius: 0.5rem;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
}

.legend-indicator {
    display: inline-block;
    width: 24px;
    height: 5px;
    border-radius: 1px;
    box-shadow: 0 0 2px rgba(0, 0, 0, 0.2);
}

.initial-indicator {
    background: #ef4444;
}

.future-indicator {
    background: var(--primary-color);
    height: 6px;
}

.legend-label {
    color: var(--text-secondary);
    font-weight: 500;
}

.initial-line {
    position: absolute;
    top: -4px;
    bottom: -4px;
    width: 5px;
    background: #ef4444;
    transform: translateX(-50%);
    transition: left 0.5s ease;
    z-index: 3;
    opacity: 1;
    box-shadow: 0 0 4px rgba(239, 68, 68, 0.5);
}

.line-pointer {
    position: absolute;
    top: -10px;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-left: 7px solid transparent;
    border-right: 7px solid transparent;
    border-top: 10px solid #ef4444;
    filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.2));
}

.confidence-marker {
    position: absolute;
    top: -4px;
    bottom: -4px;
    width: 6px;
    transform: translateX(-50%);
    background: var(--primary-color);
    transition: left 0.5s ease;
    z-index: 4;
    box-shadow: 0 0 4px rgba(99, 102, 241, 0.5);
}

.marker-pointer {
    position: absolute;
    top: -12px;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-left: 8px solid transparent;
    border-right: 8px solid transparent;
    border-top: 12px solid var(--primary-color);
    filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.2));
}

.probability-details {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
}

.prob-item {
    display: flex;
    justify-content: space-between;
    padding: 0.5rem 0.65rem;
    background: white;
    border-radius: 0.375rem;
    border: 1px solid var(--border-color);
    font-size: 0.85rem;
}

.prob-label {
    font-weight: 500;
    color: var(--text-secondary);
}

.prob-value {
    font-weight: 600;
    color: var(--text-primary);
}

.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: none;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 1rem;
    z-index: 1000;
    backdrop-filter: blur(4px);
}

.loading-overlay.active {
    display: flex;
}

.loading-overlay p {
    color: white;
    font-size: 1.125rem;
    font-weight: 500;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

#drawingCanvas {
    position: absolute;
    top: 0;
    left: 0;
    cursor: crosshair;
    z-index: 10;
}

.drawing-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
    padding: 0.5rem;
    background: rgba(99, 102, 241, 0.05);
    border-radius: 0.375rem;
}

.btn-small {
    padding: 0.35rem 0.65rem;
    font-size: 0.8rem;
}

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

.btn-danger:hover:not(:disabled) {
    background: #dc2626;
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

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

.btn-success:hover:not(:disabled) {
    background: #059669;
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.points-counter {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--primary-color);
    padding: 0.35rem 0.65rem;
    background: white;
    border-radius: 0.375rem;
    border: 1px solid var(--border-color);
}

/* Instructions Collapsible */
.instructions-container {
    max-width: 900px;
    margin: 0 auto;
}

.instructions-small {
    max-width: 700px;
}

.instructions-toggle {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.875rem 1.25rem;
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.1) 0%, rgba(139, 92, 246, 0.1) 100%);
    border: 2px solid var(--primary-color);
    border-radius: 0.75rem;
    font-size: 1rem;
    font-weight: 600;
    color: var(--primary-color);
    cursor: pointer;
    transition: all 0.3s ease;
    font-family: inherit;
}

.instructions-small .instructions-toggle {
    padding: 0.625rem 1rem;
    font-size: 0.875rem;
    border-radius: 0.5rem;
}

.instructions-toggle:hover {
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.15) 0%, rgba(139, 92, 246, 0.15) 100%);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.instructions-icon {
    flex-shrink: 0;
}

.instructions-toggle span {
    flex: 1;
    text-align: left;
}

.chevron-icon {
    flex-shrink: 0;
    transition: transform 0.3s ease;
}

.instructions-toggle.active .chevron-icon {
    transform: rotate(180deg);
}

.instructions-toggle.active {
    border-radius: 0.75rem 0.75rem 0 0;
    border-bottom: none;
}

.instructions-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease, padding 0.3s ease, border 0.3s ease;
    background: var(--bg-secondary);
    border: none;
    border-radius: 0 0 0.75rem 0.75rem;
    margin-top: 0;
}

.instructions-content.expanded {
    max-height: 500px;
    padding: 1.5rem 1.25rem 1.25rem 1.25rem;
    border: 2px solid var(--primary-color);
    border-top: none;
}

.instructions-small .instructions-content.expanded {
    padding: 1rem 1rem 0.875rem 1rem;
}

.instructions-list {
    list-style: none;
    counter-reset: instructions-counter;
    margin: 0;
    padding: 0;
}

.instructions-list li {
    counter-increment: instructions-counter;
    position: relative;
    padding-left: 2.5rem;
    margin-bottom: 1rem;
    line-height: 1.6;
    color: var(--text-primary);
    font-size: 0.95rem;
}

.instructions-small .instructions-list li {
    padding-left: 2rem;
    margin-bottom: 0.75rem;
    font-size: 0.85rem;
    line-height: 1.5;
}

.instructions-list li:last-child {
    margin-bottom: 0;
}

.instructions-list li::before {
    content: counter(instructions-counter);
    position: absolute;
    left: 0;
    top: 0;
    width: 1.75rem;
    height: 1.75rem;
    background: var(--primary-color);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.85rem;
}

.instructions-small .instructions-list li::before {
    width: 1.5rem;
    height: 1.5rem;
    font-size: 0.75rem;
}

.instructions-list li strong {
    color: var(--primary-color);
}

@media (max-width: 768px) {
    body {
        padding: 1rem;
    }

    header h1 {
        font-size: 1.75rem;
    }

    main {
        padding: 1.5rem;
    }

    .image-container {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .swm-inputs-content {
        grid-template-columns: 1fr;
    }

    .arrow-container {
        transform: rotate(90deg);
    }

    .input-group {
        flex-direction: column;
    }

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

    .probability-details {
        grid-template-columns: 1fr;
    }
    
    .drawing-controls {
        flex-direction: column;
        gap: 0.5rem;
        align-items: stretch;
    }

    .instructions-toggle {
        font-size: 0.9rem;
        padding: 0.75rem 1rem;
    }

    .instructions-list li {
        font-size: 0.875rem;
        padding-left: 2.25rem;
    }

    .instructions-list li::before {
        width: 1.5rem;
        height: 1.5rem;
        font-size: 0.75rem;
    }
}

