/* ============================ CALENDAR ============================ */
#cal {
  --bg: #ffffff;
  --grouped: #f2f2f7;
  --card: #ffffff;
  --text: #000000;
  --muted: #8e8e93;
  --sep: rgba(60, 60, 67, .22);
  --tint: #ff3b30;
  --glass: rgba(255, 255, 255, .72);
  --glass-edge: rgba(0, 0, 0, .06);
  --field: rgba(118, 118, 128, .12);
  --sel-bg: #000000;
  --sel-fg: #ffffff;
  --press: rgba(0, 0, 0, .06);
  background: var(--bg);
  color: var(--text);
  font-size: 17px;
  letter-spacing: -.01em;
}
@media (prefers-color-scheme: dark) {
  #cal {
    --bg: #000000;
    --grouped: #000000;
    --card: #1c1c1e;
    --text: #ffffff;
    --muted: #8d8d93;
    --sep: rgba(84, 84, 88, .55);
    --tint: #ff453a;
    --glass: rgba(44, 44, 46, .7);
    --glass-edge: rgba(255, 255, 255, .08);
    --field: rgba(118, 118, 128, .24);
    --sel-bg: #ffffff;
    --sel-fg: #000000;
    --press: rgba(255, 255, 255, .08);
  }
}
.c-view { position: absolute; inset: 0; display: flex; flex-direction: column; background: var(--bg); }
.c-scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }

