:root {
  /* Always dark, whatever the phone's appearance setting. */
  color-scheme: dark;
  --bg: #000000;
  --card: #1c1c1e;
  --text: #f2f2f7;
  --muted: #98989f;
  --line: #2c2c2e;
  --accent: #4c9bff;
  --accent-soft: #14284a;
  --warn: #ff9f5a;
  --warn-soft: #3a2314;
  --tab: rgba(22, 22, 24, 0.92);
  --shadow: none;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.35 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

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

#screen {
  padding: calc(env(safe-area-inset-top) + 12px) 16px calc(env(safe-area-inset-bottom) + 84px);
  max-width: 640px;
  margin: 0 auto;
}

.top h1 { font-size: 34px; font-weight: 700; letter-spacing: -0.02em; margin: 8px 0 2px; }
.sub { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; margin-bottom: 14px; }
#refresh { color: var(--accent); font-size: 17px; line-height: 1; padding: 4px; }
#refresh.spin { animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.section { font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; margin: 22px 4px 8px; }
.section:first-child { margin-top: 4px; }

.card {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  background: var(--card);
  border-radius: 14px;
  padding: 12px 14px;
  margin-bottom: 8px;
  box-shadow: var(--shadow);
}
.card:active { opacity: 0.6; }
.card .main { flex: 1; min-width: 0; }
.card .course { font-size: 12px; font-weight: 700; color: var(--accent); letter-spacing: 0.03em; }
.card .name { font-size: 17px; font-weight: 600; margin-top: 1px; overflow-wrap: anywhere; }
.card .meta { font-size: 14px; color: var(--muted); margin-top: 2px; }
.card .side { text-align: right; flex-shrink: 0; }
.card .when { font-size: 15px; font-weight: 600; }
.card .time { font-size: 13px; color: var(--muted); }
.card .chev { color: var(--line); font-size: 22px; margin-left: -4px; }
.card .count { font-size: 11px; color: var(--accent); background: var(--accent-soft); border-radius: 6px; padding: 1px 6px; margin-left: 6px; font-weight: 600; vertical-align: 2px; }

.badge { display: inline-block; font-size: 12px; font-weight: 600; border-radius: 6px; padding: 2px 7px; background: var(--accent-soft); color: var(--accent); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }

.todo { align-items: flex-start; }
.todo .name { white-space: normal; font-weight: 500; font-size: 16px; }
.done-btn {
  flex-shrink: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 999px;
  padding: 6px 12px;
  margin-top: 2px;
}

.empty { color: var(--muted); text-align: center; padding: 48px 16px; }
.error { color: var(--warn); background: var(--warn-soft); border-radius: 12px; padding: 10px 14px; font-size: 14px; margin-bottom: 12px; }

/* Detail view slides in from the right, like a navigation push. */
.detail {
  position: fixed;
  inset: 0;
  background: var(--bg);
  transform: translateX(100%);
  transition: transform 0.28s ease;
  overflow-y: auto;
  z-index: 20;
  padding: 0 16px calc(env(safe-area-inset-bottom) + 96px);
}
.detail.open { transform: none; }
.detail-bar {
  position: sticky;
  top: 0;
  padding: calc(env(safe-area-inset-top) + 10px) 0 8px;
  background: var(--bg);
  max-width: 640px;
  margin: 0 auto;
}
.back { color: var(--accent); font-size: 17px; }
#detail-body { max-width: 640px; margin: 0 auto; }
.d-course { font-size: 14px; font-weight: 700; color: var(--accent); margin-top: 6px; }
.d-name { font-size: 28px; font-weight: 700; letter-spacing: -0.01em; margin: 2px 0 12px; }
.facts { background: var(--card); border-radius: 14px; box-shadow: var(--shadow); }
.fact { display: flex; justify-content: space-between; gap: 12px; padding: 11px 14px; border-bottom: 0.5px solid var(--line); }
.fact:last-child { border-bottom: 0; }
.fact span:first-child { color: var(--muted); }
.fact span:last-child { text-align: right; }
.post { background: var(--card); border-radius: 14px; padding: 12px 14px; margin-bottom: 8px; box-shadow: var(--shadow); }
.post-head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: 13px; color: var(--muted); }
.post-title { font-weight: 600; margin: 6px 0 4px; }
.post-text { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 15px; }
.post a, .link { color: var(--accent); text-decoration: none; font-size: 14px; display: inline-block; margin-top: 8px; }

.sheet { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.35); display: none; align-items: flex-end; z-index: 40; }
.sheet.open { display: flex; }
.sheet-panel {
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  background: var(--card);
  border-radius: 16px 16px 0 0;
  padding: 18px 16px calc(env(safe-area-inset-bottom) + 14px);
  text-align: center;
}
.sheet-title { font-weight: 600; font-size: 17px; margin: 0 0 4px; }
.sheet-text { color: var(--muted); font-size: 14px; margin: 0 0 14px; }
.sheet-btn { display: block; width: 100%; padding: 14px; border-radius: 12px; font-size: 17px; font-weight: 600; margin-top: 8px; background: var(--bg); color: var(--accent); }
.sheet-btn.primary { background: var(--accent); color: #fff; }

.tabs {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  background: var(--tab);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: 0.5px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 30; /* stays visible over the detail view, like an iOS tab bar */
}
.tabs button { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 7px 0 5px; color: var(--muted); font-size: 10px; font-weight: 500; }
.tabs svg { width: 25px; height: 25px; fill: currentColor; }
.tabs button.active { color: var(--accent); }

/* The status bar is translucent: keep scrolled content from showing behind the clock. */
body::before {
  content: "";
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: env(safe-area-inset-top);
  background: var(--bg);
  z-index: 15;
}

/* Schedule: a week grid sized to the space between the header and the tab bar. */
.sched {
  display: grid;
  grid-template-columns: 30px repeat(5, minmax(0, 1fr));
  grid-template-rows: 22px repeat(var(--rows), minmax(0, 1fr));
  column-gap: 4px;
  row-gap: 0;
  height: calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 196px);
  min-height: 420px;
}
.sched-day { grid-row: 1; text-align: center; font-size: 12px; font-weight: 600; color: var(--muted); letter-spacing: 0.04em; text-transform: uppercase; }
.sched-day.today { color: var(--accent); }
.sched-hour { grid-column: 1; font-size: 10px; color: var(--muted); transform: translateY(-6px); }
.sched-line { grid-column: 2 / -1; border-top: 0.5px solid var(--line); }
.slot {
  margin: 2px 0;
  border-radius: 10px;
  background: var(--card);
  padding: 4px 3px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 1px;
  overflow: hidden;
  z-index: 1;
}
.slot b { font-size: 13px; color: var(--accent); letter-spacing: -0.01em; }
.slot span { font-size: 10.5px; color: var(--muted); line-height: 1.2; overflow-wrap: anywhere; }
.slot em { font-style: normal; font-size: 10px; font-weight: 600; color: var(--warn); }
.slot.today { box-shadow: inset 0 0 0 1px var(--accent-soft); }
.slot.live { background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent); }
.slot.live span { color: var(--text); }
.slot.changed { box-shadow: inset 0 0 0 1px var(--warn); }
