/* Color belongs to people. Everything else stays ink and grey. */
:root {
  color-scheme: light;
  --bg: #EEF1F5;
  --surface: #FFFFFF;
  --surface-2: #F6F7FA;
  --ink: #18202E;
  --muted: #5F6B7D;
  --faint: #98A2B3;
  --line: #DCE1E8;
  --line-strong: #C3CAD5;
  --hover: rgba(24, 32, 46, .045);
  --select: rgba(37, 82, 214, .14);
  --focus: #2552D6;
  --danger: #B42318;
  --on-danger: #FFFFFF;
  --banner-bg: #FDECEA;
  --bar-bg-s: 72%;
  --bar-bg-l: 87%;
  --bar-fg-s: 60%;
  --bar-fg-l: 24%;
  --ring-l: 42%;
  --mark-l: 52%;
  --shadow: 0 24px 60px -20px rgba(16, 24, 40, .45);
  --num-h: 2rem;
  --lane-h: 1.5rem;
  --lane-pad: 1.75rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #0F131A;
    --surface: #171C25;
    --surface-2: #13171F;
    --ink: #E6E9EF;
    --muted: #9BA5B5;
    --faint: #5E6878;
    --line: #262D39;
    --line-strong: #364050;
    --hover: rgba(230, 233, 239, .045);
    --select: rgba(125, 155, 255, .2);
    --focus: #7D9BFF;
    --danger: #FF8A80;
    --on-danger: #1A0F0E;
    --banner-bg: #3A1D1B;
    --bar-bg-s: 42%;
    --bar-bg-l: 29%;
    --bar-fg-s: 75%;
    --bar-fg-l: 90%;
    --ring-l: 68%;
    --mark-l: 62%;
    --shadow: 0 24px 60px -20px rgba(0, 0, 0, .8);
  }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 400 .9375rem/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* ---- Top bar ---------------------------------------------------------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  max-width: 84rem;
  margin: 0 auto;
  padding: 1rem 1.5rem 0;
}
.brand { margin: 0; font-size: .9375rem; font-weight: 650; color: var(--muted); }
.me { display: flex; align-items: center; gap: .25rem; color: var(--muted); }
.me strong { display: inline-flex; align-items: center; gap: .4rem; color: var(--ink); font-weight: 600; }
.me strong::before {
  content: "";
  width: .625rem;
  height: .625rem;
  border-radius: 50%;
  background: hsl(var(--h, 220) 62% var(--mark-l));
}
.text-btn {
  padding: .25rem .375rem;
  border: 0;
  border-radius: 4px;
  background: none;
  color: var(--focus);
  font-weight: 600;
}
.text-btn:hover { text-decoration: underline; }

/* ---- Layout ----------------------------------------------------------- */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 19rem;
  gap: 2.5rem;
  align-items: start;
  max-width: 84rem;
  margin: 0 auto;
  padding: 1.25rem 1.5rem 3rem;
}

/* ---- Locked (missing or wrong access key) ------------------------------ */
body.is-locked .cal,
body.is-locked .panel,
body.is-locked .me { display: none; }
body.is-locked .layout { grid-template-columns: minmax(0, 36rem); }
.gate h2 {
  margin: 2rem 0 1rem;
  font-size: clamp(1.75rem, 1.1rem + 2.4vw, 2.75rem);
  line-height: 1.05;
  font-weight: 750;
  letter-spacing: -.025em;
}
.gate p { margin: 0 0 .75rem; color: var(--muted); }
.gate code {
  padding: .1em .35em;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--surface);
  color: var(--ink);
  font: 600 .875em ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* ---- Calendar header -------------------------------------------------- */
