:root {
  color-scheme: light;
  --bg: #f3f4f7;
  --surface: #ffffff;
  --surface-2: #f5f6f9;
  --text: #14171d;
  --muted: #5e6674;
  --faint: #99a0ac;
  --border: #e1e4ea;
  --focus: #2563eb;
  --danger: #dc2626;
  --warn: #b45309;
  --night: #4f46e5;
  --hl: #7c3aed;
  --gold: #d97706;
  --accent: #15803d;
  --accent-hover: #166534;
  --accent-text: #ffffff;
  --accent-ink: #15803d;
  --glow: rgb(34 197 94 / 0.10);
  --glow-2: rgb(124 58 237 / 0.07);
  --glow-strong: rgb(34 197 94 / 0.25);

  --cell: #eceff3;
  --pick: #2ecc6d;
  --pick-text: #04210f;
  --h1: #dcfce7; --h1-t: #14532d;
  --h2: #b4f1c8; --h2-t: #14532d;
  --h3: #74e09e; --h3-t: #052e16;
  --h4: #2fbf6a; --h4-t: #052e16;
  --h5: #15803d; --h5-t: #ffffff;

  --shadow: 0 1px 2px rgb(16 24 40 / 0.05), 0 8px 24px rgb(16 24 40 / 0.06);
  --radius: 16px;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", "Cascadia Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #0b0d11;
    --surface: #13161d;
    --surface-2: #191d26;
    --text: #e8ebf1;
    --muted: #98a1af;
    --faint: #5c6576;
    --border: #242a35;
    --focus: #60a5fa;
    --danger: #f87171;
    --warn: #fbbf24;
    --night: #a5b4fc;
    --hl: #b69cff;
    --gold: #fbbf24;
    --accent: #3ddc84;
    --accent-hover: #62e89e;
    --accent-text: #04210f;
    --accent-ink: #4ade80;
    --glow: rgb(61 220 132 / 0.10);
    --glow-2: rgb(139 92 246 / 0.10);
    --glow-strong: rgb(61 220 132 / 0.35);

    --cell: #1c212b;
    --pick: #3ddc84;
    --pick-text: #04210f;
    --h1: #16352a; --h1-t: #bfe8cf;
    --h2: #1a5236; --h2-t: #dcf5e6;
    --h3: #1f7a46; --h3-t: #effbf3;
    --h4: #2fb866; --h4-t: #03170a;
    --h5: #56e694; --h5-t: #03170a;

    --shadow: 0 1px 2px rgb(0 0 0 / 0.5), 0 10px 30px rgb(0 0 0 / 0.25);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(1100px 520px at 0% -8%, var(--glow), transparent 62%),
    radial-gradient(900px 480px at 100% -12%, var(--glow-2), transparent 60%),
    var(--bg);
  background-repeat: no-repeat;
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }

.wrap {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px max(16px, env(safe-area-inset-right)) 32px max(16px, env(safe-area-inset-left));
}

/* ---------- header ---------- */

.top { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; }
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.logo { width: 46px; height: 46px; flex: none; filter: drop-shadow(0 6px 16px var(--glow-strong)); }
h1 { margin: 0; font-size: clamp(24px, 6vw, 32px); line-height: 1.05; font-weight: 800; letter-spacing: -0.02em; }
.sub { margin: 3px 0 0; color: var(--muted); font-size: 14px; }
.top-actions { display: flex; align-items: center; gap: 8px; }
.lead { margin: 14px 0 16px; max-width: 62ch; color: var(--muted); }
@media (max-width: 480px) {
  .top { flex-wrap: nowrap; }
  #share { padding: 8px 11px; }
  #share span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .lead { margin: 12px 0 14px; font-size: 14px; }
}

