:root {
    --bg: #0e2238; --bg2: #07121f; --card: rgba(255,255,255,.06); --line: rgba(255,255,255,.17);
    --ink: #eef6ff; --muted: #b9d3ee; --accent: #74c0fc; --accent-ink: #06172a; --field: rgba(255,255,255,.08);
    --soft: rgba(116,192,252,.15); --good: #8ce99a; --warn: #ffc078; --warn-bg: rgba(255,192,120,.14); --bad: #ffa8a8;
    color-scheme: dark;
}
@media (prefers-color-scheme: light) {
    :root { --bg: #eef6fd; --bg2: #d6e8f8; --card: #fff; --line: #c3d9ee; --ink: #0d2136; --muted: #3d5873;
            --accent: #1971c2; --accent-ink: #fff; --field: #f8fbff; --soft: #e1effc; --good: #2b8a3e; --warn: #b45309; --warn-bg: #fff1dc; --bad: #c92a2a; color-scheme: light; }
}
:root[data-theme="light"] { --bg: #eef6fd; --bg2: #d6e8f8; --card: #fff; --line: #c3d9ee; --ink: #0d2136; --muted: #3d5873;
            --accent: #1971c2; --accent-ink: #fff; --field: #f8fbff; --soft: #e1effc; --good: #2b8a3e; --warn: #b45309; --warn-bg: #fff1dc; --bad: #c92a2a; color-scheme: light; }
:root[data-theme="dark"] {
    --bg: #0e2238; --bg2: #07121f; --card: rgba(255,255,255,.06); --line: rgba(255,255,255,.17);
    --ink: #eef6ff; --muted: #b9d3ee; --accent: #74c0fc; --accent-ink: #06172a; --field: rgba(255,255,255,.08);
    --soft: rgba(116,192,252,.15); --good: #8ce99a; --warn: #ffc078; --warn-bg: rgba(255,192,120,.14); --bad: #ffa8a8;
    color-scheme: dark;
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; padding: clamp(1rem,4vw,2.5rem) 1rem 4rem; display: flex; justify-content: center;
       font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--ink);
       background: var(--bg2) linear-gradient(180deg, var(--bg), var(--bg2) 900px) no-repeat; touch-action: manipulation; }
.app { width: min(560px, 100%); min-width: 0; display: flex; flex-direction: column; }
.col-main, .col-side { display: contents; }
.app > .topbar, .app > .back { order: 0; }
.app > header, .warn-box { order: 1; }
.now { order: 2; }
.app > .col-main > .day { order: 3; }
.week { order: 4; }
.add { order: 5; }
.subjects { order: 6; }
.settings { order: 7; }
.tools { order: 8; }
.app > .faq { order: 9; }
.app > footer { order: 10; }
/* first use: the form straight under the title */
.app.setup .add { order: 2; }
.app.setup .now { order: 3; }
header { text-align: center; margin-bottom: 1.1rem; }
h1 { margin: 0; font-size: 1.7rem; line-height: 1.2; letter-spacing: -.02em; }
.sub { margin: .4rem 0 0; color: var(--muted); font-size: 1rem; }
h2 { margin: 0 0 .7rem; font-size: 1.15rem; overflow-wrap: anywhere; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 1.1rem; margin-bottom: .9rem; min-width: 0; }
label, legend, .label-like { display: block; margin: .9rem 0 .35rem; font-size: .9rem; font-weight: 600; color: var(--muted); padding: 0; }
input[type=text], input[type=date], input[type=time], select, textarea { display: block; width: 100%; min-width: 0; max-width: 100%; min-height: 48px; padding: .6rem .8rem; font: inherit; font-size: 1.05rem; color: var(--ink);
       background: var(--field); border: 1px solid var(--line); border-radius: 12px; -webkit-appearance: none; appearance: none; }
select, input[type=date], input[type=time] { -webkit-appearance: auto; appearance: auto; }
textarea { resize: vertical; line-height: 1.4; min-height: 84px; }
input[aria-invalid="true"], select[aria-invalid="true"] { border-color: var(--bad); }
select option { color: #111; background: #fff; }
input:focus-visible, button:focus-visible, select:focus-visible, textarea:focus-visible, summary:focus-visible, a:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
::placeholder { color: var(--muted); opacity: .75; }
.hint { margin: .45rem 0 0; color: var(--muted); font-size: .88rem; overflow-wrap: anywhere; }
.hint.top { margin: 0 0 .7rem; }
.hint.tight { margin: 0 0 .5rem; }
.hint:empty { display: none; }
[hidden] { display: none !important; }
.warn-box { margin: 0 0 .9rem; padding: .7rem .9rem; border-radius: 12px; background: var(--warn-bg); border-left: 5px solid var(--warn); font-weight: 600; }
fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }

/* buttons */
.primary, .secondary, .danger { display: flex; align-items: center; justify-content: center; width: 100%; min-height: 48px; padding: .5rem .8rem; border-radius: 12px;
       font: inherit; font-weight: 700; text-align: center; text-decoration: none; cursor: pointer; line-height: 1.2; overflow-wrap: anywhere; }
.primary { border: 0; background: var(--accent); color: var(--accent-ink); }
.secondary { border: 1px solid var(--line); background: var(--field); color: var(--ink); font-weight: 600; }
.secondary.small { width: auto; min-height: 44px; padding: 0 .85rem; font-size: .92rem; margin: 0; flex: 0 0 auto; }
.danger { border: 1px solid var(--bad); background: transparent; color: var(--bad); font-weight: 600; margin-top: .9rem; }
.link { display: block; min-height: 44px; margin-top: .3rem; padding: 0 .1rem; border: 0; background: none; color: var(--accent); font: inherit; font-size: .95rem; font-weight: 600; text-align: left; cursor: pointer; }
.err { margin: .4rem 0 0; color: var(--bad); font-weight: 600; font-size: .92rem; overflow-wrap: anywhere; }
.err:empty { margin: 0; }
.msg { margin: 0; color: var(--muted); font-size: .95rem; overflow-wrap: anywhere; }
.msg.show { display: flex; flex-wrap: wrap; align-items: center; gap: .3rem .8rem; margin: .2rem 0 .8rem; padding: .5rem .75rem; border-radius: 12px; background: var(--soft); color: var(--ink); }
.msg .undo { min-height: 40px; padding: 0 .9rem; border: 1px solid var(--accent); border-radius: 10px; background: none; color: var(--accent); font: inherit; font-weight: 700; cursor: pointer; }
.week .msg.show, .settings .msg.show, .tools .msg.show { margin: .8rem 0 0; }
.row-btns { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: 1rem; }
.row-btns > * { flex: 1 1 9rem; width: auto; margin-top: 0; }
.tool-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: .5rem; margin-top: 1rem; }
.tool-grid .wide { grid-column: 1 / -1; }
.inline { display: flex; align-items: center; gap: .5rem; min-width: 0; }
.inline > input { flex: 1 1 auto; }
.pair { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 0 .6rem; }
.check { display: flex; align-items: flex-start; gap: .6rem; margin: .3rem 0 0; font-size: 1rem; font-weight: 600; color: var(--ink); cursor: pointer; min-height: 44px; padding-top: .55rem; }
.check input { width: 22px; height: 22px; margin: 0; flex: 0 0 auto; accent-color: var(--accent); }
.seg { display: flex; flex-wrap: wrap; gap: .4rem; }
.seg label { display: flex; align-items: center; gap: .5rem; margin: 0; min-height: 44px; padding: 0 .9rem; border: 1px solid var(--line); border-radius: 999px; background: var(--field); color: var(--ink); font-size: .95rem; cursor: pointer; }
.seg label:has(input:checked) { border-color: var(--accent); background: var(--soft); }
.seg input { accent-color: var(--accent); margin: 0; }
.seg-btn { min-height: 44px; padding: 0 1rem; border: 1px solid var(--line); border-radius: 999px; background: var(--field); color: var(--ink); font: inherit; font-size: .95rem; font-weight: 600; cursor: pointer; }
.seg-btn[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.dot { display: inline-block; width: .8em; height: .8em; border-radius: 50%; margin-right: .45em; flex: 0 0 auto; vertical-align: baseline; border: 2px solid rgba(255,255,255,.7); }
.badge { display: inline-block; margin-left: .5rem; padding: .05rem .5rem; border-radius: 999px; background: var(--accent); color: var(--accent-ink); font-size: .78rem; font-weight: 700; vertical-align: middle; }

/* right now */
.now { border: 2px solid var(--accent); }
.now .big { margin: 0; font-size: 1.4rem; font-weight: 800; line-height: 1.25; overflow-wrap: anywhere; }
.now .detail { margin: .3rem 0 0; color: var(--muted); overflow-wrap: anywhere; }
.now .left { margin: .35rem 0 0; font-weight: 700; color: var(--accent); }
.now .last { color: var(--ink); font-weight: 600; margin-top: .6rem; }
.later { margin-top: .9rem; padding-top: .8rem; border-top: 1px solid var(--line); }
.later .label { margin: 0; font-size: .85rem; font-weight: 700; color: var(--muted); }
.next-line { margin: .15rem 0 0; font-size: 1.15rem; font-weight: 700; overflow-wrap: anywhere; }
.later .detail { margin: .2rem 0 0; }
.bring { margin: .5rem 0 0; padding: .4rem .65rem; border-radius: 10px; background: var(--warn-bg); color: var(--ink); font-size: .95rem; font-weight: 600; overflow-wrap: anywhere; }

/* today and tomorrow */
.lessons { list-style: none; margin: 0; padding: 0; display: grid; gap: .45rem; }
.lesson { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: .2rem .75rem; padding: .6rem .75rem; border: 1px solid var(--line); border-left: 6px solid var(--c); border-radius: 12px; background: var(--field); }
.lesson .when { font-variant-numeric: tabular-nums; font-weight: 700; font-size: .95rem; white-space: nowrap; }
.lesson .what { min-width: 0; display: flex; flex-direction: column; }
.lesson .name { font-weight: 700; overflow-wrap: anywhere; }
.lesson .meta, .wl .meta { color: var(--muted); font-size: .88rem; overflow-wrap: anywhere; }
.lesson .badge { margin: 0; }
.lesson.on { border-color: var(--accent); border-left-color: var(--c); background: var(--soft); }
.lesson.done { opacity: .55; }
.free-gap { padding: .3rem .75rem; border: 1px dashed var(--line); border-radius: 10px; color: var(--muted); font-size: .88rem; }
.free-gap.on { border-color: var(--accent); color: var(--ink); font-weight: 600; }

/* whole week */
.week .seg { margin: 0 0 .8rem; }
.week-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: .6rem; }
.wday { min-width: 0; padding: .6rem .65rem; border: 1px solid var(--line); border-radius: 12px; }
.wday.is-today { border: 2px solid var(--accent); }
.wday-h { margin: 0 0 .4rem; font-size: .98rem; }
.wday .hint { margin: 0; }
.wlist { list-style: none; margin: 0; padding: 0; display: grid; gap: .35rem; }
.wl { display: flex; flex-direction: column; gap: 0; padding: .3rem .5rem; border-left: 5px solid var(--c); border-radius: 6px; background: var(--field); min-width: 0; }
.wl .when { font-variant-numeric: tabular-nums; font-size: .85rem; font-weight: 600; color: var(--muted); overflow-wrap: anywhere; }
.wl .name { font-weight: 700; font-size: .95rem; overflow-wrap: break-word; hyphens: auto; min-width: 0; }

