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

html { scroll-behavior: smooth; }

/* Safety net: the page itself must never scroll sideways —
   wide tables scroll inside .table-container instead. */
html, body { overflow-x: hidden; max-width: 100%; }

body {
    font-family: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
    background-color: var(--bg);
    color: var(--text);
    margin: 0;
    padding: 24px 20px 0;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    min-height: 100vh;
    transition: background-color 0.4s ease, color 0.4s ease;
}

/* Floating gradient blobs in the background */
.bg-decor {
    position: fixed;
    inset: 0;
    z-index: -1;
    pointer-events: none;
    overflow: hidden;
}
.bg-decor::before,
.bg-decor::after {
    content: '';
    position: absolute;
    width: 55vmax;
    height: 55vmax;
    border-radius: 50%;
    filter: blur(90px);
    opacity: 0.16;
    animation: floatBlob 26s ease-in-out infinite alternate;
}
.bg-decor::before {
    background: radial-gradient(circle, var(--accent-a), transparent 65%);
    top: -20vmax;
    left: -15vmax;
}
.bg-decor::after {
    background: radial-gradient(circle, var(--accent-b), transparent 65%);
    bottom: -22vmax;
    right: -15vmax;
    animation-delay: -13s;
}
body.light-mode .bg-decor::before,
body.light-mode .bg-decor::after { opacity: 0.13; }

@keyframes floatBlob {
    0%   { transform: translate(0, 0) scale(1); }
    50%  { transform: translate(9vmax, 6vmax) scale(1.15); }
    100% { transform: translate(-5vmax, 10vmax) scale(0.95); }
}

.container {
    width: 100%;
    max-width: 1150px;
    padding: 10px 0;
}

/* ---------------- Header ---------------- */
header {
    text-align: center;
    margin: 18px 0 44px;
}

.class-badge {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 16px;
    padding: 6px 16px 6px 6px;
    border-radius: 999px;
    background: var(--card);
    border: 1px solid var(--line);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    box-shadow: var(--shadow-sm);
}
.badge-grade {
    display: inline-block;
    padding: 5px 13px;
    border-radius: 999px;
    background: var(--hero-grad);
    color: var(--hero-text);
    font-weight: 800;
    font-size: 0.9em;
    letter-spacing: 0.5px;
}
.badge-teacher {
    font-size: 0.85em;
    font-weight: 600;
    color: var(--text-soft);
}

h1 {
    font-size: clamp(2.1em, 5vw, 3em);
    font-weight: 800;
    letter-spacing: -0.02em;
    margin: 0 0 12px;
    background: var(--hero-grad);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    color: var(--accent-a); /* fallback */
    cursor: default;
    user-select: none;
    -webkit-user-select: none;
}

#datetime-display {
    font-size: 1.05em;
    font-weight: 500;
    color: var(--text-soft);
    margin: 0 0 10px;
    font-variant-numeric: tabular-nums;
}

.shift-info {
    display: inline-block;
    margin: 0;
    padding: 7px 18px;
    border-radius: 999px;
    font-size: 0.9em;
    font-weight: 700;
    color: var(--accent-c);
    background: color-mix(in srgb, var(--accent-c) 12%, transparent);
    border: 1px solid color-mix(in srgb, var(--accent-c) 30%, transparent);
}
.shift-info:empty { display: none; }

/* ---------------- Dorian's Lab cross-link ----------------
   Sits under the header as an opt-in invitation, deliberately lighter
   than the hero card so it never competes with "what is on right now". */
.lab-cta {
    /* flex + auto margins, not inline-flex: it must own its line, otherwise it
       rides up beside the shift pill on wide screens. */
    display: flex;
    width: fit-content;
    align-items: center;
    gap: 12px;
    margin: 20px auto 0;
    padding: 8px 18px 8px 8px;
    border-radius: 999px;
    text-decoration: none;
    color: var(--text);
    background: var(--card);
    border: 1px solid var(--line);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    box-shadow: var(--shadow-sm);
    transition: transform 0.25s ease, border-color 0.25s ease, box-shadow 0.25s ease;
}
.lab-cta:hover,
.lab-cta:focus-visible {
    transform: translateY(-2px);
    border-color: var(--accent-a);
    box-shadow: 0 10px 26px color-mix(in srgb, var(--accent-a) 26%, transparent);
}
.lab-cta:active { transform: translateY(0); }

