:root {
    --bg: #121a3d; --bg2: #0a0f26; --card: rgba(255,255,255,.06); --line: rgba(255,255,255,.17);
    --ink: #f2f5ff; --muted: #bcc6ee; --accent: #91a7ff; --accent-ink: #0f1846; --field: rgba(255,255,255,.08);
    --soft: rgba(145,167,255,.15); --good: #4ade80; --good-bg: rgba(74,222,128,.13); --bad: #ff8a8a; --bad-bg: rgba(255,107,107,.14);
    --warn: #fcc419; --plan: #fcc419; --plan-bg: rgba(252,196,25,.08);
    color-scheme: dark;
}
@media (prefers-color-scheme: light) {
    :root { --bg: #f5f7ff; --bg2: #e6ebfd; --card: #fff; --line: #d3dbf7; --ink: #121a42; --muted: #4f5a85;
            --accent: #3b5bdb; --accent-ink: #fff; --field: #f8f9ff; --soft: #e9eeff; --good: #2b8a3e; --good-bg: #ebfbee; --bad: #c92a2a; --bad-bg: #fff0f0;
            --warn: #b07800; --plan: #e8a400; --plan-bg: #fffbea; color-scheme: light; }
}
:root[data-theme="light"] { --bg: #f5f7ff; --bg2: #e6ebfd; --card: #fff; --line: #d3dbf7; --ink: #121a42; --muted: #4f5a85;
            --accent: #3b5bdb; --accent-ink: #fff; --field: #f8f9ff; --soft: #e9eeff; --good: #2b8a3e; --good-bg: #ebfbee; --bad: #c92a2a; --bad-bg: #fff0f0;
            --warn: #b07800; --plan: #e8a400; --plan-bg: #fffbea; color-scheme: light; }
:root[data-theme="dark"] {
    --bg: #121a3d; --bg2: #0a0f26; --card: rgba(255,255,255,.06); --line: rgba(255,255,255,.17);
    --ink: #f2f5ff; --muted: #bcc6ee; --accent: #91a7ff; --accent-ink: #0f1846; --field: rgba(255,255,255,.08);
    --soft: rgba(145,167,255,.15); --good: #4ade80; --good-bg: rgba(74,222,128,.13); --bad: #ff8a8a; --bad-bg: rgba(255,107,107,.14);
    --warn: #fcc419; --plan: #fcc419; --plan-bg: rgba(252,196,25,.08);
    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-side, .col-main { display: contents; }
.app > .topbar, .app > .back { order: 0; }
.app > header { order: 1; }
.scale { order: 2; }
.base { order: 3; }
.sems { order: 4; }
.results { order: 5; }
.goal { order: 6; }
.share { order: 7; }
.app > .faq { order: 8; }
.app > footer { order: 9; }
.report { display: none; }
header { text-align: center; margin-bottom: 1.1rem; }
h1 { margin: 0; font-size: 1.8rem; 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; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 1.1rem; margin-bottom: .9rem; min-width: 0; }
label { display: block; margin: .9rem 0 .35rem; font-size: .9rem; font-weight: 600; color: var(--muted); }
.card > h2 + label, .card > h2 + .two .field > label { margin-top: 0; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; margin: 0; }
input[type=text], select { 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; }
select { padding-right: .5rem; text-overflow: ellipsis; }
input[aria-invalid="true"], select[aria-invalid="true"] { border-color: var(--bad); box-shadow: 0 0 0 1px var(--bad); }
select option, select optgroup { color: #111; background: #fff; }
input:focus-visible, button:focus-visible, select: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; }
[hidden] { display: none !important; }
.two { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: .7rem; }
.field { min-width: 0; }
.goal .two, .base .two { align-items: end; }

/* buttons */
.primary, .secondary { 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; }
.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; }
.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; }
.link.inline { display: inline; min-height: 0; margin: 0; padding: .45rem .2rem; text-decoration: underline; font-size: inherit; }
.danger-link { color: var(--bad); }
.x { flex: none; width: 44px; height: 44px; border: 1px solid var(--line); border-radius: 10px; background: transparent; color: var(--muted); font: inherit; font-size: 1.4rem; line-height: 1; cursor: pointer; }
.x:hover { color: var(--bad); border-color: var(--bad); }

.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-top: .8rem; padding: .6rem .75rem; border-radius: 12px; background: var(--soft); color: var(--ink); }
.msg p { margin: 0; }
.msg .msg-extra { margin-top: .35rem; color: var(--muted); }
.msg.bad { background: var(--bad-bg); }
.msg.bad p:first-child { color: var(--bad); font-weight: 700; }
.msg .undo { margin-left: .2rem; font-weight: 700; }

