:root {
  --bg: #222226;
  --surface: #0f0f11;
  --surface-2: #1b1b1f;
  --input: #18181c;
  --border: #26262c;
  --text: #f2f1f5;
  --muted: #9d9ca6;
  /* --bg, --on-bg*, --accent* are overwritten per user by applyTheme() in app.js */
  --on-bg: #f2f1f5;        /* text directly on the background */
  --on-bg-muted: #9d9ca6;
  --accent: #a78bfa;
  --accent-soft: rgba(167, 139, 250, .14);
  --accent-border: rgba(167, 139, 250, .45);
  --accent-text: #1a1033;
  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, .14);
  --warn: #fbbf24;
  --warn-soft: rgba(251, 191, 36, .14);
  --shadow: 0 1px 2px rgba(0,0,0,.25), 0 6px 18px rgba(0,0,0,.18);
  --radius: 16px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--on-bg);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
button, input, select, textarea { font: inherit; color: inherit; }
/* Black surfaces always use light text; text placed directly on the background follows --on-bg. */
.card, .tile, dialog, .seg, .back, input, select, textarea, .btn { color: var(--text); }
.btn.primary { color: var(--accent-text); }
.greeting, .day-head, main > p.muted { color: var(--on-bg-muted); }
.view-head .badge { background: var(--surface); } /* stays readable on light backgrounds */
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 1.25rem; font-weight: 650; }
h2 { font-size: 1.35rem; }
h3 { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.hidden { display: none !important; }

/* Line icons: one stroke style everywhere */
.ico { display: inline-grid; place-items: center; flex: none; }
.ico svg {
  width: 100%; height: 100%;
  fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round;
}

/* --- Layout --------------------------------------------------------------- */

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 12px;
  max-width: 760px; margin: 0 auto;
  padding: 14px 16px;
  padding-top: max(14px, env(safe-area-inset-top));
  background: var(--bg);
}
.topbar h1 { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; font-size: 1.05rem; }
.brand img { width: 32px; height: 32px; }
.brand-logo {
  display: inline-grid; place-items: center; width: 34px; height: 34px;
  border-radius: 9px; background: var(--surface); color: var(--accent);
}
.brand-logo .ico { width: 21px; height: 21px; }
.back {
  display: inline-grid; place-items: center;
  width: 42px; height: 42px; flex: none;
  border-radius: 12px; border: 0;
  background: var(--surface); color: var(--accent);
  cursor: pointer; text-decoration: none;
}
.back:hover { background: var(--surface-2); }
.back .ico { width: 22px; height: 22px; }

main { max-width: 760px; margin: 0 auto; padding: 4px 16px 40px; padding-bottom: max(40px, env(safe-area-inset-bottom)); }
.view-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.view-head:empty { display: none; }
.stack > * + * { margin-top: 16px; }

/* --- Start page tiles ----------------------------------------------------- */

.greeting { margin: 4px 2px 18px; }
.greeting strong { color: var(--on-bg); font-size: 1.5rem; display: block; font-weight: 650; }

.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
@media (min-width: 600px) { .tiles { grid-template-columns: repeat(3, 1fr); gap: 16px; } }

.tile {
  position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  aspect-ratio: 1 / 1;
  padding: 18px;
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow);
  color: var(--text); text-decoration: none;
  transition: transform .15s, border-color .15s;
}
.tile:hover { transform: translateY(-2px); border-color: var(--accent-border); }
.tile:active { transform: translateY(0); }
.tile .ico { width: 44%; max-width: 88px; aspect-ratio: 1; height: auto; color: var(--accent); }
.tile .ico svg { stroke-width: 1.5; }
.tile .label { font-weight: 650; font-size: 1.05rem; }
.tile { -webkit-touch-callout: none; user-select: none; -webkit-user-select: none; overflow: hidden; }
.tile.off { opacity: .4; }
.tile .off-note { position: absolute; top: 14px; left: 16px; font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }

/* Long-press feedback: bar fills along the bottom edge over 2 s */
.tile::after {
  content: ""; position: absolute; left: 0; bottom: 0; height: 4px; width: 0;
  background: var(--accent); border-radius: 0 4px 4px 0;
}
.tile.pressing { transform: scale(.97); }
.tile.pressing::after { width: 100%; transition: width 1s linear; }

