/* ---- Design tokens ----
   Every color lives here, so changing the look never means hunting
   through the file. Course card colors come from PALETTE in app.js. */
:root {
  --bg: #111214;
  --surface: #1c1d21;
  --surface-raised: #26282d;
  --text: #f4f4f5;
  --muted: #9a9ca3;
  --border: #2e3036;
  --accent: #2563eb;
  --today: #22a35a;
  --now: #ff453a;
  --color-exam: #dc2626;
  --color-dayoff: #52525b;
  --radius: 18px;
}

* {
  box-sizing: border-box;
}

/* Any rule that sets `display` (like .panel below) would otherwise beat the
   browser's built-in "hidden means invisible" rule. This keeps it winning. */
[hidden] {
  display: none !important;
}

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

main {
  max-width: 560px;
  margin: 0 auto;
  /* env(...) keeps content clear of the notch when installed on a phone. */
  padding: max(16px, env(safe-area-inset-top)) 16px max(48px, env(safe-area-inset-bottom));
}

button {
  font: inherit;
  color: inherit;
}

.hint,
.subtitle,
.picker-intro {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0;
}

/* Messages float above everything (including the app pages); they go away
   on their own, or when tapped or swiped up. */
.error {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  left: 16px;
  right: 16px;
  max-width: 528px;
  margin: 0 auto;
  z-index: 10;
  background: #3b1515;
  color: #fca5a5;
  border: 1px solid #7f1d1d;
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 0.9rem;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  touch-action: none;
}

/* ---- Shared buttons ---- */
.link-btn {
  background: none;
  border: none;
  color: var(--muted);
  text-decoration: underline;
  cursor: pointer;
  font-size: 0.9rem;
  padding: 0;
}

.primary-btn,
#load-url-btn {
  border: none;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}

.primary-btn {
  width: 100%;
  padding: 14px;
}

/* ---- Panels (upload + course picker) ---- */
.panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}

.panel h1 {
  margin: 0;
  font-size: 1.6rem;
}

.file-drop {
  display: block;
  text-align: center;
  padding: 20px;
  border: 2px dashed var(--accent);
  border-radius: 14px;
  cursor: pointer;
  color: #93b4ff;
  font-weight: 600;
}

.link-option {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.danger-link {
  color: #f87171;
  margin-top: 8px;
}

.back-btn {
  align-self: flex-start;
  text-decoration: none;
  color: #93b4ff;
}

.how-to {
  background: var(--surface-raised);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 0.9rem;
  line-height: 1.5;
}

.how-to summary {
  cursor: pointer;
  font-weight: 600;
  color: #93b4ff;
}

.how-to ol {
  padding-left: 20px;
  margin: 10px 0;
}

.how-to li + li {
  margin-top: 6px;
}

.how-to p {
  margin: 0;
  color: var(--muted);
}

.how-to a {
  color: #93b4ff;
}

.file-drop input[type="file"] {
  /* The real input is invisible; the label above acts as the clickable button. */
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  opacity: 0;
}

.url-load-row {
  display: flex;
  gap: 8px;
}

#ics-url-input,
#course-search {
  flex: 1;
  min-width: 0;
  padding: 12px 14px;
  background: var(--surface-raised);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 0.95rem;
}

#load-url-btn {
  padding: 12px 18px;
}

#course-list {
  max-height: 50vh;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 12px;
}

.course-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
  cursor: pointer;
}

.course-row:last-child {
  border-bottom: none;
}

.course-count {
  margin-left: auto;
  color: var(--muted);
  font-size: 0.8rem;
}

/* ---- App shell: two swipeable pages + bottom tab bar ---- */
#week-view {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

#pager {
  flex: 1;
  display: flex;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
}

#pager::-webkit-scrollbar {
  display: none;
}

.page {
  flex: 0 0 100%;
  scroll-snap-align: start;
  scroll-snap-stop: always;
  overflow-y: auto;
  /* Centre the content in a 560px column on wide screens. */
  padding: max(20px, env(safe-area-inset-top)) max(16px, calc((100% - 560px) / 2)) 24px;
}

.bottom-nav {
  display: flex;
  justify-content: center;
  gap: 12px;
  padding: 8px 16px max(8px, env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--border);
}

.nav-btn {
  flex: 0 1 160px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px;
  background: none;
  border: none;
  border-radius: 14px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 700;
  cursor: pointer;
}

.nav-btn[aria-current="page"] {
  color: var(--text);
  background: var(--surface-raised);
}

.nav-btn svg,
#settings-btn svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---- Home page ---- */
.profile-bar {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 32px;
}

.avatar {
  width: 64px;
  height: 64px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--accent);
  font-size: 1.4rem;
  font-weight: 800;
  overflow: hidden;
}

.profile-text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  background: none;
  border: none;
  padding: 0;
  text-align: left;
  cursor: pointer;
}

.greeting,
.profile-sub {
  color: var(--muted);
  font-weight: 700;
  font-size: 0.95rem;
}

