:root {
    --bg: #f4f7f9;
    --surface: #ffffff;
    --text: #1a1a1a;
    --text-muted: #7a8a9a;
    --accent: #5a7d95;
    --border: #dee6ed;
    --font-main: 'Inter', sans-serif;
    --font-serif: 'Playfair Display', serif;
    --transition: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    --theme-toggle-bg: rgba(90, 125, 149, 0.1);

    --status-resident: #10b981;
    --status-nron: #f59e0b;
    --status-nr: #ef4444;
}

[data-theme="dark"] {
    --bg: #0e1117;
    --surface: #161b22;
    --text: #e6edf3;
    --text-muted: #8b949e;
    --accent: #7aaccc;
    --border: #21262d;
    --theme-toggle-bg: rgba(122, 172, 204, 0.1);
}

/* Smooth global theme transition */
body,
body *,
body *::before,
body *::after {
    transition: background-color 0.5s ease, color 0.4s ease, border-color 0.4s ease, transform 0.4s ease, opacity 0.4s ease;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: var(--font-main);
}

body {
    background-color: var(--bg);
    color: var(--text);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    overflow-x: hidden;
    line-height: 1.6;
}

/* ── Abstract Background Branding ── */
.app-container::after {
    content: '';
    position: fixed;
    top: 50%;
    left: 50%;
    width: 120vmin;
    height: 120vmin;
    transform: translate(-50%, -50%) rotate(-10deg);
    background: url('../assets/logo.svg') no-repeat center / contain;
    opacity: 0.04;
    filter: grayscale(1) invert(0.2);
    z-index: -1;
    pointer-events: none;
    transition: opacity 1s ease;
}

[data-theme="dark"] .app-container::after {
    opacity: 0.1;
    filter: invert(1) sepia(0.05) saturate(0.3) brightness(1.5);
}

/* ── Navbar ── */
.navbar {
    width: 100%;
    padding: 2rem 0;
    z-index: 1000;
}

.navbar .container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 0 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.back-link {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.9rem;
    transition: var(--transition);
}

.back-link:hover {
    color: var(--accent);
}

.logo {
    font-family: var(--font-serif);
    font-weight: 700;
    font-size: 1.8rem;
    letter-spacing: -0.5px;
    text-decoration: underline;
    text-underline-offset: 4px;
    text-decoration-thickness: 2px;
}

/* ── Theme Toggle (Nav Bar) ── */
#theme-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--accent);
    cursor: pointer;
    position: relative;
    flex-shrink: 0;
    padding: 0;
    transition:
        background-color 0.35s ease,
        border-color 0.35s ease,
        color 0.35s ease,
        transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1),
        box-shadow 0.35s ease !important;
}

#theme-toggle:hover {
    background: var(--theme-toggle-bg);
    border-color: var(--accent);
    transform: scale(1.1);
    box-shadow: 0 0 0 4px var(--theme-toggle-bg);
}

#theme-toggle svg {
    width: 14px;
    height: 14px;
    position: absolute;
    transition:
        opacity 0.3s ease,
        transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

#theme-toggle .icon-sun {
    opacity: 1;
    transform: rotate(0deg) scale(1);
}

#theme-toggle .icon-moon {
    opacity: 0;
    transform: rotate(-45deg) scale(0.6);
}

[data-theme="dark"] #theme-toggle .icon-sun {
    opacity: 0;
    transform: rotate(45deg) scale(0.6);
}

[data-theme="dark"] #theme-toggle .icon-moon {
    opacity: 1;
    transform: rotate(0deg) scale(1);
}

/* Spin animation on click */
#theme-toggle.spinning {
    animation: toggle-spin 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes toggle-spin {
    from {
        transform: rotate(-30deg) scale(0.88);
    }

    to {
        transform: rotate(0deg) scale(1);
    }
}

@media (max-width: 768px) {
    #theme-toggle {
        width: 36px;
        height: 36px;
    }

    #theme-toggle svg {
        width: 18px;
        height: 18px;
    }
}

/* Main Container */
.app-container {
    width: 100%;
    max-width: 800px;
    padding: 2rem 1.5rem;
    display: flex;
    flex-direction: column;
    z-index: 10;
    min-height: calc(100vh - 100px);
}

/* Header */
.app-header {
    text-align: center;
    margin-bottom: 3.5rem;
}

.app-header h1 {
    font-family: var(--font-serif);
    font-size: 3.5rem;
    line-height: 1.1;
    color: var(--text);
    margin-bottom: 1.5rem;
}

