:root {
  --navy: #0A1628; --gold: #C9A84C; --red: #C0392B;
  --bg: var(--tg-theme-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #1a1a1a);
  --hint: var(--tg-theme-hint-color, #7a7f87);
  --link: var(--tg-theme-link-color, #1f6feb);
  --btn: var(--tg-theme-button-color, #0A1628);
  --btn-text: var(--tg-theme-button-text-color, #ffffff);
  --sec: var(--tg-theme-secondary-bg-color, #f2f3f5);
  --line: color-mix(in srgb, var(--text) 14%, transparent);
  --radius: 12px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.4 -apple-system, system-ui, "Segoe UI", Roboto, sans-serif; }
body { padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
a { color: var(--link); }
header#top { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px;
  background: var(--navy); color: #fff; position: sticky; top: 0; z-index: 5; }
header#top a { color: var(--gold); font-weight: 700; text-decoration: none; letter-spacing: .3px; }
#topright { display: flex; gap: 8px; align-items: center; }
main { padding: 12px 12px 24px; max-width: 760px; margin: 0 auto; }
nav#tabs { position: fixed; left: 0; right: 0; bottom: 0; display: flex; background: var(--bg);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); z-index: 5; }
nav#tabs a { flex: 1; text-align: center; padding: 12px 2px; font-size: 12px; color: var(--hint); text-decoration: none; font-weight: 600; }
nav#tabs a.on { color: var(--navy); box-shadow: inset 0 3px 0 var(--gold); }
@media (prefers-color-scheme: dark) { nav#tabs a.on { color: var(--gold); } }
h2 { margin: 6px 0 10px; font-size: 18px; }
.muted { color: var(--hint); }
.card { background: var(--sec); border-radius: var(--radius); padding: 12px; margin-bottom: 12px; }
.row { display: flex; align-items: center; gap: 8px; }
.row.wrap { flex-wrap: wrap; }
.spread { justify-content: space-between; }
button, .btn { font: inherit; border: 0; border-radius: 10px; padding: 9px 14px; background: var(--btn); color: var(--btn-text); }
button.ghost { background: var(--sec); color: var(--text); border: 1px solid var(--line); }
button.danger { background: var(--red); color: #fff; }
button.small { padding: 5px 10px; font-size: 13px; }
button:disabled { opacity: .5; }
input, textarea, select { font: inherit; width: 100%; padding: 9px 10px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text); }
textarea { min-height: 120px; resize: vertical; }
label.f { display: block; margin: 10px 0 4px; font-size: 13px; color: var(--hint); }
.chip { display: inline-block; padding: 4px 10px; border-radius: 99px; background: var(--sec); border: 1px solid var(--line);
  font-size: 13px; white-space: nowrap; }
.chip.on { background: var(--navy); color: var(--gold); border-color: var(--navy); }
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 6px; scrollbar-width: none; }
.seg { display: flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { flex: 1; border-radius: 0; background: var(--bg); color: var(--text); padding: 7px 4px; }
.seg button.on { background: var(--navy); color: var(--gold); }
.fab { position: fixed; right: 16px; bottom: calc(76px + env(safe-area-inset-bottom)); width: 54px; height: 54px; border-radius: 50%;
  background: var(--gold); color: var(--navy); font-size: 28px; line-height: 1; padding: 0; box-shadow: 0 3px 10px #0004; z-index: 6; }
/* kalender */
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; gap: 6px; }
.cal-title { font-weight: 700; font-size: 16px; text-align: center; flex: 1; }
.dow, .weekrow { display: grid; grid-template-columns: repeat(7, 1fr); }
.dow div { text-align: center; font-size: 12px; color: var(--hint); padding: 4px 0; }
.dow div.red { color: var(--red); }
.weekblk { position: relative; border-top: 1px solid var(--line); }
.cell { min-height: 78px; padding: 2px 2px 2px; border-left: 1px solid var(--line); overflow: hidden; }
.cell:first-child { border-left: 0; }
.cell.out { opacity: .4; }
.cell.today .dn { background: var(--navy); color: var(--gold); border-radius: 50%; }
.dn { display: inline-block; min-width: 20px; height: 20px; text-align: center; font-size: 12px; line-height: 20px; }
.dn.red { color: var(--red); font-weight: 700; }
.cell.today .dn.red { color: #ff8a7a; }
.hol { font-size: 9px; color: var(--red); line-height: 1.1; display: block; overflow: hidden; max-height: 20px; }
.ev { display: block; font-size: 10px; line-height: 1.25; padding: 1px 3px; margin-top: 1px; border-radius: 3px; overflow: hidden;
  white-space: nowrap; text-overflow: ellipsis; background: var(--navy); color: #fff; }
.ev.rem { background: var(--gold); color: #1a1a1a; }
.more { font-size: 9px; color: var(--hint); }
.banners { position: absolute; left: 0; right: 0; top: 22px; display: grid; grid-template-columns: repeat(7, 1fr); pointer-events: none; }
.banner { font-size: 10px; background: var(--navy); color: #fff; margin: 1px 1px; padding: 1px 4px; border-radius: 4px; height: 15px;
  overflow: hidden; white-space: nowrap; text-overflow: ellipsis; pointer-events: auto; }
.dayblk { border-bottom: 1px solid var(--line); padding: 8px 2px; }
.dayblk h3 { margin: 0 0 4px; font-size: 14px; }
.dayblk h3.red { color: var(--red); }
.item { display: flex; gap: 8px; align-items: flex-start; padding: 8px 10px; border-radius: 10px; margin: 4px 0;
  background: var(--navy); color: #fff; }
.item.rem { background: var(--gold); color: #1a1a1a; }
.item .t { font-variant-numeric: tabular-nums; min-width: 44px; font-weight: 600; }
.item .x { flex: 1; word-break: break-word; }
.item small { display: block; opacity: .8; }
/* notes */
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.ncard { background: var(--sec); border-radius: var(--radius); padding: 10px; overflow: hidden; }
.ncard .th { width: 100%; height: 90px; object-fit: cover; border-radius: 8px; margin-bottom: 6px; background: var(--line); display: block; }
.ncard b { display: block; word-break: break-word; }
.ncard p { margin: 4px 0; font-size: 13px; color: var(--hint); display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.ncard .chips { flex-wrap: wrap; overflow: visible; gap: 4px; }
.ncard .chip { font-size: 11px; padding: 2px 7px; }
.pre { white-space: pre-wrap; word-break: break-word; }
.thumbs { display: flex; gap: 8px; flex-wrap: wrap; }
.thumbs img { width: 96px; height: 96px; object-fit: cover; border-radius: 10px; }
/* sheet */
#sheetbg { position: fixed; inset: 0; background: #0007; z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
#sheet { background: var(--bg); width: 100%; max-width: 760px; max-height: 92vh; overflow: auto; border-radius: 16px 16px 0 0;
  padding: 16px 14px calc(18px + env(safe-area-inset-bottom)); }
#viewer { position: fixed; inset: 0; background: #000e; z-index: 30; display: flex; flex-direction: column; align-items: center; justify-content: center; }
#viewer img { max-width: 100%; max-height: 82vh; object-fit: contain; }
#toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(90px + env(safe-area-inset-bottom)); background: #000d; color: #fff;
  padding: 8px 14px; border-radius: 99px; z-index: 40; max-width: 90%; }
.err { color: var(--red); }
/* scholar & appraisal */
.subtabs { display: flex; gap: 6px; margin-bottom: 10px; }
.subtabs a { flex: 1; text-align: center; padding: 8px; border-radius: 10px; background: var(--sec); color: var(--text); text-decoration: none; font-weight: 600; }
.subtabs a.on { background: var(--navy); color: var(--gold); }
.prog { display: flex; gap: 3px; margin: 8px 0 2px; }
.prog i { flex: 1; height: 7px; border-radius: 4px; background: var(--line); }
.prog i.done { background: var(--navy); }
.prog i.act { background: var(--gold); }
.prog i.err { background: var(--red); }
.proglbl { display: flex; justify-content: space-between; font-size: 10px; color: var(--hint); }
.badge { display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 99px; background: var(--gold); color: #1a1a1a; }
.badge.red { background: var(--red); color: #fff; }
.badge.good { background: #2e8b57; color: #fff; }
.badge.mid { background: var(--gold); color: #1a1a1a; }
.badge.bad { background: var(--red); color: #fff; }
.badge.grey { background: var(--line); color: var(--text); }
.btnrow { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
table.t { width: 100%; border-collapse: collapse; font-size: 12px; }
table.t th, table.t td { border: 1px solid var(--line); padding: 4px 6px; text-align: left; vertical-align: top; }
.scroll-x { overflow-x: auto; }
.toc { position: sticky; top: 44px; background: var(--bg); padding: 6px 0; z-index: 4; display: flex; gap: 6px; overflow-x: auto; border-bottom: 1px solid var(--line); }
.cite { color: var(--link); cursor: pointer; font-weight: 700; }
.pbox { border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; margin: 6px 0; background: var(--sec); }
.pbox.off { opacity: .55; }