.profile-name {
  font-size: 1.7rem;
  font-weight: 800;
  line-height: 1.2;
}

.profile-name.is-empty {
  font-size: 1.1rem;
  color: #93b4ff;
}

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-bottom: 14px;
}

.section-head h2 {
  margin: 0 0 2px;
  font-size: 1.4rem;
}

.course-card {
  position: relative;
  width: 100%;
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 10px;
  padding: 16px 16px 16px 22px;
  background: var(--surface);
  border: none;
  border-radius: var(--radius);
  text-align: left;
  cursor: pointer;
  overflow: hidden;
}

/* The coloured strip on the left matches the course's timetable colour. */
.course-card::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 6px;
  background: var(--card-color);
}

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

.course-title {
  margin: 0 0 4px;
  font-size: 1.02rem;
  font-weight: 700;
}

.course-next {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
}

#coming-up-section {
  margin-bottom: 28px;
}

/* ---- Timetable changes (Home) ---- */
.changes-card {
  margin-bottom: 28px;
  padding: 16px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid #a16207;
}

/* "Now / Next" card at the top of Home, in the class's own colour. */
.next-card {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 28px;
  padding: 18px;
  border: none;
  border-radius: var(--radius);
  background: var(--card-color);
  color: #fff;
  text-align: left;
  font: inherit;
  cursor: pointer;
}

.next-label {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0.85;
}

.next-title {
  font-size: 1.3rem;
  font-weight: 700;
  line-height: 1.25;
}

.next-detail {
  font-size: 0.95rem;
  font-weight: 600;
}

.next-then {
  margin-top: 8px;
  padding-top: 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.25);
  font-size: 0.85rem;
  opacity: 0.9;
}

.install-card {
  margin-bottom: 28px;
  padding: 16px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
}

.changes-head .link-btn {
  white-space: nowrap;
}

.install-card .hint {
  margin: 4px 0 0;
}

.changes-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.changes-head h2 {
  margin: 0;
  font-size: 1.2rem;
}

.changes-card > .hint {
  margin: 4px 0 12px;
}

.change-row {
  width: 100%;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 10px 0;
  background: none;
  border: none;
  border-top: 1px solid var(--border);
  text-align: left;
  cursor: pointer;
}

.change-tag {
  flex-shrink: 0;
  min-width: 72px;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 800;
  text-align: center;
  background: #3a2a05;
  color: #fbbf24;
}

.change-tag.change-missing {
  background: #3b1515;
  color: #fca5a5;
}

.change-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.change-title {
  font-weight: 700;
}

.change-detail {
  color: var(--muted);
  font-size: 0.85rem;
  overflow-wrap: anywhere;
}

.change-badge {
  background: rgba(0, 0, 0, 0.35);
  color: #fde68a;
  font-weight: 700;
  font-size: 0.75rem;
  padding: 4px 10px;
  border-radius: 999px;
  white-space: nowrap;
}

.kind-badge {
  flex-shrink: 0;
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--card-color);
  color: #fff;
  font-size: 0.8rem;
  font-weight: 700;
}

.course-left {
  flex-shrink: 0;
  text-align: center;
}

.course-left strong {
  display: block;
  font-size: 1.3rem;
}

.course-left span {
  color: var(--muted);
  font-size: 0.75rem;
}

.error.is-info {
  background: #10281a;
  color: #86efac;
  border-color: #166534;
}

/* ---- Glossary: English for ZEUS words ---- */
.class-gloss {
  margin: -4px 0 0;
  font-size: 0.8rem;
  opacity: 0.85;
}

.course-gloss {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 0.78rem;
}

/* Small "unofficial · contact" line at the bottom of Home and setup. */
.contact-line {
  margin: 20px 0 0;
  color: var(--muted);
  font-size: 0.8rem;
  text-align: center;
}

.contact-line a {
  color: inherit;
}

.glossary {
  margin-top: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}

.glossary summary {
  font-weight: 700;
  cursor: pointer;
}

.glossary .hint {
  margin: 10px 0 6px;
}

.glossary dl {
  margin: 0;
}

.glossary dl div {
  display: flex;
  gap: 12px;
  padding: 8px 0;
  border-top: 1px solid var(--border);
}

.glossary dt {
  flex: 0 0 38%;
  font-weight: 600;
}

.glossary dd {
  margin: 0;
  color: var(--muted);
}

/* ---- Friends page ---- */
.friend-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin: 18px 0 22px;
}

#friend-link-input {
  flex: 1;
  min-width: 0;
  padding: 12px 14px;
  background: var(--surface-raised);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 0.95rem;
}

#add-friend-btn {
  padding: 12px 18px;
  border: none;
  border-radius: 12px;
  background: var(--surface-raised);
  font-weight: 700;
  cursor: pointer;
}

.friend-row {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 16px;
  margin-bottom: 10px;
  background: var(--surface);
  border-radius: var(--radius);
}