/* the form */
.swatches { display: flex; flex-wrap: wrap; gap: .45rem; }
.sw { position: relative; width: 44px; height: 44px; margin: 0; border-radius: 50%; background: var(--c); cursor: pointer; border: 3px solid transparent; }
.sw input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.sw:has(input:checked) { border-color: var(--ink); box-shadow: 0 0 0 2px var(--bg2) inset; }
.sw:has(input:focus-visible) { outline: 3px solid var(--accent); outline-offset: 2px; }
.rows { list-style: none; margin: 0; padding: 0; display: grid; gap: .6rem; }
.row { padding: .2rem .8rem .5rem; border: 1px solid var(--line); border-radius: 14px; background: var(--soft); min-width: 0; }
.row-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 0 .6rem; }
.row label { margin-top: .6rem; }
.quick { display: flex; flex-wrap: wrap; align-items: center; gap: .35rem; margin-top: .5rem; }
.quick-l { font-size: .85rem; color: var(--muted); font-weight: 600; }
.chip { min-height: 38px; padding: 0 .7rem; border: 1px solid var(--line); border-radius: 999px; background: var(--field); color: var(--ink); font: inherit; font-size: .88rem; font-weight: 600; cursor: pointer; }
.chip:hover { border-color: var(--accent); }
.row .rm { min-height: 40px; color: var(--bad); font-size: .9rem; }
#add-row { margin-top: .6rem; }
.opt { margin-top: .2rem; }