/* ---------- buttons ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 40px; padding: 8px 14px;
  border: 1px solid var(--border); border-radius: 11px;
  background: var(--surface); font-size: 14px; font-weight: 600;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { min-height: 44px; padding: 10px 22px; border-color: transparent; background: var(--accent); color: var(--accent-text); font-size: 15px; }
.btn.primary:hover { background: var(--accent-hover); }
.btn:disabled { opacity: 0.6; cursor: progress; }
.icon { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.link {
  padding: 4px 0; border: 0; background: none; color: var(--muted); font-size: 14px;
  text-decoration: underline; text-decoration-color: var(--border); text-underline-offset: 3px;
}
.link:hover { color: var(--text); text-decoration-color: currentColor; }
.link.danger { color: var(--danger); }
.badge {
  display: inline-flex; align-items: center; gap: 2px; padding: 3px 4px 3px 10px; border-radius: 999px;
  background: color-mix(in srgb, var(--hl) 15%, transparent); color: var(--hl); font-size: 13px; font-weight: 600;
}
.badge .x { padding: 0 6px; border: 0; background: none; color: inherit; font-size: 17px; line-height: 1; }

/* ---------- cards ---------- */

.layout { display: grid; gap: 16px; }
@media (min-width: 1000px) {
  .layout { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: start; }
}
.card { padding: 18px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.card-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px 12px; margin-bottom: 12px; }
h2 { margin: 0; font-size: 19px; letter-spacing: -0.01em; }
h3 { margin: 22px 0 4px; font-size: 15px; }
.results h2 + .empty, .results h2 + #results-body > div:first-child h3 { margin-top: 14px; }
.hint { margin: 0 0 12px; color: var(--muted); font-size: 13.5px; }
.hint b { color: var(--text); font-weight: 600; }
.count { color: var(--muted); font-weight: 500; }
.muted { color: var(--muted); }
.empty { margin: 0; padding: 28px 8px 12px; text-align: center; color: var(--muted); }

/* ---------- hero: how many people at the same time ---------- */