.lab-cta-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: none;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: var(--hero-grad);
    color: var(--hero-text);
}

.lab-cta-text {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    text-align: left;
    line-height: 1.25;
}
.lab-cta-title {
    font-weight: 800;
    font-size: 0.95em;
    letter-spacing: -0.01em;
}
.lab-cta-sub {
    font-size: 0.78em;
    font-weight: 600;
    color: var(--text-soft);
}

.lab-cta-badge {
    flex: none;
    padding: 3px 9px;
    border-radius: 999px;
    font-size: 0.62em;
    font-weight: 800;
    letter-spacing: 1.2px;
    text-transform: uppercase;
    color: var(--accent-c);
    background: color-mix(in srgb, var(--accent-c) 14%, transparent);
    border: 1px solid color-mix(in srgb, var(--accent-c) 32%, transparent);
}
.lab-cta-badge:empty { display: none; }

.lab-cta-arrow {
    color: var(--text-soft);
    transition: transform 0.25s ease, color 0.25s ease;
}
.lab-cta:hover .lab-cta-arrow,
.lab-cta:focus-visible .lab-cta-arrow {
    transform: translateX(3px);
    color: var(--accent-a);
}

@media (prefers-reduced-motion: reduce) {
    .lab-cta,
    .lab-cta-arrow { transition: none; }
    .lab-cta:hover,
    .lab-cta:focus-visible { transform: none; }
    .lab-cta:hover .lab-cta-arrow,
    .lab-cta:focus-visible .lab-cta-arrow { transform: none; }
}

/* ---------------- Controls ---------------- */
.controls {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 8px;
}

.controls button,
.controls select,
.controls a {
    appearance: none;
    -webkit-appearance: none;
    background: var(--card);
    color: var(--text);
    border: 1px solid var(--line);
    padding: 11px 22px;
    border-radius: 999px;
    font-family: inherit;
    font-size: 0.9em;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.25s ease, border-color 0.25s ease, box-shadow 0.25s ease;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    box-shadow: var(--shadow-sm);
}

.controls button:hover,
.controls select:hover,
.controls a:hover {
    transform: translateY(-2px);
    border-color: var(--accent-a);
    box-shadow: 0 8px 22px color-mix(in srgb, var(--accent-a) 25%, transparent);
}
.controls button:active { transform: translateY(0); }

/* ---------------- Section titles ---------------- */
h2 {
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    gap: 14px;
    text-transform: uppercase;
    letter-spacing: 2.5px;
    font-size: 0.82em;
    font-weight: 800;
    color: var(--text-soft);
    margin: 46px 0 4px;
}
/* A rule on each side, each fading away from the title, so the heading sits
   centred between them. */
h2::before,
h2::after {
    content: '';
    flex: 1;
    height: 1px;
}
h2::before { background: linear-gradient(90deg, transparent, var(--line)); }
h2::after { background: linear-gradient(90deg, var(--line), transparent); }

/* ---------------- Cards ---------------- */
.card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 30px;
    box-shadow: var(--shadow);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--line);
    margin-top: 18px;
    text-align: center;
    position: relative;
    overflow: hidden;
}

/* Hero card: current lesson */
.hero-card {
    padding: 44px 30px 48px;
}
.hero-card::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    padding: 2px;
    background: var(--hero-grad);
    -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
    mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
    -webkit-mask-composite: xor;
    mask-composite: exclude;
    pointer-events: none;
    opacity: 0.85;
}

.status-label {
    display: inline-block;
    font-size: 0.78em;
    font-weight: 800;
    letter-spacing: 2px;
    text-transform: uppercase;
    color: var(--accent-b);
    background: color-mix(in srgb, var(--accent-b) 12%, transparent);
    border: 1px solid color-mix(in srgb, var(--accent-b) 30%, transparent);
    padding: 6px 16px;
    border-radius: 999px;
    margin: 0 0 16px;
}
.status-label:empty { display: none; }

