/* Tokens and components follow mockups/mockup.css (concept A).
   Layout: one phone-width column, app bar on top, tab bar fixed to the bottom. */

:root {
  --bg: #f1f4f1;
  --surface: #ffffff;
  --panel: #f5f7f4;
  --sunken: #e8ece7;
  --ink: #17201c;
  --muted: #5a6761;
  --faint: #8d9893;
  --line: #d9dfd9;
  --accent: #1f7a55;
  --accent-ink: #ffffff;
  --accent-text: #1a6b4a;
  --accent-soft: #dcefe4;
  --mark: #ffe45c;
  --mark-ink: #2a2400;
  --good: #1f7a55;
  --good-soft: #dcefe4;
  --warn: #b5650d;
  --warn-soft: #fbe8d3;
  --bad: #c0392f;
  --bad-soft: #f8ddd9;
  --shadow: 0 1px 2px rgb(23 32 28 / 6%), 0 12px 32px -12px rgb(23 32 28 / 18%);
  --font-display: "Do Hyeon", "IBM Plex Sans KR", "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  --font-body: "IBM Plex Sans KR", "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif;
  --font-num: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  --tabbar-h: 64px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101513;
    --surface: #181e1b;
    --panel: #1f2622;
    --sunken: #262e2a;
    --ink: #e6ece8;
    --muted: #a0aca6;
    --faint: #75817b;
    --line: #2f3833;
    --accent: #43b884;
    --accent-ink: #06150e;
    --accent-text: #5fcf9b;
    --accent-soft: #1c3a2c;
    --mark: #e9d14a;
    --mark-ink: #221d00;
    --good: #4fc28e;
    --good-soft: #1c3a2c;
    --warn: #e39a4b;
    --warn-soft: #3b2a17;
    --bad: #ec6b61;
    --bad-soft: #432220;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 12px 32px -12px rgb(0 0 0 / 60%);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 15px/1.5 var(--font-body);
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: 0.55; }
a { color: var(--accent-text); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }

.shell {
  max-width: 520px;
  margin-inline: auto;
  min-height: 100vh;
  min-height: 100dvh;
  padding-inline: 16px;
  padding-block: env(safe-area-inset-top, 0px) calc(var(--tabbar-h) + 24px + env(safe-area-inset-bottom, 0px));
}

/* ---------- app bar ---------- */
.appbar { display: flex; align-items: center; gap: 10px; padding-block: 16px 10px; }
.appbar .grow { flex: 1; min-width: 0; }
.appbar .title {
  font: 400 24px/1.15 var(--font-display);
  margin: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.appbar .sub { font-size: 12.5px; color: var(--muted); }
.group-switch { border: 0; background: none; padding: 0; text-align: left; display: block; max-width: 100%; }
.group-switch .title::after { content: " ▾"; font: 400 14px var(--font-body); color: var(--faint); }

.icon-btn {
  width: 36px; height: 36px; flex: none;
  display: grid; place-items: center;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--surface);
  font-size: 16px;
  padding: 0;
}

.view { display: flex; flex-direction: column; gap: 14px; }

