:root {
  --bg: #f7f4ef;
  --surface: #ffffff;
  --ink: #1d1b19;
  --muted: #6f6a63;
  --line: #e4ded5;
  --loud: #b23a1e;
  --loud-ink: #ffffff;
  --loud-soft: #f6e3dc;
  --good: #2f7d4f;
  --good-soft: #dff0e5;
  --bad: #b3261e;
  --bad-soft: #f8e0de;
  --radius: 12px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161412;
    --surface: #211e1b;
    --ink: #f1ece6;
    --muted: #a59e95;
    --line: #36312c;
    --loud: #e2694a;
    --loud-ink: #1a0f0b;
    --loud-soft: #3a231c;
    --good: #6cc391;
    --good-soft: #1d3326;
    --bad: #f08a80;
    --bad-soft: #3b1f1d;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%; /* no automatic text inflation on iPhone rotation */
  text-size-adjust: 100%;
}
/* Safety net: nothing can make the page wider than the screen. `clip` (unlike `hidden`)
   does not create a scroll container, so the sticky header keeps working. */
html, body { overflow-x: clip; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.6 -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard", "Noto Sans KR", "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

[hidden] { display: none !important; }

a { color: var(--loud); }

.wrap { max-width: 720px; margin: 0 auto; padding: 16px 16px 80px; }

/* header */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 10px 16px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 800; color: var(--ink); text-decoration: none; letter-spacing: -0.01em; }
.brand span { color: var(--loud); }
#tabs { display: flex; gap: 4px; flex: 1; }
#tabs a {
  padding: 6px 12px; border-radius: 999px; color: var(--muted);
  text-decoration: none; font-weight: 600;
}
#tabs a[aria-current="page"] { background: var(--ink); color: var(--bg); }
.top .who { display: flex; gap: 8px; align-items: center; color: var(--muted); font-size: 14px; }
@media (max-width: 560px) {
  #tabs { order: 3; flex-basis: 100%; }
  .top .who { margin-left: auto; }
}

/* type */
h1 { font-size: 28px; line-height: 1.25; margin: 8px 0 4px; letter-spacing: -0.02em; }
h2 { font-size: 18px; margin: 0 0 12px; }
h3 { font-size: 16px; margin: 0; }
.muted, .hint { color: var(--muted); }
.hint { font-size: 14px; }
.eyebrow { font-size: 13px; font-weight: 700; color: var(--loud); letter-spacing: 0.04em; margin: 0; }
.big { font-size: 34px; font-weight: 800; letter-spacing: -0.02em; margin: 0; }
.error { color: var(--bad); font-size: 14px; margin: 8px 0; }