.lesson-name {
    font-size: clamp(1.7em, 4vw, 2.4em);
    font-weight: 800;
    letter-spacing: -0.01em;
    line-height: 1.2;
    margin: 0 0 10px;
}

.lesson-time {
    font-size: 1.08em;
    font-weight: 500;
    color: var(--text-soft);
    margin: 0;
    font-variant-numeric: tabular-nums;
}
.lesson-time.weekend-message {
    max-width: 560px;
    margin: 0 auto;
    line-height: 1.6;
}

.progress-bar-container {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 8px;
    background-color: color-mix(in srgb, var(--text) 8%, transparent);
}
.progress-bar-fill {
    height: 100%;
    width: 0%;
    background: var(--hero-grad);
    transition: width 0.5s linear;
    border-radius: 0 4px 4px 0;
}

/* ---------------- Tables ---------------- */
.table-container {
    overflow-x: auto;
    background: var(--card);
    padding: 14px;
    margin-top: 18px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--line);
}

table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 4px;
    text-align: center;
}

th, td {
    padding: 14px 10px;
    border: none;
}

thead th {
    color: var(--text-soft);
    font-weight: 800;
    text-transform: uppercase;
    font-size: 0.72em;
    letter-spacing: 1.5px;
    padding-bottom: 10px;
}

tbody td {
    border-radius: var(--radius-sm);
    font-size: 0.92em;
    transition: background-color 0.2s ease;
}

.time-cell {
    font-size: 0.8em !important;
    font-weight: 700;
    line-height: 1.5;
    white-space: nowrap;
    color: var(--text-soft);
    font-variant-numeric: tabular-nums;
}

/* Subject color coding: each cell gets `--subj` inline from the data
   (subjects[key].color), so colors are editable without touching CSS. */
td.subj {
    font-weight: 700;
    color: color-mix(in srgb, var(--subj) calc(100% - var(--subj-text-pct)), var(--subj-text-mix));
    background: color-mix(in srgb, var(--subj) var(--subj-bg-pct), transparent);
}

/* Today's column */
th.current-day-column {
    color: var(--accent-a);
    position: relative;
}
th.current-day-column::after {
    content: '';
    display: block;
    margin: 6px auto 0;
    width: 26px;
    height: 3px;
    border-radius: 3px;
    background: var(--hero-grad);
}
td.current-day-column {
    box-shadow: inset 0 0 0 1.5px color-mix(in srgb, var(--accent-a) 45%, transparent);
    background: var(--today-tint);
}
td.current-day-column.subj {
    background: color-mix(in srgb, var(--subj) calc(var(--subj-bg-pct) + 6%), transparent);
}

/* Live lesson cell with draining highlight */
td.current-lesson {
    position: relative;
    color: var(--hero-text) !important;
    font-weight: 800;
    overflow: hidden;
    z-index: 1;
    box-shadow: 0 6px 18px color-mix(in srgb, var(--accent-b) 30%, transparent);
}
.lesson-highlight {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--hero-grad);
    z-index: -1;
    transition: height linear;
}

/* Break indicator */
.current-break-cell {
    box-shadow: inset 0 -3px 0 var(--accent-b);
}

#mobile-schedule { display: none; }

/* ---------------- Exams ---------------- */
#exam-list {
    text-align: left;
    padding: 12px 22px;
}

.no-exams {
    text-align: center;
    color: var(--text-soft);
    font-weight: 600;
    padding: 14px 0;
    margin: 0;
}

.exam-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 15px;
    padding: 16px 14px;
    border-bottom: 1px solid var(--line);
    border-left: 4px solid transparent;
    border-radius: 6px;
    margin: 2px 0;
    transition: background-color 0.25s ease, border-color 0.25s ease;
}
.exam-item:last-child { border-bottom: none; }
.exam-item:hover {
    background-color: var(--today-tint);
    border-left-color: var(--accent-b);
}

.exam-subject { font-weight: 800; font-size: 1.05em; }

.exam-info {
    color: var(--text-soft);
    font-size: 0.88em;
    font-weight: 500;
}
.exam-info span {
    display: block;
    text-align: right;
    line-height: 1.55;
}
.exam-info .countdown {
    font-weight: 800;
    color: var(--accent-b);
}

