:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #1b1f24;
  --muted: #5d6673;
  --line: #e2e5ea;
  --accent: #1f5f6b;
  --accent-text: #ffffff;
  --red: #c62f2f;
  --red-bg: #fdeeee;
  --amber: #b86e00;
  --amber-bg: #fff5e3;
  --grey: #8a929d;
  --green: #2c7a3f;
  --green-bg: #eaf6ed;
  --radius: 10px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121418;
    --surface: #1b1e24;
    --text: #e7e9ec;
    --muted: #9aa3ae;
    --line: #2c3038;
    --accent: #5fb3c1;
    --accent-text: #0d1114;
    --red: #ff7676;
    --red-bg: #3a1d1f;
    --amber: #f0b44d;
    --amber-bg: #372a14;
    --grey: #7d8590;
    --green: #6fcf86;
    --green-bg: #17301e;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); }
h1 { font-size: 1.5rem; margin: 0 0 .25rem; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
h3 { font-size: 1rem; margin: 0; }
p { margin: .25rem 0 .75rem; }
.muted { color: var(--muted); }
.spaced { margin-top: 1rem; }
details form { margin-top: .75rem; }
.small { font-size: .85rem; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: .5rem;
  padding: .75rem 16px; background: var(--surface); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.brand { font-weight: 700; font-size: 1.15rem; text-decoration: none; color: var(--text); }
nav { display: flex; gap: .25rem; align-items: center; flex-wrap: wrap; }
nav a { padding: .35rem .65rem; border-radius: 6px; text-decoration: none; color: var(--muted); }
nav a.active { background: var(--bg); color: var(--text); font-weight: 600; }

main { max-width: 880px; margin: 0 auto; padding: 1.25rem 16px 4rem; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1rem; margin-bottom: 1rem;
}
.row { display: flex; gap: .5rem; flex-wrap: wrap; align-items: end; }
.row > * { flex: 1 1 160px; }
.row > .grow { flex: 3 1 240px; }
.row > .shrink { flex: 0 0 auto; }
.head { display: flex; justify-content: space-between; align-items: start; gap: .75rem; flex-wrap: wrap; }

label { display: block; font-size: .85rem; color: var(--muted); }
label.inline { display: flex; align-items: center; gap: .4rem; color: var(--text); font-size: .9rem; }
input, textarea, select {
  width: 100%; font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--line); border-radius: 7px; padding: .45rem .6rem; margin-top: .2rem;
}
input[type=checkbox], input[type=radio] { width: auto; margin: 0; }
textarea { min-height: 4.5rem; resize: vertical; }
input:focus, textarea:focus, select:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

button {
  font: inherit; cursor: pointer; border-radius: 7px; padding: .45rem .9rem;
  border: 1px solid var(--accent); background: var(--accent); color: var(--accent-text); font-weight: 600;
}
button.secondary { background: transparent; color: var(--accent); }
button.danger { background: transparent; color: var(--red); border-color: transparent; font-weight: 500; padding: .3rem .5rem; }
button.link { background: none; border: none; color: var(--muted); padding: .35rem .65rem; font-weight: 400; }
button:disabled { opacity: .5; cursor: default; }

/* Board */
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: .5rem; flex-wrap: wrap; margin-bottom: .75rem; }
.list { display: flex; flex-direction: column; gap: .5rem; }
.item {
  display: grid; grid-template-columns: 6px 1fr auto; gap: .75rem;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .7rem .8rem .7rem 0;
  overflow: hidden;
}
.bar { border-radius: 0 4px 4px 0; background: var(--grey); }
.item.red .bar, .item.overdue .bar { background: var(--red); }
.item.amber .bar { background: var(--amber); }
.item.overdue { opacity: .7; }
.item .title { font-weight: 600; word-break: break-word; }
.item .meta { font-size: .85rem; color: var(--muted); display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.when { text-align: right; font-size: .85rem; white-space: nowrap; }
.when strong { display: block; font-size: .95rem; }
.item.red .when strong, .item.overdue .when strong { color: var(--red); }
.item.amber .when strong { color: var(--amber); }
.badge { font-size: .72rem; padding: .05rem .45rem; border-radius: 99px; border: 1px solid var(--line); color: var(--muted); }
.note { grid-column: 2 / 4; }
.note textarea { min-height: 2.5rem; font-size: .9rem; }
.note-text { white-space: pre-wrap; font-size: .9rem; background: var(--bg); border-radius: 6px; padding: .35rem .55rem; margin: .1rem 0 0; }
details > summary { cursor: pointer; color: var(--accent); font-size: .85rem; }
.empty { text-align: center; padding: 2rem 1rem; color: var(--muted); }

/* Prep */
.exam-link { display: flex; justify-content: space-between; gap: .5rem; text-decoration: none; color: var(--text); }
.topic { border-top: 1px solid var(--line); padding-top: .75rem; margin-top: .75rem; }
.topic:first-of-type { border-top: none; margin-top: 0; padding-top: 0; }
.q { margin: .4rem 0; padding: .5rem .65rem; background: var(--bg); border-radius: 7px; }
.q ol { margin: .25rem 0 0; padding-left: 1.4rem; }
.q li.correct { color: var(--green); font-weight: 600; }
.chips { display: flex; gap: .4rem; flex-wrap: wrap; }
.chip { padding: .15rem .6rem; border-radius: 99px; font-size: .85rem; border: 1px solid var(--line); }
.chip.weak { background: var(--red-bg); color: var(--red); border-color: transparent; }
.chip.strong { background: var(--green-bg); color: var(--green); border-color: transparent; }
.test-q { margin-bottom: 1rem; }
.test-q fieldset { border: 1px solid var(--line); border-radius: 8px; padding: .5rem .75rem; }
.test-q legend { font-weight: 600; padding: 0 .25rem; }
.plan { width: 100%; border-collapse: collapse; font-size: .92rem; }
.plan td, .plan th { text-align: left; padding: .4rem .5rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.plan tr.today td { background: var(--amber-bg); }
.files { list-style: none; padding: 0; margin: 0 0 .5rem; }
.files li { display: flex; justify-content: space-between; align-items: center; gap: .5rem; padding: .25rem 0; }
.pre { white-space: pre-wrap; }

.auth { max-width: 380px; margin: 2rem auto; }
.auth .tabs { display: flex; gap: .5rem; margin-bottom: 1rem; }
.auth form > * { margin-bottom: .75rem; }
.tagline { color: var(--muted); margin-bottom: 1.25rem; }
.code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 1.05rem; letter-spacing: .05em; }
span.code { font-size: .9em; letter-spacing: 0; }

#toast {
  position: fixed; left: 50%; bottom: 1.25rem; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: .55rem 1rem; border-radius: 8px;
  max-width: calc(100% - 32px); box-shadow: 0 4px 16px rgba(0,0,0,.2); z-index: 10;
}
#toast.error { background: var(--red); color: #fff; }

@media (max-width: 560px) {
  .item { grid-template-columns: 6px 1fr; }
  .when { grid-column: 2; text-align: left; }
  .when strong { display: inline; margin-right: .4rem; }
  .note { grid-column: 2; }
}