/* grading scale */
#scale-list { font-variant-numeric: tabular-nums; }
.more { margin-top: .8rem; border: 1px solid var(--line); border-radius: 12px; background: var(--field); }
.more summary { cursor: pointer; padding: .7rem .85rem; min-height: 44px; font-weight: 600; color: var(--accent); }
.more[open] { padding: 0 .85rem .85rem; }
.more[open] summary { margin: 0 -.85rem; }
.more label:first-of-type { margin-top: .2rem; }
.more select { font-size: 1rem; padding-left: .65rem; }
.custom-rows { display: grid; gap: .45rem; }
.cg { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 44px; gap: .45rem; align-items: center; }

/* semesters: each in its own box, each course in its own box inside */
.sec-h { margin: .3rem 0 .4rem; font-size: 1.3rem; }
.sems > .hint.top { margin-bottom: .8rem; }
#sems { display: grid; gap: 1rem; }
.sem { border: 2px solid var(--line); border-top: 6px solid var(--accent); border-radius: 16px; padding: .9rem; background: var(--card); min-width: 0; }
.sem.plan { border-top-color: var(--plan); border-style: dashed; border-top-style: solid; background: var(--plan-bg); }
.sem-h { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: .7rem; }
.sem-h label { margin-top: 0; }
.sem-h input { font-weight: 700; }
.courses { display: grid; gap: .55rem; margin-top: .9rem; }
.course { border: 1px solid var(--line); border-radius: 12px; padding: .55rem .6rem .6rem; background: var(--field); min-width: 0; }
.course.replaced { opacity: .7; }
.c-top { display: flex; gap: .45rem; align-items: center; }
.c-top input { flex: 1 1 auto; min-height: 44px; font-size: 1rem; background: var(--card); }
.c-bot { display: grid; grid-template-columns: minmax(0, 6.5rem) minmax(0, 1fr); gap: .5rem; margin-top: .1rem; }
.c-bot label { margin: .45rem 0 .2rem; font-size: .82rem; }
.c-bot input, .c-bot select { min-height: 44px; font-size: 1rem; background: var(--card); }
.c-bot .cr input { font-weight: 700; font-variant-numeric: tabular-nums; }
.c-note { margin: .4rem 0 0; font-size: .85rem; color: var(--muted); overflow-wrap: anywhere; }
.c-note.bad { color: var(--bad); font-weight: 700; }
.sem-sum { margin-top: .8rem; padding: .65rem .8rem; border-radius: 12px; background: var(--soft); }
.sem.plan .sem-sum { background: var(--plan-bg); border: 1px solid var(--plan); }
.sem-sum p { margin: 0; overflow-wrap: anywhere; }
.sem-gpa .v { font-size: 1.5rem; font-variant-numeric: tabular-nums; }
.sem-gpa .k, .sem-cg .k { color: var(--muted); font-weight: 600; }
.sem-cg { margin-top: .15rem !important; }
.sem-none { color: var(--muted); }
.sem-warn { margin-top: .35rem !important; color: var(--warn); font-weight: 600; font-size: .9rem; }
.sem-f { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 0 1rem; margin-top: .3rem; }
.sem-add { margin-top: 1rem; }
.sems { margin-bottom: .9rem; }

/* results */
.empty .big { margin: 0; font-size: 1.3rem; font-weight: 700; }
.muted { color: var(--muted); }
.meta { margin: .3rem 0 0; color: var(--muted); font-size: .92rem; }
.cgpa { margin: 0; display: flex; align-items: baseline; flex-wrap: wrap; gap: .1rem .5rem; }
.cgpa-n { font-size: 3rem; font-weight: 800; line-height: 1.05; color: var(--accent); font-variant-numeric: tabular-nums; }
.cgpa-of { font-weight: 700; color: var(--muted); }
.cgpa-line { margin: .3rem 0 0; color: var(--muted); font-size: .92rem; }
.plan-line { margin: .55rem 0 0; padding: .45rem .65rem; border-left: 4px solid var(--plan); background: var(--plan-bg); border-radius: 8px; font-weight: 600; overflow-wrap: anywhere; }
.tbl-wrap { margin-top: .8rem; overflow-x: auto; }
.sem-tbl { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; font-size: .95rem; }
.sem-tbl th, .sem-tbl td { padding: .45rem .4rem; border-bottom: 1px solid var(--line); text-align: right; }
.sem-tbl th:first-child { text-align: left; overflow-wrap: anywhere; }
.sem-tbl thead th { font-size: .78rem; color: var(--muted); font-weight: 700; }
.sem-tbl tbody th { font-weight: 600; }
.sem-tbl td:nth-child(3) { font-weight: 800; }
.sem-tbl tr.plan th, .sem-tbl tr.plan td { color: var(--warn); font-style: italic; }
.sem-tbl tr.base-row th, .sem-tbl tr.base-row td { color: var(--muted); }