.exam-item.past { opacity: 0.35; text-decoration: line-through; }
.exam-item.upcoming {
    border-left-color: var(--accent-c);
    background-color: color-mix(in srgb, var(--accent-c) 8%, transparent);
}

/* ---------------- Calendar ---------------- */
#calendar-view-multi .card { padding: 24px; }

.calendar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 22px;
    padding: 0 6px;
}

.calendar-header button {
    background: var(--card);
    border: 1px solid var(--line);
    color: var(--text);
    border-radius: 50%;
    width: 42px;
    height: 42px;
    font-size: 1.1em;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.2s ease, border-color 0.2s ease;
}
.calendar-header button:hover {
    transform: scale(1.08);
    border-color: var(--accent-a);
}

.calendar-header h3 {
    font-size: 1.3em;
    font-weight: 800;
    margin: 0;
    text-transform: capitalize;
}

.calendar-multi-wrapper {
    display: flex;
    justify-content: space-between;
    gap: 24px;
}

.calendar-mini-container { flex: 1; }

.calendar-mini-container h4 {
    font-size: 1em;
    font-weight: 800;
    margin: 0 0 14px;
    color: var(--accent-a);
    text-transform: capitalize;
}

.calendar-mini-container table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 3px;
}

.calendar-mini-container th {
    font-size: 0.65em;
    letter-spacing: 1px;
    padding-bottom: 8px;
    color: var(--text-soft);
}

.calendar-mini-container td {
    height: 38px;
    width: 38px;
    border: 1.5px solid transparent;
    border-radius: 10px;
    padding: 0;
    font-size: 0.78em;
    font-weight: 600;
    text-align: center;
    vertical-align: middle;
    position: relative;
    font-variant-numeric: tabular-nums;
}

.calendar-mini-container td.other-month { opacity: 0.25; }

.calendar-mini-container td.afternoon-shift-week {
    background-color: color-mix(in srgb, var(--accent-a) 14%, transparent);
}

.calendar-mini-container td.has-exam { cursor: pointer; }
.calendar-mini-container td.has-exam::after {
    content: '';
    position: absolute;
    bottom: 4px;
    left: 50%;
    transform: translateX(-50%);
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background-color: var(--accent-b);
}

.calendar-mini-container td.current-day {
    border-color: var(--accent-b);
    color: var(--accent-b);
    font-weight: 800;
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent-b) 18%, transparent);
}

.calendar-legend {
    display: flex;
    justify-content: center;
    gap: 26px;
    margin-top: 22px;
    padding-top: 16px;
    border-top: 1px solid var(--line);
}

.legend-item { display: flex; align-items: center; gap: 8px; }

.legend-color-box {
    width: 15px;
    height: 15px;
    border-radius: 5px;
}
.legend-color-box.morning {
    background-color: transparent;
    border: 1.5px solid var(--line);
}
.legend-color-box.afternoon {
    background-color: color-mix(in srgb, var(--accent-a) 30%, transparent);
}

.legend-text {
    font-size: 0.8em;
    font-weight: 600;
    color: var(--text-soft);
}

/* ---------------- Exam tooltip ---------------- */
.exam-tooltip {
    position: fixed;
    transform: translateY(-110%);
    background: var(--card-solid);
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 16px;
    z-index: 1001;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease-in-out, transform 0.2s ease-in-out;
    min-width: 220px;
    text-align: left;
    box-shadow: var(--shadow);
}
.exam-tooltip.visible {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(-115%);
}
.exam-tooltip h5 {
    margin: 0 0 10px;
    font-size: 0.95em;
    font-weight: 800;
    color: var(--text);
}
.exam-tooltip p {
    margin: 0;
    font-size: 0.88em;
    color: var(--text-soft);
    line-height: 1.6;
}
.exam-tooltip .subject-name {
    font-weight: 800;
    color: var(--accent-b);
}
.tooltip-close-btn {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 24px;
    height: 24px;
    border: none;
    background: transparent;
    color: var(--text-soft);
    font-size: 1.2em;
    cursor: pointer;
    transition: color 0.2s;
}
.tooltip-close-btn:hover { color: var(--text); }

