/* Mobile-first styling. Phone and tablet are the primary targets; the layout
   simply gains a wider centred column on larger screens. */

:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-alt: #eef1f8;
  --text: #1b1f2a;
  --text-muted: #666e80;
  --border: #dfe3ed;
  --accent: #4f7cff;
  --accent-contrast: #ffffff;
  --success: #2f9e5d;
  --warning: #c98014;
  --danger: #d2453d;
  --radius: 14px;
  --tap: 48px;
  --shadow: 0 1px 2px rgba(20, 26, 44, 0.06), 0 6px 20px rgba(20, 26, 44, 0.06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171f;
    --surface: #1d212b;
    --surface-alt: #262b38;
    --text: #eef1f7;
    --text-muted: #9aa3b5;
    --border: #2f3542;
    --accent: #6d92ff;
    --success: #4cbd7b;
    --warning: #e0a044;
    --danger: #ef6a62;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  /* Room for the fixed tab bar plus the iOS home indicator. */
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}

.app { max-width: 720px; margin: 0 auto; }

.loading, .empty {
  color: var(--text-muted);
  text-align: center;
  padding: 2rem 1rem;
}

/* --- header --- */

.header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  padding: calc(1rem + env(safe-area-inset-top)) 1rem 0.5rem;
}
.header h1 { font-size: 1.4rem; margin: 0; white-space: nowrap; }
.header .date {
  color: var(--text-muted);
  font-size: 0.85rem;
  text-align: right;
  white-space: nowrap;
}

main { padding: 0 1rem 1rem; }

/* --- cards --- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem;
  margin-bottom: 0.75rem;
}
.card h2 { font-size: 1.05rem; margin: 0 0 0.75rem; }
.card h3 { font-size: 0.95rem; margin: 0 0 0.5rem; }

.section-title {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin: 1.5rem 0 0.5rem;
}

/* --- progress --- */

.progress {
  height: 10px;
  border-radius: 999px;
  background: var(--surface-alt);
  overflow: hidden;
  margin: 0.5rem 0;
}
.progress > span {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: var(--accent);
  width: var(--value, 0%);
  transition: width 0.25s ease;
}
.progress.is-complete > span { background: var(--success); }

.muted { color: var(--text-muted); font-size: 0.9rem; }

/* --- study blocks --- */

