@font-face { font-family: "Bricolage Grotesque"; src: url("fonts/bricolage-grotesque-latin-wght-normal.woff2") format("woff2"); font-weight: 200 800; font-display: swap; }
@font-face { font-family: "Plex Arabic"; src: url("fonts/ibm-plex-sans-arabic-arabic-600-normal.woff2") format("woff2"); font-weight: 100 900; font-display: swap; unicode-range: U+0600-06FF, U+0750-077F, U+0870-08FF, U+FB50-FDFF, U+FE70-FEFC; }

:root {
  --ground: #e6eedc;
  --board: #f6f9f1;
  --ink: #16241c;
  --soft: rgb(22 36 28 / 0.58);
  --line: rgb(22 36 28 / 0.12);
  --empty: rgb(22 36 28 / 0.08);
  --accent: #2f4bff;
  --on-accent: #ffffff;
  --danger: #c7362b;
  --c0: #2f4bff; --c1: #f0603a; --c2: #1e9e57; --c3: #d69a00; --c4: #d9468f; --c5: #0f95a0;
  --ui: "Bricolage Grotesque", "Plex Arabic", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ground: #13201a; --board: #1a2b23; --ink: #e6eedc; --soft: rgb(230 238 220 / 0.6); --line: rgb(230 238 220 / 0.12); --empty: rgb(230 238 220 / 0.1);
    --accent: #7d8cff; --on-accent: #0c1030; --danger: #ff7a6b;
    --c0: #7d8cff; --c1: #ff8a66; --c2: #4ccb85; --c3: #f2c14e; --c4: #ff7ab8; --c5: #3cc7d2;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
    --ground: #13201a; --board: #1a2b23; --ink: #e6eedc; --soft: rgb(230 238 220 / 0.6); --line: rgb(230 238 220 / 0.12); --empty: rgb(230 238 220 / 0.1);
    --accent: #7d8cff; --on-accent: #0c1030; --danger: #ff7a6b;
    --c0: #7d8cff; --c1: #ff8a66; --c2: #4ccb85; --c3: #f2c14e; --c4: #ff7ab8; --c5: #3cc7d2;
    color-scheme: dark;
  }

