:root {
  --bg: #F7F6F2; --panel: #EFEDE7; --surf: #FFFFFF; --ink: #1C1B22; --muted: #64636B;
  --line: #E7E5DF; --accent: #6D4AD6; --accent-soft: #EDE8FB; --accent-ink: #4C2FB0; --danger: #B42318; --now: #D92D20;
  --sat: env(safe-area-inset-top); --sab: env(safe-area-inset-bottom);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); }
body { font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", Inter, system-ui, sans-serif; font-variant-numeric: tabular-nums; -webkit-text-size-adjust: 100%; overscroll-behavior: none; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; text-align: inherit; }
input, select, textarea { font: inherit; color: var(--ink); }
svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
small { font-size: 12px; color: var(--muted); }
.muted { color: var(--muted); }
.center { text-align: center; }
.sr { position: absolute; left: -9999px; }
.loading { display: flex; height: 100%; align-items: center; justify-content: center; color: var(--muted); }

/* shell */
.shell { position: fixed; inset: 0; display: flex; flex-direction: column; padding-top: var(--sat); }
.hdr { flex: none; height: 56px; padding: 0 16px 0 20px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.hdr h1 { margin: 0; font-size: 25px; overflow: hidden; text-overflow: ellipsis; font-weight: 700; letter-spacing: -0.02em; white-space: nowrap; }
.hdr h1 span { font-weight: 500; color: var(--muted); }
.titlewrap { display: flex; align-items: center; gap: 2px; min-width: 0; }
.navbtns { display: flex; }
.iconbtn { width: 38px; height: 44px; display: flex; align-items: center; justify-content: center; color: var(--muted); }
.iconbtn svg { width: 20px; height: 20px; }
.hdr-right { display: flex; align-items: center; gap: 4px; flex: none; }
.avs { display: flex; }
.avs .av + .av { margin-left: -8px; }
.av { display: inline-flex; border-radius: 50%; color: #fff; font-weight: 600; align-items: center; justify-content: center; flex: none; }
.av.ring { box-shadow: 0 0 0 2px var(--bg); }
.pillbtn { font-size: 13px; font-weight: 600; color: var(--accent); background: var(--accent-soft); border-radius: 999px; padding: 0 14px; height: 32px; }
.main { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.main.v-week, .main.v-day { display: flex; flex-direction: column; overflow: hidden; }
.main.v-settings { padding-bottom: 24px; }

/* tab bar */
.tabs { flex: none; display: flex; align-items: flex-start; padding: 0 8px var(--sab); height: calc(60px + var(--sab)); background: rgba(255,255,255,0.94); border-top: 1px solid var(--line); }
.tab { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px; padding-top: 8px; min-height: 52px; font-size: 10.5px; font-weight: 500; color: var(--muted); }
.tab.on { color: var(--accent); font-weight: 600; }
.fabwrap { flex: 1; display: flex; justify-content: center; }
.fab { margin-top: -18px; width: 56px; height: 56px; border-radius: 50%; background: var(--accent); color: #fff; display: flex; align-items: center; justify-content: center; box-shadow: 0 6px 16px rgba(109,74,214,0.35); }
.fab svg { width: 26px; height: 26px; stroke-width: 2.2; }

/* month */
.wkdays { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); padding: 2px 10px 4px; }
.wkdays div { text-align: center; font-size: 11px; font-weight: 600; color: var(--muted); }
.mgrid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); grid-auto-rows: 62px; padding: 0 10px; }
.cell { border-top: 1px solid var(--line); padding: 4px 3px 0; display: flex; flex-direction: column; gap: 2px; min-width: 0; overflow: hidden; }
.cell .num { flex: none; align-self: center; width: 24px; height: 24px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 12.5px; font-weight: 500; }
.cell.out .num { color: #9C9AA3; }
.cell.out .pill { opacity: 0.45; }
.cell.today .num { color: var(--accent); font-weight: 700; }
.cell.sel .num { background: var(--accent); color: #fff; font-weight: 700; }
.pill { flex: none; display: block; color: #fff; font-size: 9.5px; font-weight: 600; line-height: 15px; height: 15px; padding: 0 4px; border-radius: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: left; }
.pill.cl { border-top-left-radius: 0; border-bottom-left-radius: 0; margin-left: -3px; }
.pill.cr { border-top-right-radius: 0; border-bottom-right-radius: 0; margin-right: -3px; }
.more { font-size: 9.5px; color: var(--muted); padding-left: 3px; }
.daypanel { margin-top: 10px; min-height: 240px; background: var(--panel); border-radius: 22px 22px 0 0; padding: 16px 16px 24px; display: flex; flex-direction: column; gap: 10px; }
.dp-head { display: flex; justify-content: space-between; align-items: baseline; }
.dp-head h2 { margin: 0; font-size: 16px; font-weight: 700; }
.dp-head span { font-size: 12px; color: var(--muted); }
.evrow { display: flex; align-items: center; gap: 12px; padding: 12px 14px; background: var(--surf); border-radius: 14px; width: 100%; }
.evrow .t { width: 46px; flex: none; display: flex; flex-direction: column; }
.evrow .t b { font-size: 13px; }
.evrow .t small { font-size: 11.5px; }
.evrow .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.evrow .body { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.evrow .body b { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.evrow .who { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
.evrow .who small { font-size: 10.5px; }
.empty { padding: 18px; border-radius: 14px; border: 1.5px dashed #CFCDC6; color: var(--muted); font-size: 14px; text-align: center; width: 100%; }

/* week + day shared */
.scroller { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; padding-bottom: 12px; }
.tgrid { position: relative; margin: 10px 12px 0 0; }
.hr { position: absolute; left: 40px; right: 0; border-top: 1px solid var(--line); }
.hr span { position: absolute; left: -38px; width: 32px; top: -7px; font-size: 10.5px; color: var(--muted); text-align: right; }
.tgrid .cols { position: absolute; left: 40px; right: 0; top: 0; bottom: 0; display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); }
.col { position: relative; border-left: 1px solid rgba(231,229,223,0.6); }
.now { position: absolute; left: 0; right: 0; border-top: 2px solid var(--now); z-index: 3; pointer-events: none; }
.now::before { content: ""; position: absolute; left: -4px; top: -5px; width: 8px; height: 8px; border-radius: 50%; background: var(--now); }
.blk { position: absolute; border-radius: 6px; padding: 3px 4px; color: #fff; overflow: hidden; display: flex; flex-direction: column; z-index: 2; }
.blk b { font-size: 9.5px; line-height: 12px; font-weight: 700; overflow-wrap: normal; word-break: normal; hyphens: none; }
.blk small { font-size: 9px; color: rgba(255,255,255,0.9); line-height: 12px; }
.whead, .adrow { flex: none; display: grid; grid-template-columns: 40px repeat(7, minmax(0, 1fr)); padding-right: 12px; }
.whead { padding-bottom: 6px; border-bottom: 1px solid var(--line); }
.wd { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 2px 0; }
.wd small { font-size: 10.5px; font-weight: 600; }
.wd b { width: 28px; height: 28px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 14px; }
.wd.today b { background: var(--accent); color: #fff; }
.adrow { padding-top: 4px; padding-bottom: 4px; border-bottom: 1px solid var(--line); }
.adrow .gut small { font-size: 9.5px; }
.adcell { display: flex; flex-direction: column; gap: 2px; padding: 0 1px; min-width: 0; }

/* day */
.strip { flex: none; display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 5px; padding: 4px 12px 8px; }
.sday { background: var(--surf); border-radius: 14px; height: 62px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; }
.sday small { font-size: 10.5px; font-weight: 600; }
.sday b { font-size: 17px; }
.sday.today:not(.on) b { color: var(--accent); }
.sday.on { background: var(--accent); color: #fff; }
.sday.on small { color: rgba(255,255,255,0.85); }
.dots { display: flex; gap: 2px; height: 5px; }
.dots i { width: 5px; height: 5px; border-radius: 50%; }
.sday.on .dots i { box-shadow: 0 0 0 1px rgba(255,255,255,0.7); }
.adlist { flex: none; display: flex; flex-wrap: wrap; gap: 6px; padding: 0 20px 8px; }
.pill.big { font-size: 12.5px; height: 24px; line-height: 24px; padding: 0 10px; border-radius: 8px; max-width: 100%; }
.tgrid.day { margin-right: 16px; }
.tgrid.day .hr { left: 56px; }
.tgrid.day .hr span { left: -54px; width: 46px; font-size: 11.5px; }
.tgrid.day .cols { left: 56px; grid-template-columns: minmax(0, 1fr); }
.tgrid.day .col { border-left: 0; }
.dblk { position: absolute; border-radius: 12px; padding: 8px 10px; color: #fff; overflow: hidden; display: flex; justify-content: space-between; gap: 8px; z-index: 2; }
.dblk .txt { display: flex; flex-direction: column; min-width: 0; }
.dblk b { font-size: 14.5px; }
.dblk small { color: rgba(255,255,255,0.92); font-size: 12px; }

/* settings + cards */
.sec { margin: 18px 20px 6px; font-size: 12px; font-weight: 600; color: var(--muted); letter-spacing: 0.04em; }
.card { margin: 0 16px; background: var(--surf); border-radius: 16px; overflow: hidden; }
.list .row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 48px; padding: 0 16px; width: 100%; font-size: 15px; }
.list .row + .row { border-top: 1px solid var(--line); }
.lr { display: flex; align-items: center; gap: 10px; }
.cdot { width: 12px; height: 12px; border-radius: 50%; }
.accent { color: var(--accent); }
.danger { color: var(--danger); font-weight: 600; }
.chev { color: var(--muted); display: flex; }
.chev svg { width: 16px; height: 16px; }
.linkbtn { color: var(--accent); font-weight: 600; }
.linkbtn.small { font-size: 13px; }
.signout { margin-top: 18px; }
.diag { margin: 12px 16px 0; padding: 12px; background: var(--surf); border-radius: 12px; font-size: 11.5px; white-space: pre-wrap; word-break: break-word; user-select: text; -webkit-user-select: text; }

/* detail page */
.page { position: fixed; inset: 0; z-index: 20; background: var(--bg); overflow-y: auto; padding: calc(var(--sat)) 0 calc(24px + var(--sab)); }
.topbar { height: 48px; padding: 0 8px; display: flex; align-items: center; justify-content: space-between; }
.back { display: flex; align-items: center; gap: 2px; color: var(--accent); font-size: 16px; min-height: 44px; padding: 0 8px; }
.back svg { width: 22px; height: 22px; }
.textbtn { color: var(--accent); font-size: 16px; font-weight: 600; padding: 12px; }
.dhead { padding: 14px 20px 18px; }
.chip { display: inline-flex; align-items: center; gap: 6px; background: color-mix(in srgb, var(--c) 14%, white); color: color-mix(in srgb, var(--c) 75%, black); font-size: 12.5px; font-weight: 600; border-radius: 999px; padding: 5px 10px; }
.chip i { width: 8px; height: 8px; border-radius: 50%; background: var(--c); }
.dhead h1 { margin: 12px 0 0; font-size: 28px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.15; word-break: break-word; }
.drow { display: flex; gap: 14px; padding: 14px 16px; font-size: 15px; align-items: flex-start; }
.drow + .drow { border-top: 1px solid var(--line); }
.drow .ic { color: var(--muted); padding-top: 1px; }
.drow .ic svg { width: 20px; height: 20px; }
.drow > div { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.drow small a { color: var(--accent); }
.notes { white-space: pre-wrap; word-break: break-word; }
.card.who { margin-top: 16px; }
.card.who .drow { align-items: center; }
.btn-delete { display: block; margin: 20px 16px 0; width: calc(100% - 32px); height: 50px; font-size: 16px; font-weight: 600; color: var(--danger); background: var(--surf); border-radius: 14px; text-align: center; }

/* editor sheet */
.backdrop { position: fixed; inset: 0; z-index: 30; background: rgba(28,27,34,0.35); }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; top: calc(var(--sat) + 24px); z-index: 31; background: var(--bg); border-radius: 22px 22px 0 0; overflow-y: auto; padding-bottom: calc(32px + var(--sab)); }
.grab { width: 38px; height: 5px; border-radius: 3px; background: #CFCDC6; margin: 8px auto 0; }
.sheetbar { display: flex; align-items: center; justify-content: space-between; padding: 6px 8px 10px; }
.sheetbar h1 { margin: 0; font-size: 16px; font-weight: 700; }
.savebtn { color: #fff; background: var(--accent); font-size: 15px; font-weight: 600; padding: 8px 16px; border-radius: 999px; margin-right: 8px; }
.titlein { font-size: 22px !important; font-weight: 700; border: 0; width: 100%; padding: 16px; background: transparent; outline: none; }
.locin { font-size: 16px; border: 0; border-top: 1px solid var(--line); width: 100%; padding: 14px 16px; background: transparent; outline: none; }
.sheet .card + .card, .mt { margin-top: 14px; }
.dt { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; min-width: 0; padding: 6px 0; }
.dt input { font-size: 16px; border: 0; background: var(--panel); border-radius: 8px; padding: 6px 8px; min-height: 34px; -webkit-appearance: none; appearance: none; }
.sheet.allday .tm { display: none; }
.switch { -webkit-appearance: none; appearance: none; width: 50px; height: 30px; border-radius: 15px; background: #E3E1DA; position: relative; transition: background .2s; margin: 0; flex: none; }
.switch::after { content: ""; position: absolute; left: 2px; top: 2px; width: 26px; height: 26px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,0.2); transition: left .2s; }
.switch:checked { background: #15803D; }
.switch:checked::after { left: 22px; }
.chips { margin: 0 16px; display: flex; flex-wrap: wrap; gap: 8px; }
.catchip input { position: absolute; opacity: 0; pointer-events: none; }
.catchip span { display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 14px; border-radius: 999px; font-size: 13.5px; font-weight: 600; background: var(--surf); border: 1.5px solid var(--line); }
.catchip span i { width: 8px; height: 8px; border-radius: 50%; background: var(--c); }
.catchip input:checked + span { background: var(--c); border-color: var(--c); color: #fff; }
.catchip input:checked + span i { background: #fff; }
.catchip input:focus-visible + span { outline: 2px solid var(--ink); outline-offset: 2px; }
.sheet select { font-size: 15px; border: 0; background: transparent; color: var(--muted); text-align: right; direction: rtl; max-width: 60%; }
.ic svg { width: 20px; height: 20px; }
.sheet .lr .ic { color: var(--muted); display: flex; }
.sheet textarea { font-size: 16px; border: 0; border-top: 1px solid var(--line); width: 100%; padding: 14px 16px; height: 100px; resize: none; background: transparent; outline: none; }

/* toast */
.toast { position: fixed; left: 50%; bottom: calc(96px + var(--sab)); transform: translate(-50%, 20px); background: var(--ink); color: #fff; font-size: 14px; padding: 10px 16px; border-radius: 12px; opacity: 0; transition: opacity .2s, transform .2s; z-index: 50; pointer-events: none; max-width: calc(100% - 40px); text-align: center; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* sign in */
.signin { min-height: 100%; padding: calc(var(--sat) + 48px) 24px calc(24px + var(--sab)); display: flex; flex-direction: column; gap: 28px; }
.brand { display: flex; flex-direction: column; align-items: center; text-align: center; }
.appicon { width: 84px; height: 84px; border-radius: 20px; background: var(--accent); display: flex; flex-direction: column; align-items: center; justify-content: center; color: #fff; box-shadow: 0 10px 24px rgba(109,74,214,0.3); }
.appicon span { font-size: 11px; font-weight: 700; letter-spacing: 0.08em; }
.appicon b { font-size: 34px; line-height: 1; }
.brand h1 { margin: 18px 0 0; font-size: 28px; letter-spacing: -0.02em; }
.brand p { margin: 6px 0 0; font-size: 15px; color: var(--muted); }
.stack { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 13px; font-weight: 600; color: var(--muted); }
.field input { font-size: 16px; height: 50px; border: 1.5px solid var(--line); border-radius: 12px; padding: 0 14px; background: var(--surf); outline: none; }
.field input:focus { border-color: var(--accent); }
.err { margin: 0; min-height: 18px; color: var(--danger); font-size: 14px; }
.btn-primary { height: 52px; border-radius: 14px; background: var(--accent); color: #fff; font-size: 16px; font-weight: 600; text-align: center; }
.btn-primary:disabled { opacity: 0.6; }
.install { margin: 0; padding: 18px; }
.install h2 { margin: 0 0 12px; font-size: 15px; }
.install ol { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 10px; }
.install li { display: flex; align-items: center; gap: 10px; font-size: 14.5px; }
.install .num { width: 26px; height: 26px; border-radius: 50%; background: var(--accent-soft); color: var(--accent-ink); font-size: 13px; font-weight: 700; display: flex; align-items: center; justify-content: center; flex: none; }
.install .ic { color: var(--muted); display: flex; }
.install .ic svg { width: 18px; height: 18px; }
