/* ───────── Tokens ───────── */
:root {
  --bg: #F6F4F1;
  --surface: #FFFFFF;
  --surface-2: #EFECE7;
  --ink: #1C1A24;
  --ink-2: #4A4656;
  --muted: #8A8597;
  --line: rgba(28, 26, 36, 0.08);
  --accent: #7448E8;
  --accent-ink: #FFFFFF;
  --accent-soft: rgba(116, 72, 232, 0.10);
  --grad: linear-gradient(135deg, #4F46E5 0%, #9D5CE8 55%, #F59E8B 100%);
  --keep: #D9961A;
  --keep-soft: rgba(217, 150, 26, 0.12);
  --archive: #2F9E6E;
  --archive-soft: rgba(47, 158, 110, 0.12);
  --danger: #D9485F;
  --danger-soft: rgba(217, 72, 95, 0.10);
  --shadow: 0 1px 2px rgba(28, 26, 36, 0.04), 0 8px 24px -12px rgba(28, 26, 36, 0.18);
  --shadow-lg: 0 2px 4px rgba(28, 26, 36, 0.04), 0 24px 48px -20px rgba(60, 40, 120, 0.35);
  --radius: 20px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Inter, system-ui, sans-serif;
  --font-round: ui-rounded, "SF Pro Rounded", -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --tabbar-h: 58px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121118;
    --surface: #1C1A24;
    --surface-2: #26232F;
    --ink: #EDEBF3;
    --ink-2: #BDB8CA;
    --muted: #8C879A;
    --line: rgba(255, 255, 255, 0.07);
    --accent: #A98BFF;
    --accent-ink: #15121F;
    --accent-soft: rgba(169, 139, 255, 0.14);
    --keep: #F2B544;
    --keep-soft: rgba(242, 181, 68, 0.14);
    --archive: #4CC490;
    --archive-soft: rgba(76, 196, 144, 0.14);
    --danger: #FF6B81;
    --danger-soft: rgba(255, 107, 129, 0.12);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px -12px rgba(0, 0, 0, 0.6);
    --shadow-lg: 0 2px 4px rgba(0, 0, 0, 0.3), 0 24px 48px -20px rgba(0, 0, 0, 0.8);
    color-scheme: dark;
  }
}

/* ───────── Base ───────── */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font: 17px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
a { color: var(--accent); }
h1 { font: 700 28px/1.15 var(--font-round); letter-spacing: -0.02em; margin: 0; }
.muted { color: var(--muted); }
.sprite { position: absolute; }
.ico {
  width: 22px; height: 22px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}
#i-more circle { fill: currentColor; stroke: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 8px; }

/* ───────── Top bar ───────── */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(var(--safe-top) + 10px) 16px 10px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  -webkit-backdrop-filter: saturate(1.6) blur(18px);
  backdrop-filter: saturate(1.6) blur(18px);
}
.brand {
  display: inline-flex; align-items: center; gap: 10px;
  text-decoration: none; color: var(--ink);
  font: 700 21px/1 var(--font-round); letter-spacing: -0.02em;
}
.brand img { border-radius: 8px; box-shadow: 0 4px 12px -4px rgba(79, 70, 229, 0.5); }
.topbar-right { display: flex; align-items: center; gap: 6px; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center; color: var(--ink-2);
  transition: background 0.2s;
}
.icon-btn:active { background: var(--surface-2); }

.sync {
  font-size: 12.5px; font-weight: 500; color: var(--muted);
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px; background: var(--surface-2);
}
.sync::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--keep); }
.sync.offline::before { background: var(--muted); }

.menu { position: relative; }
.menu-pop {
  position: absolute; right: 0; top: 46px; min-width: 210px;
  background: var(--surface); border-radius: 16px; padding: 6px;
  box-shadow: var(--shadow-lg); border: 1px solid var(--line);
  animation: pop 0.18s var(--ease);
}
.menu-pop a, .menu-pop button {
  display: block; width: 100%; text-align: left; padding: 11px 12px; border-radius: 10px;
  color: var(--ink); text-decoration: none; font-size: 15.5px;
}
.menu-pop a:active, .menu-pop button:active { background: var(--surface-2); }
.menu-pop form { margin: 0; }
.menu-who { padding: 10px 12px 8px; font-size: 13px; color: var(--muted); border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.menu-who:empty { display: none; }

/* ───────── Layout ───────── */
main {
  max-width: 680px; margin: 0 auto;
  padding: 4px 16px calc(var(--tabbar-h) + var(--safe-bottom) + 32px);
}

/* ───────── Composer ───────── */
.composer {
  position: relative;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 18px 12px;
  margin: 8px 0 28px;
  transition: box-shadow 0.3s var(--ease), transform 0.3s var(--ease);
}
.composer::before {
  /* gradient hairline that wakes up on focus */
  content: ""; position: absolute; inset: 0; border-radius: inherit; padding: 1.5px;
  background: var(--grad);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor; mask-composite: exclude;
  opacity: 0; transition: opacity 0.3s var(--ease); pointer-events: none;
}
.composer:focus-within { box-shadow: var(--shadow-lg); }
.composer:focus-within::before { opacity: 1; }
.composer textarea {
  display: block; width: 100%;
  min-height: 28vh; max-height: 60vh;
  border: 0; outline: 0; resize: none; background: transparent; color: var(--ink);
  font: 18px/1.55 var(--font); padding: 0;
  caret-color: var(--accent);
}
.composer textarea::placeholder { color: var(--muted); opacity: 0.8; }
.composer-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin-top: 8px;
}
.hint { font-size: 12.5px; color: var(--muted); transition: color 0.2s; }
.hint.ready { color: var(--accent); }
.send {
  width: 38px; height: 38px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--grad); color: #fff;
  box-shadow: 0 6px 16px -6px rgba(124, 72, 232, 0.7);
  transition: transform 0.25s var(--ease), opacity 0.25s var(--ease);
}
.send .ico { stroke-width: 2.4; width: 20px; height: 20px; }
.send:disabled { opacity: 0; transform: scale(0.6); pointer-events: none; }
.send:active { transform: scale(0.92); }

