:root {
  --bg: #f6f5fb;
  --surface: #ffffff;
  --surface-2: #f1f0f9;
  --text: #1c1b29;
  --muted: #6b6980;
  --line: #d5d2e6;
  --primary: #6d5efc;
  --primary-soft: #ece9ff;
  --green: #2fb686;
  --green-soft: #dff6ee;
  --amber: #f0a838;
  --amber-soft: #fdf1dc;
  --red: #ef5f7a;
  --red-soft: #fde3e8;
  --radius: 16px;
  --radius-sm: 11px;
  --shadow: 0 1px 2px rgba(28, 27, 41, .08), 0 4px 14px rgba(28, 27, 41, .12);
  --shadow-lg: 0 12px 44px rgba(28, 27, 41, .22);
  --nav-h: 64px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "Apple SD Gothic Neo", "Noto Sans KR", Roboto, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; cursor: pointer; }
input, select { font-family: inherit; font-size: 16px; }

/* ---------- Layout ---------- */
#app { max-width: 720px; margin: 0 auto; min-height: 100vh; }
.screen { padding: 0 16px calc(var(--nav-h) + 28px); }
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: rgba(246, 245, 251, .82);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  padding: max(14px, env(safe-area-inset-top)) 16px 12px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.topbar h1 { font-size: 20px; font-weight: 720; margin: 0; letter-spacing: -.02em; }
.topbar .sub { font-size: 12.5px; color: var(--muted); margin-top: 1px; }
.chip-actor {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 999px; padding: 6px 12px; font-size: 13px; font-weight: 600;
  box-shadow: var(--shadow);
}
.chip-actor .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--green); }

