/* The course palette (tools/teach/theme.py) and the form's own field colours
   (tools/teach/forms.py), so the page reads as the same worksheet. */
:root {
  --dark: #1F4E79;
  --mid: #2E74B5;
  --slate: #404040;
  --grey: #666666;
  --row: #F2F2F2;
  --field-line: #4A8BA8;
  --field-fill: #EEF3F6;
  --bg: #FFFFFF;
  color-scheme: light;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--slate);
  font: 16px/1.5 "Noto Sans", "Segoe UI", Arial, sans-serif;
}
header.site { background: var(--dark); padding: 10px 16px; }
header.site .back { color: #fff; text-decoration: none; font-weight: 600; }
main { max-width: 860px; margin: 0 auto; padding: 16px 16px 64px; }
h1 { color: var(--dark); font-size: 1.6rem; line-height: 1.25; }
h2 { color: var(--mid); font-size: 1.2rem; margin-top: 2rem; }
h3 { color: var(--slate); font-size: 1.05rem; }
a { color: var(--mid); }
hr { border: 0; border-top: 1px solid #ccc; margin: 1.5rem 0; }
blockquote { margin: 1rem 0; padding: 4px 14px; border-left: 3px solid var(--mid); background: var(--row); }
code { background: var(--row); padding: 0 3px; border-radius: 3px; }
th code { background: rgba(255, 255, 255, 0.2); color: #fff; }
img { max-width: 100%; height: auto; }
table { border-collapse: collapse; width: 100%; margin: 1rem 0; display: block; overflow-x: auto; }
th { background: var(--dark); color: #fff; text-align: left; }
th, td { padding: 6px 8px; border: 1px solid #d0d0d0; vertical-align: top; }
tr:nth-child(even) td { background: var(--row); }
ul.contains-task-list, ul.task-list { list-style: none; padding-left: 1.2rem; }

.toolbar {
  position: sticky; top: 0; z-index: 2;
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
  padding: 8px 16px; background: #fff; border-bottom: 1px solid #d0d0d0;
}
.toolbar button, .toolbar .button {
  font: inherit; font-size: 0.95rem; cursor: pointer;
  padding: 6px 12px; border-radius: 4px;
  border: 1px solid var(--mid); background: #fff; color: var(--mid);
}
.toolbar .primary { background: var(--mid); color: #fff; }
.toolbar button:disabled { opacity: 0.6; cursor: progress; }
#status { font-size: 0.9rem; color: var(--grey); }
#status.error { color: #B00020; font-weight: 600; }
#status.ok { color: #1B7F3B; }
.howto { font-size: 0.92rem; color: var(--grey); background: var(--row); padding: 10px 12px; border-radius: 4px; }

.ws-line, .ws-cell, .ws-box, .ws-choice {
  font: inherit; font-size: 0.95rem; color: #000;
  border: 1px solid var(--field-line); background: var(--field-fill);
  border-radius: 2px; padding: 3px 6px;
}
.ws-line { max-width: 100%; min-width: 6em; }
.ws-line.ws-wide { width: 100%; }
.ws-cell { width: 100%; min-width: 8em; resize: vertical; }
.ws-box { display: block; width: 100%; resize: vertical; margin: 4px 0 8px; }
.ws-choice { width: 100%; min-width: 12em; padding: 4px; }
.ws-tick { width: 1.1rem; height: 1.1rem; accent-color: var(--mid); vertical-align: middle; }
.ws-line:focus, .ws-cell:focus, .ws-box:focus, .ws-choice:focus { outline: 2px solid var(--mid); outline-offset: 0; background: #fff; }
ul.labs { padding-left: 1.2rem; }
ul.labs li { margin: 10px 0; }
ul.labs .lab-title { font-weight: 600; }
ul.labs .materials { display: flex; margin-top: 4px; }

/* Companion files: small buttons, opened in one window over the page */
.companion { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 12px 0 0; }
.companion > span { font-size: 0.92rem; color: var(--grey); }
.materials { display: inline-flex; flex-wrap: wrap; gap: 6px; }
a.material-link {
  font-size: 0.88rem; text-decoration: none; padding: 3px 10px; border-radius: 4px;
  border: 1px solid var(--mid); color: var(--mid); background: #fff;
}
a.material-link:hover, a.material-link:focus-visible { background: var(--mid); color: #fff; }
dialog#material {
  width: min(1100px, 96vw); height: 92vh; padding: 0; border: 0; border-radius: 6px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.35); overflow: hidden;
}
dialog#material[open] { display: flex; flex-direction: column; }
dialog#material::backdrop { background: rgba(0, 0, 0, 0.55); }
.material-bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 12px;
  padding: 8px 12px; background: var(--dark); color: #fff;
}
.material-bar .material-title { flex: 1 1 auto; min-width: 0; }
.material-bar a { color: #fff; font-size: 0.9rem; }
.material-close {
  font: inherit; font-size: 1.1rem; line-height: 1; cursor: pointer;
  background: transparent; color: #fff; border: 1px solid rgba(255, 255, 255, 0.6);
  border-radius: 4px; padding: 4px 9px;
}
.material-viewer {
  flex: 1 1 auto; overflow: auto; background: #525659;
  padding: 12px; display: flex; flex-direction: column; align-items: center; gap: 12px;
}
.material-page { position: relative; flex: none; background: #fff; box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4); }
.material-page canvas { display: block; width: 100%; height: 100%; }
.material-page a { position: absolute; display: block; }
.material-page a:hover { background: rgba(46, 116, 181, 0.15); outline: 1px solid var(--mid); }
.material-note { color: #fff; margin: 24px; }

figure.screencast { margin: 1rem 0; }
figure.screencast video { width: 100%; height: auto; background: #000; border-radius: 4px; }
figure.screencast figcaption { font-size: 0.9rem; color: var(--grey); margin-top: 6px; }
details.screencast { margin: 0.6rem 0 1rem; }
details.screencast summary { cursor: pointer; font-weight: 600; color: var(--dark); }

@media (max-width: 600px) {
  .ws-line { width: 100% !important; display: block; margin: 4px 0; }
}

/* The lab's spreadsheet (sheet.js), docked under the worksheet. */
.sheet-dock {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  height: 46vh; display: flex; flex-direction: column;
  background: #fff; border-top: 3px solid var(--dark);
  box-shadow: 0 -4px 14px rgba(0, 0, 0, 0.15); font-size: 0.9rem;
}
.sheet-dock.tall { height: 82vh; }
.sheet-dock[hidden] { display: none; }
.sheet-bar { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; padding: 6px 10px; background: var(--row); }
.sheet-title { color: var(--dark); margin-right: auto; }
.sheet-actions { display: flex; flex-wrap: wrap; gap: 4px; }
.sheet-actions button, .sheet-actions a {
  font: inherit; font-size: 0.85rem; cursor: pointer; text-decoration: none;
  padding: 3px 8px; border-radius: 4px; border: 1px solid var(--mid); background: #fff; color: var(--mid);
}
.sheet-actions button[aria-pressed="true"], .sheet-actions button[aria-expanded="true"] { background: var(--mid); color: #fff; }
.sheet-help { padding: 4px 12px; background: #FFFBEA; border-bottom: 1px solid #e8dfb0; font-size: 0.85rem; max-height: 30%; overflow: auto; }
.sheet-help p { margin: 4px 0; }
.sheet-formula { display: flex; gap: 6px; align-items: center; padding: 4px 10px; border-bottom: 1px solid #d0d0d0; }
.sheet-name { min-width: 5.5em; font-weight: 600; color: var(--dark); font-family: Consolas, monospace; }
.sheet-input { flex: 1; font: 0.95rem Consolas, "Noto Sans Mono", monospace; padding: 3px 6px; border: 1px solid var(--field-line); background: var(--field-fill); }
.sheet-grid { flex: 1; overflow: auto; outline: none; }
.sheet-grid:focus-visible { box-shadow: inset 0 0 0 2px var(--mid); }
.sheet-grid table { display: table; width: auto; margin: 0; border-collapse: separate; border-spacing: 0; user-select: none; }
.sheet-grid th, .sheet-grid td { border: 0; border-right: 1px solid #d9d9d9; border-bottom: 1px solid #d9d9d9; padding: 2px 6px; white-space: nowrap; height: 24px; }
.sheet-grid thead th { position: sticky; top: 0; z-index: 3; background: #E7ECF1; color: var(--slate); text-align: center; font-weight: 600; min-width: 6.5em; }
.sheet-grid thead th.corner { z-index: 4; min-width: 3em; }
.sheet-grid th.rown { position: sticky; left: 0; z-index: 2; background: #E7ECF1; color: var(--slate); text-align: right; min-width: 3em; }
.sheet-grid th.on { background: #C9D7E4; color: var(--dark); }
.sheet-grid tr:nth-child(even) td { background: #fff; }
.sheet-grid td { min-width: 6.5em; max-width: 16em; overflow: hidden; text-overflow: ellipsis; cursor: cell; color: #000; }
.sheet-grid td.num { text-align: right; }
.sheet-grid td.err { color: #B00020; font-weight: 600; }
.sheet-grid td.sel { background: #DCE8F4 !important; }
.sheet-grid td.active { box-shadow: inset 0 0 0 2px var(--mid); }
.sheet-grid td { position: relative; }
.sheet-grid td.fillprev { background: #EEF3F6 !important; outline: 1px dashed var(--mid); outline-offset: -1px; }
.fill-handle {
  position: absolute; right: 0; bottom: 0; width: 8px; height: 8px;
  background: var(--mid); border: 1px solid #fff; cursor: crosshair;
}
.sheet-grid tbody tr:first-child td { font-weight: 600; }
.sheet-grid tr.frozen td, .sheet-grid tr.frozen th.rown { position: sticky; top: 25px; z-index: 2; background: #F4F7FA; border-bottom: 2px solid #9fb4c8; }
.sheet-grid tr.frozen th.rown { z-index: 3; background: #E7ECF1; }
.sheet-edit { width: 100%; min-width: 8em; font: 0.95rem Consolas, monospace; border: 0; outline: 2px solid var(--mid); padding: 1px 2px; }
.sheet-log { max-height: 26%; overflow: auto; padding: 2px 10px; border-top: 1px solid #d0d0d0; background: #FAFAFA; font-size: 0.85rem; }
.sheet-log ol { margin: 4px 0; padding-left: 1.6em; }
.sheet-log .empty { list-style: none; color: var(--grey); }
.sheet-status { min-height: 1.6em; padding: 2px 10px; border-top: 1px solid #d0d0d0; color: var(--grey); font-size: 0.85rem; }
#sheet-toggle[aria-pressed="true"] { background: var(--dark); color: #fff; border-color: var(--dark); }

.sheet-chart { width: min(780px, 96vw); padding: 0; border: 1px solid #ccc; border-radius: 6px; }
.sheet-chart::backdrop { background: rgba(0, 0, 0, 0.35); }
.sheet-chart .material-bar { display: flex; gap: 8px; align-items: center; padding: 8px 12px; background: var(--row); }
.sheet-chart .material-bar strong { margin-right: auto; color: var(--dark); }
.sheet-chart .material-bar button { font: inherit; font-size: 0.85rem; cursor: pointer; padding: 3px 8px; border-radius: 4px; border: 1px solid var(--mid); background: #fff; color: var(--mid); }
.chart-controls { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; padding: 8px 12px; font-size: 0.9rem; }
.chart-controls select, .chart-controls input[type=number] { font: inherit; }
.chart-controls input[type=number] { width: 4em; }
.chart-area { padding: 0 8px 10px; }
.chart-area svg { width: 100%; height: auto; display: block; }

.sheet-menu {
  position: fixed; z-index: 10; min-width: 250px; padding: 4px 0;
  background: #fff; border: 1px solid #c8c8c8; border-radius: 4px; box-shadow: 0 6px 18px rgba(0, 0, 0, 0.2);
}
.sheet-menu[hidden] { display: none; }
.sheet-menu button {
  display: flex; width: 100%; justify-content: space-between; gap: 16px; align-items: center;
  font: inherit; font-size: 0.88rem; text-align: left; cursor: pointer;
  padding: 5px 14px; border: 0; background: none; color: #000;
}
.sheet-menu button:hover, .sheet-menu button:focus { background: #DCE8F4; outline: none; }
.sheet-menu button:disabled { color: #999; cursor: default; background: none; }
.sheet-menu kbd { font: 0.8rem Consolas, monospace; color: var(--grey); }
.sheet-menu hr { margin: 4px 0; border: 0; border-top: 1px solid #e3e3e3; }
.sheet-grid thead th.col, .sheet-grid th.rown, .sheet-grid th.corner { cursor: pointer; }
.sheet-grid thead th.col:hover, .sheet-grid th.rown:hover { background: #D5E1EC; }
.chart-notes { padding: 0 12px 12px; font-size: 0.85rem; }
.chart-notes table.box-stats { display: table; width: auto; margin: 4px 0; }
.chart-notes table.box-stats th, .chart-notes table.box-stats td { padding: 3px 8px; }
.chart-notes table.box-stats td:not(:first-child) { text-align: right; }
.box-note { color: var(--grey); margin: 6px 0 0; }
.sheet-chart { max-height: 94vh; overflow: auto; }
