/* ============================================================
   CSS VARIABLES AND RESET
   ============================================================ */
:root {
    --color-bg: hsl(15, 25%, 92%);
    --color-primary: hsl(20, 80%, 50%);
    --color-primary-dark: hsl(20, 85%, 42%);
    --color-primary-light: hsl(20, 80%, 96%);
    --color-surface: #ffffff;
    --color-border: #e0d5cc;
    --color-text: #2c2c2c;
    --color-text-muted: #6b6b6b;
    --color-success: #4caf50;
    --color-error: #e53935;
    --radius-card: 16px;
    --radius-btn: 12px;
    --shadow-card: 0 2px 12px rgba(0, 0, 0, 0.08);
    --shadow-card-hover: 0 6px 20px rgba(0, 0, 0, 0.14);
    --font-primary: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --transition-fast: 0.18s ease;
    --transition-medium: 0.35s ease;
}

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

body {
    font-family: var(--font-primary);
    background: var(--color-bg);
    color: var(--color-text);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

/* ============================================================
   SCREEN SYSTEM
   ============================================================ */
.screen {
    display: none;
    min-height: 100vh;
}

.screen.active {
    display: flex;
    flex-direction: column;
}

/* ============================================================
   LOADING SCREEN
   ============================================================ */
.screen-loading {
    align-items: center;
    justify-content: center;
    gap: 16px;
    color: var(--color-text-muted);
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--color-border);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* ============================================================
   APP HEADER (Topics screen)
   ============================================================ */
.app-header {
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    padding: 0 24px;
    height: 56px;
    flex-shrink: 0;
}

.header-inner {
    max-width: 900px;
    margin: 0 auto;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.app-logo {
    font-weight: 700;
    font-size: 1.1em;
    color: var(--color-primary);
}

.header-user {
    font-size: 0.9em;
    color: var(--color-text-muted);
}

/* Hide app header when embedded as an iframe inside my.psilyou.com */
body.embedded .app-header {
    display: none;
}

/* ============================================================
   TOPICS SCREEN
   ============================================================ */
.topics-main {
    max-width: 900px;
    margin: 0 auto;
    padding: 32px 24px;
    flex: 1;
    width: 100%;
}

.topics-heading {
    font-size: 1.5em;
    font-weight: 700;
    color: var(--color-text);
    margin-bottom: 24px;
}

.topics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
}

/* ============================================================
   TOPIC GROUP (collapsible parent)
   ============================================================ */
.topic-group {
    grid-column: 1 / -1;
}

.topic-group-header {
    list-style: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    background: var(--color-surface);
    border-radius: var(--radius-card);
    cursor: pointer;
    font-weight: 600;
    font-size: 0.95em;
    border: 1px solid var(--color-border);
    transition: background var(--transition-fast);
    user-select: none;
}

.topic-group-header::-webkit-details-marker { display: none; }
.topic-group-header::marker { display: none; }

.topic-group-header:hover {
    background: var(--color-primary-light);
}

.group-name {
    color: var(--color-text);
}

.group-progress {
    font-size: 0.8em;
    color: var(--color-text-muted);
    font-weight: 400;
}

.topic-group-children {
    padding: 12px 0 0 16px;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 12px;
}

/* ============================================================
   TOPIC CARD
   ============================================================ */
.topic-card {
    background: var(--color-surface);
    border-radius: var(--radius-card);
    box-shadow: var(--shadow-card);
    padding: 20px;
    display: flex;
    align-items: flex-start;
    gap: 16px;
    cursor: pointer;
    transition: box-shadow var(--transition-fast), transform var(--transition-fast);
    border: 2px solid transparent;
    text-align: left;
}

.topic-card:hover {
    box-shadow: var(--shadow-card-hover);
    transform: translateY(-2px);
}

.topic-card:focus {
    outline: none;
    border-color: var(--color-primary);
}

.topic-card--complete {
    border-color: var(--color-success);
}

.topic-card-ring {
    flex-shrink: 0;
}

.topic-card-body {
    flex: 1;
    min-width: 0;
}

.topic-card-name {
    font-size: 1em;
    font-weight: 600;
    color: var(--color-text);
    margin-bottom: 4px;
}

.topic-card-desc {
    font-size: 0.85em;
    color: var(--color-text-muted);
    line-height: 1.5;
    margin-bottom: 8px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.topic-card-progress {
    font-size: 0.8em;
    color: var(--color-text-muted);
}

/* ============================================================
   QUESTION SCREEN — HEADER
   ============================================================ */
.question-header {
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    padding: 12px 24px;
    display: flex;
    align-items: center;
    gap: 16px;
    flex-shrink: 0;
}

.btn-back {
    background: none;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    font-family: inherit;
    font-size: 0.9em;
    color: var(--color-text-muted);
    padding: 4px 0;
    transition: color var(--transition-fast);
}

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

.back-arrow {
    font-size: 1.1em;
}

.question-topic-name {
    font-weight: 600;
    color: var(--color-text);
    font-size: 0.95em;
}

/* ============================================================
   PROGRESS BAR
   ============================================================ */
.progress-track {
    height: 4px;
    background: var(--color-border);
    flex-shrink: 0;
}

.progress-bar {
    height: 100%;
    width: 0%;
    background: var(--color-primary);
    transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    border-radius: 0 2px 2px 0;
}


/* ============================================================
   QUESTION MAIN + CARD
   ============================================================ */
.question-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px;
    gap: 16px;
}

.question-card {
    background: var(--color-surface);
    border-radius: var(--radius-card);
    box-shadow: var(--shadow-card);
    padding: 32px;
    max-width: 600px;
    width: 100%;
    transition: opacity var(--transition-fast), transform var(--transition-fast);
}

.question-text {
    font-size: 1.15em;
    line-height: 1.7;
    color: var(--color-text);
    margin-bottom: 24px;
    font-weight: 500;
}

/* Card slide animations */
.card-exit {
    opacity: 0;
    transform: translateX(-20px);
}

.card-enter {
    opacity: 0;
    transform: translateX(20px);
}

/* ============================================================
   ANSWER AREAS
   ============================================================ */
.answer-area {
    flex-direction: column;
    gap: 12px;
}

/* Open-ended */
.open-ended-textarea {
    width: 100%;
    padding: 14px 16px;
    border: 2px solid var(--color-border);
    border-radius: 10px;
    font-family: inherit;
    font-size: 0.95em;
    line-height: 1.6;
    resize: vertical;
    min-height: 100px;
    color: var(--color-text);
    background: var(--color-surface);
    transition: border-color var(--transition-fast);
}

.open-ended-textarea:focus {
    outline: none;
    border-color: var(--color-primary);
}

/* Yes/No */
.yes-no-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

/* Multiple choice */
.mc-grid {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* Shared option button */
.btn-option {
    padding: 16px;
    border: 2px solid var(--color-border);
    border-radius: var(--radius-btn);
    background: var(--color-surface);
    font-family: inherit;
    font-size: 1em;
    font-weight: 500;
    cursor: pointer;
    transition: border-color var(--transition-fast), background var(--transition-fast), color var(--transition-fast);
    text-align: left;
    color: var(--color-text);
}

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

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

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

/* Spinner shown on the selected button while API call is in-flight */
.btn-option--saving::after {
    content: '';
    display: inline-block;
    width: 12px;
    height: 12px;
    margin-left: 8px;
    border: 2px solid currentColor;
    border-top-color: transparent;
    border-radius: 50%;
    animation: btn-spin 0.6s linear infinite;
    vertical-align: middle;
}

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

/* Primary save button */
.btn-primary {
    padding: 14px 28px;
    background: var(--color-primary);
    color: white;
    border: none;
    border-radius: var(--radius-btn);
    font-family: inherit;
    font-weight: 600;
    font-size: 1em;
    cursor: pointer;
    transition: background var(--transition-fast), transform var(--transition-fast);
}

.btn-primary:hover:not(:disabled) {
    background: var(--color-primary-dark);
    transform: translateY(-1px);
}

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

/* ============================================================
   CURRENT ANSWER DISPLAY (answered state)
   ============================================================ */
.current-answer {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 16px;
    background: hsl(15, 25%, 96%);
    border-radius: 10px;
    border: 1px solid var(--color-border);
}

.current-answer-text {
    flex: 1;
    font-size: 0.9em;
    color: var(--color-text);
    line-height: 1.5;
}

.btn-edit {
    background: none;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    padding: 6px 12px;
    font-family: inherit;
    font-size: 0.8em;
    cursor: pointer;
    color: var(--color-text-muted);
    transition: border-color var(--transition-fast), color var(--transition-fast);
    flex-shrink: 0;
}

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

/* ============================================================
   SAVE FEEDBACK FLASH
   ============================================================ */
.save-feedback {
    align-items: center;
    gap: 8px;
    color: var(--color-success);
    font-weight: 500;
    font-size: 0.9em;
    opacity: 0;
    transition: opacity 0.3s ease;
    margin-top: 8px;
}

.save-feedback--visible {
    opacity: 1;
}

.save-feedback--error {
    color: var(--color-error);
    opacity: 1;
}

.checkmark {
    font-size: 1.1em;
}

/* ============================================================
   NAVIGATION (Skip / Next)
   ============================================================ */
.question-nav {
    max-width: 600px;
    width: 100%;
    display: flex;
    justify-content: flex-end;
}

.btn-skip {
    background: none;
    border: none;
    font-family: inherit;
    font-size: 0.9em;
    color: var(--color-text-muted);
    cursor: pointer;
    padding: 8px 0;
    transition: color var(--transition-fast);
}

.btn-skip:hover {
    color: var(--color-primary);
    text-decoration: underline;
}

/* ============================================================
   COMPLETION OVERLAY
   ============================================================ */
.completion-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    animation: fadeIn 0.3s ease;
}

.completion-card {
    background: var(--color-surface);
    border-radius: var(--radius-card);
    padding: 48px 40px;
    max-width: 440px;
    width: 90%;
    text-align: center;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.2);
}

.completion-icon {
    font-size: 3em;
    margin-bottom: 16px;
    animation: celebPop 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    display: block;
}

.completion-heading {
    font-size: 1.4em;
    font-weight: 700;
    margin-bottom: 8px;
    color: var(--color-text);
}

.completion-subtext {
    color: var(--color-text-muted);
    margin-bottom: 28px;
    font-size: 0.95em;
}

@keyframes celebPop {
    0%   { transform: scale(0); }
    80%  { transform: scale(1.2); }
    100% { transform: scale(1); }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

/* ============================================================
   RESPONSIVE — MOBILE
   ============================================================ */
@media (max-width: 600px) {
    .topics-grid {
        grid-template-columns: 1fr;
    }

    .topic-group-children {
        grid-template-columns: 1fr;
        padding-left: 8px;
    }

    .topics-main {
        padding: 16px;
    }

    .question-card {
        padding: 20px;
    }

    .question-text {
        font-size: 1em;
    }

    .yes-no-grid {
        grid-template-columns: 1fr;
    }

    .question-main {
        padding: 16px;
    }

    .completion-card {
        padding: 32px 24px;
    }

    .question-header {
        padding: 10px 16px;
    }

    .progress-label {
        padding: 6px 16px;
    }
}
