:root {
  --bg: #f3efe6;
  --card: #fffdf8;
  --ink: #1f1d1a;
  --muted: #6b665c;
  --line: #1f1d1a;
  --soft: #d9d3c4;
  --hw: #2f6f4f;
  --hw-bg: #dcebe1;
  --test: #b8391f;
  --test-bg: #f6dcd5;
  --accent: #1f4fb8;
  --today: #fff0b8;
}

* { box-sizing: border-box; }

html { font-size: 16px; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Trebuchet MS", Verdana, Tahoma, sans-serif;
  line-height: 1.4;
}

.wrap { max-width: 1200px; margin: 0 auto; padding: 0 16px; }

/* Icons (Phosphor sprite) */
.ic { width: 1.15em; height: 1.15em; fill: currentColor; flex: none; vertical-align: -0.2em; }
.brand-ic { width: 1.3em; height: 1.3em; margin-right: 4px; vertical-align: -0.25em; }

/* Header */
.top { border-bottom: 2px solid var(--line); background: var(--card); }
.top-row { display: flex; align-items: center; justify-content: space-between; min-height: 60px; padding-top: 8px; padding-bottom: 8px; gap: 10px 12px; flex-wrap: wrap; }
.brand { margin: 0; font-family: Georgia, "Times New Roman", serif; font-size: 1.6rem; letter-spacing: 0.2px; white-space: nowrap; }
.account { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.btn { white-space: nowrap; }
.who { white-space: nowrap; }
.who { font-size: 0.95rem; }
.who b { font-weight: 700; }

/* Buttons */
.btn {
  font: inherit;
  font-size: 0.95rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  text-decoration: none;
  padding: 8px 14px;
  background: var(--card);
  color: var(--ink);
  border: 2px solid var(--line);
  border-radius: 6px;
  cursor: pointer;
}
.btn:hover { background: var(--soft); }
.btn:focus-visible, input:focus-visible, textarea:focus-visible, .dd-btn:focus-visible, .card:focus-visible, .tab:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}
.btn.primary { background: var(--ink); color: var(--card); box-shadow: 3px 3px 0 var(--accent); }
.btn.primary:hover { background: #3a362f; }
.btn.primary:active { box-shadow: 1px 1px 0 var(--accent); transform: translate(2px, 2px); }
.btn.danger { border-color: var(--test); color: var(--test); }
.btn.danger:hover { background: var(--test-bg); }
.btn.wide { width: 100%; }
.btn[disabled] { opacity: 0.6; cursor: wait; }

/* Week bar */
.bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 20px 0 14px; }
.week-nav { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.week-label { font-family: Georgia, "Times New Roman", serif; font-size: 1.25rem; min-width: 190px; text-align: center; }

.bar-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.filter { display: flex; align-items: center; gap: 6px; }
.filter .dd { width: 130px; }
.filter .dd-btn { padding: 8px 32px 8px 10px; font-size: 0.95rem; }

/* Week grid */
.week { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; padding-bottom: 40px; }
.day {
  background: var(--bg);
  border: 2px solid var(--line);
  border-radius: 8px;
  min-height: 260px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.day-head { padding: 8px 10px; border-bottom: 2px solid var(--line); background: var(--card); display: flex; align-items: baseline; justify-content: space-between; }
.day-name { font-weight: 700; }
.day-num { color: var(--muted); font-size: 0.9rem; }
.day.today .day-head { background: var(--today); }
.day.past .day-body { opacity: 0.6; }
.day-body { padding: 8px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.empty { color: var(--muted); font-size: 0.85rem; padding: 4px 2px; }

/* Cards */
.card {
  text-align: left;
  font: inherit;
  width: 100%;
  background: var(--card);
  border: 2px solid var(--line);
  border-left-width: 8px;
  border-radius: 6px;
  padding: 8px 10px;
  cursor: pointer;
  display: block;
  color: var(--ink);
}
.card.hw { border-left-color: var(--hw); }
.card.test { border-left-color: var(--test); }
.card:hover { box-shadow: 3px 3px 0 var(--line); transform: translate(-1px, -1px); }
.card-type { font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.6px; display: flex; align-items: center; gap: 5px; }
.card-type .ic { width: 1.35em; height: 1.35em; }
.card.hw .card-type { color: var(--hw); }
.card.test .card-type { color: var(--test); }
.card-title { font-weight: 700; margin: 2px 0; overflow-wrap: anywhere; }
.card-sub { font-size: 0.85rem; color: var(--muted); overflow-wrap: anywhere; }
.card-more { font-size: 0.75rem; color: var(--accent); margin-top: 4px; display: flex; align-items: center; gap: 4px; }

/* Dialogs */
dialog {
  border: 2px solid var(--line);
  border-radius: 10px;
  padding: 0;
  background: var(--card);
  color: var(--ink);
  width: min(520px, calc(100vw - 24px));
  max-height: calc(100vh - 24px);
  overflow: visible;
  box-shadow: 6px 6px 0 var(--ink);
}
dialog::backdrop { background: rgba(31, 29, 26, 0.55); }
#viewDlg { width: min(680px, calc(100vw - 24px)); }
.panel { padding: 18px 20px 20px; max-height: calc(100vh - 28px); overflow: visible; }
.panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.panel-head h2 { margin: 0; font-family: Georgia, "Times New Roman", serif; font-size: 1.4rem; }
.x { font: inherit; font-size: 1.3rem; background: none; border: 2px solid transparent; border-radius: 6px; color: var(--muted); cursor: pointer; padding: 3px 5px; line-height: 1; display: inline-flex; align-items: center; }
.x:hover { color: var(--ink); border-color: var(--ink); }
.x:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* Fields */
.field { margin-bottom: 14px; position: relative; }
.field > label { display: block; font-weight: 700; margin-bottom: 5px; font-size: 0.95rem; }
.opt { font-weight: 400; color: var(--muted); }
input[type="text"], input[type="password"], input[type="date"], textarea {
  width: 100%;
  font: inherit;
  padding: 9px 10px;
  background: #fff;
  color: var(--ink);
  border: 2px solid var(--line);
  border-radius: 6px;
}
textarea { resize: vertical; }
input[hidden] { display: none; }
.field input + input, .field .dd + input { margin-top: 8px; }
.hint { margin: 6px 0 0; font-size: 0.85rem; color: var(--muted); }
.hint[hidden] { display: none; }
.hint.ok { color: var(--hw); font-weight: 700; }
.hint.bad { color: var(--test); font-weight: 700; }
.error { margin: 0 0 12px; padding: 8px 10px; background: var(--test-bg); border: 2px solid var(--test); border-radius: 6px; color: #7d2412; font-size: 0.9rem; }
.error[hidden], .notice[hidden] { display: none; }
.notice { margin: 0 0 12px; padding: 8px 10px; background: var(--today); border: 2px solid var(--line); border-radius: 6px; font-size: 0.9rem; display: flex; gap: 8px; align-items: flex-start; }
.notice .ic { margin-top: 2px; }
.field > label { display: flex; align-items: center; gap: 6px; }
.google { margin-bottom: 0; }
.divider { display: flex; align-items: center; gap: 10px; margin: 14px 0; color: var(--muted); font-size: 0.85rem; }
.divider::before, .divider::after { content: ""; flex: 1; height: 2px; background: var(--soft); }
#googleBox[hidden] { display: none; }
.actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; }

/* Custom dropdown */
.dd { position: relative; }
.dd-btn {
  width: 100%;
  font: inherit;
  text-align: left;
  padding: 9px 36px 9px 10px;
  background: #fff;
  border: 2px solid var(--line);
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  color: var(--ink);
}
.dd-btn::after {
  content: "";
  position: absolute;
  right: 12px;
  top: 50%;
  width: 8px;
  height: 8px;
  border-right: 2px solid var(--ink);
  border-bottom: 2px solid var(--ink);
  transform: translateY(-70%) rotate(45deg);
}
.dd.open .dd-btn::after { transform: translateY(-30%) rotate(-135deg); }
.dd-list {
  list-style: none;
  margin: 4px 0 0;
  padding: 4px;
  position: absolute;
  left: 0;
  right: 0;
  z-index: 20;
  background: #fff;
  border: 2px solid var(--line);
  border-radius: 6px;
  box-shadow: 3px 3px 0 var(--ink);
  max-height: 240px;
  overflow-y: auto;
}
.dd-list[hidden] { display: none; }
.dd-opt { padding: 8px 10px; border-radius: 4px; cursor: pointer; }
.dd-opt.active { background: var(--soft); }
.dd-opt[aria-selected="true"] { font-weight: 700; }
.dd-opt.sep { border-top: 2px solid var(--soft); margin-top: 4px; padding-top: 10px; }

/* Auth tabs */
.tabs { display: flex; gap: 0; margin-bottom: 14px; border: 2px solid var(--line); border-radius: 6px; overflow: hidden; }
.tab { flex: 1; font: inherit; padding: 8px; background: var(--card); border: none; cursor: pointer; color: var(--ink); display: inline-flex; align-items: center; justify-content: center; gap: 7px; }
.tab + .tab { border-left: 2px solid var(--line); }
.tab[aria-selected="true"] { background: var(--ink); color: var(--card); }

/* Preview */
.badge { display: inline-block; font-size: 0.78rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.6px; padding: 3px 9px; border-radius: 4px; border: 2px solid; }
.badge.hw { color: var(--hw); background: var(--hw-bg); border-color: var(--hw); }
.badge.test { color: var(--test); background: var(--test-bg); border-color: var(--test); }
.view-title { font-family: Georgia, "Times New Roman", serif; font-size: 1.9rem; margin: 10px 0 4px; overflow-wrap: anywhere; }
.view-meta { color: var(--muted); margin: 0 0 16px; }
.view-label { font-weight: 700; margin: 0 0 6px; }
.view-info { margin: 0 0 18px; padding: 12px; background: #fff; border: 2px solid var(--soft); border-radius: 6px; white-space: pre-wrap; overflow-wrap: anywhere; min-height: 80px; }
.view-info.none { color: var(--muted); }
.view-meta .ic { margin-right: 2px; }
.view-meta span + span { margin-left: 14px; }
.view-label { display: flex; align-items: center; gap: 6px; }
.badge { display: inline-flex; align-items: center; gap: 6px; }

/* Admin */
.admin-list { max-height: 55vh; overflow-y: auto; border: 2px solid var(--soft); border-radius: 6px; background: #fff; }
.row { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-bottom: 2px solid var(--soft); }
.row:last-child { border-bottom: none; }
.row-main { flex: 1; min-width: 0; }
.row-title { font-weight: 700; overflow-wrap: anywhere; }
.row-sub { font-size: 0.82rem; color: var(--muted); overflow-wrap: anywhere; }
.pill { display: inline-block; font-size: 0.7rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; padding: 1px 6px; border: 2px solid var(--line); border-radius: 4px; margin-left: 6px; vertical-align: 1px; }
.pill.admin { background: var(--today); }
.btn.small { padding: 5px 9px; font-size: 0.85rem; }
.admin-empty { padding: 14px; color: var(--muted); }

/* Smaller screens */
@media (max-width: 960px) {
  .week { grid-template-columns: 1fr; }
  .day { min-height: 0; }
  .day-body { min-height: 44px; }
}

@media (max-width: 520px) {
  .week-label { min-width: 0; width: 100%; order: -1; }
  .brand { font-size: 1.3rem; }
}

/* ---------- Layout with footer ---------- */
body.page { min-height: 100vh; display: flex; flex-direction: column; }
body.page > main { flex: 1; width: 100%; }
a.brand, h1.brand { color: inherit; text-decoration: none; display: inline-flex; align-items: center; }
.foot { margin-top: auto; border-top: 2px solid var(--line); background: var(--card); padding: 14px 0; font-size: 0.85rem; color: var(--muted); }
.foot-row { display: flex; justify-content: space-between; align-items: center; gap: 8px 16px; flex-wrap: wrap; }
.foot a { color: var(--ink); margin-left: 16px; }
.foot a:first-child { margin-left: 0; }
.foot a:hover { color: var(--accent); }
.fine { margin: 12px 0 0; font-size: 0.8rem; color: var(--muted); text-align: center; }
.fine[hidden] { display: none; }
.fine a { color: var(--ink); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.center { text-align: center; }

/* ---------- Avatars ---------- */
.avatar { position: relative; display: inline-flex; align-items: center; justify-content: center; width: var(--size, 32px); height: var(--size, 32px); border-radius: 50%; color: #fff; font-weight: 700; font-size: calc(var(--size, 32px) * 0.5); overflow: hidden; flex: none; line-height: 1; vertical-align: middle; }
.avatar-img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.picker { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.picker-circle { position: relative; display: inline-flex; align-items: center; justify-content: center; width: var(--size, 112px); height: var(--size, 112px); max-width: 100%; border-radius: 50%; border: 2px solid var(--line); color: #fff; cursor: pointer; padding: 0; font: inherit; }
.picker-circle:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
.picker-letter { font-size: calc(var(--size, 112px) * 0.45); font-weight: 700; line-height: 1; }
.picker-circle .avatar-img { border-radius: 50%; }
.picker-badge { position: absolute; right: -4px; bottom: -4px; width: 34px; height: 34px; border-radius: 50%; background: var(--ink); color: var(--card); border: 2px solid var(--card); display: flex; align-items: center; justify-content: center; font-size: 1rem; z-index: 2; }
.picker-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.picker-actions [hidden] { display: none; }
.picker-msg { color: var(--test); font-weight: 700; margin: 0; text-align: center; }
.picker-msg[hidden] { display: none; }

/* ---------- Account menu ---------- */
.account-btn { padding: 4px 10px 4px 5px; gap: 8px; }
.who-name { max-width: 130px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 700; }
.menu-wrap { position: relative; }
.menu { position: absolute; right: 0; top: calc(100% + 8px); min-width: 230px; background: var(--card); border: 2px solid var(--line); border-radius: 8px; box-shadow: 3px 3px 0 var(--ink); padding: 4px; z-index: 50; }
.menu[hidden] { display: none; }
.menu-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 10px; border: none; background: none; font: inherit; font-size: 0.95rem; color: var(--ink); text-align: left; border-radius: 5px; cursor: pointer; text-decoration: none; }
.menu-item:hover, .menu-item:focus-visible { background: var(--soft); outline: none; }
.menu-item.danger { color: var(--test); }
.menu-sep { height: 2px; background: var(--soft); margin: 4px 0; }

/* ---------- Subject colours ---------- */
.swatch { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 9px; vertical-align: -1px; flex: none; }
.card.hw, .card.test { border-left-color: var(--c, #6b665c); }
.card.hw .card-type { color: var(--muted); }
.card-sub { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.chip { display: inline-flex; align-items: center; gap: 6px; font-weight: 700; font-size: 0.85rem; overflow-wrap: anywhere; }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.set-tag { border: 2px solid var(--soft); border-radius: 4px; padding: 0 5px; font-size: 0.75rem; font-weight: 700; color: var(--muted); }
.view-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; }
.view-meta .meta-item { display: inline-flex; align-items: center; gap: 8px; margin: 0; }
a.brand { font-weight: 700; }
.view-meta span + span { margin-left: 0; }
.view-meta .chip { font-size: 1rem; }
.view-title { padding-top: 2px; padding-bottom: 2px; }

/* ---------- Onboarding ---------- */
.narrow { max-width: 520px; padding-top: 28px; padding-bottom: 40px; }
.card-page { background: var(--card); border: 2px solid var(--line); border-radius: 10px; padding: 24px; box-shadow: 6px 6px 0 var(--ink); }
.page-title { font-family: Georgia, "Times New Roman", serif; font-size: 1.7rem; margin: 0 0 6px; }
.lead { color: var(--muted); margin: 0 0 20px; }
.btn.big { padding: 12px 14px; font-size: 1.05rem; }

/* ---------- Legal pages ---------- */
.legal { max-width: 780px; padding-top: 28px; padding-bottom: 48px; }
.legal h1 { font-family: Georgia, "Times New Roman", serif; font-size: 2rem; margin: 0 0 4px; }
.legal h2 { font-size: 1.1rem; margin: 26px 0 6px; }
.legal p, .legal li { line-height: 1.55; }
.legal ul { padding-left: 22px; }
.legal a { color: var(--accent); }
.updated { color: var(--muted); margin: 0 0 18px; font-size: 0.9rem; }
.legal table { width: 100%; border-collapse: collapse; background: var(--card); font-size: 0.92rem; }
.legal th, .legal td { border: 2px solid var(--soft); padding: 8px 10px; text-align: left; vertical-align: top; }
.legal th { background: var(--bg); }

@media (max-width: 640px) {
  .legal thead { display: none; }
  .legal table, .legal tbody, .legal tr, .legal td { display: block; width: 100%; }
  .legal tr { border: 2px solid var(--soft); margin-bottom: 10px; background: var(--card); }
  .legal td { border: none; padding: 4px 10px; }
  .legal td:first-child { padding-top: 8px; }
  .legal td:last-child { padding-bottom: 8px; }
  .legal td:nth-child(2)::before { content: "Why: "; font-weight: 700; }
  .legal td:nth-child(3)::before { content: "Who can see it: "; font-weight: 700; }
  .card-page { padding: 18px; }
}

@media (max-width: 420px) {
  .who-name { max-width: 80px; }
  .foot a { margin-left: 12px; }
}
