/* MyGrades — the look of Chrono (colours, type, panels), made for a phone first. */

/* Atkinson Hyperlegible Next (Braille Institute, SIL Open Font License: fonts/OFL-atkinson-hyperlegible-next.txt) */
@font-face {
  font-family: "Atkinson Hyperlegible Next";
  font-display: swap;
  src: url("fonts/atkinson-hyperlegible-next-wght.ttf") format("truetype");
  font-weight: 200 800;
}

:root {
  color-scheme: light;
  --bg: #e8ecf0; --panel: #fafbfc; --sunk: #eef1f4;
  --ink: #13223a; --ink-2: #4b576a; --ink-3: #7f8a9b; --rule: #d2d9e2;
  --good: #00785a; --warn: #8f5f00; --bad: #c24400; --accent: #0072b2; --track: #dde3ea;
  --gA: #0072b2; --gB: #cc79a7; --gC: #e69f00;
  --radius-lg: 18px; --radius-sm: 8px;
  --shadow: 0 1px 0 rgba(19, 34, 58, .04), 0 8px 24px -16px rgba(19, 34, 58, .18);
  --kb: 0px;   /* height of the phone keyboard, set by app.js */
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0f151d; --panel: #171f2a; --sunk: #121922;
    --ink: #e7ecf2; --ink-2: #aab4c3; --ink-3: #758094; --rule: #2a3443;
    --good: #3cc79f; --warn: #f0b545; --bad: #ff8a4c; --accent: #4aa3df; --track: #232d3a;
    --gA: #4aa3df; --gB: #e09ac4; --gC: #f0b030;
    --shadow: 0 1px 0 rgba(0, 0, 0, .3);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f151d; --panel: #171f2a; --sunk: #121922;
  --ink: #e7ecf2; --ink-2: #aab4c3; --ink-3: #758094; --rule: #2a3443;
  --good: #3cc79f; --warn: #f0b545; --bad: #ff8a4c; --accent: #4aa3df; --track: #232d3a;
  --gA: #4aa3df; --gB: #e09ac4; --gC: #f0b030;
  --shadow: 0 1px 0 rgba(0, 0, 0, .3);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font: 400 15px/1.5 "Atkinson Hyperlegible Next", system-ui, sans-serif;
  font-feature-settings: "tnum" 1; -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
[hidden] { display: none !important; }

.wrap {
  max-width: 1000px; margin: 0 auto;
  padding: env(safe-area-inset-top) max(14px, env(safe-area-inset-right)) calc(120px + var(--kb)) max(14px, env(safe-area-inset-left));
}

/* ---------- top bar */
.top { display: flex; align-items: center; gap: 10px 12px; padding: 14px 0 12px; flex-wrap: wrap; }
.brand { font-weight: 750; font-size: 19px; letter-spacing: -.02em; display: flex; align-items: center; gap: 9px; }
.brand svg { width: 24px; height: 24px; color: var(--ink); }
.sem-select {
  appearance: none; border: 1px solid var(--rule); background: var(--panel); min-width: 0;
  padding: 6px 30px 6px 12px; border-radius: 999px; font-weight: 600; cursor: pointer; margin-left: auto;
  background-image: linear-gradient(45deg, transparent 50%, var(--ink-2) 50%), linear-gradient(135deg, var(--ink-2) 50%, transparent 50%);
  background-position: calc(100% - 15px) 52%, calc(100% - 10px) 52%;
  background-size: 5px 5px; background-repeat: no-repeat;
}
.tabs { flex: 1 1 100%; display: flex; gap: 2px; background: var(--sunk); border: 1px solid var(--rule); border-radius: 999px; padding: 3px; }
.tabs button {
  flex: 1 1 0; border: 0; background: transparent; padding: 7px 10px; border-radius: 999px; cursor: pointer;
  color: var(--ink-2); font-weight: 600; white-space: nowrap;
}
.tabs button[aria-selected="true"] { background: var(--panel); color: var(--ink); box-shadow: var(--shadow); }
@media (min-width: 720px) {
  .tabs { flex: 0 1 auto; order: 2; margin-left: 0; }
  .sem-select { order: 3; }
  .top .icon-btn { order: 4; }
  .tabs button { padding: 6px 18px; }
}
.icon-btn { border: 0; background: transparent; cursor: pointer; padding: 7px; color: var(--ink-2); border-radius: 10px; display: inline-flex; }
.icon-btn:hover { color: var(--ink); background: var(--sunk); }
.icon-btn svg { width: 20px; height: 20px; }

/* ---------- panels */
.panel { background: var(--panel); border: 1px solid var(--rule); border-radius: var(--radius-lg); box-shadow: var(--shadow); }
.panel + .panel { margin-top: 14px; }
.panel-head { display: flex; align-items: baseline; gap: 10px; padding: 14px 16px 0; flex-wrap: wrap; }
.panel-head h2 { font-size: 16px; font-weight: 700; margin: 0; letter-spacing: -.01em; }
.panel-head .sub { color: var(--ink-3); font-size: 13px; }
.panel-body { padding: 10px 16px 16px; }

/* ---------- the grade table */
.tablewrap {
  overflow-x: auto; overscroll-behavior-x: contain; -webkit-overflow-scrolling: touch;
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}
table.grid { border-collapse: separate; border-spacing: 0; width: 100%; }
.grid th, .grid td { padding: 0; border-top: 1px solid var(--rule); background: var(--panel); }
.grid thead th {
  border-top: 0; font-size: 12px; font-weight: 600; color: var(--ink-3); text-align: center;
  padding: 8px 4px 6px; white-space: nowrap;
}
.grid thead th.subj-h { text-align: left; padding-left: 16px; }
/* the subject on the left and the mean on the right stay put while the grades scroll */
.grid .subj {
  position: sticky; left: 0; z-index: 2; text-align: left;
  min-width: 104px; max-width: 124px; width: 1%; box-shadow: 1px 0 0 var(--rule);
}
.grid .mean {
  position: sticky; right: 0; z-index: 2; width: 58px; min-width: 58px; text-align: center;
  box-shadow: -1px 0 0 var(--rule); font-weight: 700; font-size: 16px;
}
.grid thead .mean { font-size: 12px; font-weight: 600; }
.grid td.fill { width: 100%; }
.subj-btn {
  display: block; width: 100%; border: 0; background: none; text-align: left; cursor: pointer;
  padding: 10px 6px 10px 14px; font-weight: 600; line-height: 1.2; font-size: 14.5px;
}
.subj-btn .nm { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.subj-btn .meta { display: block; font-size: 11px; font-weight: 500; color: var(--ink-3); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.subj-btn .os { color: var(--accent); font-weight: 700; }

.cell { position: relative; width: 48px; min-width: 48px; }
.gbtn {
  display: block; width: 100%; height: 50px; border: 0; background: transparent; cursor: pointer;
  font-size: 16px; font-weight: 550; padding: 8px 2px 0; font-variant-numeric: tabular-nums; color: var(--ink);
}
/* only the next free cell of a row is grey: that is where the next grade goes */
.cell.next .gbtn { background: var(--sunk); }
.cell.next .gbtn::after { content: "+"; color: var(--ink-3); font-weight: 500; }
.cell.picking .gbtn { background: color-mix(in srgb, var(--accent) 14%, transparent); box-shadow: inset 0 0 0 2px var(--accent); }
.cell.low .gbtn { color: var(--bad); }
.cell.w2 .gbtn { font-weight: 800; }
.cell .tag {
  position: absolute; top: 3px; left: 0; right: 0; text-align: center; pointer-events: none;
  font-size: 9.5px; font-weight: 700; letter-spacing: .02em; color: var(--ink-3); line-height: 1;
}
.cell.pct .tag { color: var(--warn); }
.cell.grp::after {
  content: ""; position: absolute; left: 6px; right: 6px; bottom: 4px; height: 3px; border-radius: 2px;
  background: var(--g, var(--ink-3)); pointer-events: none;
}
.cell.gA { --g: var(--gA); } .cell.gB { --g: var(--gB); } .cell.gC { --g: var(--gC); }
.cell.grp .tag { color: var(--g); }

.mean .val { display: block; line-height: 1.1; }
.mean .prov { display: block; font-size: 10px; font-weight: 600; color: var(--ink-3); }
.mean.low { color: var(--bad); }
.mean.none { color: var(--ink-3); font-weight: 400; }

tr.newrow .subj input {
  width: 100%; border: 0; background: var(--sunk); padding: 12px 8px 12px 16px; font-weight: 600; font-size: 14.5px;
}
tr.newrow .subj input::placeholder { color: var(--ink-3); font-weight: 500; }
tr.newrow .subj input:focus { outline: none; box-shadow: inset 0 0 0 2px var(--accent); }
tr.newrow td { background: var(--panel); }

.hidden-subjects { padding: 10px 16px 14px; font-size: 13px; color: var(--ink-3); border-top: 1px solid var(--rule); }
.linkbtn { border: 0; background: none; padding: 0; color: var(--ink-2); font: inherit; font-weight: 600; cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }

/* the year table: plain numbers */
.grid.year td.num { text-align: center; padding: 12px 6px; font-weight: 550; min-width: 52px; }
.grid.year td.num.low { color: var(--bad); }
.grid.year td.num.none { color: var(--ink-3); font-weight: 400; }
.grid.year tfoot td, .grid.year tfoot th { font-weight: 700; border-top: 2px solid var(--rule); }
.grid.year tfoot .subj { padding: 12px 8px 12px 16px; font-size: 14px; }

/* ---------- the summary */
.verdict { display: flex; align-items: center; gap: 10px; padding: 14px 16px 4px; flex-wrap: wrap; }
.pill { font-size: 13px; font-weight: 700; padding: 3px 11px; border-radius: 999px; display: inline-flex; align-items: center; gap: 6px; }
.pill .dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.pill.ok { color: var(--good); background: color-mix(in srgb, var(--good) 14%, transparent); }
.pill.no { color: var(--bad); background: color-mix(in srgb, var(--bad) 14%, transparent); }
.pill.wait { color: var(--ink-2); background: var(--sunk); }
.verdict .sub { font-size: 13px; color: var(--ink-3); }
.figures { display: grid; grid-template-columns: repeat(2, 1fr); }
@media (min-width: 640px) { .figures { grid-template-columns: repeat(4, 1fr); } }
.figure { padding: 12px 16px 14px; border-top: 1px solid var(--rule); }
.figures .figure:nth-child(odd) { border-right: 1px solid var(--rule); }
@media (min-width: 640px) { .figures .figure { border-right: 1px solid var(--rule); } .figures .figure:last-child { border-right: 0; } }
.figure .k { font-size: 12.5px; color: var(--ink-2); }
.figure .v { font-size: 26px; font-weight: 700; letter-spacing: -.02em; line-height: 1.2; }
.figure .v small { font-size: 13px; font-weight: 500; color: var(--ink-3); letter-spacing: 0; }
.figure.no .v { color: var(--bad); }
.figure .note { font-size: 12px; color: var(--ink-3); line-height: 1.35; margin-top: 2px; }
.checks { list-style: none; margin: 0; padding: 4px 16px 14px; font-size: 13.5px; }
.checks li { display: flex; gap: 8px; align-items: baseline; padding: 3px 0; color: var(--bad); }
.checks li::before { content: "✗"; font-weight: 800; }

.help { font-size: 12.5px; color: var(--ink-3); padding: 12px 4px 0; line-height: 1.45; }
.help b { color: var(--ink-2); }

/* ---------- the grade picker */
.picker-shade { position: fixed; inset: 0; z-index: 19; background: rgba(10, 16, 24, .12); }
.picker {
  position: fixed; z-index: 20; width: min(320px, calc(100vw - 16px));
  background: var(--panel); border: 1px solid var(--rule); border-radius: 16px;
  box-shadow: 0 18px 40px -12px rgba(10, 16, 24, .45); padding: 10px;
}
.pk-head { display: flex; align-items: baseline; gap: 8px; padding: 0 2px 8px; flex-wrap: wrap; }
.pk-head b { font-size: 14.5px; }
.pk-head span { font-size: 12.5px; color: var(--ink-3); flex: 1; }
.pk-x { border: 0; background: none; color: var(--ink-3); font-size: 15px; cursor: pointer; padding: 0 4px; }
.pk-mode { display: flex; gap: 4px; background: var(--sunk); border: 1px solid var(--rule); border-radius: 999px; padding: 3px; }
.pk-mode .seg { flex: 1; border: 0; background: transparent; padding: 6px 8px; }
.pk-mode .seg[aria-pressed="true"] { background: var(--panel); color: var(--ink); box-shadow: var(--shadow); }
.pk-slider { display: grid; grid-template-columns: 34px 1fr 34px 54px; gap: 6px; align-items: center; padding: 10px 0 4px; }
.pk-slider input[type=range] { width: 100%; accent-color: var(--ink); height: 28px; margin: 0; }
.pk-step { width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--rule); background: var(--sunk); font-size: 18px; font-weight: 700; cursor: pointer; color: var(--ink-2); line-height: 1; }
.pk-slider output { font-size: 17px; font-weight: 750; text-align: right; font-variant-numeric: tabular-nums; }
.pk-groups { display: flex; gap: 4px; align-items: center; padding: 4px 0 10px; border-bottom: 1px solid var(--rule); }
.pk-groups span { font-size: 12.5px; color: var(--ink-3); margin-right: 2px; }
.pk-groups .seg { padding: 4px 9px; font-size: 13px; }
.pk-hint { margin: 2px 0 0; padding: 0 2px 10px; font-size: 12px; color: var(--ink-3); border-bottom: 1px solid var(--rule); line-height: 1.35; }
.pk-grades { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; padding: 10px 0 8px; }
.pk-g {
  border: 1px solid var(--rule); background: var(--sunk); border-radius: 10px; padding: 10px 0;
  font-size: 17px; font-weight: 650; cursor: pointer; font-variant-numeric: tabular-nums;
}
.pk-g.low { color: var(--bad); }
.pk-g[aria-pressed="true"] { background: var(--ink); color: var(--panel); border-color: var(--ink); }
.pk-g.del { font-size: 13px; font-weight: 600; color: var(--bad); background: transparent; }
.pk-other { width: 100%; border: 1px dashed var(--ink-3); background: none; border-radius: 10px; padding: 9px; font-weight: 600; color: var(--ink-2); cursor: pointer; }
.pk-manual { display: flex; gap: 6px; }
.pk-manual input { flex: 1; min-width: 0; border: 1px solid var(--rule); background: var(--sunk); border-radius: 10px; padding: 8px 12px; font-size: 16px; }
.seg { border: 1px solid var(--rule); background: var(--sunk); border-radius: 999px; padding: 6px 12px; font-size: 13.5px; font-weight: 600; color: var(--ink-2); cursor: pointer; white-space: nowrap; }
.seg[aria-pressed="true"] { background: var(--ink); color: var(--panel); border-color: var(--ink); }
.seg:disabled { opacity: .4; cursor: default; }
.seg.gA[aria-pressed="true"] { background: var(--gA); border-color: var(--gA); }
.seg.gB[aria-pressed="true"] { background: var(--gB); border-color: var(--gB); }
.seg.gC[aria-pressed="true"] { background: var(--gC); border-color: var(--gC); color: #13223a; }

/* ---------- buttons, sheets */
.btn {
  border: 1px solid var(--rule); background: var(--panel); padding: 9px 16px; border-radius: 12px;
  font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 8px; white-space: nowrap;
}
.btn:hover { border-color: var(--ink-3); }
.btn.primary { background: var(--ink); color: var(--panel); border-color: var(--ink); }
.btn.danger { color: var(--bad); }
.btn.small { padding: 5px 11px; font-size: 13px; border-radius: 9px; }

.sheet {
  border: 1px solid var(--rule); border-radius: var(--radius-lg); background: var(--panel); color: var(--ink);
  padding: 0; width: min(520px, calc(100vw - 20px)); max-height: calc(100dvh - 30px); box-shadow: var(--shadow);
}
.sheet::backdrop { background: rgba(10, 16, 24, .45); }
@media (max-width: 600px) {
  .sheet { margin: auto 0 0; width: 100vw; max-width: 100vw; border-radius: var(--radius-lg) var(--radius-lg) 0 0; border-bottom: 0; }
}
.sheet-head { display: flex; align-items: center; gap: 10px; padding: 16px 18px 6px; position: sticky; top: 0; background: var(--panel); z-index: 1; }
.sheet-head h2 { margin: 0; font-size: 17px; font-weight: 700; flex: 1; }
.sheet-body { padding: 6px 18px 20px; display: grid; gap: 14px; }
.sheet-body h3 { margin: 6px 0 -4px; font-size: 13px; color: var(--ink-3); font-weight: 650; text-transform: uppercase; letter-spacing: .04em; }
.field { display: grid; gap: 5px; }
.field > span { font-size: 13px; color: var(--ink-2); font-weight: 600; }
.field input[type=text], .field input[type=number], .field select {
  border: 1px solid var(--rule); background: var(--sunk); border-radius: 10px; padding: 9px 12px; width: 100%;
}
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.check { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; }
.check input { width: 20px; height: 20px; margin: 1px 0 0; accent-color: var(--ink); flex: none; }
.check small { display: block; color: var(--ink-3); font-size: 12.5px; }
.sheet-foot { display: flex; gap: 8px; justify-content: space-between; flex-wrap: wrap; padding-top: 4px; }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + var(--kb)); transform: translateX(-50%); z-index: 30;
  background: var(--ink); color: var(--panel); padding: 9px 16px; border-radius: 12px; font-weight: 600; font-size: 14px;
  box-shadow: var(--shadow); display: flex; gap: 12px; align-items: center; max-width: calc(100vw - 30px);
}
.toast button { border: 0; background: none; color: inherit; font-weight: 800; text-decoration: underline; cursor: pointer; padding: 0; }
