/* ── Reset ─────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  font-size: 16px;
}

body {
  background: var(--bg);
  color: var(--t1);
  min-height: 100dvh;
  overscroll-behavior: none;
  transition: background 0.25s, color 0.25s;
}

button { font: inherit; border: none; background: none; cursor: pointer; color: inherit; }

/* ── CSS custom properties – light (default) ────────────────────────────────── */
:root {
  --bg:       #F5F4F0;
  --surf:     #FFFFFF;
  --surf2:    #EDEDEA;
  --border:   rgba(0,0,0,0.08);
  --sep:      rgba(0,0,0,0.06);

  --t1:  #111110;
  --t2:  #5A5A55;
  --t3:  #A0A09A;

  --accent:   #0066FF;
  --accent-s: #0055DD;

  --green:    #15803D;
  --green-bg: rgba(21,128,61,0.10);
  --orange:   #C2620A;
  --orange-bg:rgba(194,98,10,0.10);
  --red:      #DC2626;
  --red-bg:   rgba(220,38,38,0.10);

  --tab-bg:   rgba(245,244,240,0.88);
  --hdr-bg:   rgba(245,244,240,0.90);

  --sh-sm:  0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --sh:     0 3px 14px rgba(0,0,0,0.08), 0 1px 4px rgba(0,0,0,0.04);
  --r:      14px;
  --r-sm:   9px;
  --r-lg:   22px;
  --hdr-h:  54px;
  --tab-h:  60px;
}

/* ── Dark (system auto) ──────────────────────────────────────────────────────── */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --bg:       #0C0C10;
    --surf:     #18181C;
    --surf2:    #222226;
    --border:   rgba(255,255,255,0.09);
    --sep:      rgba(255,255,255,0.06);

    --t1:  #F0EFE8;
    --t2:  #8A8A84;
    --t3:  #4A4A46;

    --green:    #22C55E;
    --green-bg: rgba(34,197,94,0.13);
    --orange:   #F59E0B;
    --orange-bg:rgba(245,158,11,0.13);
    --red:      #EF4444;
    --red-bg:   rgba(239,68,68,0.13);

    --tab-bg:   rgba(18,18,22,0.90);
    --hdr-bg:   rgba(12,12,16,0.92);

    --sh-sm:  0 1px 3px rgba(0,0,0,0.35);
    --sh:     0 3px 14px rgba(0,0,0,0.5);
  }
}

/* ── Manual: light ────────────────────────────────────────────────────────────── */
[data-theme="light"] {
  --bg:       #F5F4F0;
  --surf:     #FFFFFF;
  --surf2:    #EDEDEA;
  --border:   rgba(0,0,0,0.08);
  --sep:      rgba(0,0,0,0.06);
  --t1:  #111110; --t2: #5A5A55; --t3: #A0A09A;
  --green:#15803D; --green-bg:rgba(21,128,61,0.10);
  --orange:#C2620A; --orange-bg:rgba(194,98,10,0.10);
  --red:#DC2626; --red-bg:rgba(220,38,38,0.10);
  --tab-bg: rgba(245,244,240,0.88); --hdr-bg: rgba(245,244,240,0.90);
  --sh-sm: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --sh: 0 3px 14px rgba(0,0,0,0.08), 0 1px 4px rgba(0,0,0,0.04);
}

/* ── Manual: dark ─────────────────────────────────────────────────────────────── */
[data-theme="dark"] {
  --bg:       #0C0C10;
  --surf:     #18181C;
  --surf2:    #222226;
  --border:   rgba(255,255,255,0.09);
  --sep:      rgba(255,255,255,0.06);
  --t1:  #F0EFE8; --t2: #8A8A84; --t3: #4A4A46;
  --green:#22C55E; --green-bg:rgba(34,197,94,0.13);
  --orange:#F59E0B; --orange-bg:rgba(245,158,11,0.13);
  --red:#EF4444; --red-bg:rgba(239,68,68,0.13);
  --tab-bg: rgba(18,18,22,0.90); --hdr-bg: rgba(12,12,16,0.92);
  --sh-sm: 0 1px 3px rgba(0,0,0,0.35); --sh: 0 3px 14px rgba(0,0,0,0.5);
}

/* ── Manual: OLED ─────────────────────────────────────────────────────────────── */
[data-theme="oled"] {
  --bg:       #000000;
  --surf:     #000000;
  --surf2:    #0A0A0A;
  --border:   rgba(255,255,255,0.13);
  --sep:      rgba(255,255,255,0.07);
  --t1:  #FFFFFF; --t2: #888884; --t3: #404040;
  --accent:   #4D94FF;
  --green:#22C55E; --green-bg:rgba(34,197,94,0.12);
  --orange:#F59E0B; --orange-bg:rgba(245,158,11,0.12);
  --red:#EF4444; --red-bg:rgba(239,68,68,0.12);
  --tab-bg: rgba(0,0,0,0.95); --hdr-bg: rgba(0,0,0,0.97);
  --sh-sm: none; --sh: none;
}

