:root {
  --bg: #f7f7f5;
  --card: #ffffff;
  --text: #1d1d1f;
  --muted: #6b6b70;
  --border: #e2e2e0;
  --accent: #1f5fbf;
  --danger: #b3261e;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 1.25rem; margin: 0; }

.container { max-width: 900px; margin: 0 auto; padding: 16px; }

.list { display: grid; gap: 12px; }
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 16px;
}
.card h3 { margin: 0 0 4px; font-size: 1.05rem; }
.card p { margin: 4px 0; }

.muted { color: var(--muted); }
.pre { white-space: pre-wrap; }
.link { color: var(--accent); text-decoration: none; }
.link:hover { text-decoration: underline; }

/* Teacher dashboard */
.tabs { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 16px; }
.tabs button {
  border: 1px solid var(--border);
  background: var(--card);
  padding: 8px 14px;
  border-radius: 6px;
  cursor: pointer;
  font: inherit;
}
.tabs button.active { background: var(--accent); color: #fff; border-color: var(--accent); }

form.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: end; margin-bottom: 16px; }
label { display: grid; gap: 2px; font-size: 0.85rem; color: var(--muted); }
input, select, textarea {
  font: inherit;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--card);
  color: var(--text);
}
textarea { min-height: 80px; width: 100%; }
label.wide { flex: 1 1 100%; }

button.primary {
  font: inherit;
  background: var(--accent);
  color: #fff;
  border: 0;
  padding: 8px 14px;
  border-radius: 6px;
  cursor: pointer;
}
button.small {
  font: inherit;
  font-size: 0.85rem;
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 2px 8px;
  cursor: pointer;
}
button.danger { color: var(--danger); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; background: var(--card); }
th, td { text-align: left; padding: 8px; border-bottom: 1px solid var(--border); }
th { font-size: 0.85rem; color: var(--muted); }

.toast {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 8px 16px;
  border-radius: 6px;
  display: none;
}
.toast.show { display: block; }

/* Masthead (public page) */
.sticky-head { position: sticky; top: 0; z-index: 10; }
.masthead {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px 24px;
  flex-wrap: wrap;
  padding: 14px 24px;
  background: color-mix(in srgb, var(--card) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border);
}
.masthead .brand h1 { margin: 0; font-size: 1.35rem; font-weight: 800; letter-spacing: -0.01em; line-height: 1.1; }
.masthead .brand p { margin: 2px 0 0; font-size: 0.78rem; color: var(--muted); }
.masthead .meta { display: flex; align-items: center; gap: 20px; }
.masthead .dates { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.25; }
.masthead .hebdate { font-family: "Frank Ruhl Libre", "David", "Times New Roman", serif; font-size: 1.05rem; font-weight: 500; }
.masthead .greg { font-size: 0.75rem; color: var(--muted); }
.masthead .clock {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg);
  font-size: 0.85rem;
}
.masthead .clock .label { font-size: 0.68rem; font-weight: 600; letter-spacing: 0.08em; color: var(--muted); }
.masthead .clock strong { font-weight: 600; font-variant-numeric: tabular-nums; }
.masthead .dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: #2e9d5b;
  box-shadow: 0 0 0 3px color-mix(in srgb, #2e9d5b 20%, transparent);
}
@media (max-width: 560px) {
  .masthead { padding: 10px 16px; }
  .masthead .meta { width: 100%; justify-content: space-between; }
  .masthead .dates { align-items: flex-start; }
}

/* Main layout: schedule sidebar (left) + content */
.layout {
  display: grid;
  grid-template-columns: 232px minmax(0, 1fr);
  align-items: start;
}
.content { max-width: 860px; width: 100%; margin: 0 auto; padding: 20px 24px; }
.content h2 { font-size: 1.05rem; margin: 0 0 10px; }
.content section + section { margin-top: 24px; }

.schedule {
  position: sticky;
  top: var(--head-h, 86px);
  height: calc(100vh - var(--head-h, 86px));
  overflow-y: auto;
  background: var(--card);
  border-right: 1px solid var(--border);
  padding: 16px 0;
}
.schedule h2 {
  margin: 0;
  padding: 0 16px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}
.schedule #schedule-day { margin: 2px 0 10px; padding: 0 16px; font-size: 0.8rem; font-variant-numeric: tabular-nums; }

