/* Study site: one stylesheet. Light + dark via [data-theme] (auto follows the device). */
:root {
  --bg: #f6f7f9; --surface: #ffffff; --surface-2: #f0f2f5; --border: #e1e5ea;
  --text: #1c2430; --muted: #5d6b7a; --faint: #8a96a3;
  --accent: #0f766e; --accent-soft: #d5f0ec; --accent-text: #ffffff;
  --done: #15803d; --done-soft: #dcf5e3; --doing: #b45309; --doing-soft: #fdf0d9;
  --danger: #b91c1c; --danger-soft: #fde2e2; --info-soft: #e0ecfb; --info: #1d4ed8;
  --hint: #fde68a; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  --radius: 12px; --nav-h: 64px; --side-w: 232px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] {
    --bg: #0f1419; --surface: #171d24; --surface-2: #1e252e; --border: #2a333e;
    --text: #e6eaef; --muted: #9aa6b2; --faint: #6f7b88;
    --accent: #2dd4bf; --accent-soft: #123b37; --accent-text: #06201d;
    --done: #4ade80; --done-soft: #12301d; --doing: #fbbf24; --doing-soft: #33270d;
    --danger: #f87171; --danger-soft: #3a1717; --info-soft: #172b45; --info: #93c5fd;
    --hint: #7c5f10; --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1419; --surface: #171d24; --surface-2: #1e252e; --border: #2a333e;
  --text: #e6eaef; --muted: #9aa6b2; --faint: #6f7b88;
  --accent: #2dd4bf; --accent-soft: #123b37; --accent-text: #06201d;
  --done: #4ade80; --done-soft: #12301d; --doing: #fbbf24; --doing-soft: #33270d;
  --danger: #f87171; --danger-soft: #3a1717; --info-soft: #172b45; --info: #93c5fd;
  --hint: #7c5f10; --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0 0 .25rem; line-height: 1.25; }
h2 { font-size: 1.1rem; margin: 1.5rem 0 .6rem; }
h3 { font-size: 1rem; margin: 1rem 0 .4rem; }
p { margin: .4rem 0; }
.muted { color: var(--muted); }
.faint { color: var(--faint); font-size: .875rem; }
.small { font-size: .875rem; }
.nowrap { white-space: nowrap; }
.right { margin-left: auto; }
.row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.stack > * + * { margin-top: .75rem; }
.grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.hidden { display: none !important; }
code { background: var(--surface-2); padding: .1em .35em; border-radius: 5px; font-size: .9em; }

/* ---------- layout ---------- */
.sidebar { display: none; }
.main { padding: 1rem 1rem calc(var(--nav-h) + 1.5rem + env(safe-area-inset-bottom)); max-width: 1100px; margin: 0 auto; }
.main.bare { padding-bottom: 2rem; }
.bottomnav {
  position: fixed; inset: auto 0 0 0; z-index: 20; display: flex; justify-content: space-around;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--border);
}
.bottomnav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); font-size: .72rem; min-height: 44px;
}
.bottomnav a.active, .sidebar a.active { color: var(--accent); }
.bottomnav a:hover { text-decoration: none; }
.icon { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

@media (min-width: 900px) {
  .bottomnav { display: none; }
  .sidebar {
    display: flex; flex-direction: column; position: fixed; inset: 0 auto 0 0; width: var(--side-w);
    background: var(--surface); border-right: 1px solid var(--border); padding: 1.25rem .75rem; gap: .15rem; overflow-y: auto;
  }
  .sidebar .brand { font-weight: 700; font-size: 1.05rem; padding: .25rem .75rem 1rem; color: var(--text); }
  .sidebar a { display: flex; gap: .65rem; align-items: center; padding: .55rem .75rem; border-radius: 9px; color: var(--text); }
  .sidebar a:hover { background: var(--surface-2); text-decoration: none; }
  .sidebar a.active { background: var(--accent-soft); }
  .sidebar .section { margin: 1rem .75rem .25rem; font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--faint); }
  .sidebar .bottom { margin-top: auto; }
  .with-nav .main { margin-left: var(--side-w); padding: 2rem 2.5rem 3rem; max-width: calc(1100px + var(--side-w)); }
}