/* OLED: cards get border instead of shadow */
[data-theme="oled"] .sub-card,
[data-theme="oled"] .termin-card,
[data-theme="oled"] .class-btn {
  border: 1px solid var(--border);
  box-shadow: none;
}

/* ── Mask icons (.mi) ─────────────────────────────────────────────────────────── */
/* Uses CSS mask-image so icon color = currentColor. No filter hacks needed.      */
.mi {
  display: inline-block;
  flex-shrink: 0;
  background-color: currentColor;
  -webkit-mask-image: var(--u);
  -webkit-mask-size: contain;
  -webkit-mask-repeat: no-repeat;
  -webkit-mask-position: center;
  mask-image: var(--u);
  mask-size: contain;
  mask-repeat: no-repeat;
  mask-position: center;
}
.mi.sz14 { width: 14px; height: 14px; }
.mi.sz16 { width: 16px; height: 16px; }
.mi.sz18 { width: 18px; height: 18px; }
.mi.sz20 { width: 20px; height: 20px; }
.mi.sz22 { width: 22px; height: 22px; }
.mi.sz24 { width: 24px; height: 24px; }
.mi.sz40 { width: 40px; height: 40px; }
.mi.sz48 { width: 48px; height: 48px; }

/* ── Layout ─────────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }

#screen-picker, #screen-app { min-height: 100dvh; }

/* ── Header ─────────────────────────────────────────────────────────────────── */
#header {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding:
    calc(env(safe-area-inset-top) + 10px)
    calc(env(safe-area-inset-right) + 14px)
    10px
    calc(env(safe-area-inset-left) + 14px);
  min-height: calc(env(safe-area-inset-top) + var(--hdr-h));
  background: var(--hdr-bg);
  backdrop-filter: saturate(180%) blur(24px);
  -webkit-backdrop-filter: saturate(180%) blur(24px);
  border-bottom: 1px solid var(--sep);
}

.header-left  { display: flex; align-items: center; gap: 6px; flex: 1; min-width: 0; }
.header-right { display: flex; align-items: center; gap: 4px; flex: 1; justify-content: flex-end; }

.header-title {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.5px;
  color: var(--t1);
  flex-shrink: 0;
  white-space: nowrap;
}

.class-badge {
  display: inline-flex;
  align-items: center;
  background: var(--accent);
  color: #fff;
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.3px;
  padding: 4px 11px;
  border-radius: 20px;
  white-space: nowrap;
}

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  color: var(--t2);
  background: var(--surf2);
  transition: background 0.13s, transform 0.1s;
  flex-shrink: 0;
}
.icon-btn:active { background: var(--border); transform: scale(0.92); }

/* ── Date tabs (segment control) ────────────────────────────────────────────── */
#date-tabs {
  padding: 10px 14px 2px;
  background: var(--bg);
  position: sticky;
  top: calc(env(safe-area-inset-top) + var(--hdr-h));
  z-index: 90;
}

.date-tabs-track {
  display: flex;
  background: var(--surf2);
  border-radius: var(--r-sm);
  padding: 3px;
  gap: 2px;
}

.date-tab {
  flex: 1;
  padding: 7px 10px;
  font-size: 14px;
  font-weight: 500;
  color: var(--t2);
  text-align: center;
  border-radius: 6px;
  transition: all 0.18s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.date-tab.active {
  background: var(--surf);
  color: var(--t1);
  font-weight: 600;
  box-shadow: 0 1px 4px rgba(0,0,0,0.10), 0 0.5px 1px rgba(0,0,0,0.06);
}

/* ── Content ─────────────────────────────────────────────────────────────────── */
#content {
  padding: 12px
    calc(env(safe-area-inset-right) + 14px)
    calc(var(--tab-h) + env(safe-area-inset-bottom) + 20px)
    calc(env(safe-area-inset-left) + 14px);
}

/* ── Substitution cards ─────────────────────────────────────────────────────── */
.sub-card {
  display: flex;
  background: var(--surf);
  border-radius: var(--r);
  margin-bottom: 8px;
  overflow: hidden;
  box-shadow: var(--sh-sm);
  border: 1px solid var(--sep);
}

.sub-accent {
  width: 3.5px;
  flex-shrink: 0;
}

