:root {
  --bg: #f3ead8;
  --ink: #2f261c;
  --muted: #7a6a58;
  --line: #e4d4bc;
  --grid: #e2d4c0;
  --paper: #fffaf2;
  --gap: #efe4d0;
  --header: #fff8ee;
  --control: #fffaf2;
  --rosalie: #606c38;
  --rosalie-hover: #4f5a2d;
  --flintridge: #0f4c5c;
  --flintridge-hover: #0c3d4a;
  --ampersand: #9e2a2b;
  --ampersand-hover: #822223;
  --rosalie-blocked: var(--rosalie);
  --flintridge-blocked: var(--flintridge);
  --ampersand-blocked: var(--ampersand);
  --today-accent: #0f4c5c;
  --link: #0f4c5c;
  --ok: #606c38;
  --danger: #9b2c2c;
  --same: #9b2c2c;
  --same-soft: #f8e6dc;
  --same-border: #e8b8a8;
  --error-bg: #f8e6dc;
  --error-border: #e8b8a8;
  --pill-text: #fff;
  --past: #a89884;
  --outside-num: #b8a890;
  --modal-dim: rgba(47, 38, 28, 0.38);
  --qr-bg: #fff;
  --num-shadow: 0 0 2px rgba(255, 250, 242, 0.85);
  --num-shadow-stay: 0 0 2px rgba(47, 38, 28, 0.55);
  --shadow: 0 1px 2px rgba(47, 38, 28, 0.05), 0 8px 24px rgba(47, 38, 28, 0.06);
  --sans: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", sans-serif;
  --bar-h: 1.42rem;
  color-scheme: light;
}
* { box-sizing: border-box; }
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--sans);
  color: var(--ink);
  background:
    radial-gradient(1200px 420px at 8% -10%, rgba(227, 100, 20, 0.07), transparent 55%),
    radial-gradient(900px 380px at 92% 0%, rgba(96, 108, 56, 0.08), transparent 50%),
    var(--bg);
  min-height: 100vh;
  min-height: 100dvh;
}
.top {
  display: flex;
  gap: 1.5rem;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1.5rem;
  background: var(--header);
  color: var(--ink);
  border-bottom: 1px solid var(--line);
  position: relative;
  flex-wrap: wrap;
}
.top::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--rosalie) 0 33.33%, var(--flintridge) 33.33% 66.66%, var(--ampersand) 66.66% 100%);
}
.brand { display: flex; gap: 0.85rem; align-items: center; }
.mark {
  display: grid;
  place-items: center;
  width: 2.4rem;
  height: 2.4rem;
  border-radius: 0.45rem;
  background: var(--rosalie);
  color: #fff;
  font-weight: 700;
  letter-spacing: 0.04em;
  font-size: 0.75rem;
}
.top h1 { font-size: 1.05rem; margin: 0; font-weight: 650; }
.sub { margin: 0.15rem 0 0; color: var(--muted); font-size: 0.8rem; }
.top-actions { display: flex; gap: 0.75rem; align-items: center; }
.sync-line { margin: 0; color: var(--muted); font-size: 0.82rem; max-width: 28rem; }
main { padding: 1.25rem 1.5rem 3rem; max-width: 1320px; margin: 0 auto; }
.panel {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 0.75rem;
  padding: 1.1rem 1.2rem 1.25rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
}
.calendar-panel { padding-top: 1rem; }
.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}
.panel h2 { margin: 0; font-size: 1.05rem; }
.cal-title {
  margin: 0;
  font-size: 1.55rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.hint { color: var(--muted); font-size: 0.85rem; margin: 0.55rem 0 0.7rem; }
.month-nav, .filters { display: flex; gap: 0.35rem; align-items: center; flex-wrap: wrap; }
label { font-size: 0.85rem; color: var(--muted); display: flex; gap: 0.35rem; align-items: center; }
select, button { font: inherit; }
select {
  border: 1px solid var(--line);
  background: var(--control);
  border-radius: 0.4rem;
  padding: 0.3rem 0.45rem;
  color: var(--ink);
}
button {
  cursor: pointer;
  border-radius: 0.45rem;
  border: 1px solid transparent;
}
button.primary {
  background: var(--flintridge);
  color: #fff;
  padding: 0.48rem 0.95rem;
  font-weight: 600;
  border-radius: 999px;
}
button.primary:hover { background: var(--flintridge-hover); }
button.primary:disabled { opacity: 0.6; cursor: wait; }

.cal-toolbar { margin-bottom: 0.25rem; }
.cal-toolbar-row {
  display: flex;
  align-items: center;
  gap: 0.75rem 1rem;
  flex-wrap: wrap;
}
.today-btn {
  background: var(--control);
  color: var(--link);
  border: 1px solid var(--link);
  border-radius: 999px;
  padding: 0.28rem 0.9rem;
  font-weight: 600;
  font-size: 0.88rem;
}
.today-btn:hover { background: color-mix(in srgb, var(--flintridge) 10%, var(--control)); }
.nav-arrow {
  background: none;
  border: none;
  width: 2rem;
  height: 2rem;
  font-size: 1.45rem;
  line-height: 1;
  color: var(--ink);
  border-radius: 50%;
  display: grid;
  place-items: center;
  padding: 0;
}
.nav-arrow:hover { background: var(--gap); }
.period-label {
  min-width: 2.6rem;
  text-align: center;
  font-size: 1.05rem;
  font-weight: 650;
}
.year-label {
  margin-left: 0.35rem;
  font-size: 1.05rem;
  font-weight: 500;
  color: var(--ink);
}
.view-tabs {
  display: flex;
  gap: 1.25rem;
  margin-left: auto;
  align-items: flex-end;
}
.view-tab {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  padding: 0.35rem 0.1rem 0.45rem;
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--muted);
}
.view-tab.active {
  color: var(--ink);
  font-weight: 650;
  border-bottom-color: var(--ampersand);
}
.view-tab:hover { color: var(--ink); }

