:root {
  --bg: #0e0e11;
  --card: #18181d;
  --card2: #23232a;
  --text: #f3f3f6;
  --muted: #8d8d99;
  --line: #2c2c35;
  --radius: 18px;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", Inter, "Segoe UI", Roboto, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}
html:has(dialog[open]) { overflow: hidden; }
body { min-height: 100dvh; overscroll-behavior-y: none; }
button { font: inherit; color: inherit; cursor: pointer; }
svg { display: block; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 8px) 12px 8px;
  background: rgba(14, 14, 17, .82);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
}
.topbar h1 { margin: 0; font-size: 18px; font-weight: 700; letter-spacing: -.01em; }

.icon-btn {
  width: 40px; height: 40px; border: 0; border-radius: 12px;
  background: transparent; display: grid; place-items: center;
}
.icon-btn:active { background: var(--card2); }
.icon-btn svg { width: 22px; height: 22px; }

/* ---------- List ---------- */
main {
  max-width: 640px; margin: 0 auto;
  padding: 6px 16px calc(env(safe-area-inset-bottom) + 28px);
  display: flex; flex-direction: column; gap: 12px;
}
.section { margin: 18px 4px 0; font-size: 13px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .06em; }

.card {
  background: var(--card); border-radius: var(--radius);
  padding: 14px; cursor: pointer; user-select: none; -webkit-user-select: none;
  transition: transform .15s ease;
}
.card:active { transform: scale(.985); }
.card.archived { opacity: .55; }