.sub-body {
  padding: 12px 14px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.sub-top {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
}

.stunde-num {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.1px;
  color: var(--pc, var(--accent));
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
  min-width: 22px;
}

.fach-name {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.3px;
  color: var(--t1);
  flex: 1;
}

.bem-tag {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.2px;
  padding: 2px 7px;
  border-radius: 20px;
  background: var(--surf2);
  color: var(--t3);
  white-space: nowrap;
}
.bem-tag.vt  { background: var(--orange-bg); color: var(--orange); }
.bem-tag.aus { background: var(--red-bg);    color: var(--red); }
.bem-tag.swa { background: var(--green-bg);  color: var(--green); }

.teacher-row {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.t-orig {
  font-size: 14px;
  color: var(--t3);
  text-decoration: line-through;
  text-decoration-color: var(--t3);
}
.t-abbr { font-size: 11px; color: var(--t3); }
.t-arr  { color: var(--t3); flex-shrink: 0; }
.t-sub  { font-size: 14px; font-weight: 600; color: var(--t1); }
.t-sub-abbr { font-size: 11px; color: var(--t2); }

.room-row {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 13px;
  color: var(--t2);
}
.r-icon { color: var(--t3); flex-shrink: 0; }
.r-orig { text-decoration: line-through; color: var(--t3); margin-right: 1px; }

/* ── Section header ─────────────────────────────────────────────────────────── */
.section-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.7px;
  text-transform: uppercase;
  color: var(--t3);
  padding: 12px 0 8px;
}

/* ── Termine cards ───────────────────────────────────────────────────────────── */
.termin-card {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  background: var(--surf);
  border-radius: var(--r);
  padding: 14px;
  margin-bottom: 8px;
  box-shadow: var(--sh-sm);
  border: 1px solid var(--sep);
}

.t-date-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 40px;
  flex-shrink: 0;
  background: var(--surf2);
  border-radius: var(--r-sm);
  padding: 6px 4px;
}

.t-month {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--accent);
}

.t-day {
  font-size: 22px;
  font-weight: 800;
  line-height: 1.1;
  letter-spacing: -1px;
  color: var(--t1);
}

.t-day-end {
  font-size: 10px;
  color: var(--t3);
  letter-spacing: 0.2px;
}

.t-body { flex: 1; min-width: 0; }

.t-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--t1);
  line-height: 1.3;
  letter-spacing: -0.2px;
}

.t-desc {
  font-size: 13px;
  color: var(--t2);
  margin-top: 3px;
  line-height: 1.4;
}

/* ── Status bar ──────────────────────────────────────────────────────────────── */
#status-bar {
  text-align: center;
  font-size: 11px;
  color: var(--t3);
  padding: 2px 16px 0;
  height: 20px;
  letter-spacing: 0.1px;
}

/* ── Bottom tab bar (floating pill) ──────────────────────────────────────────── */
#bottom-tabs {
  position: fixed;
  bottom: calc(max(env(safe-area-inset-bottom), 10px) + 8px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  display: inline-flex;
  background: var(--tab-bg);
  backdrop-filter: saturate(180%) blur(24px);
  -webkit-backdrop-filter: saturate(180%) blur(24px);
  border-radius: var(--r-lg);
  padding: 5px;
  gap: 3px;
  box-shadow: var(--sh), 0 0 0 1px var(--border);
  white-space: nowrap;
}

.tab-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 14px;
  border-radius: 17px;
  font-size: 14px;
  font-weight: 600;
  color: var(--t3);
  transition: all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
  -webkit-tap-highlight-color: transparent;
  letter-spacing: -0.2px;
}

/* Inactive tabs: icon only, no label */
.tab-label { display: none; }

.tab-btn.active {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 2px 10px rgba(0,102,255,0.3);
}

/* Active tab: show label */
.tab-btn.active .tab-label { display: inline; }

/* Class badge as a clickable button in header-right */
#class-badge-btn {
  display: inline-flex;
  align-items: center;
  background: var(--accent);
  color: #fff;
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.3px;
  padding: 4px 11px;
  border-radius: 20px;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
  transition: opacity 0.12s;
}
#class-badge-btn:active { opacity: 0.75; }

/* ── Class picker ────────────────────────────────────────────────────────────── */
#screen-picker {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding:
    calc(env(safe-area-inset-top) + 24px)
    calc(env(safe-area-inset-right) + 20px)
    calc(env(safe-area-inset-bottom) + 24px)
    calc(env(safe-area-inset-left) + 20px);
}

