:root {
  --paper: #f6f1e7; --card: #fffdf8; --ink: #12343b; --ink2: #3d5a60; --muted: #6b7f83;
  --line: #e4dccb; --accent: #e8a136; --accent-ink: #5a3a00; --teal: #1d6b73; --good: #1f7a4d; --bad: #b8432f;
  --shadow: 0 1px 0 rgba(18,52,59,.04), 0 8px 24px -14px rgba(18,52,59,.35);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Noto Naskh Arabic", "Segoe UI", serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans Arabic", Tahoma, sans-serif;
  color-scheme: light;
}
[data-theme="dark"] {
  --paper: #0d1a1d; --card: #14262a; --ink: #eae4d6; --ink2: #b7c4c3; --muted: #8aa0a2;
  --line: #254047; --accent: #f0b04a; --accent-ink: #2b1a00; --teal: #5cc0c8; --good: #55c58e; --bad: #f0836f;
  --shadow: 0 8px 24px -14px rgba(0,0,0,.7);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; font-family: var(--sans); background: var(--paper); color: var(--ink); line-height: 1.45;
  background-image: repeating-linear-gradient(to bottom, transparent 0, transparent 31px, rgba(18,52,59,.045) 31px, rgba(18,52,59,.045) 32px);
  padding-bottom: 40px;
}
.skip { position: absolute; inset-inline-start: 8px; top: 0; transform: translateY(-300%); background: var(--ink); color: var(--paper); padding: 8px 12px; z-index: 50; }
.skip:focus { transform: none; top: 8px; }
.top, main, .foot { max-width: 760px; margin-inline: auto; padding-inline: 16px; }
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-top: calc(14px + env(safe-area-inset-top)); padding-bottom: 8px; }
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand img { border-radius: 12px; flex: none; }
h1 { margin: 0; font-family: var(--serif); font-size: 1.55rem; letter-spacing: .01em; line-height: 1.1; }
.sub { margin: 2px 0 0; font-size: .8rem; color: var(--muted); }
.tools { display: flex; gap: 6px; flex: none; }
.pill { border: 1px solid var(--line); background: var(--card); color: var(--ink); border-radius: 999px; padding: 7px 13px; font: inherit; font-size: .85rem; cursor: pointer; min-height: 38px; }
button, select, input { font: inherit; color: inherit; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid var(--accent); outline-offset: 1px; }