/* Soundboard */
.tiles.three { grid-template-columns: repeat(3, 1fr); gap: 10px; }
.tile.sound, .tile.add { cursor: pointer; font: inherit; gap: 10px; padding: 12px; }
.tile.sound .ico, .tile.add .ico { width: 40%; height: auto; aspect-ratio: 1; color: var(--accent); }
.tile.sound .label, .tile.add .label { font-size: .9rem; line-height: 1.2; overflow-wrap: anywhere; }
.tile.add { background: transparent; border: 2px dashed var(--on-bg-muted); color: var(--on-bg-muted); box-shadow: none; }
.tile.add .ico { color: var(--on-bg-muted); }
.tile.sound.playing { border-color: var(--accent); animation: sound-pulse 1s ease-in-out infinite; }
@keyframes sound-pulse { 50% { box-shadow: 0 0 0 5px var(--accent-soft); } }
@media (prefers-reduced-motion: reduce) { .tile.sound.playing { animation: none; box-shadow: 0 0 0 3px var(--accent-soft); } }
.icon-pick { display: flex; flex-wrap: wrap; gap: 6px; }
.icon-pick button {
  width: 44px; height: 44px; display: grid; place-items: center;
  border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); color: var(--muted); cursor: pointer;
}
.icon-pick button .ico { width: 22px; height: 22px; }
.icon-pick button.sel { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }

/* Sound trim editor */
dialog.wide { width: min(640px, calc(100vw - 24px)); }
.wave { display: block; width: 100%; border-radius: 10px; background: var(--surface-2); touch-action: none; cursor: pointer; }
.wave.overview { height: 44px; }
.wave.detail { height: 120px; cursor: ew-resize; }
.tnum { font-variant-numeric: tabular-nums; min-width: 4.6em; text-align: center; display: inline-block; }
.trim-row { display: grid; gap: 4px; }
.trim-row .nudges { gap: 4px; }
.trim-row .nudges .btn.small { min-height: 32px; padding: 0 7px; font-size: .8rem; }
.range:disabled { opacity: .35; }
@media (max-width: 420px) { .trim-row .nudges .btn.small { padding: 0 5px; } .tnum { min-width: 4.2em; font-size: .85rem; } }
input[type=url] { width: 100%; padding: 10px 12px; background: var(--input); border: 1px solid var(--border); border-radius: 10px; outline: none; min-height: 44px; color: var(--text); }
input[type=url]:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input[type=file] { color: var(--text); }

/* Washer / dryer tiles */
.tiles.two { grid-template-columns: repeat(2, 1fr); }
.tile.machine { cursor: pointer; font: inherit; gap: 6px; }
.tile.machine .ring { position: relative; width: 62%; max-width: 140px; aspect-ratio: 1; display: grid; place-items: center; margin-bottom: 6px; }
.tile.machine .ring > svg.progress { position: absolute; inset: 0; width: 100%; height: 100%; transform: rotate(-90deg); }
.tile.machine .progress circle { fill: none; stroke-width: 5; }
.tile.machine .progress .track { stroke: var(--surface-2); }
.tile.machine .progress .bar { stroke: var(--accent); stroke-linecap: round; transition: stroke-dashoffset .6s; }
.tile.machine .ring .ico { width: 52%; height: auto; aspect-ratio: 1; color: var(--accent); }
.tile.machine .state { font-weight: 600; font-size: .95rem; }
.tile.machine .sub { color: var(--muted); font-size: .82rem; }
.tile.machine.idle .ring .ico { color: var(--muted); }
.tile.machine.done { border-color: var(--danger); }
.tile.machine.done .state { color: var(--danger); }
.tile.machine.done .progress .bar { stroke: var(--danger); }
.tile.machine.idle .progress .bar { stroke: none; }
@media (max-width: 420px) { .tile.machine { aspect-ratio: auto; padding: 18px 10px; } }