/* ---------- tab bar ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0;
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  z-index: 10;
}
.tabbar nav { max-width: 520px; margin-inline: auto; display: grid; grid-template-columns: repeat(4, 1fr); height: var(--tabbar-h); }
.tabbar a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  text-decoration: none; color: var(--faint); font-size: 11.5px;
}
.tabbar a i { font-style: normal; font-size: 18px; line-height: 1.1; }
.tabbar a[aria-current="page"] { color: var(--accent-text); font-weight: 600; }

/* ---------- shared pieces ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 14px; }
.row { display: flex; align-items: center; gap: 10px; }
.between { justify-content: space-between; }
.wrap-row { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.num { font-family: var(--font-num); font-variant-numeric: tabular-nums; }
.label {
  font: 500 11px/1 var(--font-num);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}
.center { text-align: center; }

.avatar {
  width: 32px; height: 32px; flex: none;
  border-radius: 50%;
  display: grid; place-items: center;
  font-size: 13px; font-weight: 600;
}
.av-me { background: #ffe45c; color: #2a2400; }
.av-0 { background: #f6c8d4; color: #4a1222; }
.av-1 { background: #c6daf8; color: #11264a; }
.av-2 { background: #cfe9c8; color: #183a12; }
.av-3 { background: #ead5f5; color: #36184a; }
.av-4 { background: #f8dcc0; color: #4a2a0b; }

.pill {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11.5px; font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  white-space: nowrap;
}
.pill.good { background: var(--good-soft); color: var(--good); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.neutral { background: var(--sunken); color: var(--muted); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 12px;
  padding: 10px 14px;
  font-weight: 600;
  font-size: 14px;
  text-decoration: none;
  color: var(--ink);
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--bad); }
.btn.block { width: 100%; }
.btn.small { padding: 6px 10px; font-size: 12.5px; border-radius: 10px; }

.seg { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.seg::-webkit-scrollbar { display: none; }
.seg button {
  flex: none;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 13.5px;
  color: var(--muted);
}
.seg button[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--surface); font-weight: 600; }

.bar { height: 8px; border-radius: 999px; background: var(--sunken); overflow: hidden; }
.bar > span { display: block; height: 100%; border-radius: inherit; background: var(--accent); }

.empty { text-align: center; padding: 28px 16px; display: flex; flex-direction: column; gap: 10px; align-items: center; }
.empty h3 { margin: 0; font: 400 22px/1.2 var(--font-display); }
.empty p { margin: 0; color: var(--muted); font-size: 14px; max-width: 28em; }

.loading { padding: 40px 0; text-align: center; color: var(--faint); }

/* ---------- forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field > label, .field > .label-text { font-size: 13px; color: var(--muted); font-weight: 500; }
.input {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 12px;
  padding: 11px 12px;
  font-size: 15px;
}
.form { display: flex; flex-direction: column; gap: 16px; }
.choice-grid { display: grid; gap: 8px; }
.choice {
  display: flex; gap: 10px; align-items: flex-start;
  border: 1.5px solid var(--line); border-radius: 14px; padding: 12px;
  background: var(--surface); cursor: pointer;
}
.choice input { margin: 3px 0 0; accent-color: var(--accent); }
.choice b { display: block; font-size: 14.5px; }
.choice span { font-size: 12.5px; color: var(--muted); }
.choice:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.icon-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.icon-chips button {
  width: 40px; height: 40px; border-radius: 12px; font-size: 20px; padding: 0;
  border: 1.5px solid var(--line); background: var(--surface);
}
.icon-chips button[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); }
.stepper { display: flex; align-items: center; gap: 12px; }
.stepper output { font: 600 22px var(--font-num); min-width: 2ch; text-align: center; }
.stepper button { width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface); font-size: 20px; padding: 0; }
.date-pick { display: flex; align-items: center; gap: 8px; }
.date-pick .input { width: auto; padding: 6px 10px; font-size: 14px; }
.weeks-input { display: flex; align-items: center; gap: 6px; font-size: 14px; }
.weeks-input .input { width: 76px; padding: 6px 10px; text-align: center; font-family: var(--font-num); }
.preview { background: var(--panel); border-radius: 12px; padding: 10px 12px; font-size: 13px; color: var(--muted); }

dialog.sheet {
  width: min(520px, 100%);
  max-width: 100%;
  max-height: 92vh;
  max-height: 92dvh;
  overflow-y: auto;
  margin: auto auto 0;
  border: 0;
  border-radius: 20px 20px 0 0;
  padding: 0;
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow);
}
dialog.sheet::backdrop { background: rgb(0 0 0 / 40%); }
dialog.sheet .sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 16px 4px; }
dialog.sheet .sheet-head h2 { margin: 0; font: 400 22px var(--font-display); }
dialog.sheet .sheet-body { padding: 12px 16px calc(20px + env(safe-area-inset-bottom, 0px)); overflow-y: auto; }

/* ---------- auth / onboarding ---------- */
.auth { min-height: 80vh; display: flex; flex-direction: column; justify-content: center; gap: 22px; padding-block: 40px; }
.auth h1 { font: 400 48px/1.05 var(--font-display); margin: 0; }
.auth .lede { color: var(--muted); font-size: 16px; margin: 0; }
.auth .actions { display: flex; flex-direction: column; gap: 10px; }
.auth .note { font-size: 13px; color: var(--muted); }
.invite-card { border: 1.5px dashed var(--accent); background: var(--accent-soft); border-radius: 16px; padding: 14px 16px; }
.invite-card b { font-size: 17px; }