.hero { display: flex; align-items: center; gap: 18px; background: var(--ink); color: #f6f1e7; border-radius: 24px; padding: 18px; margin: 10px 0 14px; box-shadow: var(--shadow); position: relative; overflow: hidden; }
[data-theme="dark"] .hero { background: #1b3a40; }
.hero::after { content: ""; position: absolute; inset-inline-end: -40px; top: -40px; width: 140px; height: 140px; border-radius: 50%; border: 18px solid rgba(240,168,58,.12); }
.gauge { position: relative; width: 132px; height: 132px; flex: none; }
.gauge svg { width: 100%; height: 100%; }
.g-track { fill: none; stroke: rgba(246,241,231,.16); stroke-width: 10; }
.g-bar { fill: none; stroke: var(--accent); stroke-width: 10; stroke-linecap: round; transition: stroke-dashoffset .6s cubic-bezier(.2,.8,.2,1); }
.g-center { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.g-value { font-family: var(--serif); font-size: 2.1rem; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; direction: ltr; }
.g-max { font-size: .72rem; opacity: .7; margin-top: 4px; }
.hero-side { min-width: 0; flex: 1; position: relative; z-index: 1; }
.hero-label { font-size: .78rem; text-transform: uppercase; letter-spacing: .08em; opacity: .75; }
[dir="rtl"] .hero-label { letter-spacing: 0; text-transform: none; font-size: .85rem; }
.honors { margin: 6px 0 10px; min-height: 28px; }
.badge-honor { display: inline-block; background: var(--accent); color: #2b1a00; font-weight: 700; border-radius: 999px; padding: 4px 12px; font-size: .9rem; }
.badge-honor.h-below { background: #d9735f; color: #fff; }
.hero .muted { color: rgba(246,241,231,.75); font-size: .9rem; }
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; margin: 0; }
.stats div { background: rgba(246,241,231,.08); border-radius: 12px; padding: 8px 7px; min-width: 0; }
.stats dt { font-size: .66rem; opacity: .75; line-height: 1.2; min-height: 2.4em; }
.stats dd { margin: 2px 0 0; font-family: var(--serif); font-size: 1.25rem; font-weight: 700; font-variant-numeric: tabular-nums; }

.tabs { display: flex; gap: 4px; background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 4px; margin-bottom: 14px; position: sticky; top: 6px; z-index: 10; box-shadow: var(--shadow); }
.tab { flex: 1; border: 0; background: transparent; padding: 10px 6px; border-radius: 12px; cursor: pointer; font-size: .88rem; color: var(--ink2); min-height: 44px; }
.tab.on { background: var(--ink); color: var(--paper); font-weight: 600; }
[data-theme="dark"] .tab.on { background: var(--accent); color: #2b1a00; }

.panel { display: grid; gap: 14px; }
.panel[hidden] { display: none; }
.card, .sem, .chart-card, .empty { background: var(--card); border: 1px solid var(--line); border-radius: 20px; padding: 16px; box-shadow: var(--shadow); }
.h2 { font-family: var(--serif); font-size: 1.15rem; margin: 0 0 8px; }
.h3 { font-family: var(--serif); font-size: 1rem; margin: 16px 0 8px; }
.muted { color: var(--muted); }
.note { background: rgba(232,161,54,.14); border-inline-start: 4px solid var(--accent); padding: 8px 12px; border-radius: 8px; font-size: .88rem; margin: 0 0 12px; }

.empty { text-align: center; padding: 28px 18px; }
.empty h2 { font-family: var(--serif); margin: 10px 0 4px; }
.empty p { color: var(--muted); margin: 0 0 16px; }
.empty img { border-radius: 16px; }

.btn { border: 1px solid var(--line); background: var(--card); color: var(--ink); border-radius: 12px; padding: 10px 16px; cursor: pointer; min-height: 44px; font-weight: 600; font-size: .92rem; }
.btn.primary { background: var(--ink); color: var(--paper); border-color: var(--ink); }
[data-theme="dark"] .btn.primary { background: var(--accent); color: #2b1a00; border-color: var(--accent); }
.btn.ghost:hover { background: rgba(29,107,115,.1); }
.btn.danger { color: var(--bad); border-color: var(--bad); }
.btn.wide { width: 100%; }
.row { display: flex; gap: 8px; justify-content: center; margin-top: 12px; }
.row.wrap { flex-wrap: wrap; justify-content: flex-start; }
.icon { border: 0; background: transparent; width: 40px; height: 40px; border-radius: 50%; font-size: 1.5rem; line-height: 1; cursor: pointer; color: var(--muted); flex: none; }
.icon:hover { background: rgba(184,67,47,.12); color: var(--bad); }

.chart-svg { width: 100%; max-width: 520px; margin-inline: auto; height: auto; display: block; direction: ltr; }
.chart-svg .grid { stroke: var(--line); stroke-width: 1; }
.chart-svg .axis { fill: var(--muted); font-size: 9px; }
.chart-svg .bar { fill: var(--teal); opacity: .85; }
.chart-svg .val { fill: #fff; font-size: 9px; font-weight: 700; }
.chart-svg .line { fill: none; stroke: var(--accent); stroke-width: 2.5; stroke-linejoin: round; }
.chart-svg .dot { fill: var(--accent); stroke: var(--card); stroke-width: 1.5; }
.legend { display: flex; gap: 14px; font-size: .78rem; color: var(--muted); margin-top: 4px; }
.lg::before { content: ""; display: inline-block; width: 12px; height: 8px; border-radius: 2px; margin-inline-end: 6px; }
.bar-lg::before { background: var(--teal); }
.line-lg::before { background: var(--accent); height: 3px; vertical-align: middle; }

.sem-head { display: flex; align-items: center; gap: 4px; }
input.s-name { flex: 1; min-width: 0; font-family: var(--serif); font-size: 1.1rem; font-weight: 700; background: transparent; border: 0; border-bottom: 2px dashed var(--line); padding: 6px 2px; }
input.s-name:focus { border-bottom-color: var(--accent); outline: none; }
.sem-chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 12px; }
.chip { background: rgba(29,107,115,.12); color: var(--teal); border-radius: 999px; padding: 4px 11px; font-size: .8rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.chip.gpa { background: var(--accent); color: #2b1a00; }
.chip.soft { background: transparent; border: 1px solid var(--line); color: var(--muted); font-weight: 500; }
.courses { display: grid; gap: 10px; margin-bottom: 12px; }
.course { border: 1px solid var(--line); border-radius: 14px; padding: 10px; background: rgba(246,241,231,.4); }
[data-theme="dark"] .course { background: rgba(0,0,0,.18); }
.course.superseded { opacity: .55; }
.course.superseded .c-name { text-decoration: line-through; }
.c-top { display: flex; align-items: center; gap: 4px; }
input.c-name { flex: 1; min-width: 0; border: 0; border-bottom: 1px solid var(--line); background: transparent; padding: 8px 2px; font-weight: 600; }
input.c-name:focus { outline: none; border-bottom-color: var(--accent); }
.c-mid { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px; margin-top: 8px; }
.f { display: grid; gap: 4px; font-size: .78rem; color: var(--ink2); }
.f > span { font-weight: 600; }
.c-mid .f { flex: 1 1 96px; }
input[type=text], input[type=number], select {
  width: 100%; min-height: 42px; padding: 8px 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); color: var(--ink);
}
input[type=range] { width: 100%; accent-color: var(--accent); min-height: 36px; }
.chk { display: flex; align-items: center; gap: 6px; font-size: .82rem; min-height: 42px; cursor: pointer; }
.chk input { width: 20px; height: 20px; accent-color: var(--teal); }
.cbadge { min-width: 62px; text-align: center; border-radius: 10px; padding: 8px 8px; font-size: .85rem; font-weight: 700; font-variant-numeric: tabular-nums; margin-inline-start: auto; direction: ltr; }
.cbadge.ok { background: rgba(31,122,77,.14); color: var(--good); }
.cbadge.bad { background: rgba(184,67,47,.14); color: var(--bad); }
.cbadge.mute { background: rgba(107,127,131,.14); color: var(--muted); }
.cnote { font-size: .76rem; color: var(--muted); margin-top: 6px; }

.grid2 { display: grid; grid-template-columns: 1fr; gap: 12px; }
.result { margin-top: 14px; padding: 12px 14px; background: rgba(29,107,115,.08); border-radius: 14px; }
.result p { margin: 0; }
.big { font-family: var(--serif); font-size: 1.7rem; margin-inline: 2px; }
.ok-text { color: var(--good); font-weight: 600; }
.bad-text { color: var(--bad); font-weight: 600; }
.delta { font-size: .85rem; font-weight: 700; }
.delta.up { color: var(--good); } .delta.down { color: var(--bad); }

.shead, .srow { display: grid; grid-template-columns: 1fr 1fr 1fr 40px; gap: 8px; align-items: center; }
.shead { font-size: .75rem; font-weight: 700; color: var(--ink2); margin: 14px 0 6px; }
.srows { display: grid; gap: 6px; }
.srow input { min-height: 40px; direction: ltr; text-align: center; }
.errors { margin-top: 10px; background: rgba(184,67,47,.1); border: 1px solid var(--bad); border-radius: 12px; padding: 10px 14px; font-size: .86rem; color: var(--bad); }
.errors ul { margin: 6px 0 0; padding-inline-start: 18px; }

.foot { color: var(--muted); font-size: .78rem; text-align: center; margin-top: 24px; }
.toast { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translate(-50%, 30px); background: var(--ink); color: var(--paper); padding: 10px 18px; border-radius: 999px; opacity: 0; pointer-events: none; transition: .25s; z-index: 60; font-size: .9rem; max-width: 90vw; }
[data-theme="dark"] .toast { background: var(--accent); color: #2b1a00; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.modal { position: fixed; inset: 0; background: rgba(8,20,22,.55); display: grid; place-items: center; z-index: 70; padding: 20px; }
.modal[hidden] { display: none; }
.modal-card { background: var(--card); border-radius: 20px; padding: 20px; max-width: 360px; width: 100%; box-shadow: var(--shadow); }
.modal-card p { margin: 0 0 16px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; }

@media (min-width: 640px) {
  .grid2 { grid-template-columns: 1fr 1fr; }
  .gauge { width: 160px; height: 160px; }
  .g-value { font-size: 2.5rem; }
  .hero { padding: 24px; gap: 28px; }
  .stats dt { font-size: .72rem; }
  .c-mid .f { flex: 0 1 140px; }
  .c-mid .f:nth-of-type(1) { flex-basis: 110px; }
}
@media (max-width: 380px) {
  .hero { flex-direction: column; text-align: center; }
  .stats { width: 100%; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
@media print {
  body { background: #fff; color: #000; }
  .tabs, .tools, #btn-add-sem, .add-course, .icon, .toast, .foot, #panel-planner, #panel-scale, .chk, .skip { display: none !important; }
  #panel-semesters { display: grid !important; }
  .hero { background: #fff; color: #000; border: 1px solid #000; box-shadow: none; }
  .card, .sem, .chart-card { box-shadow: none; break-inside: avoid; }
  .g-bar { stroke: #000; }
}

.quick-row { display: grid; grid-template-columns: 140px 1fr; gap: 14px; align-items: end; }
.quick-out { font-family: var(--serif); font-size: 1.4rem; font-weight: 700; min-height: 42px; display: flex; align-items: center; direction: ltr; justify-content: flex-start; }
[dir="rtl"] .quick-out { justify-content: flex-end; }