.cal-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}
.month {
  margin: 0;
  font-size: clamp(1.75rem, 1.1rem + 2.4vw, 2.75rem);
  line-height: 1.05;
  font-weight: 750;
  letter-spacing: -.025em;
}
.nav { display: flex; gap: .375rem; }
.nav button {
  display: inline-grid;
  place-items: center;
  height: 2.25rem;
  min-width: 2.25rem;
  padding: 0 .75rem;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--surface);
  font-weight: 600;
}
.nav button:hover { border-color: var(--muted); }

.banner {
  margin: 0 0 1rem;
  padding: .75rem 1rem;
  border-radius: 6px;
  background: var(--banner-bg);
  color: var(--danger);
  font-size: .875rem;
}

/* ---- Month grid ------------------------------------------------------- */
.grid {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  -webkit-user-select: none;
  user-select: none;
}
.weekdays,
.week {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
}
.weekdays { border-bottom: 1px solid var(--line); }
.weekdays div {
  padding: .5rem .625rem;
  color: var(--muted);
  font-size: .8125rem;
  font-weight: 600;
}
.week { min-height: 6.75rem; }
.week + .week { border-top: 1px solid var(--line); }

.day {
  position: relative;
  grid-row: 1 / -1;
  display: block;
  margin: 0;
  padding: 0;
  border: 0;
  border-left: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
  text-align: left;
}
.day:first-child { border-left: 0; }
.day:hover { background: var(--hover); }
.day.outside { background: var(--surface-2); }
.day.selecting { background: var(--select); }
.day:focus-visible { outline-offset: -2px; }

.num {
  position: absolute;
  top: .375rem;
  left: .5rem;
  display: inline-grid;
  place-items: center;
  min-width: 1.5rem;
  height: 1.5rem;
  padding: 0 .25rem;
  border-radius: 999px;
  font-size: .8125rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.day.past .num { color: var(--muted); }
.day.outside .num { color: var(--faint); }
.day.today .num { background: var(--ink); color: var(--surface); }

/* Blockout bars: one lane per overlap, continuous across days in a week. */
.bar {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: .4em;
  min-width: 0;
  margin: 1px 4px;
  padding: 0 .5rem;
  border: 0;
  border-radius: 5px;
  background: hsl(var(--h) var(--bar-bg-s) var(--bar-bg-l));
  color: hsl(var(--h) var(--bar-fg-s) var(--bar-fg-l));
  font-size: .8125rem;
  line-height: 1;
  white-space: nowrap;
  overflow: hidden;
  text-align: left;
}
.bar:hover { filter: saturate(1.25); }
.bar.mine { box-shadow: inset 0 0 0 1.5px hsl(var(--h) 60% var(--ring-l)); }
.bar.cont-left { margin-left: 0; border-top-left-radius: 0; border-bottom-left-radius: 0; }
.bar.cont-right { margin-right: 0; border-top-right-radius: 0; border-bottom-right-radius: 0; }
.bar-name { flex: none; max-width: 100%; overflow: hidden; text-overflow: ellipsis; font-weight: 650; }
.bar-note { min-width: 0; overflow: hidden; text-overflow: ellipsis; opacity: .8; }
.weeks.dragging .bar { pointer-events: none; }

.hint { margin: .75rem 0 0; color: var(--muted); font-size: .875rem; }
.hint .touch { display: none; }
@media (hover: none) {
  .hint .mouse { display: none; }
  .hint .touch { display: inline; }
}

/* ---- Month list ------------------------------------------------------- */
.panel h2 { margin: 0 0 .75rem; font-size: 1rem; font-weight: 650; }
.items { margin: 0; padding: 0; list-style: none; border-top: 1px solid var(--line); }
.item {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  column-gap: .75rem;
  padding: .75rem 0 .75rem 1rem;
  border-bottom: 1px solid var(--line);
}
.item::before {
  content: "";
  position: absolute;
  top: .875rem;
  bottom: .875rem;
  left: 0;
  width: 4px;
  border-radius: 2px;
  background: hsl(var(--h) 62% var(--mark-l));
}
.item-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: .125rem .5rem; }
.item-head strong { font-weight: 650; }
.item-dates { color: var(--muted); font-size: .875rem; font-variant-numeric: tabular-nums; }
.item-note { grid-column: 1; margin: .25rem 0 0; font-size: .875rem; white-space: pre-wrap; overflow-wrap: anywhere; }
.item .text-btn { grid-column: 2; grid-row: 1; align-self: start; }
.empty-note { margin: 0; color: var(--muted); font-size: .875rem; }

