:root {
    color-scheme: light;
    --ink: #13213a;
    --ink-soft: #5f6b7e;
    --navy: #12213f;
    --navy-2: #1b315d;
    --blue: #315efb;
    --blue-soft: #e8eeff;
    --coral: #f05b47;
    --amber: #d98600;
    --green: #16815f;
    --paper: #ffffff;
    --canvas: #f2f5fa;
    --line: #dfe5ef;
    --shadow: 0 18px 50px rgba(18, 33, 63, 0.09);
    --radius: 22px;
    font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
    background: var(--canvas);
}

body {
    min-width: 320px;
    min-height: 100vh;
    margin: 0;
    color: var(--ink);
    background: var(--canvas);
    font-size: 16px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

button,
input {
    font: inherit;
}

button,
a {
    -webkit-tap-highlight-color: transparent;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.eyebrow {
    margin: 0 0 2px;
    color: inherit;
    font-size: 0.75rem;
    font-weight: 800;
    letter-spacing: 0.11em;
    line-height: 1.2;
    text-transform: uppercase;
    opacity: 0.68;
}

/* PIN screen */
.login-page {
    display: grid;
    place-items: center;
    padding: max(24px, env(safe-area-inset-top)) 18px max(24px, env(safe-area-inset-bottom));
    background:
        radial-gradient(circle at 12% 10%, rgba(49, 94, 251, 0.22), transparent 34%),
        radial-gradient(circle at 88% 88%, rgba(240, 91, 71, 0.15), transparent 32%),
        var(--navy);
}

.login-shell {
    width: min(100%, 410px);
}

.login-card {
    padding: 34px 26px 28px;
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 28px;
    background: rgba(255, 255, 255, 0.98);
    box-shadow: 0 28px 80px rgba(0, 0, 0, 0.24);
}

.login-mark,
.brand-mark {
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    border-radius: 14px;
    color: #fff;
    background: var(--coral);
    font-weight: 900;
    letter-spacing: -0.05em;
}

.login-mark {
    width: 54px;
    height: 54px;
    margin-bottom: 28px;
    font-size: 1rem;
    box-shadow: 0 10px 24px rgba(240, 91, 71, 0.28);
}

.login-card .eyebrow {
    color: var(--blue);
    opacity: 1;
}

.login-card h1 {
    margin: 4px 0 4px;
    font-size: clamp(2.3rem, 10vw, 3.25rem);
    letter-spacing: -0.06em;
    line-height: 1;
}

.login-hint {
    margin: 14px 0 24px;
    color: var(--ink-soft);
}

.pin-form {
    display: grid;
    gap: 10px;
}

.pin-form label {
    font-size: 0.875rem;
    font-weight: 800;
}

.pin-form input {
    width: 100%;
    height: 60px;
    padding: 0 18px;
    border: 2px solid var(--line);
    border-radius: 15px;
    outline: none;
    color: var(--ink);
    background: #fff;
    font-size: 1.45rem;
    font-weight: 800;
    letter-spacing: 0.42em;
    text-align: center;
    transition: border-color 160ms ease, box-shadow 160ms ease;
}

.pin-form input:focus {
    border-color: var(--blue);
    box-shadow: 0 0 0 4px rgba(49, 94, 251, 0.12);
}

.pin-form button,
.error-state button {
    min-height: 54px;
    margin-top: 6px;
    border: 0;
    border-radius: 15px;
    color: #fff;
    background: var(--blue);
    font-weight: 850;
    cursor: pointer;
    box-shadow: 0 12px 24px rgba(49, 94, 251, 0.23);
}

.pin-form button:hover,
.error-state button:hover {
    background: #234be1;
}

.pin-form button:focus-visible,
.error-state button:focus-visible,
.refresh-button:focus-visible,
.logout-link:focus-visible {
    outline: 3px solid rgba(49, 94, 251, 0.35);
    outline-offset: 3px;
}

.form-error {
    margin: 0;
    color: #b3261e;
    font-size: 0.875rem;
    font-weight: 700;
}

/* Schedule */
.app-page {
    background:
        linear-gradient(180deg, var(--navy) 0, var(--navy) 196px, var(--canvas) 196px, var(--canvas) 100%);
}

.app-shell {
    width: 100%;
    min-height: 100vh;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: min(100%, 920px);
    min-height: 92px;
    margin: 0 auto;
    padding: max(18px, env(safe-area-inset-top)) 18px 14px;
    color: #fff;
}

.topbar__brand {
    display: flex;
    align-items: center;
    gap: 13px;
}

.brand-mark {
    width: 46px;
    height: 46px;
    border-radius: 13px;
    font-size: 0.9rem;
}

.topbar h1 {
    margin: 0;
    font-size: 1.65rem;
    letter-spacing: -0.04em;
    line-height: 1.08;
}

.logout-link,
.refresh-button {
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    border: 0;
    border-radius: 13px;
    cursor: pointer;
}

.logout-link {
    color: rgba(255, 255, 255, 0.78);
    background: rgba(255, 255, 255, 0.1);
}

.logout-link:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.16);
}

