/* Little Habit */
:root {
  --black: #000000;
  --white: #ffffff;
  --pink: #fcdbde;
  --pink-2: #f8c6cb;
  --pink-soft: #fef1f2;
  --sage: #a1a171;
  --sage-2: #8f8f62;
  --sage-soft: #ecece1;
  --ink-2: rgba(0, 0, 0, 0.68);
  --line: rgba(0, 0, 0, 0.14);
  --radius: 16px;
  --edge: #f1dde1;
  --edge-2: #e6c3cc;
  --plum: #d98ca8;
  --plum-deep: #8c4a63;
  --shadow-soft: 0 6px 18px rgba(99, 63, 50, 0.1);
  --font-head: 'Life Savers', Georgia, 'Times New Roman', serif;
  --font-body: 'Inter Tight', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--white); color: var(--black);
  font-family: var(--font-body); font-size: 16px; line-height: 1.45;
  -webkit-font-smoothing: antialiased; min-height: 100vh;
  padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right);
}
h1, h2, h3 { font-family: var(--font-head); font-weight: 700; line-height: 1.15; margin: 0; letter-spacing: 0.1px; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--plum-deep); outline-offset: 2px; border-radius: 8px; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 16px;
  padding: 12px 24px; padding-top: calc(12px + env(safe-area-inset-top));
  background: var(--white); border-bottom: 1.5px solid var(--edge);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--black); font-family: var(--font-head); font-weight: 800; font-size: 22px; white-space: nowrap; }
.tabs { display: flex; gap: 4px; padding: 4px; border: 1.5px solid var(--edge); border-radius: 999px; background: var(--pink-soft); margin: 0 auto; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  border: 0; background: transparent; border-radius: 999px; padding: 7px 14px; font-weight: 600; font-size: 15px; white-space: nowrap;
  display: inline-flex; align-items: center; gap: 6px; transition: background 0.15s;
}
.tab:hover { background: var(--pink); }
.tab[aria-current='page'] { background: var(--sage); }
.tab .n { font-size: 12px; font-weight: 700; background: var(--white); border: 1.5px solid var(--edge); border-radius: 999px; min-width: 20px; padding: 0 5px; line-height: 17px; text-align: center; }
.top-actions { display: flex; align-items: center; gap: 8px; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1.5px solid var(--edge-2); border-radius: 14px;
  padding: 8px 16px; font-weight: 700; background: var(--white);
  transition: background 0.15s; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--pink-soft); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--pink); border-color: #f4c3cd; }
.btn.primary:hover { background: var(--pink-2); }
.btn.sage { background: var(--sage); border-color: rgba(0, 0, 0, 0.1); }
.btn.sage:hover { background: var(--sage-2); }
.btn.small { padding: 5px 12px; font-size: 14px; border-radius: 10px; }
.btn.ghost { border-color: var(--line); background: transparent; font-weight: 600; }
.btn.ghost:hover { background: var(--pink-soft); transform: none; border-color: var(--edge-2); }
.btn.danger { background: #fff; color: #9b1c1c; border-color: #ecc3c3; }
.btn.danger:hover { background: #fdecec; }
.btn.is-off { opacity: 0.55; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; transform: none; }
.icon-btn {
  display: inline-grid; place-items: center; width: 38px; height: 38px; border: 2px solid transparent; border-radius: 12px; background: transparent; padding: 0;
}
.icon-btn:hover { background: var(--pink); border-color: var(--edge-2); }
.icon-btn[disabled] { opacity: 0.35; cursor: not-allowed; background: transparent; border-color: transparent; }

/* ---------- page ---------- */
main { max-width: 1320px; margin: 0 auto; padding: 28px 24px 96px; outline: none; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 22px; }
.page-head h1 { font-size: clamp(28px, 4vw, 40px); }
.page-head p { margin: 4px 0 0; color: var(--ink-2); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1.5px solid var(--edge); background: var(--white); border-radius: 999px; padding: 4px 12px; font-weight: 600; font-size: 14px; }
.chip:hover { background: var(--pink); }
.chip.on { background: var(--sage); }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 360px), 1fr)); gap: 28px 26px; align-items: start; }
.card-tile { display: flex; flex-direction: column; gap: 10px; position: relative; }
.card-art { position: relative; border-radius: 28px; }
.card-svg, .card-img { display: block; width: 100%; height: auto; filter: drop-shadow(0 7px 12px rgba(0, 0, 0, 0.14)); user-select: none; -webkit-user-select: none; }
.card-img { border-radius: 14px; max-height: 520px; object-fit: contain; background: var(--white); border: 1.5px solid var(--edge); }
.card-svg text { pointer-events: none; }
.cell { cursor: pointer; transform-box: fill-box; transform-origin: center; transition: transform 0.12s; }
.cell:hover { transform: scale(1.06); }
.cell:focus, .cell:focus-visible { outline: none; }
.cell:focus-visible path { stroke-width: 6; }
.cell.pop { animation: pop 0.5s cubic-bezier(0.3, 1.7, 0.5, 1); }
@keyframes pop { 0% { transform: scale(0.4); } 60% { transform: scale(1.22); } 100% { transform: scale(1); } }
.card-tile.celebrate .card-art { animation: wiggle 0.6s ease; }
@keyframes wiggle { 20% { transform: rotate(-1.2deg) scale(1.01); } 50% { transform: rotate(1deg) scale(1.01); } 100% { transform: none; } }