/* ───────── Feed ───────── */
.feed { display: flex; flex-direction: column; }
.day {
  position: sticky; top: calc(var(--safe-top) + 60px); z-index: 5;
  align-self: flex-start;
  font: 600 12.5px/1 var(--font); letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--muted);
  padding: 7px 11px; margin: 18px 0 6px -4px; border-radius: 999px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
}
.day:first-child { margin-top: 0; }

.note {
  position: relative;
  display: grid; grid-template-columns: 52px 1fr; gap: 4px;
  padding: 14px 4px 14px 0;
  border-bottom: 1px solid var(--line);
  cursor: text;
  animation: enter 0.45s var(--ease) both;
}
.note:last-child { border-bottom: 0; }
.note time {
  font-size: 12.5px; color: var(--muted); padding-top: 3px;
  font-variant-numeric: tabular-nums;
}
.note .body {
  white-space: pre-wrap; overflow-wrap: anywhere; word-break: break-word;
  min-width: 0;
}
.note .body a { text-decoration: none; background: var(--accent-soft); border-radius: 5px; padding: 0 3px; }
.note .tag {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11.5px; font-weight: 600; letter-spacing: 0.02em;
  margin-top: 6px; padding: 2px 8px 2px 6px; border-radius: 999px;
}
.note .tag .ico { width: 13px; height: 13px; stroke-width: 2.2; }
.tag-kept { color: var(--keep); background: var(--keep-soft); }
.note.pending time::after {
  content: ""; display: inline-block; width: 6px; height: 6px; border-radius: 50%;
  background: var(--keep); margin-left: 6px; vertical-align: middle;
}

/* editing in place */
.note.editing { cursor: default; }
.note.editing .body { display: none; }
.note .edit { grid-column: 2; }
.note .edit textarea {
  width: 100%; border: 0; outline: 0; resize: none; padding: 10px 12px; margin: -4px 0 0 -12px;
  width: calc(100% + 12px);
  background: var(--surface); color: var(--ink); border-radius: 14px;
  font: inherit; line-height: 1.5; box-shadow: var(--shadow);
}
.note .tools { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0 2px -56px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 12px; border-radius: 999px;
  font-size: 14px; font-weight: 500; white-space: nowrap;
  background: var(--surface-2); color: var(--ink-2);
  transition: transform 0.15s var(--ease);
}
.chip .ico { width: 17px; height: 17px; }
.chip:active { transform: scale(0.95); }
.chip.keep { color: var(--keep); background: var(--keep-soft); }
.chip.archive { color: var(--archive); background: var(--archive-soft); }
.chip.delete { color: var(--danger); background: var(--danger-soft); }
.chip.done { margin-left: auto; background: var(--accent); color: var(--accent-ink); }

.empty {
  text-align: center; color: var(--muted); padding: 56px 24px;
}
.empty .glyph {
  width: 64px; height: 64px; margin: 0 auto 14px; border-radius: 20px;
  display: grid; place-items: center; background: var(--surface); box-shadow: var(--shadow);
  color: var(--accent);
}
.empty .glyph .ico { width: 28px; height: 28px; }
.empty strong { display: block; color: var(--ink); font: 600 18px/1.3 var(--font-round); margin-bottom: 4px; }

/* ───────── List views ───────── */
.list-head { display: flex; flex-direction: column; gap: 14px; margin: 10px 0 18px; }
.search {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface); border-radius: 14px; padding: 0 14px;
  box-shadow: var(--shadow); color: var(--muted);
}
.search .ico { width: 18px; height: 18px; }
.search input {
  flex: 1; border: 0; outline: 0; background: transparent; color: var(--ink);
  font: 16px var(--font); padding: 12px 0; -webkit-appearance: none; appearance: none;
}

