:root {
  --bg: #eef2f0;
  --card: #ffffff;
  --text: #17312b;
  --accent: #0d6b57;
  --on-accent: #ffffff;
  --muted: color-mix(in srgb, var(--text) 72%, var(--bg));
  --line: color-mix(in srgb, var(--text) 16%, transparent);
  --danger: light-dark(#b3261e, #ff9d94);
  --ease: cubic-bezier(.2, .8, .2, 1);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font: 400 1rem/1.5 "Segoe UI Variable Text", "Segoe UI", system-ui, sans-serif;
  transition: background-color .4s, color .4s;
  accent-color: var(--accent);
}

h1, h2, h3, p, ul { margin: 0; }
h1 { font-size: 2rem; line-height: 1.15; font-weight: 700; letter-spacing: -.02em; overflow-wrap: anywhere; }
h2 { font-size: 1.125rem; font-weight: 650; }
h3 { font-size: .95rem; font-weight: 650; margin-top: 8px; }
ul { list-style: none; padding: 0; }
small { display: block; font-size: .85rem; color: var(--muted); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { opacity: .55; cursor: progress; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
#view:focus { outline: none; }
.icon { width: 22px; height: 22px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* Layout */
#view {
  max-width: 820px;
  margin: 0 auto;
  padding: 28px 16px calc(104px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 20px;
  view-transition-name: view;
}
#view > .tag, #view > .link, #view > .btn { align-self: flex-start; }
section { display: flex; flex-direction: column; gap: 12px; }

#nav {
  position: fixed;
  inset: auto 0 0 0;
  z-index: 5;
  display: flex;
  padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
  background: var(--card);
  border-top: 1px solid var(--line);
}
.brand { display: none; }
.tab {
  position: relative;
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 2px;
  border: 0;
  border-radius: 12px;
  background: none;
  color: var(--muted);
  font-size: .75rem;
}
.tab .icon { transition: transform .35s var(--ease); }
.tab[aria-current] { color: var(--text); background: color-mix(in srgb, var(--accent) 20%, transparent); font-weight: 650; }
.tab[aria-current] .icon { transform: translateY(-1px) scale(1.1); }
.badge { position: absolute; top: 4px; left: calc(50% + 6px); min-width: 18px; padding: 0 5px; border-radius: 9px; background: var(--accent); color: var(--on-accent); font-size: .7rem; line-height: 18px; text-align: center; }

@media (min-width: 860px) {
  #nav { inset: 0 auto 0 0; width: 216px; flex-direction: column; gap: 4px; padding: 28px 14px; border: 0; border-right: 1px solid var(--line); }
  .brand { display: block; padding: 0 12px 20px; font-size: 1.25rem; font-weight: 750; white-space: nowrap; letter-spacing: -.03em; }
  .tab { flex: none; flex-direction: row; gap: 12px; padding: 11px 12px; font-size: 1rem; }
  .badge { position: static; margin-left: auto; }
  #view { margin-left: max(216px, calc((100vw - 820px) / 2)); margin-right: auto; padding: 44px 32px 64px; }
}

.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; }
.page-head p { color: var(--muted); }
.actions, .row-btns { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* Pockets: square top, deep rounded bottom, stitched seam */
.pocket {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 24px 22px;
  background: var(--card);
  border: 0;
  border-radius: 8px 8px 28px 28px;
  box-shadow: 0 1px 2px rgb(0 0 0 / .06), 0 8px 24px rgb(0 0 0 / .05);
  transition: background-color .4s;
}
.pocket::after {
  content: "";
  position: absolute;
  inset: 7px;
  border: 1.5px dashed color-mix(in srgb, var(--c, var(--text)) 32%, transparent);
  border-top: 0;
  border-radius: 0 0 22px 22px;
  pointer-events: none;
}

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(220px, 100%), 1fr)); gap: 14px; }
.list-card { text-align: left; align-items: flex-start; gap: 10px; border-top: 5px solid var(--c); transition: transform .3s var(--ease), box-shadow .3s; }
.list-card:hover { transform: translateY(-3px); }
.list-card:active { transform: scale(.98); }
.list-title { font-size: 1.1rem; font-weight: 650; overflow-wrap: anywhere; }
.bar { width: 100%; height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; margin-top: auto; }
.bar i { display: block; height: 100%; background: var(--c); transform: scaleX(var(--p)); transform-origin: left; animation: grow .7s var(--ease); }

