:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-2: #efede7;
  --line: #e2dfd7;
  --text: #1d1f24;
  --muted: #6b6f78;
  --accent: #5b5bd6;
  --accent-soft: #e7e6fb;
  --good: #1f9d6b;
  --good-soft: #dcf3e9;
  --warn: #c2410c;
  --warn-soft: #fde8dc;
  --etsy: #f1641e;
  --ebay: #3665f3;
  --tcgplayer: #1b8a5a;
  --vaultrips: #a855f7;
  --radius: 16px;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.04), 0 4px 16px rgb(0 0 0 / 0.04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14161c;
    --surface: #1c1f27;
    --surface-2: #252935;
    --line: #2e3341;
    --text: #eceef3;
    --muted: #9aa0ad;
    --accent: #8b8cff;
    --accent-soft: #2a2b55;
    --good: #45d19b;
    --good-soft: #173a2e;
    --warn: #ff8a50;
    --warn-soft: #43261a;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 17px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 1.7rem; letter-spacing: -0.01em; }
h2 { font-size: 1.05rem; font-weight: 650; }

/* ---------- shell ---------- */
.shell { min-height: 100dvh; }
.view {
  max-width: 720px;
  margin: 0 auto;
  padding: calc(20px + env(safe-area-inset-top)) 16px calc(96px + env(safe-area-inset-bottom));
  outline: none;
}
.tabs {
  position: fixed; inset: auto 0 0 0; z-index: 10;
  display: flex; justify-content: space-around;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
.tabs a {
  position: relative; flex: 1; display: grid; justify-items: center; gap: 2px;
  padding: 6px 0; border-radius: 12px;
  color: var(--muted); text-decoration: none; font-size: 0.72rem; font-weight: 600;
}
.tabs a .ico { font-size: 1.3rem; filter: grayscale(1); opacity: 0.7; }
.tabs a.on { color: var(--text); }
.tabs a.on .ico { filter: none; opacity: 1; }
.badge {
  position: absolute; top: 2px; left: calc(50% + 6px);
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: #e5262b; color: #fff; font-size: 0.7rem; line-height: 18px; text-align: center;
}
@media (min-width: 900px) {
  .tabs {
    inset: 0 auto 0 0; width: 96px; flex-direction: column; justify-content: flex-start; gap: 4px;
    border-top: 0; border-right: 1px solid var(--line); padding: 24px 8px;
  }
  .tabs a { flex: 0; padding: 10px 0; }
  .view { padding-bottom: 48px; padding-left: 112px; max-width: 840px; }
}

/* ---------- building blocks ---------- */
.head { display: flex; align-items: end; justify-content: space-between; gap: 12px; margin-bottom: 20px; }
.head .sub { color: var(--muted); font-size: 0.95rem; margin-top: 4px; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; margin-bottom: 16px;
}
.card > h2 { margin-bottom: 12px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.empty { color: var(--muted); padding: 8px 0; }
.row { display: flex; align-items: center; gap: 10px; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 10px; }
.error { color: var(--warn); min-height: 1.4em; margin: 8px 0 0; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 0 14px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface-2); cursor: pointer; font-weight: 600;
  text-decoration: none; color: var(--text);
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--warn); }
.btn.big { min-height: 52px; font-size: 1.05rem; width: 100%; }
.btn.small { min-height: 32px; padding: 0 10px; font-size: 0.85rem; border-radius: 10px; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; border: 0; background: transparent;
  display: inline-grid; place-items: center; cursor: pointer; color: var(--muted); font-size: 1.15rem;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn.on { color: #f5a524; }

input[type="text"], input[type="password"], input[type="url"], input[type="date"], input[type="time"],
input[type="datetime-local"], select, textarea {
  width: 100%; min-height: 46px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--bg);
}
textarea { min-height: 80px; resize: vertical; }
input:focus-visible, select:focus-visible, textarea:focus-visible, .btn:focus-visible, .icon-btn:focus-visible, .tabs a:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.field { display: grid; gap: 6px; font-size: 0.9rem; font-weight: 600; color: var(--muted); }
.field input, .field select, .field textarea { color: var(--text); font-weight: 400; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px;
  padding: 6px 12px; font-size: 0.85rem; font-weight: 600; cursor: pointer; color: var(--text);
}
.chip.on { background: var(--accent-soft); border-color: var(--accent); }

/* ---------- tasks ---------- */
.task { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.task:first-child { border-top: 0; }
.task .title { font-weight: 550; overflow-wrap: anywhere; }
.task .meta { font-size: 0.8rem; color: var(--muted); display: flex; gap: 10px; flex-wrap: wrap; margin-top: 2px; }
.task .meta .late { color: var(--warn); font-weight: 650; }
.task.done .title { text-decoration: line-through; color: var(--muted); }
.check {
  flex: none; width: 30px; height: 30px; border-radius: 50%;
  border: 2px solid var(--muted); background: transparent; cursor: pointer;
  display: grid; place-items: center; color: transparent; font-size: 0.95rem; font-weight: 800;
}
.check:hover { border-color: var(--good); color: var(--good); }
.task.done .check, .check.done { background: var(--good); border-color: var(--good); color: #fff; }

.top3 .slot {
  display: flex; align-items: center; gap: 14px; padding: 14px; border-radius: 14px;
  background: var(--surface-2); margin-top: 10px; min-height: 64px;
}
.top3 .slot:first-of-type { margin-top: 0; }
.top3 .num { font-size: 1.4rem; font-weight: 800; color: var(--accent); width: 22px; text-align: center; }
.top3 .slot .title { font-size: 1.1rem; font-weight: 650; }
.top3 .slot.open input { background: transparent; border: 0; min-height: 36px; padding: 0; }
.top3 .slot.open input:focus-visible { outline: none; }
.top3 .check { width: 36px; height: 36px; }

.src {
  display: inline-block; font-size: 0.7rem; font-weight: 750; letter-spacing: 0.02em; text-transform: uppercase;
  padding: 2px 8px; border-radius: 6px; color: #fff; background: var(--muted);
}
.src.etsy { background: var(--etsy); }
.src.ebay { background: var(--ebay); }
.src.tcgplayer { background: var(--tcgplayer); }
.src.vaultrips { background: var(--vaultrips); }

/* ---------- inbox ---------- */
.note { display: flex; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); align-items: flex-start; }
.note:first-child { border-top: 0; }
.note .emoji { font-size: 1.4rem; line-height: 1; padding-top: 2px; }
.note.read { opacity: 0.55; }
.note .title { font-weight: 600; overflow-wrap: anywhere; }
.note pre { white-space: pre-wrap; font-size: 0.75rem; color: var(--muted); margin: 6px 0 0; max-height: 7em; overflow: auto; }
.note.alert .title { color: var(--warn); }

/* ---------- calendar ---------- */
.month-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.grid .dow { text-align: center; font-size: 0.72rem; font-weight: 700; color: var(--muted); padding: 4px 0; }
.day {
  aspect-ratio: 1 / 1; border-radius: 12px; border: 1px solid transparent; background: var(--surface-2);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  cursor: pointer; font-weight: 600; font-size: 0.95rem; padding: 0;
}
.day.other { opacity: 0.35; }
.day.today { border-color: var(--accent); color: var(--accent); }
.day.sel { background: var(--accent); color: #fff; }
.dots { display: flex; gap: 2px; height: 6px; }
.dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }
.day.sel .dots i { background: #fff !important; }
.event { display: flex; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); align-items: center; }
.event:first-child { border-top: 0; }
.event .bar { width: 4px; align-self: stretch; border-radius: 2px; background: var(--accent); }
.event .when { font-size: 0.8rem; color: var(--muted); }

/* ---------- login / sheet / toast ---------- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: min(360px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 20px;
  padding: 28px 22px; display: grid; gap: 16px; justify-items: center; box-shadow: var(--shadow);
}
.login-card .field { width: 100%; }

.sheet {
  width: min(520px, calc(100% - 16px)); max-height: 90dvh; border: 1px solid var(--line); border-radius: 20px;
  background: var(--surface); color: var(--text); padding: 20px; margin: auto;
}
.sheet::backdrop { background: rgb(0 0 0 / 0.45); }
.sheet form { display: grid; gap: 14px; }
.sheet .actions { display: flex; gap: 10px; justify-content: space-between; flex-wrap: wrap; }

.toast {
  position: fixed; left: 50%; bottom: calc(88px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: var(--text); color: var(--bg); padding: 12px 18px; border-radius: 14px; font-weight: 650;
  opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s; z-index: 50; max-width: calc(100% - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.bad { background: var(--warn); color: #fff; }

.pop { animation: pop 0.45s ease; }
@keyframes pop { 0% { transform: scale(1); } 40% { transform: scale(1.25); } 100% { transform: scale(1); } }
.burst { position: fixed; pointer-events: none; z-index: 60; font-size: 1.2rem; animation: burst 0.9s ease-out forwards; }
@keyframes burst { to { transform: translate(var(--dx), var(--dy)) rotate(var(--r)); opacity: 0; } }
@media (prefers-reduced-motion: reduce) {
  .pop, .burst { animation: none; }
  .burst { display: none; }
}
.mono { font-family: ui-monospace, Consolas, monospace; font-size: 0.8rem; overflow-wrap: anywhere; background: var(--surface-2); padding: 8px 10px; border-radius: 10px; }
.toggle { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.toggle input { width: 22px; height: 22px; accent-color: var(--accent); }

/* ---------- shop tiles with red count badges ---------- */
.shops { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 16px; }
.shop {
  display: grid; justify-items: center; gap: 4px; padding: 14px 4px 10px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); cursor: pointer; color: var(--text); min-width: 0;
}
.shop:hover { border-color: var(--muted); }
.shop.on { border-color: var(--accent); background: var(--accent-soft); }
.shop-icon {
  position: relative; width: 52px; height: 52px; border-radius: 14px;
  display: grid; place-items: center; color: #fff; font-weight: 800; font-size: 0.9rem; letter-spacing: -0.02em;
}
.shop-icon.etsy { background: var(--etsy); font-family: Georgia, serif; font-size: 1rem; }
.shop-icon.ebay { background: #fff; color: var(--ebay); border: 1px solid var(--line); font-size: 1rem; }
.shop-icon.tcgplayer { background: var(--tcgplayer); }
.shop-icon.vaultrips { background: linear-gradient(135deg, #a855f7, #6d28d9); }
.pip {
  position: absolute; top: -8px; right: -10px; min-width: 24px; height: 24px; padding: 0 6px;
  border-radius: 12px; background: #e5262b; color: #fff; font-size: 0.8rem; font-weight: 800; line-height: 24px;
  text-align: center; border: 2px solid var(--bg); font-family: system-ui, sans-serif; letter-spacing: 0;
  animation: pip-in 0.3s ease;
}
@keyframes pip-in { from { transform: scale(0.4); } to { transform: scale(1); } }
.shop-name { font-size: 0.8rem; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.shop-sub { font-size: 0.68rem; color: var(--muted); text-align: center; line-height: 1.25; }
.shop:has(.pip) .shop-sub { color: #e5262b; font-weight: 700; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .shop:has(.pip) .shop-sub { color: #ff6b6f; }
}

/* ---------- week strip ---------- */
.week { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; margin-bottom: 8px; }
.wday {
  display: grid; justify-items: center; gap: 2px; padding: 8px 0 6px; border-radius: 12px;
  border: 1px solid transparent; background: var(--surface-2); cursor: pointer; color: var(--text);
}
.wday .dow { font-size: 0.68rem; font-weight: 700; color: var(--muted); }
.wday .num { font-size: 1.05rem; font-weight: 700; }
.wday.today { border-color: var(--accent); }
.wday.sel { background: var(--accent); color: #fff; }
.wday.sel .dow { color: #fff; }
.wday.sel .dots i { background: #fff; }
.steps { margin: 0; padding-left: 20px; display: grid; gap: 4px; }