/* ───────── Review ───────── */
.review { display: flex; flex-direction: column; }
.review-head { margin: 10px 0 18px; }
.review-head p { margin: 4px 0 12px; font-size: 15px; }
.bar { height: 5px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.bar-fill { height: 100%; width: 0; background: var(--grad); border-radius: inherit; transition: width 0.5s var(--ease); }

.review-stage { position: relative; display: grid; align-items: stretch; }
.card {
  grid-area: 1 / 1;
  min-height: 260px;
  background: var(--surface); border-radius: 26px; box-shadow: var(--shadow-lg);
  padding: 26px 24px 30px; display: flex; flex-direction: column; gap: 14px;
  touch-action: pan-y; user-select: none; -webkit-user-select: none;
  transition: transform 0.35s var(--ease), opacity 0.35s var(--ease);
  animation: card-in 0.4s var(--ease) both;
  max-height: 58vh; overflow: hidden;
}
.card.behind { transform: translateY(12px) scale(0.96); opacity: 0.6; animation: none; pointer-events: none; }
.card.dragging { transition: none; }
.card .when { font-size: 13.5px; color: var(--muted); display: flex; justify-content: space-between; gap: 12px; }
.card .when b { color: var(--ink-2); font-weight: 600; }
.card .text {
  flex: 1; overflow-y: auto; white-space: pre-wrap; overflow-wrap: anywhere;
  font: 21px/1.45 var(--font); letter-spacing: -0.01em;
  user-select: text; -webkit-user-select: text;
}
.card .text a { text-decoration: none; background: var(--accent-soft); border-radius: 6px; padding: 0 4px; }
.card .stamp {
  position: absolute; top: 22px; padding: 6px 12px; border-radius: 10px;
  font: 800 14px/1 var(--font-round); letter-spacing: 0.08em; text-transform: uppercase;
  border: 2px solid currentColor; opacity: 0; transition: opacity 0.1s;
}
.card .stamp.keep { left: 22px; color: var(--keep); transform: rotate(-8deg); }
.card .stamp.archive { right: 22px; color: var(--archive); transform: rotate(8deg); }

.review-actions {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-top: 22px;
}
.ra {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 14px 4px 12px; border-radius: 18px;
  font-size: 13px; font-weight: 600;
  background: var(--surface); box-shadow: var(--shadow);
  transition: transform 0.15s var(--ease);
}
.ra:active { transform: scale(0.94); }
.ra .ico { width: 24px; height: 24px; }
.ra-delete { color: var(--danger); }
.ra-archive { color: var(--archive); }
.ra-keep { color: var(--keep); }
.ra-skip { color: var(--ink-2); }
.review-tip { text-align: center; font-size: 13px; margin: 14px 0 0; }

/* ───────── Tab bar ───────── */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(4, 1fr);
  padding: 6px max(8px, env(safe-area-inset-left)) calc(var(--safe-bottom) + 6px) max(8px, env(safe-area-inset-right));
  background: color-mix(in srgb, var(--bg) 80%, transparent);
  -webkit-backdrop-filter: saturate(1.6) blur(20px);
  backdrop-filter: saturate(1.6) blur(20px);
  border-top: 1px solid var(--line);
}
.tab {
  position: relative;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 6px 0 4px; color: var(--muted);
  font-size: 11px; font-weight: 600; letter-spacing: 0.01em;
  transition: color 0.2s;
}
.tab .ico { width: 25px; height: 25px; transition: transform 0.25s var(--ease); }
.tab[aria-current="page"] { color: var(--accent); }
.tab[aria-current="page"] .ico { transform: translateY(-1px) scale(1.06); }
.badge {
  position: absolute; top: 1px; left: calc(50% + 7px);
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px;
  background: var(--grad); color: #fff;
  font: 700 11px/18px var(--font); text-align: center;
  box-shadow: 0 0 0 2px var(--bg);
}

/* Hide tab bar while typing on phones so the keyboard has room */
body.typing .tabbar { transform: translateY(110%); }
.tabbar { transition: transform 0.3s var(--ease); }

/* ───────── Toast ───────── */
.toast {
  position: fixed; left: 50%; z-index: 40;
  bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 16px);
  transform: translateX(-50%);
  display: flex; align-items: center; gap: 16px;
  padding: 10px 10px 10px 18px; border-radius: 999px;
  background: var(--ink); color: var(--bg);
  font-size: 14.5px; font-weight: 500;
  box-shadow: var(--shadow-lg);
  animation: toast-in 0.35s var(--ease);
  max-width: calc(100vw - 32px);
}
.toast button {
  padding: 7px 14px; border-radius: 999px; font-weight: 600; font-size: 14px;
  background: color-mix(in srgb, var(--bg) 18%, transparent); color: var(--bg);
}

/* ───────── Motion ───────── */
@keyframes enter { from { opacity: 0; transform: translateY(-8px); } }
@keyframes card-in { from { opacity: 0; transform: translateY(18px) scale(0.97); } }
@keyframes pop { from { opacity: 0; transform: translateY(-6px) scale(0.97); } }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 12px); } }
.note.leaving { animation: leave 0.3s var(--ease) forwards; }
@keyframes leave { to { opacity: 0; transform: translateX(24px); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

@media (min-width: 720px) {
  main { padding-top: 16px; }
  .composer textarea { min-height: 22vh; }
}