.tile .alert {
  position: absolute; top: 16px; right: 16px;
  min-width: 24px; height: 24px; padding: 0 7px;
  display: grid; place-items: center;
  border-radius: 99px; background: var(--accent); color: var(--accent-text);
  font-size: .8rem; font-weight: 700;
}
.tile .alert.danger { background: var(--danger); color: #2a0c0c; }

/* --- Cards & forms -------------------------------------------------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}
.card > h3 { margin-bottom: 12px; }

label.field { display: block; }
label.field > span { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 4px; }
input[type=text], input[type=password], input[type=date], input[type=time], input[type=number], input[type=search], select, textarea {
  width: 100%;
  padding: 10px 12px;
  background: var(--input);
  border: 1px solid var(--border);
  border-radius: 10px;
  outline: none;
  min-height: 44px;
}
input::placeholder, textarea::placeholder { color: #6f6e78; }
textarea { resize: vertical; min-height: 140px; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input[type=date]::-webkit-calendar-picker-indicator,
input[type=time]::-webkit-calendar-picker-indicator { filter: invert(.7); }

.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.form-grid { display: grid; gap: 12px; }

.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 16px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface-2); cursor: pointer; font-weight: 550; white-space: nowrap;
}
.btn:hover { border-color: #3a3a42; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: var(--danger-soft); }
.btn.small { min-height: 34px; padding: 0 10px; font-size: .88rem; }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn {
  display: inline-grid; place-items: center;
  width: 36px; height: 36px; flex: none;
  border: 0; border-radius: 8px; background: none; color: var(--muted); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); color: var(--accent); }
.icon-btn .ico { width: 19px; height: 19px; }

/* --- Lists ---------------------------------------------------------------- */

.list { list-style: none; margin: 0; padding: 0; }
.item {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 4px;
  border-bottom: 1px solid var(--border);
  min-height: 52px;
}
.item:last-child { border-bottom: 0; }
.item .body { flex: 1; min-width: 0; cursor: pointer; }
.item .title { overflow-wrap: anywhere; }
.item .meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 2px; font-size: .82rem; color: var(--muted); }
.item.done .title { text-decoration: line-through; color: var(--muted); }

