/* Mobile first: one column, the table scrolling sideways inside its own box with the
   hero column pinned. Grade colours are the window's (gui/src/main.rs grade_colour). */

:root {
  --bg: #ffffff;
  --fg: #1f2328;
  --muted: #59636e;
  --line: #d1d9e0;
  --raised: #f6f8fa;
  --accent: #5865f2;
  --accent-fg: #ffffff;
  --top: #1a7f37;
  --high: #0a7b83;
  --above: #0969da;
  --below: #9a6700;
  --bottom: #cf222e;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #2b2d31;
    --fg: #e6e6e6;
    --muted: #9da5b4;
    --line: #3f4248;
    --raised: #33363c;
    --top: #3fb950;
    --high: #2ec4b6;
    --above: #6cb2eb;
    --below: #d8923f;
    --bottom: #ff6b6b;
  }
}

* { box-sizing: border-box; }

/* The hidden attribute has to win over every display rule below, or #roles and
   #picker -- flex and grid -- would stay on screen when the page hides them. */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
}

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
           max(24px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

button, input { font: inherit; color: inherit; }

#search { display: flex; gap: 8px; }

#name {
  flex: 1;
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--raised);
  /* 16px or more, or iOS zooms the page on focus. */
  font-size: 16px;
}

button {
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--raised);
  cursor: pointer;
}

#search button { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }

#status { color: var(--muted); min-height: 1.4em; margin: 10px 0; }
#status.error { color: var(--bottom); }
#status p { margin: 0 0 6px; }

#picker { list-style: none; padding: 0; margin: 0 0 12px; display: grid; gap: 8px; }
#picker button { width: 100%; text-align: left; }
#picker .meta { display: block; color: var(--muted); font-size: 14px; }

header h1 { font-size: 20px; margin: 4px 0 2px; }
header p { margin: 0 0 8px; color: var(--muted); }

.controls { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; margin: 8px 0 12px; }

.segmented { display: inline-flex; }
.segmented button { border-radius: 0; margin-left: -1px; padding: 8px 12px; }
.segmented button:first-child { border-radius: 8px 0 0 8px; margin-left: 0; }
.segmented button:last-child { border-radius: 0 8px 8px 0; }
.segmented button[aria-pressed="true"] { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.segmented button:disabled { opacity: .5; cursor: default; }

#roles { display: flex; gap: 12px; }
#roles label, #grades-box { display: inline-flex; align-items: center; gap: 4px; }
/* At the row's right end, as the window has it, whichever line it wraps onto. */
#grades-box { margin-left: auto; }

#table-box {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--line);
  border-radius: 8px;
}

/* separate rather than collapse: collapsed borders under a sticky cell draw with gaps. */
table { border-collapse: separate; border-spacing: 0; width: 100%; font-variant-numeric: tabular-nums; }

th, td { padding: 8px 10px; white-space: nowrap; text-align: right; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 500; }
th button { all: unset; cursor: pointer; }
th[aria-sort] button { color: var(--fg); }

/* The hero column stays put while the numbers scroll under it. */
th:first-child, td:first-child {
  position: sticky;
  left: 0;
  text-align: left;
  background: var(--bg);
  z-index: 1;
}
td:first-child button { all: unset; cursor: pointer; color: var(--accent); }
tfoot td { font-weight: 600; border-bottom: none; }

/* A letter sits in a fixed gutter so numbers line up whether or not one was earned. */
.g { display: inline-block; width: 2.4em; text-align: left; padding-left: .3em; }
.top { color: var(--top); }
.high { color: var(--high); }
.above { color: var(--above); }
.below { color: var(--below); }
.bottom { color: var(--bottom); }

#empty { padding: 12px; margin: 0; color: var(--muted); }

#card { margin-top: 4px; }
.card-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.card-head h2 { margin: 0; font-size: 20px; text-transform: uppercase; }
.card-body { display: grid; gap: 4px 32px; grid-template-columns: 1fr; margin-top: 12px; }
@media (min-width: 760px) { .card-body { grid-template-columns: 1fr 1fr; } }
dl { margin: 0 0 12px; display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; }
dt { color: var(--fg); }
dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
dl h3 { grid-column: 1 / -1; margin: 4px 0; font-size: 15px; color: var(--muted); }

#legend-open { display: flex; gap: 12px; align-items: flex-start; }
.legend-notes { flex: 1; min-width: 0; }
.legend-notes h3 { margin: 12px 0 0; font-size: 14px; font-weight: 600; }
#legend-hide { padding: 4px 10px; margin-top: 8px; }
#legend-show { margin-top: 12px; padding: 6px 10px; background: none; color: var(--accent); }

.notes { padding-left: 18px; margin: 12px 0; color: var(--muted); font-size: 14px; }
.notes li { margin-bottom: 4px; }
/* The card's opening line heads its notes as plain text, as in the window. */
#card-opening { padding-left: 0; margin-bottom: 4px; }
.sources { color: var(--muted); font-size: 13px; }
