:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --text: #1b2230;
  --muted: #6b7385;
  --line: #e1e5ee;
  --brand: #1f3f8f;
  --brand-text: #ffffff;
  --accent: #f2b705;
  --me: #fff6d6;
  --on: #2e9d5b;
  --off: #c9ced9;
  --danger: #d64545;
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11151d;
    --card: #1b212c;
    --text: #e8ecf3;
    --muted: #98a0b2;
    --line: #2b3240;
    --brand: #4b6fd1;
    --me: #3a3320;
    --on: #3fb873;
    --off: #3a4252;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  padding-bottom: calc(80px + env(safe-area-inset-bottom));
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; cursor: pointer; }
button.link { background: none; border: 0; color: var(--brand); padding: 6px 4px; }
button.primary {
  background: var(--brand); color: var(--brand-text); border: 0; border-radius: 999px;
  padding: 10px 22px; font-weight: 700;
}
button.primary:disabled { opacity: .45; cursor: default; }
button.wide { width: 100%; padding: 14px; font-size: 18px; }

.top {
  position: sticky; top: 0; z-index: 2;
  display: flex; align-items: center; gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--brand); color: var(--brand-text);
}
.top .logo { width: 36px; height: 36px; }
.top h1 { font-size: 19px; margin: 0; flex: 1; }
.top select {
  font: inherit; font-size: 15px; border-radius: 8px; border: 0; padding: 6px 8px; max-width: 45vw;
}

.me-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 16px; color: var(--muted); font-size: 14px;
}

main { padding: 0 12px; }
.season-range { margin: 0 4px 8px; color: var(--muted); font-size: 13px; }
.ranking { list-style: none; margin: 0; padding: 0; }
.ranking li {
  display: flex; align-items: center; gap: 12px;
  background: var(--card); border-radius: var(--radius);
  padding: 8px 12px; margin-bottom: 6px;
}
.ranking li.me { background: var(--me); outline: 2px solid var(--accent); }
.ranking li.zero { opacity: .6; }
.ranking .rank { width: 28px; text-align: center; font-weight: 700; color: var(--muted); }
.ranking li.top1 .rank, .ranking li.top2 .rank, .ranking li.top3 .rank { color: var(--accent); font-size: 18px; }
.ranking .name { flex: 1; font-weight: 600; }
.ranking .count { font-variant-numeric: tabular-nums; font-weight: 700; }
.ranking .count small { font-weight: 400; color: var(--muted); }
.empty { color: var(--muted); text-align: center; padding: 40px 0; }

.avatar {
  width: 44px; height: 44px; border-radius: 50%; flex: none;
  background: var(--line); object-fit: cover;
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 700; color: var(--muted);
}

.bottom {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 2;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: var(--card); border-top: 1px solid var(--line);
}
.today-count { color: var(--muted); font-size: 14px; }
.bottom button.primary { font-size: 18px; padding: 12px 28px; }

.overlay {
  position: fixed; inset: 0; z-index: 10;
  background: rgba(0, 0, 0, .45);
  display: flex; align-items: flex-end; justify-content: center;
}
.overlay[hidden] { display: none; }
.sheet {
  background: var(--card); width: 100%; max-width: 560px; max-height: 92vh;
  border-radius: 16px 16px 0 0; display: flex; flex-direction: column;
  padding: 14px 14px calc(10px + env(safe-area-inset-bottom));
}
@media (min-width: 600px) {
  .overlay { align-items: center; }
  .sheet { border-radius: 16px; }
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.sheet-head h2 { font-size: 19px; margin: 0; }
.sheet-head small { font-weight: 400; color: var(--muted); font-size: 14px; }
.hint { color: var(--muted); font-size: 13px; margin: 6px 0 8px; }
.quick { margin-top: 10px; text-align: center; }
.sheet-foot { display: flex; align-items: center; justify-content: space-between; padding-top: 10px; }
.save-bar { border-top: 1px solid var(--line); margin-top: 6px; }
#attend-summary { font-size: 15px; }

.grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px;
  overflow-y: auto; padding: 2px; flex: 1; min-height: 0;
}
.cell {
  position: relative; background: none; border: 2px solid transparent; border-radius: 10px;
  padding: 6px 2px 4px; display: flex; flex-direction: column; align-items: center; gap: 4px;
}
.cell .avatar { width: 60px; height: 60px; font-size: 22px; }
.cell .label { font-size: 13px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cell.selected { border-color: var(--accent); }
.cell.off .avatar { filter: grayscale(1); opacity: .5; }
.cell.on .avatar { box-shadow: 0 0 0 3px var(--on); }
.cell.on::after {
  content: "✓"; position: absolute; top: 4px; right: 10%;
  background: var(--on); color: #fff; border-radius: 50%;
  width: 20px; height: 20px; font-size: 13px; line-height: 20px; text-align: center;
}
.cell.changed { border-style: dashed; border-color: var(--brand); }
.cell.changed.off { border-color: var(--danger); }

.toast {
  position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  z-index: 20; background: rgba(20, 24, 32, .92); color: #fff; padding: 10px 18px; border-radius: 999px;
  font-size: 15px; max-width: calc(100vw - 32px);
}