.legend {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 0.85rem;
}
.legend span { display: flex; gap: 0.35rem; align-items: center; }
.swatch {
  width: 1.15rem;
  height: 0.7rem;
  border-radius: 999px;
  display: inline-block;
}
.swatch.prop-rosalie { background: var(--rosalie); }
.swatch.prop-flintridge { background: var(--flintridge); }
.swatch.prop-ampersand { background: var(--ampersand); }
.swatch.blocked-demo { background-color: var(--rosalie); }
.swatch.empty { background: var(--gap); border: 1px solid var(--grid); border-radius: 0.15rem; height: 0.7rem; width: 0.7rem; }

.calendar-wrap { overflow-x: auto; }

/* Month grid */
.month-grid {
  border: 1px solid var(--grid);
  background: var(--paper);
  min-width: 720px;
}
.dow-row {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  border-bottom: 1px solid var(--grid);
  background: var(--paper);
}
.dow-row > span {
  text-align: center;
  font-size: 0.78rem;
  color: var(--muted);
  padding: 0.7rem 0 0.6rem;
  font-weight: 500;
}
.dow-short { display: none; }
.week {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  position: relative;
  min-height: 7.85rem;
}
.week + .week { border-top: 1px solid var(--grid); }
.day-cell {
  border-right: 1px solid var(--grid);
  padding: 0.4rem 0.5rem 0.5rem;
  min-height: 7.85rem;
  background: var(--paper);
  min-width: 0;
}
.day-cell:last-child { border-right: none; }
.day-cell.outside { background: var(--gap); }
.day-num {
  font-size: 0.82rem;
  font-weight: 500;
  line-height: 1.2;
  color: var(--ink);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.25rem;
}
.day-num.past {
  text-decoration: line-through;
  color: var(--past);
}
.day-cell.outside .day-num { color: var(--outside-num); }
.day-num.today {
  width: 1.45rem;
  height: 1.45rem;
  border-radius: 50%;
  background: var(--flintridge);
  color: #fff;
  text-decoration: none;
  font-weight: 650;
}