.italic {
    font-family: inherit;
    font-style: italic;
    font-weight: 400;
}

.app-header p {
    color: var(--text-muted);
    font-size: 1.1rem;
    max-width: 500px;
    margin: 0 auto;
}

/* Panel Styles */
.glass-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 24px;
    padding: 3rem;
    position: relative;
    overflow: hidden;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.05);
}

[data-theme="dark"] .glass-panel {
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}

/* Progress Bar */
.progress-container {
    width: 100%;
    height: 6px;
    background: var(--border);
    border-radius: 3px;
    margin-bottom: 2rem;
    overflow: hidden;
    display: none;
}

.progress-bar {
    height: 100%;
    width: 0%;
    background: var(--accent);
    transition: width 0.4s ease-out;
    border-radius: 3px;
}

/* UI Elements - Typography & Labels */
.wizard-step h2,
.wizard-step h3 {
    font-family: var(--font-serif);
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 1rem;
    color: var(--text);
}

.step-description {
    color: var(--text-muted);
    font-size: 1.1rem;
    margin-bottom: 4rem;
    /* Increased spacing to buttons */
    display: block;
}

/* UI Elements - Buttons & Inputs */
.options-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
}

.option-btn {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 2rem;
    border-radius: 16px;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.2rem;
    font-size: 1.1rem;
    font-weight: 500;
}

.option-btn i {
    font-size: 2.2rem;
    color: var(--accent);
    transition: var(--transition);
}

.option-btn:hover {
    border-color: var(--accent);
    transform: translateY(-5px);
    background: var(--theme-toggle-bg);
}

.option-btn.selected {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--surface);
}

.option-btn.selected i {
    color: var(--surface);
}

/* Form Styles */
.input-group {
    margin-bottom: 2rem;
}

.radio-group {
    display: flex;
    gap: 1rem;
    margin-top: 1rem;
}

.radio-label {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.8rem;
    padding: 1.2rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    cursor: pointer;
    transition: var(--transition);
    font-weight: 600;
    color: var(--text);
}

.radio-label:hover {
    border-color: var(--accent);
    background: var(--theme-toggle-bg);
}

.radio-label input[type="radio"] {
    display: none;
}

.radio-label.selected {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--surface);
}

.text-input {
    width: 100%;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 1.2rem;
    border-radius: 12px;
    font-size: 1.1rem;
    transition: var(--transition);
    margin-top: 0.5rem;
}

.text-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 4px var(--theme-toggle-bg);
}

/* Action Buttons */
.action-buttons {
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
    margin-top: 3rem;
    border-top: 1px solid var(--border);
    padding-top: 2rem;
}

.btn {
    padding: 1rem 2.5rem;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.8rem;
    transition: var(--transition);
    border: none;
}

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

.btn.primary:hover {
    filter: brightness(1.1);
    transform: translateY(-2px);
}

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

.btn.secondary:hover {
    border-color: var(--accent);
    color: var(--accent);
}

/* Results View */
.result-header {
    text-align: center;
    margin-bottom: 3rem;
}

.pulse-icon {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    background: var(--theme-toggle-bg);
    border: 3px solid var(--status-resident);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 2rem;
    font-size: 3rem;
    color: var(--status-resident);
}

.gradient-text {
    font-family: var(--font-serif);
    font-size: 3.5rem;
    font-weight: 800;
    color: var(--status-resident);
    margin-top: 0.5rem;
}

.info-card {
    background: var(--surface);
    border-left: 4px solid var(--accent);
    padding: 2rem;
    border-radius: 12px;
    margin-bottom: 1.5rem;
    border: 1px solid var(--border);
    border-left: 6px solid var(--accent);
}

.info-card h4 {
    color: var(--text-muted);
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 2px;
    margin-bottom: 0.8rem;
    display: flex;
    align-items: center;
    gap: 0.8rem;
}

.info-card p {
    font-size: 1.2rem;
    font-weight: 600;
}

.impact-list {
    list-style: none;
}

.impact-list li {
    padding: 1.2rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    margin-bottom: 1rem;
    display: flex;
    gap: 1.2rem;
    align-items: center;
    transition: var(--transition);
}

.impact-list li:hover {
    border-color: var(--accent);
    transform: translateX(5px);
}

.impact-list li::before {
    content: '\f058';
    font-family: 'Font Awesome 6 Free';
    font-weight: 900;
    color: var(--accent);
    font-size: 1.4rem;
}