/* ---------------- Modal ---------------- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background-color: color-mix(in srgb, var(--bg) 60%, transparent);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    padding: 20px;
}
.modal-overlay.visible { opacity: 1; pointer-events: auto; }

.modal-popup {
    background: var(--card-solid);
    padding: 36px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: 1px solid var(--line);
    text-align: center;
    max-width: 100%;
    width: 460px;
    transform: scale(0.92) translateY(10px);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.modal-overlay.visible .modal-popup { transform: scale(1) translateY(0); }

.modal-popup h2 {
    display: block;
    margin: 0 0 4px;
    font-size: 1.6em;
    font-weight: 800;
    letter-spacing: 0;
    text-transform: none;
    color: var(--text);
}
.modal-popup h2::before,
.modal-popup h2::after { display: none; }

.modal-popup p {
    margin-bottom: 22px;
    font-size: 1.05em;
    line-height: 1.65;
    color: var(--text-soft);
}

#exam-modal-language-selector {
    margin-bottom: 20px;
    padding: 9px 14px;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: var(--card);
    color: var(--text);
    font-family: inherit;
    font-weight: 700;
    cursor: pointer;
}

.modal-popup button {
    background: var(--hero-grad);
    color: var(--hero-text);
    border: none;
    padding: 13px 38px;
    border-radius: 999px;
    font-family: inherit;
    font-weight: 800;
    cursor: pointer;
    transition: transform 0.25s ease, box-shadow 0.25s ease;
    font-size: 1em;
    box-shadow: 0 6px 20px color-mix(in srgb, var(--accent-b) 35%, transparent);
}
.modal-popup button:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 26px color-mix(in srgb, var(--accent-b) 45%, transparent);
}

/* ---------------- Simulation controls (hidden easter egg) ---------------- */
#simulation-controls {
    display: none;
    background: var(--card);
    padding: 24px;
    margin: 20px auto;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px dashed color-mix(in srgb, var(--accent-c) 50%, transparent);
    text-align: center;
    max-width: 600px;
}
#simulation-controls.visible { display: block; }

#simulation-controls h3 {
    text-transform: uppercase;
    letter-spacing: 2px;
    font-size: 0.85em;
    color: var(--accent-c);
    margin: 0 0 18px;
    font-weight: 800;
}

#simulation-controls input,
#simulation-controls button {
    background: var(--card-solid);
    color: var(--text);
    border: 1px solid var(--line);
    padding: 10px 16px;
    border-radius: 10px;
    font-family: inherit;
    font-size: 0.88em;
    font-weight: 600;
    cursor: pointer;
    transition: border-color 0.25s ease, transform 0.2s ease;
    margin: 4px;
    vertical-align: middle;
}
#simulation-controls input:hover,
#simulation-controls button:hover {
    border-color: var(--accent-c);
    transform: translateY(-1px);
}
#simulation-controls #sim-apply-btn {
    background: var(--accent-c);
    border-color: var(--accent-c);
    color: #0e1018;
    font-weight: 800;
}
#simulation-controls input[type="datetime-local"]::-webkit-calendar-picker-indicator {
    cursor: pointer;
    filter: invert(0.7);
}
body.light-mode #simulation-controls input[type="datetime-local"]::-webkit-calendar-picker-indicator {
    filter: none;
}

/* ---------------- Footer ---------------- */
footer {
    text-align: center;
    margin-top: 56px;
    padding: 26px 20px 34px;
    border-top: 1px solid var(--line);
}

.footer-text {
    font-size: 0.85em;
    color: var(--text-soft);
    line-height: 1.7;
    margin: 0;
}
.footer-text a {
    color: var(--accent-a);
    text-decoration: none;
    font-weight: 700;
    transition: color 0.3s;
}
.footer-text a:hover { color: var(--accent-b); }

/* ---------------- Responsive ---------------- */
@media (max-width: 1024px) {
    .calendar-multi-wrapper {
        flex-direction: column;
        gap: 30px;
    }
}

