:root {
  --bg: #f2f2f7; --card: #ffffff; --card2: #e9e9ee; --label: #000000; --label2: rgba(60,60,67,.6); --label3: rgba(60,60,67,.3);
  --sep: rgba(60,60,67,.18); --accent: #007aff; --green: #248a3d; --green-bg: #e3f5e8; --orange: #c25e00; --orange-bg: #fff1dc;
  --red: #d70015; --red-bg: #ffe5e7; --blue-bg: #e5f0ff; --bar: rgba(249,249,249,.88); --sheet-bg: #f2f2f7; --shadow: rgba(0,0,0,.35);
  --sheet-card: #ffffff; --seg-on: #ffffff; --field: #e9e9ee;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #000000; --card: #1c1c1e; --card2: #2c2c2e; --label: #ffffff; --label2: rgba(235,235,245,.6); --label3: rgba(235,235,245,.3);
    --sep: rgba(84,84,88,.6); --accent: #0a84ff; --green: #30d158; --green-bg: #0f3a1b; --orange: #ff9f0a; --orange-bg: #3d2a07;
    --red: #ff453a; --red-bg: #43120f; --blue-bg: #0b2a4d; --bar: rgba(22,22,24,.88); --sheet-bg: #1c1c1e; --shadow: rgba(0,0,0,.6);
    --sheet-card: #2c2c2e; --seg-on: #636366; --field: #3a3a3c;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--label);
  font: 17px/1.3 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased; overscroll-behavior-y: none;
  -webkit-user-select: none; user-select: none;
}
input, textarea, select, button { font: inherit; color: inherit; }
button { background: none; border: 0; padding: 0; cursor: pointer; }
textarea, input { -webkit-user-select: text; user-select: text; }

#app { min-height: 100%; }
.screen { padding: calc(env(safe-area-inset-top) + 8px) 16px calc(env(safe-area-inset-bottom) + 96px); max-width: 640px; margin: 0 auto; }

