/* Layout: phone-first app shell. Header and tab bar stay put, the middle scrolls.
   Each course gets one of eight colours in the order it first appears in the week.
   Fonts are system fonts (Roboto and Roboto Condensed on Android), so nothing has to download.
   Theme: follows the phone unless Settings sets data-theme="light" or "dark" on <html>. */
:root {
  --bg: #F3F5F8;
  --surface: #FFFFFF;
  --ink: #15202D;
  --muted: #5B6877;
  --line: #DDE3EA;
  --accent: #1F5FD1;
  --on-accent: #FFFFFF;
  --danger: #C92A2A;
  --warn-bg: #FFF4E0;
  --warn-ink: #7A4A00;
  --p0: #D9480F; --p1: #1C7ED6; --p2: #7048E8; --p3: #2B8A3E;
  --p4: #C2255C; --p5: #0B7285; --p6: #B07D00; --p7: #9C5B2E;
  --f-display: "sans-serif-condensed", "Roboto Condensed", "Arial Narrow", sans-serif;
  --f-body: Roboto, system-ui, -apple-system, "Segoe UI", sans-serif;
  --slot: 9px; /* one 10-minute row in the week grid */
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0E141C; --surface: #151E29; --ink: #E5EAF1; --muted: #94A2B4; --line: #253142; --accent: #79AEFF; --on-accent: #0E141C;
    --danger: #FF8787; --warn-bg: #3A2C12; --warn-ink: #FFD8A8;
    --p0: #FF8A4C; --p1: #5AAAF2; --p2: #A994FB; --p3: #5DC876;
    --p4: #F2709C; --p5: #3BC9DB; --p6: #FFC234; --p7: #D9A066;
    color-scheme: dark;
  }
}
/* Same dark values, so an explicit choice wins over the phone's setting in both directions. */
:root[data-theme="dark"] {
  --bg: #0E141C; --surface: #151E29; --ink: #E5EAF1; --muted: #94A2B4; --line: #253142; --accent: #79AEFF; --on-accent: #0E141C;
  --danger: #FF8787; --warn-bg: #3A2C12; --warn-ink: #FFD8A8;
  --p0: #FF8A4C; --p1: #5AAAF2; --p2: #A994FB; --p3: #5DC876;
  --p4: #F2709C; --p5: #3BC9DB; --p6: #FFC234; --p7: #D9A066;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  display: flex; flex-direction: column;
  background: var(--bg); color: var(--ink);
  font: 15px/1.45 var(--f-body);
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; }
button:focus-visible, a:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.k0 { --c: var(--p0); } .k1 { --c: var(--p1); } .k2 { --c: var(--p2); } .k3 { --c: var(--p3); }
.k4 { --c: var(--p4); } .k5 { --c: var(--p5); } .k6 { --c: var(--p6); } .k7 { --c: var(--p7); }

