:root {
  --brand: #f59e0b;
  --brand-dark: #d97706;
  --present: #16a34a;
  --present-soft: #dcfce7;
  --bible: #7c3aed;
  --bible-soft: #ede9fe;
  --prayer: #2563eb;
  --prayer-soft: #dbeafe;
  --bg: #f6f7f9;
  --card: #ffffff;
  --ink: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --danger: #dc2626;
  --radius: 18px;
  --pad: 16px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard",
    "Malgun Gothic", "Segoe UI", Roboto, sans-serif;
  font-size: 17px;
  line-height: 1.4;
  -webkit-text-size-adjust: 100%;
  /* Native app feel: no page bounce, no text selection / long-press callout on chrome */
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
/* Re-enable selection/callout only where it's useful */
input, textarea, select, [contenteditable] { -webkit-user-select: text; user-select: text; }
[hidden] { display: none !important; }

/* App shell: fixed header + scrolling content + fixed bottom tab bar */
#appRoot { display: flex; flex-direction: column; height: 100%; position: relative; }

/* Pull-to-refresh indicator */
.ptr {
  position: absolute; top: calc(var(--safe-top) + 54px); left: 50%;
  transform: translateX(-50%); opacity: 0;
  width: 38px; height: 38px; border-radius: 50%;
  background: var(--card); color: var(--brand-dark);
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; font-weight: 700;
  box-shadow: 0 2px 10px rgba(0,0,0,0.18);
  z-index: 5; pointer-events: none; transition: opacity 0.15s ease;
}
.ptr.ready { color: var(--present); }

/* ---------- Login ---------- */
.login {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  padding: calc(24px + var(--safe-top)) 24px calc(24px + var(--safe-bottom));
  overflow-y: auto;
  background: linear-gradient(160deg, #fbbf24, #d97706);
}
.login-card {
  width: 100%; max-width: 380px;
  background: var(--card);
  border-radius: 24px;
  padding: 32px 24px calc(24px + var(--safe-bottom));
  box-shadow: 0 20px 50px rgba(0,0,0,0.25);
  text-align: center;
}
.login-mark {
  width: 64px; height: 64px; margin: 0 auto 12px;
  display: flex; align-items: center; justify-content: center;
  background: var(--brand); color: #fff;
  border-radius: 20px; font-size: 34px;
}
.login-card h1 { margin: 0 0 4px; font-size: 24px; font-weight: 800; }
.login-sub { margin: 0 0 24px; color: var(--muted); font-size: 15px; }
.login-error { color: var(--danger); font-size: 14px; font-weight: 600; margin: 4px 0 0; }

/* ---------- App bar ---------- */
.appbar {
  flex: 0 0 auto; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(var(--safe-top) + 14px) var(--pad) 14px;
  background: var(--brand); color: #fff;
}
.appbar h1 { font-size: 20px; font-weight: 800; margin: 0; letter-spacing: -0.01em; }
.appbar-right { display: flex; align-items: center; gap: 10px; }
.sync-dot { width: 11px; height: 11px; border-radius: 50%; background: #86efac; box-shadow: 0 0 0 3px rgba(255,255,255,0.25); transition: background 0.3s; }
.sync-dot.stale { background: #fca5a5; }
.icon-btn {
  background: rgba(255,255,255,0.22); border: none; color: #fff;
  width: 40px; height: 40px; border-radius: 50%; font-size: 20px; cursor: pointer;
}

/* ---------- Bottom tab bar (iOS-style) ---------- */
.tabbar {
  flex: 0 0 auto; z-index: 10;
  display: flex;
  padding-bottom: var(--safe-bottom);
  background: rgba(255, 255, 255, 0.82);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-top: 1px solid var(--line);
}
.tab {
  flex: 1; background: none; border: none; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  padding: 8px 4px 6px; color: var(--muted);
  font-size: 11px; font-weight: 600;
  transition: color 0.12s ease;
}
.tab svg {
  width: 26px; height: 26px; fill: none;
  stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}
.tab.active { color: var(--brand-dark); }
.tab:active { opacity: 0.6; }

/* ---------- Layout ---------- */
main {
  flex: 1 1 auto; min-height: 0;
  overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
  padding: var(--pad); padding-bottom: 32px;
  max-width: 640px; width: 100%; margin: 0 auto;
}
.view { display: none; }
.view.active { display: block; }
.controls { margin-bottom: 16px; }

/* Date / month stepper */
.field-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.field-label { font-size: 13px; color: var(--muted); font-weight: 700; }
.date-stepper { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.date-stepper input {
  flex: 1; min-width: 0; text-align: center;
  font-size: 17px; padding: 13px 10px; border: 1px solid var(--line);
  border-radius: 12px; background: var(--card); color: var(--ink);
}
.date-stepper input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(245,158,11,0.2); }
.step-btn {
  flex: 0 0 auto; width: 50px; height: 50px; border: 1px solid var(--line);
  border-radius: 12px; background: var(--card); color: var(--ink);
  font-size: 26px; font-weight: 700; line-height: 1; cursor: pointer;
  transition: transform 0.08s ease;
}
.step-btn:active { transform: scale(0.94); }

/* Tap feedback + view transition (native feel) */
.att-toggle, .primary-btn, .report-btn, .menu-item, .icon-btn { transition: transform 0.08s ease, background 0.12s ease, border-color 0.12s ease; }
.att-toggle:active, .primary-btn:active, .report-btn:active, .menu-item:active, .icon-btn:active { transform: scale(0.97); }
.check-btn:active { transform: scale(0.94); }
.view.active { animation: viewIn 0.2s ease; }
@keyframes viewIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.field span { font-size: 13px; color: var(--muted); font-weight: 700; }
.field input {
  font-size: 17px; padding: 13px 14px; border: 1px solid var(--line);
  border-radius: 12px; background: var(--card); color: var(--ink); width: 100%;
}
.field input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(245,158,11,0.2); }

.summary { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.quick { display: flex; gap: 4px; }

/* Telegram report button */
.report-btn {
  display: block; width: 100%; margin-top: 18px; padding: 15px 20px;
  border: none; border-radius: 14px; background: #229ed9; color: #fff;
  font-size: 16px; font-weight: 800; cursor: pointer;
}
.report-btn:active { background: #1b87ba; }
.report-btn:disabled { opacity: 0.6; }
.count { font-size: 16px; color: var(--muted); }
.count strong { color: var(--ink); font-size: 22px; }
.pill { display: inline-flex; align-items: center; gap: 5px; padding: 6px 12px; border-radius: 999px; font-size: 14px; font-weight: 700; margin-right: 6px; }
.pill.bible { background: var(--bible-soft); color: var(--bible); }
.pill.prayer { background: var(--prayer-soft); color: var(--prayer); }
.pill strong { font-size: 16px; }

.text-btn { background: none; border: none; color: var(--brand-dark); font-weight: 700; font-size: 15px; cursor: pointer; padding: 6px; }
.hint { color: var(--muted); font-size: 14px; line-height: 1.5; margin: 0 0 8px; }

/* ---------- Child list ---------- */
.child-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.child-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px 16px; min-height: 64px;
  transition: background 0.15s, border-color 0.15s;
}
.child-name { font-size: 19px; font-weight: 700; flex: 1; }
.child-row.flash { animation: flash 1s ease; }
@keyframes flash { 0% { background: #fef3c7; } 100% { background: var(--card); } }

/* Attendance toggle */
.att-toggle {
  border: 2px solid var(--line); background: var(--card); color: var(--muted);
  border-radius: 12px; padding: 12px 20px; font-size: 17px; font-weight: 800;
  min-width: 100px; cursor: pointer; transition: all 0.12s ease;
}
.child-row.present { background: var(--present-soft); border-color: var(--present); }
.child-row.present .att-toggle { background: var(--present); border-color: var(--present); color: #fff; }

/* Checks */
.check-controls { display: flex; gap: 10px; }
.check-btn {
  border: 2px solid var(--line); background: var(--card); border-radius: 12px;
  padding: 8px 10px; min-width: 76px; cursor: pointer; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: 2px; line-height: 1.1;
}
.check-btn .lbl { font-size: 12px; font-weight: 700; }
.check-btn .val { font-size: 18px; font-weight: 800; }
.check-btn.on.bible { background: var(--bible); border-color: var(--bible); color: #fff; }
.check-btn.on.prayer { background: var(--prayer); border-color: var(--prayer); color: #fff; }
.checks .child-row { flex-wrap: wrap; }
.checks .child-name { min-width: 110px; }

/* Roster */
.roster-card { cursor: pointer; }
.roster-card:active { background: var(--bg); }
.roster-info { display: flex; flex-direction: column; gap: 3px; flex: 1; min-width: 0; }
.roster-sub { font-size: 13px; color: var(--muted); font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chevron { color: var(--line); font-size: 26px; font-weight: 700; padding-left: 8px; }
.roster-actions { margin-top: 20px; }

/* Child editor — iOS grouped ("inset") form */
.ios-sheet {
  padding: 0; overflow: hidden;
  display: flex; flex-direction: column;
  max-height: 92vh; background: var(--bg);
}
.ios-navbar {
  flex: 0 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  padding: 2px 8px 12px;
}
.ios-nav-btn {
  background: none; border: none; color: var(--brand-dark);
  font-size: 17px; font-weight: 600; cursor: pointer; padding: 8px 10px;
}
.ios-nav-btn.strong { font-weight: 800; }
.ios-nav-btn:active { opacity: 0.5; }
.ios-nav-title { font-size: 17px; font-weight: 800; color: var(--ink); }
.ios-scroll {
  flex: 1 1 auto; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 4px 0 calc(var(--safe-bottom) + 24px);
}
.ios-group-label {
  font-size: 13px; color: var(--muted); font-weight: 600;
  margin: 14px 20px 6px;
}
.ios-group {
  background: var(--card); border-radius: 12px; margin: 0 16px;
  overflow: hidden;
}
.ios-row {
  display: flex; align-items: center; gap: 12px;
  min-height: 52px; padding: 8px 16px;
  border-bottom: 1px solid var(--line);
}
.ios-row:last-child { border-bottom: none; }
.ios-row-label { flex: 0 0 80px; color: var(--ink); font-size: 16px; font-weight: 600; }
.ios-input {
  flex: 1; min-width: 0; border: none; background: transparent;
  font-size: 17px; color: var(--ink); text-align: right; padding: 8px 0;
}
.ios-input::placeholder { color: var(--muted); opacity: 0.7; }
.ios-input:focus { outline: none; }
.ios-select { appearance: none; -webkit-appearance: none; text-align-last: right; }
.ios-value { flex: 1; min-width: 0; text-align: right; font-size: 17px; color: var(--ink); }
.ios-link {
  width: 100%; justify-content: space-between; background: none; border: none;
  cursor: pointer; text-align: left; font-size: 16px; font-weight: 600; color: var(--ink);
}
.ios-link:active { background: var(--bg); }
.ios-link-icon { color: var(--muted); font-size: 19px; font-weight: 700; }
.ios-note { color: var(--muted); font-size: 13px; line-height: 1.5; margin: 16px 20px 0; }
.ios-nav-spacer { visibility: hidden; }
.ios-action {
  color: var(--present); font-weight: 700; justify-content: center;
  text-decoration: none; cursor: pointer;
}
.ios-action:active { background: var(--bg); }
.ios-destructive {
  width: 100%; justify-content: center; background: none; border: none;
  color: var(--danger); font-weight: 700; font-size: 17px; cursor: pointer;
}
.ios-destructive:active { background: var(--bg); }
.primary-btn {
  background: var(--brand); color: #fff; border: none; border-radius: 14px;
  padding: 15px 24px; font-size: 17px; font-weight: 800; cursor: pointer; width: 100%;
}
.primary-btn:active { background: var(--brand-dark); }

/* ---------- Sheet ---------- */
.sheet { position: fixed; inset: 0; z-index: 50; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.4); }
.sheet-panel {
  position: absolute; left: 0; right: 0; bottom: 0; background: var(--card);
  border-radius: 22px 22px 0 0; padding: 12px var(--pad) calc(var(--safe-bottom) + 22px);
  max-width: 640px; margin: 0 auto; animation: slideUp 0.2s ease;
  max-height: 88vh; overflow-y: auto; -webkit-overflow-scrolling: touch;
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.sheet-handle { width: 42px; height: 5px; background: var(--line); border-radius: 3px; margin: 4px auto 14px; }
.sheet-panel h2 { margin: 0 0 4px; font-size: 21px; }
.menu-item {
  display: block; width: 100%; text-align: left; background: var(--bg);
  border: 1px solid var(--line); border-radius: 12px; padding: 16px;
  font-size: 16px; font-weight: 700; color: var(--ink); margin-top: 10px; cursor: pointer;
}
.menu-item.danger { color: var(--danger); }
.menu-item.close { text-align: center; color: var(--muted); background: none; border: none; }
.version { text-align: center; color: var(--line); font-size: 12px; margin: 12px 0 0; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--safe-bottom) + 26px); transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 13px 22px; border-radius: 999px;
  font-size: 15px; font-weight: 600; z-index: 60; box-shadow: 0 6px 20px rgba(0,0,0,0.25);
  animation: fadeIn 0.2s ease; max-width: 90%; text-align: center;
}
@keyframes fadeIn { from { opacity: 0; transform: translate(-50%, 10px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ---------- Dark mode ---------- */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f172a; --card: #1e293b; --ink: #f1f5f9; --muted: #94a3b8; --line: #334155;
    --present-soft: #14532d; --bible-soft: #3b0764; --prayer-soft: #1e3a8a;
  }
  .roster input.name-edit:focus { background: #422006; }
  @keyframes flash { 0% { background: #422006; } 100% { background: var(--card); } }
  .tabbar { background: rgba(30, 41, 59, 0.82); }
}
