:root {
  --bg: #f6f7f9;
  --card: #ffffff;
  --text: #1c2430;
  --muted: #5d6878;
  --line: #dde2e8;
  --accent: #1f6feb;
  --accent-text: #ffffff;
  --mine: #2da44e;
  --available: #8fdf9f;
  --preferred: #1a7f37;
  --unavailable: #d9534f;
  --pref-dot: #f5b400;
  --heat: 31, 111, 235;
  --cell: #f1f3f6;
  --danger: #c93c37;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11151b;
    --card: #191f27;
    --text: #e5e9ef;
    --muted: #96a1b0;
    --line: #2c3540;
    --accent: #4c8dff;
    --mine: #3fb760;
    --available: #2f6b3d;
    --preferred: #4cc765;
    --unavailable: #c4504b;
    --pref-dot: #ffc83d;
    --heat: 76, 141, 255;
    --cell: #222a34;
    --danger: #f06b66;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

main { max-width: 1200px; margin: 0 auto; padding: 24px 16px 48px; }

h1 { font-size: 1.6rem; margin: 0 0 4px; }
h2 { font-size: 1.05rem; margin: 0 0 4px; }
.lede { color: var(--muted); margin: 0 0 20px; }
.muted { color: var(--muted); margin: 0; }
.small { font-size: 0.85rem; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 16px;
  margin-bottom: 16px;
}

label { display: flex; flex-direction: column; gap: 4px; font-weight: 500; font-size: 0.9rem; }
label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 400; }

input, select, button {
  font: inherit;
  color: inherit;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px 10px;
}
input:focus, select:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

button { cursor: pointer; font-weight: 500; }
button:hover { border-color: var(--muted); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }

.row { display: flex; flex-wrap: wrap; gap: 12px; }
.row > * { flex: 1 1 140px; }

#setup-form, #unlock-form { display: flex; flex-direction: column; gap: 14px; max-width: 560px; }
label .hint { font-weight: 400; }
.pw-row { display: flex; gap: 8px; }
.pw-row input { flex: 1; min-width: 0; }
.error { color: var(--danger); margin: 0; min-height: 1.2em; }

.board-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 16px;
}
.actions { display: flex; align-items: center; gap: 8px; }

.status { font-size: 0.85rem; color: var(--muted); margin-right: 4px; white-space: nowrap; }
.status::before {
  content: '';
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: 1px;
  background: var(--muted);
}
.status.live::before { background: var(--mine); }
.status.offline::before { background: var(--danger); }

.people { display: grid; grid-template-columns: minmax(180px, 260px) 1fr; gap: 16px; align-items: start; }
#participants { list-style: none; margin: 4px 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
#participants li {
  display: flex;
  align-items: center;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 4px 2px 10px;
  font-size: 0.85rem;
}
#participants li.me { border-color: var(--mine); }
#participants li button {
  border: 0;
  background: none;
  padding: 0 6px;
  color: var(--muted);
  line-height: 1.4;
}
#participants li button:hover { color: var(--danger); }

.grids { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grids > .card { margin-bottom: 16px; min-width: 0; }

.grid-wrap { position: relative; overflow-x: auto; margin-top: 12px; }
.grid {
  display: grid;
  gap: 1px;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  min-width: max-content;
}
.grid .day {
  text-align: center;
  font-size: 0.78rem;
  line-height: 1.25;
  padding-bottom: 4px;
  color: var(--muted);
}
.grid .day b { display: block; color: var(--text); font-weight: 600; }
.grid .time {
  font-size: 0.72rem;
  color: var(--muted);
  text-align: right;
  padding-right: 6px;
  transform: translateY(-0.6em);
  white-space: nowrap;
}
.grid .cell { height: 18px; background: var(--cell); }
.grid .cell.hour { box-shadow: inset 0 1px 0 var(--line); }

#mine .cell { cursor: pointer; }
#mine .cell.available { background: var(--available); }
#mine .cell.preferred { background: var(--preferred); }
#mine .cell.unavailable {
  background: repeating-linear-gradient(
    -45deg,
    var(--unavailable) 0 4px,
    color-mix(in srgb, var(--unavailable) 65%, var(--cell)) 4px 8px
  );
}

.brushes { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.brush { display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px; font-size: 0.85rem; }
.brush::before {
  content: '';
  width: 12px;
  height: 12px;
  border-radius: 3px;
  border: 1px solid var(--line);
  background: var(--cell);
}
.brush.available::before { background: var(--available); }
.brush.preferred::before { background: var(--preferred); }
.brush.unavailable::before { background: var(--unavailable); }
.brush[aria-pressed="true"] {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, var(--card));
}

#group .cell { position: relative; background: rgba(var(--heat), calc(0.08 + var(--a, 0) * 0.92)); }
#group .cell.pref::after,
.pref-dot {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--pref-dot);
}
#group .cell.pref::after {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  opacity: calc(0.45 + var(--p, 0) * 0.55);
}
.pref-dot { display: inline-block; margin-left: 10px; }
#group .cell.none { background: var(--cell); }
#group .cell.all { box-shadow: inset 0 0 0 2px var(--mine); }
#group .cell.hover { outline: 2px solid var(--text); outline-offset: -2px; }

.lock {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 16px;
  background: color-mix(in srgb, var(--card) 80%, transparent);
  font-weight: 500;
  cursor: pointer;
}
.lock[hidden] { display: none; }

.legend { display: flex; align-items: center; gap: 6px; }
.ramp {
  display: inline-block;
  width: 80px;
  height: 10px;
  border-radius: 3px;
  background: linear-gradient(to right, rgba(var(--heat), 0.08), rgba(var(--heat), 1));
}

.detail { margin-top: 12px; min-height: 7.5em; }
.detail strong { color: var(--text); }
.detail .who { color: var(--text); }

#best { margin: 8px 0 0; padding-left: 20px; }
#best li { margin: 2px 0; }
#best .empty { list-style: none; margin-left: -20px; color: var(--muted); }


#toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%) translateY(20px);
  background: var(--text);
  color: var(--bg);
  padding: 8px 16px;
  border-radius: 6px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 820px) {
  .grids, .people { grid-template-columns: 1fr; }
}