/* Header */
.app-head {
  flex: none; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.club { flex: none; display: block; border-radius: 50%; }
.club img { display: block; width: 32px; height: 32px; border-radius: 50%; }
.titles { min-width: 0; }
.app-head h1 { margin: 0; font: 700 22px/1.05 var(--f-display); letter-spacing: .01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.term { margin: 2px 0 0; font-size: 12px; line-height: 1.3; color: var(--muted); }
.icon-btn {
  flex: none; display: grid; place-items: center; width: 44px; height: 44px; margin-right: -6px;
  border: 0; border-radius: 50%; background: transparent; color: var(--muted);
}
.icon-btn:active { background: var(--bg); }

/* Scrolling middle and tab bar */
main { flex: 1; overflow-y: auto; padding: 16px 16px 28px; overscroll-behavior: contain; }
.view { display: grid; gap: 14px; align-content: start; max-width: 640px; margin: 0 auto; }
.tabs { flex: none; display: grid; grid-template-columns: repeat(4, 1fr); background: var(--surface); border-top: 1px solid var(--line); }
.tabs button { position: relative; min-height: 56px; border: 0; background: transparent; font-size: 13.5px; font-weight: 600; color: var(--muted); }
.tabs button[aria-selected="true"] { color: var(--accent); }
.tabs button[aria-selected="true"]::before {
  content: ""; position: absolute; top: 0; left: 28%; right: 28%; height: 3px; border-radius: 0 0 3px 3px; background: var(--accent);
}

/* Buttons */
.btn { min-height: 46px; padding: 0 18px; border: 1px solid transparent; border-radius: var(--radius); font-weight: 600; }
.btn.primary { background: var(--accent); color: var(--on-accent); }
.btn.ghost { background: transparent; border-color: var(--line); }
.btn.danger { background: transparent; color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
.btn.wide { width: 100%; }
.link-btn { flex: none; min-height: 36px; padding: 0 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); font-size: 13px; font-weight: 600; color: var(--accent); }

/* Shared pieces */
.code {
  font-family: var(--f-display); font-weight: 700; font-size: 18px; line-height: 1.05; letter-spacing: .01em;
  color: color-mix(in srgb, var(--c, var(--ink)) 78%, var(--ink));
}
.tag {
  padding: 2px 5px; border-radius: 4px;
  font-size: 10px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
  color: color-mix(in srgb, var(--c) 78%, var(--ink));
  background: color-mix(in srgb, var(--c) 16%, var(--surface));
}
.top { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; }
.hint { margin: 0; font-size: 13px; color: var(--muted); }
.muted { color: var(--muted); }
.sw { flex: none; width: 10px; height: 10px; border-radius: 3px; background: var(--c); }
.lbl-sm { margin: 4px 0 0; font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }

/* Today: first-run card */
.empty-card { display: grid; gap: 10px; padding: 20px 18px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); }
.empty-card h2 { margin: 0; font: 700 24px/1.1 var(--f-display); }
.empty-card p { margin: 0; color: var(--muted); }
.empty-card .btn { justify-self: start; }

/* Today: status card */
.status {
  display: grid; gap: 2px; padding: 14px 16px; border-radius: var(--radius); background: var(--surface);
  border: 1px solid color-mix(in srgb, var(--c, var(--line)) 45%, var(--line));
}
.status .lbl { font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--accent); }
.status .top .code { font-size: 26px; }
.status .name { font-weight: 600; }
.status .sub { font-size: 13.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.bar { height: 6px; margin-top: 8px; border-radius: 3px; overflow: hidden; background: color-mix(in srgb, var(--c) 18%, var(--surface)); }
.bar i { display: block; height: 100%; border-radius: 3px; background: var(--c); }

/* Today: day chips */
.chips { display: grid; gap: 6px; }
.chip {
  display: grid; justify-items: center; align-content: center; gap: 6px; min-height: 54px; padding: 8px 0;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface);
  font-size: 13.5px; font-weight: 600;
}
.chip.is-today { border-color: var(--accent); color: var(--accent); }
.chip[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--surface); }
.dots { display: flex; flex-wrap: wrap; justify-content: center; gap: 3px; min-height: 6px; padding: 0 4px; }
.dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--c); }

/* Today: timeline */
.day-title { margin: 4px 0 0; display: flex; align-items: baseline; gap: 10px; font: 700 22px/1 var(--f-display); }
.day-title span { font: 400 13px var(--f-body); color: var(--muted); font-variant-numeric: tabular-nums; }
.timeline { margin: 0; padding: 0; list-style: none; display: grid; gap: 8px; }
.item { display: grid; grid-template-columns: 3.2rem minmax(0, 1fr); gap: 10px; align-items: start; }
.item .time { display: grid; padding-top: 10px; font-size: 13px; line-height: 1.3; color: var(--muted); font-variant-numeric: tabular-nums; }
.item .time b { font-weight: 600; color: var(--ink); }
.card {
  display: grid; gap: 2px; width: 100%; min-width: 0; padding: 10px 12px; text-align: left; text-decoration: none;
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--c) 12%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--c) 35%, transparent);
}
.item.alt .card {
  background: repeating-linear-gradient(135deg, color-mix(in srgb, var(--c) 12%, var(--surface)) 0 4px, var(--surface) 4px 10px);
  border-color: color-mix(in srgb, var(--c) 60%, transparent);
}
.item.live .card { box-shadow: 0 0 0 2px var(--c); }
.item.past { opacity: .5; }
.card .nm { font-size: 14.5px; font-weight: 600; }
.card .meta { font-size: 13px; color: var(--muted); }
.gap { padding-left: calc(3.2rem + 10px); }
.gap span { display: block; padding: 4px 12px; font-size: 12.5px; color: var(--muted); border-left: 2px dotted var(--line); }
.empty { padding: 18px; text-align: center; color: var(--muted); border: 1px dashed var(--line); border-radius: var(--radius); list-style: none; }