.tick {
  appearance: none; flex: none;
  width: 26px; height: 26px; margin: 0;
  border: 2px solid #3d3c45; border-radius: 50%;
  cursor: pointer; display: grid; place-items: center;
  background: transparent;
}
.tick:hover { border-color: var(--accent); }
.tick:checked { background: var(--accent); border-color: var(--accent); }
.tick:checked::after {
  content: ""; width: 7px; height: 12px; margin-top: -3px;
  border: solid var(--accent-text); border-width: 0 2.5px 2.5px 0; transform: rotate(45deg);
}

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 1px 8px; border-radius: 99px;
  background: var(--surface-2); color: var(--muted); font-size: .78rem; font-weight: 550;
}
.badge.accent { background: var(--accent-soft); color: var(--accent); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.qty { font-weight: 600; color: var(--accent); margin-right: 6px; }

.group + .group { margin-top: 18px; }
.group > h3 { margin: 0 4px 4px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center;
  border: 1px solid var(--border); border-radius: 99px; background: var(--surface-2);
  font-size: .88rem; overflow: hidden;
}
.chip button { border: 0; background: none; cursor: pointer; padding: 6px 4px 6px 12px; }
.chip button.x { padding: 6px 10px 6px 6px; color: var(--muted); }
.chip button:hover { color: var(--accent); }
.chip button.x:hover { color: var(--danger); }

.seg { display: inline-flex; background: var(--surface); border-radius: 10px; padding: 3px; }
.seg button { border: 0; background: none; padding: 6px 12px; border-radius: 8px; cursor: pointer; color: var(--muted); font-weight: 550; font-size: .9rem; }
.seg button.on { background: var(--accent-soft); color: var(--accent); }

.empty { text-align: center; color: var(--muted); padding: 28px 8px; }

/* --- Notes ---------------------------------------------------------------- */

.notes-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.note {
  text-align: left; cursor: pointer;
  display: flex; flex-direction: column; gap: 6px;
  min-height: 120px;
}
.note:hover { border-color: var(--accent-border); }
.note .title { font-weight: 650; overflow-wrap: anywhere; }
.note .text {
  white-space: pre-wrap; overflow-wrap: anywhere; color: var(--muted); font-size: .92rem;
  display: -webkit-box; -webkit-line-clamp: 6; -webkit-box-orient: vertical; overflow: hidden;
}
.note .meta { margin-top: auto; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; font-size: .78rem; color: var(--muted); }

/* --- Calendar ------------------------------------------------------------- */

.cal-head { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.cal-head h2 { flex: 1; font-size: 1.15rem; text-align: center; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-wd { text-align: center; font-size: .75rem; font-weight: 600; color: var(--muted); padding: 2px 0 6px; }
.cal-day {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  height: 48px; padding: 7px 0 0;
  border: 1px solid transparent; border-radius: 10px;
  background: none; cursor: pointer; font-size: .92rem;
}
.cal-day:hover { background: var(--surface-2); }
.cal-day.out { color: #55545c; }
.cal-day.today { border-color: var(--accent); color: var(--accent); font-weight: 700; }
.cal-day.sel { background: var(--accent); color: var(--accent-text); font-weight: 700; }
.cal-dots { display: flex; gap: 3px; height: 6px; }
.cal-dots i { width: 5px; height: 5px; border-radius: 50%; background: var(--accent); }
.cal-dots i.task { background: none; border: 1px solid var(--muted); }
/* Dots carry the creator's color inline; on the selected day they get a ring so they stay visible. */
.cal-day.sel .cal-dots i { box-shadow: 0 0 0 1.5px var(--accent-text); }
.cal-day.sel .cal-dots i.task { border-color: var(--accent-text); box-shadow: none; }

/* Person colors */
.pdot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; flex: none; vertical-align: middle; }
.person { display: inline-flex; align-items: center; gap: 5px; }
.badge.person-badge { font-weight: 600; }

.swatches { display: grid; grid-template-columns: repeat(6, 1fr); gap: 10px; }
@media (max-width: 420px) { .swatches { grid-template-columns: repeat(4, 1fr); } }
.swatch {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  border: 0; background: none; padding: 0; cursor: pointer; color: var(--muted); font-size: .72rem;
}
.swatch i { width: 38px; height: 38px; border-radius: 50%; display: block; border: 3px solid transparent; outline: 2px solid transparent; }
.swatch.sel i { outline-color: var(--text); }
.swatch.sel { color: var(--text); font-weight: 600; }
.swatch:disabled { cursor: not-allowed; }
.swatch:disabled i { opacity: .25; }
.range { width: 100%; accent-color: var(--accent); }
.bg-scale { height: 10px; border-radius: 99px; background: linear-gradient(90deg, #111113, #f0f0f2); margin-top: 4px; }

.day-head { margin: 14px 4px 6px; }
.ev { border-left: 3px solid var(--accent); padding-left: 10px; }
.ev.task { border-left-color: #55545c; }
.ev .when { min-width: 56px; font-size: .85rem; color: var(--accent); font-weight: 600; }
.ev.task .when { color: var(--muted); }

.mod-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px 16px; }

/* --- Admin ---------------------------------------------------------------- */

.user-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.user-row:last-child { border-bottom: 0; }
.avatar {
  width: 38px; height: 38px; border-radius: 50%; flex: none;
  display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent); font-weight: 700;
}
.user-row.inactive { opacity: .55; }

/* --- Dialog & toast ------------------------------------------------------- */

dialog {
  width: min(520px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  padding: 0; border: 1px solid var(--border); border-radius: 18px;
  background: var(--surface); color: var(--text);
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
}
dialog::backdrop { background: rgba(0,0,0,.55); }
dialog form { padding: 20px; display: grid; gap: 14px; }
dialog .actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-top: 4px; }
dialog .actions .left { margin-right: auto; }

#toast {
  position: fixed; left: 50%; transform: translateX(-50%) translateY(20px);
  bottom: calc(24px + env(safe-area-inset-bottom));
  z-index: 100; pointer-events: none;
  padding: 10px 16px; border-radius: 10px;
  background: var(--accent); color: var(--accent-text); font-size: .92rem; font-weight: 550;
  max-width: calc(100vw - 32px);
  opacity: 0; transition: opacity .2s, transform .2s;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.error { background: var(--danger); color: #2a0c0c; }

/* --- Auth screens --------------------------------------------------------- */

.auth { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.auth .card { width: min(400px, 100%); padding: 28px 24px; }
.auth .brand { justify-content: center; margin-bottom: 6px; font-size: 1.3rem; }
.auth p { text-align: center; margin: 0 0 20px; }
.form-error { color: var(--danger); font-size: .9rem; min-height: 1.2em; }

/* Two-factor setup */
.auth .card.mfa { width: min(460px, 100%); }
.qr { width: 200px; max-width: 100%; padding: 8px; background: #fff; border-radius: 12px; }
.qr svg { display: block; width: 100%; height: auto; }
.secret { display: inline-block; margin-top: 6px; padding: 6px 8px; border-radius: 8px; background: var(--surface-2); letter-spacing: .05em; word-break: break-all; }
.codes { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; }
.codes code { padding: 8px; border-radius: 8px; background: var(--surface-2); text-align: center; font-size: 1rem; letter-spacing: .05em; }