/* subjects and holidays */
.box-list { list-style: none; margin: 0; padding: 0; display: grid; gap: .6rem; }
.box { padding: .75rem .85rem; border: 1px solid var(--line); border-left: 6px solid var(--c, var(--line)); border-radius: 14px; background: var(--field); min-width: 0; transition: box-shadow .3s; }
.box.flash { box-shadow: 0 0 0 3px var(--accent); }
.box-head { display: flex; align-items: center; justify-content: space-between; gap: .6rem; }
.box-h { margin: 0; font-size: 1.05rem; display: flex; align-items: center; min-width: 0; overflow-wrap: anywhere; }
.box-sub { margin: .2rem 0 0; color: var(--muted); font-size: .9rem; overflow-wrap: anywhere; }
.times { list-style: none; margin: .4rem 0 0; padding: 0; font-size: .95rem; font-variant-numeric: tabular-nums; }
.times li { padding: .1rem 0; overflow-wrap: anywhere; }
.box .bring { margin-top: .45rem; }
.note { margin: .4rem 0 0; color: var(--muted); font-size: .9rem; font-style: italic; overflow-wrap: anywhere; white-space: pre-wrap; }
.clash { margin: .45rem 0 0; color: var(--bad); font-weight: 600; font-size: .9rem; overflow-wrap: anywhere; }
.empty { margin: 0; color: var(--muted); }
.g-h { margin: 1.2rem 0 .3rem; font-size: 1rem; }
.hol { display: flex; align-items: center; justify-content: space-between; gap: .6rem; }
.hol-txt { display: flex; flex-direction: column; min-width: 0; }
.hol-txt .name { font-weight: 700; overflow-wrap: anywhere; }
.hol-txt .meta { color: var(--muted); font-size: .88rem; }
.ab-now { margin-top: .4rem; }
.tools .inline .small { min-height: 48px; }

