:root {
  --bg: #EEE9E0;
  --surface: #FBF8F2;
  --ink: #241B2F;
  --muted: #6D6478;
  --line: #DAD1C2;
  --violet: #5B2E8C;
  --violet-soft: #E8DFF2;
  --gold: #9E7419;
  --gold-soft: #F4E8C8;
  --allday: #2E7D4F;
  --range: #7DBF93;
  --no: #B23A3A;
  --open: #CFC6B8;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light dark;
  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15111B;
    --surface: #1F1928;
    --ink: #ECE5D8;
    --muted: #A69DB0;
    --line: #362C43;
    --violet: #B892E8;
    --violet-soft: #2D2240;
    --gold: #DDB25A;
    --gold-soft: #3A2F18;
    --allday: #5CC184;
    --range: #3E7A54;
    --no: #E07575;
    --open: #4A4056;
  }
}
*, *::before, *::after { box-sizing: border-box; }
html { scroll-padding-top: env(safe-area-inset-top, 0px); }
body { margin: 0; background: var(--bg); color: var(--ink); font: 400 16px/1.5 var(--sans); }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .45; }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }

.wrap { max-width: 1040px; margin: 0 auto; padding: 28px 16px 64px; }
h1 { font: 700 clamp(2rem, 5.5vw, 3.2rem)/1.05 var(--serif); margin: 0; color: var(--violet); }
h2 { font: 700 1.25rem/1.2 var(--serif); margin: 0 0 12px; }
h3 { font: 700 1rem/1.3 var(--sans); margin: 18px 0 8px; color: var(--muted); }
.sub { color: var(--muted); margin: 6px 0 22px; }

.notice { border-left: 4px solid var(--gold); background: var(--gold-soft); padding: 10px 14px; border-radius: 0 8px 8px 0; margin-bottom: 18px; }
.notice form { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }

.who { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 22px; }
.who > label { color: var(--muted); white-space: nowrap; }
.whosel {
  appearance: none; -webkit-appearance: none;
  font: 700 1rem/1.2 var(--sans); color: var(--surface);
  background: var(--violet) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='white' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E") no-repeat right 14px center;
  border: 1.5px solid var(--violet); border-radius: 999px;
  padding: 9px 38px 9px 16px; min-width: 170px; cursor: pointer;
}
.whosel.need { color: var(--ink); background-color: var(--gold-soft); border-color: var(--gold); background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%239E7419' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E"); }
.whosel option { color: #241B2F; background: #FBF8F2; }

.sessions { display: flex; flex-direction: column; gap: 10px; margin-bottom: 24px; }
.session { background: var(--violet); color: var(--surface); border-radius: 14px; padding: 14px 18px; display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; }
.session b { font: 700 1.4rem/1.15 var(--serif); display: block; }
.session small { opacity: .85; }
.session button { background: transparent; border: 1.5px solid currentColor; color: inherit; border-radius: 8px; padding: 5px 10px; }

.grid { display: grid; grid-template-columns: minmax(0, 360px) minmax(0, 1fr); gap: 22px; align-items: start; }
.col { display: flex; flex-direction: column; gap: 22px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 16px; }

.calhead { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.calhead strong { font: 700 1.2rem var(--serif); }
.nav { width: 36px; height: 36px; border: 1px solid var(--line); background: transparent; border-radius: 8px; font-size: 1.15rem; }
.days { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.dow { text-align: center; font-size: .78rem; color: var(--muted); padding: 2px 0 4px; }
.day { aspect-ratio: 1 / 1.08; border: 1.5px solid transparent; background: transparent; border-radius: 9px; display: flex; flex-direction: column; align-items: center; justify-content: space-between; padding: 5px 2px 6px; position: relative; }
@media (hover: hover) { .day:hover:not(:disabled) { background: var(--violet-soft); } }
.day .n { font-weight: 600; font-size: .95rem; }
.day.today .n { color: var(--violet); text-decoration: underline 2px; text-underline-offset: 3px; }
.day.past { opacity: .35; }
.day:disabled { cursor: default; }
.day.sel { border-color: var(--violet); background: var(--violet-soft); }
.day.all { background: var(--gold-soft); }
.day.mine-missing .n::after { content: "•"; color: var(--violet); position: absolute; top: 2px; right: 6px; }
.day .badge { position: absolute; top: 2px; right: 3px; font-size: .62rem; line-height: 1; }
.dots { display: grid; gap: 2px; justify-content: center; }
.dots.c1 { grid-template-columns: repeat(1, auto); }
.dots.c2 { grid-template-columns: repeat(2, auto); }
.dots.c3 { grid-template-columns: repeat(3, auto); }
.dots.c4 { grid-template-columns: repeat(4, auto); }
.dots.c5 { grid-template-columns: repeat(5, auto); }
.dots.c6 { grid-template-columns: repeat(6, auto); }
.dot { display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--open); }
.dot.allday { background: var(--allday); }
.dot.range { background: var(--range); }
.dot.no { background: var(--no); }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 12px; font-size: .82rem; color: var(--muted); }
.legend .dot { margin-right: 5px; vertical-align: 1px; }

.best { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 6px; }
.best button { width: 100%; text-align: left; border: 1px solid var(--line); background: transparent; border-radius: 10px; padding: 8px 12px; display: flex; justify-content: space-between; gap: 8px; }
@media (hover: hover) { .best button:hover { background: var(--violet-soft); } }
.best .meta { color: var(--muted); font-size: .88rem; white-space: nowrap; }
.empty { color: var(--muted); font-size: .92rem; }

.panel h2 { font-size: 1.5rem; }
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg button { border: 1.5px solid var(--line); background: transparent; border-radius: 9px; padding: 7px 12px; }
.seg button[aria-pressed="true"] { border-color: var(--violet); background: var(--violet-soft); font-weight: 700; }
.ranges { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.rrow { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
input[type="time"], input[type="text"], input[type="password"] { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; min-width: 0; }
input[type="text"], input[type="password"] { flex: 1; }
.btn { background: var(--violet); color: var(--surface); border: 0; border-radius: 9px; padding: 8px 14px; font-weight: 700; }
.ghost { background: transparent; border: 1px solid var(--line); border-radius: 9px; padding: 6px 11px; color: var(--muted); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.hint { color: var(--muted); font-size: .88rem; margin: 6px 0 0; }

.roster { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.roster li { display: flex; justify-content: space-between; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.roster li:last-child { border-bottom: 0; }
.roster .st { color: var(--muted); }
.roster .st.allday { color: var(--allday); font-weight: 600; }
.roster .st.range { color: var(--ink); }
.roster .st.no { color: var(--no); }

.overlap { margin-top: 16px; border-radius: 12px; padding: 12px 14px; background: var(--bg); }
.overlap.all { background: var(--gold-soft); }
.overlap strong { font: 700 1.15rem var(--serif); }

footer { margin-top: 36px; color: var(--muted); font-size: .9rem; display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }

.phead { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.phead h2 { flex: 1; margin: 0; text-align: center; }
.phead .close { display: none; }
.weekbulk { margin-top: 6px; }
.weekbulk .actions { margin-top: 8px; }
.weekbulk .scope { margin-bottom: 8px; }
.weekbulk .scope button { flex: 1; }
.bulkrange .btn { white-space: nowrap; }
.weekbulk .actions > button { flex: 1 1 0; white-space: nowrap; }
.caltoggle { display: block; width: 100%; margin-top: 10px; }
.caltoggle[hidden] { display: none; }
.best .near { border-style: dashed; }
.best .near .meta { white-space: normal; text-align: right; }

@media (max-width: 780px) {
  .wrap { padding: 16px 14px 48px; }
  .sub { margin-bottom: 14px; }
  .grid { grid-template-columns: 1fr; }
  .who { position: sticky; top: 0; z-index: 10; flex-wrap: nowrap; margin: 0 -14px 16px; padding: calc(8px + env(safe-area-inset-top, 0px)) 14px 8px; background: var(--bg); }
  .whosel { flex: 1; }
  .bulkrange .btn { flex: 1 1 100%; padding: 11px; }
  .card { padding: 12px; }
  .days { gap: 2px; }
  .day { aspect-ratio: auto; min-height: 52px; padding: 6px 1px 7px; }
  .dot { width: 5px; height: 5px; }
  .session { padding: 12px 14px; }
  .session .actions { width: 100%; }
  .session .actions button { flex: 1; padding: 9px; }
  .grid { display: flex; flex-direction: column; align-items: stretch; gap: 16px; }
  .col { display: contents; }
  .cal { order: 1; scroll-margin-top: 64px; }
  .panel { order: 2; }
  .col > .card:not(.cal) { order: 3; }
  .panel:not(.open) { display: none; }
  .panel.open { border-color: var(--violet); }
  .phead .close { display: inline-block; }
  .panel h2 { font-size: 1.2rem; }
  .seg button { flex: 1 1 calc(50% - 6px); padding: 12px 8px; }
  .actions > button { flex: 1 1 auto; padding: 11px 12px; }
  .rrow input[type="time"] { flex: 1; padding: 10px; }
  footer { flex-direction: column; align-items: stretch; }
  footer .ghost { padding: 10px; }
  .toast { bottom: calc(24px + env(safe-area-inset-bottom, 0px)); z-index: 40; }
}

.toast { position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 8px 14px; border-radius: 9px; font-size: .92rem; opacity: 0; transition: opacity .2s; pointer-events: none; }
.toast.on { opacity: 1; }
@media (prefers-reduced-motion: reduce) { .toast { transition: none; } }