/* HabitForge — forge-dark design system. No inline styles, no truncation. */

:root {
  color-scheme: dark;
  --bg: #0b0e13;
  --bg-2: #0f131a;
  --surface: #151a23;
  --surface-2: #1b2230;
  --surface-3: #222b3b;
  --line: #283141;
  --line-strong: #3b485e;
  --fg: #edf0f5;
  --muted: #9aa5b8;
  --faint: #667288;
  --accent: #ff9e45;
  --accent-2: #ffc078;
  --accent-soft: #4a2f1d;
  --accent-ink: #180d05;
  --good: #34d399;
  --crit: #f2766b;
  --h0: #11161e;
  --shadow: 0 18px 44px rgba(0, 0, 0, .32);
  --radius: 16px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

:root[data-accent="verdant"] {
  --accent: #34d399;
  --accent-2: #8ff0ca;
  --accent-soft: #123b30;
  --accent-ink: #042018;
}

:root[data-accent="cobalt"] {
  --accent: #8fb0ff;
  --accent-2: #bed0ff;
  --accent-soft: #202c4a;
  --accent-ink: #071026;
}

[data-color="0"] { --hc: #f2766b; }
[data-color="1"] { --hc: #f2b45e; }
[data-color="2"] { --hc: #b6dc6a; }
[data-color="3"] { --hc: #5fd6a0; }
[data-color="4"] { --hc: #62b8f0; }
[data-color="5"] { --hc: #9aa8ff; }
[data-color="6"] { --hc: #c08cf0; }
[data-color="7"] { --hc: #f07fb4; }

*, *::before, *::after { box-sizing: border-box; }

html {
  scroll-padding-top: calc(12px + env(safe-area-inset-top, 0px));
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background:
    radial-gradient(900px 460px at 88% -8%, rgba(255, 158, 69, .09), transparent 62%),
    radial-gradient(700px 420px at 4% 12%, rgba(52, 211, 153, .045), transparent 60%),
    var(--bg);
  color: var(--fg);
  font: 15px/1.5 var(--font);
  padding: calc(12px + env(safe-area-inset-top, 0px)) 16px calc(24px + env(safe-area-inset-bottom, 0px));
  hyphens: none;
  -webkit-hyphens: none;
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3, p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; hyphens: none; -webkit-hyphens: none; }
button:disabled { cursor: default; opacity: .38; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
img { max-width: 100%; }
strong { font-weight: 650; }

.skip {
  position: fixed;
  top: -80px;
  left: 12px;
  z-index: 100;
  background: var(--accent);
  color: var(--accent-ink);
  padding: 10px 16px;
  border-radius: 10px;
  text-decoration: none;
}
.skip:focus { top: 12px; }

.wrap { width: 100%; max-width: 1120px; margin: 0 auto; }

/* Header */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-mark {
  flex: none;
  width: 40px;
  height: 40px;
  filter: drop-shadow(0 0 14px rgba(255, 158, 69, .22));
}
.brand-copy { min-width: 0; }
.brand h1 {
  font-size: 22px;
  font-weight: 750;
  letter-spacing: .02em;
  text-transform: uppercase;
  overflow-wrap: anywhere;
}
.sub { color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.lang { display: grid; gap: 4px; }
.lang-label { color: var(--faint); font-size: 11px; text-transform: uppercase; letter-spacing: .08em; }
.lang select { min-width: 132px; }
.top-actions { display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; }
.quick-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  border-color: var(--line);
  color: var(--muted);
  overflow-wrap: anywhere;
  white-space: normal;
  text-align: center;
}
.quick-toggle[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--fg);
  box-shadow: inset 0 0 0 1px var(--accent-soft);
}
.quick-icon { font-size: 15px; line-height: 1; filter: drop-shadow(0 0 5px rgba(255, 158, 69, .45)); }
html.quick-mode .tabs, html.quick-mode .demo-banner { display: none; }

/* Navigation — always in normal flow, directly below the header. */
.tabs {
  display: flex;
  gap: 4px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 4px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.tab {
  flex: 1;
  min-width: 0;
  display: grid;
  place-items: center;
  min-height: 44px;
  padding: 6px 14px;
  border-radius: 10px;
  color: var(--muted);
  text-decoration: none;
  font-weight: 600;
  text-align: center;
  overflow-wrap: break-word;
  word-break: normal;
  white-space: normal;
  hyphens: none;
  -webkit-hyphens: none;
  transition: background .18s ease, color .18s ease;
}
.tab > span { min-width: 0; max-width: 100%; overflow-wrap: break-word; }
.tab[aria-current="page"] {
  background: var(--surface-3);
  color: var(--fg);
  box-shadow: inset 0 0 0 1px var(--line-strong);
}
.tab:not([aria-current="page"]):hover { color: var(--fg); background: var(--surface-2); }

@media (max-width: 699px) {
  body { padding-left: max(12px, env(safe-area-inset-left, 0px)); padding-right: max(12px, env(safe-area-inset-right, 0px)); }
  .tabs { gap: 4px; margin-bottom: 12px; }
  .tab { min-height: 44px; padding: 6px 8px; font-size: 14px; }
  .demo-banner { margin-top: 8px; padding: 11px 12px; }
  .demo-banner-copy { flex-basis: 100%; }
  .demo-banner .btn { width: 100%; }
}

@media (max-width: 359px) {
  .tabs { padding: 3px; gap: 2px; }
  .tab { padding: 6px 4px; font-size: 13px; }
  .demo-banner { gap: 8px; }
}

@media (min-width: 700px) {
  body { padding-top: 26px; padding-bottom: 40px; }
  .brand h1 { font-size: 26px; }
}

/* Demo mode banner */
.demo-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin: 12px 0 16px;
  padding: 12px 14px;
  border: 1px solid var(--accent-soft);
  border-radius: var(--radius);
  background: linear-gradient(180deg, var(--surface-2), var(--bg-2));
  box-shadow: var(--shadow);
}
.demo-banner-copy {
  display: grid;
  gap: 3px;
  flex: 1 1 240px;
  min-width: 0;
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}
.demo-banner-copy strong {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--fg);
  font-size: 13px;
}
.demo-banner-copy strong::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  flex: none;
}
.demo-banner .btn { flex: 0 0 auto; }

/* Shared surfaces and controls */
.stack { display: grid; gap: 16px; align-items: start; }
.card {
  background: linear-gradient(180deg, var(--surface), var(--bg-2));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  min-width: 0;
}
.chead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.chead h2 { font-size: 16px; font-weight: 650; overflow-wrap: anywhere; }
.chead-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.lab {
  display: block;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: .08em;
  text-transform: uppercase;
  margin-bottom: 8px;
  overflow-wrap: anywhere;
}
.help { color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.err { margin-top: 12px; color: var(--crit); font-size: 13px; overflow-wrap: anywhere; }

.btn, .link, .ib, .filebtn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 8px 16px;
  border-radius: 11px;
  border: 1px solid var(--line-strong);
  background: var(--surface-2);
  color: var(--fg);
  font-weight: 600;
  text-align: center;
  text-decoration: none;
  white-space: normal;
  hyphens: none;
  overflow-wrap: anywhere;
  transition: transform .12s ease, background .16s ease, border-color .16s ease;
}
.btn:hover, .filebtn:hover { background: var(--surface-3); }
.btn:active, .filebtn:active, .ib:active { transform: scale(.96); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: var(--accent-2); border-color: var(--accent-2); }
.btn.danger { color: var(--crit); border-color: rgba(242, 118, 107, .45); }
.btn.armed { background: var(--crit); border-color: var(--crit); color: #1b0705; }
.btn.small { min-height: 36px; padding: 6px 12px; font-size: 13px; }
.link {
  min-height: 36px;
  padding: 4px 6px;
  border: 0;
  background: none;
  color: var(--accent);
  font-size: 13px;
}
.link:hover { color: var(--accent-2); }
.ib { width: 44px; min-width: 44px; height: 44px; padding: 0; font-size: 22px; }
.filebtn { position: relative; overflow: hidden; cursor: pointer; }
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
.pill, .status-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 99px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--muted);
  white-space: normal;
  overflow-wrap: anywhere;
}
.status-paused { color: var(--accent-2); border-color: var(--accent-soft); }
.status-archived { color: var(--faint); }

select, input[type="text"], input[type="number"], input[type="time"], textarea {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  min-height: 44px;
  max-width: 100%;
}
input[type="text"], input[type="number"], textarea { width: 100%; font-size: 16px; }
textarea { min-height: 88px; resize: vertical; line-height: 1.45; }
input::placeholder, textarea::placeholder { color: var(--faint); }

.seg {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 3px;
}
.seg button {
  flex: 1 1 auto;
  min-height: 40px;
  padding: 6px 12px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-weight: 600;
  white-space: normal;
  hyphens: none;
  overflow-wrap: anywhere;
  transition: background .16s ease, color .16s ease;
}
.seg button[aria-pressed="true"] {
  background: var(--surface-3);
  color: var(--fg);
  box-shadow: inset 0 0 0 1px var(--line-strong);
}
.seg.compact button { min-height: 36px; padding: 5px 10px; font-size: 13px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.chips button {
  min-width: 46px;
  min-height: 42px;
  padding: 6px 10px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--muted);
  font-weight: 600;
}
.chips button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.sw { display: flex; gap: 10px; flex-wrap: wrap; }
.sw button {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 2px solid transparent;
  background: var(--hc);
  padding: 0;
}
.sw button[aria-checked="true"] { box-shadow: 0 0 0 3px var(--surface), 0 0 0 5px var(--hc); }

progress.meter {
  appearance: none;
  -webkit-appearance: none;
  display: block;
  width: 100%;
  height: 10px;
  border: 0;
  border-radius: 99px;
  overflow: hidden;
  background: var(--h0);
}
progress.meter::-webkit-progress-bar { background: var(--h0); border-radius: 99px; }
progress.meter::-webkit-progress-value { background: var(--hc, var(--accent)); border-radius: 99px; transition: width .3s ease; }
progress.meter::-moz-progress-bar { background: var(--hc, var(--accent)); border-radius: 99px; }
progress.thin { height: 6px; }

.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--hc, var(--accent)); flex: none; }
.empty { color: var(--muted); text-align: center; padding: 26px 12px; display: grid; gap: 12px; justify-items: center; overflow-wrap: anywhere; }
.note {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px dashed var(--line-strong);
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}

/* Today */
.today-grid { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 880px) {
  .today-grid { grid-template-columns: 332px minmax(0, 1fr); }
  .today-grid .summary { position: sticky; top: 12px; }
}
.summary { position: relative; overflow: hidden; }
.summary::before {
  content: "";
  position: absolute;
  inset: -60% 40% 60% -40%;
  background: radial-gradient(circle, rgba(255, 158, 69, .12), transparent 70%);
  pointer-events: none;
}
.summary.celebrate { animation: forge-glow 1.15s ease-out; }
@keyframes forge-glow {
  0% { box-shadow: 0 0 0 0 rgba(52, 211, 153, 0); }
  30% { box-shadow: 0 0 0 6px rgba(52, 211, 153, .22), 0 0 60px rgba(52, 211, 153, .22); }
  100% { box-shadow: 0 0 0 18px rgba(52, 211, 153, 0); }
}
.date-nav { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 14px; }
.date-title { display: grid; justify-items: center; gap: 4px; text-align: center; min-width: 0; }
.date-title strong { font-weight: 650; overflow-wrap: anywhere; }
.ring-row { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.ring { position: relative; width: 108px; height: 108px; flex: none; }
.ring svg { display: block; width: 100%; height: 100%; }
.ring-label { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; gap: 2px; }
.ring-label b { font: 650 26px/1 var(--mono); font-variant-numeric: tabular-nums; }
.ring-label span { font-size: 11px; color: var(--muted); }
.kpis { display: flex; gap: 18px; flex-wrap: wrap; }
.kpis > div { display: grid; gap: 2px; }
.kpis b { font: 650 27px/1 var(--mono); font-variant-numeric: tabular-nums; }
.kpis span { font-size: 11px; color: var(--muted); overflow-wrap: anywhere; }
.day-progress { margin: 15px 0 8px; }
.state { color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.state.ok { color: var(--good); }
.week-strip { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line); }
.wd {
  display: grid;
  justify-items: center;
  gap: 4px;
  padding: 6px 2px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: none;
  min-width: 0;
}
.wd[aria-pressed="true"] { background: var(--surface-3); border-color: var(--line-strong); }
.wl, .wn { font: 11px var(--mono); color: var(--muted); }
.wn { color: var(--faint); }
.wc { width: 28px; height: 28px; display: grid; place-items: center; border-radius: 50%; }
.wc.full { background: var(--accent); color: var(--accent-ink); }
.wc.full.rest { background: var(--good); }
.wc.full svg { width: 16px; height: 16px; }
.wc.nil { color: var(--faint); }
.wc svg { width: 28px; height: 28px; }
.protect-row { display: grid; gap: 8px; margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line); }
.protect-row .btn { width: 100%; }
.shield-count { color: var(--accent-2); font-family: var(--mono); }
.reflection { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line); display: grid; gap: 8px; }
.reflection textarea { min-height: 68px; }
.saved-hint { color: var(--good); font-size: 11px; opacity: 0; transition: opacity .2s ease; }
.saved-hint.show { opacity: 1; }

/* Quick view: one clean list with the day percentage, no secondary panels. */
.quick-view { max-width: 680px; margin: 0 auto; }
.quick-head { padding: 18px; }
.quick-head-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.quick-head-copy { display: grid; gap: 4px; min-width: 0; }
.quick-head-copy strong { font-size: 19px; overflow-wrap: anywhere; }
.quick-head-copy small { color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.quick-head .btn { flex: none; }
.quick-list { padding: 6px 14px; display: grid; }
.quick-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 2px;
  border-top: 1px solid var(--line);
  min-width: 0;
  border-left: 3px solid transparent;
}
.quick-row:first-child { border-top: 0; }
.quick-row.is-rescue { border-left-color: #f5b942; padding-left: 9px; }
.quick-info { flex: 1; display: grid; gap: 2px; min-width: 0; overflow-wrap: anywhere; }
.quick-info strong { font-size: 15px; overflow-wrap: anywhere; }
.quick-info small { color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.quick-controls { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; justify-content: flex-end; min-width: 0; }
.quick-controls .check { width: 38px; height: 38px; }
.quick-controls .ib { width: 38px; min-width: 38px; height: 38px; }
@media (max-width: 699px) {
  .quick-head, .quick-list { padding-left: 12px; padding-right: 12px; }
  .quick-row { flex-wrap: wrap; }
  .quick-controls { flex: 1 1 100%; justify-content: flex-start; padding-left: 32px; }
}

.filter-bar { display: grid; gap: 8px; }
.plabel { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; color: var(--muted); font-size: 12px; }
.plabel strong { color: var(--fg); }
.habit-card {
  background: linear-gradient(180deg, var(--surface), var(--bg-2));
  border: 1px solid var(--line);
  border-left: 3px solid var(--hc, var(--accent));
  border-radius: 14px;
  padding: 14px;
  min-width: 0;
  transition: border-color .18s ease, transform .18s ease;
}
.habit-card:hover { border-color: var(--line-strong); border-left-color: var(--hc, var(--accent)); }
.forged-card {
  --forged-glow: rgba(255, 208, 82, .2);
  background:
    radial-gradient(circle at top right, rgba(255, 235, 160, .18), transparent 42%),
    linear-gradient(180deg, rgba(86, 62, 18, .34), rgba(34, 26, 12, .92));
  border-color: rgba(255, 208, 82, .72);
  border-left-color: #ffd052;
  box-shadow: inset 0 0 0 1px rgba(255, 225, 122, .14), 0 0 0 1px rgba(255, 208, 82, .08), 0 12px 28px rgba(255, 151, 24, .12);
}
.forged-card:hover {
  border-color: rgba(255, 225, 122, .92);
  border-left-color: #ffe17a;
  box-shadow: inset 0 0 0 1px rgba(255, 235, 160, .2), 0 0 0 1px rgba(255, 208, 82, .12), 0 14px 32px rgba(255, 151, 24, .18);
}
.prow.forged-card {
  margin: 6px -10px;
  padding: 14px 10px;
  border: 1px solid rgba(255, 208, 82, .5);
  border-left: 3px solid #ffd052;
  border-radius: 12px;
}
.prow.forged-card + .prow { border-top-color: transparent; }
.habit-top { display: flex; align-items: center; gap: 12px; min-width: 0; }
.habit-id { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.habit-icon { font-size: 22px; line-height: 1; flex: none; }
.habit-text { display: grid; gap: 2px; min-width: 0; overflow-wrap: anywhere; }
.habit-text small { color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.habit-meta { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.check {
  position: relative;
  width: 40px;
  height: 40px;
  flex: none;
  border-radius: 50%;
  border: 2px solid var(--line-strong);
  background: transparent;
  color: transparent;
  display: grid;
  place-items: center;
  transition: background .18s ease, border-color .18s ease, transform .18s ease;
}
.check svg { width: 22px; height: 22px; }
.check[aria-pressed="true"] { background: var(--hc, var(--accent)); border-color: var(--hc, var(--accent)); color: var(--accent-ink); }
.check:active { transform: scale(.88); }
.check.burst::after {
  content: "";
  position: absolute;
  inset: -8px;
  border-radius: 50%;
  border: 2px solid var(--hc, var(--accent));
  animation: check-burst .45s ease-out forwards;
  pointer-events: none;
}
@keyframes check-burst {
  from { transform: scale(.7); opacity: .9; }
  to { transform: scale(1.45); opacity: 0; }
}
.habit-meter { margin-top: 12px; display: grid; gap: 8px; }
.count-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.count-line { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; min-width: 0; }
.count-row .count-value { font: 600 14px var(--mono); font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.rescue-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 99px;
  border: 1px solid rgba(245, 185, 66, .55);
  background: rgba(245, 185, 66, .12);
  color: #f5cb74;
  font-size: 11px;
  font-weight: 600;
  white-space: normal;
  overflow-wrap: anywhere;
  hyphens: none;
}
.is-rescue .habit-meter progress { accent-color: #f5b942; }
.habit-card.is-rescue { border-left-color: #f5b942; }
.count-buttons { display: flex; gap: 6px; }
.count-buttons .ib { width: 38px; min-width: 38px; height: 38px; font-size: 20px; }
.habit-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-top: 8px; }
.note-editor { margin-top: 8px; display: grid; gap: 6px; }
.note-editor textarea { min-height: 62px; }
.rest-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.rest-chips span { font-size: 12px; color: var(--muted); padding: 4px 10px; border: 1px solid var(--line); border-radius: 99px; overflow-wrap: anywhere; }

/* Heatmap */
.heat-card .chead-actions { flex: 1; justify-content: flex-end; }
.hm-wrap { overflow-x: auto; padding-bottom: 4px; }
.hm-inner { min-width: 0; }
.hm-months, .hm-grid {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(6px, 1fr);
  gap: 3px;
}
.hm-months { margin-bottom: 5px; }
.hm-months span { font: 10px var(--mono); color: var(--faint); text-align: left; min-width: 0; overflow-wrap: anywhere; }
.hm-body { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 5px; }
.hm-days { display: grid; grid-template-rows: repeat(7, minmax(0, 1fr)); gap: 3px; }
.hm-days span { font: 9px var(--mono); color: var(--faint); display: flex; align-items: center; }
.hm-grid { grid-template-rows: repeat(7, minmax(0, 1fr)); }
.hm-cell {
  position: relative;
  aspect-ratio: 1;
  min-width: 0;
  padding: 0;
  border: 0;
  border-radius: 3px;
  background: var(--h0);
  display: block;
}
.hm-cell[data-l="1"] { background: color-mix(in srgb, var(--accent) 30%, var(--h0)); }
.hm-cell[data-l="2"] { background: color-mix(in srgb, var(--accent) 55%, var(--h0)); }
.hm-cell[data-l="3"] { background: color-mix(in srgb, var(--accent) 78%, var(--h0)); }
.hm-cell[data-l="4"] { background: var(--accent); }
.hm-cell[data-l="n"] { background: transparent; box-shadow: inset 0 0 0 1px var(--line); }
.hm-cell[data-l="r"] { background: var(--good); }
.hm-cell[data-l="f"] { visibility: hidden; }
.hm-cell.today { box-shadow: inset 0 0 0 2px var(--fg); }
.hm-cell.sel { outline: 2px solid var(--fg); outline-offset: 1px; }
.legend { display: flex; align-items: center; justify-content: flex-end; gap: 5px; margin-top: 12px; font-size: 12px; color: var(--muted); flex-wrap: wrap; }
.legend .c { width: 13px; height: 13px; aspect-ratio: auto; border-radius: 3px; }
.tooltip {
  position: fixed;
  z-index: 80;
  max-width: min(280px, calc(100vw - 24px));
  padding: 9px 12px;
  border-radius: 10px;
  background: var(--surface-3);
  border: 1px solid var(--line-strong);
  box-shadow: var(--shadow);
  color: var(--fg);
  font-size: 12px;
  line-height: 1.4;
  pointer-events: none;
  overflow-wrap: anywhere;
}
.hd { margin-top: 12px; font-size: 13px; color: var(--muted); min-height: 3em; display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; flex-wrap: wrap; overflow-wrap: anywhere; }
.hd strong { color: var(--fg); }

/* Comparison and stats */
.big { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.big b { font: 650 40px/1 var(--mono); font-variant-numeric: tabular-nums; }
.big span { color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.compare { display: grid; gap: 12px; }
.compare-row { display: grid; grid-template-columns: minmax(58px, auto) minmax(0, 1fr) 52px; gap: 10px; align-items: center; }
.compare-row .cl { font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
.compare-row .cv { font: 600 13px var(--mono); text-align: right; font-variant-numeric: tabular-nums; }
.compare-row.current .cl, .compare-row.current .cv { color: var(--fg); }
.insight { margin-top: 14px; font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.insight-list { display: grid; gap: 12px; counter-reset: insight; }
.insight-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: linear-gradient(180deg, var(--surface-2), var(--bg-2));
  min-width: 0;
}
.insight-num {
  flex: none;
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 9px;
  border: 1px solid var(--accent-soft);
  background: var(--accent-soft);
  color: var(--accent-2);
  font: 650 12px var(--mono);
}
.insight-copy { display: grid; gap: 4px; min-width: 0; overflow-wrap: anywhere; }
.insight-copy strong { font-size: 14px; overflow-wrap: anywhere; }
.insight-copy p { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.5; overflow-wrap: anywhere; }
.prow { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 8px 10px; align-items: center; padding: 12px 0; border-top: 1px solid var(--line); }
.habit-prow-group { min-width: 0; }
.habit-prow-group > .prow[data-a="habitCal"] { cursor: pointer; }
.prow:first-of-type { border-top: 0; }
.prow .pname { display: grid; gap: 3px; min-width: 0; overflow-wrap: anywhere; }
.prow .pname small { color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.pm { font: 12px var(--mono); color: var(--muted); text-align: right; overflow-wrap: anywhere; }
.pp { font: 650 14px var(--mono); min-width: 3.2em; text-align: right; }
.prow progress, .prow .forge-track { grid-column: 2 / -1; }

/* Monthly calendar per habit, inside Progreso > Por hábito. */
.habit-cal {
  display: grid;
  gap: 10px;
  margin: 6px 10px 14px;
  padding: 14px;
  border: 1px solid var(--line-strong);
  border-left: 3px solid var(--hc, var(--accent));
  border-radius: 12px;
  background: linear-gradient(180deg, var(--surface-2), var(--bg-2));
  min-width: 0;
}
.cal-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.cal-head strong { font-size: 14px; text-align: center; overflow-wrap: anywhere; }
.cal-head .btn { flex: 1 1 120px; }
.cal-weekdays, .cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 5px; }
.cal-weekdays span { text-align: center; font: 10px var(--mono); color: var(--faint); overflow-wrap: anywhere; }
.cal-blank { min-width: 0; }
.cal-day {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  min-width: 0;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  font: 600 12px var(--mono);
  display: grid;
  place-items: center;
  overflow-wrap: anywhere;
}
.cal-day:not(:disabled):hover { border-color: var(--accent); transform: translateY(-1px); }
.cal-day[aria-pressed="true"] { outline: 2px solid var(--fg); outline-offset: 1px; }
.cal-day[data-s="done"] { background: color-mix(in srgb, var(--hc, var(--good)) 62%, var(--good)); color: #06140d; border-color: var(--good); }
.cal-day[data-s="rescue"] { background: rgba(245, 185, 66, .32); color: #ffdc9a; border-color: #f5b942; }
.cal-day[data-s="shield"] { background: rgba(90, 169, 255, .3); color: #cfe8ff; border-color: #5aa9ff; }
.cal-day[data-s="rest"] { background: var(--surface-3); color: var(--muted); border-color: var(--line-strong); }
.cal-day[data-s="fail"] { background: rgba(248, 113, 113, .18); color: #f8a5a5; border-color: rgba(248, 113, 113, .45); }
.cal-day[data-s="pending"] { background: var(--surface-2); color: var(--fg); border-style: dashed; }
.cal-day[data-s="future"], .cal-day[data-s="empty"] { background: transparent; color: var(--faint); }
.cal-day[data-friction="1"]::after {
  content: "";
  position: absolute;
  right: 4px;
  bottom: 4px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #f5b942;
}
.cal-legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 11px; color: var(--muted); }
.cal-legend span { display: inline-flex; align-items: center; gap: 5px; overflow-wrap: anywhere; }
.cal-legend i { width: 11px; height: 11px; border-radius: 3px; border: 1px solid var(--line-strong); background: var(--surface-3); }
.cal-legend i[data-s="done"] { background: var(--good); border-color: var(--good); }
.cal-legend i[data-s="rescue"] { background: #f5b942; border-color: #f5b942; }
.cal-legend i[data-s="shield"] { background: #5aa9ff; border-color: #5aa9ff; }
.cal-legend i[data-s="rest"] { background: var(--surface-3); }
.cal-legend i[data-s="fail"] { background: rgba(248, 113, 113, .55); border-color: #f87171; }
.cal-detail {
  min-height: 2.6em;
  padding: 10px;
  border-radius: 10px;
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}
.cal-detail strong { color: var(--fg); }
@media (max-width: 699px) {
  .habit-cal { margin: 6px 0 14px; padding: 10px; }
  .cal-grid, .cal-weekdays { gap: 3px; }
  .cal-day { min-height: 32px; font-size: 11px; border-radius: 6px; }
  .cal-legend { gap: 8px; }
}
.report-grid { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.report-stat { background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 12px; display: grid; gap: 4px; }
.report-stat b { font: 650 22px var(--mono); }
.report-stat span { color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }

/* Habits manager */
.form-grid { display: grid; gap: 14px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 620px) { .form-grid { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); } }
.field { margin-top: 14px; }
.target-row { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); margin-top: 12px; }
.target-row > div { min-width: 0; }
.rescue-row { display: grid; gap: 6px; margin-top: 12px; padding: 12px; border: 1px dashed var(--line-strong); border-radius: 12px; background: var(--bg-2); }
.rescue-row > div { min-width: 0; }
.rescue-row .help { font-size: 12px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 18px; }
.data-actions { align-items: stretch; }
.data-actions > * { flex: 1 1 160px; }
.templates { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.template {
  display: grid;
  justify-items: start;
  gap: 4px;
  min-height: 88px;
  padding: 12px;
  border-radius: 12px;
  border: 1px dashed var(--line-strong);
  background: var(--bg);
  text-align: left;
  transition: transform .14s ease, border-color .14s ease;
}
.template:hover { border-color: var(--accent); transform: translateY(-2px); }
.template .t-icon { font-size: 22px; }
.template .t-name { font-weight: 600; overflow-wrap: anywhere; }
.template small { color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.habit-item { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 12px 0; border-top: 1px solid var(--line); }
.habit-item:first-of-type { border-top: 0; }
.habit-item .info { flex: 1 1 180px; min-width: 0; display: grid; gap: 3px; overflow-wrap: anywhere; }
.habit-item .info small { color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.habit-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; min-width: 0; }
.habit-actions > * { min-width: 0; max-width: 100%; }
.habit-actions .btn { min-height: 38px; padding: 6px 12px; font-size: 13px; }
.habit-actions .ib { width: 38px; min-width: 38px; height: 38px; font-size: 18px; }
@media (max-width: 699px) {
  .habit-item { align-items: flex-start; }
  .habit-actions {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    flex: 1 1 100%;
    width: 100%;
    justify-content: stretch;
  }
  .habit-actions .btn { width: 100%; min-height: 40px; padding: 6px 8px; font-size: 12px; }
  .habit-actions .ib { width: 100%; min-width: 0; height: 40px; }
}
.reminder-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.reminder-row input { width: 130px; }

/* Forge levels — one SVG emblem per rank, reused on Hoy and Progreso */
.forge-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-width: 0;
  max-width: 100%;
  padding: 2px 8px 2px 4px;
  border-radius: 99px;
  border: 1px solid var(--lv, var(--line-strong));
  background: color-mix(in srgb, var(--lv, var(--muted)) 16%, transparent);
  font: 600 10px var(--font);
  letter-spacing: .02em;
  color: var(--lv, var(--muted));
  white-space: normal;
  overflow-wrap: anywhere;
  hyphens: none;
  line-height: 1.2;
}
.forge-badge > span { min-width: 0; overflow-wrap: anywhere; }
.forge-emblem { width: 20px; height: 20px; flex: none; overflow: visible; }
.forge-badge[data-level="spark"] { --lv: #ffb63d; border-color: #ff9d2e; }
.forge-badge[data-level="bronze"] { --lv: #f0a45f; border-color: #ffc68b; }
.forge-badge[data-level="iron"] { --lv: #b3bcc8; border-color: #8f9aaa; background: color-mix(in srgb, #7b8797 24%, transparent); }
.forge-badge[data-level="steel"] { --lv: #8ff3ff; border-color: #cfffff; background: color-mix(in srgb, #35dfff 22%, transparent); box-shadow: 0 0 8px rgba(83, 232, 255, .24); }
.forge-badge[data-level="forged"] { --lv: #ffd052; border-color: #ffe17a; box-shadow: 0 0 10px rgba(255, 151, 24, .28); }
.forge-emblem[data-level="spark"] { filter: drop-shadow(0 0 3px rgba(255, 106, 0, .8)); }
.forge-emblem[data-level="bronze"] { filter: drop-shadow(0 0 3px rgba(232, 130, 55, .72)); }
.forge-emblem[data-level="iron"] { filter: drop-shadow(0 0 3px rgba(110, 124, 143, .75)) saturate(.45); }
.forge-emblem[data-level="steel"] { filter: drop-shadow(0 0 6px rgba(83, 232, 255, .95)) drop-shadow(0 0 12px rgba(200, 255, 255, .45)); }
.forge-emblem[data-level="forged"] { filter: drop-shadow(0 0 6px rgba(255, 151, 24, .9)); }
.forge-track { display: grid; gap: 4px; margin-top: 6px; }
.forge-track small { color: var(--faint); font-size: 10px; overflow-wrap: anywhere; }
.forge-track progress { height: 4px; }
.forge-line { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; min-width: 0; }

/* Routine launch + friction shortcuts */
.routine-btn { white-space: normal; text-align: center; overflow-wrap: anywhere; }
.habit-actions-inline { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.friction-tags { display: grid; gap: 8px; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); margin-top: 12px; }
.friction-tag {
  min-height: 44px;
  padding: 10px 12px;
  border-radius: 11px;
  border: 1px solid var(--line-strong);
  background: var(--surface-2);
  color: var(--fg);
  font-size: 13px;
  text-align: left;
  overflow-wrap: anywhere;
}
.friction-tag:hover, .friction-tag[aria-pressed="true"] { border-color: var(--accent); background: var(--surface-3); }
.friction-note { display: grid; gap: 8px; margin-top: 14px; }
.friction-note textarea { min-height: 80px; }
.friction-summary { display: grid; gap: 12px; }
.friction-stat {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 10px 12px;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: var(--bg);
  overflow-wrap: anywhere;
}
.friction-stat b { font: 650 17px var(--mono); color: var(--accent-2); text-align: right; overflow-wrap: anywhere; }
.friction-stat span { color: var(--muted); font-size: 12px; }
.habit-flag { animation: flag-flash 1.1s ease-out; }
@keyframes flag-flash { 0% { box-shadow: 0 0 0 2px var(--accent); } 100% { box-shadow: 0 0 0 0 transparent; } }

/* Template catalog — fixed, paginated grid; never scrolls horizontally */
.tpl-filters { margin: 10px 0 12px; flex-wrap: wrap; max-width: 100%; }
.tpl-filters button { min-width: 0; }
.templates { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; }
.templates.compact {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-rows: repeat(2, minmax(0, auto));
  grid-auto-flow: row;
  min-width: 0;
  width: 100%;
}
@media (max-width: 699px) {
  .templates.compact { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
.tpl-pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  margin: 0 0 12px;
}
.tpl-pager .btn { min-height: 44px; padding: 8px 14px; }
.tpl-page {
  min-width: 56px;
  color: var(--muted);
  font: 600 13px var(--mono);
  font-variant-numeric: tabular-nums;
  text-align: center;
  overflow-wrap: anywhere;
}
.tpl-wrap { position: relative; display: grid; min-width: 0; }
.tpl-wrap .template { width: 100%; height: 100%; min-height: 0; gap: 5px; padding: 10px; grid-template-columns: auto minmax(0, 1fr); align-items: start; }
.tpl-wrap.has-del .template { padding-right: 38px; }
.template .t-icon { font-size: 20px; line-height: 1.1; }
.template .t-body { display: grid; gap: 2px; min-width: 0; }
.template .t-cat { color: var(--faint); font-size: 9px; text-transform: uppercase; letter-spacing: .04em; overflow-wrap: anywhere; }
.template .t-name { font-weight: 600; font-size: 13px; line-height: 1.25; overflow-wrap: anywhere; }
.template small { color: var(--muted); font-size: 11px; line-height: 1.25; overflow-wrap: anywhere; }
.template .t-del {
  position: absolute;
  top: 6px;
  right: 6px;
  min-width: 28px;
  height: 28px;
  padding: 0 5px;
  border-radius: 8px;
  border: 1px solid var(--line-strong);
  background: var(--surface-2);
  color: var(--crit);
  font-size: 14px;
  line-height: 1;
  overflow-wrap: anywhere;
}
.template.added { border-style: solid; border-color: var(--accent); }

/* Contextual avoid / limit quick bar inside the habit form */
.avoid-quick {
  margin-top: 10px;
  padding: 10px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg);
}
.avoid-quick .lab { margin-bottom: 6px; }
.avoid-quick-list { display: flex; gap: 7px; flex-wrap: wrap; }
.avoid-tpl {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 38px;
  padding: 6px 10px;
  border-radius: 9px;
  border: 1px solid var(--line-strong);
  background: var(--surface-2);
  color: var(--fg);
  font-size: 12px;
  text-align: left;
  white-space: normal;
  hyphens: none;
  overflow-wrap: anywhere;
}
.avoid-tpl:hover { border-color: var(--accent); background: var(--surface-3); }

/* Modal / focus mode */
.modal {
  position: fixed;
  inset: 0;
  z-index: 95;
  display: grid;
  place-items: center;
  padding: calc(12px + env(safe-area-inset-top, 0px)) 12px calc(12px + env(safe-area-inset-bottom, 0px));
}
.modal-backdrop { position: absolute; inset: 0; background: rgba(3, 5, 9, .78); backdrop-filter: blur(4px); }
.modal-card {
  position: relative;
  width: min(100%, 520px);
  max-height: calc(100dvh - 24px);
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--radius);
  border: 1px solid var(--line-strong);
  background: linear-gradient(180deg, var(--surface-2), var(--surface));
  box-shadow: var(--shadow);
  padding: 18px;
  display: grid;
  gap: 14px;
}
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.modal-head h2, .modal-head h3 { font-size: 18px; overflow-wrap: anywhere; }
.modal-head p { color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.modal-close { width: 38px; height: 38px; flex: none; font-size: 20px; }
.focus-step {
  display: grid;
  justify-items: center;
  gap: 8px;
  text-align: center;
  padding: 12px 4px;
  overflow-wrap: anywhere;
}
.focus-icon {
  width: 72px; height: 72px;
  display: grid; place-items: center;
  border-radius: 20px;
  border: 1px solid var(--line-strong);
  border-left: 4px solid var(--hc, var(--accent));
  background: var(--bg);
  font-size: 34px;
  line-height: 1;
}
.focus-name { font-size: 21px; font-weight: 650; overflow-wrap: anywhere; }
.focus-meta { color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.focus-timer { display: grid; gap: 10px; justify-items: center; width: 100%; padding: 12px; border-radius: 12px; background: var(--bg); border: 1px solid var(--line); }
.timer-display { font: 650 32px/1 var(--mono); font-variant-numeric: tabular-nums; }
.timer-presets { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; width: 100%; }
.timer-presets button { flex: 1 1 54px; min-height: 38px; border-radius: 9px; border: 1px solid var(--line-strong); background: var(--surface); }
.timer-presets button[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); color: var(--fg); }
.timer-custom { display: flex; gap: 8px; align-items: center; justify-content: center; width: 100%; }
.timer-custom input { width: 76px; text-align: center; }
.timer-row { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.modal-actions { display: grid; gap: 8px; grid-template-columns: minmax(0, 1fr); }
.modal-actions .btn { min-height: 44px; overflow-wrap: anywhere; }
@media (min-width: 480px) { .modal-actions { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.done-panel { display: grid; justify-items: center; gap: 8px; text-align: center; padding: 14px 4px; overflow-wrap: anywhere; }
.done-mark { width: 64px; height: 64px; display: grid; place-items: center; border-radius: 50%; background: var(--good); color: #04130d; font-size: 30px; }
.done-mark svg { width: 34px; height: 34px; }
.done-panel p { color: var(--muted); font-size: 14px; }
body.modal-open { overflow: hidden; }

/* Toast */
#toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  z-index: 90;
  transform: translate(-50%, 12px);
  background: var(--surface-3);
  border: 1px solid var(--line-strong);
  padding: 10px 16px;
  border-radius: 11px;
  font-size: 13px;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
  max-width: calc(100vw - 24px);
  text-align: center;
  overflow-wrap: anywhere;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
.noscript { padding: 24px; text-align: center; }

@media (min-width: 700px) {
  #toast { bottom: 24px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