* { box-sizing: border-box; }
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
body { margin: 0; background: var(--ground); color: var(--ink); font: 500 15px/1.45 var(--ui); -webkit-font-smoothing: antialiased; }
a { color: inherit; text-underline-offset: 3px; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.bar { display: flex; align-items: baseline; gap: 4px 20px; flex-wrap: wrap; padding: 18px 28px 8px; }
.brand { margin: 0; font-size: 28px; font-weight: 800; letter-spacing: -0.03em; }
.brand span { color: var(--accent); }
.purpose { flex: 1; margin: 0; font-size: 17px; }
.bar-meta { color: var(--soft); font-size: 13px; }
.bar-meta .lang { margin-inline-start: 12px; unicode-bidi: isolate; }
.app { display: flex; flex-direction: column; min-height: 100dvh; }
.due { display: flex; align-items: center; gap: 8px; } /* the label stays with its days when the line wraps */
.due-label { color: var(--soft); font-size: 13px; font-weight: 600; }
.legend { margin: 10px 0 0; color: var(--soft); font-size: 13px; }
.legend b { color: var(--ink); }
.swatch-off { display: inline-block; width: 14px; height: 14px; margin-inline-end: 2px; vertical-align: -2px; border-radius: 4px; background: repeating-linear-gradient(135deg, var(--empty) 0 3px, transparent 3px 6px); box-shadow: inset 0 0 0 1px var(--line); }

.wrap { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 14px; padding: 8px 28px 18px; }

/* Add a habit: one line */
.add, .edit { display: flex; align-items: center; gap: 12px 18px; flex-wrap: wrap; }
.add input, .edit input { flex: 1 1 240px; min-width: 0; height: 44px; padding: 0 14px; border: 1.5px solid var(--line); border-radius: 10px; background: var(--board); }
.add input:focus, .edit input:focus { outline: none; border-color: var(--accent); }
.dots { display: flex; gap: 6px; }
.dots button { width: 26px; height: 26px; padding: 0; border: 0; border-radius: 50%; background: var(--c); box-shadow: inset 0 0 0 0 var(--board); transition: box-shadow 0.12s; }
.dots button[aria-checked="true"] { box-shadow: inset 0 0 0 4px var(--board), 0 0 0 2px var(--c); }
.week { display: flex; gap: 3px; }
.week button { width: 30px; height: 30px; padding: 0; border: 0; border-radius: 8px; background: var(--empty); color: var(--soft); font-size: 13px; font-weight: 700; }
.week button[aria-pressed="true"] { background: var(--ink); color: var(--ground); }
.primary { height: 44px; padding: 0 22px; border: 0; border-radius: 10px; background: var(--accent); color: var(--on-accent); font-weight: 700; }
.primary:hover { filter: brightness(1.08); }
.link { padding: 0; border: 0; background: none; color: inherit; font-weight: 700; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
.link:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }

/* The board: one row per habit */
.board { flex: 1; min-height: 0; display: flex; flex-direction: column; padding: 10px 18px 14px; border-radius: 16px; background: var(--board); overflow: auto; }
.rows { margin: 0; padding: 0; list-style: none; }
.row { --gap: 4px; display: grid; grid-template-columns: 22px minmax(120px, 200px) 1fr 64px 52px; align-items: center; gap: 0 12px; min-height: 54px; }
.rows .row + .row { border-top: 1px solid var(--line); }
.row.dragging { position: relative; z-index: 1; background: var(--board); box-shadow: 0 10px 28px rgb(0 0 0 / 0.16); border-radius: 10px; }
.cells { display: grid; grid-template-columns: repeat(30, 1fr); gap: var(--gap); }

.head { min-height: 40px; padding-top: 14px; align-items: end; padding-bottom: 6px; color: var(--soft); font-size: 12px; }
.head .cells span { display: grid; justify-items: center; line-height: 1.15; font-variant-numeric: tabular-nums; }
.head .cells b { font-size: 13px; font-weight: 600; color: var(--ink); }
.head .cells .is-today b { color: var(--accent); }
.head .cells .is-today { color: var(--accent); font-weight: 700; }
.head .num, .head .best { font-size: 12px; font-weight: 700; color: var(--soft); letter-spacing: 0; text-align: end; }
.month, .month-m { position: relative; }
.month-m:not(.month)::before { display: none; }
.month::before, .month-m::before { content: attr(data-month); position: absolute; bottom: 100%; inset-inline-start: 0; color: var(--soft); font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; font-size: 10px; }

.handle { width: 22px; height: 32px; padding: 0; border: 0; border-radius: 6px; background: radial-gradient(circle, var(--soft) 1.2px, transparent 1.6px) 0 0 / 7px 7px; background-position: 4px 6px; opacity: 0.45; cursor: grab; touch-action: none; }
.handle:hover, .handle:focus-visible { opacity: 1; }
.name { display: flex; align-items: center; gap: 9px; min-width: 0; padding: 6px 4px; border: 0; border-radius: 8px; background: none; text-align: start; font-weight: 700; }
.name i { flex: none; width: 10px; height: 10px; border-radius: 3px; background: var(--c); }
.name span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.name:hover { background: var(--empty); }

/* A square. Done squares next to each other fuse into one chain. */
.cell { position: relative; height: 36px; padding: 0; border: 0; border-radius: 7px; background: var(--empty); }
.cell:hover { box-shadow: inset 0 0 0 2px var(--c); }
.cell.off { background: repeating-linear-gradient(135deg, var(--empty) 0 3px, transparent 3px 6px); }
.cell.today { box-shadow: inset 0 0 0 2px var(--accent); }
.cell[aria-pressed="true"] { background: var(--c); box-shadow: none; }
.cell.join-r { border-start-end-radius: 0; border-end-end-radius: 0; }
.cell.join-l { border-start-start-radius: 0; border-end-start-radius: 0; }
.cell.join-r[aria-pressed="true"] { box-shadow: calc(var(--gap) + 2px) 0 0 var(--c); }
/* Right to left, the next day is on the left: the chain fills the gap on that side */
:dir(rtl) .cell.join-r[aria-pressed="true"] { box-shadow: calc(-1 * (var(--gap) + 2px)) 0 0 var(--c); }
.cell.fill { animation: fill 0.35s cubic-bezier(0.3, 1.6, 0.5, 1); }
@keyframes fill { from { transform: scale(0.6); } }

.num { font-size: 26px; font-weight: 800; letter-spacing: -0.02em; text-align: end; font-variant-numeric: tabular-nums; }
.num.zero { color: var(--soft); font-weight: 600; }
.best { color: var(--soft); font-size: 15px; font-weight: 600; text-align: end; font-variant-numeric: tabular-nums; }
.num.pop { animation: pop 0.7s cubic-bezier(0.3, 1.8, 0.4, 1); color: var(--c); }
@keyframes pop { 40% { transform: scale(1.6); } }
.spark { position: fixed; width: 7px; height: 7px; border-radius: 2px; background: var(--c); pointer-events: none; z-index: 5; }

.empty { display: grid; place-content: center; justify-items: center; flex: 1; padding: 40px 0; color: var(--soft); text-align: center; }
.empty p { margin: 0; }
.empty-title { color: var(--ink); font-size: 26px; font-weight: 800; }

.foot { display: flex; align-items: center; gap: 8px 18px; flex-wrap: wrap; font-size: 14px; }
.foot p { margin: 0; margin-inline-end: auto; font-weight: 600; }
.saved { color: var(--soft); font-size: 13px; }

/* Edit popover */
.edit { width: min(400px, calc(100vw - 24px)); margin: 0; padding: 16px; border: 1px solid var(--line); border-radius: 14px; background: var(--board); color: var(--ink); box-shadow: 0 18px 44px rgb(0 0 0 / 0.2); position: fixed; inset: auto; }
.edit:not(:popover-open) { display: none; }
.edit input { flex-basis: 100%; }
.edit-actions { display: flex; justify-content: space-between; width: 100%; }
.danger { height: 44px; padding: 0 16px; border: 1.5px solid currentColor; border-radius: 10px; background: none; color: var(--danger); font-weight: 700; }

.toast { position: fixed; left: 50%; bottom: 22px; display: flex; align-items: center; gap: 14px; margin: 0; padding: 10px 12px 10px 16px; border-radius: 12px; background: var(--ink); color: var(--ground); font-weight: 600; transform: translate(-50%, 12px); opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s; z-index: 10; }
.toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.toast button { padding: 4px 10px; border: 0; border-radius: 8px; background: var(--accent); color: var(--on-accent); font-weight: 700; }

@media (prefers-reduced-motion: reduce) {
  .cell.fill, .num.pop { animation: none; }
  .toast, .dots button { transition: none; }
}

/* Phones: the last 7 days, numbers under the name */
@media (max-width: 760px) {
  .bar, .wrap { padding-inline: 16px; }
  .purpose { flex-basis: 100%; order: 3; font-size: 15px; }
  .add input { flex-basis: 100%; }
  .add .primary { flex: 1; }
  .board { padding: 8px 10px 10px; }
  .row { --gap: 3px; grid-template-columns: 18px 1fr 40px 30px; grid-template-areas: "h n s b" ". c c c"; gap: 2px 8px; padding: 6px 0 8px; }
  .handle { grid-area: h; width: 18px; }
  .name { grid-area: n; }
  .cells { grid-area: c; grid-template-columns: repeat(7, 1fr); }
  .row .cells > :nth-child(-n+23) { display: none; }
  .row > .num { grid-area: s; font-size: 22px; }
  .row > .best { grid-area: b; }
  .head { grid-template-areas: ". c c c"; padding: 14px 0 4px; }
  .head > :not(.cells) { display: none; }
  .cell { height: 36px; }
  .month::before { display: none; }
  .month-m::before, .month-m:not(.month)::before { display: block; }
  .foot p { flex-basis: 100%; }
}

/* Questions under the tool: for people who scroll, and for search engines */
.faq { max-width: 920px; margin: 0 auto; padding: 56px 20px 64px; }
.faq h2 { margin: 0 0 20px; font: 800 22px/1.2 var(--ui); letter-spacing: -0.02em; }
.faq-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 22px 32px; }
.faq h3 { margin: 0 0 6px; font-size: 15px; font-weight: 700; }
.faq p { margin: 0; color: var(--soft); line-height: 1.6; }

/* Light/dark button (theme.js): follows the device until the visitor picks */
.theme { display: inline-grid; place-items: center; width: 28px; height: 28px; margin-inline-start: 8px; padding: 0; border: 0; border-radius: 8px; background: none; color: var(--ink); cursor: pointer; vertical-align: middle; }
.theme:hover { background: var(--line); }
.theme svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.theme .sun, .theme[data-dark="true"] .moon { display: none; }
.theme[data-dark="true"] .sun { display: block; }