.block {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  min-height: var(--tap);
  padding: 0.75rem;
  margin-bottom: 0.5rem;
  border: 1px solid var(--border);
  border-left: 5px solid var(--subject-color, var(--accent));
  border-radius: var(--radius);
  background: var(--surface);
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.block:active { transform: scale(0.99); }
.block.is-done { opacity: 0.55; }
.block.is-done .block-title { text-decoration: line-through; }

.block-check {
  flex: 0 0 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid var(--border);
  display: grid;
  place-items: center;
  font-size: 1rem;
  color: transparent;
}
.block.is-done .block-check {
  background: var(--success);
  border-color: var(--success);
  color: #fff;
}
.block-body { flex: 1 1 auto; min-width: 0; }
.block-title {
  display: block;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.block-meta {
  display: block;
  color: var(--text-muted);
  font-size: 0.85rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.block-minutes {
  flex: 0 0 auto;
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
  font-size: 0.85rem;
}
.tag {
  display: inline-block;
  font-size: 0.72rem;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  background: var(--surface-alt);
  color: var(--text-muted);
  margin-left: 0.35rem;
}

/* --- week view --- */

.week-nav { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; }
.day-group { margin-bottom: 1rem; }
.day-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 0.35rem;
  font-weight: 600;
}
.day-head.is-today { color: var(--accent); }
.day-head .load { font-weight: 400; color: var(--text-muted); font-size: 0.85rem; }

/* --- exams --- */

.exam-row {
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
  border-left: 5px solid var(--subject-color, var(--accent));
  padding-left: 0.75rem;
}
.exam-row + .exam-row { margin-top: 1rem; padding-top: 1rem; border-top: 1px solid var(--border); }
.countdown {
  flex: 0 0 auto;
  text-align: center;
  min-width: 56px;
  background: var(--surface-alt);
  border-radius: var(--radius);
  padding: 0.35rem 0.5rem;
}
.countdown strong { display: block; font-size: 1.25rem; line-height: 1.1; }
.countdown span { font-size: 0.7rem; color: var(--text-muted); }

/* --- forms --- */

label { display: block; font-weight: 600; font-size: 0.9rem; margin: 0.85rem 0 0.25rem; }
input, select, textarea {
  width: 100%;
  min-height: var(--tap);
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}
textarea { min-height: 96px; resize: vertical; }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.choice-group { display: flex; gap: 0.5rem; }
.choice-group label {
  flex: 1;
  margin: 0;
  text-align: center;
  padding: 0.7rem 0.25rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  min-height: var(--tap);
  display: grid;
  place-items: center;
}
.choice-group input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.choice-group input:checked + span { color: var(--accent-contrast); }
.choice-group label:has(input:checked) { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }

button {
  min-height: var(--tap);
  padding: 0.6rem 1rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }
button.danger { color: var(--danger); }
button.ghost { background: transparent; border-color: transparent; color: var(--accent); }
button[disabled] { opacity: 0.6; cursor: default; }
.button-row { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-top: 1rem; }
.button-row button { flex: 1 1 auto; }

/* --- invite codes --- */

/*
 * The code is read off one screen and typed on another, so it gets the room and
 * the letter spacing of something meant to be copied by hand.
 */
.invite-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: 0.22em;
  text-align: center;
  margin: 0.75rem 0 0.25rem;
  user-select: all;
}
ul.plain { list-style: none; padding: 0; margin: 0.35rem 0 0; }
ul.plain li { padding: 0.35rem 0; border-bottom: 1px solid var(--border); }
ul.plain li:last-child { border-bottom: none; }

/* --- notices --- */

.notice {
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  margin-bottom: 0.75rem;
  font-size: 0.92rem;
  border: 1px solid var(--border);
  background: var(--surface-alt);
}
.notice.warn { border-color: var(--warning); color: var(--warning); }
.notice.error { border-color: var(--danger); color: var(--danger); }
.notice.ok { border-color: var(--success); color: var(--success); }

/* --- traffic light --- */

.light { display: inline-flex; align-items: center; gap: 0.35rem; font-size: 0.85rem; }
.light::before {
  content: '';
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--success);
}
.light.amber::before { background: var(--warning); }
.light.red::before { background: var(--danger); }

/* --- tab bar --- */

.tabs {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 10;
}
.tabs button {
  flex: 1 1 0;
  /* Five tabs have to share a narrow phone screen without clipping a label. */
  min-width: 0;
  border: none;
  border-radius: 0;
  background: none;
  min-height: 64px;
  padding: 0 0.15rem;
  font-size: 0.66rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.2rem;
}
.tabs .label {
  display: block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tabs button.is-active { color: var(--accent); }
.tabs .icon { display: block; width: 22px; height: 22px; }
.tabs .icon svg { width: 100%; height: 100%; display: block; }

/* --- dialog --- */

.sheet {
  position: fixed;
  inset: 0;
  background: rgba(10, 13, 20, 0.5);
  display: grid;
  place-items: end center;
  z-index: 20;
}
.sheet-inner {
  background: var(--surface);
  width: 100%;
  max-width: 720px;
  max-height: 85vh;
  overflow-y: auto;
  border-radius: 20px 20px 0 0;
  padding: 1.25rem 1rem calc(1.25rem + env(safe-area-inset-bottom));
}

/* --- login --- */

.login { padding: 3rem 1rem; }
.login .card { margin-top: 1rem; }

/* --- settings --- */

.capacity-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}
.capacity-row span { flex: 0 0 3rem; font-weight: 600; }
.capacity-row input { flex: 1; }

.subject-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-height: var(--tap);
  border-bottom: 1px solid var(--border);
}
.subject-row .dot { width: 14px; height: 14px; border-radius: 50%; background: var(--subject-color); flex: 0 0 auto; }
.subject-row .name { flex: 1; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
