:root {
  color-scheme: light dark;
  --bg: #F2F2F7;
  --surface: #FFFFFF;
  --surface-2: #F2F2F7;
  --fill: rgba(118, 118, 128, 0.12);
  --label: #000000;
  --label-2: #6C6C70;
  --separator: rgba(60, 60, 67, 0.18);
  --accent: #0066CC;
  --accent-soft: rgba(0, 102, 204, 0.12);
  --red: #D70015;
  --red-soft: rgba(215, 0, 21, 0.1);
  --orange: #C93400;
  --orange-soft: rgba(201, 52, 0, 0.1);
  --green: #248A3D;
  --green-soft: rgba(36, 138, 61, 0.12);
  --glass: rgba(255, 255, 255, 0.72);
  --glass-border: rgba(255, 255, 255, 0.6);
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
  --accent-fill: #0066CC;   /* backgrounds behind white text/icons */
  --green-fill: #248A3D;
  --press: rgba(118, 118, 128, 0.16);
  --radius: 16px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-xl: 20px;
  --ease-out: cubic-bezier(.2, .8, .2, 1);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Hebrew", system-ui, "Segoe UI", "Heebo", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --surface: #1C1C1E;
    --surface-2: #2C2C2E;
    --fill: rgba(118, 118, 128, 0.24);
    --label: #FFFFFF;
    --label-2: #AEAEB2;
    --separator: rgba(84, 84, 88, 0.6);
    --accent: #4BA3FF;
    --accent-soft: rgba(75, 163, 255, 0.16);
    --red: #FF6961;
    --red-soft: rgba(255, 105, 97, 0.16);
    --orange: #FFB340;
    --orange-soft: rgba(255, 179, 64, 0.16);
    --green: #30DB5B;
    --green-soft: rgba(48, 219, 91, 0.16);
    --glass: rgba(30, 30, 32, 0.72);
    --glass-border: rgba(255, 255, 255, 0.08);
    --shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
    --accent-fill: #0071E3;  /* #4BA3FF only reaches 2.6:1 under white text */
    --green-fill: #248A3D;   /* #30DB5B only reaches 1.8:1 under a white check */
    --press: rgba(118, 118, 128, 0.28);
  }
}

* { box-sizing: border-box; }
html {
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none; /* app shell: no pull-to-refresh, no page rubber-band */
}
body {
  overscroll-behavior: none;
  margin: 0;
  background: var(--bg);
  color: var(--label);
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }

