:root {
    --bg: #1b1633; --bg2: #0e0b1d; --card: rgba(255,255,255,.06); --line: rgba(255,255,255,.17);
    --ink: #f4f2fb; --muted: #c4bddf; --accent: #b9a5ff; --accent-ink: #1a0f3d; --field: rgba(255,255,255,.08);
    --soft: rgba(185,165,255,.16); --good: #6ee7a8; --warn: #fbbf72; --warn-bg: rgba(251,191,114,.13); --bad: #fda4af; --exam: #fda4af;
    color-scheme: dark;
}
@media (prefers-color-scheme: light) {
    :root { --bg: #f6f4fd; --bg2: #e9e4f8; --card: #fff; --line: #d9d2ef; --ink: #1d1638; --muted: #574d78;
            --accent: #5b36d1; --accent-ink: #fff; --field: #faf9fe; --soft: #ece6fc; --good: #15803d; --warn: #9a5b00; --warn-bg: #fdf3e2; --bad: #b91c1c; --exam: #be123c; color-scheme: light; }
}
:root[data-theme="light"] { --bg: #f6f4fd; --bg2: #e9e4f8; --card: #fff; --line: #d9d2ef; --ink: #1d1638; --muted: #574d78;
            --accent: #5b36d1; --accent-ink: #fff; --field: #faf9fe; --soft: #ece6fc; --good: #15803d; --warn: #9a5b00; --warn-bg: #fdf3e2; --bad: #b91c1c; --exam: #be123c; color-scheme: light; }
:root[data-theme="dark"] {
    --bg: #1b1633; --bg2: #0e0b1d; --card: rgba(255,255,255,.06); --line: rgba(255,255,255,.17);
    --ink: #f4f2fb; --muted: #c4bddf; --accent: #b9a5ff; --accent-ink: #1a0f3d; --field: rgba(255,255,255,.08);
    --soft: rgba(185,165,255,.16); --good: #6ee7a8; --warn: #fbbf72; --warn-bg: rgba(251,191,114,.13); --bad: #fda4af; --exam: #fda4af;
    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 { order: 1; }
.warn-box { order: 1; }
.today { order: 2; }
.exams { order: 4; }
.plan { order: 3; }
.studydays { order: 5; }
.tools { order: 6; }
.app > .faq { order: 7; }
.app > footer { order: 8; }
header { text-align: center; margin-bottom: 1.1rem; }
h1 { margin: 0; font-size: 1.75rem; 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; }
.sub-h { margin: 1rem 0 .4rem; font-size: 1rem; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 1.1rem; margin-bottom: .9rem; min-width: 0; }
label, legend { 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 { width: 100%; min-width: 0; 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; }
textarea { resize: vertical; line-height: 1.45; display: block; }
input[type=date], input[type=time] { -webkit-appearance: none; appearance: none; display: block; }
input[type=date]::-webkit-date-and-time-value, input[type=time]::-webkit-date-and-time-value { text-align: left; }
input[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; }
.check input:focus-visible + span, .check input:focus-visible + .it-text { 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; }
[hidden] { display: none !important; }
.field { min-width: 0; }
.two { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 0 .6rem; }
.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; }

/* 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, .primary.small { width: auto; min-height: 42px; padding: 0 .85rem; font-size: .92rem; margin: 0; }
.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: .2rem; padding: 0 .1rem; border: 0; background: none; color: var(--accent); font: inherit; font-size: .95rem; font-weight: 600; text-align: left; cursor: pointer; }
.link.inline { display: inline; min-height: 0; margin: 0; padding: .55rem .2rem; text-decoration: underline; }
.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 { margin: 0 0 .8rem; padding: .6rem .75rem; border-radius: 12px; background: var(--soft); color: var(--ink); }
.tools .msg.show { margin: .8rem 0 0; }
.row-btns { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: 1rem; }
.row-btns > button { flex: 1 1 8rem; width: auto; }
.check { display: flex; align-items: flex-start; gap: .65rem; margin: 0; color: var(--ink); font-size: 1rem; font-weight: 400; cursor: pointer; min-height: 44px; padding: .55rem 0; }
.check input { width: 22px; height: 22px; margin: .05rem 0 0; flex: none; accent-color: var(--accent); }

/* today */
.today { border: 2px solid var(--accent); background: var(--soft); }
.today h2 { margin-bottom: .1rem; }
.today-date { margin: 0 0 .7rem; color: var(--muted); font-weight: 600; }
.countdown { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 8.5rem), 1fr)); gap: .5rem; }
.cd { border: 1px solid var(--line); border-radius: 14px; padding: .55rem .7rem; background: var(--card); min-width: 0; display: flex; flex-direction: column; }
.cd.soon { border-color: var(--exam); }
.cd.none { color: var(--muted); grid-column: 1 / -1; }
.cd-name { font-weight: 700; font-size: .92rem; overflow-wrap: anywhere; line-height: 1.25; }
.cd-num { font-size: 1.7rem; font-weight: 800; line-height: 1.15; font-variant-numeric: tabular-nums; }
.cd.soon .cd-num { color: var(--exam); }
.cd-sub { font-size: .82rem; color: var(--muted); line-height: 1.3; }
.cd-date { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.empty { margin: .2rem 0 .3rem; color: var(--muted); }
.today-progress { margin: .4rem 0 0; font-weight: 700; }
.today-progress:empty { display: none; }
.today-progress.good { color: var(--good); }

/* items: topics, revision and exams */
.items { list-style: none; margin: 0; padding: 0; display: grid; gap: .1rem; }
.item { min-width: 0; }
.item .check { padding: .45rem 0; }
.it-text { display: flex; flex-wrap: wrap; align-items: baseline; gap: .1rem .5rem; min-width: 0; overflow-wrap: anywhere; }
.it-name { overflow-wrap: anywhere; min-width: 0; }
.item.done .it-name, .topic.done .it-name { text-decoration: line-through; color: var(--muted); }
.tag { font-size: .78rem; font-weight: 700; padding: .05rem .5rem; border-radius: 999px; background: var(--soft); color: var(--accent); border: 1px solid var(--line); white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.item.it-revise, .item.it-exam { display: flex; gap: .65rem; align-items: flex-start; padding: .45rem 0; font-weight: 700; }
.item.it-revise { color: var(--accent); }
.item.it-exam { color: var(--exam); }
.it-icon { width: 22px; flex: none; text-align: center; }

/* plan */
.plan-sum { margin: 0 0 .5rem; font-weight: 600; }
.plan-notes { list-style: none; margin: 0 0 .6rem; padding: 0; display: grid; gap: .4rem; }
.plan-notes li { padding: .5rem .7rem; border-radius: 12px; font-size: .92rem; font-weight: 600; overflow-wrap: anywhere; }
.plan-notes .warn { background: var(--warn-bg); border-left: 5px solid var(--warn); }
.plan-notes .info { background: var(--field); border-left: 5px solid var(--accent); }
.days { list-style: none; margin: 0; padding: 0; display: grid; gap: .5rem; }
.day { border: 1px solid var(--line); border-left: 6px solid var(--accent); border-radius: 14px; padding: .55rem .8rem; background: var(--field); min-width: 0; }
.day.quiet { border-left-color: var(--line); padding: .4rem .8rem; }
.day.quiet .day-what { color: var(--muted); }
.day.has-exam { border-left-color: var(--exam); }
.day-head { display: flex; justify-content: space-between; align-items: baseline; gap: .2rem .6rem; flex-wrap: wrap; }
.day-date { font-weight: 700; }
.day-what { font-size: .88rem; color: var(--muted); font-weight: 600; }
.day .items { margin-top: .15rem; }
#more { margin-top: .8rem; }

/* exams, each in its own box */
.exam-list { list-style: none; margin: 0 0 .8rem; padding: 0; display: grid; gap: .75rem; }
.exam-list:empty { display: none; }
.exam { border: 1px solid var(--line); border-left: 6px solid var(--accent); border-radius: 14px; padding: .75rem .85rem .85rem; background: var(--field); min-width: 0; }
.exam.past { border-left-color: var(--line); opacity: .85; }
.ex-top { display: flex; justify-content: space-between; align-items: baseline; gap: .3rem .6rem; flex-wrap: wrap; }
.ex-name { margin: 0; font-size: 1.12rem; overflow-wrap: anywhere; min-width: 0; }
.badge { font-size: .85rem; font-weight: 700; padding: .1rem .6rem; border-radius: 999px; background: var(--soft); color: var(--accent); white-space: nowrap; }
.badge.soon { background: transparent; border: 1px solid var(--exam); color: var(--exam); }
.ex-when { margin: .15rem 0 0; color: var(--muted); font-size: .92rem; overflow-wrap: anywhere; }
.progress { display: flex; align-items: center; gap: .6rem; margin-top: .55rem; flex-wrap: wrap; }
.pr-text { font-weight: 700; font-size: .92rem; }
.pr-track { flex: 1 1 6rem; height: 10px; border-radius: 5px; background: var(--card); border: 1px solid var(--line); overflow: hidden; min-width: 0; }
.pr-fill { display: block; height: 100%; background: var(--accent); }
.ex-note { margin: .45rem 0 0; font-size: .9rem; color: var(--muted); overflow-wrap: anywhere; }
.ex-note.warn { color: var(--warn); font-weight: 600; }
.topics { list-style: none; margin: .35rem 0 0; padding: 0; border-top: 1px solid var(--line); }
.topic { border-bottom: 1px solid var(--line); min-width: 0; }
.topic .check { padding: .5rem 0; }
.ex-btns { display: flex; flex-wrap: wrap; gap: .45rem; margin-top: .7rem; }
.ex-btns button { flex: 1 1 auto; }
.panel { margin-top: .8rem; padding: .8rem; border: 1px solid var(--line); border-radius: 12px; background: var(--card); min-width: 0; }
.panel h3, .panel h4 { margin: 0 0 .2rem; font-size: 1rem; overflow-wrap: anywhere; }
.exams > .panel { margin-top: 0; }

/* when you can study */
.week { border: 0; margin: 0; padding: 0; min-width: 0; }
.week legend { margin-top: 0; }
.chips { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: .35rem; }
.chip { min-height: 44px; min-width: 0; padding: 0; border: 2px solid var(--line); border-radius: 12px; background: var(--field); color: var(--ink); font: inherit; font-size: .9rem; font-weight: 700; cursor: pointer; }
.chip.on { border-color: var(--warn); background: var(--warn-bg); color: var(--warn); text-decoration: line-through; }
.off-row { display: flex; gap: .5rem; min-width: 0; }
.off-row input { flex: 1 1 auto; }
.off-row button { flex: none; min-height: 48px; }
.offs { list-style: none; margin: .5rem 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: .4rem; }
.off { display: flex; align-items: center; gap: .2rem; padding: 0 0 0 .7rem; border: 1px solid var(--line); border-radius: 999px; background: var(--field); font-size: .9rem; font-weight: 600; }
.x { width: 40px; min-height: 40px; border: 0; background: none; color: var(--muted); font-size: 1.3rem; cursor: pointer; border-radius: 999px; }

/* tools */
.tool-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: .5rem; }

/* 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; }

/* narrow phones */
@media (max-width: 420px) {
    .tool-grid { grid-template-columns: minmax(0, 1fr); }
    .card { padding: 1rem .85rem; }
    .chip { font-size: .8rem; }
}
@media (max-width: 374px) {
    .two { grid-template-columns: minmax(0, 1fr); }
    .off-row { flex-direction: column; }
    .off-row button { width: 100%; }
}
@media (max-width: 360px) {
    .topbar .theme-toggle { padding: 0; width: 44px; justify-content: center; }
    .topbar .theme-toggle span { display: none; }
    .chip { font-size: .72rem; border-radius: 10px; }
    .chips { gap: .25rem; }
}

/* printing: the countdown, today, the plan and the exams */
@media print {
    body { background: #fff; color: #000; padding: 0; display: block; font-size: 11pt; }
    .app { display: block; width: 100%; }
    .app > header, .col-side, .col-main { display: block !important; }
    .warn-box, .studydays, .tools, .faq, footer, .ex-btns, .exams .panel, #add-open, #more, .msg, .link, .plan-notes .info { display: none !important; }
    .card, .day, .exam, .cd { background: #fff !important; border-color: #999 !important; break-inside: avoid-page; }
    .day, .exam { break-inside: avoid; }
    .pr-fill { background: #555 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    * { color: #000 !important; }
}

/* laptops and desktops: exams and settings on the left, today and the plan on the right */
@media (min-width: 900px) {
    .app { width: min(1140px, 100%); display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.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; }
    .cd-num { font-size: 2rem; }
}