/* ---------- Cards ---------- */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px; margin-bottom: 12px;
}
.card-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.section-title { font-size: 13px; font-weight: 700; color: var(--muted); margin: 22px 4px 10px; letter-spacing: .01em; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.empty { text-align: center; color: var(--muted); padding: 40px 16px; }
.empty .big { font-size: 34px; margin-bottom: 6px; }

/* ---------- Buttons ---------- */
.btn {
  border: none; border-radius: var(--radius-sm); padding: 11px 16px;
  font-weight: 650; font-size: 15px; background: var(--surface-2); color: var(--text);
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
}
.btn.primary { background: var(--primary); color: #fff; box-shadow: 0 6px 16px rgba(109, 94, 252, .32); }
.btn.ghost { background: transparent; color: var(--primary); }
.btn.danger { background: var(--red-soft); color: var(--red); }
.btn.block { width: 100%; }
.btn.sm { padding: 7px 12px; font-size: 13.5px; border-radius: 9px; }
.btn:active { transform: scale(.97); }
.fab {
  position: fixed; right: max(16px, env(safe-area-inset-right));
  bottom: calc(var(--nav-h) + 18px + env(safe-area-inset-bottom));
  z-index: 30; width: 56px; height: 56px; border-radius: 50%;
  background: var(--primary); color: #fff; border: none; font-size: 28px; line-height: 1;
  box-shadow: 0 10px 28px rgba(109, 94, 252, .45); display: grid; place-items: center;
}
.fab:active { transform: scale(.94); }

/* ---------- Segmented control (attendance) ---------- */
.seg { display: inline-flex; background: var(--surface-2); border-radius: 11px; padding: 3px; gap: 2px; }
.seg button {
  border: none; background: transparent; border-radius: 8px;
  padding: 7px 12px; font-size: 13.5px; font-weight: 650; color: var(--muted); min-width: 46px;
}
.seg button.on.on-time { background: var(--green); color: #fff; box-shadow: 0 2px 6px rgba(47,182,134,.35); }
.seg button.on.late { background: var(--amber); color: #fff; box-shadow: 0 2px 6px rgba(240,168,56,.35); }
.seg button.on.absent { background: var(--red); color: #fff; box-shadow: 0 2px 6px rgba(239,95,122,.3); }

.toggle-chip {
  border: 1.5px solid var(--line); background: var(--surface); color: var(--muted);
  border-radius: 999px; padding: 7px 13px; font-size: 13px; font-weight: 650;
  display: inline-flex; align-items: center; gap: 5px;
}
.toggle-chip.on { border-color: var(--primary); background: var(--primary-soft); color: var(--primary); }

/* ---------- Check-in student row ---------- */
.stu {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 13px; margin-bottom: 10px; box-shadow: var(--shadow);
}
.stu .top { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.stu .name { font-weight: 680; font-size: 16px; }
.stu .avatar {
  width: 34px; height: 34px; border-radius: 10px; background: var(--primary-soft);
  color: var(--primary); display: grid; place-items: center; font-weight: 720; font-size: 15px;
}
.stu .who { display: flex; align-items: center; gap: 10px; }
.stu .row2 { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.pts { font-size: 12.5px; font-weight: 700; color: var(--primary); }

/* ---------- Selector bar ---------- */
.selectbar { display: flex; gap: 8px; margin: 4px 0 8px; }
.selectbar .field { flex: 1; }
.field label { display: block; font-size: 12px; color: var(--muted); font-weight: 600; margin: 0 0 5px 3px; }
.field select, .field input, .field textarea {
  width: 100%; border: 1px solid var(--line); background: var(--surface);
  border-radius: 11px; padding: 11px 12px; color: var(--text); appearance: none;
  font-size: 16px; font-family: inherit; box-sizing: border-box;
}
.field textarea { resize: vertical; line-height: 1.4; }
.sunday-strip { display: flex; gap: 7px; overflow-x: auto; padding: 4px 0 8px; scrollbar-width: none; }
.sunday-strip::-webkit-scrollbar { display: none; }
.sunday-strip .sun {
  flex: 0 0 auto; border: 1px solid var(--line); background: var(--surface);
  border-radius: 12px; padding: 8px 12px; text-align: center; font-weight: 650; color: var(--muted); min-width: 52px;
}
.sunday-strip .sun.on { background: var(--primary); color: #fff; border-color: var(--primary); }
.sunday-strip .sun .d { font-size: 17px; font-weight: 740; }
.sunday-strip .sun .w { font-size: 10.5px; opacity: .85; }
.monthnav { display: flex; align-items: center; justify-content: center; gap: 14px; margin: 18px 0 10px; }
.monthnav button { border: none; background: var(--surface); border-radius: 10px; width: 34px; height: 34px; box-shadow: var(--shadow); font-size: 18px; color: var(--muted); }
.monthnav .m { font-weight: 700; font-size: 15px; min-width: 120px; text-align: center; }

/* ---------- Bottom nav ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 25;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: rgba(255,255,255,.9);
  backdrop-filter: saturate(180%) blur(14px); -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-top: 1px solid var(--line);
  display: flex; max-width: 720px; margin: 0 auto;
}
.tabbar button {
  flex: 1; border: none; background: transparent; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  font-size: 10.5px; font-weight: 600;
}
.tabbar button .ic { font-size: 21px; line-height: 1; }
.tabbar button.on { color: var(--primary); }

/* ---------- Pills / badges ---------- */
.pill { display: inline-block; background: var(--surface-2); color: var(--muted); border-radius: 999px; padding: 3px 9px; font-size: 12px; font-weight: 650; }
.pill.grade { background: var(--primary-soft); color: var(--primary); }
.pill.teacher { background: var(--amber-soft); color: #b9791a; }
.list-item.is-teacher .nm { color: #b9791a; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }

/* ---------- Tabs (manage) ---------- */
.tabs { display: flex; gap: 6px; background: var(--surface-2); padding: 4px; border-radius: 12px; margin: 4px 0 14px; }
.tabs button { flex: 1; border: none; background: transparent; border-radius: 9px; padding: 9px; font-weight: 650; color: var(--muted); font-size: 14px; }
.tabs button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 50; background: rgba(20,18,40,.42);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade .15s ease;
}
.modal {
  position: relative;
  background: var(--surface); width: 100%; max-width: 720px;
  border-radius: 22px 22px 0 0; padding: 0 18px calc(20px + env(safe-area-inset-bottom));
  box-shadow: var(--shadow-lg); animation: slideup .22s cubic-bezier(.2,.8,.2,1);
  max-height: 85vh; max-height: 85dvh; overflow-y: auto; overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
.modal-head { position: sticky; top: 0; z-index: 3; background: var(--surface); margin: 0 -18px 6px; padding: 8px 18px 6px; border-radius: 22px 22px 0 0; }
.modal .grab { width: 40px; height: 4px; background: var(--line); border-radius: 3px; margin: 2px auto 0; }
.modal-close {
  position: absolute; top: 4px; right: 12px; width: 34px; height: 34px;
  border: none; border-radius: 50%; background: var(--surface-2); color: var(--muted);
  font-size: 15px; display: grid; place-items: center; z-index: 4;
}
.modal-close:active { transform: scale(.92); }
.modal h2 { font-size: 18px; margin: 2px 0 16px; letter-spacing: -.01em; }
.modal .field { margin-bottom: 13px; }
.modal .actions { display: flex; gap: 9px; margin-top: 8px; }
.modal .actions .btn { flex: 1; }
@keyframes slideup { from { transform: translateY(30px); opacity: .4; } to { transform: translateY(0); opacity: 1; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* ---------- Identity gate ---------- */
.gate { min-height: 100vh; display: flex; flex-direction: column; justify-content: center; padding: 32px 22px; text-align: center; }
.gate .logo { width: 68px; height: 68px; margin: 0 auto 18px; }
.gate h1 { font-size: 22px; margin: 0 0 6px; letter-spacing: -.02em; }
.gate p { color: var(--muted); margin: 0 0 26px; }
.gate .who-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.gate .who-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 12px; font-weight: 680; box-shadow: var(--shadow); font-size: 15px;
}
.gate .who-card:active { transform: scale(.97); border-color: var(--primary); }
.gate .who-cls { display: block; font-size: 12px; color: var(--muted); font-weight: 600; margin-top: 3px; }

/* ---------- Stats ---------- */
.stat-cards { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin: 16px 0 6px; }
.stat-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.stat-card .k { font-size: 12.5px; color: var(--muted); font-weight: 600; }
.stat-card .v { font-size: 26px; font-weight: 760; letter-spacing: -.02em; margin-top: 2px; }
.stat-card .v small { font-size: 14px; color: var(--muted); font-weight: 600; }
.bar-row { display: flex; align-items: center; gap: 10px; padding: 9px 2px; border-bottom: 1px solid var(--line); }
.bar-row:last-child { border-bottom: none; }
.bar-row .nm { width: 78px; font-weight: 640; font-size: 14px; flex: 0 0 auto; }
.bar-track { flex: 1; height: 10px; background: var(--surface-2); border-radius: 6px; overflow: hidden; }
.bar-fill { height: 100%; background: linear-gradient(90deg, #8b7bff, var(--primary)); border-radius: 6px; }
.bar-row .val { width: 44px; text-align: right; font-weight: 720; font-size: 14px; color: var(--primary); }

.rank-row { display: flex; align-items: center; gap: 11px; padding: 11px 2px; border-bottom: 1px solid var(--line); }
.rank-row .rk { width: 24px; text-align: center; font-weight: 760; color: var(--muted); }
.rank-row .rk.top { color: var(--amber); }
.rank-row .nm { flex: 1; font-weight: 650; }
.rank-row .tl { font-weight: 760; color: var(--primary); }
.rank-row .tl small { color: var(--muted); font-weight: 600; font-size: 12px; }

.srow { display: flex; flex-direction: column; gap: 7px; padding: 11px 2px; border-bottom: 1px solid var(--line); }
.srow:last-child { border-bottom: none; }
.srow-main { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.srow .nm { font-weight: 650; font-size: 14.5px; min-width: 0; }
.srow .rate { font-weight: 760; font-size: 15px; }
.srow .rate.none { color: var(--muted); font-weight: 600; font-size: 13px; }
.mini { display: flex; gap: 5px; }
.mini .c { font-size: 11.5px; font-weight: 700; border-radius: 7px; padding: 3px 7px; white-space: nowrap; }
.mini .c.ontime { background: var(--green-soft); color: #1f8a63; }
.mini .c.late { background: var(--amber-soft); color: #b17b1c; }
.mini .c.absent { background: var(--red-soft); color: #d23f5b; }
.seg-tabs { display: flex; gap: 6px; background: var(--surface-2); padding: 4px; border-radius: 12px; margin: 12px 0 4px; }
.seg-tabs button { flex: 1; border: none; background: transparent; border-radius: 9px; padding: 9px; font-weight: 650; color: var(--muted); font-size: 14px; }
.seg-tabs button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.srow.clickable { cursor: pointer; }
.srow.clickable:active { background: var(--surface-2); }
.srow.clickable .nm::after { content: " ›"; color: var(--muted); font-weight: 700; }
.section-title .hint { font-weight: 500; color: var(--muted); font-size: 12px; }

/* talent leaderboard */
.lead-row { display: flex; align-items: center; gap: 11px; padding: 10px 3px; border-bottom: 1px solid var(--line); }
.lead-row:last-child { border-bottom: none; }
.lead-row .rk { width: 30px; text-align: center; font-weight: 760; font-size: 15px; color: var(--muted); flex: 0 0 auto; }
.lead-row.top1 .rk, .lead-row.top2 .rk, .lead-row.top3 .rk { font-size: 19px; }
.lead-row .body { flex: 1; min-width: 0; }
.lead-row .nm { display: flex; justify-content: space-between; gap: 8px; font-weight: 650; font-size: 14.5px; margin-bottom: 5px; }
.lead-row .tl { color: var(--primary); font-weight: 760; }
.lead-row .tl small { color: var(--muted); font-weight: 600; font-size: 11px; }
.lead-row .bar-track { height: 9px; background: var(--surface-2); border-radius: 6px; overflow: hidden; }
.lead-row .bar-fill { height: 100%; border-radius: 6px; background: linear-gradient(90deg, #8b7bff, var(--primary)); }
.lead-row.top1 .bar-fill { background: linear-gradient(90deg, #ffd76a, #f5a524); }
.lead-row.top2 .bar-fill { background: linear-gradient(90deg, #dbe0ee, #9aa6c4); }
.lead-row.top3 .bar-fill { background: linear-gradient(90deg, #f0c49a, #cf894f); }

/* class comparison column chart */
.colchart-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.colchart { display: flex; align-items: flex-end; gap: 12px; padding: 6px 2px 0; min-width: min-content; }
.col { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; flex: 0 0 auto; }
.col .cval { font-size: 11px; font-weight: 760; color: var(--primary); margin-bottom: 4px; }
.col .cbar { width: 30px; border-radius: 8px 8px 0 0; background: linear-gradient(180deg, #8b7bff, var(--primary)); }
.col .cname { font-size: 11px; margin-top: 6px; color: var(--text); font-weight: 650; text-align: center; white-space: nowrap; line-height: 1.3; }
.col .cavg { color: var(--muted); font-weight: 600; font-size: 10px; }

/* ---------- Detail table (grid) ---------- */
.grid-wrap { overflow: auto; max-height: 72vh; -webkit-overflow-scrolling: touch; border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); background: var(--surface); margin-top: 10px; }
table.grid { border-collapse: separate; border-spacing: 0; font-size: 12px; }
table.grid th, table.grid td { border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 5px 6px; text-align: center; white-space: nowrap; min-width: 30px; box-sizing: border-box; }
table.grid thead th { position: sticky; z-index: 5; height: 30px; background: var(--surface-2); font-weight: 700; }
table.grid thead tr:first-child th { top: 0; }
table.grid thead tr:nth-child(2) th { top: 30px; }
table.grid th.month-h { background: #eceaf7; }
table.grid .name-col { position: sticky; left: 0; background: var(--surface); text-align: left; font-weight: 650; min-width: 64px; }
table.grid td.name-col { z-index: 2; box-shadow: 1px 0 0 var(--line); }
table.grid thead th.name-col { z-index: 6; box-shadow: 1px 0 0 var(--line); }
table.grid td.p5 { background: #e2f6ee; color: #1f8a63; font-weight: 700; }
table.grid td.p3 { background: #fdf0da; color: #b17b1c; font-weight: 700; }
table.grid td.m3 { background: #e6e1ff; color: #5a45d8; font-weight: 700; }
table.grid td.m2 { background: #f1eefb; color: #7a6bd0; font-weight: 700; }
table.grid td.wb { color: var(--muted); background: #faf9fe; }
table.grid td.tal { font-weight: 760; color: var(--primary); background: #efedff; }
table.grid td.month-start, table.grid th.month-start { border-left: 2px solid #a9a3cf; }
table.grid tr.grp td { background: #f0eefb; text-align: left; font-weight: 700; padding: 7px 8px; border-left: none; }
.grp-label { position: sticky; left: 10px; display: inline-block; }

.bmonth { font-size: 13px; font-weight: 700; color: var(--muted); margin: 16px 4px 8px; }
.bmonth.now { color: var(--primary); }
.list-link { cursor: pointer; }
.list-link:active { transform: scale(.99); }
.stats-toolbar { display: flex; gap: 8px; justify-content: flex-end; margin: 12px 0 4px; }

@media print {
  .topbar, .tabbar, .fab, .stats-toolbar, .seg-tabs, .selectbar, #toast-root, #modal-root { display: none !important; }
  body { background: #fff; }
  #app { max-width: none; }
  .screen { padding: 0 !important; }
  .card { box-shadow: none; border: 1px solid #ccc; }
  .grid-wrap { max-height: none !important; overflow: visible !important; border: none; box-shadow: none; }
  table.grid thead th { position: static !important; }
  table.grid td.name-col, table.grid thead th.name-col { position: static !important; box-shadow: none !important; }
  .colchart-wrap { overflow: visible !important; }
}

/* ---------- Log ---------- */
.log-item { padding: 11px 2px; border-bottom: 1px solid var(--line); }
.log-item .l1 { font-size: 14px; }
.log-item .l2 { font-size: 12px; color: var(--muted); margin-top: 2px; }
.log-item .who { font-weight: 700; }

/* ---------- Toast ---------- */
#toast-root { position: fixed; left: 0; right: 0; bottom: calc(var(--nav-h) + 20px); display: flex; justify-content: center; z-index: 60; pointer-events: none; }
.toast { background: #232135; color: #fff; padding: 10px 16px; border-radius: 999px; font-size: 13.5px; font-weight: 600; box-shadow: var(--shadow-lg); animation: fade .15s ease; }

.list-item { display: flex; align-items: center; gap: 12px; padding: 12px 2px; border-bottom: 1px solid var(--line); }
.list-item:last-child { border-bottom: none; }
.list-item .grow { flex: 1; min-width: 0; }
.list-item .nm { font-weight: 660; }
.list-item .meta { font-size: 12.5px; color: var(--muted); margin-top: 1px; }
.icon-btn { border: none; background: var(--surface-2); border-radius: 9px; width: 34px; height: 34px; color: var(--muted); font-size: 15px; }