.card-head { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.icon {
  width: 42px; height: 42px; border-radius: 12px; flex: none;
  display: grid; place-items: center; font-size: 22px;
}
.titles { flex: 1; min-width: 0; }
.titles h3, .titles p { margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.titles h3 { font-size: 16px; font-weight: 600; }
.titles p { margin-top: 2px; color: var(--muted); font-size: 13px; }

.check {
  position: relative; flex: none;
  width: 44px; height: 44px; border: 0; border-radius: 13px;
  display: grid; place-items: center;
  transition: transform .12s ease, background .2s ease;
}
.check:active { transform: scale(.88); }
.check svg { width: 22px; height: 22px; position: relative; }
.check.multi::before {
  content: ""; position: absolute; inset: 4px; border-radius: 10px; background: var(--card);
}
.check.multi span { position: relative; font-size: 12px; font-weight: 700; }

.heat {
  display: grid; grid-template-rows: repeat(7, auto);
  grid-auto-flow: column; grid-auto-columns: 1fr; gap: 3px;
}
.heat i { display: block; aspect-ratio: 1; border-radius: 3px; }
.heat-scroll { overflow-x: auto; scrollbar-width: none; }
.heat-scroll::-webkit-scrollbar { display: none; }
.heat-scroll .heat { grid-auto-columns: 12px; width: max-content; }

.meta { display: flex; justify-content: space-between; gap: 8px; margin-top: 10px; color: var(--muted); font-size: 12.5px; }
.meta b { color: var(--text); font-weight: 600; }

.empty { text-align: center; padding: 18vh 24px 0; color: var(--muted); }
.empty .big { font-size: 48px; margin-bottom: 8px; }
.empty h2 { color: var(--text); margin: 0 0 6px; font-size: 20px; }
.empty p { margin: 0 0 20px; }

/* ---------- Buttons & fields ---------- */
.btn {
  border: 0; border-radius: 12px; padding: 12px 16px;
  background: var(--card2); font-size: 15px; font-weight: 500;
}
.btn:active { filter: brightness(1.2); }
.btn.primary { background: var(--text); color: #000; font-weight: 600; }
.btn.danger { color: #ff6166; }
.link { border: 0; background: none; padding: 8px 6px; font-size: 16px; color: var(--muted); }
.link.strong { color: var(--text); font-weight: 600; }

.field { display: block; margin-bottom: 20px; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin: 0 0 8px 2px; font-weight: 500; }
.field input[type=text], .field input:not([type]) {
  width: 100%; background: var(--card); color: var(--text);
  border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 14px; font-size: 16px; outline: none;
}
.field input:focus { border-color: var(--accent, #666); }

.emojis, .swatches {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(42px, 1fr)); gap: 8px;
}
.emoji {
  aspect-ratio: 1; border: 0; border-radius: 12px; background: var(--card);
  font-size: 22px; display: grid; place-items: center;
}
.emoji.sel { background: var(--accent); }
.emoji-custom { margin-top: 8px; display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; }
.emoji-custom input { width: 72px !important; text-align: center; font-size: 20px !important; padding: 8px !important; }

.swatch { aspect-ratio: 1; border: 0; border-radius: 50%; }
.swatch.sel { outline: 2.5px solid var(--text); outline-offset: 3px; }

.stepper { display: inline-flex; align-items: center; background: var(--card); border-radius: 12px; overflow: hidden; }
.stepper button { width: 48px; height: 44px; border: 0; background: none; font-size: 22px; }
.stepper button:active { background: var(--card2); }
.stepper output { min-width: 36px; text-align: center; font-size: 17px; font-weight: 600; }
.help { font-size: 12.5px; color: var(--muted); margin: 8px 2px 0; }

.segmented { display: inline-flex; background: var(--card); border-radius: 12px; padding: 3px; }
.segmented button { border: 0; background: none; padding: 8px 14px; border-radius: 9px; font-size: 14px; color: var(--muted); }
.segmented button.sel { background: var(--card2); color: var(--text); font-weight: 600; }

.row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--card); border-radius: 14px; padding: 12px 14px; margin-bottom: 10px;
}
.switch { position: relative; width: 50px; height: 30px; flex: none; }
.switch input { opacity: 0; position: absolute; inset: 0; margin: 0; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; border-radius: 99px; background: var(--card2); transition: background .2s; }
.switch span::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px;
  border-radius: 50%; background: #fff; transition: transform .2s;
}
.switch input:checked + span { background: #22c55e; }
.switch input:checked + span::after { transform: translateX(20px); }

/* ---------- Sheets (dialogs) ---------- */
dialog {
  border: 0; padding: 0; margin: 0 auto;
  width: 100%; max-width: 640px; height: 100dvh; max-height: 100dvh;
  background: var(--bg); color: var(--text);
}
dialog[open] { display: flex; flex-direction: column; animation: sheet-up .22s ease-out; }
dialog::backdrop { background: rgba(0, 0, 0, .65); }
@keyframes sheet-up { from { transform: translateY(28px); opacity: 0; } }
dialog form { display: contents; }

.sheet-head {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  padding: calc(env(safe-area-inset-top) + 8px) 12px 8px; border-bottom: 1px solid var(--line);
}
.sheet-head > :first-child { justify-self: start; }
.sheet-head > :last-child { justify-self: end; }
.sheet-head h2 { margin: 0; font-size: 17px; font-weight: 600; }
.sheet-body { flex: 1; overflow-y: auto; padding: 18px 16px calc(env(safe-area-inset-bottom) + 32px); }

/* ---------- Detail ---------- */
.hero { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; }
.hero .icon { width: 56px; height: 56px; border-radius: 16px; font-size: 30px; }
.hero h3 { margin: 0; font-size: 20px; }
.hero p { margin: 2px 0 0; color: var(--muted); }

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.stat { background: var(--card); border-radius: 14px; padding: 12px 14px; }
.stat b { display: block; font-size: 24px; font-weight: 700; letter-spacing: -.02em; }
.stat span { color: var(--muted); font-size: 12.5px; }

.panel { background: var(--card); border-radius: var(--radius); padding: 14px; margin-bottom: 14px; }
.panel-title { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; font-weight: 600; }
.panel-title .icon-btn { width: 34px; height: 34px; }
.panel-title .icon-btn:disabled { opacity: .25; }

.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; text-align: center; }
.cal .dow { font-size: 11.5px; color: var(--muted); padding-bottom: 2px; }
.cal button {
  aspect-ratio: 1; border: 0; border-radius: 10px; background: var(--card2);
  font-size: 14px; font-weight: 500; position: relative;
}
.cal button:disabled { opacity: .3; cursor: default; }
.cal button.today { box-shadow: inset 0 0 0 2px var(--accent); }
.cal button small { position: absolute; bottom: 2px; left: 0; right: 0; font-size: 9px; opacity: .85; }
.hint { color: var(--muted); font-size: 12.5px; margin: -4px 2px 18px; }

.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* Desktop: show sheets as centered panels */
@media (min-width: 700px) {
  dialog { height: min(860px, 92dvh); margin-top: 4dvh; border-radius: 20px; }
}
