:root {
  --bg: #f1efea; --card: #ffffff; --text: #1f1e1b; --text2: #6b6a64; --muted: #a09f98;
  --line: rgba(0,0,0,.09); --line2: rgba(0,0,0,.16);
  --accent: #2f6fd6; --accent-bg: #e6f1fb; --accent-fg: #0c447c;
  --buy: #e8a317; --buy-bg: #faeeda; --buy-fg: #854f0b;
  --ok: #3b8a2a; --danger: #c0392b; --switch-off: #d6d4cc;
  --violet-bg:#EEEDFE; --violet-fg:#3C3489; --violet:#7F77DD;
  --amber-bg:#FAEEDA;  --amber-fg:#633806;  --amber:#EF9F27;
  --teal-bg:#E1F5EE;   --teal-fg:#085041;   --teal:#1D9E75;
  --coral-bg:#FAECE7;  --coral-fg:#712B13;  --coral:#D85A30;
  --blue-bg:#E6F1FB;   --blue-fg:#0C447C;   --blue:#378ADD;
  --pink-bg:#FBEAF0;   --pink-fg:#72243E;   --pink:#D4537E;
  --green-bg:#EAF3DE;  --green-fg:#27500A;  --green:#639922;
  --gray-bg:#F1EFE8;   --gray-fg:#444441;   --gray:#888780;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1c1b; --card: #262624; --text: #ecebe6; --text2: #a9a8a1; --muted: #75746e;
    --line: rgba(255,255,255,.09); --line2: rgba(255,255,255,.18);
    --accent: #5b9cf0; --accent-bg: #0c447c; --accent-fg: #b5d4f4;
    --buy: #f0a92e; --buy-bg: #633806; --buy-fg: #fac775;
    --ok: #7cc35a; --danger: #ef6b5d; --switch-off: #4a4945;
    --violet-bg:#3C3489; --violet-fg:#CECBF6;
    --amber-bg:#633806;  --amber-fg:#FAC775;
    --teal-bg:#085041;   --teal-fg:#9FE1CB;
    --coral-bg:#712B13;  --coral-fg:#F5C4B3;
    --blue-bg:#0C447C;   --blue-fg:#B5D4F4;
    --pink-bg:#72243E;   --pink-fg:#F4C0D1;
    --green-bg:#27500A;  --green-fg:#C0DD97;
    --gray-bg:#444441;   --gray-fg:#D3D1C7;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
[hidden] { display: none !important; }
svg.i { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; vertical-align: middle; }

#app { max-width: 640px; margin: 0 auto; min-height: 100dvh; display: flex; flex-direction: column; }
#top { position: sticky; top: 0; z-index: 5; background: var(--bg); display: flex; align-items: center; gap: 6px;
  padding: calc(10px + env(safe-area-inset-top)) 12px 10px 16px; margin-bottom: 8px; }
#top h1 { font-size: 24px; font-weight: 600; margin: 0; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#top .hdr-r { display: flex; }
#top.colored { background: var(--cc); color: #2b2a27; border-radius: 0 0 22px 22px; padding-left: 8px; }
#top.colored .icon-btn { color: #2b2a27; }
#top.colored .icon-btn:hover { background: rgba(0,0,0,.07); }
#top.colored #syncBtn.ok { color: #2f7a22; }
#homeBtn { background: rgba(255,255,255,.55); }
.icon-btn { width: 40px; height: 40px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; color: var(--text2); }
.icon-btn:hover { background: var(--line); }
#syncBtn.ok { color: var(--ok); } #syncBtn.err { color: var(--muted); } #syncBtn.sync svg { animation: pulse 1s infinite alternate; }
@keyframes pulse { to { opacity: .35; } }
#view { flex: 1; padding: 0 16px 120px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.tile { border-radius: 20px; padding: 18px 10px 16px; min-height: 150px; display: flex; flex-direction: column;
  align-items: center; justify-content: center; text-align: center; gap: 4px; background: var(--card); color: var(--text);
  border: 1px solid var(--line); transition: transform .12s; }