/* ---------- components ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.1rem; box-shadow: var(--shadow); }
.card h2:first-child, .card h3:first-child { margin-top: 0; }
.card + .card { margin-top: 1rem; }
.page-head { display: flex; gap: .75rem; align-items: flex-start; justify-content: space-between; flex-wrap: wrap; margin-bottom: 1rem; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem; min-height: 44px; padding: .5rem 1rem;
  border-radius: 10px; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; cursor: pointer; text-decoration: none !important;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.05); }
.btn.danger { color: var(--danger); }
.btn.small { min-height: 36px; padding: .3rem .75rem; font-size: .875rem; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.linkbtn { background: none; border: 0; padding: 0; color: var(--accent); font: inherit; cursor: pointer; }

input[type=text], input[type=password], input[type=number], select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: .6rem .75rem; min-height: 44px; width: 100%;
}
textarea { min-height: 120px; resize: vertical; }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label { display: block; font-weight: 600; font-size: .9rem; margin: .75rem 0 .3rem; }
.check { display: flex; gap: .5rem; align-items: center; font-weight: 400; margin: .35rem 0; min-height: 32px; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }
.chips-input { display: flex; flex-wrap: wrap; gap: .4rem; }
.chips-input label { margin: 0; }
.chips-input input { position: absolute; opacity: 0; pointer-events: none; }
.chips-input span {
  display: inline-block; padding: .4rem .8rem; border-radius: 999px; border: 1px solid var(--border);
  font-weight: 500; font-size: .875rem; cursor: pointer; min-height: 36px; line-height: 1.6;
}
.chips-input input:checked + span { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.chips-input input:focus-visible + span { outline: 2px solid var(--accent); }

.tabs { display: flex; gap: .25rem; overflow-x: auto; border-bottom: 1px solid var(--border); margin: 0 -1rem 1rem; padding: 0 1rem; scrollbar-width: none; }
.tabs a { padding: .6rem .8rem; white-space: nowrap; color: var(--muted); border-bottom: 2px solid transparent; font-weight: 500; }
.tabs a.active { color: var(--accent); border-color: var(--accent); }
.tabs a:hover { text-decoration: none; color: var(--text); }

.chip { display: inline-flex; align-items: center; gap: .3rem; padding: .1rem .55rem; border-radius: 999px; font-size: .78rem; font-weight: 600; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.chip.done { background: var(--done-soft); color: var(--done); }
.chip.in_progress { background: var(--doing-soft); color: var(--doing); }
.chip.accent { background: var(--accent-soft); color: var(--accent); }
.chip.danger { background: var(--danger-soft); color: var(--danger); }
.chip.info { background: var(--info-soft); color: var(--info); }

.list { list-style: none; margin: 0; padding: 0; }
.list > li { display: flex; gap: .75rem; align-items: center; padding: .7rem 0; border-top: 1px solid var(--border); flex-wrap: wrap; }
.list > li:first-child { border-top: 0; }
.list .title { flex: 1 1 220px; min-width: 0; }
.list .title a { font-weight: 600; color: var(--text); }
.list .title .faint { display: block; }
.status-select { width: auto; min-height: 36px; padding: .25rem .5rem; font-size: .85rem; border-radius: 8px; }
.status-select[data-status=done] { color: var(--done); border-color: var(--done); }
.status-select[data-status=in_progress] { color: var(--doing); border-color: var(--doing); }

.bar { height: 10px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--accent); border-radius: inherit; }
.progress-row { display: grid; grid-template-columns: 90px 1fr 48px; gap: .6rem; align-items: center; margin: .4rem 0; font-size: .9rem; }

.stat { font-size: 2rem; font-weight: 700; line-height: 1.1; }
.countdown { display: flex; align-items: baseline; gap: .5rem; flex-wrap: wrap; }
.countdown .stat { color: var(--accent); }

.empty { text-align: center; color: var(--muted); padding: 1.5rem 1rem; }
.empty strong { display: block; color: var(--text); margin-bottom: .25rem; }

.markdown table { border-collapse: collapse; width: 100%; font-size: .9rem; display: block; overflow-x: auto; }
.markdown th, .markdown td { border: 1px solid var(--border); padding: .4rem .55rem; text-align: left; vertical-align: top; }
.markdown th { background: var(--surface-2); }
.markdown h1 { font-size: 1.35rem; } .markdown h2 { font-size: 1.1rem; }
.markdown blockquote { margin: .5rem 0; padding: .25rem .9rem; border-left: 3px solid var(--accent); color: var(--muted); }

.alert { padding: .75rem 1rem; border-radius: 10px; margin: .75rem 0; }
.alert.error { background: var(--danger-soft); color: var(--danger); }
.alert.warning { background: var(--doing-soft); color: var(--doing); }
.alert.info { background: var(--info-soft); color: var(--info); }
.alert ul { margin: 0; padding-left: 1.2rem; }

/* toasts */
.toasts { position: fixed; z-index: 50; left: 50%; transform: translateX(-50%); bottom: calc(var(--nav-h) + 1rem + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: .5rem; width: min(92vw, 420px); pointer-events: none; }
@media (min-width: 900px) { .toasts { bottom: 1.5rem; left: auto; right: 1.5rem; transform: none; } }
.toast { pointer-events: auto; background: var(--text); color: var(--bg); padding: .75rem 1rem; border-radius: 10px; box-shadow: 0 6px 24px rgba(0,0,0,.2); font-size: .92rem; transition: opacity .3s, transform .3s; }
.toast.success { border-left: 4px solid var(--done); }
.toast.error { border-left: 4px solid var(--danger); }
.toast.warning { border-left: 4px solid var(--doing); }
.toast.hide { opacity: 0; transform: translateY(8px); }

/* login */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem; }
.auth-card { width: min(100%, 400px); }
.auth-card h1 { margin-bottom: .75rem; }