.hero { display: flex; align-items: center; gap: 22px; margin-bottom: 16px; padding: 18px 22px; }
.hero-num { display: flex; flex: none; align-items: baseline; gap: 6px; font-family: var(--mono); }
.hero-num .big { font-size: 64px; line-height: 0.9; font-weight: 800; letter-spacing: -0.05em; color: var(--accent-ink); text-shadow: 0 0 30px var(--glow-strong); }
.hero-num .of { color: var(--muted); font-size: 18px; font-weight: 600; white-space: nowrap; }
.hero-text { min-width: 0; }
.hero-title { font-size: 18px; font-weight: 700; line-height: 1.3; }
.hero-sub { margin-top: 2px; color: var(--muted); font-size: 14px; }
.hero-runs { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.run {
  display: inline-flex; align-items: baseline; gap: 6px; padding: 5px 12px;
  border: 1px solid var(--border); border-radius: 999px; background: var(--surface-2);
  font-size: 14px; font-weight: 650; text-align: left;
}
.run small { color: var(--muted); font-size: 13px; font-weight: 500; }
.run:hover { border-color: var(--faint); }
.run[aria-pressed="true"] { border-color: var(--hl); box-shadow: inset 0 0 0 1px var(--hl); }
.hero .btn { margin-top: 10px; }
.hero-people { display: grid; flex: none; justify-items: end; gap: 4px; margin-left: auto; }
.faces { display: flex; padding-left: 8px; }
.faces .avatar { width: 30px; height: 30px; margin-left: -8px; border: 2px solid var(--surface); font-size: 13px; }
.faces .more { background: var(--surface-2); color: var(--muted); font-size: 11px; }
@media (max-width: 700px) { .hero-people { display: none; } }
@media (max-width: 560px) {
  .hero { align-items: flex-start; gap: 14px; padding: 16px; }
  .hero-num { flex-direction: column; align-items: center; gap: 2px; min-width: 56px; }
  .hero-num .big { font-size: 52px; }
  .hero-num .of { font-size: 14px; }
  .hero-title { font-size: 16px; }
}

/* ---------- form ---------- */

.field { display: grid; gap: 6px; margin: 0 0 14px; }
.field > span { color: var(--muted); font-size: 13px; font-weight: 600; }
.field i { font-style: normal; font-weight: 400; }
input[type="text"] {
  width: 100%; min-height: 44px; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: 11px; background: var(--surface-2);
  font-size: 16px;
}
input[type="text"]::placeholder { color: var(--faint); }
input[type="text"]:focus { outline: 2px solid var(--focus); outline-offset: 0; border-color: transparent; background: var(--surface); }
input[aria-invalid="true"] { border-color: var(--danger); }
.field-error { margin: -8px 0 14px; color: var(--danger); font-size: 13.5px; }
.field-error .link { color: inherit; font-weight: 600; }

/* ---------- grids ---------- */

.grid {
  width: calc(100% + 6px); margin: 0 -3px;
  table-layout: fixed; border-collapse: separate; border-spacing: 3px;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
.grid col.c-time { width: 50px; }
.grid thead th { padding: 0 0 4px; font-weight: 400; vertical-align: bottom; }
.grid .wd { display: block; color: var(--muted); font-size: 12px; line-height: 1.2; }
.grid .dm { display: block; font-size: 14px; font-weight: 700; line-height: 1.25; white-space: nowrap; }
.grid tbody th { padding: 0 6px 0 0; color: var(--muted); font: 500 12px/1 var(--mono); text-align: right; white-space: nowrap; }
.grid tbody th.night { color: var(--night); }
.grid td.cell {
  height: 30px; padding: 0; border-radius: 7px; background: var(--cell);
  color: var(--faint); font: 700 12px/1 var(--mono); text-align: center; vertical-align: middle;
}
.grid td.cell.off { background: repeating-linear-gradient(135deg, transparent 0 5px, var(--border) 5px 6px); cursor: not-allowed; }
.grid tr.midnight td { padding: 5px 0 2px; }
.midnight-label { display: flex; align-items: center; gap: 8px; color: var(--night); font-size: 12px; font-weight: 600; }
.midnight-label::before, .midnight-label::after { content: ""; flex: 1; border-top: 1px dashed color-mix(in srgb, var(--night) 40%, transparent); }
.midnight-label .icon { width: 13px; height: 13px; }
.hbtn { display: block; width: 100%; padding: 4px 0; border: 0; border-radius: 8px; background: none; font: inherit; text-align: inherit; }
thead .hbtn { text-align: center; }
.hbtn:hover { background: var(--surface-2); }

.pick td.cell { cursor: pointer; touch-action: none; color: var(--muted); font-weight: 600; }
.pick td.cell.on { background: var(--pick); color: var(--pick-text); font-weight: 700; }
@media (hover: hover) { .pick td.cell:not(.off):hover { box-shadow: inset 0 0 0 2px var(--pick); } }
.grid-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 8px 0 16px; color: var(--muted); font-size: 13.5px; }

.heat td.cell { cursor: pointer; }
.heat td.l1 { background: var(--h1); color: var(--h1-t); }
.heat td.l2 { background: var(--h2); color: var(--h2-t); }
.heat td.l3 { background: var(--h3); color: var(--h3-t); }
.heat td.l4 { background: var(--h4); color: var(--h4-t); }
.heat td.l5 { background: var(--h5); color: var(--h5-t); }
.heat td.all { box-shadow: inset 0 0 0 2px var(--gold); }
.heat td.hl { box-shadow: inset 0 0 0 2px var(--hl); }
.heat.focusing td.cell:not(.hl):not(.off) { opacity: 0.22; }
.heat td.pinned { outline: 2px solid var(--focus); outline-offset: 1px; }
.peak-badge { display: block; min-height: 15px; margin-top: 1px; color: var(--accent-ink); font-size: 11px; font-weight: 700; white-space: nowrap; }

.legend { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; margin-top: 8px; color: var(--muted); font-size: 12px; }
.legend i { width: 18px; height: 10px; border-radius: 3px; }
.legend .l1 { background: var(--h1); } .legend .l2 { background: var(--h2); } .legend .l3 { background: var(--h3); }
.legend .l4 { background: var(--h4); } .legend .l5 { background: var(--h5); }
.legend > span:first-child { margin-right: 2px; }
.legend > span:nth-last-child(2) { margin-left: 2px; }
.legend-all { display: inline-flex; align-items: center; gap: 5px; margin-left: 12px; }
.legend .all { background: var(--h5); box-shadow: inset 0 0 0 2px var(--gold); }

.detail { min-height: 66px; margin-top: 10px; padding: 10px 12px; border-radius: 12px; background: var(--surface-2); font-size: 14px; }
.detail-head { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 2px; }
.detail-n { color: var(--accent-ink); font-family: var(--mono); font-weight: 700; white-space: nowrap; }
.detail-no, .detail .lbl { color: var(--muted); }

.focus-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 0 0 8px; padding: 5px 6px 5px 12px;
  border-radius: 10px; background: color-mix(in srgb, var(--hl) 14%, transparent); font-size: 13.5px;
}
.focus-bar b { color: var(--hl); }

