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

:root {
  --bg: #f8f7f4;
  --surface: #ffffff;
  --text: #1a1a1a;
  --text-secondary: #6b6b6b;
  --text-tertiary: #9a9a9a;
  --border: #e8e6e1;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow-card: 0 1px 3px rgba(0,0,0,0.04), 0 4px 12px rgba(0,0,0,0.03);
  /* Theme colors — set by JS per student */
  --accent: #300060;
  --accent-soft: #f3eef8;
  --header-bg: #300060;
  --header-text: #ffffff;
  --now-border: #16a34a;
  --now-bg: #f0fdf4;
  --now-badge-bg: #16a34a;
  --sat: env(safe-area-inset-top);
  --sab: env(safe-area-inset-bottom);
}

html {
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

/* ── Layout & Page ────────────────────────────────────── */
.page {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: calc(40px + var(--sat)) 24px calc(40px + var(--sab));
  max-width: 460px;
  margin: 0 auto;
  width: 100%;
}

.page-header {
  text-align: center;
  margin-bottom: 36px;
}

.page-header h1 {
  font-family: 'Montserrat', sans-serif;
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--text);
}

.page-header p {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-tertiary);
  margin-top: 4px;
  letter-spacing: 0.01em;
}

.student-cards {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.student-card {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 24px;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1.5px solid var(--border);
  box-shadow: 0 1px 3px rgba(0,0,0,0.04), 0 4px 14px rgba(0,0,0,0.03);
  text-decoration: none;
  color: inherit;
  transition: transform 0.15s ease, box-shadow 0.2s ease;
  -webkit-user-select: none;
  user-select: none;
}

.student-card:active {
  transform: scale(0.97);
}

@media (hover: hover) {
  .student-card:hover {
    box-shadow: 0 2px 8px rgba(0,0,0,0.07), 0 8px 28px rgba(0,0,0,0.06);
  }
}

.student-avatar {
  width: 56px;
  height: 56px;
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  font-weight: 800;
  color: #fff;
  flex-shrink: 0;
  letter-spacing: -0.02em;
  overflow: hidden;
  background: #ffffff;
  padding: 4px;
}

.student-avatar img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.student-info {
  flex: 1;
  min-width: 0;
}

.student-info .name {
  font-family: 'Montserrat', sans-serif;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.student-info .school {
  font-size: 14px;
  color: var(--text-secondary);
  margin-top: 2px;
}

.student-info .time-range {
  font-size: 12px;
  color: var(--text-tertiary);
  margin-top: 4px;
  font-weight: 500;
  letter-spacing: 0.02em;
}

.card-arrow {
  width: 20px;
  height: 20px;
  color: var(--text-tertiary);
  flex-shrink: 0;
}

/* ── Header ────────────────────────────────────── */
.header {
  padding: calc(12px + var(--sat)) 20px 14px;
  background: var(--header-bg);
  border-bottom: 1px solid rgba(255, 255, 255, 0.15);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-inner {
  max-width: 540px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
}

.back-link {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 15px;
  font-weight: 500;
  color: var(--header-text);
  text-decoration: none;
  flex-shrink: 0;
  padding: 4px 0;
  transition: opacity 0.15s ease;
}

.back-link:active {
  opacity: 0.6;
}

.back-link svg {
  width: 18px;
  height: 18px;
}

.header-title {
  flex: 1;
  text-align: center;
  font-family: 'Montserrat', sans-serif;
  font-size: 17px;
  font-weight: 700;
  color: var(--header-text);
  letter-spacing: -0.02em;
}

.header-spacer {
  width: 52px;
  flex-shrink: 0;
}

/* ── Content & School Info ───────────────────────── */
.content {
  padding: 0 20px 40px;
  max-width: 540px;
  margin: 0 auto;
}

.school-info {
  margin: 20px 0 16px;
  padding: 0 2px;
}

.student-name {
  font-family: 'Montserrat', sans-serif;
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.15;
  color: var(--accent);
}

.school-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-top: 2px;
}

.school-info-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 2px;
}

.school-logo {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  object-fit: contain;
  flex-shrink: 0;
}

.term-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-tertiary);
  margin-top: 4px;
  letter-spacing: 0.02em;
}

/* ── Term Selector ─────────────────────────────── */
.term-selector {
  display: flex;
  background: var(--border);
  border-radius: 10px;
  padding: 3px;
  margin: 16px 0 4px;
}

.term-segment {
  flex: 1;
  padding: 7px 0;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  border-radius: 8px;
  border: none;
  background: transparent;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
  font-family: inherit;
}

.term-segment.active {
  background: var(--accent-soft);
  color: var(--accent);
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.term-date-range {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-tertiary);
  margin-top: 4px;
  margin-bottom: 12px;
  letter-spacing: 0.02em;
}

/* ── Period Cards ──────────────────────────────── */
.period-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 10px;
  box-shadow: var(--shadow-card);
  border: 1.5px solid var(--border);
  transition: border-color 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
  display: flex;
  align-items: center;
  gap: 14px;
}

.period-card.now {
  border-color: var(--now-border);
  background: var(--now-bg);
  box-shadow: 0 2px 6px rgba(0,0,0,0.06), 0 8px 24px rgba(0,0,0,0.05);
}

.period-badge {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 800;
  color: #fff;
  background: var(--accent);
  flex-shrink: 0;
}

.period-content {
  flex: 1;
  min-width: 0;
}

.period-card.now .period-badge {
  background: var(--now-badge-bg);
}

.period-time {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-tertiary);
  letter-spacing: 0.03em;
  line-height: 1;
  margin-bottom: 3px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.now-indicator,
.next-indicator {
  display: none;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 1px 6px;
  border-radius: 4px;
}

.now-indicator {
  color: var(--now-border);
  background: rgba(22, 163, 74, 0.1);
}

.period-card.now .now-indicator {
  display: inline-block;
}

.next-indicator {
  color: #3b82f6;
  background: rgba(59, 130, 246, 0.1);
}

.period-card.next {
  border-color: #93c5fd;
  background: #eff6ff;
  box-shadow: 0 2px 6px rgba(0,0,0,0.06), 0 8px 24px rgba(0,0,0,0.05);
}

.period-card.next .period-badge {
  background: #3b82f6;
}

.period-card.next .next-indicator {
  display: inline-block;
}

.period-class {
  font-family: 'Montserrat', sans-serif;
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.3;
  letter-spacing: -0.01em;
}

.period-details {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  margin-top: 6px;
  font-size: 13px;
  color: var(--text-secondary);
}

.detail-item {
  display: flex;
  align-items: center;
  gap: 4px;
}

.detail-icon {
  width: 14px;
  height: 14px;
  opacity: 0.5;
  flex-shrink: 0;
}

/* ── Lunch Break ───────────────────────────────── */
.lunch-break {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  margin-bottom: 10px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-tertiary);
  letter-spacing: 0.02em;
}

.lunch-break::before,
.lunch-break::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* ── Footer ────────────────────────────────────── */
.footer {
  text-align: center;
  padding: 8px 20px calc(20px + var(--sab));
  font-size: 11px;
  color: var(--text-tertiary);
  letter-spacing: 0.02em;
}

@media (prefers-reduced-motion: reduce) {
  .period-card,
  .student-card {
    transition: none;
  }
}