/* ---- Dialogs ---------------------------------------------------------- */
dialog {
  width: min(28rem, calc(100vw - 2rem));
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(12, 17, 26, .5); }
dialog[open] { animation: pop .16s ease-out; }
@keyframes pop { from { opacity: 0; transform: translateY(6px) scale(.985); } }

.sheet { display: grid; gap: 1rem; padding: 1.25rem; }
.sheet h2 { margin: 0; font-size: 1.25rem; font-weight: 700; letter-spacing: -.01em; }
.sheet p { margin: 0; }
.sub { margin-top: .25rem !important; color: var(--muted); font-size: .875rem; }
.field { display: grid; gap: .375rem; font-size: .875rem; font-weight: 600; }
.opt { color: var(--muted); font-weight: 400; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
input, textarea {
  width: 100%;
  padding: .55rem .7rem;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--bg);
  font-size: 1rem;
  font-weight: 400;
}
textarea { min-height: 5.5rem; resize: vertical; }
.form-error { color: var(--danger); font-size: .875rem; }

.actions { display: flex; align-items: center; gap: .5rem; }
.spacer { flex: 1; }
.btn {
  height: 2.5rem;
  padding: 0 1rem;
  border: 1px solid transparent;
  border-radius: 6px;
  font-weight: 600;
}
.btn.primary { background: var(--ink); color: var(--surface); }
.btn.ghost { border-color: var(--line-strong); background: transparent; }
.btn.danger { padding: 0 .5rem; background: transparent; color: var(--danger); }
.btn.danger.armed { padding: 0 1rem; background: var(--danger); color: var(--on-danger); }
.btn:disabled { opacity: .6; cursor: progress; }

.view-title { display: flex; align-items: center; gap: .5rem; }
.view-title::before {
  content: "";
  flex: none;
  width: .75rem;
  height: .75rem;
  border-radius: 50%;
  background: hsl(var(--h, 220) 62% var(--mark-l));
}
.view-dates { margin-top: .25rem !important; color: var(--muted); font-variant-numeric: tabular-nums; }
.view-note { white-space: pre-wrap; overflow-wrap: anywhere; }
.view-note.empty { color: var(--muted); }

/* ---- Responsive ------------------------------------------------------- */
@media (min-width: 961px) {
  .panel { position: sticky; top: 1.5rem; padding-top: 3.25rem; }
}
@media (max-width: 960px) {
  .layout { grid-template-columns: minmax(0, 1fr); gap: 2rem; }
}
@media (max-width: 640px) {
  :root { --num-h: 1.625rem; --lane-h: 1.125rem; --lane-pad: 1rem; }
  .topbar { padding: .75rem .75rem 0; }
  .layout { padding: 1rem .75rem 2.5rem; }
  .cal-head { flex-wrap: wrap; }
  .weekdays div { padding: .375rem .25rem; text-align: center; font-size: .75rem; }
  .week { min-height: 4.5rem; }
  .num { top: .25rem; left: 50%; transform: translateX(-50%); min-width: 1.25rem; height: 1.25rem; font-size: .75rem; }
  .bar { margin: 1px 2px; padding: 0 .25rem; border-radius: 3px; font-size: .6875rem; }
  .bar-note { display: none; }
  dialog {
    width: 100%;
    max-width: 100%;
    margin: auto 0 0;
    border-radius: 14px 14px 0 0;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
}

@media (prefers-reduced-motion: reduce) {
  dialog[open] { animation: none; }
}