/* Specific theme classes for results */
.theme-rnor .pulse-icon {
    border-color: var(--status-nron);
    color: var(--status-nron);
}

.theme-rnor .gradient-text {
    color: var(--status-nron);
}

.theme-nr .pulse-icon {
    border-color: var(--status-nr);
    color: var(--status-nr);
}

.theme-nr .gradient-text {
    color: var(--status-nr);
}

/* Footer */
footer {
    margin-top: auto;
    padding: 4rem 0;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.9rem;
    border-top: 1px solid var(--border);
    width: 100%;
}

/* Mobile Adjustments */
@media (max-width: 600px) {
    .glass-panel {
        padding: 2rem 1.5rem;
    }

    .app-header h1 {
        font-size: 2.5rem;
    }

    .gradient-text {
        font-size: 2.5rem;
    }

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

    .step-description {
        margin-bottom: 2.5rem;
    }
}

/* ── Decision Logic Section ── */
.logic-link-container {
    text-align: center;
    margin-top: 2rem;
}

.result-logic-link {
    margin-top: 0;
    margin-bottom: 1.5rem;
}

.logic-link {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border-radius: 8px;
    transition: var(--transition);
}

.logic-link:hover {
    color: var(--accent);
    background: var(--theme-toggle-bg);
}

.logic-section {
    margin-top: 2rem;
    animation: fadeIn 0.6s ease-out forwards;
}

.logic-header {
    text-align: center;
    margin-bottom: 2.5rem;
}

.logic-header h2 {
    font-family: var(--font-serif);
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--text);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.8rem;
}

.logic-header h2 i {
    color: var(--accent);
    font-size: 1.4rem;
}

.logic-header .step-description {
    margin-bottom: 0;
}

.logic-step {
    display: flex;
    gap: 1.5rem;
    margin-bottom: 2.5rem;
    position: relative;
}

.logic-step::after {
    content: '';
    position: absolute;
    left: 22px;
    top: 48px;
    bottom: -2.5rem;
    width: 2px;
    background: var(--border);
}

.logic-step:last-of-type::after {
    display: none;
}

.logic-step-number {
    width: 44px;
    height: 44px;
    min-width: 44px;
    border-radius: 50%;
    background: var(--accent);
    color: var(--bg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1.1rem;
    z-index: 1;
}

.logic-step-content {
    flex: 1;
}

.logic-step-content h3 {
    font-family: var(--font-serif);
    font-size: 1.4rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    color: var(--text);
}

.logic-step-content > p {
    color: var(--text-muted);
    margin-bottom: 1.2rem;
}

.logic-conditions {
    display: flex;
    flex-direction: column;
    gap: 0;
    margin-bottom: 1.2rem;
}

.logic-condition {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.2rem 1.5rem;
}

.condition-tag {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--accent);
    margin-bottom: 0.4rem;
}

.logic-condition p {
    font-size: 1rem;
    line-height: 1.5;
}

.logic-or, .logic-and {
    text-align: center;
    font-weight: 700;
    font-size: 0.85rem;
    color: var(--text-muted);
    padding: 0.5rem 0;
    letter-spacing: 2px;
}

.logic-outcome {
    padding: 1rem 1.2rem;
    border-radius: 10px;
    font-size: 0.95rem;
    display: flex;
    align-items: center;
    gap: 0.8rem;
    margin-bottom: 0.6rem;
}

.logic-outcome i {
    font-size: 1rem;
}

.outcome-nr {
    background: rgba(239, 68, 68, 0.08);
    border: 1px solid rgba(239, 68, 68, 0.2);
    color: var(--status-nr);
}

.outcome-ror {
    background: rgba(16, 185, 129, 0.08);
    border: 1px solid rgba(16, 185, 129, 0.2);
    color: var(--status-resident);
}

.outcome-rnor {
    background: rgba(245, 158, 11, 0.08);
    border: 1px solid rgba(245, 158, 11, 0.2);
    color: var(--status-nron);
}

