  :root {
    box-sizing: border-box;
    padding-top: env(safe-area-inset-top, 0px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
    --font-sans: "Figtree", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    --font-display: "Fraunces", Georgia, "Times New Roman", serif;
    --bg: #f0f1f4;
    --surface: #ffffff;
    --ink: #22252c;
    --muted: #797e8a;
    --line: #e5e7ee;
    --line-strong: #d7dae3;
    --accent: #2f6bed;
    --accent-soft: #e9effc;
    --accent-ink: #ffffff;
    --done: #1f9d55;
    --danger: #d6453f;
    --amber: #d98a1a;
    --shadow: 0 1px 2px rgba(28, 30, 40, .05), 0 8px 24px rgba(28, 30, 40, .06);
    --sheet-shadow: 0 -10px 40px rgba(10, 12, 20, .28);
  }
  html { scroll-padding-top: env(safe-area-inset-top, 0px); }
  @media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
      --bg: #15171c; --surface: #1f222a; --ink: #e9ebef; --muted: #8a8f9b;
      --line: #2b2f38; --line-strong: #3a3f4a; --accent: #6fa2ff; --accent-soft: #16233f;
      --accent-ink: #0d1a33; --done: #3cba6d; --danger: #e5645f; --amber: #e0a13c;
      --shadow: 0 1px 2px rgba(0,0,0,.3), 0 10px 30px rgba(0,0,0,.35);
      --sheet-shadow: 0 -10px 40px rgba(0,0,0,.5);
    }
  }
  :root[data-theme="dark"] {
    --bg: #15171c; --surface: #1f222a; --ink: #e9ebef; --muted: #8a8f9b;
    --line: #2b2f38; --line-strong: #3a3f4a; --accent: #6fa2ff; --accent-soft: #16233f;
    --accent-ink: #0d1a33; --done: #3cba6d; --danger: #e5645f; --amber: #e0a13c;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 10px 30px rgba(0,0,0,.35);
    --sheet-shadow: 0 -10px 40px rgba(0,0,0,.5);
  }
  * { box-sizing: border-box; }
  body {
    margin: 0; background: var(--bg); color: var(--ink);
    font-family: var(--font-sans);
    -webkit-font-smoothing: antialiased; line-height: 1.5; min-height: 100%;
  }
  .app { max-width: 560px; margin: 0 auto; padding: clamp(20px,6vw,48px) clamp(16px,5vw,28px) 72px; }
  .app[hidden] { display: none; }

  /* pantalla de acceso */
  .gate { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 24px; background: var(--bg); }
  .gate[hidden] { display: none; }
  .gate-card { width: 100%; max-width: 340px; background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 28px 24px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 12px; text-align: center; }
  .gate-title { font-family: var(--font-display); font-weight: 600; font-size: 2.1rem; margin: 0; letter-spacing: -.01em; line-height: 1; }
  .gate-sub { color: var(--muted); font-size: .9rem; margin: 0 0 6px; }
  .gate-input { width: 100%; border: 1px solid var(--line-strong); background: transparent; color: var(--ink); font: inherit; font-size: 1rem; padding: 12px 14px; border-radius: 12px; outline: none; text-align: center; transition: border-color .15s, box-shadow .15s; }
  .gate-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
  .gate-input::placeholder { color: var(--muted); }
  .gate-btn { border: 0; background: var(--accent); color: var(--accent-ink); font-family: var(--font-sans); font-weight: 600; font-size: 1rem; padding: 12px 18px; border-radius: 12px; cursor: pointer; transition: filter .15s, transform .1s; }
  .gate-btn:hover { filter: brightness(1.06); }
  .gate-btn:active { transform: scale(.98); }
  .gate-btn:disabled { opacity: .6; cursor: default; }
  .gate-msg { min-height: 1.2em; margin: 4px 0 0; font-size: .85rem; color: var(--muted); line-height: 1.4; }
  .gate-msg.err { color: var(--danger); }
  .gate-msg.ok { color: var(--done); }

  header { margin-bottom: 20px; }
  .title-row { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
  h1 { font-family: var(--font-display); font-weight: 600; font-size: clamp(2.1rem,9vw,2.9rem); letter-spacing: -.01em; margin: 0; line-height: 1; }
  .meta { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 12px; }
  .count { color: var(--muted); font-size: .9rem; }
  .sync { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: .78rem; white-space: nowrap; }
  .sync::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
  .sync[data-state="connecting"] { color: var(--amber); }
  .sync[data-state="connecting"]::before { background: var(--amber); animation: pulse 1.2s ease-in-out infinite; }
  .sync[data-state="synced"] { color: var(--done); }
  .sync[data-state="synced"]::before { background: var(--done); }
  .sync[data-state="local"]::before { background: var(--line-strong); }
  .sync[data-state="offline"] { color: var(--amber); }
  .sync[data-state="offline"]::before { background: var(--amber); }
  @keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .3; } }

  .theme-btn { flex: none; width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface); color: var(--ink); cursor: pointer; font-size: 1.05rem; display: grid; place-items: center; transition: border-color .15s, transform .1s; }
  .theme-btn:hover { border-color: var(--line-strong); }
  .theme-btn:active { transform: scale(.94); }

  /* menú de la cabecera */
  .menu-wrap { position: relative; flex: none; }
  .menu-btn { width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface); color: var(--ink); cursor: pointer; font-size: 1.35rem; line-height: 1; display: grid; place-items: center; transition: border-color .15s, transform .1s; }
  .menu-btn:hover { border-color: var(--line-strong); }
  .menu-btn:active { transform: scale(.94); }
  .menu { position: absolute; top: calc(100% + 8px); right: 0; z-index: 50; min-width: 184px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); padding: 6px; display: flex; flex-direction: column; gap: 2px; animation: in .14s ease; }
  .menu[hidden] { display: none; }
  .menu-item { text-align: left; border: 0; background: transparent; color: var(--ink); font-family: var(--font-sans); font-weight: 500; font-size: .92rem; padding: 10px 12px; border-radius: 9px; cursor: pointer; transition: background .12s; }
  .menu-item:hover { background: var(--accent-soft); }
  .menu-item.danger { color: var(--danger); }

  /* desplegable de etiquetas en el añadir rápido */
  .qa-chip.open { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
  .qa-tagmenu { margin-top: 10px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 6px; display: flex; flex-direction: column; gap: 2px; box-shadow: var(--shadow); animation: in .14s ease; }
  .qa-tagempty { color: var(--muted); font-size: .82rem; padding: 8px 10px; }
  .qa-tagitem { display: flex; align-items: center; gap: 9px; text-align: left; border: 0; background: transparent; color: var(--ink); font-family: var(--font-sans); font-weight: 500; font-size: .9rem; padding: 9px 10px; border-radius: 9px; cursor: pointer; transition: background .12s; }
  .qa-tagitem:hover { background: var(--accent-soft); }
  .qa-tagitem .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
  .qa-tagname { flex: 1; min-width: 0; }
  .qa-tagitem.on { color: var(--accent); font-weight: 600; }
  .qa-tagcheck { color: var(--accent); font-weight: 700; width: 14px; text-align: center; flex: none; }
  .qa-tagcreate { text-align: left; border: 0; border-top: 1px solid var(--line); margin-top: 4px; background: transparent; color: var(--accent); font-family: var(--font-sans); font-weight: 600; font-size: .88rem; padding: 10px; cursor: pointer; border-radius: 0 0 8px 8px; }
  .qa-tagcreate:hover { background: var(--accent-soft); }

  .addbox { position: relative; }
  .add { display: flex; gap: 8px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 7px 7px 7px 8px; box-shadow: var(--shadow); transition: border-color .15s, box-shadow .15s; }
  .add:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
  .add input { flex: 1; border: 0; background: transparent; color: var(--ink); font: inherit; font-size: 1rem; padding: 10px 6px; outline: none; min-width: 0; }
  .add input::placeholder { color: var(--muted); }
  .add button { flex: none; border: 0; background: var(--accent); color: var(--accent-ink); font-family: var(--font-sans); font-weight: 600; font-size: 1rem; padding: 0 20px; border-radius: 11px; cursor: pointer; transition: filter .15s, transform .1s; }
  .add button:hover { filter: brightness(1.06); }
  .add button:active { transform: scale(.97); }

  .qa { margin-top: 8px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 11px 12px; box-shadow: var(--shadow); animation: in .16s ease; }
  .qa[hidden] { display: none; }
  .qa-row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
  .qa-hint { color: var(--muted); font-size: .78rem; margin-right: 2px; }
  .qa-chip { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line-strong); background: transparent; color: var(--ink); font-family: var(--font-sans); font-weight: 600; font-size: .82rem; padding: 6px 11px; border-radius: 999px; cursor: pointer; white-space: nowrap; }
  .qa-chip .dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
  .qa-chip.sel { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
  .qa-chip.manage-lite { border-style: dashed; color: var(--muted); }
  .qa-cal { margin-top: 10px; }

  /* tag filter bar */
  .tagbar { display: flex; gap: 6px; margin: 18px 0 4px; overflow-x: auto; padding-bottom: 4px; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  .tagbar::-webkit-scrollbar { display: none; }
  .tagchip { flex: none; display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line-strong); background: transparent; color: var(--muted); font-family: var(--font-sans); font-weight: 600; font-size: .82rem; padding: 5px 12px; border-radius: 999px; cursor: pointer; white-space: nowrap; transition: background .15s, color .15s, border-color .15s; }
  .tagchip:hover { color: var(--ink); }
  .tagchip[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
  .tagchip .dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
  .tagchip.manage { color: var(--muted); border-style: dashed; }

  .group { margin-top: 22px; }
  .group-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 2px; }
  .group-title { font-family: var(--font-display); font-weight: 600; font-size: 1.15rem; color: var(--ink); margin: 0; letter-spacing: -.01em; }
  .group.overdue .group-title { color: var(--danger); }
  .group-count { font-size: .82rem; color: var(--muted); }
  .toggle-btn { border: 0; background: transparent; color: var(--accent); font-family: var(--font-sans); font-weight: 600; font-size: .88rem; cursor: pointer; padding: 8px 0; }

  ul { list-style: none; margin: 0; padding: 0; }
  .task { display: flex; align-items: flex-start; gap: 11px; padding: 12px 2px; border-bottom: 1px solid var(--line); }
  .task:last-child { border-bottom: 0; }
  .check { flex: none; width: 22px; height: 22px; margin-top: 1px; border: 2px solid var(--line-strong); border-radius: 7px; background: transparent; cursor: pointer; display: grid; place-items: center; padding: 0; transition: border-color .15s, background .15s; }
  .check:hover { border-color: var(--accent); }
  .check svg { width: 13px; height: 13px; stroke: #fff; stroke-width: 3; fill: none; opacity: 0; transform: scale(.5); transition: opacity .15s, transform .18s cubic-bezier(.3,1.5,.5,1); }
  .task.done .check { background: var(--done); border-color: var(--done); }
  .task.done .check svg { opacity: 1; transform: scale(1); }
  .body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; cursor: pointer; }
  .label { font-size: 1rem; word-break: break-word; line-height: 1.4; }
  .task.prio .label { font-weight: 700; }
  .task.done .label { color: var(--muted); text-decoration: line-through; text-decoration-color: var(--line-strong); }
  .metarow { display: flex; align-items: center; flex-wrap: wrap; gap: 7px; }
  .pill { font-family: var(--font-sans); font-weight: 600; font-size: .74rem; color: var(--muted); padding: 2px 8px; border: 1px solid var(--line-strong); border-radius: 999px; white-space: nowrap; }
  .pill.overdue { color: #fff; background: var(--danger); border-color: var(--danger); }
  .pill.today { color: var(--accent); border-color: var(--accent); }
  .rep { font-size: .74rem; color: var(--muted); white-space: nowrap; }
  .rowtag { display: inline-flex; align-items: center; gap: 5px; font-size: .74rem; color: var(--muted); }
  .rowtag .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
  .note-ic { display: inline-flex; align-items: center; color: var(--muted); }
  .note-ic svg { width: 13px; height: 13px; }
  .star { flex: none; border: 0; background: transparent; color: var(--line-strong); font-size: 1.1rem; line-height: 1; width: 30px; height: 30px; border-radius: 8px; cursor: pointer; transition: color .15s; }
  .star.on { color: var(--accent); }
  .del { flex: none; border: 0; background: transparent; color: var(--muted); font-size: 1.3rem; line-height: 1; width: 28px; height: 30px; border-radius: 8px; cursor: pointer; opacity: 0; transition: opacity .15s, background .15s, color .15s; }
  .task:hover .del, .task:focus-within .del { opacity: 1; }
  .del:hover { background: var(--danger); color: #fff; }
  @media (hover: none) { .del { opacity: .5; } }

  .empty { text-align: center; color: var(--muted); padding: 40px 20px; font-size: 1rem; }

  footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 24px; padding-top: 16px; border-top: 1px solid var(--line); color: var(--muted); font-size: .88rem; }
  footer[hidden] { display: none; }
  .clear { border: 0; background: transparent; color: var(--muted); font-family: var(--font-sans); font-weight: 600; cursor: pointer; padding: 4px 2px; border-radius: 6px; transition: color .15s; }
  .clear:hover { color: var(--danger); }
  .clear:disabled { opacity: .4; cursor: default; }

  .overlay { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; justify-content: center; background: rgba(10,12,18,.5); }
  .overlay[hidden] { display: none; }
  .sheet { background: var(--bg); width: 100%; max-width: 560px; max-height: 92vh; overflow: auto; border-radius: 20px 20px 0 0; padding: 16px 18px calc(26px + env(safe-area-inset-bottom, 0px)); box-shadow: var(--sheet-shadow); }
  @media (min-width: 600px) { .overlay { align-items: center; } .sheet { border-radius: 20px; max-height: 88vh; } }
  .sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; position: sticky; top: 0; background: var(--bg); padding: 4px 0 8px; }
  .sheet-head h2 { font-family: var(--font-display); font-size: 1.2rem; font-weight: 600; margin: 0; }
  .icon-btn { border: 0; background: transparent; color: var(--muted); font-family: var(--font-sans); font-weight: 600; font-size: .95rem; cursor: pointer; padding: 6px 8px; border-radius: 8px; }
  .icon-btn:hover { color: var(--ink); background: var(--line); }
  .icon-btn.danger:hover { color: #fff; background: var(--danger); }

  .field { margin-bottom: 18px; }
  .field > .flabel { font-family: var(--font-sans); font-weight: 600; font-size: .8rem; color: var(--muted); margin-bottom: 8px; }
  .title-input { width: 100%; font-family: var(--font-sans); font-size: 1.1rem; font-weight: 500; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; outline: none; }
  .title-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
  .notes-input { width: 100%; min-height: 92px; resize: vertical; font-family: var(--font-sans); font-size: .95rem; line-height: 1.5; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; outline: none; }
  .notes-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
  .note-links { margin-top: 8px; display: flex; flex-direction: column; gap: 4px; }
  .note-links a { color: var(--accent); font-size: .85rem; word-break: break-all; text-decoration: none; }
  .note-links a:hover { text-decoration: underline; }

  .opt-row { display: flex; flex-wrap: wrap; gap: 6px; }
  .opt { border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink); font-family: var(--font-sans); font-weight: 600; font-size: .85rem; padding: 8px 13px; border-radius: 10px; cursor: pointer; transition: background .15s, color .15s, border-color .15s; }
  .opt:hover { border-color: var(--accent); }
  .opt.sel { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

  .prio-toggle { display: flex; align-items: center; gap: 10px; width: 100%; border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 12px 14px; cursor: pointer; font-family: var(--font-sans); font-weight: 600; color: var(--ink); }
  .prio-toggle .pstar { font-size: 1.2rem; color: var(--line-strong); }
  .prio-toggle.on { border-color: var(--accent); background: var(--accent-soft); }
  .prio-toggle.on .pstar { color: var(--accent); }
  .prio-toggle .state { margin-left: auto; color: var(--muted); font-size: .85rem; }

  .custom-rep { display: flex; align-items: center; gap: 8px; margin-top: 8px; font-size: .9rem; color: var(--muted); }
  .custom-rep input { width: 60px; font: inherit; font-family: var(--font-sans); font-size: .95rem; color: var(--ink); background: var(--surface); border: 1px solid var(--line-strong); border-radius: 9px; padding: 7px 9px; outline: none; text-align: center; }
  .custom-rep select { font-family: var(--font-sans); font-size: .95rem; color: var(--ink); background: var(--surface); border: 1px solid var(--line-strong); border-radius: 9px; padding: 7px 9px; outline: none; }

  .cal { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 12px; margin-top: 10px; }
  .cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
  .cal-title { font-family: var(--font-display); font-weight: 600; font-size: 1.02rem; text-transform: capitalize; }
  .cal-nav { border: 0; background: transparent; color: var(--ink); font-size: 1.3rem; width: 34px; height: 34px; border-radius: 8px; cursor: pointer; }
  .cal-nav:hover { background: var(--line); }
  .cal-grid { display: grid; grid-template-columns: repeat(7,1fr); gap: 2px; }
  .cal-dow { font-family: var(--font-sans); font-size: .72rem; color: var(--muted); text-align: center; padding: 4px 0; font-weight: 600; }
  .cal-day { font-family: var(--font-sans); font-weight: 500; font-size: .9rem; aspect-ratio: 1; border: 0; background: transparent; color: var(--ink); border-radius: 9px; cursor: pointer; display: grid; place-items: center; }
  .cal-day:hover { background: var(--line); }
  .cal-day.other { color: var(--line-strong); }
  .cal-day.today { box-shadow: inset 0 0 0 1.5px var(--accent); color: var(--accent); }
  .cal-day.sel { background: var(--accent); color: var(--accent-ink); }
  .cal-foot { display: flex; justify-content: space-between; margin-top: 8px; }
  .cal-foot button { border: 0; background: transparent; font-family: var(--font-sans); font-weight: 600; font-size: .85rem; cursor: pointer; padding: 6px 8px; border-radius: 8px; }
  .cal-foot .cal-today { color: var(--accent); }
  .cal-foot .cal-clear { color: var(--muted); }
  .cal-foot .cal-clear:hover { color: var(--danger); }
  .date-display { display: flex; align-items: center; justify-content: space-between; width: 100%; border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 12px 14px; cursor: pointer; font-family: var(--font-sans); font-weight: 600; color: var(--ink); }
  .date-display .muted { color: var(--muted); font-weight: 600; }

  .etq-list { display: flex; flex-wrap: wrap; gap: 6px; }
  .etq { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line-strong); background: var(--surface); font-family: var(--font-sans); font-weight: 600; font-size: .84rem; color: var(--ink); padding: 6px 11px; border-radius: 999px; cursor: pointer; }
  .etq .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
  .etq.on { border-color: transparent; }
  .link-btn { border: 0; background: transparent; color: var(--accent); font-family: var(--font-sans); font-weight: 600; font-size: .85rem; cursor: pointer; padding: 8px 0; }

  .tag-row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
  .tag-swatch { width: 26px; height: 26px; border-radius: 8px; border: 1px solid rgba(0,0,0,.12); cursor: pointer; flex: none; }
  .tag-name { flex: 1; min-width: 0; font-family: var(--font-sans); font-weight: 600; font-size: .95rem; color: var(--ink); background: transparent; border: 0; border-bottom: 1px solid transparent; padding: 4px 2px; outline: none; }
  .tag-name:focus { border-bottom-color: var(--accent); }
  .palette { display: flex; flex-wrap: wrap; gap: 8px; padding: 10px 0; }
  .swatch { width: 26px; height: 26px; border-radius: 8px; cursor: pointer; border: 2px solid transparent; }
  .swatch.sel { border-color: var(--ink); }
  .new-tag { display: flex; align-items: center; gap: 8px; margin-top: 12px; }
  .new-tag input { flex: 1; min-width: 0; font-family: var(--font-sans); font-size: .95rem; color: var(--ink); background: var(--surface); border: 1px solid var(--line-strong); border-radius: 10px; padding: 9px 11px; outline: none; }
  .new-tag button { border: 0; background: var(--accent); color: var(--accent-ink); font-family: var(--font-sans); font-weight: 600; padding: 9px 15px; border-radius: 10px; cursor: pointer; }

  @keyframes in { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
  .task.new { animation: in .18s ease; }
  @media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* Estado de inicio de sesión (solo versión alojada con backend propio) */
.sync[data-state="signin"] { color: var(--accent); cursor: pointer; }
.sync[data-state="signin"]::before { background: var(--accent); }