/* Week grid */
.summary { margin: 0; font-size: 13.5px; color: var(--muted); }
.week {
  --rows: 60;
  display: grid; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
}
.dh { padding: 9px 0 8px; text-align: center; font: 700 15px/1 var(--f-display); border-left: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.dh.is-today { color: var(--accent); }
.corner { border-bottom: 1px solid var(--line); }
.times, .col { position: relative; height: calc(var(--slot) * var(--rows)); margin-block: 8px; }
.hr { position: absolute; right: 4px; transform: translateY(-50%); font-size: 10px; color: var(--muted); font-variant-numeric: tabular-nums; }
.col {
  border-left: 1px solid var(--line);
  background-image: repeating-linear-gradient(to bottom, var(--line) 0 1px, transparent 1px calc(var(--slot) * 6));
}
.col.is-today { background-color: color-mix(in srgb, var(--accent) 6%, transparent); }
.col .free { position: absolute; inset: 0; display: grid; place-items: center; font-size: 12px; color: var(--muted); }
.blk {
  position: absolute; left: 2px; right: 2px; display: flex; flex-direction: column; gap: 1px;
  padding: 3px 4px; overflow: hidden; text-align: left; text-decoration: none; border-radius: 6px;
  background: color-mix(in srgb, var(--c) 14%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--c) 40%, transparent);
}
.blk.alt {
  background: repeating-linear-gradient(135deg, color-mix(in srgb, var(--c) 14%, var(--surface)) 0 3px, var(--surface) 3px 7px);
  border-color: color-mix(in srgb, var(--c) 65%, transparent);
}
.blk .code { font-size: 12px; letter-spacing: 0; white-space: nowrap; }
.blk .room { font-size: 10px; line-height: 1.2; color: var(--muted); }
.now { position: absolute; left: 0; right: 0; height: 2px; background: var(--accent); z-index: 2; pointer-events: none; }

/* Courses */
.courses { margin: 0; padding: 0; list-style: none; display: grid; gap: 12px; }
.course { display: grid; gap: 10px; padding: 14px 16px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); }
.ch { display: flex; align-items: center; gap: 8px; }
.ects { font-size: 12px; color: var(--muted); }
.ext { margin-left: auto; font-size: 13px; font-weight: 600; color: var(--accent); text-decoration: none; }
.ext.muted { color: var(--muted); font-weight: 400; }
.course h3 { margin: -4px 0 0; font-size: 16px; line-height: 1.3; }
.unit { margin: -8px 0 0; font-size: 12.5px; color: var(--muted); }
.entries { margin: 0; padding: 0; list-style: none; display: grid; gap: 6px; }
.entry { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 6px 0 6px 10px; border-left: 3px solid var(--c); font-size: 14px; font-variant-numeric: tabular-nums; }
.people { margin: 0; padding: 0; list-style: none; display: grid; gap: 10px; }
.people li { display: grid; gap: 1px; min-width: 0; }
.pn { font-size: 14.5px; font-weight: 600; }
.pr { font-size: 13px; color: var(--muted); }
.pd { font-size: 13px; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.pd a { color: var(--accent); text-decoration: none; }
.source { margin: 0; font-size: 12px; color: var(--muted); }

/* Sheets: class editor and settings */
.sheet {
  width: 100%; max-width: min(100%, 560px); max-height: 92%; margin: auto auto 0; padding: 0;
  border: 0; border-radius: 16px 16px 0 0; background: var(--surface); color: var(--ink);
}
.sheet::backdrop { background: rgba(10, 16, 24, .45); }
.sheet-body { display: grid; gap: 12px; padding: 20px 16px 16px; }
.sheet-body h2 { margin: 0; font: 700 22px/1.1 var(--f-display); }
.field { display: grid; gap: 6px; min-width: 0; font-size: 13px; font-weight: 600; color: var(--muted); }
.field input, .field select {
  width: 100%; min-height: 46px; padding: 0 12px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--bg); font-size: 16px; font-weight: 400; color: var(--ink);
}

/* Settings */
.set-group { display: grid; gap: 10px; padding-top: 12px; border-top: 1px solid var(--line); }
.set-group h3 { margin: 0; font: 700 18px/1.1 var(--f-display); }
.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 44px; }
.toggle-row label { font-size: 15px; font-weight: 600; }
.field.sub { grid-template-columns: minmax(0, 1fr) 9rem; align-items: center; padding-left: 12px; border-left: 2px solid var(--line); }
.field.sub.off { opacity: .45; }
.switch {
  flex: none; appearance: none; -webkit-appearance: none; position: relative; width: 48px; height: 28px; margin: 0;
  border-radius: 999px; background: var(--line); cursor: pointer; transition: background .15s ease;
}
.switch::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%;
  background: var(--surface); box-shadow: 0 1px 2px rgba(0, 0, 0, .25); transition: transform .15s ease;
}
.switch:checked { background: var(--accent); }
.switch:checked::after { transform: translateX(20px); }
.switch:disabled { opacity: .45; cursor: default; }
#permNote { display: grid; gap: 8px; justify-items: start; }
#notifyNote a { color: var(--accent); font-weight: 600; }
#fCode { text-transform: uppercase; font-family: var(--f-display); font-weight: 700; font-size: 20px; letter-spacing: .02em; }
.row2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
.course-name { margin: -4px 0 0; font-size: 14px; font-weight: 600; }
.suggest { margin: -6px 0 0; padding: 4px; list-style: none; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.suggest button { display: block; width: 100%; padding: 10px; border: 0; border-radius: 6px; background: transparent; text-align: left; font-size: 14px; }
.suggest button:active { background: var(--bg); }
.suggest b { font-family: var(--f-display); margin-right: 6px; }
.sections { display: grid; gap: 6px; max-height: 210px; overflow-y: auto; }
.sec-btn {
  min-height: 42px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg);
  text-align: left; font-size: 13.5px; font-weight: 400; color: var(--ink); font-variant-numeric: tabular-nums;
}
.sec-btn[aria-pressed="true"] { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.seg { display: flex; gap: 4px; padding: 3px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); }
.seg button { flex: 1; min-width: 0; min-height: 40px; padding: 0 4px; border: 0; border-radius: 7px; background: transparent; font-size: 13.5px; font-weight: 600; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0, 0, 0, .12); }
.warn, .error { margin: 0; padding: 10px 12px; border-radius: 8px; font-size: 13.5px; }
.warn { background: var(--warn-bg); color: var(--warn-ink); }
.error { background: color-mix(in srgb, var(--danger) 12%, var(--surface)); color: var(--danger); }
.actions { display: flex; gap: 8px; padding-top: 4px; }
.actions .primary { flex: 1; }

