:root {
  color-scheme: light;
  --background: #f3f4f6;
  --surface: #fff;
  --text: #17191c;
  --muted: #565e68;
  --line: #9da6b1;
  --free: #d7edfa;
  --accent: #245c93;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --background: #181a1e;
  --surface: #25282d;
  --text: #f3f3f3;
  --muted: #c0c6ce;
  --line: #68717b;
  --free: #293e50;
  --accent: #a7d6ff;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--background); color: var(--text); font: 14px Arial, sans-serif; }
button, input, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .8; }
button:focus-visible, input:focus-visible, select:focus-visible, summary:focus-visible, .schedule-scroll:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.icon-library { position: absolute; width: 0; height: 0; overflow: hidden; }
.page-shell { max-width: 1300px; margin: 0 auto; padding: 20px; }
.password-gate { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.password-card { width: min(420px, 100%); padding: 24px; background: var(--surface); border: 1px solid var(--line); border-radius: 4px; }
.password-card h1 { margin: 8px 0; font-size: 22px; }
.password-card > label:not(.remember-password) { display: grid; gap: 6px; margin: 18px 0 8px; font-size: 12px; }
.password-card > button { width: 100%; }
.intro { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.intro h1 { margin: 0; font-size: 24px; }
.intro p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.top-actions, .schedule-controls, .week-nav { display: flex; align-items: center; gap: 8px; }
.auth-actions { display: flex; justify-content: flex-end; gap: 8px; margin-bottom: 12px; }
.button, .icon-button, .week-nav button { border: 1px solid var(--line); background: var(--surface); color: var(--text); border-radius: 3px; padding: 7px 10px; }
.icon-button { display: grid; place-items: center; width: 36px; height: 34px; padding: 0; }
.button:hover, .icon-button:hover, .week-nav button:hover { border-color: var(--accent); }
.button-primary { background: var(--accent); border-color: var(--accent); color: var(--surface); }
html[data-theme="dark"] .button-primary { color: #14171a; }
.button-danger { color: #b3261e; }
.moon-icon { display: none; }
html[data-theme="dark"] .sun-icon { display: none; }
html[data-theme="dark"] .moon-icon { display: block; }
.schedule-section { background: var(--surface); border: 1px solid var(--line); }
.section-heading, .week-bar { padding: 10px 12px; border-bottom: 1px solid var(--line); }
.schedule-controls { justify-content: space-between; }
.week-bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.week-nav { flex-wrap: wrap; }
.week-nav label { display: flex; align-items: center; gap: 5px; }
.week-nav input { height: 32px; width: auto; }
.no-class-week { margin: 0; padding: 28px 12px; text-align: center; color: var(--muted); }
.week-entry { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.week-entry label { width: 100%; font-size: 12px; }
.week-entry input { width: auto; }
.block-week-list { list-style: none; padding: 0; margin: 0; }
.block-week-list li { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 6px 0; border-top: 1px solid var(--line); }
#substitution-status { color: var(--muted); font-size: 12px; }
#substitution-status.substitution-errors { color: #b3261e; }
.schedule-scroll { overflow-x: auto; }
.schedule-grid { min-width: 820px; display: grid; grid-template-columns: 150px repeat(5, minmax(130px, 1fr)); }
.grid-head, .time-cell, .day-total, .grid-corner, .slot, .lesson { border: 0; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.grid-head, .grid-corner { display: flex; justify-content: center; align-items: center; gap: 8px; font-size: 14px; font-weight: bold; }
.grid-head .day-date { color: var(--muted); font-size: 11px; font-weight: normal; }
.time-cell { display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 2px; text-align: center; }
.time-cell strong { white-space: nowrap; font-size: 13px; font-variant-numeric: tabular-nums; }
.time-cell span { font-size: 11px; color: var(--muted); }
.time-cell .break-time { color: #ba3732; }
html[data-theme="dark"] .time-cell .break-time { color: #ff9a94; }
.slot { background: var(--free); color: var(--accent); display: grid; place-items: center; }
.slot svg { opacity: 0; }
.slot:hover svg, .slot:focus-visible svg { opacity: 1; }
.lesson { --card-bg: hsl(var(--subject-hue, 220) 75% 86%); --card-ink: hsl(var(--subject-hue, 220) 55% 24%); position: relative; background: var(--card-bg); color: #20232b; padding: 5px; text-align: center; min-width: 0; overflow: auto; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; }
html[data-theme="dark"] .lesson { --card-bg: hsl(var(--subject-hue, 220) 42% 23%); --card-ink: hsl(var(--subject-hue, 220) 80% 85%); color: #fff; }
.lesson:disabled, .slot:disabled { opacity: 1; }
.lesson:hover:not(:disabled) { box-shadow: inset 0 0 0 2px var(--accent); }
.lesson strong { font-size: 13px; overflow-wrap: anywhere; }
.lesson span { color: var(--card-ink); font-size: 12px; overflow-wrap: anywhere; }
.lesson.substituted { background: #f7d8d6; color: #7d1717; }
html[data-theme="dark"] .lesson.substituted { background: #512e32; color: #ffd5d1; }
.lesson.substituted .original { text-decoration: line-through; color: #b3261e; }
html[data-theme="dark"] .lesson.substituted .original { color: #ffa8a1; }
.lesson.substituted span { color: inherit; }
.lesson.substituted .replacement { font-weight: bold; font-size: 13px; }
.lesson.substituted .replacement-note { font-style: italic; }
.day-total { display: flex; align-items: center; justify-content: center; gap: 4px; font-size: 11px; }
.total-label { font-weight: bold; }
.schedule-footer { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 12px; color: var(--muted); font-size: 12px; flex-wrap: wrap; }
.schedule-footer label, .remember-password { display: flex; align-items: center; gap: 7px; color: var(--text); }
.schedule-footer input, .remember-password input { width: auto; height: auto; }
.comparison { margin-top: 12px; padding: 12px; background: var(--surface); border: 1px solid var(--line); }
.comparison summary { cursor: pointer; font-weight: bold; }
.comparison p, .dialog-copy { color: var(--muted); line-height: 1.5; font-size: 12px; }
.source-item { padding: 4px 0; }
a { color: var(--accent); }
dialog { width: min(520px, calc(100% - 32px)); max-height: 90vh; overflow: auto; border: 1px solid var(--line); border-radius: 4px; padding: 20px; background: var(--surface); color: var(--text); }
dialog::backdrop { background: rgba(0, 0, 0, .5); }
.dialog-header { display: flex; align-items: start; justify-content: space-between; margin-bottom: 20px; }
.dialog-header h2 { margin: 5px 0 0; font-size: 20px; }
.section-kicker { color: var(--muted); font-size: 11px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; }
.full { grid-column: 1 / -1; }
input, select { width: 100%; min-width: 0; height: 36px; border: 1px solid var(--line); border-radius: 3px; padding: 0 8px; background: var(--surface); color: var(--text); }
.remember-password { margin: 14px 0; font-size: 12px; }
.times-heading { display: flex; justify-content: space-between; align-items: center; margin: 20px 0 10px; }
.times-heading h3 { margin: 0; font-size: 13px; }
.times-heading span { font-size: 11px; color: var(--muted); }
.times-fields { display: grid; gap: 8px; }
.time-row { display: grid; grid-template-columns: 65px 1fr 1fr; gap: 10px; align-items: center; }
.time-row > span { font-size: 12px; }
.form-error { color: #b3261e; font-size: 12px; min-height: 1em; }
.dialog-actions { display: flex; align-items: center; gap: 7px; margin-top: 20px; flex-wrap: wrap; }
.action-spacer { flex: 1; }
.storage-warning { position: fixed; bottom: 20px; right: 20px; padding: 14px 18px; background: #8c3731; color: white; z-index: 10; }
[hidden] { display: none !important; }
@media (max-width: 700px) {
  .page-shell { padding: 12px; }
  .intro { align-items: flex-start; flex-direction: column; }
  .schedule-controls { flex-wrap: wrap; }
  .auth-actions { justify-content: flex-start; flex-wrap: wrap; }
}