@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; }
  .schedule { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--border); }
  .content { padding: 16px; }
}

/* Timeline (nav-style rows on a thin rail) */
.timeline { list-style: none; margin: 0; padding: 0; position: relative; }
.timeline::before {
  content: "";
  position: absolute;
  left: 21px; top: 8px; bottom: 8px;
  width: 1px;
  background: var(--border);
}
.timeline li {
  position: relative;
  padding: 5px 16px 5px 36px;
  border-left: 3px solid transparent;
}
.timeline li::before {
  content: "";
  position: absolute;
  left: 15px; top: 11px;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--card);
  border: 1.5px solid var(--muted);
}
.timeline .time { font-size: 0.72rem; color: var(--muted); font-variant-numeric: tabular-nums; line-height: 1.3; }
.timeline .title { font-size: 0.875rem; font-weight: 500; line-height: 1.3; }
.timeline .teacher { font-size: 0.72rem; color: var(--muted); line-height: 1.3; }
.timeline .break { padding-top: 1px; padding-bottom: 1px; font-size: 0.7rem; color: var(--muted); }
.timeline .break::before { width: 3px; height: 3px; left: 17px; top: 8px; background: var(--border); border: 0; }
.timeline .past { opacity: 0.45; }
.timeline .now { background: color-mix(in srgb, var(--accent) 8%, transparent); border-left-color: var(--accent); }
.timeline .now::before { background: var(--accent); border-color: var(--accent); }
.timeline .now .title { color: var(--accent); font-weight: 600; }

/* Break-time games */
.games {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
}
.games-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; padding: 0 4px 10px; }
.games-head h2 { margin: 0; }
.games-head .link { font-size: 0.85rem; }
.games iframe { display: block; width: 100%; height: min(70vh, 640px); border: 0; border-radius: 6px; background: var(--bg); }

/* Who's online (sidebar footer) */
.presence { margin: 16px 16px 0; padding-top: 12px; border-top: 1px solid var(--border); font-size: 0.75rem; color: var(--muted); }
.presence summary { display: flex; align-items: center; gap: 6px; cursor: pointer; list-style: none; user-select: none; }
.presence summary::-webkit-details-marker { display: none; }
.presence summary:hover { color: var(--text); }
.presence .dot { width: 6px; height: 6px; border-radius: 50%; background: #2e9d5b; }
.presence ul { list-style: none; margin: 8px 0 0; padding: 0 0 0 12px; display: grid; gap: 2px; }
.presence li { color: var(--text); }

/* Countdown ring */
.countdown { position: relative; display: grid; justify-items: center; margin: 4px 16px 16px; padding-bottom: 14px; border-bottom: 1px solid var(--border); }
.countdown svg { width: 132px; height: 132px; transform: rotate(-90deg); }
.countdown circle { fill: none; stroke-width: 7; }
.countdown .track { stroke: var(--border); }
.countdown .bar { stroke: var(--accent); stroke-linecap: round; transition: stroke-dasharray 1s linear; }
.countdown[data-mode="wait"] .bar { stroke: #2e9d5b; }
.countdown .cd-center {
  position: absolute; top: 0; left: 0; right: 0; height: 132px;
  display: grid; place-content: center; text-align: center; line-height: 1;
}
.countdown .cd-center strong { font-size: 2rem; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.countdown .cd-center span { margin-top: 4px; font-size: 0.68rem; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.countdown .cd-label { margin: 8px 0 0; font-size: 0.8rem; color: var(--muted); text-align: center; }
/* During class: small, discreet inline ring */
.countdown[data-mode="class"] {
  grid-template-columns: 34px 1fr;
  justify-items: start;
  align-items: center;
  column-gap: 10px;
  margin-bottom: 12px;
  padding-bottom: 10px;
}
.countdown[data-mode="class"] svg { width: 34px; height: 34px; }
.countdown[data-mode="class"] circle { stroke-width: 9; }
.countdown[data-mode="class"] .bar { stroke: var(--muted); opacity: 0.7; }
.countdown[data-mode="class"] .cd-center { width: 34px; height: 34px; }
.countdown[data-mode="class"] .cd-center strong { font-size: 0.72rem; font-weight: 600; letter-spacing: 0; }
.countdown[data-mode="class"] .cd-center span { display: none; }
.countdown[data-mode="class"] .cd-label { margin: 0; text-align: left; font-size: 0.75rem; }