@media (max-width: 768px) {
    body { padding: 14px 12px 0; }

    header { margin-bottom: 32px; }

    .hero-card { padding: 34px 20px 40px; }

    .card { padding: 22px; }

    th, td { padding: 12px 7px; }
    tbody td { font-size: 0.85em; }

    .exam-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }
    .exam-info span { text-align: left; }

    #calendar-current,
    #calendar-next { display: none; }

    /* Weekly table scrolls sideways; keep the time column pinned
       and give day columns enough room to stay readable. */
    #full-schedule table { min-width: 620px; }
    #full-schedule th:first-child,
    #full-schedule td:first-child {
        position: sticky;
        left: 0;
        z-index: 2;
        background: var(--card-solid);
        /* Two jobs. The flat block on the left extends the pinned column
           under the container's padding and the table's border-spacing, so
           lessons cannot peek out beside it. The soft shadow on the right
           shows that the rest of the week is sliding underneath. */
        box-shadow:
            -22px 0 0 var(--card-solid),
            1px 0 0 var(--line),
            10px 0 14px -6px rgba(0, 0, 0, 0.7);
    }
    body.light-mode #full-schedule th:first-child,
    body.light-mode #full-schedule td:first-child {
        box-shadow:
            -22px 0 0 var(--card-solid),
            1px 0 0 var(--line),
            10px 0 14px -6px rgba(88, 80, 60, 0.38);
    }
    .table-container {
        overscroll-behavior-x: contain;
        -webkit-overflow-scrolling: touch;
    }
}

/* Small phones */
@media (max-width: 480px) {
    body { padding: 12px 10px 0; }

    .controls { gap: 8px; }
    .controls button,
    .controls select {
        padding: 10px 15px;
        font-size: 0.82em;
    }
    .controls .icon-control { width: 42px; height: 42px; padding: 0; }
    .icon { width: 19px; height: 19px; }

    .class-badge { margin-bottom: 12px; }
    .badge-teacher { font-size: 0.78em; }

    h1 { font-size: 1.95em; }
    #datetime-display { font-size: 0.9em; }
    .shift-info { font-size: 0.8em; padding: 6px 14px; }

    .lab-cta {
        margin-top: 16px;
        gap: 10px;
        padding: 7px 14px 7px 7px;
        max-width: 100%;
    }
    .lab-cta-icon { width: 34px; height: 34px; }
    .lab-cta .icon { width: 18px; height: 18px; }
    .lab-cta-title { font-size: 0.88em; }
    .lab-cta-sub { font-size: 0.72em; }
    .lab-cta-badge { font-size: 0.58em; padding: 3px 7px; }

    h2 {
        font-size: 0.74em;
        letter-spacing: 1.8px;
        margin-top: 36px;
        gap: 10px;
    }

    .card { padding: 18px 14px; }
    .hero-card { padding: 30px 16px 38px; }
    .status-label { font-size: 0.7em; padding: 5px 13px; }
    .lesson-name { font-size: 1.45em; }
    .lesson-time { font-size: 0.95em; }

    .table-container { padding: 8px; }
    th, td { padding: 11px 6px; }
    tbody td { font-size: 0.8em; }
    .time-cell { font-size: 0.7em !important; }
    thead th { font-size: 0.62em; letter-spacing: 1px; }

    #exam-list { padding: 8px 12px; }
    .exam-subject { font-size: 0.95em; }
    .exam-info { font-size: 0.82em; }

    #notice-list, #homework-list { padding: 8px 12px 14px; }
    .notice-banner { padding: 14px 16px; }
    .notice-headline { font-size: 1em; }
    /* Stack the due date under the task so neither gets squeezed. */
    .hw-item { flex-direction: column; gap: 6px; }
    .hw-due { text-align: left; }

    #calendar-view-multi .card { padding: 16px 10px; }
    .calendar-header { margin-bottom: 16px; }
    .calendar-header h3 { font-size: 1.05em; }
    .calendar-header button { width: 38px; height: 38px; }
    .calendar-mini-container td { height: 40px; font-size: 0.8em; }
    .calendar-legend { gap: 16px; flex-wrap: wrap; }

    .modal-popup { padding: 26px 20px; }
    .modal-popup h2 { font-size: 1.35em; }
    .modal-popup p { font-size: 0.95em; }

    footer { margin-top: 36px; padding: 20px 12px 28px; }
    .footer-text { font-size: 0.8em; }
}

