:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --ink: #1d1f1c;
  --muted: #676b63;
  --line: #e3dfd5;
  --accent: #2f6b4f;
  --accent-press: #255a41;
  --accent-ink: #ffffff;
  --accent-soft: #e3efe7;
  --wait-soft: #efece5;
  --danger: #a33a2c;
  --shadow: 0 1px 2px rgb(30 30 20 / 0.06), 0 4px 14px rgb(30 30 20 / 0.05);

  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px;
  --r-control: 12px;
  --r-card: 18px;
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --t-press: 120ms;
  --t-state: 220ms;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151714;
    --surface: #1f221e;
    --ink: #ecebe6;
    --muted: #a3a69d;
    --line: #30342e;
    --accent: #5fae86;
    --accent-press: #4f9874;
    --accent-ink: #0f1a13;
    --accent-soft: #233a2d;
    --wait-soft: #272a25;
    --danger: #e0806f;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html {
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
  background: var(--bg);
}

body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.4;
  color: var(--ink);
  background: var(--bg);
}

button, input { font: inherit; color: inherit; }
input { font-size: 16px; }
button, a { touch-action: manipulation; }
button { user-select: none; -webkit-user-select: none; cursor: pointer; }

.app {
  min-height: 100dvh;
  max-width: 560px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top, 0px) + var(--s4)) var(--s4) calc(env(safe-area-inset-bottom, 0px) + 104px);
}

.splash { color: var(--muted); text-align: center; margin-top: 40dvh; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 0 var(--s5);
  border: 0;
  border-radius: var(--r-control);
  font-weight: 600;
  transition: transform var(--t-press) var(--ease-out), background var(--t-press);
}
.btn:active:not(:disabled) { transform: scale(0.97); }
.btn:focus-visible, .person:focus-visible, .link-btn:focus-visible, .toast-action:focus-visible, .segmented label:has(input:focus-visible) {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:active:not(:disabled) { background: var(--accent-press); }
.btn-primary:disabled { background: var(--wait-soft); color: var(--muted); cursor: default; }
.btn-quiet { background: transparent; color: var(--ink); box-shadow: inset 0 0 0 1px var(--line); }
.btn-block { width: 100%; }

.link-btn {
  border: 0;
  background: none;
  padding: var(--s2) 0;
  color: var(--muted);
  font-size: 15px;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.link-btn.danger { color: var(--danger); }

@media (hover: hover) and (pointer: fine) {
  .btn-primary:hover:not(:disabled) { background: var(--accent-press); }
  .btn-quiet:hover, .person:hover { background: var(--wait-soft); }
  .link-btn:hover { color: var(--ink); }
}

/* Sign in */
.signin { padding-top: 12dvh; }
.signin h1 { font-size: 34px; letter-spacing: -0.02em; margin: 0 0 var(--s2); }
.signin p.lead { color: var(--muted); margin: 0 0 var(--s5); }
.people { display: grid; gap: var(--s3); }
.person {
  display: flex;
  align-items: center;
  gap: var(--s3);
  width: 100%;
  min-height: 64px;
  padding: 0 var(--s4);
  border: 1px solid var(--line);
  border-radius: var(--r-card);
  background: var(--surface);
  font-size: 18px;
  font-weight: 600;
  text-align: left;
  box-shadow: var(--shadow);
  transition: transform var(--t-press) var(--ease-out);
}
.person:active { transform: scale(0.98); }
.initial {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
}
.code-form { display: grid; gap: var(--s4); }
.field { display: grid; gap: var(--s2); border: 0; margin: 0; padding: 0; min-width: 0; }
.field > span, .field > legend { font-weight: 600; font-size: 15px; padding: 0; margin-bottom: var(--s2); }
.field input {
  width: 100%;
  min-height: 52px;
  padding: 0 var(--s4);
  border: 1px solid var(--line);
  border-radius: var(--r-control);
  background: var(--surface);
}
.field input:focus { outline: 3px solid var(--accent-soft); border-color: var(--accent); }
.hint { color: var(--muted); font-size: 14px; margin: 0; }
.form-error { color: var(--danger); margin: 0; font-size: 15px; }

/* Header */
.top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--s3);
  margin-bottom: var(--s2);
}
.top h1 { font-size: 30px; letter-spacing: -0.02em; margin: 0; }
.who { color: var(--muted); font-size: 15px; display: flex; gap: var(--s3); align-items: baseline; }
.summary { color: var(--muted); margin: 0 0 var(--s5); }

.banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s3);
  padding: var(--s3) var(--s4);
  margin-bottom: var(--s4);
  border-radius: var(--r-control);
  background: var(--wait-soft);
  font-size: 15px;
}
.banner .link-btn { color: var(--ink); padding: 0; }

/* Chore cards */
.list { display: grid; gap: var(--s3); list-style: none; margin: 0; padding: 0; }
.card {
  padding: var(--s4);
  border: 1px solid var(--line);
  border-radius: var(--r-card);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.card.mine { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: var(--s3); }
.card h2 { font-size: 19px; margin: 0; overflow-wrap: anywhere; }
.turn { font-size: 14px; font-weight: 600; color: var(--muted); white-space: nowrap; }
.card.mine .turn { color: var(--accent); }
.lasts { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s2); margin: var(--s3) 0 var(--s4); }
.last { padding: var(--s2) var(--s3); border-radius: var(--r-control); background: var(--wait-soft); }
.last b { display: block; font-size: 13px; font-weight: 600; color: var(--muted); }
.last span { font-size: 15px; }
.card details { margin-top: var(--s2); }
.card summary {
  color: var(--muted);
  font-size: 15px;
  padding: var(--s2) 0;
  cursor: pointer;
  list-style: none;
  user-select: none;
  -webkit-user-select: none;
}
.card summary::-webkit-details-marker { display: none; }
.card summary::after { content: " +"; }
.card details[open] summary::after { content: " –"; }
.history { list-style: none; margin: 0 0 var(--s2); padding: 0; font-size: 15px; }
.history li { display: flex; justify-content: space-between; padding: var(--s1) 0; border-bottom: 1px solid var(--line); }
.history li:last-child { border-bottom: 0; }
.history time { color: var(--muted); }

.empty {
  padding: var(--s6) var(--s4);
  text-align: center;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: var(--r-card);
}

/* Bottom action bar */
.bottom-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  padding: var(--s3) var(--s4) calc(env(safe-area-inset-bottom, 0px) + var(--s3));
  background: linear-gradient(to top, var(--bg) 70%, transparent);
}
.bottom-bar .btn { display: flex; width: 100%; max-width: 528px; margin: 0 auto; }

/* Add sheet */
.sheet {
  width: min(100% - 2 * var(--s4), 528px);
  margin: auto auto calc(env(safe-area-inset-bottom, 0px) + var(--s4));
  padding: var(--s5);
  border: 0;
  border-radius: var(--r-card);
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 10px 40px rgb(0 0 0 / 0.2);
}
.sheet::backdrop { background: rgb(10 12 10 / 0.4); }
.sheet[open] { animation: rise var(--t-state) var(--ease-out); }
.sheet h2 { margin: 0 0 var(--s4); font-size: 21px; }
.sheet form { display: grid; gap: var(--s4); }
.sheet-actions { display: grid; grid-template-columns: 1fr 1.4fr; gap: var(--s3); }
@keyframes rise { from { transform: translateY(16px); opacity: 0; } }

.segmented { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s2); }
.segmented label {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: var(--r-control);
  font-weight: 600;
  user-select: none;
  -webkit-user-select: none;
  cursor: pointer;
}
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented label:has(input:checked) { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 84px);
  transform: translateX(-50%);
  width: min(100% - 2 * var(--s4), 528px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s3);
  padding: var(--s3) var(--s4);
  border-radius: var(--r-control);
  background: var(--ink);
  color: var(--bg);
  font-size: 15px;
  animation: rise var(--t-state) var(--ease-out);
}
.toast-action {
  border: 0;
  background: none;
  color: inherit;
  font-weight: 700;
  padding: var(--s2);
  margin: calc(-1 * var(--s2));
  text-decoration: underline;
  text-underline-offset: 3px;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