.week-bars {
  position: absolute;
  left: 0;
  right: 0;
  top: 1.85rem;
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  grid-auto-rows: var(--bar-h);
  row-gap: 0.22rem;
  pointer-events: none;
  z-index: 2;
}
.bar {
  --span: 1;
  pointer-events: auto;
  height: var(--bar-h);
  margin: 0;
  border-radius: 0;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 0.32em;
  padding: 0 0.5rem 0 0.65rem;
  font-size: 0.74rem;
  font-weight: 700;
  color: var(--pill-text);
  -webkit-text-fill-color: var(--pill-text);
  white-space: nowrap;
  overflow: hidden;
  border: none;
  cursor: pointer;
  min-width: 0;
  text-align: left;
  box-shadow: 0 1px 1px rgba(47, 38, 28, 0.12);
}
.bar-label {
  flex: 0 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.bar .note-icon {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
  object-fit: contain;
  display: block;
  filter: drop-shadow(0 0 1px rgba(47, 38, 28, 0.35));
}
/* Occupancy pills: reserved guest + Blocked labels stay bold white on every bar. */
.bar.reserved,
.bar.blocked,
.bar.other {
  color: var(--pill-text);
  -webkit-text-fill-color: var(--pill-text);
  font-weight: 700;
}
.bar.prop-rosalie { background-color: var(--rosalie); }
.bar.prop-rosalie:hover { background-color: var(--rosalie-hover); }
.bar.prop-flintridge { background-color: var(--flintridge); }
.bar.prop-flintridge:hover { background-color: var(--flintridge-hover); }
.bar.prop-ampersand { background-color: var(--ampersand); }
.bar.prop-ampersand:hover { background-color: var(--ampersand-hover); }
/* Blocked/other pills use the same solid property color as reserved (no hatch). */
/* Week wrap: flush square edges on Sat/Sun. */
.bar.continue-left {
  margin-left: 0;
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
  padding-left: 0.55rem;
}
.bar.continue-right {
  margin-right: 0;
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
}
/* True check-in: start ~4pm, right half of the cell, rounded left tip. */
.bar.tip-start {
  margin-left: calc(50% / var(--span) + 0.2rem);
  border-top-left-radius: 999px;
  border-bottom-left-radius: 999px;
}
/* True checkout: end ~10am, left half of the cell, rounded right tip. */
.bar.tip-end {
  margin-right: calc(50% / var(--span) + 0.2rem);
  border-top-right-radius: 999px;
  border-bottom-right-radius: 999px;
}

/* Year overview */
.year-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1.5rem 1.75rem;
}
.mini-month {
  background: none;
  border: none;
  padding: 0.35rem 0.2rem;
  text-align: left;
  cursor: pointer;
  border-radius: 0.5rem;
  color: inherit;
  width: 100%;
}
.mini-month:hover { background: var(--gap); }
.mini-month h3 {
  margin: 0 0 0.45rem 0.2rem;
  font-size: 0.95rem;
  font-weight: 650;
}
.mini-month.current h3 { color: var(--link); }
.mini-dows, .mini-days {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
}
.mini-dows span {
  text-align: center;
  font-size: 0.62rem;
  color: var(--muted);
  padding-bottom: 0.2rem;
}
.mini-day {
  aspect-ratio: 1;
  margin: 1px;
  border-radius: 0.2rem;
  font-size: 0.62rem;
  display: grid;
  grid-template-rows: repeat(3, 1fr);
  place-items: stretch;
  color: var(--ink);
  position: relative;
  overflow: hidden;
  background: var(--gap);
}
.mini-day.outside { color: transparent; background: transparent; }
.mini-lane {
  display: block;
  min-height: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.42rem;
  font-weight: 700;
  color: var(--pill-text);
  -webkit-text-fill-color: var(--pill-text);
  line-height: 1.15;
  padding: 0 1px;
}
.mini-lane.reserved,
.mini-lane.blocked {
  color: var(--pill-text);
  -webkit-text-fill-color: var(--pill-text);
  font-weight: 700;
}
.mini-lane.empty { background: transparent; color: transparent; -webkit-text-fill-color: transparent; }
.mini-lane.prop-rosalie.reserved,
.mini-lane.prop-rosalie.blocked { background: var(--rosalie); }
.mini-lane.prop-flintridge.reserved,
.mini-lane.prop-flintridge.blocked { background: var(--flintridge); }
.mini-lane.prop-ampersand.reserved,
.mini-lane.prop-ampersand.blocked { background: var(--ampersand); }
.mini-num {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-weight: 600;
  z-index: 1;
  pointer-events: none;
  text-shadow: var(--num-shadow);
}
.mini-day.has-stay .mini-num { color: var(--pill-text); text-shadow: var(--num-shadow-stay); }
.mini-day.today { box-shadow: inset 0 0 0 1.5px var(--today-accent); font-weight: 700; }

