:root {
  color-scheme: light;
  --bg: #efe7db;
  --bg-2: #e5d9c8;
  --surface: #fffaf4;
  --ink: #1b3048;
  --muted: #5e6a78;
  --line: #e4d8c8;
  --navy: #1b3048;
  --navy-2: #274868;
  --good: #0e7a4b;
  --good-bg: #e5f6ee;
  --bad: #a33b24;
  --bad-bg: #fdecea;
  --wait: #8a5a12;
  --wait-bg: #fff4e5;
  --shadow: 0 16px 40px rgba(48, 32, 16, 0.08);
  --radius: 22px;
  --font: "Outfit", sans-serif;
  --display: "Fraunces", serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(900px 420px at 10% -10%, #fff 0%, transparent 55%),
    linear-gradient(180deg, #f6f0e7 0%, var(--bg) 40%, #e7dccb 100%);
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
}
button, a, summary { touch-action: manipulation; }

button, input, select, textarea {
  font: inherit;
  color: var(--ink);
  -webkit-text-fill-color: var(--ink);
}
a { color: inherit; }

.shell {
  width: min(920px, calc(100% - 20px));
  margin: 0 auto;
  padding: calc(12px + env(safe-area-inset-top)) 0 calc(128px + env(safe-area-inset-bottom));
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  text-decoration: none;
}
.brand strong { display: block; font-size: 16px; letter-spacing: -0.02em; }
.brand small { color: var(--muted); }
.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  background: var(--navy);
  color: #f6efe4;
  font-family: var(--display);
  font-size: 22px;
}

h1 {
  font-family: var(--display);
  font-weight: 620;
  font-size: clamp(30px, 8vw, 48px);
  letter-spacing: -0.03em;
  margin: 0;
  line-height: 1.05;
}
h2 {
  margin: 28px 0 12px;
  font-size: 18px;
}
.eyebrow {
  margin: 0 0 6px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
}
.lead { color: var(--muted); margin-top: 8px; line-height: 1.45; }
.title-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 18px 0;
}
.stats article {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 14px 14px 12px;
  box-shadow: var(--shadow);
}
.stats b {
  display: block;
  font-family: var(--display);
  font-size: clamp(28px, 8vw, 36px);
  line-height: 1;
}
.stats span { color: var(--muted); font-size: 14px; }
.stats .good b { color: var(--good); }
.stats .bad b { color: var(--bad); }

.progress-block { margin: 8px 0 16px; }
.progress-label { display: flex; justify-content: space-between; font-size: 14px; margin-bottom: 8px; }
.bar {
  height: 10px;
  background: #e7dccb;
  border-radius: 99px;
  overflow: hidden;
}
.bar span { display: block; height: 100%; background: var(--good); border-radius: 99px; }