/* target answer */
.answer { margin-top: .9rem; padding: .8rem .9rem; border-radius: 12px; background: var(--soft); }
.answer p { margin: 0; overflow-wrap: anywhere; }
.answer .a-line + .a-line { margin-top: .35rem; }
.answer .a-big { font-size: 1.45rem; font-weight: 800; line-height: 1.2; margin-bottom: .3rem; }
.answer.need .a-big { color: var(--accent); }
.answer.good { background: var(--good-bg); }
.answer.good .a-big { color: var(--good); }
.answer.bad { background: var(--bad-bg); }
.answer.bad .a-big { color: var(--bad); }
.answer.muted { color: var(--muted); }
.answer.plan { background: var(--plan-bg); border: 1px solid var(--plan); }
.answer .a-h { font-weight: 700; margin-bottom: .2rem; }

/* share */
.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: 400px) {
    .card { padding: 1rem .85rem; }
    .sem { padding: .75rem .6rem; }
    .sem-h { grid-template-columns: minmax(0, 1fr); gap: 0; }
    .sem-h .field + .field label { margin-top: .6rem; }
    .goal .two, .base .two { grid-template-columns: minmax(0, 1fr); gap: 0; }
    .goal .two .field + .field label, .base .two .field + .field label { margin-top: .9rem; }
    .tool-grid { grid-template-columns: minmax(0, 1fr); }
    .c-bot { grid-template-columns: minmax(0, 5.6rem) minmax(0, 1fr); }
    .cgpa-n { font-size: 2.6rem; }
}
@media (max-width: 360px) {
    .topbar .theme-toggle { padding: 0; width: 44px; justify-content: center; }
    .topbar .theme-toggle span { display: none; }
    .sem-tbl { font-size: .86rem; }
    .sem-tbl th, .sem-tbl td { padding: .4rem .25rem; }
    .more[open] { padding: 0 .55rem .7rem; }
    .more[open] summary { margin: 0 -.55rem; }
}

/* printing: only the report */
@media print {
    body { background: #fff; color: #000; padding: 0; display: block; font-size: 11pt; }
    .app > *:not(.report) { display: none !important; }
    .app { display: block; width: 100%; }
    .report { display: block !important; }
    .report h2 { font-size: 16pt; margin: 0 0 .3rem; }
    .report h3 { font-size: 12pt; margin: .9rem 0 0; }
    .report p { margin: .1rem 0; }
    .report .r-big { font-size: 13pt; font-weight: 700; }
    .report table { width: 100%; border-collapse: collapse; margin-top: .4rem; font-size: 9.5pt; }
    .report th, .report td { border: 1px solid #999; padding: 2px 5px; text-align: left; }
    .report thead { display: table-header-group; }
    .report tr { break-inside: avoid; }
    .report .r-foot { margin-top: .6rem; font-size: 9pt; color: #333; }
}

/* laptops and desktops: scale and semesters on the left, CGPA, target and sharing on the right */
@media (min-width: 900px) {
    .app { width: min(1140px, 100%); display: grid; grid-template-columns: minmax(0, 1.25fr) 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; width: min(760px, 100%); justify-self: center; }
    .app > .col-main { grid-column: 1; grid-row: 3; }
    .app > .col-side { grid-column: 2; grid-row: 3; }
    .app > .faq { grid-row: 4; width: min(760px, 100%); justify-self: center; }
    .app > footer { grid-row: 5; width: min(760px, 100%); justify-self: center; }
    .app > .report { grid-row: 6; }
    header h1 { font-size: 2.3rem; }
}

/* wide laptops: each course on one line (name, credit hours, grade, delete) */
@media (min-width: 1100px) {
    .course { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 5.5rem) minmax(0, 9.5rem) 44px; gap: .5rem; align-items: end; }
    .c-top, .c-bot { display: contents; }
    .c-top input { grid-column: 1; grid-row: 1; }
    .c-top .x { grid-column: 4; grid-row: 1; }
    .c-bot .cr { grid-column: 2; grid-row: 1; }
    .c-bot .gr { grid-column: 3; grid-row: 1; }
    .c-bot label { margin-top: 0; }
    .c-note { grid-column: 1 / -1; grid-row: 2; margin-top: 0; }
}