/* Rows */
.stack { display: flex; flex-direction: column; gap: 8px; }
.item {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 56px;
  padding: 6px 8px 6px 16px;
  background: var(--card);
  border-radius: 14px;
  animation: rise .35s var(--ease) backwards;
}
.item:nth-child(2) { animation-delay: .03s; }
.item:nth-child(3) { animation-delay: .06s; }
.item:nth-child(n+4) { animation-delay: .09s; }
.flat .item { padding-left: 0; min-height: 48px; }
.item label { flex: 1; min-width: 0; display: flex; align-items: center; gap: 14px; padding: 6px 0; cursor: pointer; }
.item label > span { min-width: 0; overflow-wrap: anywhere; background: linear-gradient(currentColor, currentColor) 0 .75em / 0 1.5px no-repeat; transition: background-size .28s var(--ease), opacity .28s; }
.item.done label > span { background-size: 100% 1.5px; opacity: .62; }
.item.late small { color: var(--danger); font-weight: 600; }
.grow { flex: 1; }
.feed > span { min-width: 0; padding: 8px 0; overflow-wrap: anywhere; font-weight: 600; }
.feed p { font-weight: 400; }
.item input[type=checkbox] { appearance: none; flex: none; width: 24px; height: 24px; margin: 0; border: 2px solid var(--muted); border-radius: 8px; display: grid; place-items: center; transition: background-color .2s, border-color .2s; cursor: pointer; }
.item input[type=checkbox]::after { content: ""; width: 6px; height: 11px; border: solid var(--on-accent); border-width: 0 2.5px 2.5px 0; transform: translateY(-1px) rotate(45deg) scale(0); transition: transform .28s var(--ease); }
.item input[type=checkbox]:checked { background: var(--accent); border-color: var(--accent); }
.item input[type=checkbox]:checked::after { transform: translateY(-1px) rotate(45deg) scale(1); }
.vault-row { flex: 1; min-width: 0; display: flex; align-items: center; gap: 14px; padding: 6px 0; border: 0; background: none; text-align: left; overflow-wrap: anywhere; }
.kind { font-size: 1.4rem; }

.tag { padding: 2px 10px; border-radius: 99px; font-size: .82rem; white-space: nowrap; background: color-mix(in srgb, var(--c) 22%, var(--card)); }
@media (max-width: 520px) { .reminder .tag { display: none; } }

