/* ===== CSS Variables ===== */
:root {
    --primary-color: #0d9488;
    --primary-dark: #0f766e;
    --primary-darker: #042f2e;
    --primary-light: #f0fdfa;
    --accent-color: #f59e0b;
    --text-main: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    --bg-page: #f8fafc;
    --bg-card: #ffffff;
    --border-color: #e2e8f0;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.12);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.16);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    --font-family: 'Outfit', sans-serif;

    /* Progress bar colors */
    --green: #10b981;
    --yellow-green: #84cc16;
    --orange: #f59e0b;
    --red: #ef4444;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-family);
    background: var(--bg-page);
    color: var(--text-main);
    min-height: 100vh;
    -webkit-tap-highlight-color: transparent;
}

.app-container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    max-width: 480px;
    margin: 0 auto;
}

/* ===== Header ===== */
.app-header {
    background: linear-gradient(135deg, var(--primary-darker) 0%, var(--primary-color) 100%);
    color: white;
    padding: 0.75rem 1.25rem;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.header-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.4rem;
}

.meta-info {
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.copyright {
    font-size: 0.6rem;
    opacity: 0.6;
}

.version {
    font-size: 0.6rem;
    opacity: 0.6;
}

.header-center {
    flex: 1;
    display: flex;
    justify-content: center;
}

.timer-display {
    font-size: 1.6rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.05em;
    color: #5eead4;
    text-shadow: 0 0 12px rgba(94, 234, 212, 0.4);
    animation: pulse-glow 1.5s ease-in-out infinite;
}

@keyframes pulse-glow {

    0%,
    100% {
        text-shadow: 0 0 12px rgba(94, 234, 212, 0.4);
    }

    50% {
        text-shadow: 0 0 20px rgba(94, 234, 212, 0.7);
    }
}

.language-toggle {
    display: flex;
    gap: 4px;
}

.lang-btn {
    padding: 4px 10px;
    border: 1.5px solid rgba(255, 255, 255, 0.4);
    border-radius: 6px;
    background: transparent;
    color: rgba(255, 255, 255, 0.7);
    font-family: var(--font-family);
    font-size: 0.75rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.lang-btn.active {
    background: white;
    color: var(--primary-dark);
    border-color: white;
    box-shadow: var(--shadow-sm);
}

h1 {
    font-size: 1.15rem;
    font-weight: 700;
    text-align: center;
    margin-bottom: 0.25rem;
    letter-spacing: -0.01em;
}

/* ===== Pages ===== */
.page {
    display: none;
    flex: 1;
}

.page.active {
    display: flex;
    flex-direction: column;
}

.page-content {
    flex: 1;
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.25rem;
}

/* ===== Page 1: Instructions ===== */
.intro-card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    box-shadow: var(--shadow-md);
    text-align: center;
    width: 100%;
    border: 1px solid var(--border-color);
}

.card-icon {
    font-size: 2.5rem;
    margin-bottom: 0.75rem;
}

.intro-card h2 {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--primary-dark);
    margin-bottom: 1rem;
}

.intro-text {
    text-align: start;
    line-height: 1.7;
    color: var(--text-secondary);
    font-size: 0.95rem;
}

.intro-text ul {
    list-style: none;
    padding: 0;
    margin: 0.5rem 0;
}

.intro-text li {
    padding: 0.4rem 0;
    padding-inline-start: 1.5rem;
    position: relative;
}

.intro-text li::before {
    content: '•';
    position: absolute;
    inset-inline-start: 0.25rem;
    color: var(--primary-color);
    font-weight: 700;
    font-size: 1.1rem;
}

.intro-text h4 {
    font-size: 1rem;
    color: var(--primary-dark);
    margin: 0.75rem 0 0.25rem 0;
    font-weight: 600;
}

/* ===== Buttons ===== */
.primary-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    width: 100%;
    padding: 1rem 1.5rem;
    background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
    color: white;
    border: none;
    border-radius: var(--radius-md);
    font-family: var(--font-family);
    font-size: 1.05rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: 0 4px 12px rgba(13, 148, 136, 0.3);
}

.primary-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(13, 148, 136, 0.4);
}

.primary-btn:active {
    transform: translateY(0);
}

.secondary-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    width: 100%;
    padding: 0.85rem 1.25rem;
    background: var(--bg-card);
    color: var(--primary-dark);
    border: 2px solid var(--primary-color);
    border-radius: var(--radius-md);
    font-family: var(--font-family);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
}

.secondary-btn:hover {
    background: var(--primary-light);
}

.tertiary-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    width: 100%;
    padding: 0.75rem 1rem;
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-family: var(--font-family);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.tertiary-btn:hover {
    background: var(--bg-page);
    color: var(--primary-dark);
}

.next-btn {
    margin-top: auto;
}

.back-link {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    background: none;
    border: none;
    color: var(--text-muted);
    font-family: var(--font-family);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    padding: 0.5rem;
    transition: color 0.2s;
}

.back-link:hover {
    color: var(--primary-color);
}

.btn-icon {
    font-size: 1.15rem;
}

.btn-arrow {
    font-size: 1rem;
}

.large-btn {
    padding: 1.25rem 1.5rem;
    font-size: 1.2rem;
}

/* Test button special states */
.test-btn.running {
    background: linear-gradient(135deg, #ef4444, #dc2626);
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
    animation: pulse-red 2s ease-in-out infinite;
}

@keyframes pulse-red {

    0%,
    100% {
        box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
    }

    50% {
        box-shadow: 0 4px 20px rgba(239, 68, 68, 0.5);
    }
}

/* ===== Page 2: Test ===== */
.illustration-container {
    width: 100%;
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 1rem;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-color);
    display: flex;
    justify-content: center;
}