/* ==========================================================
   v3 additions: notices, homework, freshness line,
   PWA install UI, update toast, standalone mode
   ========================================================== */
[hidden] { display: none !important; }

/* ---------------- Notice banner ---------------- */
.notice-banner {
    --level: var(--accent-c);
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
    margin: 0 0 8px;
    padding: 16px 20px;
    border: 1px solid color-mix(in srgb, var(--level) 40%, transparent);
    border-left: 4px solid var(--level);
    border-radius: var(--radius-sm);
    background: color-mix(in srgb, var(--level) 10%, var(--card));
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    box-shadow: var(--shadow-sm);
}
.notice-banner.level-important { --level: var(--accent-a); }
.notice-banner.level-urgent { --level: var(--accent-b); }

.notice-level {
    padding: 3px 11px;
    border-radius: 999px;
    background: color-mix(in srgb, var(--level) 18%, transparent);
    color: var(--level);
    font-size: 0.68em;
    font-weight: 800;
    letter-spacing: 1.4px;
    text-transform: uppercase;
    white-space: nowrap;
}
.notice-headline { font-size: 1.05em; font-weight: 800; line-height: 1.35; }
.notice-body { font-size: 0.9em; color: var(--text-soft); line-height: 1.55; }

/* ---------------- Notice list ---------------- */
#notice-list { text-align: left; padding: 12px 22px; }

.notice-item {
    --level: var(--accent-c);
    padding: 16px 4px;
    border-bottom: 1px solid var(--line);
}
.notice-item:last-child { border-bottom: none; }
.notice-item.level-important { --level: var(--accent-a); }
.notice-item.level-urgent { --level: var(--accent-b); }

.notice-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.notice-subject { font-weight: 800; font-size: 1.02em; }
.notice-text { margin: 6px 0 0; font-size: 0.9em; color: var(--text-soft); line-height: 1.6; }
.notice-date {
    display: block;
    margin-top: 6px;
    font-size: 0.78em;
    font-weight: 600;
    color: var(--text-soft);
    text-transform: capitalize;
}

/* ---------------- Homework ---------------- */
#homework-list { text-align: left; padding: 10px 22px 18px; }

.group-label {
    margin: 16px 0 6px;
    font-size: 0.7em;
    font-weight: 800;
    letter-spacing: 1.8px;
    text-transform: uppercase;
    color: var(--accent-a);
}
.group-label:first-child { margin-top: 6px; }

.hw-item {
    --subj: var(--accent-c);
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 14px;
    padding: 13px 14px;
    margin: 6px 0;
    border-left: 4px solid var(--subj);
    border-radius: 6px;
    background: color-mix(in srgb, var(--subj) 7%, transparent);
}
.hw-item.past { opacity: 0.42; }

