:root {
  --bg: #f2f4f7;
  --card: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --accent: #2481cc;
  --accent-text: #ffffff;
  --good: #16a34a;
  --warn: #d97706;
  --bad: #dc2626;
  --z-good: #b9e6c9;
  --z-off: #eceef2;
  --z-night: #c5cad8;
  --radius: 14px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not(.light) {
    --bg: #0f1115;
    --card: #181b21;
    --text: #e8eaed;
    --muted: #9aa0a6;
    --line: #2a2f37;
    --good: #34d399;
    --warn: #fbbf24;
    --bad: #f87171;
    --z-good: #1d5236;
    --z-off: #262a31;
    --z-night: #0b0d11;
    color-scheme: dark;
  }
}

:root.dark {
  --line: rgba(255, 255, 255, 0.1);
  --good: #34d399;
  --warn: #fbbf24;
  --bad: #f87171;
  --z-good: #1d5236;
  --z-off: rgba(255, 255, 255, 0.08);
  --z-night: rgba(0, 0, 0, 0.45);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

.wrap { max-width: 720px; margin: 0 auto; padding: 16px 16px 120px; }
.loading, .empty { color: var(--muted); text-align: center; padding: 40px 0; }

h1 { font-size: 24px; margin: 4px 0 6px; }
h2 { font-size: 17px; margin: 0 0 8px; }
.top { margin: 4px 0 8px; }
.title {
  width: 100%;
  font: 700 23px/1.2 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: inherit;
  background: transparent;
  border: 0;
  border-bottom: 1px dashed transparent;
  padding: 4px 0;
}
.title:hover { border-bottom-color: var(--line); }
.title:focus { outline: none; border-bottom-color: var(--accent); }
.sub, .muted, .hint { color: var(--muted); font-size: 13px; margin: 4px 0; }
.hint { margin-top: 10px; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px;
  margin: 12px 0;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

button, .btn {
  font: inherit;
  font-size: 14px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--card);
  color: inherit;
  padding: 9px 13px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
button:disabled { opacity: 0.5; cursor: default; }
.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
.danger { color: var(--bad); }
.link { border: 0; background: none; padding: 0; color: var(--accent); }
.link.danger { color: var(--bad); }

.chips { position: relative; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.chips.scroll { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.chips.scroll::-webkit-scrollbar { display: none; }
.chip {
  flex: none;
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 13px;
  white-space: nowrap;
  background: transparent;
}
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.chip.good { border-color: var(--good); color: var(--good); margin: 2px 0; }
.chip.pick { flex-direction: row; align-items: center; color: inherit; border: 1px solid var(--line); cursor: pointer; }
.chip.pick input { border: 0; background: transparent; color: inherit; font: inherit; padding: 0; margin-left: 4px; max-width: 8.5em; }

.lanes { margin-top: 4px; }
.overlap { padding-bottom: 8px; }
.lane-label { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.lane { position: relative; height: 32px; border-radius: 9px; }
.overlap .lane { height: 10px; background: var(--z-off); border-radius: 5px; }
.ov-segs span { position: absolute; top: 0; bottom: 0; background: var(--good); border-radius: 5px; }

.row { padding: 10px 0 2px; border-top: 1px solid var(--line); }
.row-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 9px; }
.who {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  padding: 0;
  border: 0;
  background: none;
  text-align: left;
}
.avatar {
  flex: none;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 700;
  background: var(--z-off);
}
.row.me .avatar { background: var(--accent); color: var(--accent-text); }
.who-text { display: flex; flex-direction: column; min-width: 0; }
.who-text small { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me-tag {
  font-style: normal;
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  border: 1px solid currentColor;
  border-radius: 6px;
  padding: 0 4px;
  margin-left: 4px;
  vertical-align: 2px;
}
.when { flex: none; text-align: right; }
.when .t { display: block; font-size: 20px; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.when small { font-size: 12px; color: var(--muted); }
.d.other-day { color: var(--warn); font-weight: 600; }
.state { font-weight: 600; }
.row[data-comfort="good"] .state { color: var(--good); }
.row[data-comfort="off"] .state { color: var(--warn); }
.row[data-comfort="night"] .state { color: var(--bad); }

.track { cursor: grab; touch-action: pan-y; user-select: none; -webkit-user-select: none; outline: none; }
.track:focus-visible { box-shadow: 0 0 0 2px var(--accent); }
.track.dragging { cursor: grabbing; }
.zones { position: absolute; inset: 0; border-radius: inherit; }
.block {
  position: absolute;
  top: -4px;
  bottom: -4px;
  border: 2px solid var(--accent);
  border-radius: 9px;
  background: rgba(36, 129, 204, 0.2);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
  pointer-events: none;
  transition: left 0.08s linear, width 0.08s linear;
}
.track.dragging .block { transition: none; }
.overlap .block { top: -3px; bottom: -3px; background: transparent; box-shadow: none; }
.grip {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 6px;
  height: 12px;
  transform: translate(-50%, -50%);
  border-left: 2px solid var(--accent);
  border-right: 2px solid var(--accent);
  opacity: 0.8;
}
.ticks { position: relative; height: 18px; font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.tick { position: absolute; top: 3px; transform: translateX(-50%); }
.tick.first { transform: none; }
.tick.last { transform: translateX(-100%); }
.tick.day { color: var(--text); font-weight: 700; }

.nudge { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; margin: 12px 0 6px; }
.best { margin-top: 8px; line-height: 2; }

.fold { width: 100%; justify-content: space-between; border: 0; padding: 2px 0; font-weight: 600; background: none; }
.fold::after { content: "+"; font-size: 18px; color: var(--muted); }
.fold[aria-expanded="true"]::after { content: "-"; }

.person { border: 1px solid var(--line); border-radius: 12px; margin: 10px 0; padding: 10px 12px; }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 10px; }
.grid .wide { grid-column: 1 / -1; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
input {
  font: inherit;
  font-size: 15px;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 8px 10px;
  min-width: 0;
}
input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.person .link { margin-top: 8px; font-size: 13px; }
.editor-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.editor-actions .primary { margin-left: auto; }
.err { color: var(--bad); font-size: 13px; }
.field { font-size: 13px; }

.share { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
.result .share { margin-bottom: 0; }
.card-img { display: block; width: 100%; height: auto; border-radius: 12px; margin: 10px 0; }
.card-holder .card-img { margin: 12px 0; box-shadow: 0 6px 24px rgba(0, 0, 0, 0.18); }
.msg { border-radius: 12px; padding: 10px 12px; margin: 12px 0; font-size: 14px; }
.msg.err { background: rgba(220, 38, 38, 0.1); color: var(--bad); }

.latest { display: flex; gap: 12px; align-items: center; color: inherit; text-decoration: none; }
.latest img { width: 120px; flex: none; border-radius: 8px; }
.latest span { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.latest small { color: var(--muted); font-size: 12px; }

.times { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.times li { display: grid; grid-template-columns: 1fr auto; gap: 0 10px; align-items: baseline; }
.times li b { font-size: 18px; font-variant-numeric: tabular-nums; }
.times li > small { grid-column: 2; text-align: right; color: var(--muted); font-size: 12px; }
.times li span small { color: var(--muted); font-size: 12px; }

.actionbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 5;
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: center;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  background: var(--card);
  border-top: 1px solid var(--line);
}
.summary { flex: 1; max-width: 460px; display: flex; flex-direction: column; font-size: 13px; font-variant-numeric: tabular-nums; }
.summary .ok { color: var(--good); }
.summary .warn { color: var(--warn); }
.actionbar .primary { padding: 12px 18px; font-size: 15px; }

@media (max-width: 420px) {
  .when .t { font-size: 17px; }
  .nudge button { padding: 8px 9px; font-size: 13px; }
  .actionbar .primary { padding: 12px 14px; }
}