/* --- Liquid-glass buttons --- */
.g-pill, .g-circle {
  height: 44px; border-radius: 22px;
  background: var(--glass);
  -webkit-backdrop-filter: blur(18px) saturate(180%); backdrop-filter: blur(18px) saturate(180%);
  box-shadow: inset 0 0 0 .5px var(--glass-edge), 0 4px 16px rgba(0, 0, 0, .08);
  display: inline-flex; align-items: center;
}
.g-circle { width: 44px; justify-content: center; }
.g-pill { padding: 0 15px; gap: 2px; }
.c-text { color: var(--tint); font-size: 17px; font-weight: 400; }
.g-pill.c-text { padding: 0 18px; }
.g-pill:active, .g-circle:active, .c-icon:active { opacity: .55; }
svg { width: 24px; height: 24px; fill: none; stroke: var(--tint); stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.chev { width: 11px; height: 19px; stroke-width: 2.6; margin-right: 5px; }
.c-back { color: var(--tint); padding-left: 12px; }
.c-icons { padding: 0 6px; }
.c-icon { width: 40px; height: 44px; display: grid; place-items: center; }

.c-bar {
  display: flex; align-items: center; gap: 10px;
  padding: calc(var(--safe-top) + 6px) 16px 6px;
  flex: none; position: relative; z-index: 2;
}
.c-bar-fill { flex: 1; }

/* --- Bottom toolbar --- */
.c-tools {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 5;
  display: flex; align-items: center; gap: 10px;
  padding: 8px 16px calc(var(--safe-bottom) + 8px);
  pointer-events: none;
}
.c-tools > * { pointer-events: auto; }
.c-tools-pair { padding: 0 6px; gap: 0; }
.c-tools-pair .c-text { padding: 0 12px; height: 44px; }

/* --- Month view --- */
.m-title { flex: none; font-size: 34px; font-weight: 700; letter-spacing: -.02em; padding: 2px 16px 8px; line-height: 1.15; }
.c-weekdays {
  display: grid; grid-template-columns: repeat(7, 1fr); flex: none;
  font-size: 12px; font-weight: 500; color: var(--text); text-align: center;
  padding: 2px 0 6px; border-bottom: .5px solid var(--sep);
}
.c-weekdays span:first-child, .c-weekdays span:last-child { color: var(--muted); }
#m-scroll { padding-bottom: calc(var(--safe-bottom) + 70px); }
.m-month { padding-top: 6px; }
.m-label {
  display: grid; grid-template-columns: repeat(7, 1fr);
  font-size: 22px; font-weight: 700; letter-spacing: -.02em; height: 36px; align-items: end;
}
.m-label span { white-space: nowrap; text-align: center; }
.m-label.now span { color: var(--tint); }
.m-week { display: grid; grid-template-columns: repeat(7, 1fr); height: 68px; }
.m-day { border-top: .5px solid var(--sep); text-align: center; padding-top: 5px; position: relative; }
.m-day.blank { border-top-color: transparent; }
.m-num {
  display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 50%;
  font-size: 20px; font-weight: 400; font-variant-numeric: tabular-nums;
}
.m-day.wkend .m-num { color: var(--muted); }
.m-day.today .m-num { background: var(--tint); color: #fff; font-weight: 600; }
.m-day:active .m-num { background: var(--press); }
.m-day.today:active .m-num { background: var(--tint); }
.m-dots { display: flex; justify-content: center; gap: 3px; margin-top: 3px; }
.m-dot { display: block; width: 6px; height: 6px; border-radius: 50%; background: var(--c, var(--muted)); }

/* --- Year view --- */
#y-scroll { padding: 0 16px calc(var(--safe-bottom) + 70px); }
.y-year { padding-bottom: 16px; }
.y-title { font-size: 34px; font-weight: 700; letter-spacing: -.02em; padding: 6px 0 6px; border-bottom: .5px solid var(--sep); margin-bottom: 12px; }
.y-year.now .y-title { color: var(--tint); }
.y-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px 16px; }
.y-month { min-width: 0; }
.y-mname { font-size: 18px; font-weight: 700; margin-bottom: 4px; letter-spacing: -.01em; }
.y-month.now .y-mname { color: var(--tint); }
.y-mini { display: grid; grid-template-columns: repeat(7, 1fr); font-size: 9px; font-weight: 500; line-height: 15px; text-align: center; }
.y-mini span.today { background: var(--tint); color: #fff; border-radius: 50%; font-weight: 700; }

/* --- Day view --- */
.d-week { display: grid; grid-template-columns: repeat(7, 1fr); flex: none; padding: 0 8px; text-align: center; touch-action: pan-y; }
.d-wd { font-size: 11px; font-weight: 500; color: var(--text); margin-bottom: 4px; }
.d-wd.wkend { color: var(--muted); }
.d-n { display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 50%; font-size: 20px; font-variant-numeric: tabular-nums; }
.d-cell.wkend .d-n { color: var(--muted); }
.d-cell.today .d-n { color: var(--tint); font-weight: 600; }
.d-cell.sel .d-n { background: var(--sel-bg); color: var(--sel-fg); font-weight: 600; }
.d-cell.sel.today .d-n { background: var(--tint); color: #fff; }
.d-title { flex: none; text-align: center; font-size: 15px; font-weight: 600; padding: 8px 0 8px; border-bottom: .5px solid var(--sep); }
.d-allday { flex: none; display: grid; grid-template-columns: 56px 1fr; border-bottom: .5px solid var(--sep); }
.d-allday:empty { display: none; }
.d-allday-label { font-size: 11px; color: var(--muted); padding: 7px 8px 0 0; text-align: right; }
.d-allday-list { padding: 4px 8px 4px 4px; display: grid; gap: 2px; }
.d-scroll { touch-action: pan-y; padding-bottom: calc(var(--safe-bottom) + 70px); }
.d-grid { position: relative; height: calc(24 * 52px + 20px); margin-top: 10px; }
.d-hour { position: absolute; left: 0; right: 0; height: 0; }
.d-hour span { position: absolute; left: 0; width: 48px; text-align: right; top: -7px; font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.d-hour::after { content: ""; position: absolute; left: 56px; right: 0; top: 0; border-top: .5px solid var(--sep); }
.d-now { position: absolute; left: 50px; right: 0; height: 0; border-top: 1.5px solid var(--tint); z-index: 2; }
.d-now::before { content: ""; position: absolute; left: -4px; top: -5px; width: 8px; height: 8px; border-radius: 50%; background: var(--tint); }
.ev {
  --c: #1badf8;
  background: color-mix(in srgb, var(--c) 22%, var(--bg));
  border-left: 3px solid var(--c);
  border-radius: 5px; padding: 3px 7px; overflow: hidden;
  font-size: 13px; font-weight: 600; line-height: 1.25;
  color: color-mix(in srgb, var(--c) 55%, var(--text));
}
.ev small { display: block; font-weight: 400; opacity: .85; }
.d-grid .ev { position: absolute; left: 58px; right: 6px; }
.d-allday .ev { border-radius: 4px; padding: 3px 7px; }

/* --- Search --- */
.s-bar { flex: none; display: flex; align-items: center; gap: 12px; padding: calc(var(--safe-top) + 8px) 16px 10px; border-bottom: .5px solid var(--sep); }
.s-field { flex: 1; min-width: 0; display: flex; align-items: center; gap: 6px; height: 38px; border-radius: 12px; background: var(--field); padding: 0 8px; }
.s-field > svg { width: 18px; height: 18px; stroke: var(--muted); flex: none; }
.s-field input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--text); font-size: 17px; padding: 0; -webkit-appearance: none; appearance: none; }
.s-field input::-webkit-search-cancel-button { display: none; }
.s-field input::placeholder { color: var(--muted); }
.s-clear svg { width: 18px; height: 18px; fill: var(--muted); stroke: var(--bg); stroke-width: 2; }
.s-cancel { color: var(--tint); font-size: 17px; flex: none; white-space: nowrap; }
.s-scroll { padding-bottom: 40px; }
.s-head { font-size: 15px; font-weight: 600; padding: 14px 16px 6px; background: var(--bg); position: sticky; top: 0; border-bottom: .5px solid var(--sep); }
.s-row { display: grid; grid-template-columns: 4px 1fr auto; gap: 10px; align-items: center; padding: 10px 16px; min-height: 52px; position: relative; }
.s-row::after { content: ""; position: absolute; left: 30px; right: 0; bottom: 0; border-bottom: .5px solid var(--sep); }
.s-row:last-child::after { display: none; }
.s-row:active { background: var(--press); }
.s-bar-c { width: 4px; align-self: stretch; border-radius: 2px; background: var(--c); }
.s-title { font-size: 17px; line-height: 1.25; }
.s-sub { font-size: 15px; color: var(--muted); }
.s-time { font-size: 15px; color: var(--muted); text-align: right; }
.s-none { text-align: center; color: var(--muted); font-size: 17px; padding-top: 30vh; }

/* --- Event detail --- */
.e-view { background: var(--grouped); }
.e-scroll { padding: 4px 16px calc(var(--safe-bottom) + 40px); }
.e-head { padding: 10px 4px 20px; }
.e-title { font-size: 24px; font-weight: 700; letter-spacing: -.02em; line-height: 1.2; margin-bottom: 8px; word-break: break-word; }
.e-line { font-size: 17px; color: var(--muted); line-height: 1.4; }
.e-line.strong { color: var(--text); }
.e-card { background: var(--card); border-radius: 12px; margin-bottom: 20px; overflow: hidden; }
.e-row { display: flex; align-items: center; min-height: 46px; padding: 0 16px; position: relative; }
.e-row + .e-row::before { content: ""; position: absolute; left: 16px; right: 0; top: 0; border-top: .5px solid var(--sep); }
.e-row .k { flex: 1; }
.e-row .v { color: var(--muted); display: flex; align-items: center; gap: 7px; }
.e-row .v i { width: 10px; height: 10px; border-radius: 50%; background: var(--c); display: inline-block; }
.e-row .v svg { width: 13px; height: 13px; stroke: var(--muted); stroke-width: 2.4; }
.e-notes { padding: 12px 16px 14px; }
.e-notes .k { font-size: 17px; margin-bottom: 4px; }
.e-notes .t { color: var(--muted); white-space: pre-wrap; }
.e-delete { color: var(--tint); text-align: center; justify-content: center; }

/* --- Sheets --- */
.sheet-wrap { position: absolute; inset: 0; z-index: 20; }
.sheet-dim { position: absolute; inset: 0; background: rgba(0, 0, 0, .25); animation: fade .25s; }
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0; top: calc(var(--safe-top) + 12px);
  background: var(--grouped); border-radius: 14px 14px 0 0; overflow-y: auto;
  animation: up .32s cubic-bezier(.2, .8, .2, 1);
  padding-bottom: calc(var(--safe-bottom) + 20px);
}
@media (prefers-color-scheme: dark) { .sheet { background: #1c1c1e; } .sheet .e-card { background: #2c2c2e; } }
@keyframes up { from { transform: translateY(100%); } }
@keyframes fade { from { opacity: 0; } }
.sh-bar { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; padding: 14px 16px; }
.sh-bar .l { justify-self: start; color: var(--tint); }
.sh-bar .g-circle svg { width: 20px; height: 20px; stroke: var(--text); stroke-width: 2.2; }
.sh-bar .g-circle.ok { background: var(--tint); box-shadow: none; }
.sh-bar .g-circle.ok svg { stroke: #fff; }
.sh-bar .g-circle.ok[disabled] { background: var(--glass); }
.sh-bar .g-circle.ok[disabled] svg { stroke: var(--muted); }
.sh-bar .r { justify-self: end; color: var(--tint); font-weight: 600; }
.sh-bar .r[disabled] { color: var(--muted); }
.sh-bar .t { font-weight: 600; }
.sh-body { padding: 8px 16px; }
.sh-section { font-size: 13px; color: var(--muted); text-transform: uppercase; padding: 14px 16px 6px; }
.sh-field { width: 100%; border: 0; outline: 0; background: transparent; color: var(--text); font-size: 17px; padding: 0; height: 46px; }
.sh-check { color: var(--tint); font-weight: 600; }
.sh-empty { text-align: center; color: var(--muted); padding-top: 28vh; font-size: 17px; }
.toggle { width: 51px; height: 31px; border-radius: 16px; background: rgba(120, 120, 128, .32); position: relative; }
.toggle::after { content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%; background: #fff; box-shadow: 0 2px 6px rgba(0, 0, 0, .2); }