.hw-main { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.hw-subject {
    font-size: 0.72em;
    font-weight: 800;
    letter-spacing: 1.2px;
    text-transform: uppercase;
    color: color-mix(in srgb, var(--subj) calc(100% - var(--subj-text-pct)), var(--subj-text-mix));
}
.hw-title { font-weight: 700; font-size: 0.98em; line-height: 1.4; overflow-wrap: anywhere; }
.hw-details { margin: 4px 0 0; font-size: 0.86em; color: var(--text-soft); line-height: 1.55; overflow-wrap: anywhere; }
.hw-due {
    flex: none;
    font-size: 0.78em;
    font-weight: 700;
    color: var(--text-soft);
    text-align: right;
    text-transform: capitalize;
}

/* ---------------- Freshness line ---------------- */
.data-status {
    margin: 0 0 10px;
    font-size: 0.76em;
    font-weight: 600;
    color: var(--text-soft);
    opacity: 0.85;
}
.data-status:empty { display: none; }
.data-status.offline { color: var(--accent-b); opacity: 1; }

/* ---------------- Icon controls ---------------- */
/* The sprite itself never renders; only its symbols are referenced. */
.icon-sprite { display: none; }

.icon {
    width: 20px;
    height: 20px;
    flex: none;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.9;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* Square, icon-only buttons: same height as the language select, far less width. */
.controls .icon-control {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    padding: 0;
    text-decoration: none;
    color: var(--text);
}
.controls .icon-control:hover { color: var(--accent-a); }

/* Install keeps its wording: an icon alone would not explain the offer. */
.controls .install-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    border-color: color-mix(in srgb, var(--accent-c) 45%, transparent);
    color: var(--accent-c);
}

/* The way in for a new admin: quiet, but findable without being told a URL. */
.footer-admin { margin: 14px 0 0; }
.footer-admin a {
    display: inline-block;
    padding: 5px 14px;
    border: 1px solid var(--line);
    border-radius: 999px;
    color: var(--text-soft);
    font-size: 0.74em;
    font-weight: 700;
    letter-spacing: 1.2px;
    text-transform: uppercase;
    text-decoration: none;
    opacity: 0.65;
    transition: opacity 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}
.footer-admin a:hover {
    opacity: 1;
    color: var(--accent-a);
    border-color: color-mix(in srgb, var(--accent-a) 45%, transparent);
}

/* iOS "Add to Home Screen" bottom sheet */
.sheet {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1002;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 24px 20px calc(24px + env(safe-area-inset-bottom));
    background: var(--card-solid);
    border-top: 1px solid var(--line);
    border-radius: var(--radius) var(--radius) 0 0;
    box-shadow: 0 -14px 40px rgba(0, 0, 0, 0.35);
    text-align: center;
    animation: sheetUp 0.4s cubic-bezier(0.34, 1.3, 0.64, 1);
}
.sheet img { width: 64px; height: 64px; border-radius: 16px; box-shadow: var(--shadow-sm); }
.sheet h3 { margin: 0; font-size: 1.15em; font-weight: 800; }
.sheet p { margin: 0; max-width: 420px; color: var(--text-soft); font-size: 0.95em; line-height: 1.55; }
.sheet p strong { color: var(--text); }
.sheet .sheet-note {
    font-size: 0.82em;
    color: var(--text-soft);
    opacity: 0.8;
    max-width: 420px;
}
.sheet-buttons {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: center;
    margin-top: 6px;
}
.sheet button {
    margin-top: 6px;
    background: var(--hero-grad);
    color: var(--hero-text);
    border: none;
    padding: 12px 34px;
    border-radius: 999px;
    font-family: inherit;
    font-weight: 800;
    font-size: 0.95em;
    cursor: pointer;
    box-shadow: 0 6px 20px color-mix(in srgb, var(--accent-b) 35%, transparent);
}
.sheet-buttons button { margin-top: 0; }
.sheet button.ghost {
    background: transparent;
    color: var(--text-soft);
    border: 1px solid var(--line);
    box-shadow: none;
    font-weight: 700;
}
.sheet button.ghost:hover { color: var(--text); border-color: var(--accent-a); }
@keyframes sheetUp {
    from { transform: translateY(100%); }
    to   { transform: translateY(0); }
}

/* "New version available" toast */
.toast {
    position: fixed;
    left: 50%;
    bottom: calc(18px + env(safe-area-inset-bottom));
    transform: translateX(-50%);
    z-index: 1002;
    display: flex;
    align-items: center;
    gap: 14px;
    max-width: calc(100vw - 24px);
    padding: 10px 10px 10px 18px;
    background: var(--card-solid);
    border: 1px solid var(--line);
    border-radius: 999px;
    box-shadow: var(--shadow);
    font-size: 0.9em;
    font-weight: 600;
}
.toast button {
    background: var(--hero-grad);
    color: var(--hero-text);
    border: none;
    padding: 9px 18px;
    border-radius: 999px;
    font-family: inherit;
    font-weight: 800;
    font-size: 0.9em;
    cursor: pointer;
    white-space: nowrap;
}
.toast button:disabled { opacity: 0.6; cursor: default; }

/* Installed (standalone) mode: keep content clear of the notch / home bar */
@media (display-mode: standalone) {
    body { padding-top: calc(14px + env(safe-area-inset-top)); }
    footer { padding-bottom: calc(34px + env(safe-area-inset-bottom)); }
}

@media (prefers-reduced-motion: reduce) {
    .sheet,
    .bg-decor::before,
    .bg-decor::after { animation: none; }
}