.tile:active { transform: scale(.97); }
.tile .circ { width: 60px; height: 60px; border-radius: 50%; display: flex; align-items: center; justify-content: center; margin-bottom: 6px; }
.tile .circ svg.i { width: 30px; height: 30px; stroke-width: 1.9; }
.tile .tn { font-size: 16px; font-weight: 600; line-height: 1.25; overflow-wrap: anywhere; }
.tile .tc { font-size: 13px; color: var(--text2); }
.tile.add { background: transparent; border: 2px dashed var(--line2); color: var(--text2); }
.tile.add .circ { background: var(--line); color: var(--text2); }
.tile.add .tn { font-weight: 500; font-size: 15px; }
.tile.preview { min-height: 0; margin-top: 14px; padding: 14px; flex-direction: row; gap: 12px; justify-content: flex-start; }
.tile.preview .circ { width: 44px; height: 44px; margin: 0; }
.tile.preview .circ svg.i { width: 24px; height: 24px; }
.icons { display: grid; grid-template-columns: repeat(auto-fill, minmax(42px, 1fr)); gap: 6px; }
.icons button { aspect-ratio: 1; border-radius: 50%; display: flex; align-items: center; justify-content: center; border: 1px solid var(--line); }
.icons button.on { border-color: transparent; }
#title.editable { cursor: pointer; }
.tile { -webkit-touch-callout: none; user-select: none; }
.hico { display: inline-flex; vertical-align: -3px; margin-right: 8px; }
.hico svg.i { width: 24px; height: 24px; }
.swatches { display: grid; grid-template-columns: repeat(6, 1fr); gap: 10px; }
.swatches button { aspect-ratio: 1; border-radius: 14px; border: 3px solid transparent; display: flex; align-items: center; justify-content: center; color: #2b2a27; }
.swatches button.on { border-color: #2b2a27; }
.swatches svg.i { width: 20px; height: 20px; stroke-width: 3; }

#fab { position: fixed; z-index: 6; right: max(18px, calc(50vw - 302px)); bottom: calc(22px + env(safe-area-inset-bottom));
  width: 58px; height: 58px; border-radius: 50%; background: var(--text); color: var(--bg);
  display: flex; align-items: center; justify-content: center; box-shadow: 0 4px 14px rgba(0,0,0,.18); }
#fab svg.i { width: 28px; height: 28px; stroke-width: 2.2; }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 4px 0 10px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex-shrink: 0; font-size: 14px; padding: 6px 14px; border-radius: 999px; border: 1px solid var(--line2);
  color: var(--text2); background: var(--card); display: inline-flex; align-items: center; gap: 6px; }
