:root {
  --bg: #fbf3e8;
  --surface: #fffaf3;
  --surface-2: #f4e8d8;
  --ink: #2b2233;
  --muted: #7a6c74;
  --line: #ead9c4;
  --accent: #d9654b;       /* collar red */
  --accent-ink: #fff;
  --accent-soft: #f9ddd3;
  --okay: #3f9a6b;  --okay-soft: #dcefe2;
  --meh:  #c89a1c;  --meh-soft:  #f6ebc8;
  --need: #d2445a;  --need-soft: #f8d9de;
  --shadow: 0 1px 0 rgba(60, 40, 20, .04), 0 6px 20px -10px rgba(60, 40, 20, .25);
  --radius: 18px;
  --font-display: 'Fredoka', ui-rounded, system-ui, sans-serif;
  --font-body: 'Nunito', ui-rounded, system-ui, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1d1824; --surface: #27202f; --surface-2: #31283a; --ink: #f3ebf0; --muted: #b3a5b0;
    --line: #3d3247; --accent: #f08168; --accent-ink: #20141a; --accent-soft: #48302f;
    --okay: #6fcf98; --okay-soft: #22392d; --meh: #e9c25a; --meh-soft: #3b3320; --need: #ff7c90; --need-soft: #45232b;
    --shadow: 0 8px 24px -14px rgba(0,0,0,.7);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 var(--font-body);
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
  padding-bottom: env(safe-area-inset-bottom);
}
h1, h2, h3 { font-family: var(--font-display); font-weight: 600; line-height: 1.15; margin: 0; }
h2 { font-size: 1.2rem; }
button, input, textarea, select { font: inherit; color: inherit; }
.muted { color: var(--muted); }
[hidden] { display: none !important; }