.card-bar { display: flex; align-items: center; gap: 8px; padding: 0 2px; }
.meter { flex: 1; min-width: 0; }
.meter .row { display: flex; align-items: baseline; gap: 8px; font-size: 14px; color: var(--ink-2); }
.meter strong { font-size: 18px; color: var(--black); font-variant-numeric: tabular-nums; }
.meter .streak { display: inline-flex; align-items: center; gap: 4px; margin-left: auto; font-weight: 600; color: var(--black); white-space: nowrap; }
.bar { height: 8px; background: var(--sage-soft); border: 1.5px solid var(--edge); border-radius: 999px; overflow: hidden; margin-top: 5px; }
.bar > i { display: block; height: 100%; background: var(--sage); border-radius: 999px; transition: width 0.3s; }
.bar.full > i { background: var(--pink); }

/* ---------- empty state ---------- */
.empty { text-align: center; padding: 56px 16px 24px; max-width: 640px; margin: 0 auto; }
.empty .demo { display: flex; justify-content: center; gap: 10px; margin-bottom: 22px; }
.empty .demo svg { width: 54px; height: 54px; }
.empty h2 { font-size: 32px; margin-bottom: 8px; }
.empty p { color: var(--ink-2); margin: 0 auto 22px; max-width: 46ch; }
.starters { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 26px; }
.starters .label { width: 100%; font-size: 13px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-2); font-weight: 600; }