.prop-empty { color: var(--muted); padding: 1.5rem 0.25rem; }

.turns { display: flex; flex-direction: column; gap: 0.65rem; }
.turn {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 0.85rem;
  align-items: start;
  border: 1px solid var(--line);
  border-left-width: 4px;
  border-radius: 0.7rem;
  padding: 0.85rem 0.95rem;
  background: var(--control);
}
.turn.prop-rosalie { border-left-color: var(--rosalie); }
.turn.prop-flintridge { border-left-color: var(--flintridge); }
.turn.prop-ampersand { border-left-color: var(--ampersand); }
.turn.same {
  border-color: var(--same-border);
  background: linear-gradient(90deg, var(--same-soft), var(--control) 42%);
}
.turn .side {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.4rem;
}
.turn.done { opacity: 0.62; }
.turn.done .who { text-decoration: line-through; }
.check {
  width: 1.2rem;
  height: 1.2rem;
  margin-top: 0.2rem;
}
.turn.prop-rosalie .check { accent-color: var(--rosalie); }
.turn.prop-flintridge .check { accent-color: var(--flintridge); }
.turn.prop-ampersand .check { accent-color: var(--ampersand); }
.turn h3 { margin: 0 0 0.15rem; font-size: 0.98rem; }
.who { margin: 0; font-size: 0.92rem; }
.who .note-icon {
  width: 16px;
  height: 16px;
  display: inline-block;
  vertical-align: -0.18em;
  margin-left: 0.32em;
  object-fit: contain;
  cursor: pointer;
}
.meta { margin: 0.25rem 0 0; color: var(--muted); font-size: 0.82rem; }
.booking-note {
  margin: 0.4rem 0 0;
  display: flex;
  align-items: flex-start;
  gap: 0.4rem;
  font-size: 0.85rem;
  color: var(--ink);
  cursor: pointer;
  line-height: 1.35;
}
.booking-note .note-icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  object-fit: contain;
  margin-top: 0.08rem;
}
.booking-note .note-text {
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.booking-note.expanded .note-text {
  white-space: pre-wrap;
  overflow: visible;
  text-overflow: unset;
}
.note-open {
  background: var(--control);
  color: var(--link);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.22rem 0.65rem;
  font-size: 0.75rem;
  font-weight: 650;
  white-space: nowrap;
}
.note-open:hover { background: var(--gap); }
.note-open.has-note { border-color: color-mix(in srgb, var(--ampersand) 45%, var(--line)); }
.badge {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  background: var(--same-soft);
  color: var(--same);
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
}
.badge.quiet {
  background: var(--gap);
  color: var(--muted);
}
.empty-msg { color: var(--muted); padding: 0.5rem 0; }
.errors {
  background: var(--error-bg);
  border-color: var(--error-border);
  color: var(--danger);
  font-size: 0.88rem;
}

.modal {
  position: fixed;
  inset: 0;
  background: var(--modal-dim);
  display: grid;
  place-items: center;
  z-index: 20;
  padding: 1rem;
}
.modal[hidden] { display: none; }
.modal-card {
  background: var(--paper);
  border-radius: 0.8rem;
  padding: 1.2rem 1.3rem 1.3rem;
  width: min(30rem, 100%);
  position: relative;
  box-shadow: var(--shadow);
  border-top: 3px solid var(--ampersand);
}
.modal-card h2 { margin: 0 1.5rem 0.6rem 0; font-size: 1.1rem; }
.note-editor {
  margin-top: 1rem;
  padding-top: 0.85rem;
  border-top: 1px solid var(--line);
}
.note-editor label {
  display: block;
  font-weight: 650;
  color: var(--ink);
  margin-bottom: 0.35rem;
}
.note-editor textarea {
  width: 100%;
  min-height: 5rem;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  padding: 0.55rem 0.65rem;
  font: inherit;
  background: var(--control);
  color: var(--ink);
  resize: vertical;
  line-height: 1.4;
}
.note-editor textarea:focus {
  outline: 2px solid color-mix(in srgb, var(--flintridge) 40%, transparent);
  outline-offset: 1px;
}
.note-actions {
  display: flex;
  gap: 0.45rem;
  align-items: center;
  margin-top: 0.55rem;
  flex-wrap: wrap;
}
.note-actions .primary { padding: 0.38rem 0.9rem; }
button.ghost {
  background: var(--control);
  color: var(--ink);
  border: 1px solid var(--line);
  padding: 0.38rem 0.85rem;
  font-weight: 600;
  border-radius: 999px;
}
button.ghost:hover { background: var(--gap); }
.note-status {
  font-size: 0.8rem;
  color: var(--ok);
  min-height: 1em;
}
.note-status.err { color: var(--danger); }
.close {
  position: absolute;
  top: 0.55rem;
  right: 0.55rem;
  background: none;
  border: none;
  font-size: 1.4rem;
  color: var(--muted);
  line-height: 1;
}
dl { margin: 0; display: grid; grid-template-columns: 7.5rem 1fr; gap: 0.35rem 0.75rem; font-size: 0.92rem; }
dt { color: var(--muted); }
dd { margin: 0; font-weight: 600; }

@media (max-width: 900px) {
  .year-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .view-tabs { margin-left: 0; }
}

.sign-out {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.2rem 0.35rem;
  text-decoration: underline;
  text-underline-offset: 0.16em;
  white-space: nowrap;
}
.sign-out:hover { color: var(--ink); }

.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}
.login-card {
  width: min(26.5rem, 100%);
  margin: 0;
}
.login-card .brand { margin-bottom: 1.1rem; }
.login-card h1 { font-size: 1.05rem; margin: 0; }
.login-card form,
#step-backup {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.login-card .field {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.35rem;
  color: var(--muted);
  font-size: 0.85rem;
}
.login-card input[type="password"],
.login-card input[type="text"] {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--control);
  border-radius: 0.45rem;
  padding: 0.5rem 0.65rem;
  color: var(--ink);
  font: inherit;
}
.login-card input[type="password"]:focus,
.login-card input[type="text"]:focus {
  outline: 2px solid color-mix(in srgb, var(--flintridge) 40%, transparent);
  outline-offset: 1px;
}
.remember-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  font-size: 0.88rem;
  color: var(--ink);
}
.qr-wrap {
  text-align: center;
  background: var(--qr-bg);
  padding: 0.75rem;
  border-radius: 0.5rem;
  border: 1px solid var(--line);
}
.qr-wrap img {
  width: 12rem;
  height: 12rem;
  image-rendering: pixelated;
}
.manual-secret {
  font-size: 0.85rem;
  color: var(--muted);
  margin: 0;
}
.manual-secret code {
  display: block;
  margin-top: 0.35rem;
  font-size: 0.95rem;
  letter-spacing: 0.06em;
  word-break: break-all;
  color: var(--ink);
  background: var(--gap);
  padding: 0.4rem 0.5rem;
  border-radius: 0.4rem;
}
.backup-codes {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.4rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.92rem;
  letter-spacing: 0.04em;
}
.backup-codes li {
  background: var(--gap);
  padding: 0.4rem 0.55rem;
  border-radius: 0.35rem;
  text-align: center;
}
.msg.err {
  color: var(--danger);
  font-size: 0.88rem;
  margin: 0.35rem 0 0;
}