@media print {
    body { background: #fff; color: #000; padding: 0; display: block; }
    .app { width: 100%; display: block; }
    .back, .topbar, header .sub, .add, .settings, .tools, .faq, footer, .msg, #week-tools, .week .seg, .theme-toggle, .help-btn { display: none !important; }
    .card, .box, .wday { border-color: #999; background: #fff; break-inside: avoid; }
    .hint, .meta, .when, .box-sub { color: #333 !important; }
    body.print-week .app > *:not(.col-main), body.print-week .col-main > *:not(.week) { display: none !important; }
    body.print-week .week { border: 0; padding: 0; }
    body.print-week .week-grid { grid-template-columns: repeat(auto-fit, minmax(0, 1fr)); grid-auto-flow: column; }
    .wl { background: #fff; }
}

/* questions */
.faq { margin-top: 1.2rem; }
.faq details { border: 1px solid var(--line); border-radius: 12px; margin: 0 0 .5rem; background: var(--card); }
.faq summary { cursor: pointer; padding: .75rem .9rem; font-weight: 600; min-height: 44px; }
.faq details p { margin: 0; padding: 0 .9rem .8rem; color: var(--muted); }
footer { margin-top: 1.4rem; text-align: center; font-size: .9rem; }
footer a { color: var(--muted); }

.back { display: inline-flex; align-items: center; gap: .4rem; min-height: 44px; margin: 0 0 .5rem; padding: 0 1rem 0 .8rem; border: 1px solid var(--line, rgba(127,127,127,.4)); border-radius: 999px; color: var(--muted, var(--mut, inherit)); font-size: .92rem; font-weight: 600; text-decoration: none; background: transparent; }
.back:hover { color: var(--ink, inherit); border-color: currentColor; }
.back:focus-visible { outline: 3px solid var(--accent, var(--acc, #fff)); outline-offset: 2px; }

/* tablets: the week as columns */
@media (min-width: 600px) {
    .week-grid { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
}

/* narrow phones */
@media (max-width: 420px) {
    .card { padding: 1rem .8rem; }
    .box { padding: .65rem .7rem; }
    .row { padding: .2rem .65rem .5rem; }
    .tool-grid, .settings .pair { grid-template-columns: minmax(0, 1fr); }
    .row-btns > * { flex-basis: 100%; }
    .inline.grow { flex-wrap: wrap; }
    .inline.grow .small { flex: 1 1 100%; }
    .lesson { grid-template-columns: minmax(0, 1fr) auto; }
    .lesson .when { grid-column: 1; }
    .lesson .what { grid-column: 1 / -1; grid-row: 2; }
    .lesson .badge { grid-column: 2; grid-row: 1; justify-self: end; }
    h1 { font-size: 1.5rem; }
    .now .big { font-size: 1.25rem; }
}
@media (max-width: 360px) {
    .topbar .theme-toggle { padding: 0; width: 44px; justify-content: center; }
    .topbar .theme-toggle span { display: none; }
    .pair, .row-grid { grid-template-columns: minmax(0, 1fr); }
}

/* laptops and desktops: now, today, tomorrow and the week on the left; the form, subjects and settings on the right */
@media (min-width: 900px) {
    .app { width: min(1160px, 100%); display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); column-gap: 1.5rem; align-items: start; }
    .app > * { grid-column: 1 / -1; }
    .col-main, .col-side { display: block; min-width: 0; }
    .app > .topbar { grid-row: 1; }
    .app > header { grid-row: 2; }
    .app > .warn-box { grid-row: 3; }
    .app > .col-main { grid-column: 1; grid-row: 4; }
    .app > .col-side { grid-column: 2; grid-row: 4; }
    .app > .faq { grid-row: 5; width: min(760px, 100%); justify-self: center; }
    .app > footer { grid-row: 6; width: min(760px, 100%); justify-self: center; }
    header h1 { font-size: 2.3rem; }
    .now .big { font-size: 1.7rem; }
    .week-grid { grid-template-columns: repeat(auto-fit, minmax(100px, 1fr)); gap: .5rem; }
    .wday { padding: .55rem .5rem; }
}