/* Kopf */
.head { display: flex; align-items: flex-end; justify-content: space-between; gap: 8px; padding: 10px 4px 8px; }
.head h1 { font-size: 34px; font-weight: 700; letter-spacing: .3px; margin: 0; line-height: 1.1; }
.head .sub { font-size: 15px; color: var(--label2); margin-top: 2px; }
.icon-btn { width: 36px; height: 36px; border-radius: 18px; display: inline-flex; align-items: center; justify-content: center; color: var(--accent); }
.icon-btn svg { width: 24px; height: 24px; }
.icon-btn.spin svg { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.navbar { display: flex; align-items: center; justify-content: space-between; height: 44px; color: var(--accent); }
.navbar button { color: var(--accent); display: inline-flex; align-items: center; gap: 2px; font-size: 17px; }
.navbar svg { width: 22px; height: 22px; }

/* Karten und Listen */
.section-title { font-size: 13px; color: var(--label2); text-transform: uppercase; letter-spacing: .2px; padding: 18px 16px 6px; }
.section-title.first { padding-top: 6px; }
.card { background: var(--card); border-radius: 12px; overflow: hidden; }
.row { display: flex; align-items: center; gap: 12px; padding: 11px 16px; min-height: 48px; position: relative; }
.row + .row::before { content: ""; position: absolute; top: 0; right: 0; left: var(--indent, 16px); border-top: .5px solid var(--sep); }
.row.tap:active { background: var(--card2); }
.row .main { flex: 1; min-width: 0; }
.row .title { font-size: 17px; overflow: hidden; text-overflow: ellipsis; }
.row .meta { font-size: 14px; color: var(--label2); margin-top: 2px; display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: center; }
.chev { color: var(--label3); width: 14px; flex-shrink: 0; }
.muted { color: var(--label2); }
.empty { text-align: center; color: var(--label2); padding: 36px 16px; font-size: 15px; line-height: 1.5; }
.empty strong { display: block; color: var(--label); font-size: 17px; font-weight: 600; margin-bottom: 4px; }
.banner { border-radius: 12px; padding: 12px 16px; font-size: 15px; margin: 4px 0 8px; background: var(--orange-bg); color: var(--orange); display: flex; gap: 10px; align-items: center; }
.banner button { margin-left: auto; font-weight: 600; color: inherit; }

/* Stundenplan */
.weeknav { display: flex; align-items: center; justify-content: space-between; padding: 0 0 8px; }
.weeknav button { color: var(--accent); width: 40px; height: 36px; display: inline-flex; align-items: center; justify-content: center; }
.weeknav button svg { width: 22px; height: 22px; }
.weeknav .label { font-size: 15px; color: var(--label2); font-weight: 500; }
.days { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; margin-bottom: 12px; }
.day { background: var(--card); border-radius: 12px; padding: 7px 0; text-align: center; }
.day .dn { font-size: 13px; color: var(--label2); }
.day .dd { font-size: 19px; font-weight: 600; }
.day.today .dd { color: var(--accent); }
.day.sel { background: var(--accent); }
.day.sel .dn, .day.sel .dd { color: #fff; }
.day .dot { width: 5px; height: 5px; border-radius: 50%; background: var(--orange); margin: 2px auto 0; visibility: hidden; }
.day .dot.on { visibility: visible; }
.day .dot.exam { background: var(--red); }
.day.sel .dot { background: #fff; }
.lesson { --indent: 76px; align-items: stretch; }
.lesson .time { width: 48px; font-size: 13px; color: var(--label2); font-variant-numeric: tabular-nums; display: flex; flex-direction: column; justify-content: space-between; padding: 2px 0; }
.lesson .stripe { width: 4px; border-radius: 2px; flex-shrink: 0; }
.lesson.now { background: var(--blue-bg); }
.lesson.cancelled .title, .lesson.cancelled .time { text-decoration: line-through; color: var(--label3); }
.lesson .abbr { font-size: 13px; color: var(--label2); font-weight: 400; margin-left: 4px; }
.gap { font-size: 12px; color: var(--label3); text-align: center; padding: 3px 0; }

/* Marken */
.tag { font-size: 12px; font-weight: 600; padding: 2px 7px; border-radius: 6px; white-space: nowrap; }
.tag.untis { background: var(--blue-bg); color: var(--accent); }
.tag.own { background: var(--card2); color: var(--label2); }
.tag.red { background: var(--red-bg); color: var(--red); }
.tag.orange { background: var(--orange-bg); color: var(--orange); }
.tag.green { background: var(--green-bg); color: var(--green); }

/* Aufgaben */
.check { width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--label3); flex-shrink: 0; display: flex; align-items: center; justify-content: center; align-self: flex-start; margin-top: 1px; }
.check.on { background: var(--accent); border-color: var(--accent); }
.check svg { width: 16px; height: 16px; color: #fff; visibility: hidden; }
.check.on svg { visibility: visible; }
.hw { --indent: 54px; align-items: flex-start; }
.hw .title { white-space: normal; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; }
.hw.done .title { color: var(--label3); text-decoration: line-through; }
.hw.gone .title { color: var(--label2); }
.overdue { color: var(--red); }
.exam { --indent: 74px; }
.count { width: 46px; height: 46px; border-radius: 10px; display: flex; flex-direction: column; align-items: center; justify-content: center; flex-shrink: 0; line-height: 1; }
.count b { font-size: 19px; font-variant-numeric: tabular-nums; }
.count span { font-size: 11px; margin-top: 2px; }
.count.c-good { background: var(--green-bg); } .count.c-mid { background: var(--orange-bg); } .count.c-bad { background: var(--red-bg); }
.count.c-none { background: var(--card2); color: var(--label2); }
.linkbtn { color: var(--accent); font-size: 15px; padding: 14px 16px; display: block; width: 100%; text-align: left; }

/* Noten */
.avg-card { display: flex; align-items: center; justify-content: space-between; padding: 16px; }
.avg-card .big { font-size: 40px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1; }
.pill { min-width: 52px; text-align: center; font-weight: 700; font-size: 16px; padding: 4px 9px; border-radius: 8px; font-variant-numeric: tabular-nums; }
.c-good { color: var(--green); } .c-mid { color: var(--orange); } .c-bad { color: var(--red); } .c-none { color: var(--label3); }
.pill.c-good { background: var(--green-bg); } .pill.c-mid { background: var(--orange-bg); } .pill.c-bad { background: var(--red-bg); } .pill.c-none { background: transparent; }
.grade-sq { width: 34px; height: 34px; border-radius: 8px; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 17px; flex-shrink: 0; }
.grade-sq.c-good { background: var(--green-bg); } .grade-sq.c-mid { background: var(--orange-bg); } .grade-sq.c-bad { background: var(--red-bg); }
.hero { text-align: center; padding: 22px 16px 18px; }
.hero .big { font-size: 56px; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; }
.hero .formula { font-size: 13px; color: var(--label2); margin-top: 10px; font-family: ui-monospace, "SF Mono", Menlo, monospace; line-height: 1.5; }
.detail-title { font-size: 34px; font-weight: 700; margin: 4px 4px 2px; }

/* Tab-Leiste */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: flex; justify-content: space-around;
  background: var(--bar); backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: .5px solid var(--sep); padding: 6px 0 calc(env(safe-area-inset-bottom) + 4px);
}
.tabbar button { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 10px; font-weight: 500; color: var(--label2); padding: 2px 0; position: relative; }
.tabbar button svg { width: 26px; height: 26px; }
.tabbar button.on { color: var(--accent); }
.tabbar .badge { position: absolute; top: -2px; left: calc(50% + 6px); background: var(--red); color: #fff; font-size: 11px; font-weight: 600; min-width: 18px; height: 18px; border-radius: 9px; display: flex; align-items: center; justify-content: center; padding: 0 5px; }

/* Blatt (Sheet) */
.overlay { position: fixed; inset: 0; z-index: 20; background: var(--shadow); opacity: 0; transition: opacity .25s; }
.overlay.open { opacity: 1; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21; max-height: 94%; overflow-y: auto; -webkit-overflow-scrolling: touch;
  background: var(--sheet-bg); border-radius: 14px 14px 0 0; padding: 8px 16px calc(env(safe-area-inset-bottom) + 20px);
  transform: translateY(100%); transition: transform .3s cubic-bezier(.2,.9,.3,1); max-width: 640px; margin: 0 auto;
}
.sheet.open { transform: none; }
.sheet .grab { width: 36px; height: 5px; border-radius: 3px; background: var(--label3); margin: 0 auto 6px; }
.sheet .bar { display: flex; align-items: center; justify-content: space-between; height: 44px; margin-bottom: 8px; }
.sheet .bar .t { font-weight: 600; }
.sheet .bar button { color: var(--accent); font-size: 17px; min-width: 70px; text-align: left; }
.sheet .bar button.save { font-weight: 600; text-align: right; }
.sheet .card { background: var(--sheet-card); margin-bottom: 16px; }
.field { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 0 16px; min-height: 48px; position: relative; }
.field + .field::before { content: ""; position: absolute; top: 0; left: 16px; right: 0; border-top: .5px solid var(--sep); }
.field label { flex-shrink: 0; }
.field select, .field input[type="date"], .field input[type="text"], .field input[type="password"] {
  border: 0; background: transparent; text-align: right; color: var(--label2); flex: 1; min-width: 0; padding: 12px 0; outline: none; -webkit-appearance: none; appearance: none;
}
.field input[type="date"] { color: var(--accent); }
.field input::placeholder { color: var(--label3); }
textarea.note { width: 100%; border: 0; background: transparent; padding: 12px 16px; min-height: 96px; resize: none; outline: none; display: block; font-size: 17px; }
.seg { display: flex; background: var(--field); border-radius: 9px; padding: 2px; margin: 12px; }
.seg button { flex: 1; padding: 7px 0; border-radius: 7px; font-size: 14px; font-weight: 500; color: var(--label); }
.seg button.on { background: var(--seg-on); box-shadow: 0 1px 3px rgba(0,0,0,.15); }
.grades6 { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; padding: 0 12px 12px; }
.grades6 button { height: 50px; border-radius: 10px; background: var(--field); font-size: 22px; font-weight: 700; }
.grades6 button.on { background: var(--accent); color: #fff; }
.hint { font-size: 13px; color: var(--label2); padding: 0 16px 16px; line-height: 1.4; }
.danger-btn { width: 100%; background: var(--card); color: var(--red); border-radius: 12px; height: 50px; font-size: 17px; }
.primary-btn { width: 100%; background: var(--accent); color: #fff; border-radius: 12px; height: 50px; font-size: 17px; font-weight: 600; }
.primary-btn:disabled { opacity: .5; }
.readonly-text { padding: 14px 16px; font-size: 17px; line-height: 1.4; white-space: pre-wrap; -webkit-user-select: text; user-select: text; }
.switch { position: relative; width: 51px; height: 31px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; background: var(--card2); border-radius: 16px; transition: background .2s; }
.switch span::after { content: ""; position: absolute; width: 27px; height: 27px; left: 2px; top: 2px; background: #fff; border-radius: 50%; box-shadow: 0 2px 4px rgba(0,0,0,.2); transition: transform .2s; }
.switch input:checked + span { background: #34c759; }
.switch input:checked + span::after { transform: translateX(20px); }

/* Anmeldung */
.login { max-width: 420px; margin: 0 auto; padding: calc(env(safe-area-inset-top) + 60px) 20px 40px; }
.login .logo { width: 84px; height: 84px; border-radius: 20px; margin: 0 auto 18px; display: block; }
.login h1 { text-align: center; font-size: 28px; margin: 0 0 6px; }
.login p { text-align: center; color: var(--label2); margin: 0 0 26px; font-size: 15px; line-height: 1.4; }
.login .card { margin-bottom: 16px; }
.login .err { color: var(--red); text-align: center; font-size: 15px; min-height: 20px; margin-bottom: 12px; }
.login .skip { display: block; margin: 16px auto 0; color: var(--accent); font-size: 15px; }

.toast { position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 76px); transform: translate(-50%, 20px); opacity: 0; z-index: 30;
  background: rgba(40,40,42,.94); color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 15px; transition: all .25s; pointer-events: none; max-width: 90%; text-align: center; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.fade-in { animation: fade .18s ease-out; }
@keyframes fade { from { opacity: .4; transform: translateX(14px); } to { opacity: 1; transform: none; } }