/* schedule */
.day { margin-bottom: 1rem; }
.day h3 { margin: 0 0 .5rem; font-size: .95rem; color: var(--muted); }
.day.today h3 { color: var(--accent); }
.session { display: grid; grid-template-columns: 92px 1fr; gap: .75rem; padding: .6rem 0; border-top: 1px solid var(--border); }
.session:first-of-type { border-top: 0; }
.session .time { font-variant-numeric: tabular-nums; color: var(--muted); font-size: .9rem; }
.session .what { font-weight: 600; }
.session.duty { background: var(--accent-soft); border-radius: 8px; padding: .6rem .5rem; border-top: 0; margin: .25rem 0; }

/* viewer */
.viewer-head { position: sticky; top: 0; z-index: 10; background: var(--bg); padding: .5rem 0; display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.viewer-head .title { font-weight: 700; flex: 1 1 200px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pdf-pages { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 10px 0 30px; background: var(--surface-2); border-radius: var(--radius); min-height: 60vh; }
.pdf-page { background: #fff; box-shadow: 0 1px 4px rgba(0,0,0,.18); max-width: 100%; position: relative; }
.pdf-page canvas { display: block; width: 100%; height: auto; }
.pdf-page .num { position: absolute; right: 6px; bottom: 4px; font-size: .7rem; color: #888; }
.pdf-toolbar { display: flex; gap: .4rem; align-items: center; }
.pdf-toolbar input { width: 70px; min-height: 36px; padding: .25rem .4rem; text-align: center; }
.panel { margin-bottom: 1rem; }
.conf { display: inline-flex; gap: .25rem; }
.conf button { min-width: 40px; }
.conf button.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.img-view { max-width: 100%; border-radius: var(--radius); }
details.panel > summary { cursor: pointer; font-weight: 600; min-height: 44px; display: flex; align-items: center; }

/* quiz */
.q-stem { font-size: 1.08rem; line-height: 1.6; margin: .5rem 0 1rem; }
mark.hint { background: transparent; color: inherit; transition: background .2s; border-radius: 3px; padding: 0 .1em; }
.show-hints mark.hint { background: var(--hint); }
.options { display: flex; flex-direction: column; gap: .6rem; }
.option { display: flex; gap: .75rem; align-items: flex-start; padding: .8rem 1rem; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); cursor: pointer; min-height: 52px; }
.option input { margin-top: .25rem; width: 20px; height: 20px; accent-color: var(--accent); flex: none; }
.option .letter { font-weight: 700; color: var(--muted); }
.option:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.option.correct { border-color: var(--done); background: var(--done-soft); }
.option.wrong { border-color: var(--danger); background: var(--danger-soft); }
.option .why { display: block; font-size: .9rem; margin-top: .35rem; color: var(--text); }
.option.static { cursor: default; flex-direction: column; gap: .2rem; }
.q-nav { display: flex; flex-wrap: wrap; gap: .35rem; }
.q-nav a { width: 38px; height: 38px; display: grid; place-items: center; border: 1px solid var(--border); border-radius: 8px; color: var(--text); font-size: .85rem; }
.q-nav a.answered { background: var(--accent-soft); border-color: var(--accent); }
.q-nav a.current { outline: 2px solid var(--accent); }
.timer { font-variant-numeric: tabular-nums; font-weight: 700; }
.timer.low { color: var(--danger); }
.score-big { font-size: 3rem; font-weight: 800; color: var(--accent); }
.meta-tags { display: flex; gap: .35rem; flex-wrap: wrap; margin: .25rem 0; }

/* refresh */
.change { display: flex; gap: .6rem; align-items: flex-start; padding: .6rem 0; border-top: 1px solid var(--border); }
.change:first-child { border-top: 0; }
.change input { margin-top: .2rem; width: 20px; height: 20px; flex: none; accent-color: var(--accent); }
.change .reason { display: block; font-size: .82rem; color: var(--faint); }
.spinner { width: 22px; height: 22px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 1s linear infinite; display: inline-block; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }
pre.log { white-space: pre-wrap; font-size: .8rem; background: var(--surface-2); padding: .75rem; border-radius: 8px; max-height: 300px; overflow: auto; }

table.simple { width: 100%; border-collapse: collapse; font-size: .92rem; }
table.simple th, table.simple td { text-align: left; padding: .5rem .4rem; border-top: 1px solid var(--border); }
table.simple th { color: var(--muted); font-weight: 600; border-top: 0; }
.pdf-page { scroll-margin-top: 72px; }
.panel summary { cursor: pointer; min-height: 44px; display: flex; align-items: center; color: var(--muted); }

.sticky-actions { position: sticky; bottom: calc(var(--nav-h) + .5rem + env(safe-area-inset-bottom)); background: var(--bg); padding: .5rem 0; z-index: 5; }
@media (min-width: 900px) { .sticky-actions { bottom: 0; } }
.progress-label { margin: .25rem 0 0; font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--faint); font-weight: 600; }
