:root {
  color-scheme: dark;
  --bg: #0b0d0c;
  --panel: #131715;
  --panel-2: #1a1f1c;
  --line: #2a312d;
  --text: #e6ebe7;
  --muted: #8b968f;
  --signal: #ffb000;
  --clear: #3ddc84;
  --danger: #ff6b5f;
  --mono: "IBM Plex Mono", ui-monospace, Consolas, monospace;
  --sans: "IBM Plex Sans", "Segoe UI", system-ui, sans-serif;
  --r: 10px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 400 15px/1.45 var(--sans);
  min-height: 100vh;
  /* faint scanlines */
  background-image: repeating-linear-gradient(0deg, rgba(255,255,255,.012) 0 1px, transparent 1px 3px);
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--signal); outline-offset: 2px; }
[hidden] { display: none !important; }

.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ---------- header ---------- */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 16px clamp(16px, 3vw, 32px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand h1 { margin: 0; font: 600 26px/1 var(--mono); letter-spacing: .08em; color: var(--signal); text-shadow: 0 0 14px rgba(255,176,0,.35); }
.freq { font: 400 12px/1.4 var(--mono); color: var(--muted); letter-spacing: .06em; margin-top: 4px; }
.wave { width: 64px; height: 24px; }
.wave path { fill: none; stroke: var(--signal); stroke-width: 2.2; stroke-linejoin: round; stroke-dasharray: 160; animation: buzz 2.4s linear infinite; }
@keyframes buzz { from { stroke-dashoffset: 320; } to { stroke-dashoffset: 0; } }
@media (prefers-reduced-motion: reduce) { .wave path { animation: none; stroke-dasharray: none; } }
.who { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.chip {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--panel);
}
.chip .dot { width: 10px; height: 10px; border-radius: 50%; }
.ghost { background: transparent; border: 1px solid var(--line); border-radius: 8px; padding: 6px 12px; }
.ghost:hover { border-color: var(--muted); }
.ghost.small { padding: 4px 10px; font-size: 13px; }
.primary { background: var(--signal); color: #1a1200; border: 0; border-radius: 8px; padding: 9px 16px; font-weight: 600; }
.primary:hover { filter: brightness(1.08); }
.danger { color: var(--danger); }

/* ---------- layout ---------- */
#app {
  display: grid; gap: 20px;
  grid-template-columns: minmax(0, 1fr) 300px;
  grid-template-areas: "tools tools" "cal side";
  padding: 20px clamp(16px, 3vw, 32px) 40px;
  max-width: 1280px; margin: 0 auto;
}
.toolbar { grid-area: tools; display: flex; align-items: flex-end; gap: 12px 20px; flex-wrap: wrap; }
.toolbar .tool { display: flex; flex-direction: column; gap: 5px; }
.toolbar .primary { margin-left: auto; }
select { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; }
select:focus { border-color: var(--signal); outline: none; }

/* schedules panel + editor */
.sched-group { margin-top: 10px; }
.sched-group:first-child { margin-top: 2px; }
.sched-group h5 { margin: 0 0 4px; font: 600 13px var(--sans); display: flex; align-items: center; gap: 7px; }
.sched-group h5 .dot { width: 9px; height: 9px; border-radius: 50%; }
.sched { display: flex; flex-direction: column; gap: 1px; padding: 5px 6px 5px 16px; border-radius: 6px; font-size: 13.5px; }
.sched .w { color: var(--muted); font-size: 12.5px; }
button.sched { width: 100%; background: transparent; border: 0; text-align: left; }
button.sched:hover { background: var(--panel-2); }
.cat { font: 600 10px var(--mono); text-transform: uppercase; letter-spacing: .06em; padding: 1px 5px; border-radius: 4px; margin-right: 6px; vertical-align: 1px; background: rgba(255,255,255,.08); color: var(--muted); }
.cat.work { color: #8ec5ff; } .cat.kids { color: #ffb3d1; } .cat.band { color: #ffd680; } .cat.other { color: #c7cfc9; }
.days7 { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.days7 label { text-align: center; }
.days7 input { position: absolute; opacity: 0; pointer-events: none; }
.days7 span { display: block; padding: 7px 0; border: 1px solid var(--line); border-radius: 8px; font: 600 12px var(--mono); cursor: pointer; }
.days7 input:checked + span { background: var(--me, var(--signal)); color: #111; border-color: transparent; }
.days7 input:focus-visible + span { outline: 2px solid var(--signal); outline-offset: 2px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field > span { font-size: 13px; color: var(--muted); }
input[type=date], input[type=time] { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; color-scheme: dark; }
.check { display: inline-flex; align-items: center; gap: 8px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.people .what { color: var(--text); font-size: 13px; }
.cal-wrap { grid-area: cal; min-width: 0; }
.side { grid-area: side; display: flex; flex-direction: column; gap: 16px; }
@media (max-width: 900px) {
  #app { grid-template-columns: minmax(0, 1fr); grid-template-areas: "tools" "cal" "side"; }
}
.label { color: var(--muted); font-size: 13px; }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--panel); }
.seg button { border: 0; background: transparent; padding: 8px 14px; display: inline-flex; align-items: center; gap: 7px; border-right: 1px solid var(--line); }
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--panel-2); color: var(--signal); box-shadow: inset 0 -2px 0 var(--signal); }
.sw { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.sw.busy { background: var(--me, var(--signal)); }
.sw.maybe { background: repeating-linear-gradient(45deg, var(--me, var(--signal)) 0 2px, transparent 2px 4px); outline: 1px solid var(--me, var(--signal)); outline-offset: -1px; }
.sw.free { border: 1px solid var(--muted); }

/* ---------- calendar ---------- */
.cal-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.cal-head h2 { margin: 0; font: 600 20px/1.2 var(--mono); letter-spacing: .04em; min-width: 9.5em; text-align: center; }
.dow, .grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.dow span { font: 400 11px var(--mono); color: var(--muted); text-transform: uppercase; letter-spacing: .08em; padding: 0 4px 4px; }
.grid { user-select: none; -webkit-user-select: none; }
.grid.painting { touch-action: none; }

.day {
  position: relative; min-height: 96px; padding: 6px 6px 8px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  display: flex; flex-direction: column; gap: 4px; text-align: left; overflow: hidden;
}
.day:hover { border-color: #46504a; }
.day.out { opacity: .38; }
.day.past { opacity: .55; }
.day.today .num { background: var(--signal); color: #1a1200; }
.day.clear { border-color: rgba(61,220,132,.55); box-shadow: inset 0 0 0 1px rgba(61,220,132,.25), 0 0 12px rgba(61,220,132,.08); }
.day.clear .num::after { content: "all free"; margin-left: 6px; font: 600 9px var(--mono); letter-spacing: .06em; color: var(--clear); text-transform: uppercase; vertical-align: 2px; }
.day.sel { outline: 2px solid var(--signal); outline-offset: -2px; }
.num { font: 600 13px/1 var(--mono); padding: 3px 5px; border-radius: 5px; align-self: flex-start; }

/* One thin line per person: a timeline from 6am to midnight. */
.lines { display: flex; flex-direction: column; gap: 3px; margin-top: auto; }
.line { position: relative; height: 5px; border-radius: 3px; background: rgba(255,255,255,.06); overflow: hidden; }
.line i { position: absolute; top: 0; bottom: 0; background: var(--c); border-radius: 2px; }
.line.maybe { background: repeating-linear-gradient(45deg, var(--c) 0 2px, transparent 2px 4px); box-shadow: inset 0 0 0 1px var(--c); }
.line .win { background: rgba(61,220,132,.18); border-radius: 0; }

.ev { font-size: 11.5px; line-height: 1.25; background: rgba(255,176,0,.14); color: #ffd680; border-radius: 4px; padding: 2px 5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.notes-flag { position: absolute; top: 6px; right: 7px; width: 6px; height: 6px; border-radius: 50%; background: var(--muted); }

@media (max-width: 560px) {
  .day { min-height: 66px; padding: 4px 3px 5px; }
  .num { font-size: 12px; padding: 2px 4px; }
  .day.clear .num::after { content: ""; }
  .ev { font-size: 0; height: 5px; padding: 0; background: var(--signal); }
  .lines { gap: 2px; }
  .line { height: 4px; }
  .toolbar .tool { width: 100%; }
  .toolbar .primary { width: 100%; }
  .seg button { padding: 8px 10px; }
  .cal-head h2 { font-size: 17px; min-width: 0; flex: 1; }
}

.legend { display: flex; flex-wrap: wrap; gap: 8px 16px; margin-top: 12px; font-size: 13px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 14px; height: 8px; border-radius: 2px; display: inline-block; }

/* ---------- side panels ---------- */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 14px 16px; }
.panel h3 { margin: 0 0 4px; font: 600 14px var(--mono); letter-spacing: .06em; text-transform: uppercase; color: var(--signal); }
.panel p { margin: 4px 0 10px; }
.clear-list, .plan-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.clear-list button, .plan-list button.go {
  width: 100%; text-align: left; background: transparent; border: 0; border-radius: 6px; padding: 6px 8px;
  display: flex; justify-content: space-between; gap: 10px;
}
.clear-list button:hover, .plan-list button.go:hover { background: var(--panel-2); }
.clear-list .d { font-family: var(--mono); }
.clear-list .tag { color: var(--clear); font-size: 12px; }
.plan-list .t { color: var(--muted); font-size: 13px; font-family: var(--mono); white-space: nowrap; }
.empty { color: var(--muted); font-size: 13px; padding: 4px 8px; }

/* ---------- login ---------- */
.login { display: grid; place-items: center; min-height: 70vh; padding: 16px; }
.login form { width: min(360px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 24px; display: flex; flex-direction: column; gap: 12px; }
.login h2 { margin: 0; font: 600 20px var(--mono); color: var(--signal); }
.login p { margin: 0; }
input[type=text], input[type=password], input:not([type]) {
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; width: 100%;
}
input:focus { border-color: var(--signal); outline: none; }
.err { color: var(--danger); min-height: 1.2em; font-size: 14px; }

/* ---------- dialog ---------- */
dialog {
  background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 14px;
  padding: 0; width: min(460px, calc(100vw - 32px)); max-height: calc(100vh - 48px);
}
dialog::backdrop { background: rgba(0,0,0,.6); }
.dlg { padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.dlg h2 { margin: 0; font: 600 18px var(--mono); }
.dlg h4 { margin: 4px 0 0; font: 600 12px var(--mono); color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
.dlg .row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.dlg .end { justify-content: flex-end; }
.people { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.people li { display: flex; align-items: baseline; gap: 8px; }
.people .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; transform: translateY(1px); }
.people .st { font-family: var(--mono); font-size: 13px; }
.people .st.busy { color: var(--danger); }
.people .st.maybe { color: var(--signal); }
.people .st.free { color: var(--clear); }
.people .nt { color: var(--muted); font-size: 13px; }
.mine { background: var(--panel-2); border-radius: 10px; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.plans { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.plans li { display: flex; gap: 8px; align-items: center; justify-content: space-between; background: var(--panel-2); border-radius: 8px; padding: 6px 6px 6px 10px; }
.plans .x { border: 0; background: transparent; color: var(--muted); padding: 2px 8px; font-size: 18px; line-height: 1; }
.plans .x:hover { color: var(--danger); }
.pick { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.pick button { padding: 14px 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel-2); display: flex; align-items: center; gap: 10px; }
.pick button:hover { border-color: var(--c); }
.pick .dot { width: 14px; height: 14px; border-radius: 50%; background: var(--c); }
.members-edit { display: flex; flex-direction: column; gap: 8px; }
.members-edit .row { flex-wrap: nowrap; }
.members-edit input[type=color] { width: 40px; height: 38px; padding: 2px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); flex: none; }

#toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%);
  background: #232a26; border: 1px solid var(--line); border-radius: 10px; padding: 10px 16px; z-index: 10;
  box-shadow: 0 8px 24px rgba(0,0,0,.4); max-width: calc(100vw - 32px);
}
#toast.err { border-color: var(--danger); }