.test-illustration {
    width: 100%;
    max-width: 360px;
    height: auto;
    border-radius: var(--radius-sm);
}

.test-actions {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

/* ===== Page 3: Results ===== */
.result-card {
    width: 100%;
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-color);
    text-align: center;
}

.result-card h2 {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--primary-dark);
    margin-bottom: 1rem;
}

.result-time-display {
    display: flex;
    align-items: baseline;
    justify-content: center;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
}

.result-time-value {
    font-size: 3rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: var(--text-main);
}

.result-time-unit {
    font-size: 1.1rem;
    color: var(--text-secondary);
    font-weight: 500;
}

/* Progress Bar */
.progress-bar-container {
    margin: 0.5rem 0 1.5rem 0;
    position: relative;
    padding: 0 4px;
}

.progress-bar-track {
    height: 16px;
    width: 100%;
    border-radius: 8px;
    background: linear-gradient(to right,
            var(--green) 0%, var(--green) 50%,
            var(--yellow-green) 50%, var(--yellow-green) 60%,
            var(--orange) 60%, var(--orange) 70%,
            var(--red) 70%, var(--red) 100%);
    position: relative;
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.15);
}

.progress-indicator {
    position: absolute;
    top: -22px;
    left: calc(var(--progress-percent, 0) * 1% - 10px);
    width: 20px;
    text-align: center;
    transition: left 0.6s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 2;
}

.indicator-arrow {
    font-size: 1.2rem;
    color: var(--text-main);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
    line-height: 1;
}

.progress-labels {
    position: relative;
    height: 1.2rem;
    margin-top: 6px;
    width: 100%;
}

.progress-labels span {
    position: absolute;
    transform: translateX(-50%);
    font-size: 0.7rem;
    color: var(--text-muted);
    font-weight: 500;
}

/* Adjust end labels to not overflow */
.progress-labels span:first-child {
    transform: translateX(0);
}

.progress-labels span:last-child {
    transform: translateX(-100%);
}

.result-interpretation {
    font-size: 1rem;
    font-weight: 600;
    padding: 0.75rem;
    border-radius: var(--radius-sm);
    margin-top: 0.5rem;
}

.result-interpretation.risk-low {
    background: rgba(16, 185, 129, 0.1);
    color: #059669;
}

.result-interpretation.risk-mild {
    background: rgba(132, 204, 22, 0.1);
    color: #65a30d;
}

.result-interpretation.risk-moderate {
    background: rgba(245, 158, 11, 0.1);
    color: #d97706;
}

.result-interpretation.risk-high {
    background: rgba(239, 68, 68, 0.1);
    color: #dc2626;
}

.result-actions {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

/* ===== Modal ===== */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(15, 23, 42, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    padding: 1rem;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.modal-content {
    background: var(--bg-card);
    border-radius: var(--radius-xl);
    width: 100%;
    max-width: 440px;
    max-height: 85vh;
    overflow: hidden;
    box-shadow: var(--shadow-lg);
    position: relative;
    display: flex;
    flex-direction: column;
}

.modal-header {
    padding: 1.25rem 1.5rem 0.75rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h2 {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--primary-dark);
}

.modal-body {
    padding: 1rem 1.5rem 1.5rem 1.5rem;
    line-height: 1.7;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.scrollable-modal {
    overflow-y: auto;
    max-height: 60vh;
    -webkit-overflow-scrolling: touch;
}

.close-btn {
    position: absolute;
    top: 0.75rem;
    right: 1rem;
    font-size: 1.75rem;
    color: var(--text-muted);
    cursor: pointer;
    line-height: 1;
    z-index: 10;
    transition: color 0.2s;
}

html[dir="rtl"] .close-btn {
    right: auto;
    left: 1rem;
}

.close-btn:hover {
    color: var(--text-main);
}

/* Modal info sections */
.info-section {
    margin-bottom: 1rem;
}

.info-section h4 {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--primary-dark);
    margin-bottom: 0.35rem;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 4px;
}

.info-section ul {
    list-style: none;
    padding: 0;
}

.info-section li {
    padding: 0.3rem 0;
    padding-inline-start: 1.25rem;
    position: relative;
    font-size: 0.88rem;
}

.info-section li::before {
    content: '•';
    position: absolute;
    inset-inline-start: 0.15rem;
    color: var(--primary-color);
    font-weight: 700;
}

.info-section p {
    font-size: 0.88rem;
    margin-bottom: 0.35rem;
}

/* Interpretation modal range table */
.range-table {
    width: 100%;
    border-collapse: collapse;
    margin: 0.75rem 0;
    font-size: 0.82rem;
}

.range-table th,
.range-table td {
    padding: 0.5rem 0.6rem;
    border: 1px solid var(--border-color);
    text-align: start;
}

.range-table th {
    background: var(--primary-light);
    font-weight: 600;
    color: var(--primary-dark);
    font-size: 0.8rem;
}

.range-table .color-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-inline-end: 4px;
    vertical-align: middle;
}

/* Highlighted result row in interpretation */
.current-result {
    background: var(--primary-light);
    font-weight: 600;
}

/* ===== RTL Adjustments ===== */
html[dir="rtl"] .btn-arrow {
    transform: scaleX(-1);
}

html[dir="rtl"] .back-link .btn-arrow {
    transform: scaleX(-1);
}

/* ===== Animations ===== */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.page.active .page-content {
    animation: fadeIn 0.35s ease-out;
}

/* ===== Responsive ===== */
@media (min-width: 480px) {
    .app-container {
        border-left: 1px solid var(--border-color);
        border-right: 1px solid var(--border-color);
    }
}