:root {
  --paper: #f3ecdf;
  --card: #fffaf4;
  --ink: #2a2622;
  --muted: #6f675e;
  --line: #e4d9c8;
  --sage: #2f5d4a;
  --sage-deep: #1e4034;
  --sand: #efe2c6;
  --sand-ink: #6a4b24;
  --late: #8a6232;
  --late-bg: #f6e6cf;
  --absent: #8d403c;
  --absent-bg: #f6ddd8;
  --shadow: 0 10px 30px rgba(62, 44, 24, 0.06);
  --sans: "Avenir Next", "Segoe UI", sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --nav: 4.6rem;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
img { max-width: 100%; }

.shell {
  min-height: 100%;
  display: flex;
  flex-direction: column;
}
.main {
  width: min(760px, 100%);
  margin: 0 auto;
  padding: 1.1rem 1rem calc(var(--nav) + 1.4rem);
  flex: 1;
}

.top {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 1rem;
  margin-bottom: 1rem;
}
.kicker {
  margin: 0 0 0.15rem;
  color: var(--muted);
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
h1, h2, h3 { font-family: var(--serif); font-weight: 600; letter-spacing: -0.02em; }
h1 { margin: 0; font-size: 2rem; line-height: 1.1; }
h2 { margin: 0 0 0.35rem; font-size: 1.35rem; }
h3 { margin: 0; font-size: 1.05rem; }
p { margin: 0.35rem 0; }
.muted { color: var(--muted); }
.small { font-size: 0.92rem; }

.who, .ghost, .solid, .texty, .level, .mark, .pill, .icon-btn {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 999px;
}
.who {
  padding: 0.55rem 0.85rem;
  text-align: right;
  line-height: 1.15;
}
.who small { display: block; color: var(--muted); font-size: 0.72rem; }
.sync {
  margin: -0.35rem 0 1rem;
  color: var(--muted);
  font-size: 0.85rem;
}
.banner {
  background: var(--sand);
  color: var(--sand-ink);
  border-radius: 14px;
  padding: 0.75rem 0.9rem;
  margin-bottom: 0.9rem;
  font-size: 0.92rem;
}

.card, .row, .child-card, .material-row {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
}
.card { padding: 1rem; margin-bottom: 0.8rem; }
.stack { display: flex; flex-direction: column; gap: 0.55rem; }
.row-between, .child-card, .material-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
}

.child-card, .material-row {
  width: 100%;
  text-align: left;
  padding: 0.9rem 1rem;
  margin-bottom: 0.65rem;
}
.child-card {
  flex-direction: column;
  align-items: stretch;
}
.child-card strong, .material-row strong { display: block; font-size: 1.05rem; }
.bar {
  display: flex;
  height: 8px;
  border-radius: 99px;
  overflow: hidden;
  background: #ece3d4;
  margin-top: 0.55rem;
}
.bar i { display: block; height: 100%; }
.bar .s1 { background: #e4d3b0; }
.bar .s2 { background: #c4a574; }
.bar .s3 { background: var(--sage); }

.pills, .filters {
  display: flex;
  gap: 0.45rem;
  overflow-x: auto;
  padding-bottom: 0.2rem;
  margin: 0.2rem 0 0.8rem;
}
.pill, .filters button {
  flex: 0 0 auto;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: transparent;
  padding: 0.45rem 0.75rem;
}
.pill.on, .filters button.on, .mark.on {
  background: var(--sage);
  color: white;
  border-color: var(--sage);
}

.levels, .marks {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.4rem;
  margin-top: 0.65rem;
}
.level, .mark {
  min-height: 46px;
  border-radius: 12px;
  font-weight: 600;
}
.mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
}
.mark-icon {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.attend-row {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  width: 100%;
  text-align: left;
  padding: 0.9rem 1rem;
  margin-bottom: 0.65rem;
}
.attend-who {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  min-width: 0;
}
.attend-who strong {
  font-size: 1.05rem;
  min-width: 0;
}
.attend-num {
  flex: 0 0 auto;
  width: 1.85rem;
  height: 1.85rem;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: #fff1d6;
  color: #7a5600;
  font-weight: 700;
  font-size: 0.92rem;
}
.level.on-1 { background: white; color: var(--sage); border-color: var(--sage); }
.level.on-2 { background: var(--sand); color: var(--sand-ink); border-color: #e2d0ae; }
.level.on-3 { background: var(--sage); color: white; border-color: var(--sage); }
.mark.present.on { background: var(--sage); color: white; border-color: var(--sage); }
.mark.late.on { background: var(--late-bg); color: var(--late); border-color: #e6d0ad; }
.mark.absent.on { background: var(--absent-bg); color: var(--absent); border-color: #ecc8c2; }

.group-label {
  margin: 0.9rem 0 0.4rem;
  color: var(--muted);
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.solid, .ghost, .texty, .danger {
  border-radius: 12px;
  min-height: 46px;
  padding: 0.55rem 0.9rem;
}
.solid { background: var(--sage); color: white; border: 0; }
.ghost { background: var(--card); }
.texty, .danger {
  background: transparent;
  border: 0;
  color: var(--sage-deep);
  min-height: 40px;
  padding-left: 0;
  padding-right: 0;
}
.danger { color: var(--absent); }
.actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.8rem; }
.actions .solid, .actions .ghost { flex: 1; }

label { display: block; font-size: 0.85rem; color: var(--muted); margin: 0.7rem 0 0.25rem; }
input[type="text"], input[type="date"], input[type="search"], select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: white;
  border-radius: 12px;
  padding: 0.7rem 0.75rem;
  font-size: 16px;
}
textarea { min-height: 88px; resize: vertical; }
.search { margin-bottom: 0.7rem; }

.nav {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.15rem;
  padding: 0.35rem 0.4rem calc(0.35rem + env(safe-area-inset-bottom));
  background: rgba(255, 250, 244, 0.96);
  border-top: 1px solid var(--line);
  z-index: 5;
}
.nav button {
  border: 0;
  background: transparent;
  border-radius: 12px;
  padding: 0.35rem 0.1rem 0.25rem;
  color: var(--muted);
  font-size: 0.68rem;
}
.nav button.on { color: var(--sage-deep); background: #e7f0eb; }
.nav svg { display: block; margin: 0 auto 0.12rem; }

.sheet-back {
  position: fixed;
  inset: 0;
  background: rgba(42, 38, 34, 0.35);
  z-index: 8;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.sheet {
  width: min(760px, 100%);
  max-height: min(88vh, 720px);
  overflow: auto;
  background: var(--card);
  border-radius: 22px 22px 0 0;
  padding: 0.7rem 1rem calc(1rem + env(safe-area-inset-bottom));
}
.handle {
  width: 42px;
  height: 4px;
  border-radius: 99px;
  background: var(--line);
  margin: 0.2rem auto 0.8rem;
}
.history { list-style: none; padding: 0; margin: 0.6rem 0 0; }
.history li {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.45rem 0;
  border-top: 1px solid var(--line);
  font-size: 0.92rem;
}
.area-block { margin-bottom: 1rem; }
.counts { color: var(--muted); font-size: 0.88rem; margin-top: 0.35rem; }
.empty { padding: 0.4rem 0 0.2rem; }
.warn { border-color: #e2d0ae; }
:focus-visible { outline: 2px solid var(--sage); outline-offset: 2px; }
.card > .solid, .main > .solid { width: 100%; }
.form-error { color: var(--absent); margin: 0.6rem 0 0; }
.recorder-row { display: flex; gap: 0.45rem; align-items: center; margin: 0.45rem 0; }
.recorder-row input { flex: 1; }
.recorder-row .pill, .recorder-row .danger { flex: 0 0 auto; min-height: 42px; padding: 0.35rem 0.7rem; }

@media (min-width: 900px) {
  .shell { flex-direction: row; }
  .nav {
    position: sticky;
    top: 0;
    height: 100vh;
    width: 168px;
    display: flex;
    flex-direction: column;
    border-top: 0;
    border-right: 1px solid var(--line);
    padding: 1rem 0.6rem;
  }
  .nav button { font-size: 0.95rem; text-align: left; padding: 0.7rem 0.75rem; }
  .nav svg { display: inline-block; vertical-align: -4px; margin: 0 0.45rem 0 0; }
  .main { padding: 1.6rem 1.4rem 2rem; }
  .sheet-back { align-items: center; }
  .sheet { border-radius: 22px; margin: 1rem; }
}

@media (min-width: 760px) {
  .attend-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    align-items: center;
    gap: 0.85rem;
  }
  .attend-row .marks {
    margin-top: 0;
  }
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.class-switch { margin-top: 0.45rem; }