.chip.on { background: var(--accent-bg); color: var(--accent-fg); border-color: transparent; }
.chip.pc { color: #2b2a27; border-color: transparent; }
.chip.pc.on { box-shadow: 0 0 0 2px #2b2a27 inset; background-image: none; }
.chip .n { font-size: 12px; opacity: .75; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex-shrink: 0; }

.search { width: 100%; height: 42px; border-radius: 12px; border: 1px solid var(--line2); background: var(--card);
  padding: 0 14px; margin: 0 0 10px; outline: none; }
.search:focus, .field:focus { border-color: var(--accent); }

.list { background: var(--card); border-radius: 14px; border: 1px solid var(--line); overflow: hidden; }
.list + .list, .sec + .list { margin-top: 6px; }
.row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-top: 1px solid var(--line); min-height: 52px; }
.row:first-child { border-top: 0; }
.row .main { flex: 1; min-width: 0; cursor: pointer; }
.row .t { overflow-wrap: anywhere; }
.row .sub { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row.done .t { text-decoration: line-through; color: var(--muted); }
.cb { width: 24px; height: 24px; border-radius: 7px; border: 1.8px solid var(--line2); flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; color: #fff; }
.cb svg.i { width: 16px; height: 16px; stroke-width: 3; }
.cb.on { background: var(--ok); border-color: var(--ok); }
.badge { font-size: 12px; padding: 2px 9px; border-radius: 999px; flex-shrink: 0; white-space: nowrap; }
.sec { font-size: 13px; color: var(--text2); margin: 18px 4px 6px; display: flex; align-items: center; justify-content: space-between; }
.sec button { color: var(--accent); font-size: 13px; }
.empty { text-align: center; color: var(--text2); padding: 40px 20px; }
.empty b { display: block; font-size: 17px; color: var(--text); margin-bottom: 4px; font-weight: 600; }

.sw { width: 46px; height: 28px; border-radius: 14px; background: var(--switch-off); position: relative; flex-shrink: 0; transition: background .15s; }
.sw::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%;
  background: #fff; transition: left .15s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.sw.buy { background: var(--buy); } .sw.buy::after { left: 21px; }
.st { font-size: 13px; color: var(--muted); width: 54px; text-align: right; flex-shrink: 0; }
.row.buy .st { color: var(--buy-fg); font-weight: 600; }
@media (prefers-color-scheme: dark) { .row.buy .st { color: var(--buy); } }
.counter { font-size: 13px; padding: 4px 12px; border-radius: 999px; background: var(--buy-bg); color: var(--buy-fg); }

.quick { display: flex; gap: 8px; margin-bottom: 10px; }
.quick input { flex: 1; }
.quick .search { margin: 0; }
.btn { height: 42px; padding: 0 16px; border-radius: 12px; border: 1px solid var(--line2); background: var(--card); font-weight: 500; white-space: nowrap; }
.btn.primary { background: var(--accent); color: #fff; border-color: transparent; }
.btn.danger { color: var(--danger); }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .5; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px; }
.card p { margin: 0 0 10px; color: var(--text2); font-size: 14px; }
.card .btns { display: flex; gap: 8px; flex-wrap: wrap; }
.kv { display: flex; justify-content: space-between; gap: 10px; font-size: 14px; margin-bottom: 10px; }
.kv span:last-child { color: var(--text2); text-align: right; }

#sheet { position: fixed; inset: 0; z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
#sheet .backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.4); }
#sheet .panel { position: relative; width: 100%; max-width: 640px; max-height: 92dvh; overflow-y: auto; background: var(--card);
  border-radius: 20px 20px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); animation: up .18s ease-out; }
@media (min-width: 700px) { #sheet { align-items: center; } #sheet .panel { border-radius: 20px; max-width: 520px; } }
@keyframes up { from { transform: translateY(30px); opacity: 0; } }
.panel h2 { font-size: 19px; margin: 0 0 14px; font-weight: 600; }
.panel label { display: block; font-size: 13px; color: var(--text2); margin: 12px 0 6px; }
.field { width: 100%; border-radius: 12px; border: 1px solid var(--line2); background: var(--bg); padding: 10px 12px; outline: none; }
textarea.field { min-height: 120px; resize: vertical; }
.panel .actions { display: flex; gap: 8px; margin-top: 18px; }
.panel .actions .btn.primary { flex: 1; }
.colors { display: flex; gap: 10px; flex-wrap: wrap; }
.colors button { width: 34px; height: 34px; border-radius: 50%; border: 3px solid transparent; }
.colors button.on { border-color: var(--text); }
.togglerow { display: flex; align-items: center; justify-content: space-between; margin-top: 14px; }
.linkbox { font-size: 13px; word-break: break-all; background: var(--bg); border-radius: 10px; padding: 10px; color: var(--text2); margin: 10px 0; user-select: all; }

#toast { position: fixed; z-index: 30; left: 50%; transform: translateX(-50%); bottom: calc(96px + env(safe-area-inset-bottom));
  background: #2b2a27; color: #fff; border-radius: 12px; padding: 10px 14px; display: flex; gap: 16px; align-items: center;
  font-size: 14px; max-width: calc(100vw - 32px); box-shadow: 0 4px 14px rgba(0,0,0,.25); }
#toast button { color: #8ab8ff; font-weight: 600; }