[data-theme="dark"] {
  --bg: #161310;
  --ink: #f0e6d4;
  --muted: #b3a18c;
  --line: #3d342a;
  --grid: #4a4034;
  --paper: #221c16;
  --gap: #2c261e;
  --header: #1c1814;
  --control: #2a241c;
  --today-accent: #d4c4a8;
  --link: #8fc5d0;
  --ok: #9aaa62;
  --danger: #e07a6a;
  --same: #e07a6a;
  --same-soft: #3a2420;
  --same-border: #6b3a32;
  --error-bg: #3a2420;
  --error-border: #6b3a32;
  --pill-text: #fff;
  --past: #8a7a68;
  --outside-num: #6e6254;
  --modal-dim: rgba(8, 6, 4, 0.62);
  --qr-bg: #fff;
  --num-shadow: 0 0 2px rgba(22, 19, 16, 0.9);
  --num-shadow-stay: 0 0 2px rgba(0, 0, 0, 0.7);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.28), 0 10px 28px rgba(0, 0, 0, 0.32);
  color-scheme: dark;
}
[data-theme="dark"] body {
  background:
    radial-gradient(1200px 420px at 8% -10%, rgba(158, 42, 43, 0.14), transparent 55%),
    radial-gradient(900px 380px at 92% 0%, rgba(96, 108, 56, 0.12), transparent 50%),
    var(--bg);
}
[data-theme="dark"] .day-num.today {
  background: var(--flintridge);
  color: #fff;
}
[data-theme="dark"] select {
  color-scheme: dark;
}