.room-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
.room-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-height: 112px;
  padding: 14px;
  text-decoration: none;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
}
.room-card.is-done { background: #f3fbf6; border-color: #c9ead8; }
.room-card.is-alert { background: #fff6f4; border-color: #f3cfc7; }
.room-no {
  font-family: var(--display);
  font-size: 32px;
  line-height: 1;
}
.room-meta { color: var(--muted); font-size: 13px; }

.pill {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  border-radius: 999px;
  padding: 4px 8px;
  background: var(--wait-bg);
  color: var(--wait);
  font-size: 12px;
  font-weight: 600;
}
.pill.ok { background: var(--good-bg); color: var(--good); }
.pill.bad { background: var(--bad-bg); color: var(--bad); }

.btn {
  border: 0;
  cursor: pointer;
  border-radius: 16px;
  padding: 14px 16px;
  text-decoration: none;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  font-weight: 650;
}
.btn.primary { background: var(--navy); color: #f8f3eb; -webkit-text-fill-color: #f8f3eb; }
.btn.ghost { background: transparent; color: var(--navy); border: 1px solid #c9bba8; }
.btn.block { width: 100%; margin: 8px 0 4px; }
.btn:disabled, button:disabled { opacity: 0.55; cursor: not-allowed; }

.actions {
  position: sticky;
  bottom: calc(86px + env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 16px;
  background: rgba(239, 231, 219, 0.92);
  padding-top: 8px;
}
.actions.column { grid-template-columns: 1fr; position: static; background: transparent; }
.actions form { margin: 0; }
.actions .btn { width: 100%; }

.student-list { display: flex; flex-direction: column; gap: 8px; }
.student {
  width: 100%;
  text-align: left;
  display: grid;
  grid-template-columns: 32px 1fr auto;
  gap: 10px;
  align-items: center;
  min-height: 68px;
  padding: 12px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: var(--surface);
  cursor: pointer;
}
.student.is-absent {
  background: var(--bad-bg);
  border-color: #f0c2b8;
}
.idx {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: #f3ebe1;
  font-weight: 700;
}
.who { display: flex; flex-direction: column; min-width: 0; }
.who strong, .roster strong, .person-row span, .people span {
  color: var(--ink);
  -webkit-text-fill-color: var(--ink);
}
.who strong { font-size: 15px; line-height: 1.25; }
.who em { color: var(--muted); font-style: normal; font-size: 13px; }
.state {
  font-weight: 700;
  font-size: 13px;
  color: var(--good);
}
.is-absent .state { color: var(--bad); }

.people { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.people a, .recipient {
  display: flex;
  gap: 12px;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 12px 14px;
  text-decoration: none;
}
.people b {
  min-width: 42px;
  font-family: var(--display);
  font-size: 20px;
}
.people span, .recipient span { color: var(--muted); }
.recipient { justify-content: space-between; }

.messages { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.msg {
  margin: 0;
  padding: 12px 14px;
  border-radius: 14px;
  background: #fff;
  border: 1px solid var(--line);
}
.msg.success { background: var(--good-bg); color: #0d5c39; }
.msg.error { background: var(--bad-bg); color: #8a2e1c; }
.msg.warning { background: var(--wait-bg); color: #7a4e0d; }

.empty {
  background: rgba(255, 250, 244, 0.7);
  border: 1px dashed #d9cbb8;
  border-radius: 16px;
  padding: 14px;
  color: var(--muted);
}

.back { color: var(--navy-2); text-decoration: none; font-weight: 600; font-size: 14px; }

.report {
  white-space: pre-wrap;
  background: var(--navy);
  color: #f6efe4;
  border-radius: 18px;
  padding: 16px;
  line-height: 1.45;
  font-family: "Outfit", sans-serif;
  font-size: 14px;
}

.notice {
  background: var(--wait-bg);
  border-radius: 18px;
  padding: 14px;
  margin: 12px 0;
}
.notice p { margin: 6px 0 10px; color: #6d5420; }
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  background: white;
  border-radius: 999px;
  padding: 6px 10px;
  text-decoration: none;
  font-weight: 700;
}

.history-list { display: flex; flex-direction: column; gap: 10px; }
.history-card {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  text-decoration: none;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 14px;
}
.history-card small, .history-counts { color: var(--muted); }
.history-counts { display: flex; flex-direction: column; align-items: flex-end; font-size: 13px; }
.bad-text { color: var(--bad); font-weight: 700; }
.history-card em { font-style: normal; }

.roster {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 12px 14px;
  margin-bottom: 10px;
}
.fold { margin: 0 0 12px; }
.fold > summary.btn { display: flex; align-items: center; justify-content: center; cursor: pointer; list-style: none; }
.fold > summary.btn::-webkit-details-marker { display: none; }
.fold[open] > summary { margin-bottom: 10px; }
.person-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}
.person-row:last-child { border-bottom: 0; }
.js-confirm-delete { display: flex; gap: 8px; align-items: center; }
.js-confirm-delete[hidden] { display: none; }

.roster summary {
  display: flex;
  justify-content: space-between;
  cursor: pointer;
  font-size: 16px;
}
.roster ol { margin: 10px 0 0; padding-left: 18px; }
.roster li { margin: 8px 0; }
.roster small { display: block; color: var(--muted); }

.stack { display: flex; flex-direction: column; gap: 12px; }
.card-form, .login-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: 14px; }
input, select {
  border: 1px solid #d9cbb8;
  background: #fff;
  border-radius: 12px;
  padding: 14px 12px;
  font-weight: 500;
  font-size: 16px;
}
.field-error { color: var(--bad); font-weight: 500; }
.text-btn {
  border: 0;
  background: transparent;
  color: var(--navy);
  font-weight: 650;
  cursor: pointer;
  padding: 8px;
}
.text-btn.danger { color: var(--bad); }

.tabbar {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(8px + env(safe-area-inset-bottom));
  width: min(640px, calc(100% - 16px));
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
  padding: 6px;
  background: rgba(27, 48, 72, 0.96);
  border-radius: 20px;
  z-index: 5;
}
.tabbar a {
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  text-decoration: none;
  color: #d5deea;
  font-size: 12px;
  font-weight: 600;
  padding: 8px 2px;
  border-radius: 14px;
}
.tabbar a.active { background: #f6efe4; color: var(--navy); }

.login-body {
  display: grid;
  place-items: center;
  padding: calc(24px + env(safe-area-inset-top)) 16px calc(24px + env(safe-area-inset-bottom));
}
.login-card { width: min(440px, 100%); }
.login-card h1 { margin-bottom: 8px; }
.tg-id {
  margin: 0;
  font-weight: 700;
  background: var(--wait-bg);
  border-radius: 12px;
  padding: 10px 12px;
}

@media (max-width: 480px) {
  .room-grid { gap: 8px; }
  .room-card { min-height: 108px; padding: 12px; }
  .room-no { font-size: 28px; }
  .stats article { padding: 12px 10px; }
  .who strong { font-size: 14px; }
  .btn { min-height: 48px; }
}

@media (min-width: 800px) {
  .room-grid { grid-template-columns: repeat(5, 1fr); }
  .shell { padding-top: 28px; padding-bottom: 40px; }
  .tabbar {
    position: static;
    transform: none;
    width: 100%;
    margin: 0 0 18px;
  }
  .actions { bottom: 16px; position: static; background: transparent; }
}