/* ---------- period views ---------- */
.period-nav { display: flex; align-items: center; gap: 8px; }
.period-nav h1 { font-size: clamp(24px, 3.4vw, 34px); min-width: 7ch; text-align: center; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 24px; }
.stat { border: 1.5px solid var(--edge); border-radius: 18px; padding: 12px 16px; background: var(--pink-soft); }
.stat:nth-child(2) { background: var(--sage-soft); }
.stat b { display: block; font-family: var(--font-head); font-size: 32px; line-height: 1.1; }
.stat span { font-size: 14px; color: var(--ink-2); }
.panels { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 340px), 1fr)); gap: 18px; align-items: start; }
.panels.wide.q { grid-template-columns: repeat(auto-fill, minmax(min(100%, 620px), 1fr)); }
.panel { min-width: 0; }
.panels.wide.y { grid-template-columns: minmax(0, 1fr); }
.panel { border: 1.5px solid var(--edge); border: 1.5px solid color-mix(in srgb, var(--ol) 28%, transparent); box-shadow: var(--shadow-soft); border-radius: 22px; padding: 16px 18px 18px; background: var(--bg); color: var(--ink); }
.panel > header { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.panel h3 { font-size: 21px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.panel .count { font-size: 13px; font-weight: 600; white-space: nowrap; background: rgba(255, 255, 255, 0.7); color: #000; border: 1px solid var(--edge); border-radius: 999px; padding: 1px 9px; }
.panel .dot { width: 26px; height: 26px; flex: none; }
.months { display: flex; flex-wrap: wrap; gap: 14px 18px; }
.month { flex: 0 0 auto; max-width: 100%; }
.month.grow { flex: 1 1 100%; }
.month h4 { margin: 0 0 4px; font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; opacity: 0.75; }
.cal-svg { display: block; max-width: 100%; height: auto; }
.month.grow .cal-svg { width: 100%; }
.day { cursor: pointer; transform-box: fill-box; transform-origin: center; transition: transform 0.1s; }
.day:hover { transform: scale(1.12); }
.day.pop { animation: pop 0.5s cubic-bezier(0.3, 1.7, 0.5, 1); }
.day.fut { opacity: 0.3; cursor: default; pointer-events: none; }
.day:focus, .day:focus-visible { outline: none; }
.day:focus-visible path { stroke-width: 9; }

/* ---------- menus ---------- */
.menu {
  position: fixed; z-index: 80; min-width: 210px; background: var(--white); border: 1.5px solid var(--edge); border-radius: 16px;
  box-shadow: 0 10px 30px rgba(99, 63, 50, 0.18); padding: 6px; display: flex; flex-direction: column;
}
.menu button {
  display: flex; align-items: center; gap: 10px; border: 0; background: transparent; padding: 8px 10px; border-radius: 9px; text-align: left; font-weight: 600; font-size: 15px;
}
.menu button:hover, .menu button:focus-visible { background: var(--pink); outline: none; }
.menu button.danger { color: #9b1c1c; }
.menu hr { border: 0; border-top: 1.5px solid var(--line); margin: 5px 4px; }

/* ---------- dialogs ---------- */
dialog.dlg {
  border: 0; border-radius: 26px; padding: 0; background: var(--white); color: var(--black);
  width: min(96vw, 520px); max-height: 92vh; box-shadow: 0 20px 60px rgba(99, 63, 50, 0.28); overflow: hidden;
}
dialog.dlg[open] { display: flex; flex-direction: column; animation: dlgIn 0.18s ease-out; }
dialog.dlg::backdrop { background: rgba(0, 0, 0, 0.4); }
@keyframes dlgIn { from { opacity: 0; transform: translateY(10px) scale(0.98); } to { opacity: 1; transform: none; } }
.dlg-head { display: flex; align-items: center; gap: 10px; padding: 16px 20px 12px; border-bottom: 1.5px solid var(--edge); background: var(--pink); }
.dlg-head h2 { font-size: 24px; flex: 1; }
.dlg-body { padding: 18px 20px; overflow: auto; flex: 1; }
.dlg-foot { display: flex; gap: 10px; justify-content: flex-end; padding: 12px 20px; border-top: 1.5px solid var(--edge); background: var(--sage-soft); padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
.dlg p { margin: 0 0 10px; }

dialog.dlg.editor { width: min(98vw, 1040px); height: min(92vh, 840px); }
.ed { display: grid; grid-template-columns: minmax(0, 1fr) minmax(300px, 400px); grid-template-rows: minmax(0, 1fr); min-height: 0; flex: 1; overflow: hidden; }
.ed-form { overflow: auto; padding: 4px 22px 22px; min-height: 0; }
.ed-side { background: var(--pink-soft); border-left: 1.5px solid var(--edge); padding: 18px; display: flex; flex-direction: column; gap: 10px; align-items: stretch; overflow: auto; }
.ed-side .cap { font-family: var(--font-head); font-size: 22px; font-weight: 700; color: var(--black); text-align: center; line-height: 1.1; }
.ed-side .cap-sub { font-size: 13px; color: var(--ink-2); text-align: center; margin-top: -6px; }
.preview-art .card-svg { filter: drop-shadow(0 7px 12px rgba(0, 0, 0, 0.16)); }
.fs { border: 0; padding: 0; margin: 18px 0 0; min-width: 0; }
.fs > legend, .lbl { font-family: var(--font-head); font-weight: 700; font-size: 18px; padding: 0; margin-bottom: 8px; display: block; }
.hint { font-size: 13.5px; color: var(--ink-2); margin: 6px 0 0; }
.field { display: block; margin-top: 12px; }
.field > span { display: block; font-weight: 600; font-size: 14px; margin-bottom: 4px; }
.inp {
  width: 100%; border: 1.5px solid var(--edge); border-radius: 12px; padding: 9px 12px; background: var(--white); min-height: 42px;
}
.inp:focus { outline: none; border-color: var(--plum); box-shadow: 0 0 0 4px rgba(238, 168, 194, 0.35); }
.seg { display: inline-flex; border: 1.5px solid var(--edge); border-radius: 12px; overflow: hidden; background: var(--white); flex-wrap: wrap; }
.seg button { border: 0; background: transparent; padding: 7px 14px; font-weight: 600; border-right: 1.5px solid var(--edge); }
.seg button:last-child { border-right: 0; }
.seg button:hover { background: var(--pink); }
.seg button.on { background: var(--sage); }
.row-wrap { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.num { width: 92px; text-align: center; }

.shapes { display: grid; grid-template-columns: repeat(auto-fill, minmax(54px, 1fr)); gap: 8px; }
.shape-btn { aspect-ratio: 1; border: 2px solid var(--line); border-radius: 12px; background: var(--white); display: grid; place-items: center; padding: 8px; }
.shape-btn:hover { border-color: var(--edge-2); background: var(--pink-soft); }
.shape-btn.on { border-color: var(--edge-2); background: var(--sage-soft); }
.shape-btn svg { width: 100%; height: 100%; }
.themes { display: grid; grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: 8px; }
.theme-btn { border: 2px solid var(--line); border-radius: 12px; background: var(--white); padding: 6px; text-align: left; font-size: 13px; font-weight: 600; display: flex; flex-direction: column; gap: 5px; }
.theme-btn:hover { border-color: var(--edge-2); }
.theme-btn .sw-row { display: flex; height: 22px; border-radius: 7px; overflow: hidden; border: 1px solid rgba(0, 0, 0, 0.12); }
.theme-btn .sw-row i { flex: 1; }
.color-row { display: flex; align-items: center; gap: 10px; justify-content: space-between; flex-wrap: wrap; padding: 7px 0; border-bottom: 1.5px dashed var(--line); }
.color-row:last-child { border-bottom: 0; }
.color-row > label { font-weight: 600; font-size: 14px; min-width: 120px; }
.swatches { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.sw { width: 26px; height: 26px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.16); background: var(--c); padding: 0; position: relative; }
.sw:hover { transform: scale(1.12); }
.sw.on::after { content: ''; position: absolute; inset: -5px; border: 2px solid var(--plum); border-radius: 50%; }
.sw.custom { overflow: hidden; background: conic-gradient(#fcdbde, #a1a171, #58719e, #f7bd64, #fcdbde); display: inline-block; cursor: pointer; }
.sw.custom input { opacity: 0; width: 100%; height: 100%; cursor: pointer; position: absolute; inset: 0; border: 0; padding: 0; }
.fonts { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px; max-height: 190px; overflow: auto; padding: 2px; }
.font-btn { border: 2px solid var(--line); border-radius: 10px; background: var(--white); padding: 6px 10px; text-align: left; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.font-btn:hover { border-color: var(--edge-2); background: var(--pink-soft); }
.font-btn.on { border-color: var(--edge-2); background: var(--sage-soft); }
.font-btn small { font-family: var(--font-body); font-size: 11px; display: block; color: var(--ink-2); }

/* history */
.hist { list-style: none; margin: 10px 0 0; padding: 0; max-height: 280px; overflow: auto; border: 1.5px solid var(--edge); border-radius: 14px; }
.hist li { display: flex; align-items: center; gap: 10px; padding: 7px 12px; border-bottom: 1.5px solid var(--line); }
.hist li:last-child { border-bottom: 0; }
.hist .no { width: 28px; height: 28px; border-radius: 50%; background: var(--sage); display: grid; place-items: center; font-size: 12px; font-weight: 700; flex: none; }
.hist .when { flex: 1; font-weight: 600; }
.hist .empty-hist { padding: 16px; text-align: center; color: var(--ink-2); display: block; }
.addrow { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.addrow .inp { width: auto; flex: 1; min-width: 150px; }
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 8px; margin-bottom: 4px; }
.facts div { border: 1.5px solid var(--edge); border-radius: 12px; padding: 8px 12px; background: var(--pink-soft); }
.facts div:nth-child(even) { background: var(--sage-soft); }
.facts b { display: block; font-family: var(--font-head); font-size: 22px; line-height: 1.2; }
.facts span { font-size: 13px; color: var(--ink-2); }

/* ---------- toasts, dropzone, confetti ---------- */
#toasts { position: fixed; z-index: 100; left: 50%; transform: translateX(-50%); bottom: calc(20px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 8px; align-items: center; width: min(92vw, 460px); pointer-events: none; }
.toast {
  pointer-events: auto; display: flex; align-items: center; gap: 12px; background: #272323; color: var(--white); border-radius: 16px; padding: 10px 14px; width: 100%;
  box-shadow: 0 8px 24px rgba(39, 35, 35, 0.25); animation: toastIn 0.2s ease-out; font-weight: 500;
}
.toast.out { opacity: 0; transform: translateY(8px); transition: 0.25s; }
.toast span { flex: 1; }
.toast button { background: var(--pink); color: #000; border: 0; border-radius: 8px; font-weight: 700; padding: 4px 12px; }
.toast.err { background: #9b1c1c; border-color: #9b1c1c; }
@keyframes toastIn { from { opacity: 0; transform: translateY(10px); } }
#dropzone { position: fixed; inset: 0; z-index: 90; background: rgba(252, 219, 222, 0.92); display: grid; place-items: center; }
#dropzone > div { border: 2px dashed var(--plum); border-radius: 28px; padding: 48px 56px; font-family: var(--font-head); font-size: 28px; background: var(--white); text-align: center; }
.confetti { position: absolute; inset: 0; pointer-events: none; overflow: visible; z-index: 5; }
.confetti i { position: absolute; left: 50%; top: 40%; width: 10px; height: 14px; border-radius: 3px; animation: fly 1.3s cubic-bezier(0.2, 0.7, 0.3, 1) forwards; }
@keyframes fly { to { transform: translate(var(--x), var(--y)) rotate(var(--r)); opacity: 0; } }

/* ---------- responsive ---------- */
@media (max-width: 860px) {
  .topbar { flex-wrap: wrap; padding: 10px 14px; padding-top: calc(10px + env(safe-area-inset-top)); gap: 10px; }
  .brand { order: 1; flex: 1; }
  .top-actions { order: 2; }
  .tabs { order: 3; width: 100%; margin: 0; }
  .tab { flex: 1; justify-content: center; padding: 7px 10px; }
  main { padding: 20px 14px 90px; }
  .ed { grid-template-columns: 1fr; grid-template-rows: auto minmax(0, 1fr); }
  dialog.dlg.editor { height: 96vh; }
  .ed-side { order: -1; border-left: 0; border-bottom: 1.5px solid var(--edge); padding: 10px 14px; height: 30vh; flex: none; flex-direction: row; justify-content: center; align-items: stretch; }
  .ed-side .cap, .ed-side .cap-sub { display: none; }
  .ed-side .preview-art { height: 100%; width: 100%; display: flex; justify-content: center; align-items: center; }
  .ed-side .preview-art .card-svg { max-height: 100%; width: auto; max-width: 100%; }
  .btn span.lbl-hide { display: none; }
}
@media (max-width: 520px) {
  .btn#btnNew span { display: none; }
  .btn#btnNew { padding: 8px 10px; }
  .grid { gap: 24px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