/* ---------- layout ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-family: var(--font-display); font-weight: 600; font-size: 1.1rem; min-width: 0; }
.brand span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand img { border-radius: 10px; flex: none; }
.wrap { max-width: 640px; margin: 0 auto; padding: 16px; display: grid; gap: 16px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.stack { display: grid; gap: 14px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.between { justify-content: space-between; }
.section-title { font-size: 1rem; color: var(--muted); margin: 4px 4px 10px; letter-spacing: .02em; }
.label-sm { font-size: .82rem; font-weight: 700; color: var(--muted); margin-bottom: 8px; text-transform: uppercase; letter-spacing: .06em; }
.hint { font-size: .85rem; margin: 8px 0 0; }

label { display: grid; gap: 6px; font-weight: 600; font-size: .95rem; }
label.inline { display: flex; align-items: center; gap: 8px; }
input:not([type=checkbox]), textarea, select {
  width: 100%; padding: 12px 14px; border-radius: 12px;
  border: 1.5px solid var(--line); background: var(--bg); font-weight: 400; font-size: 16px;
}
textarea { resize: vertical; min-height: 64px; }
input:focus-visible, textarea:focus-visible, select:focus-visible, button:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 2px;
}

/* ---------- buttons ---------- */
.btn {
  white-space: nowrap;
  appearance: none; border: 1.5px solid var(--line); background: var(--surface-2);
  padding: 11px 16px; border-radius: 999px; font-weight: 700; cursor: pointer;
  transition: transform .08s ease, background .15s ease;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-ghost { background: transparent; }
.btn-big { padding: 16px; font-size: 1.1rem; font-family: var(--font-display); font-weight: 600; width: 100%; }
.btn[disabled] { opacity: .55; cursor: default; }
.icon-btn { border: 0; background: transparent; font-size: 1.2rem; cursor: pointer; padding: 6px 10px; border-radius: 10px; }
.chip {
  display: inline-flex; align-items: center; gap: 8px; flex: none;
  border: 1.5px solid var(--line); background: var(--surface); padding: 7px 14px;
  border-radius: 999px; font-weight: 700; cursor: pointer;
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.dot.is-live { background: var(--okay); box-shadow: 0 0 0 3px var(--okay-soft); }

/* ---------- banner ---------- */
.banner {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  background: var(--accent-soft); border: 1.5px dashed var(--accent); border-radius: var(--radius); padding: 14px 16px;
}
.banner p { margin: 2px 0 0; font-size: .9rem; }

/* ---------- caregiver: status ---------- */
.status { display: flex; align-items: center; gap: 14px; }
.status-face {
  width: 58px; height: 58px; flex: none; border-radius: 50%; display: grid; place-items: center;
  font-size: 1.8rem; background: var(--surface-2);
}
.status.is-okay .status-face { background: var(--okay-soft); }
.status.is-meh  .status-face { background: var(--meh-soft); }
.status.is-need .status-face { background: var(--need-soft); animation: pulse 1.6s ease-in-out infinite; }
.status.is-wait .status-face { background: var(--accent-soft); }
.status-name { font-family: var(--font-display); font-weight: 600; font-size: 1.2rem; }
@keyframes pulse { 50% { box-shadow: 0 0 0 8px color-mix(in srgb, var(--need) 25%, transparent); } }

/* ---------- caregiver: presets ---------- */
.presets { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.preset {
  display: grid; justify-items: center; gap: 4px; padding: 12px 6px; border-radius: 14px;
  border: 1.5px solid var(--line); background: var(--bg); cursor: pointer; font-size: .85rem; font-weight: 700;
  text-align: center;
}
/* odd one out on the last row spans the full width on phones */
.preset:last-child:nth-child(3n+1) { grid-column: 1 / -1; }
.preset-emoji { font-size: 1.5rem; line-height: 1; }
.preset.is-on { border-color: var(--accent); background: var(--accent-soft); }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip-opt { border: 1.5px solid var(--line); background: var(--bg); padding: 7px 13px; border-radius: 999px; font-weight: 700; font-size: .9rem; cursor: pointer; }
.chip-opt.is-on { border-color: var(--accent); background: var(--accent-soft); }

.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; }
.switch input { appearance: none; width: 46px; height: 28px; border-radius: 999px; background: var(--line); position: relative; cursor: pointer; transition: background .15s; margin: 0; }
.switch input::after { content: ''; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 3px rgba(0,0,0,.25); }
.switch input:checked { background: var(--accent); }
.switch input:checked::after { transform: translateX(18px); }

/* ---------- pup ---------- */
.pup-card { padding: 22px 18px; }
.ask-from { font-weight: 700; font-size: .9rem; margin-bottom: 6px; }
.ask-text { font-size: 1.55rem; }
.pup-card.has-ask { border: 2px solid var(--accent); }
.moods { display: grid; gap: 10px; }
.mood {
  display: flex; align-items: center; gap: 14px; width: 100%;
  padding: 16px 18px; border-radius: 16px; border: 2px solid transparent; cursor: pointer;
  font-family: var(--font-display); font-weight: 600; font-size: 1.2rem; text-align: left;
  transition: transform .08s ease;
}
.mood:active { transform: scale(.98); }
.mood-emoji { font-size: 1.7rem; line-height: 1; }
.mood-okay { background: var(--okay-soft); border-color: color-mix(in srgb, var(--okay) 40%, transparent); }
.mood-meh  { background: var(--meh-soft);  border-color: color-mix(in srgb, var(--meh) 40%, transparent); }
.mood-need { background: var(--need-soft); border-color: color-mix(in srgb, var(--need) 45%, transparent); }

/* ---------- need-you chat ---------- */
.chat { display: grid; gap: 12px; }
.chat.is-open { border: 2px solid var(--need); box-shadow: 0 0 0 4px var(--need-soft), var(--shadow); }
.chat-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.chat-head p { margin: 4px 0 0; font-size: .92rem; }
.msgs { list-style: none; margin: 0; padding: 4px 2px; display: flex; flex-direction: column; gap: 8px; max-height: 46vh; overflow-y: auto; }
.msg { max-width: 82%; display: grid; gap: 2px; padding: 9px 13px; border-radius: 18px; background: var(--surface-2); align-self: flex-start; }
.msg-pup { background: var(--need-soft); }
.msg-me { align-self: flex-end; background: var(--accent); color: var(--accent-ink); border-bottom-right-radius: 6px; }
.msg-them, .msg-pup { border-bottom-left-radius: 6px; }
.msg-name { font-size: .78rem; font-weight: 700; opacity: .75; }
.msg-body { white-space: pre-wrap; word-wrap: break-word; }
.msg time { font-size: .72rem; opacity: .65; justify-self: end; }
.msg-sys { align-self: center; font-size: .82rem; font-weight: 700; color: var(--muted); text-align: center; }
.compose { display: flex; gap: 8px; align-items: flex-end; }
.compose textarea { min-height: 46px; max-height: 140px; resize: none; border-radius: 22px; }
.btn-ok { background: var(--okay-soft); border-color: color-mix(in srgb, var(--okay) 45%, transparent); width: 100%; }
.need-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.link-btn { border: 0; background: none; color: var(--accent); font-weight: 700; cursor: pointer; padding: 4px 0; font-size: .92rem; }

/* ---------- feed ---------- */
.feed { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.item {
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 12px 14px;
  display: grid; gap: 6px;
}
.item.is-highlight { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.item-top { display: flex; justify-content: space-between; gap: 10px; font-size: .85rem; color: var(--muted); font-weight: 700; }
.item-msg { font-weight: 600; }
.reply { display: inline-flex; align-items: center; gap: 6px; font-weight: 700; font-size: .92rem; padding: 4px 10px; border-radius: 999px; justify-self: start; }
.reply-okay { background: var(--okay-soft); }
.reply-meh  { background: var(--meh-soft); }
.reply-need { background: var(--need-soft); }
.reply-wait { background: var(--accent-soft); }
.reply-late { background: var(--need-soft); }
.reply-note { font-style: italic; color: var(--muted); font-size: .92rem; }
.empty { text-align: center; padding: 20px; }

/* ---------- settings sheet ---------- */
.sheet {
  border: 1px solid var(--line); border-radius: 22px; padding: 18px; width: min(480px, calc(100vw - 24px));
  background: var(--surface); color: var(--ink); box-shadow: 0 30px 80px -20px rgba(0,0,0,.45);
}
.sheet::backdrop { background: rgba(20, 12, 24, .45); }
.sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.devices { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.devices li { display: flex; justify-content: space-between; align-items: center; gap: 10px; font-size: .9rem; padding: 8px 12px; border-radius: 12px; background: var(--bg); }
.devices li span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- password folds ---------- */
.fold { border: 1.5px solid var(--line); border-radius: 14px; background: var(--bg); }
.fold summary { cursor: pointer; padding: 12px 14px; font-weight: 700; list-style: none; display: flex; justify-content: space-between; }
.fold summary::-webkit-details-marker { display: none; }
.fold summary::after { content: '▾'; color: var(--muted); transition: transform .15s; }
.fold[open] summary::after { transform: rotate(180deg); }
.fold-body { padding: 0 14px 14px; }
.fold-body input, .fold-body select { background: var(--surface); }
.sheet { max-height: calc(100dvh - 32px); overflow-y: auto; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translate(-50%, 30px);
  background: var(--ink); color: var(--bg); padding: 12px 18px; border-radius: 999px; font-weight: 700;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; max-width: calc(100vw - 32px); text-align: center;
}
.toast.is-on { opacity: 1; transform: translate(-50%, 0); }

/* ---------- login ---------- */
.login-body { display: grid; place-items: center; padding: 24px 16px; }
.login { width: min(380px, 100%); text-align: center; display: grid; gap: 12px; }
.login-mark { margin: 0 auto; border-radius: 24px; }
.login h1 { font-size: 1.7rem; }
.login p { margin: 0; }
.login form { text-align: left; margin-top: 8px; }
.error { background: var(--need-soft); color: var(--ink); padding: 10px 14px; border-radius: 12px; font-weight: 700; }

@media (min-width: 560px) {
  .presets { grid-template-columns: repeat(7, 1fr); }
  .preset:last-child:nth-child(3n+1) { grid-column: auto; }
  .moods { grid-template-columns: repeat(3, 1fr); }
  .mood { flex-direction: column; text-align: center; padding: 20px 10px; font-size: 1.1rem; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