/* cards */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; margin: 16px 0;
}
.card > :last-child { margin-bottom: 0; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.between { justify-content: space-between; }

/* buttons & inputs */
button, .button {
  font: inherit; border-radius: 10px; padding: 9px 16px; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  font-weight: 600; text-decoration: none; display: inline-block;
}
button:disabled { opacity: 0.5; cursor: default; }
.loud { background: var(--loud); border-color: var(--loud); color: var(--loud-ink); }
.quiet { background: transparent; }
.link { background: none; border: none; padding: 0; color: var(--muted); text-decoration: underline; font-weight: 500; }
.danger { color: var(--bad); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.actions.end { justify-content: flex-end; }

input, select, textarea {
  font: inherit; color: var(--ink); background: var(--bg);
  border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; width: 100%;
}
textarea { resize: vertical; }
/* iOS Safari draws date and file inputs at their own intrinsic width, ignoring width: 100%. */
input[type="date"] { -webkit-appearance: none; appearance: none; display: block; min-width: 0; min-height: 2.6em; text-align: left; }
input[type="date"]::-webkit-date-and-time-value { text-align: left; }
input[type="file"] { min-width: 0; max-width: 100%; }
.field, .pair > * { min-width: 0; }
.field { display: flex; flex-direction: column; gap: 6px; margin: 12px 0; font-size: 14px; font-weight: 600; }
.field small { font-weight: 400; }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.inline-form { display: flex; gap: 8px; align-items: center; }
.inline-form input { width: 7em; }

.segmented { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 12px 0; }
.segmented label { position: relative; }
.segmented input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.segmented span {
  display: block; text-align: center; padding: 10px; border-radius: 10px;
  border: 1px solid var(--line); font-weight: 700; cursor: pointer;
}
.segmented input:checked + span { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.segmented input:focus-visible + span { outline: 2px solid var(--loud); outline-offset: 2px; }

/* gate */
.gate { max-width: 380px; margin: 12vh auto 0; }
.gate h1 { font-size: 32px; }
.gate h1 span { color: var(--loud); }

/* progress bars */
.bar { position: relative; height: 10px; border-radius: 999px; background: var(--line); overflow: visible; }
.bar > i { position: absolute; inset: 0 auto 0 0; border-radius: 999px; background: var(--loud); }
.bar > b { position: absolute; top: -4px; bottom: -4px; width: 2px; background: var(--ink); opacity: 0.55; }
.gap-ahead { color: var(--good); font-weight: 700; }
.gap-behind { color: var(--bad); font-weight: 700; }

/* quota chips */
.quota { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  display: inline-flex; gap: 6px; align-items: center; padding: 6px 12px; border-radius: 999px;
  background: var(--bg); border: 1px solid var(--line); font-weight: 700; font-size: 14px;
}
.chip.done { background: var(--good-soft); border-color: transparent; color: var(--good); }

/* member list */
.members { list-style: none; padding: 0; margin: 0; }
.members li { padding: 12px 0; border-top: 1px solid var(--line); }
.members li:first-child { border-top: none; }
.members .name { font-weight: 700; }
.members button.name { padding: 0; border: none; background: none; text-align: left; }
.members button.name[aria-pressed="true"] { color: var(--loud); }

/* weekly board */
.board-scroll { overflow-x: auto; margin: 0 -18px; padding: 0 18px; }
table.board { border-collapse: collapse; font-size: 14px; min-width: 100%; }
.board th, .board td { padding: 8px 6px; text-align: center; border-bottom: 1px solid var(--line); white-space: nowrap; }
.board th:first-child, .board td:first-child { text-align: left; position: sticky; left: 0; background: var(--surface); }
.board thead th { color: var(--muted); font-weight: 600; }
.board th.now { color: var(--loud); }
.status { display: inline-block; min-width: 3.2em; padding: 2px 8px; border-radius: 999px; font-weight: 700; font-size: 13px; }
.status.met { background: var(--good-soft); color: var(--good); }
.status.short { background: var(--bad-soft); color: var(--bad); }
.status.open { background: var(--loud-soft); color: var(--loud); }
.status.upcoming { color: var(--muted); }

/* feed */
.feed { list-style: none; padding: 0; margin: 0; }
.post { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin: 12px 0; }
.post header { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.post .who { font-weight: 800; color: var(--ink); font-size: 16px; }
.post .tag { font-size: 13px; font-weight: 700; color: var(--loud); }
.post .meta { font-size: 13px; color: var(--muted); }
.post .body { white-space: pre-wrap; word-break: break-word; margin: 10px 0; }
.post .body.clamp { display: -webkit-box; -webkit-line-clamp: 6; -webkit-box-orient: vertical; overflow: hidden; }
.post audio { width: 100%; margin: 10px 0 4px; }
.reactions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.reactions button { padding: 4px 10px; border-radius: 999px; font-weight: 600; font-size: 14px; }
.reactions button[aria-pressed="true"] { background: var(--loud-soft); border-color: var(--loud); }
.comments { list-style: none; padding: 0; margin: 12px 0 0; border-top: 1px solid var(--line); }
.comments li { padding: 8px 0 0; font-size: 14px; }
.comments li b { margin-right: 6px; }
.comment-form { display: flex; gap: 8px; margin-top: 10px; align-items: center; }
.comment-form input { flex: 1; min-width: 0; font-size: 14px; padding: 7px 10px; }
.comment-form button { flex: none; white-space: nowrap; padding: 7px 12px; font-size: 14px; }
.inline-form button, .actions button { white-space: nowrap; }

/* schedule */
.schedule { list-style: none; padding: 0; margin: 0; font-size: 14px; }
.schedule li { display: flex; justify-content: space-between; padding: 6px 0; border-top: 1px solid var(--line); }
.schedule li.today { color: var(--loud); font-weight: 800; }
.schedule li.past { color: var(--muted); }
details summary { cursor: pointer; font-weight: 700; }

/* dialog */
dialog {
  width: min(520px, calc(100vw - 24px)); border: none; border-radius: 16px; padding: 0;
  max-height: calc(100dvh - 24px); overflow-y: auto;
  /* overflow-y: auto silently makes overflow-x auto too, and iOS then lets the dialog
     slide sideways on any sub-pixel overflow. Allow vertical scrolling only. */
  overflow-x: hidden; touch-action: pan-y;
  overscroll-behavior: contain; /* scrolling inside the dialog never drags the page */
  background: var(--surface); color: var(--ink);
}
/* Freeze the page behind an open dialog so only the dialog scrolls. */
html:has(dialog[open]), html:has(dialog[open]) body { overflow: hidden; }
dialog > form, #day-body { padding: 20px 20px 0; }
/* Keep the submit/close buttons in reach while the form scrolls. */
dialog .actions.end {
  position: sticky; bottom: 0; z-index: 1; margin: 12px -20px 0; padding: 12px 20px 16px;
  background: var(--surface); border-top: 1px solid var(--line);
}
dialog::backdrop { background: rgb(0 0 0 / 0.45); }
dialog progress { width: 100%; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 20;
  background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 999px;
  font-weight: 600; font-size: 14px; max-width: calc(100vw - 32px);
}
.toast.bad { background: var(--bad); color: #fff; }

.copy-box { display: flex; gap: 8px; }
.copy-box input { font-size: 13px; min-width: 0; flex: 1; }
.copy-box button { flex: none; white-space: nowrap; }

/* week calendar */
.week-nav { gap: 4px; }
.week-nav button { padding: 2px 10px; font-size: 18px; line-height: 1.2; }
.calendar { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; margin-top: 10px; }
.day {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 2px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); color: var(--ink); font: inherit; font-weight: 400; min-width: 0; min-height: 104px;
}
button.day { cursor: pointer; }
button.day:hover { border-color: var(--loud); }
.day .dow { font-size: 12px; color: var(--muted); }
.day .num { font-size: 17px; font-weight: 800; }
.day .plan { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.day .read { font-size: 11px; font-weight: 700; color: var(--good); white-space: nowrap; }
.day.unread .read { color: var(--muted); font-weight: 500; }
.day .marks { font-size: 13px; line-height: 1.2; text-align: center; word-break: break-all; }
.day.today { border: 2px solid var(--loud); }
.day.future { opacity: 0.6; }
.day.off { opacity: 0.35; }
@media (max-width: 420px) {
  .calendar { gap: 3px; }
  .day { padding: 6px 0; }
  .day .read { font-size: 10px; }
}

/* photos */
.thumbs { display: flex; gap: 6px; flex-wrap: wrap; }
.thumbs img { width: 64px; height: 64px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); }
.thumbs .error { flex-basis: 100%; margin: 0; }
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 6px; margin: 10px 0 4px; }
.photos a { display: block; aspect-ratio: 3 / 4; border-radius: 8px; overflow: hidden; background: var(--bg); }
.photos img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photos.one { grid-template-columns: 1fr; }
.photos.one a { aspect-ratio: auto; max-height: 520px; }
.photos.one img { height: auto; max-height: 520px; object-fit: contain; }

/* day sheet */
#day-dialog .big { margin: -4px 0 4px; }
#day-dialog .day-section { margin: 12px 0; padding: 14px; }
#day-dialog .day-section p { margin: 4px 0 0; }

@media (max-width: 560px) {
  /* iOS zooms into any input under 16px and may keep that zoom on the next visit.
     Every form control stays at 16px on phones. */
  input, select, textarea, .comment-form input, .copy-box input { font-size: 16px; }
}

/* account */
.top .who-name { color: var(--ink); font-weight: 700; text-decoration: none; }
.top .who-name:hover { text-decoration: underline; }
.notice { border-color: var(--loud); background: var(--loud-soft); }
details.subsection { margin: 12px 0; padding: 10px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
#account-dialog form { padding: 20px 20px 0; }

/* admin recording for a member */
.card.acting { padding: 12px 18px; }
.card.acting label { gap: 12px; flex-wrap: nowrap; }
.card.acting select { width: auto; min-width: 9em; }
.card.acting.on { border-color: var(--loud); background: var(--loud-soft); }

[tabindex="-1"]:focus { outline: none; }