/* Controls respond instantly and never select their label on long-press. Content text stays selectable. */
button, a, label, select, [role="button"] { touch-action: manipulation; }
button, [role="button"], .chip, .tab, .card, .grabber, .type-picker label {
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

/* Native press feedback: dim on touch-down, fade back on release. */
.btn, .bar-btn, .chip, .segmented button, .tab, .side-item, .add-line, .add-file,
.kind, .icon-btn, .link, .file-row a, .compact-add, .google-btn {
  transition: opacity .16s var(--ease-out);
}
:is(.btn, .bar-btn, .chip, .segmented button, .tab, .side-item, .add-line, .add-file,
.kind, .icon-btn, .link, .file-row a, .compact-add, .google-btn):active:not(:disabled) {
  opacity: .55;
  transition-duration: 0s;
}
svg { width: 22px; height: 22px; flex-shrink: 0; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 8px; }

/* ---------- Layout ---------- */
.app { min-height: 100dvh; }
.sidebar { display: none; }
.main {
  max-width: 760px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 12px) max(16px, env(safe-area-inset-right)) calc(env(safe-area-inset-bottom) + 110px) max(16px, env(safe-area-inset-left));
}

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0 12px;
}
.page-head h1 {
  margin: 0;
  font-size: 34px;
  line-height: 41px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.btn-round {
  width: 44px; height: 44px;
  border-radius: 50%;
  border: 0;
  display: grid; place-items: center;
  background: var(--accent-fill);
  color: #fff;
  box-shadow: 0 4px 14px var(--accent-soft);
  transition: transform .12s var(--ease-out);
}
.btn-round:active { transform: scale(.92); transition-duration: 0s; }

.controls { display: grid; gap: 12px; margin-bottom: 24px; }
.search {
  display: flex; align-items: center; gap: 8px;
  background: var(--fill);
  border-radius: var(--radius-md);
  padding: 0 12px;
  height: 44px;
  color: var(--label-2);
}
.search svg { width: 18px; height: 18px; }
.search input {
  flex: 1; border: 0; background: none; outline: none; min-width: 0;
  color: var(--label); font-size: 17px; height: 100%;
}
.search input::placeholder { color: var(--label-2); }
.search:focus-within { outline: 3px solid var(--accent-soft); }

.segmented {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  background: var(--fill);
  border-radius: 10px;
  padding: 2px;
}
.segmented button {
  border: 0; background: none;
  position: relative;
  height: 32px; border-radius: var(--radius-sm);
  font-size: 15px; font-weight: 500;
  color: var(--label);
}
.segmented button::after { content: ""; position: absolute; inset: -6px 0; } /* 44px hit area */
.segmented button[aria-selected="true"] {
  background: var(--surface);
  box-shadow: 0 2px 6px rgba(0,0,0,.12);
  font-weight: 600;
}
@media (prefers-color-scheme: dark) {
  .segmented button[aria-selected="true"] { background: #636366; }
}

/* ---------- List ---------- */
.list { display: grid; gap: 24px; }
.group-title {
  margin: 0 16px 8px;
  line-height: 18px;
  font-size: 13px;
  font-weight: 600;
  color: var(--label-2);
}
.group { display: grid; gap: 10px; }

.card {
  display: flex;
  align-items: stretch;
  gap: 14px;
  width: 100%;
  text-align: start;
  background: var(--surface);
  border: 0;
  border-radius: var(--radius);
  padding: 14px 16px;
  position: relative;
  color: inherit;
  transition: transform .16s var(--ease-out), background .16s var(--ease-out);
}
.card:active { transform: scale(.985); transition-duration: 0s; }
@media (hover: hover) and (pointer: fine) { .card:hover { background: color-mix(in srgb, var(--surface) 92%, var(--accent)); } }

/* signature: days-left block */
.days {
  width: 62px;
  flex-shrink: 0;
  border-radius: var(--radius-md);
  display: grid;
  place-content: center;
  text-align: center;
  background: var(--accent-soft);
  color: var(--accent);
  padding: 6px 0;
}
.days b { display: block; font-size: 28px; line-height: 1; font-weight: 700; font-variant-numeric: tabular-nums; }
.days small { display: block; font-size: 12px; font-weight: 600; margin-top: 3px; }
.days.soon { background: var(--red-soft); color: var(--red); }
.days.week { background: var(--orange-soft); color: var(--orange); }
.days.past { background: var(--fill); color: var(--label-2); }
.days.word b { font-size: 17px; }

.card-body { flex: 1; min-width: 0; display: grid; gap: 4px; align-content: center; }
.card-title { font-size: 17px; line-height: 22px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-sub { font-size: 15px; line-height: 20px; color: var(--label-2); display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; }
.card-sub .meta { display: inline-flex; align-items: center; gap: 3px; }
.card-sub svg { width: 15px; height: 15px; }
.subject {
  display: inline-block;
  font-size: 13px; font-weight: 600;
  color: var(--accent);
}

.progress {
  height: 4px; border-radius: 4px;
  background: var(--fill);
  overflow: hidden;
  margin-top: 4px;
}
.progress i { display: block; height: 100%; background: var(--green); border-radius: 4px; }

.check {
  width: 28px; height: 28px; border-radius: 50%;
  border: 2px solid var(--label-2);
  background: none;
  display: grid; place-items: center;
  color: transparent;
  flex-shrink: 0;
  align-self: center;
  position: relative;
}
.check::after { content: ""; position: absolute; inset: -8px; } /* 44px hit area */
.check svg { width: 16px; height: 16px; }
.check[aria-checked="true"] { background: var(--green-fill); border-color: var(--green-fill); color: #fff; }
.card.is-done .card-title { color: var(--label-2); text-decoration: line-through; }

.empty {
  text-align: center;
  padding: 56px 24px;
  color: var(--label-2);
}
.empty svg { width: 52px; height: 52px; color: var(--accent); opacity: .5; margin-bottom: 10px; }
.empty h2 { margin: 0 0 8px; font-size: 20px; line-height: 25px; color: var(--label); }
.empty p { margin: 0 0 18px; }

.btn {
  height: 44px;
  padding: 0 20px;
  border-radius: var(--radius-md);
  border: 0;
  font-weight: 600;
  font-size: 17px;
  background: var(--fill);
  color: var(--accent);
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn.primary { background: var(--accent-fill); color: #fff; }
.btn.danger { color: var(--red); }
.btn:disabled { opacity: .5; cursor: default; }

/* ---------- Tab bar (mobile) ---------- */
.tabbar {
  position: fixed;
  inset-inline: 0;
  bottom: calc(env(safe-area-inset-bottom) + 10px);
  margin: 0 auto;
  width: min(380px, calc(100% - 32px));
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  padding: 5px;
  border-radius: 999px;
  background: var(--glass);
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  box-shadow: var(--shadow);
  z-index: 10;
}
.tab {
  border: 0; background: none;
  height: 54px;
  border-radius: 999px;
  display: grid; justify-items: center; align-content: center; gap: 2px;
  font-size: 11px; font-weight: 600;
  color: var(--label-2);
}
.tab svg { width: 24px; height: 24px; }
.tab[aria-current="page"] { color: var(--accent); background: var(--accent-soft); }

@media (prefers-reduced-transparency: reduce) {
  .tabbar { background: var(--surface); backdrop-filter: none; -webkit-backdrop-filter: none; }
}

/* ---------- Desktop ---------- */
@media (min-width: 900px) {
  .app { display: grid; grid-template-columns: 260px 1fr; }
  .tabbar { display: none; }
  .sidebar {
    display: flex; flex-direction: column;
    position: sticky; top: 0; height: 100dvh;
    padding: 20px 12px;
    background: var(--surface);
    border-inline-end: 1px solid var(--separator);
  }
  .brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 20px; padding: 4px 10px 22px; }
  .brand img { border-radius: 8px; }
  .side-nav { display: grid; gap: 2px; }
  .side-item {
    display: flex; align-items: center; gap: 10px;
    border: 0; background: none;
    height: 40px; padding: 0 10px;
    border-radius: var(--radius-sm);
    font-size: 15px; font-weight: 500;
    text-align: start;
  }
  .side-item svg { color: var(--accent); width: 20px; height: 20px; }
  .side-item span:nth-child(2) { flex: 1; }
  .side-item .count { font-size: 13px; color: var(--label-2); font-variant-numeric: tabular-nums; }
  .side-item[aria-current="page"] { background: var(--accent-fill); color: #fff; }
  .side-item[aria-current="page"] svg, .side-item[aria-current="page"] .count { color: #fff; }
  .sync { margin-top: auto; padding: 0 10px; font-size: 13px; color: var(--label-2); }
  .main { padding: 28px 40px 60px; max-width: 980px; margin: 0; width: 100%; }
  .controls { grid-template-columns: 1fr 280px; }
  .group { grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }
  body { font-size: 15px; }
}
@media (min-width: 900px) and (hover: hover) and (pointer: fine) {
  .side-item:not([aria-current="page"]):hover { background: var(--fill); }
}

/* ---------- Sheet ---------- */
.sheet {
  border: 0;
  padding: 0;
  color: var(--label);
  background: var(--surface-2);
  width: 100%;
  max-width: 100%;
  max-height: 92dvh;
  margin: auto 0 0;
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  overflow: hidden;
  box-shadow: var(--shadow);
}
.sheet[open] { display: flex; flex-direction: column; animation: sheet-up .32s cubic-bezier(.2,.9,.3,1); }
.sheet::backdrop { background: rgba(0,0,0,.35); animation: fade .25s ease; }
@media (prefers-color-scheme: dark) { .sheet { background: #1C1C1E; } }
@keyframes sheet-up { from { transform: translateY(100%); } }
@keyframes fade { from { opacity: 0; } }
@media (prefers-reduced-motion: reduce) {
  .sheet[open], .sheet::backdrop { animation: none; }
  .card, .btn-round { transition: none; }
}
.grabber { width: 36px; height: 5px; border-radius: 3px; background: var(--label-2); opacity: .4; margin: 6px auto 0; flex-shrink: 0; touch-action: none; }
#sheet-body { display: flex; flex-direction: column; min-height: 0; flex: 1; }
@media (min-width: 900px) {
  .sheet { max-width: 560px; margin: auto; border-radius: var(--radius); max-height: 86dvh; }
  .grabber { display: none; }
  @keyframes sheet-up { from { transform: scale(.96); opacity: 0; } }
}

.sheet-bar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 10px 8px 8px;
  flex-shrink: 0;
}
.sheet-bar h2 { margin: 0; font-size: 17px; line-height: 22px; font-weight: 600; text-align: center; }
.sheet-bar .start { justify-self: start; }
.sheet-bar .end { justify-self: end; }
.bar-btn {
  border: 0; background: none;
  color: var(--accent);
  min-height: 44px; padding: 0 10px;
  font-size: 17px;
  display: inline-flex; align-items: center; gap: 4px;
}
.bar-btn.strong { font-weight: 600; }
.bar-btn:disabled { opacity: .4; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 50%;
  border: 0; background: var(--fill); color: var(--label-2);
  display: grid; place-items: center;
  margin: 4px;
  position: relative;
}
.icon-btn::after { content: ""; position: absolute; inset: -4px; }
.icon-btn svg { width: 18px; height: 18px; }

.sheet-scroll {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 4px 16px calc(env(safe-area-inset-bottom) + 24px);
  overscroll-behavior: contain;
}

/* Form */
.form-group {
  background: var(--surface);
  border-radius: var(--radius-md);
  margin-bottom: 24px;
  overflow: hidden;
}
@media (prefers-color-scheme: dark) { .form-group { background: #2C2C2E; } }
.field {
  display: flex; align-items: center; gap: 12px;
  min-height: 48px;
  padding: 0 16px;
  position: relative;
}
.field + .field::before {
  content: ""; position: absolute; top: 0; inset-inline: 16px 0;
  border-top: 1px solid var(--separator);
}
.field label { flex-shrink: 0; width: 84px; font-size: 17px; }
.field input, .field textarea, .field select {
  flex: 1; min-width: 0;
  border: 0; background: none; outline: none;
  font-size: 17px;
  padding: 12px 0;
}
.field input[type="date"] { text-align: start; min-height: 24px; }
.field.stack { flex-direction: column; align-items: stretch; gap: 0; padding-top: 10px; }
.field.stack label { width: auto; font-size: 13px; font-weight: 600; color: var(--label-2); }
.field textarea { resize: none; min-height: 96px; line-height: 1.45; padding: 6px 0 12px; field-sizing: content; }
.hint { font-size: 13px; line-height: 18px; color: var(--label-2); margin: -16px 16px 24px; }
.section-label { font-size: 13px; line-height: 18px; font-weight: 600; color: var(--label-2); margin: 0 16px 8px; }

/* Files */
.files { display: grid; gap: 0; }
.file-row {
  display: flex; align-items: center; gap: 12px;
  min-height: 52px; padding: 6px 16px;
  position: relative;
}
.file-row + .file-row::before { content: ""; position: absolute; top: 0; inset-inline: 60px 0; border-top: 1px solid var(--separator); }
.file-icon {
  width: 34px; height: 34px; border-radius: 8px;
  background: var(--accent-soft); color: var(--accent);
  display: grid; place-items: center; flex-shrink: 0;
  overflow: hidden;
}
.file-icon svg { width: 18px; height: 18px; }
.file-icon img { width: 100%; height: 100%; object-fit: cover; }
.file-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-name small { display: block; font-size: 13px; color: var(--label-2); }
.file-row a, .file-row .link { color: var(--accent); font-weight: 600; text-decoration: none; border: 0; background: none; min-height: 44px; padding: 0 6px; display: inline-flex; align-items: center; font-size: 15px; }
.add-file {
  display: flex; align-items: center; gap: 10px;
  min-height: 48px; padding: 0 16px;
  color: var(--accent);
  cursor: pointer;
  position: relative;
}
.files:not(:empty) + .add-file::before { content: ""; position: absolute; top: 0; inset-inline: 16px 0; border-top: 1px solid var(--separator); }
.add-file input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.add-file svg { width: 20px; height: 20px; }

/* Detail */
.detail-head { padding: 8px 4px 16px; display: flex; gap: 16px; align-items: center; }
.detail-head .days { width: 72px; height: 72px; }
.detail-head h3 { margin: 0; font-size: 22px; line-height: 28px; font-weight: 700; }
.detail-head p { margin: 4px 0 0; color: var(--label-2); font-size: 15px; line-height: 20px; }

.topic {
  display: flex; align-items: center; gap: 12px;
  min-height: 48px; padding: 8px 16px;
  position: relative;
  width: 100%;
  border: 0; background: none; text-align: start;
  font-size: 17px;
}
.topic + .topic::before { content: ""; position: absolute; top: 0; inset-inline: 56px 0; border-top: 1px solid var(--separator); }
.topic .check { width: 26px; height: 26px; }
.topic .check::after { display: none; }
.topic.done span { color: var(--label-2); text-decoration: line-through; }
button.topic { transition: background .16s var(--ease-out); }
button.topic:active { background: var(--press); transition-duration: 0s; }
.topic-progress { display: flex; align-items: center; gap: 10px; margin: 0 16px 8px; font-size: 13px; color: var(--label-2); font-weight: 600; }
.topic-progress .progress { flex: 1; margin: 0; height: 6px; }

.notes { white-space: pre-wrap; padding: 14px 16px; margin: 0; line-height: 1.5; }
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 13px 16px; position: relative; }
.kv + .kv::before { content: ""; position: absolute; top: 0; inset-inline: 16px 0; border-top: 1px solid var(--separator); }
.kv span:first-child { color: var(--label-2); }
.kv span:last-child { text-align: end; white-space: pre-wrap; }

.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 4px; }
.actions .btn { width: 100%; }

.preview-img { width: 100%; border-radius: 12px; display: block; margin-top: 8px; }

/* Toast */
.toast {
  position: fixed;
  inset-inline: 0;
  top: calc(env(safe-area-inset-top) + 12px);
  margin: 0 auto;
  width: max-content;
  max-width: calc(100% - 32px);
  padding: 10px 18px;
  border-radius: 999px;
  background: var(--glass);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border: 1px solid var(--glass-border);
  box-shadow: var(--shadow);
  font-size: 15px; font-weight: 600;
  opacity: 0;
  transform: translateY(-12px);
  transition: opacity .2s, transform .2s;
  pointer-events: none;
  z-index: 100;
}
.toast.show { opacity: 1; transform: none; }
.toast.error { color: var(--red); }

.skeleton { height: 82px; border-radius: var(--radius); background: var(--surface); opacity: .6; animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .3; } }
@media (prefers-reduced-motion: reduce) { .skeleton { animation: none; } }

/* ---------- Test type picker ---------- */
.type-picker { margin-bottom: 24px; }
.type-picker label { display: grid; position: relative; cursor: pointer; }
.type-picker label::after { content: ""; position: absolute; inset: -5px 0; } /* 44px hit area */
.type-picker input { position: absolute; opacity: 0; pointer-events: none; }
.type-picker span {
  display: grid; place-items: center;
  height: 34px; padding: 0 4px;
  border-radius: var(--radius-sm);
  font-size: 15px; font-weight: 500;
  white-space: nowrap;
}
.type-picker input:checked + span { background: var(--surface); box-shadow: 0 2px 6px rgba(0,0,0,.12); font-weight: 600; }
.type-picker input:focus-visible + span { outline: 3px solid var(--accent); }
@media (prefers-color-scheme: dark) { .type-picker input:checked + span { background: #636366; } }

/* ---------- Line editor (checkbox or plain text per line) ---------- */
.line-row {
  display: flex; align-items: center; gap: 4px;
  min-height: 48px;
  padding-inline: 4px 10px;
  position: relative;
}
.line-row + .line-row::before,
.line-row + .add-line::before {
  content: ""; position: absolute; top: 0; inset-inline: 52px 0;
  border-top: 1px solid var(--separator);
}
.kind {
  width: 44px; height: 44px;
  border: 0; background: none;
  display: grid; place-items: center;
  color: var(--label-2);
  flex-shrink: 0;
  border-radius: var(--radius-md);
}
.kind svg { width: 24px; height: 24px; }
.kind[aria-pressed="true"] { color: var(--accent); }
@media (hover: hover) and (pointer: fine) { .kind:hover { background: var(--fill); } }
.line-input {
  flex: 1; min-width: 0;
  border: 0; background: none; outline: none;
  font-size: 17px; padding: 12px 0;
}
.line-input::placeholder { color: var(--label-2); opacity: 1; } /* .7 dropped it to 2.9:1 */
.icon-btn.small { width: 26px; height: 26px; margin: 0; flex-shrink: 0; }
.icon-btn.small svg { width: 14px; height: 14px; }
.icon-btn.small::after { inset: -9px; }
.line-row:not(:focus-within) .icon-btn.small { opacity: .55; }
.add-line {
  display: flex; align-items: center; gap: 10px;
  width: 100%; min-height: 48px;
  padding-inline: 16px;
  border: 0; background: none;
  color: var(--accent); font-size: 17px;
  text-align: start;
  position: relative;
}
.add-line svg { width: 20px; height: 20px; }

.topic.plain { cursor: default; }
.topic .dot { width: 26px; display: grid; place-items: center; flex-shrink: 0; }
.topic .dot::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--label-2); }

/* ---------- Subject + date filters ---------- */
.filters { display: grid; gap: 10px; min-width: 0; }
.filter-row {
  display: flex; align-items: center; gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
  margin-inline: -16px;
  padding: 2px 16px;
}
.filter-row::-webkit-scrollbar { display: none; }
.chips { display: flex; gap: 8px; }
.chip {
  flex-shrink: 0;
  height: 34px;
  padding-inline: 14px;
  border-radius: 999px;
  border: 1px solid var(--separator);
  background: var(--surface);
  font-size: 15px; font-weight: 500;
  white-space: nowrap;
  display: inline-flex; align-items: center; gap: 6px;
  position: relative;
}
.chip::after { content: ""; position: absolute; inset: -5px -2px; }
.chip[aria-pressed="true"], .chip.active {
  background: var(--accent-fill); border-color: var(--accent-fill); color: #fff;
}
.chip-divider { width: 1px; height: 22px; background: var(--separator); flex-shrink: 0; }
.select-chip { padding-inline: 12px 10px; cursor: pointer; }
.select-chip svg { width: 17px; height: 17px; }
.select-chip .chev { width: 14px; height: 14px; opacity: .7; }
/* the real <select> covers the whole chip (invisible) so any tap opens it */
.select-chip select {
  position: absolute; inset: 0; z-index: 1;
  width: 100%; height: 100%;
  opacity: 0;
  font-size: 16px;
  cursor: pointer;
}
.select-chip:focus-within { outline: 3px solid var(--accent); outline-offset: 2px; }
.select-chip option { color: var(--label); background: var(--surface); }
.custom-range { display: flex; gap: 10px; flex-wrap: wrap; }
.custom-range[hidden], .app[hidden], .segmented[hidden], .filters[hidden] { display: none; }
.custom-range label {
  flex: 1; min-width: 140px;
  display: flex; align-items: center; gap: 8px;
  height: 44px; padding-inline: 12px;
  background: var(--fill); border-radius: var(--radius-md);
  font-size: 15px; color: var(--label-2);
}
.custom-range input {
  flex: 1; min-width: 0; height: 100%;
  border: 0; background: none; outline: none;
  font-size: 16px; color: var(--label);
  -webkit-appearance: none; appearance: none;
  display: flex; align-items: center;
}
/* iOS Safari collapses empty date inputs and centers their text */
input[type="date"] { min-height: 1.6em; }
input[type="date"]::-webkit-date-and-time-value { text-align: start; }
.empty .btn + .btn { margin-inline-start: 8px; }

@media (min-width: 900px) {
  .filters { grid-column: 1 / -1; }
  .filter-row { margin-inline: 0; padding-inline: 0; flex-wrap: wrap; overflow: visible; }
  .chips { flex-wrap: wrap; }
}

/* ---------- Lock screen ---------- */
.lock {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  background: var(--bg);
  z-index: 100;
}
.lock-card {
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 32px 24px;
  background: var(--surface);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow);
  text-align: center;
}
.lock-card h1 { margin: 4px 0 0; font-size: 28px; line-height: 34px; font-weight: 700; }
.lock-card p { margin: 0; color: var(--label-2); font-size: 15px; }
.lock-error { min-height: 1.4em; color: var(--red) !important; font-weight: 500; font-size: 15px; line-height: 20px; }
.auth-msg { line-height: 20px; }

/* Google sign-in button (Google's light/dark button colours) */
.google-btn {
  width: 100%;
  min-height: 48px;
  margin-top: 12px;
  padding: 0 16px;
  display: inline-flex; align-items: center; justify-content: center; gap: 12px;
  border: 1px solid #747775;
  border-radius: 999px;
  background: #FFFFFF;
  color: #1F1F1F;
  font-size: 17px; font-weight: 600;
}
.google-btn:disabled { opacity: .6; cursor: default; }
.g-logo { width: 20px; height: 20px; }
@media (prefers-color-scheme: dark) {
  .google-btn { background: #131314; color: #E3E3E3; border-color: #8E918F; }
}
/* While Firebase restores the session, show only the logo */
.lock.checking .google-btn, .lock.checking .auth-msg, .lock.checking .lock-error { visibility: hidden; }

/* Wrapping variant for pickers with many/long options (מסע - נחשון) */
.type-picker.wrap { display: flex; flex-wrap: wrap; gap: 2px; }
.type-picker.wrap label { flex: 1 1 auto; }
.type-picker.wrap span { padding: 0 10px; }

/* ---------- Links ---------- */
.link-card { padding: 0; align-items: center; gap: 0; }
.link-main {
  flex: 1; min-width: 0;
  display: flex; align-items: center; gap: 14px;
  padding: 14px;
  color: inherit; text-decoration: none;
  border-radius: var(--radius);
}
.link-main:focus-visible { outline: 3px solid var(--accent); outline-offset: -3px; }
.link-icon {
  flex: none;
  display: grid; place-items: center;
  width: 48px; height: 48px;
  border-radius: 12px;
  background: var(--accent-soft); color: var(--accent);
  font-size: 22px; font-weight: 700;
}
.link-card .icon-btn { margin-inline-end: 10px; }
.link-card .card-sub .meta { direction: ltr; }

/* ---------- Compact title bar (iOS inline nav title) ---------- */
.compact-bar {
  position: fixed;
  inset-inline: 0; top: 0;
  z-index: 9;
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  align-items: center;
  height: calc(env(safe-area-inset-top, 0px) + 44px);
  padding: env(safe-area-inset-top, 0px) max(8px, env(safe-area-inset-right, 0px)) 0 max(8px, env(safe-area-inset-left, 0px));
  background: var(--glass);
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  border-bottom: 0.5px solid var(--separator);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s var(--ease-out);
}
.compact-bar.show { opacity: 1; pointer-events: auto; }
#compact-title {
  grid-column: 2;
  text-align: center;
  font-size: 17px; line-height: 22px; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.compact-add {
  grid-column: 3;
  width: 44px; height: 44px;
  border: 0; background: none;
  display: grid; place-items: center;
  color: var(--accent);
}
.compact-add svg { width: 24px; height: 24px; }
@media (prefers-reduced-transparency: reduce) {
  .compact-bar { background: var(--surface); backdrop-filter: none; -webkit-backdrop-filter: none; }
}
@media (prefers-reduced-motion: reduce) { .compact-bar { transition: none; } }
@media (min-width: 900px) { .compact-bar { display: none; } }

/* ---------- Phone: inset-grouped lists instead of floating cards ---------- */
@media (max-width: 899px) {
  .group {
    gap: 0;
    background: var(--surface);
    border-radius: var(--radius);
    overflow: hidden;
  }
  .card {
    border-radius: 0;
    background: none;
    padding: 12px 16px;
    gap: 12px;
  }
  .card:active { transform: none; background: var(--press); }
  /* hairline separators start at the text, after the days block (16 + 60 + 12) */
  .card + .card::before {
    content: "";
    position: absolute; top: 0;
    inset-inline: 88px 0;
    border-top: 0.5px solid var(--separator);
  }
  .days { width: 60px; }
  .group .skeleton { border-radius: 0; opacity: 1; background: none; }
  .group .skeleton + .skeleton { border-top: 0.5px solid var(--separator); }

  .link-card { padding: 0; }
  .link-main { padding: 12px 16px; gap: 12px; border-radius: 0; }
  .link-card + .link-card::before { inset-inline-start: 76px; } /* 16 + 48 + 12 */
}
@media (prefers-reduced-motion: reduce) { .card, .btn-round { transition: none; } }

/* =========================================================
   Motion
   Short, purposeful, ease-out; all of it is off under Reduce Motion.
   ========================================================= */
:root { --spring: cubic-bezier(.34, 1.25, .64, 1); }

/* ----- Sliding selection pill: segmented control ----- */
.segmented:not([hidden]) { position: relative; isolation: isolate; }
#filter::before {
  content: "";
  position: absolute; z-index: -1;
  top: 2px; bottom: 2px;
  width: calc((100% - 4px) / var(--n, 1));
  inset-inline-start: calc(2px + (100% - 4px) / var(--n, 1) * var(--i, 0));
  border-radius: var(--radius-sm);
  background: var(--surface);
  box-shadow: 0 2px 6px rgba(0,0,0,.12);
  transition: inset-inline-start .32s var(--spring);
}
@media (prefers-color-scheme: dark) { #filter::before { background: #636366; } }
#filter button[aria-selected="true"] { background: none; box-shadow: none; }
#filter.no-anim::before { transition: none; }

/* ----- Sliding selection pill: tab bar ----- */
.tabbar { isolation: isolate; }
.tabbar::before {
  content: "";
  position: absolute; z-index: -1;
  top: 5px; bottom: 5px;
  width: calc((100% - 10px) / var(--n, 4));
  inset-inline-start: calc(5px + (100% - 10px) / var(--n, 4) * var(--i, 0));
  border-radius: 999px;
  background: var(--accent-soft);
  transition: inset-inline-start .36s var(--spring);
}
.tabbar.no-anim::before { transition: none; }
.tab[aria-current="page"] { background: none; }
.tab { transition: color .2s var(--ease-out), height .3s var(--ease-out), opacity .16s var(--ease-out); }

/* ----- Tab bar minimizes while scrolling down ----- */
.tabbar { transition: width .3s var(--ease-out), transform .3s var(--ease-out); }
.tab span { max-height: 14px; overflow: hidden; transition: opacity .2s var(--ease-out), max-height .3s var(--ease-out); }
.tabbar.mini { width: min(300px, calc(100% - 64px)); }
.tabbar.mini .tab { height: 44px; gap: 0; }
.tabbar.mini .tab span { opacity: 0; max-height: 0; }

/* ----- Large title fades into the compact bar as it scrolls away ----- */
@supports (animation-timeline: scroll()) {
  @media (prefers-reduced-motion: no-preference) and (max-width: 899px) {
    .page-head h1, .page-head .btn-round {
      animation: title-away linear both;
      animation-timeline: scroll(root);
      animation-range: 0 72px;
    }
    .page-head h1 { transform-origin: right center; }
  }
}
@keyframes title-away { to { opacity: 0; transform: scale(.94); } }

/* ----- Page switch: cross-fade with a slight rise; chrome stays put ----- */
.tabbar { view-transition-name: tabbar; }
.sidebar { view-transition-name: sidebar; }
::view-transition-old(tabbar), ::view-transition-old(sidebar) { display: none; }
::view-transition-new(tabbar), ::view-transition-new(sidebar) { animation: none; }
html[data-vt="tab"]::view-transition-old(root) { animation: vt-out .16s var(--ease-out) both; }
html[data-vt="tab"]::view-transition-new(root) { animation: vt-in .3s var(--ease-out) both; }
@keyframes vt-out { to { opacity: 0; } }
@keyframes vt-in { from { opacity: 0; transform: translateY(8px); } }

/* ----- List changes: rows morph to their new place ----- */
html[data-vt="list"] :is(.card, .group) { view-transition-name: var(--vtn); }
html[data-vt="list"]::view-transition-old(root) { display: none; }
html[data-vt="list"]::view-transition-new(root) { animation: none; }
html[data-vt="list"]::view-transition-group(*) { animation-duration: .32s; animation-timing-function: var(--ease-out); }
html[data-vt="list"]::view-transition-old(*):only-child { animation: vt-out .2s var(--ease-out) both; }
html[data-vt="list"]::view-transition-new(*):only-child { animation: vt-in .3s var(--ease-out) both; }

/* ----- Check pop ----- */
.check.pop { animation: pop .38s var(--spring); }
.check.pop svg { animation: draw .3s .06s var(--ease-out) both; }
@keyframes pop { 0% { transform: scale(.8); } 60% { transform: scale(1.12); } 100% { transform: scale(1); } }
@keyframes draw { from { opacity: 0; transform: scale(.4); } }

/* ----- Sheet slides back down ----- */
.sheet.closing { animation: sheet-down .24s cubic-bezier(.4, 0, 1, 1) forwards; }
.sheet.closing::backdrop { animation: fade-out .24s ease forwards; }
@keyframes sheet-down { to { transform: translateY(100%); } }
@keyframes fade-out { to { opacity: 0; } }
@media (min-width: 900px) {
  .sheet.closing { animation-name: sheet-shrink; animation-duration: .18s; }
  @keyframes sheet-shrink { to { transform: scale(.96); opacity: 0; } }
}

/* ----- First data load ----- */
.list.fade-in { animation: fade .3s var(--ease-out); }

/* ----- Toast: drop in with a little give ----- */
.toast { transition: opacity .2s var(--ease-out), transform .32s var(--spring); transform: translateY(-12px) scale(.96); }
.toast.show { transform: none; }

/* ----- Reduce Motion: everything above becomes instant ----- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after, ::view-transition-group(*), ::view-transition-old(*), ::view-transition-new(*) {
    animation-duration: .01ms !important;
    animation-delay: 0s !important;
    transition-duration: .01ms !important;
  }
}

/* ---------- Settings ---------- */
[hidden] { display: none !important; }
.side-bottom { margin-top: auto; padding-top: 8px; }
.side-bottom + .sync { margin-top: 8px; }
.settings-row {
  display: flex; align-items: center; gap: 12px;
  width: 100%; min-height: 60px;
  padding: 8px 16px;
  border: 0; background: none;
  text-align: start; font-size: 17px; line-height: 22px;
  color: var(--label);
  position: relative;
  cursor: pointer;
  transition: background .16s var(--ease-out);
}
.settings-row:active { background: var(--press); transition-duration: 0s; }
.settings-row:disabled { opacity: .5; }
.settings-row + .settings-row::before {
  content: ""; position: absolute; top: 0; inset-inline: 60px 0;
  border-top: 0.5px solid var(--separator);
}
.settings-icon {
  width: 32px; height: 32px; flex-shrink: 0;
  border-radius: var(--radius-sm);
  display: grid; place-items: center;
  background: var(--accent-fill); color: #fff;
}
.settings-icon.green { background: var(--green-fill); }
.settings-icon svg { width: 18px; height: 18px; }
.settings-text { flex: 1; min-width: 0; display: grid; gap: 2px; }
.settings-text small { font-size: 13px; line-height: 18px; color: var(--label-2); }
.settings-chev { width: 16px; height: 16px; color: var(--label-2); transform: rotate(90deg); } /* points "forward" in RTL */
.settings-row input[type="file"] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.settings-hint { margin-top: -16px; }
@media (hover: hover) and (pointer: fine) { .settings-row:hover { background: var(--fill); } }

/* ---------- Account (settings) ---------- */
.account-row {
  display: flex; align-items: center; gap: 12px;
  min-height: 72px; padding: 12px 16px;
}
.avatar {
  width: 48px; height: 48px; flex-shrink: 0;
  border-radius: 50%;
  object-fit: cover;
  display: grid; place-items: center;
  background: var(--accent-fill); color: #fff;
  font-size: 22px; font-weight: 600;
}
.account-row .settings-text { font-size: 17px; line-height: 22px; font-weight: 600; }
.account-row small { font-weight: 400; text-align: right; } /* LTR email, right-aligned under the Hebrew name */
.settings-row.sign-out { color: var(--red); justify-content: center; min-height: 48px; font-weight: 500; }
.account-row + .settings-row::before {
  content: ""; position: absolute; top: 0; inset-inline: 16px 0;
  border-top: 0.5px solid var(--separator);
}

/* ---------- Sign in with Apple (Apple's black/white button) + legal ---------- */
.apple-btn {
  width: 100%;
  min-height: 48px;
  padding: 0 16px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; border-radius: 999px;
  background: #000; color: #fff;
  font-size: 17px; font-weight: 600;
}
.apple-btn:disabled { opacity: .6; }
.apple-logo { width: 17px; height: 20px; }
@media (prefers-color-scheme: dark) { .apple-btn { background: #fff; color: #000; } }
.lock.checking .apple-btn, .lock.checking .auth-legal { visibility: hidden; }
.auth-legal { font-size: 13px !important; line-height: 18px; margin-top: 4px !important; }
.auth-legal a { color: var(--accent); }

a.settings-row { text-decoration: none; }
.settings-row:has(use[href="#i-external"]) .settings-chev { transform: none; width: 18px; height: 18px; }
.settings-row.danger-row { color: var(--red); justify-content: center; min-height: 48px; font-weight: 500; }
.copyright { margin-top: -12px; }
.support-email { text-align: right; } /* LTR address, right-aligned under the Hebrew label */

/* Done checklist rows: gray the label only, keep the white check legible on green */
.topic.done .check { color: #fff; }

/* iPad / wide layouts: keep the sidebar and page title clear of the status bar */
@media (min-width: 900px) {
  .sidebar { padding-top: calc(env(safe-area-inset-top, 0px) + 20px); }
  .main { padding-top: calc(env(safe-area-inset-top, 0px) + 28px); }
}

/* ---------- Custom pages ---------- */
.head-actions { display: flex; align-items: center; gap: 8px; }
.btn-round.ghost { background: var(--fill); color: var(--accent); box-shadow: none; }
.page-icon {
  width: 60px; flex-shrink: 0; align-self: stretch; min-height: 60px;
  display: grid; place-items: center;
  border-radius: var(--radius-md);
  background: var(--accent-soft); color: var(--accent);
}
.page-icon svg { width: 26px; height: 26px; }
.detail-head .page-icon { width: 72px; height: 72px; align-self: center; }
.detail-head .page-icon svg { width: 32px; height: 32px; }
.side-pages { margin-top: 18px; }
.side-heading { margin: 0 10px 6px; font-size: 13px; line-height: 18px; font-weight: 600; color: var(--label-2); }
.side-item.side-add, .side-item.side-add svg { color: var(--accent); }
.template-chips { flex-wrap: wrap; margin: 0 0 24px; }
.icon-picker { display: grid; grid-template-columns: repeat(auto-fill, 52px); justify-content: space-between; gap: 10px; margin-bottom: 24px; }
.icon-picker label { position: relative; cursor: pointer; }
.icon-picker input { position: absolute; opacity: 0; pointer-events: none; }
.icon-picker span {
  display: grid; place-items: center; width: 52px; height: 52px;
  border-radius: var(--radius-md); background: var(--surface); color: var(--label-2);
  transition: background .16s var(--ease-out), color .16s var(--ease-out);
}
@media (prefers-color-scheme: dark) { .icon-picker span { background: #2C2C2E; } }
.icon-picker input:checked + span { background: var(--accent-fill); color: #fff; }
.icon-picker input:focus-visible + span { outline: 3px solid var(--accent); }
.icon-picker svg { width: 22px; height: 22px; }
#checklist-label-field label { width: auto; }
.switch-row {
  display: flex; align-items: center; gap: 12px;
  min-height: 60px; padding: 8px 16px;
  position: relative; cursor: pointer;
}
.switch-row + .switch-row::before, .switch-row + .field::before {
  content: ""; position: absolute; top: 0; inset-inline: 16px 0; border-top: 0.5px solid var(--separator);
}
.switch-row + .field { position: relative; }
/* iOS-style switch on a native checkbox */
.switch-row input {
  appearance: none; -webkit-appearance: none; flex-shrink: 0;
  width: 51px; height: 31px; margin: 0; border-radius: 999px;
  background: var(--fill); position: relative; cursor: pointer;
  transition: background .2s var(--ease-out);
}
.switch-row input::after {
  content: ""; position: absolute; top: 2px; inset-inline-end: 2px;
  width: 27px; height: 27px; border-radius: 50%; background: #fff;
  box-shadow: 0 2px 6px rgba(0,0,0,.2);
  transition: inset-inline-end .22s var(--spring);
}
.switch-row input:checked { background: var(--green-fill); }
.switch-row input:checked::after { inset-inline-end: 22px; }
.switch-row input:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.line-row.plain { padding-inline-start: 16px; }
.line-row.plain + .line-row::before, .line-row.plain + .add-line::before { inset-inline-start: 16px; }