/* Controls */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 46px;
  padding: 8px 18px;
  border: 1.5px solid transparent;
  border-radius: 14px;
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 600;
  transition: transform .2s var(--ease), filter .2s;
}
.btn:hover { filter: brightness(1.07); }
.btn:active { transform: scale(.96); }
.btn.ghost { background: none; color: var(--text); border-color: var(--line); }
.btn.danger { background: #b3261e; color: #fff; }
.btn.danger-ghost { background: none; color: var(--danger); border-color: var(--line); }
.btn.wide { width: 100%; }
.pocket > .btn:not(.wide) { align-self: flex-start; }
.icon-btn { display: grid; place-items: center; flex: none; width: 44px; height: 44px; border: 0; border-radius: 12px; background: none; color: var(--muted); }
.icon-btn:hover { background: var(--line); color: var(--text); }
.link { min-height: 32px; padding: 0 4px; border: 0; background: none; color: inherit; text-decoration: underline; text-underline-offset: 3px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; align-items: center; gap: 6px; min-height: 40px; padding: 4px 14px; border: 1.5px solid var(--line); border-radius: 99px; background: var(--card); transition: transform .2s var(--ease), background-color .2s; }
.chip:active { transform: scale(.94); }
.chip[aria-pressed=true] { background: color-mix(in srgb, var(--c, var(--accent)) 30%, var(--card)); border-color: var(--c, var(--accent)); font-weight: 600; }
.chip.plain { background: none; border-style: dashed; }
.chip .icon { width: 16px; height: 16px; }

input:not([type=checkbox], [type=color]), select, textarea {
  width: 100%;
  min-height: 46px;
  padding: 10px 14px;
  border: 1.5px solid color-mix(in srgb, var(--text) 30%, transparent);
  border-radius: 12px;
  background: color-mix(in srgb, var(--bg) 45%, var(--card));
}
select option { background: var(--card); color: var(--text); }
textarea { resize: vertical; }
input[type=color] { width: 100%; height: 46px; padding: 4px; border: 1.5px solid var(--line); border-radius: 12px; background: none; cursor: pointer; }
::placeholder { color: var(--muted); opacity: 1; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-weight: 600; font-size: .95rem; }
.hint { font-size: .88rem; color: var(--muted); }
.quiet { color: var(--muted); }
.form-error { color: var(--danger); font-weight: 600; }
.form-error:empty { display: none; }
.two { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.add-item { display: flex; gap: 8px; }
.add-item input { min-width: 0; }
.notice { flex-direction: row; flex-wrap: wrap; align-items: center; justify-content: space-between; }

.toggle { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 44px; cursor: pointer; }
.toggle input { appearance: none; position: relative; flex: none; width: 50px; height: 30px; margin: 0; border-radius: 15px; background: color-mix(in srgb, var(--text) 35%, var(--card)); transition: background-color .25s; cursor: pointer; }
.toggle input::after { content: ""; position: absolute; top: 4px; left: 4px; width: 22px; height: 22px; border-radius: 50%; background: var(--card); transition: transform .3s var(--ease); }
.toggle input:checked { background: var(--accent); }
.toggle input:checked::after { transform: translateX(20px); background: var(--on-accent); }

.themes { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 10px; }
.swatch { display: flex; flex-direction: column; gap: 6px; align-items: center; padding: 6px; border: 2px solid transparent; border-radius: 14px; background: none; font-size: .9rem; overflow-wrap: anywhere; }
.swatch[aria-pressed=true] { border-color: var(--accent); font-weight: 650; }
.swatch i { width: 100%; height: 52px; border-radius: 6px 6px 16px 16px; border: 1px solid var(--line); background: linear-gradient(90deg, var(--b) 0 35%, var(--k) 35% 60%, var(--t) 60% 78%, var(--a) 78%); }

.empty { display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 36px 0; color: var(--muted); text-align: center; }
.empty-pocket { width: 72px; height: 80px; border: 2px dashed var(--muted); border-top: 10px solid var(--line); border-radius: 4px 4px 34px 34px; }

/* Vault */
.vault-gate { width: 100%; max-width: 440px; align-self: center; overflow: hidden; }
.vault-form { display: flex; flex-direction: column; gap: 14px; }
.flap { display: grid; place-items: center; height: 92px; margin: -24px -22px 0; background: var(--accent); color: var(--on-accent); clip-path: polygon(0 0, 100% 0, 100% 45%, 50% 100%, 0 45%); transform-origin: top; transition: transform .45s var(--ease); }
.flap .icon { width: 30px; height: 30px; margin-bottom: 20px; }
.opening .flap { transform: perspective(500px) rotateX(-100deg); }
.opening .vault-form, .opening .finger { opacity: 0; transform: translateY(16px); transition: .35s; }
.shake { animation: shake .4s; }
.meter { display: flex; align-items: center; gap: 10px; min-height: 22px; font-size: .88rem; }
.meter i { flex: 1; height: 6px; border-radius: 3px; background: linear-gradient(var(--accent), var(--accent)) 0 / 8% no-repeat var(--line); transition: background-size .4s var(--ease); }
.meter[data-level="1"] i { background-size: 40%; }
.meter[data-level="2"] i { background-size: 70%; }
.meter[data-level="3"] i { background-size: 100%; }
.choices { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.choice { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 20px 10px; border: 1.5px solid var(--line); border-radius: 8px 8px 22px 22px; background: none; font-weight: 600; }
.choice span { font-size: 1.8rem; }
.secret-line { display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: 0 4px; border-bottom: 1px solid var(--line); padding-bottom: 6px; }
.secret-line small { grid-column: 1 / -1; }
.secret-value { overflow-wrap: anywhere; font-family: "Cascadia Mono", Consolas, monospace; }
.note-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.preview { max-width: 100%; border-radius: 12px; }

/* Dialogs and toasts */
.sheet { width: min(520px, 100%); max-width: 100%; max-height: 92dvh; margin: auto auto 0; padding: 0; border: 0; border-radius: 24px 24px 0 0; background: var(--card); color: var(--text); animation: sheet .38s var(--ease); }
.sheet::backdrop { background: rgb(0 0 0 / .5); animation: fade .3s; }
.sheet header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 12px 4px 22px; }
.sheet header h2 { font-size: 1.3rem; overflow-wrap: anywhere; }
.dialog-body { display: flex; flex-direction: column; align-items: stretch; gap: 14px; padding: 10px 22px; }
.dialog-body > .btn, .dialog-body > .tag { align-self: flex-start; }
.sheet footer { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 22px calc(20px + env(safe-area-inset-bottom)); }
@media (min-width: 600px) { .sheet { margin: auto; border-radius: 12px 12px 28px 28px; } }

#toasts { position: fixed; z-index: 10; left: 16px; right: 16px; bottom: calc(88px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.toast { display: flex; align-items: center; gap: 14px; max-width: 460px; padding: 12px 18px; border-radius: 14px; background: var(--text); color: var(--bg); box-shadow: 0 8px 24px rgb(0 0 0 / .25); animation: rise .3s var(--ease); pointer-events: auto; }
.toast button { border: 0; background: none; color: inherit; font-weight: 700; text-decoration: underline; }
.toast.leaving { opacity: 0; transform: translateY(8px); transition: .25s; }
@media (min-width: 860px) { #toasts { bottom: 28px; } }

@keyframes rise { from { opacity: 0; transform: translateY(10px); } }
@keyframes grow { from { transform: scaleX(0); } }
@keyframes sheet { from { opacity: 0; transform: translateY(60px); } }
@keyframes fade { from { opacity: 0; } }
@keyframes shake { 20%, 60% { transform: translateX(-7px); } 40%, 80% { transform: translateX(7px); } }
::view-transition-old(root), ::view-transition-new(root) { animation: none; }
::view-transition-old(view) { animation: fade .15s reverse both; }
::view-transition-new(view) { animation: rise .32s var(--ease) both; }

.still *, .still *::before, .still *::after { animation: none !important; transition: none !important; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