.picker-container {
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

.picker-icon-wrap {
  width: 76px;
  height: 76px;
  background: var(--accent);
  border-radius: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  box-shadow: 0 6px 28px rgba(0,102,255,0.40);
}

.picker-title {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -0.8px;
  color: var(--t1);
  text-align: center;
}

.picker-subtitle {
  font-size: 15px;
  color: var(--t2);
  text-align: center;
  max-width: 270px;
  line-height: 1.45;
  margin-top: -8px;
}

.class-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 7px;
  width: 100%;
}

.class-btn {
  padding: 13px 4px;
  background: var(--surf);
  border-radius: var(--r-sm);
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.2px;
  color: var(--t1);
  text-align: center;
  box-shadow: var(--sh-sm);
  border: 1px solid var(--sep);
  transition: transform 0.12s, background 0.12s;
  -webkit-tap-highlight-color: transparent;
}
.class-btn:active   { transform: scale(0.93); }
.class-btn.selected { background: var(--accent); color: #fff; border-color: transparent; box-shadow: 0 2px 12px rgba(0,102,255,0.30); }

.privacy-note {
  font-size: 11px;
  color: var(--t3);
  text-align: center;
  line-height: 1.5;
  max-width: 300px;
  letter-spacing: 0.1px;
}

/* ── States ─────────────────────────────────────────────────────────────────── */
.empty-state, .error-state, .loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 52px 24px;
  text-align: center;
  gap: 8px;
}

.state-ico { color: var(--t3); margin-bottom: 4px; }

.state-title {
  font-size: 17px;
  font-weight: 700;
  color: var(--t1);
  letter-spacing: -0.3px;
}

.state-sub {
  font-size: 14px;
  color: var(--t3);
  line-height: 1.4;
}

.spinner {
  width: 30px;
  height: 30px;
  border: 2.5px solid var(--sep);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.65s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Pull-to-refresh bar ─────────────────────────────────────────────────────── */
#ptr-bar {
  height: 0;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--t3);
  transition: height 0.2s ease, opacity 0.2s ease;
  opacity: 0;
}

/* ── Swipe host ───────────────────────────────────────────────────────────────── */
#swipe-host {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* ── Settings screen ─────────────────────────────────────────────────────────── */
.settings-screen {
  padding: 16px
    calc(env(safe-area-inset-right) + 14px)
    calc(var(--tab-h) + env(safe-area-inset-bottom) + 20px)
    calc(env(safe-area-inset-left) + 14px);
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.settings-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.settings-heading-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.settings-heading {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.7px;
  text-transform: uppercase;
  color: var(--t3);
  padding: 0 2px;
}

.settings-link {
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  -webkit-tap-highlight-color: transparent;
}

/* ── Theme grid ─────────────────────────────────────────────────────────────── */
.theme-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 7px;
}

.theme-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 12px 4px;
  background: var(--surf);
  border-radius: var(--r-sm);
  font-size: 12px;
  font-weight: 600;
  color: var(--t2);
  border: 2px solid transparent;
  box-shadow: var(--sh-sm);
  border: 1px solid var(--sep);
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.theme-btn.active {
  border-color: var(--accent);
  color: var(--accent);
}

/* ── Subject grid ───────────────────────────────────────────────────────────── */
.subject-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.subject-chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: var(--surf);
  border-radius: var(--r-sm);
  padding: 7px 10px;
  border: 1px solid var(--sep);
  box-shadow: var(--sh-sm);
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
  min-width: 52px;
  opacity: 0.42;
}

.subject-chip.sel {
  border-color: var(--accent);
  opacity: 1;
}

.subj-abbr {
  font-size: 14px;
  font-weight: 700;
  color: var(--t1);
  letter-spacing: -0.2px;
}

.subj-name {
  font-size: 10px;
  color: var(--t2);
  white-space: nowrap;
}

/* ── Settings row button ────────────────────────────────────────────────────── */
.settings-row-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surf);
  border-radius: var(--r);
  padding: 14px 16px;
  box-shadow: var(--sh-sm);
  border: 1px solid var(--sep);
  width: 100%;
  color: var(--t1);
  font-size: 16px;
  font-weight: 500;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.12s;
}
.settings-row-btn:active { background: var(--surf2); }
.srb-label   { font-weight: 700; color: var(--accent); }
.srb-chevron { color: var(--t3); }

.settings-hint {
  font-size: 12px;
  color: var(--t3);
  padding: 0 4px;
  line-height: 1.4;
}

/* OLED overrides for settings */
[data-theme="oled"] .theme-btn,
[data-theme="oled"] .subject-chip,
[data-theme="oled"] .settings-row-btn {
  box-shadow: none;
}

/* ── Utility ─────────────────────────────────────────────────────────────────── */
.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0,0,0,0); border: 0;
}