.avatar.small {
  width: 44px;
  height: 44px;
  font-size: 1rem;
}

.friend-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.friend-info p {
  margin: 0;
}

.friend-name {
  font-weight: 800;
  font-size: 1.05rem;
}

.friend-status {
  font-weight: 700;
  font-size: 0.92rem;
}

.friend-status.tone-busy {
  color: #93b4ff;
}

.friend-status.tone-free {
  color: var(--today);
}

.friend-status.tone-done {
  color: var(--muted);
}

.friend-together {
  font-size: 0.85rem;
  color: var(--text);
}

.friend-age {
  font-size: 0.8rem;
  color: var(--muted);
}

.friend-age.is-stale {
  color: #fbbf24;
}

.remove-friend {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  font-size: 1.1rem;
  color: var(--muted);
}

/* ---- Free rooms page ---- */
.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 14px 0 0;
}

.chip-btn {
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
}

.chip-btn[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

#rooms-list {
  margin-top: 18px;
}

.room-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  margin-bottom: 8px;
  background: var(--surface);
  border-radius: 14px;
}

.room-name {
  font-weight: 700;
  min-width: 0;
  overflow-wrap: anywhere;
}

.room-until {
  flex-shrink: 0;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 700;
}

.room-until.is-long {
  color: var(--today);
}

#rooms-updated.is-stale {
  color: #fbbf24;
}

#rooms-updated {
  margin-right: auto;
  color: var(--muted);
  font-size: 0.85rem;
}

/* ---- Week view ---- */
.toolbar {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 8px;
}

#updated-label {
  margin-right: auto;
  color: var(--muted);
  font-size: 0.85rem;
}

#updated-label.is-stale {
  color: #fbbf24;
}

.day-header h2 {
  margin: 0;
  font-size: 1.8rem;
}

.day-header p {
  margin: 4px 0 0;
  color: var(--muted);
  font-weight: 600;
}

.week-nav {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 18px 0 12px;
  color: var(--muted);
  font-size: 0.9rem;
}

#week-label {
  flex: 1;
  text-align: center;
}

.icon-btn,
.pill-btn {
  background: var(--surface);
  border: none;
  border-radius: 999px;
  cursor: pointer;
}

.icon-btn {
  width: 36px;
  height: 36px;
  font-size: 1.3rem;
  line-height: 1;
}

.pill-btn {
  padding: 8px 14px;
  font-size: 0.85rem;
  font-weight: 600;
}

#day-tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
}

.day-tab {
  flex: 1 0 48px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 14px 6px;
  background: var(--surface);
  border: 2px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
  font-weight: 700;
}

.day-tab.is-today {
  border-color: var(--today);
}

.day-tab.is-selected {
  background: var(--accent);
}

.day-tab-count {
  min-width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  font-size: 0.8rem;
}

.day-tab-count:empty {
  background: none;
}

/* ---- Timeline + class cards ---- */
.timeline-row {
  display: grid;
  grid-template-columns: 52px 1fr;
  gap: 10px;
  margin-bottom: 12px;
}

.timeline-time {
  align-self: start; /* only as tall as the time, so app.js can tell where it is */
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 600;
  padding-top: 18px;
}

.class-card {
  background: var(--card-color);
  border-radius: var(--radius);
  padding: 18px;
  color: #fff;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.class-card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}

.class-title {
  margin: 0;
  font-size: 1.15rem;
  line-height: 1.3;
}

.class-badge {
  background: #fff;
  color: var(--card-color);
  font-weight: 700;
  font-size: 0.8rem;
  padding: 4px 12px;
  border-radius: 999px;
  white-space: nowrap;
}

.class-note {
  margin: 0;
  font-size: 0.85rem;
  opacity: 0.85;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(0, 0, 0, 0.22);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 0.85rem;
  font-weight: 600;
}

.chip svg {
  width: 14px;
  height: 14px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* The red "now" line across today's timetable (placed by app.js). */
#schedule {
  position: relative;
}

.now-line {
  position: absolute;
  left: 0;
  right: 0;
  height: 2px;
  margin-top: -1px;
  background: var(--now);
  /* A thin outline in the page colour keeps it visible on red exam cards. */
  box-shadow: 0 0 0 1.5px var(--bg);
  pointer-events: none;
  z-index: 0;
}

/* Text and chips sit above the line; the line still shows across the card. */
.class-card > *,
.break-row span {
  position: relative;
  z-index: 1;
}

.break-row span {
  background: var(--bg);
  padding-right: 8px;
}

.now-time {
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  background: var(--now);
  color: #fff;
  font-size: 0.78rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  padding: 3px 7px;
  border-radius: 999px;
}

.timeline-time.is-covered {
  visibility: hidden;
}

.break-row {
  margin: 4px 0 16px 62px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 600;
  border-top: 1px dashed var(--border);
  padding-top: 8px;
}

.empty-day {
  color: var(--muted);
  text-align: center;
  padding: 48px 0;
}