.theme-toggle {
  background: none;
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 650;
  padding: 0.22rem 0.6rem;
  border-radius: 999px;
  white-space: nowrap;
}
.theme-toggle:hover {
  color: var(--ink);
  background: var(--gap);
}
.login-theme {
  position: fixed;
  top: 0.85rem;
  right: 1rem;
  z-index: 5;
}

/* Phone: 7-day month grid fills the viewport; desktop month view is unchanged. */
@media (max-width: 700px) {
  :root { --bar-h: 1.16rem; }

  .top {
    flex-direction: column;
    align-items: stretch;
    gap: 0.65rem;
    padding: calc(0.7rem + env(safe-area-inset-top, 0px)) calc(0.85rem + env(safe-area-inset-right, 0px)) 0.7rem calc(0.85rem + env(safe-area-inset-left, 0px));
  }
  .top-actions {
    width: 100%;
    flex-wrap: wrap;
    justify-content: flex-start;
    gap: 0.5rem;
  }
  .sync-line { max-width: none; }

  main {
    padding: 0.85rem calc(0.75rem + env(safe-area-inset-right, 0px)) calc(2rem + env(safe-area-inset-bottom, 0px)) calc(0.75rem + env(safe-area-inset-left, 0px));
  }
  .panel { padding: 0.85rem 0.75rem 1rem; }
  .cal-title { font-size: 1.3rem; }

  .year-grid { grid-template-columns: 1fr; }
  .turn { grid-template-columns: auto 1fr; }
  .turn .side { grid-column: 2; }

  .calendar-wrap {
    overflow-x: auto; /* fallback if a week still overflows */
    overflow-y: visible;
    max-height: none;
  }
  .month-grid {
    min-width: 0;
    width: 100%;
  }
  .dow-row {
    position: sticky;
    top: 0;
    z-index: 5;
    background: var(--paper);
  }
  .dow-full { display: none; }
  .dow-short { display: inline; }
  .dow-row > span { padding: 0.45rem 0 0.35rem; font-size: 0.72rem; }

  .week, .day-cell { min-height: 5.85rem; }
  .day-cell { padding: 0.22rem 0.12rem 0.28rem; }
  .week-bars {
    top: 1.4rem;
    row-gap: 0.12rem;
  }
  .bar {
    padding: 0 0.22rem 0 0.28rem;
    font-size: 0.62rem;
    gap: 0.18em;
  }
  .bar.continue-left { padding-left: 0.22rem; }
  .bar-prop,
  .bar-sep { display: none; }
  .bar .note-icon { width: 12px; height: 12px; }

  .today-btn,
  .nav-arrow,
  .view-tab,
  .theme-toggle,
  .sign-out,
  button.primary,
  button.ghost {
    min-height: 44px;
    min-width: 44px;
  }
  .nav-arrow {
    width: 44px;
    height: 44px;
    font-size: 1.55rem;
  }
  .today-btn { padding: 0.4rem 0.95rem; }
  .view-tab { padding: 0.55rem 0.2rem; }
  .theme-toggle { padding: 0.4rem 0.75rem; }
  .sign-out { padding: 0.4rem 0.55rem; }
  button.primary { padding: 0.5rem 1rem; }

  select,
  input,
  textarea {
    font-size: 16px;
  }
  select {
    min-height: 44px;
    padding: 0.4rem 0.5rem;
  }

  .modal {
    padding: max(0.5rem, env(safe-area-inset-top, 0px)) max(0.5rem, env(safe-area-inset-right, 0px)) max(0.5rem, env(safe-area-inset-bottom, 0px)) max(0.5rem, env(safe-area-inset-left, 0px));
    align-items: end;
  }
  .modal-card {
    width: 100%;
    max-height: calc(100dvh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - 1rem);
    overflow: auto;
    padding: 1.1rem 1rem calc(1.2rem + env(safe-area-inset-bottom, 0px));
  }
  .close {
    min-width: 44px;
    min-height: 44px;
    top: 0.25rem;
    right: 0.25rem;
  }
  .note-editor textarea { font-size: 16px; min-height: 5.5rem; }
  dl { grid-template-columns: 6.2rem 1fr; font-size: 0.9rem; }

  .mini-day { min-height: 2.4rem; }

  .login-body {
    min-height: 100dvh;
    padding: max(3.6rem, env(safe-area-inset-top, 0px) + 3rem) max(0.85rem, env(safe-area-inset-right, 0px)) max(1rem, env(safe-area-inset-bottom, 0px)) max(0.85rem, env(safe-area-inset-left, 0px));
    align-items: start;
    place-items: start center;
  }
  .login-card { width: 100%; }
  .login-card input[type="password"],
  .login-card input[type="text"] {
    font-size: 16px;
    min-height: 44px;
    padding: 0.65rem 0.7rem;
  }
  .remember-row {
    min-height: 44px;
    align-items: center;
  }
  .remember-row input[type="checkbox"] {
    width: 1.2rem;
    height: 1.2rem;
    flex-shrink: 0;
  }
  .login-theme {
    top: max(0.5rem, env(safe-area-inset-top, 0px));
    right: max(0.65rem, env(safe-area-inset-right, 0px));
    min-height: 44px;
  }
  .qr-wrap img {
    width: min(12rem, 68vw);
    height: auto;
    aspect-ratio: 1;
  }
}

@media (max-width: 400px) {
  :root { --bar-h: 1.08rem; }
  .week, .day-cell { min-height: 5.45rem; }
  .calendar-panel > .hint { display: none; }
  .top h1 { font-size: 0.98rem; }
  .sub { font-size: 0.72rem; }
  .day-cell { padding: 0.18rem 0.08rem 0.22rem; }
  .bar { font-size: 0.58rem; padding: 0 0.16rem 0 0.2rem; }
  dl { grid-template-columns: 1fr; }
}