/* Quizzes */
.quiz-head { display: grid; gap: 10px; }
.quiz-head h2 { margin: 0; font: 700 22px/1.1 var(--f-display); }
.quiz-list { display: grid; gap: 14px; }
.quiz-day { display: grid; gap: 6px; }
.quiz-day h3 { margin: 0; display: flex; align-items: baseline; gap: 8px; font: 700 17px/1.1 var(--f-display); }
.quiz-day h3 span { font: 400 12.5px var(--f-body); color: var(--muted); }
.quiz {
  display: grid; grid-template-columns: 3.2rem minmax(0, 1fr); gap: 10px; align-items: start;
  padding: 10px 12px; border-radius: var(--radius); background: var(--surface);
  border: 1px solid color-mix(in srgb, var(--c, var(--line)) 45%, var(--line));
}
.quiz.scored { grid-template-columns: 4.6rem minmax(0, 1fr); }
.score { display: grid; gap: 4px; }
.score input {
  width: 100%; min-width: 0; min-height: 38px; padding: 0 4px; text-align: center;
  border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--ink);
  font: 700 17px var(--f-body); font-variant-numeric: tabular-nums;
}
.score-max { display: flex; align-items: center; gap: 4px; font-size: 12px; color: var(--muted); }
.score-max input { min-height: 30px; font-size: 14px; font-weight: 500; }
.quiz-day.past h3 { color: var(--muted); }
.quiz .when { font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; padding-top: 2px; }
.quiz .when.muted { font-weight: 400; }
.quiz .what { display: grid; gap: 2px; min-width: 0; }
.quiz .nm { font-size: 14px; font-weight: 600; }
.quiz .meta { font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.quiz-soon {
  display: grid; gap: 4px; width: 100%; padding: 12px 14px; text-align: left;
  border: 1px solid color-mix(in srgb, var(--accent) 35%, var(--line)); border-radius: var(--radius);
  background: color-mix(in srgb, var(--accent) 7%, var(--surface));
}
.quiz-soon .lbl { font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--accent); }
.quiz-soon .row { font-size: 14px; font-variant-numeric: tabular-nums; }
.quiz-soon .row b { font-family: var(--f-display); font-size: 15px; }
.quiz-soon .more { font-size: 13px; font-weight: 600; color: var(--accent); }
textarea {
  width: 100%; min-height: 64px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--bg); font: 400 16px/1.4 var(--f-body); color: var(--ink); resize: vertical;
}
.field small.hint { font-weight: 400; }
.hp { position: absolute; left: -9999px; width: 1px; height: 1px; opacity: 0; }
.toast {
  position: fixed; left: 16px; right: 16px; bottom: 72px; z-index: 20; max-width: 528px; margin: 0 auto;
  padding: 12px 14px; border-radius: var(--radius); background: var(--ink); color: var(--surface);
  font-size: 14px; box-shadow: 0 6px 24px rgba(0, 0, 0, .25);
}

/* Narrow phones: room for the club logo, the title and the settings button. */
@media (max-width: 400px) {
  .app-head { padding-left: 12px; padding-right: 12px; gap: 8px; }
  .app-head h1 { font-size: 20px; }
}

@media (prefers-reduced-motion: no-preference) {
  .card, .chip, .blk { transition: transform .12s ease; }
  .card:active, .chip:active, .blk:active { transform: scale(.98); }
}