/* ---------- board ---------- */
.week-nav { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.week-nav .wk { text-align: center; }
.week-nav .wk b { display: block; font-size: 15px; }
.week-nav .wk span { font-size: 12px; color: var(--muted); }

.board-card { padding: 12px 10px 10px; }
.board { width: 100%; border-collapse: separate; border-spacing: 0 6px; table-layout: fixed; }
.board th { font: 500 11px/1.2 var(--font-num); color: var(--muted); padding: 0 0 2px; }
.board th.today span { background: var(--mark); color: var(--mark-ink); border-radius: 6px; padding: 2px 4px; }
.board th.picked span { box-shadow: inset 0 0 0 1.5px var(--ink); color: var(--ink); border-radius: 6px; padding: 2px 4px; }
.board col.name { width: 56px; }
.board col.res { width: 70px; }
.board td { padding: 0; text-align: center; vertical-align: middle; }
.board td.who { text-align: left; font-size: 12.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.board tr.me td.who { color: var(--accent-text); }
.cell {
  width: calc(100% - 4px); max-width: 30px; aspect-ratio: 1 / 1; margin: 0 auto;
  border-radius: 8px;
  display: grid; place-items: center;
  font-size: 13px; font-weight: 700;
  background: var(--sunken);
  color: transparent;
  border: 1px solid transparent;
  padding: 0;
}
.cell.future, .cell.off { background: transparent; border: 1px dashed var(--line); }
.cell.off { opacity: 0.4; }
.cell.done { background: var(--accent); color: var(--accent-ink); }
.cell.limit { background: var(--bad-soft); color: var(--bad); border-color: color-mix(in srgb, var(--bad) 35%, transparent); }
.cell.miss { color: var(--faint); }
button.cell:hover { border-color: var(--accent); }
/* A dot in the corner marks a day with a comment or photo. */
.cell.noted { position: relative; }
.cell.noted::after {
  content: ""; position: absolute; top: -2px; right: -2px;
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--warn); box-shadow: 0 0 0 2px var(--surface);
}
.res-count { font: 600 13px/1.1 var(--font-num); display: block; }
.res .pill { margin-top: 3px; font-size: 10.5px; padding: 1px 6px; }
.legend { display: flex; flex-wrap: wrap; gap: 10px; font-size: 11.5px; color: var(--muted); padding-inline: 2px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 4px; vertical-align: -1px; }
.legend i.noted-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); }

/* ---------- board popup ---------- */
.entry { display: flex; flex-direction: column; gap: 12px; font-size: 14px; }
.entry-note { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; background: var(--panel); border-radius: 12px; padding: 10px 12px; }
.entry-photo { display: block; width: 100%; max-height: 60vh; object-fit: contain; border-radius: 12px; background: var(--sunken); }