.logic-outcomes {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

/* Exceptions */
.logic-exceptions {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.logic-exception {
    display: flex;
    gap: 1.2rem;
    align-items: flex-start;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.2rem 1.5rem;
}

.exception-icon {
    width: 40px;
    height: 40px;
    min-width: 40px;
    border-radius: 10px;
    background: var(--theme-toggle-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--accent);
    font-size: 1.1rem;
}

.logic-exception h4 {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 0.3rem;
}

.logic-exception p {
    font-size: 0.9rem;
    color: var(--text-muted);
    line-height: 1.5;
}

/* Summary Grid */
.logic-summary {
    margin-top: 2rem;
    padding-top: 2rem;
    border-top: 1px solid var(--border);
}

.logic-summary h3 {
    font-family: var(--font-serif);
    font-size: 1.3rem;
    font-weight: 700;
    margin-bottom: 1.2rem;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    color: var(--text);
}

.logic-summary h3 i {
    color: var(--accent);
}

.summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
}

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

.summary-status {
    font-family: var(--font-serif);
    font-size: 1.8rem;
    font-weight: 800;
    margin-bottom: 0.3rem;
}

.summary-card p {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.summary-card small {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.summary-ror .summary-status { color: var(--status-resident); }
.summary-ror { border-color: rgba(16, 185, 129, 0.3); }

.summary-rnor .summary-status { color: var(--status-nron); }
.summary-rnor { border-color: rgba(245, 158, 11, 0.3); }

.summary-nr .summary-status { color: var(--status-nr); }
.summary-nr { border-color: rgba(239, 68, 68, 0.3); }

@media (max-width: 600px) {
    .logic-step {
        gap: 1rem;
    }

    .logic-step-number {
        width: 36px;
        height: 36px;
        min-width: 36px;
        font-size: 0.95rem;
    }

    .logic-step::after {
        left: 17px;
    }

    .logic-header h2 {
        font-size: 1.4rem;
    }

    .logic-exception {
        flex-direction: column;
        gap: 0.8rem;
    }
}

/* ── Answer Annotation Badges ── */
.logic-answer-tag {
    margin-top: 0.7rem;
    padding: 0.45rem 0.75rem;
    border-radius: 8px;
    font-size: 0.82rem;
    line-height: 1.45;
    font-weight: 500;
}

.lba-met {
    background: rgba(16, 185, 129, 0.1);
    border: 1px solid rgba(16, 185, 129, 0.3);
    color: var(--status-resident);
}

.lba-not-met {
    background: rgba(239, 68, 68, 0.07);
    border: 1px solid rgba(239, 68, 68, 0.2);
    color: var(--status-nr);
}

.lba-neutral {
    background: var(--theme-toggle-bg);
    border: 1px solid var(--border);
    color: var(--text-muted);
}

.lba-na {
    background: var(--surface);
    border: 1px dashed var(--border);
    color: var(--text-muted);
    opacity: 0.75;
}

.hidden {
    display: none !important;
}

.fade-in {
    animation: fadeIn 0.8s ease-out forwards;
}

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

    to {
        opacity: 1;
        transform: translateY(0);
    }
}
.theme-resident .pulse-icon {
    border-color: var(--status-resident);
    color: var(--status-resident);
}
.theme-resident .gradient-text {
    color: var(--status-resident);
}

.disclaimer-box {
    background: var(--theme-toggle-bg);
    padding: 1.5rem;
    border-radius: 12px;
    border-left: 4px solid var(--status-nron);
    color: var(--text);
    text-align: left;
}

/* --- Floating Button --- */
.floating-btn {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: var(--text-primary);
    padding: 0.7rem 1.1rem;
    border-radius: 30px;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15);
    display: flex;
    align-items: center;
    gap: 0.4rem;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1000;
}

.floating-btn:hover {
    transform: translateY(-2px);
    background: rgba(255, 255, 255, 0.15);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
}

/* --- Modal Overlay --- */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(5px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.modal-overlay:not(.hidden) {
    opacity: 1;
    pointer-events: auto;
}

.modal-content {
    width: 90%;
    max-width: 520px;
    padding: 2rem;
    position: relative;
    max-height: 85vh;
    overflow-y: auto;
    border-radius: 16px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
    animation: slideUp 0.3s ease forwards;
}

.modal-close {
    position: absolute;
    top: 1rem;
    right: 1.2rem;
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 1.6rem;
    cursor: pointer;
    opacity: 0.5;
    transition: opacity 0.2s;
}

.modal-close:hover {
    opacity: 0.9;
}

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

/* ── Error Banner ── */
.error-banner {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background-color: var(--status-nr);
    color: #ffffff;
    padding: 1rem;
    text-align: center;
    font-weight: 600;
    font-size: 0.95rem;
    z-index: 3000;
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.6rem;
    transform: translateY(-100%);
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.error-banner.visible {
    transform: translateY(0);
}