/* ---------- best options ---------- */

.best { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; }
.win {
  display: flex; align-items: flex-start; gap: 12px; width: 100%; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: 12px; background: var(--surface-2); text-align: left;
}
.win:hover { border-color: var(--faint); }
.win[aria-pressed="true"] { border-color: var(--hl); box-shadow: inset 0 0 0 1px var(--hl); }
.win-count {
  flex: none; min-width: 54px; padding: 5px 6px; border-radius: 10px;
  background: var(--h4); color: var(--h4-t); font-family: var(--mono); line-height: 1.1; text-align: center;
}
.win-count b { display: block; font-size: 20px; }
.win-count small { font-size: 11px; }
.win-count.all { background: var(--h5); color: var(--h5-t); box-shadow: inset 0 0 0 2px var(--gold); }
.win-body { display: grid; gap: 1px; min-width: 0; }
.win-when { font-weight: 700; }
.win-meta, .win-missing { color: var(--muted); font-size: 13px; }
.win-who { font-size: 13.5px; overflow-wrap: anywhere; }

/* ---------- people ---------- */

.people { display: grid; margin: 6px 0 0; padding: 0; list-style: none; }
.person { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; padding: 9px 0; border-top: 1px solid var(--border); }
.person:first-child { border-top: 0; }
.avatar {
  display: grid; flex: none; place-items: center; width: 34px; height: 34px; border-radius: 50%;
  background: hsl(var(--hue, 150) 52% 44%); color: #fff; font-weight: 700;
}
.p-main { flex: 1 1 150px; min-width: 0; }
.p-name { font-weight: 600; overflow-wrap: anywhere; }
.p-meta { color: var(--muted); font-size: 13.5px; overflow-wrap: anywhere; }
.p-hours { font: 600 13px var(--mono); }
.p-hours.none { color: var(--danger); font-family: inherit; }
.p-hours + .p-comment::before { content: "·"; margin: 0 6px; }
.p-actions { display: flex; flex: none; gap: 4px; margin-left: auto; }
.chip { min-height: 30px; padding: 3px 10px; border: 1px solid var(--border); border-radius: 999px; background: var(--surface); font-size: 13px; }
.chip:hover { background: var(--surface-2); }
.chip[aria-pressed="true"] { border-color: var(--hl); color: var(--hl); }
.chip.danger { color: var(--danger); }
.tag {
  margin-left: 6px; padding: 1px 7px; border-radius: 999px; vertical-align: 1px;
  background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--accent-ink); font-size: 12px; font-weight: 600;
}

/* ---------- save bar, notices, toast ---------- */

.entry-actions { display: flex; flex-wrap: wrap; gap: 4px 18px; margin: -4px 0 10px; }
.notice {
  margin: 4px 0 0; padding: 12px 14px; border-radius: 12px; font-size: 14px;
  border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
  background: color-mix(in srgb, var(--accent) 10%, var(--surface));
}
.notice p { margin: 4px 0 8px; color: var(--muted); }
.copy-row { display: flex; gap: 8px; }
.copy-row input[type="text"] { min-height: 40px; font: 13px var(--mono); }
.savebar {
  position: sticky; bottom: 0; z-index: 3;
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px;
  margin: 16px -18px -18px; padding: 12px 18px;
  border-top: 1px solid var(--border); border-radius: 0 0 var(--radius) var(--radius);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
}
.save-state { color: var(--muted); font-size: 13.5px; }
.save-state.warn { color: var(--warn); }
.toast {
  position: fixed; left: 50%; bottom: calc(88px + env(safe-area-inset-bottom)); z-index: 20; transform: translateX(-50%);
  width: max-content; max-width: min(520px, calc(100vw - 32px)); padding: 11px 16px; border-radius: 12px;
  background: var(--text); color: var(--bg); box-shadow: 0 10px 30px rgb(0 0 0 / 0.25); font-size: 14px; font-weight: 600;
}
.toast.error { background: var(--danger); color: #fff; }

.foot { margin-top: 24px; color: var(--faint); font-size: 13px; text-align: center; }