/* ---------- today ---------- */
.today-card { display: flex; flex-direction: column; gap: 10px; }
.today-card h3 { margin: 0; font-size: 16px; display: flex; align-items: center; gap: 6px; min-width: 0; }
.today-card .rule { font-size: 12.5px; color: var(--muted); }
.dots { display: flex; gap: 5px; }
.dots span { width: 24px; height: 24px; border-radius: 7px; background: var(--sunken); font: 500 10.5px/24px var(--font-num); text-align: center; color: var(--faint); }
.dots span.done { background: var(--accent); color: var(--accent-ink); }
.dots span.limit { background: var(--bad-soft); color: var(--bad); }
.dots span.today { outline: 2px solid var(--mark); outline-offset: 1px; }
.big-check {
  display: flex; align-items: center; gap: 12px;
  width: 100%; text-align: left;
  border: 1.5px solid var(--line); background: var(--surface);
  border-radius: 14px; padding: 12px 14px; font-weight: 600;
}
.big-check .box { width: 26px; height: 26px; border-radius: 8px; border: 2px solid var(--line); display: grid; place-items: center; flex: none; color: transparent; font-weight: 800; }
.big-check[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); }
.big-check[aria-pressed="true"] .box { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.big-check.limit[aria-pressed="true"] { border-color: var(--bad); background: var(--bad-soft); }
.big-check.limit[aria-pressed="true"] .box { background: var(--bad); border-color: var(--bad); color: var(--surface); }

.day-strip { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.day-strip button {
  display: flex; flex-direction: column; align-items: center; gap: 1px;
  border: 1px solid var(--line); background: var(--surface); border-radius: 12px;
  padding: 6px 0; font-size: 11.5px; color: var(--muted);
}
.day-strip button b { font-size: 15px; color: var(--ink); }
.day-strip button.is-today { border-color: var(--mark); box-shadow: inset 0 0 0 1px var(--mark); }
.day-strip button[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--surface); }
.day-strip button[aria-pressed="true"] b { color: var(--surface); }
.note-box { display: flex; flex-direction: column; gap: 6px; }
.note-input { resize: vertical; min-height: 56px; font-size: 14px; line-height: 1.45; }
.photo-box { display: flex; flex-direction: column; gap: 8px; }
.photo-box img { display: block; width: 100%; max-height: 320px; object-fit: cover; border-radius: 12px; background: var(--sunken); }
/* File inputs live inside their label buttons; keep them focusable but invisible. */
.file-input { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; }
label.btn { position: relative; cursor: pointer; }
label.btn:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- history ---------- */
.heat-wrap { overflow-x: auto; }
.heat { width: 100%; border-collapse: separate; border-spacing: 3px; table-layout: fixed; min-width: 300px; }
.heat th { font: 500 10px/1.2 var(--font-num); color: var(--muted); }
.heat td { height: 24px; border-radius: 5px; padding: 0; }
.heat td.who { font-size: 12px; font-weight: 600; text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.heat td.success { background: var(--accent); }
.heat td.fail { background: var(--bad-soft); border: 1px solid color-mix(in srgb, var(--bad) 30%, transparent); }
.heat td.open { background: repeating-linear-gradient(135deg, var(--sunken) 0 4px, var(--surface) 4px 8px); }
.heat td.none { background: transparent; }
.heat td.streak { font: 600 11.5px var(--font-num); text-align: right; }
.heat col.name { width: 48px; }
.heat col.stk { width: 40px; }
dl.rules { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0; font-size: 13.5px; }
dl.rules dt { color: var(--muted); }
dl.rules dd { margin: 0; font-weight: 500; }

/* ---------- group ---------- */
.list { display: flex; flex-direction: column; gap: 10px; }
.invite-link { display: flex; gap: 8px; align-items: center; }
.invite-link code {
  flex: 1; min-width: 0;
  font: 500 13px var(--font-num);
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 9px 10px; overflow-x: auto; white-space: nowrap;
  user-select: all;
}

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tabbar-h) + 16px + env(safe-area-inset-bottom, 0px));
  max-width: min(92vw, 480px);
  background: var(--ink); color: var(--surface);
  padding: 10px 16px; border-radius: 12px; font-size: 14px;
  box-shadow: var(--shadow);
  z-index: 30;
}

@media (max-width: 380px) {
  .shell { padding-inline: 12px; }
  .board col.name { width: 46px; }
  .board col.res { width: 62px; }
}