.logout-link svg,
.refresh-button svg {
    width: 21px;
    height: 21px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.schedule-main {
    width: min(calc(100% - 24px), 880px);
    margin: 0 auto;
    padding-bottom: max(30px, env(safe-area-inset-bottom));
}

.date-panel {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 14px;
    min-height: 126px;
    padding: 24px 20px;
    border: 1px solid rgba(255, 255, 255, 0.7);
    border-radius: var(--radius);
    background: rgba(255, 255, 255, 0.98);
    box-shadow: var(--shadow);
}

.date-panel__weekday {
    margin: 0 0 3px;
    color: var(--blue);
    font-size: 0.9rem;
    font-weight: 850;
}

.date-panel__date {
    margin: 0;
    font-size: clamp(1.45rem, 7vw, 2.15rem);
    font-weight: 900;
    letter-spacing: -0.045em;
    line-height: 1.15;
}

.sync-control {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
}

.sync-status {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    min-height: 34px;
    padding: 7px 10px;
    border-radius: 999px;
    color: var(--ink-soft);
    background: #f4f6fa;
    font-size: 0.75rem;
    font-weight: 800;
    white-space: nowrap;
}

.sync-status__dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #8290a6;
}

.sync-status[data-state="ready"] {
    color: var(--green);
    background: #eaf7f2;
}

.sync-status[data-state="ready"] .sync-status__dot {
    background: var(--green);
}

.sync-status[data-state="warning"] {
    color: #8a5900;
    background: #fff3d9;
}

.sync-status[data-state="warning"] .sync-status__dot {
    background: var(--amber);
}

.sync-status[data-state="error"] {
    color: #a62b23;
    background: #ffe9e7;
}

.sync-status[data-state="error"] .sync-status__dot {
    background: var(--coral);
}

.refresh-button {
    flex: 0 0 auto;
    color: var(--blue);
    background: var(--blue-soft);
}

.refresh-button:hover {
    background: #dce5ff;
}

.refresh-button:disabled {
    cursor: wait;
}

.refresh-button.is-loading svg {
    animation: spin 0.9s linear infinite;
}

.schedule-section {
    margin-top: 16px;
}

.schedule-list {
    display: grid;
    gap: 12px;
}

.lesson-card {
    position: relative;
    display: grid;
    grid-template-columns: 76px minmax(0, 1fr);
    min-height: 158px;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--paper);
    box-shadow: 0 10px 32px rgba(18, 33, 63, 0.055);
}

.lesson-card::before {
    position: absolute;
    inset: 0 auto 0 0;
    width: 5px;
    content: "";
    background: var(--blue);
}

.lesson-card--weekly::before {
    background: var(--coral);
}

.lesson-card--lecture::before {
    background: #8b5cf6;
}

.lesson-card--current {
    border-color: rgba(49, 94, 251, 0.45);
    box-shadow: 0 16px 38px rgba(49, 94, 251, 0.13);
}

.lesson-card--completed {
    opacity: 0.76;
}

.lesson-card__time {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 24px 8px;
    border-right: 1px solid var(--line);
    color: var(--ink);
    background: #f8faff;
    text-align: center;
}

.lesson-card__time strong {
    font-size: 1.12rem;
    font-weight: 900;
    letter-spacing: -0.025em;
}

.lesson-card__time span {
    margin-top: 3px;
    color: var(--ink-soft);
    font-size: 0.72rem;
    font-weight: 700;
}

.lesson-card--weekly .lesson-card__time {
    background: #fff7f4;
}

.lesson-card--lecture .lesson-card__time {
    color: #6d28d9;
    background: #f5f3ff;
}

.lesson-card__body {
    min-width: 0;
    padding: 20px 17px 19px;
}

.lesson-card__meta {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 7px;
    margin-bottom: 10px;
}

.period-badge,
.source-label,
.now-badge {
    display: inline-flex;
    align-items: center;
    min-height: 25px;
    padding: 4px 8px;
    border-radius: 8px;
    font-size: 0.73rem;
    font-weight: 850;
    line-height: 1.2;
}

.period-badge {
    color: var(--blue);
    background: var(--blue-soft);
}

.lesson-card--weekly .period-badge {
    color: #b83d2e;
    background: #ffe9e4;
}

.lesson-card--lecture .period-badge {
    color: #6d28d9;
    background: #ede9fe;
}

.source-label {
    color: var(--ink-soft);
    background: #f2f4f8;
}

.now-badge {
    color: #fff;
    background: var(--green);
}

.lesson-card__title {
    margin: 0 0 14px;
    overflow-wrap: anywhere;
    font-size: clamp(1.15rem, 5.4vw, 1.45rem);
    font-weight: 900;
    letter-spacing: -0.025em;
    line-height: 1.2;
}

.lesson-details {
    display: grid;
    gap: 7px;
    margin: 0;
}

.lesson-details__row {
    display: grid;
    grid-template-columns: 76px minmax(0, 1fr);
    gap: 8px;
}

.lesson-details dt,
.lesson-details dd {
    margin: 0;
    overflow-wrap: anywhere;
}

.lesson-details dt {
    color: var(--ink-soft);
    font-size: 0.76rem;
    font-weight: 750;
}

.lesson-details dd {
    color: #35425a;
    font-size: 0.88rem;
    font-weight: 700;
}

.empty-state,
.error-state {
    padding: 42px 24px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--paper);
    box-shadow: 0 10px 32px rgba(18, 33, 63, 0.055);
    text-align: center;
}

.empty-state__icon {
    display: grid;
    place-items: center;
    width: 52px;
    height: 52px;
    margin: 0 auto 16px;
    border-radius: 16px;
    color: var(--green);
    background: #eaf7f2;
    font-size: 1.45rem;
    font-weight: 900;
}

.empty-state h2,
.error-state h2 {
    margin: 0 0 6px;
    font-size: 1.25rem;
}

.empty-state p,
.error-state p {
    margin: 0;
    color: var(--ink-soft);
}

.error-state button {
    min-height: 48px;
    padding: 0 20px;
    margin-top: 20px;
}

.schedule-footer {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 20px 10px 0;
    color: var(--ink-soft);
    font-size: 0.75rem;
    text-align: center;
}

.schedule-footer__time {
    font-weight: 750;
}

/* Loading */
.lesson-card--skeleton::before {
    background: #d8deea;
}

.lesson-card--skeleton .lesson-card__body {
    display: grid;
    align-content: start;
    gap: 13px;
}

.skeleton {
    border-radius: 8px;
    background: linear-gradient(90deg, #edf0f5 20%, #f8f9fb 40%, #edf0f5 60%);
    background-size: 300% 100%;
    animation: shimmer 1.5s ease-in-out infinite;
}

.skeleton--time {
    width: 45px;
    height: 20px;
    margin: 28px auto;
}

.skeleton--small {
    width: 110px;
    height: 24px;
}

.skeleton--title {
    width: 76%;
    height: 25px;
}

.skeleton--line {
    width: 68%;
    height: 14px;
}

.skeleton--short {
    width: 48%;
}

@keyframes shimmer {
    0% { background-position: 100% 0; }
    100% { background-position: 0 0; }
}

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

@media (max-width: 520px) {
    .date-panel {
        align-items: stretch;
        flex-direction: column;
    }

    .sync-control {
        justify-content: space-between;
    }

    .sync-status {
        white-space: normal;
    }
}

@media (min-width: 700px) {
    .topbar {
        min-height: 108px;
        padding-inline: 20px;
    }

    .schedule-main {
        width: min(calc(100% - 40px), 880px);
    }

    .date-panel {
        align-items: center;
        min-height: 142px;
        padding: 28px 30px;
    }

    .lesson-card {
        grid-template-columns: 112px minmax(0, 1fr);
        min-height: 164px;
    }

    .lesson-card__time {
        padding-top: 28px;
    }

    .lesson-card__time strong {
        font-size: 1.35rem;
    }

    .lesson-card__body {
        padding: 24px 26px;
    }

    .lesson-details__row {
        grid-template-columns: 92px minmax(0, 1fr);
    }

    .schedule-footer {
        flex-direction: row;
        justify-content: space-between;
        padding-inline: 6px;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
