/* =============================================================================
   Daily Habits — styles. Mobile-first, calm palette, follows light/dark mode.
============================================================================= */
:root {
  --bg: #f7f5f1;
  --card: #ffffff;
  --ink: #26282b;
  --muted: #8a8780;
  --line: #e9e5de;
  --accent: #3d7f7a;        /* deep teal */
  --accent-soft: #e2efed;
  --green: #4f9a68;
  --green-soft: #e4f1e8;
  --amber: #c8962e;
  --red: #cf5b4e;
  --red-soft: #f8e2df;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 1px 2px rgba(38,40,43,.04), 0 6px 20px rgba(38,40,43,.06);
  --bar: rgba(247,245,241,.86);
  --tabbar: rgba(255,255,255,.92);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161718;
    --card: #212325;
    --ink: #ecebe8;
    --muted: #9a978f;
    --line: #33363a;
    --accent: #6cb8b1;
    --accent-soft: #23393a;
    --green: #6cbb86;
    --green-soft: #213528;
    --red: #e47c70;
    --red-soft: #3b2522;
    --shadow: 0 1px 2px rgba(0,0,0,.3);
    --bar: rgba(22,23,24,.86);
    --tabbar: rgba(33,35,37,.94);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(74px + env(safe-area-inset-bottom));
}

/* ---------- header ---------- */
.app-bar {
  position: sticky; top: 0; z-index: 20;
  background: var(--bar);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--line);
  padding: calc(env(safe-area-inset-top) + 12px) 18px 12px;
  display: flex; align-items: baseline; justify-content: space-between; gap: 10px;
}
.app-bar h1 { font-size: 19px; margin: 0; letter-spacing: -.01em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.app-bar .sub { font-size: 12.5px; color: var(--muted); white-space: nowrap; }

/* ---------- layout ---------- */
#view { padding: 16px 16px 24px; max-width: 640px; margin: 0 auto; }
.section-title { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 22px 4px 10px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.help { font-size: 13px; color: var(--muted); line-height: 1.5; margin: 0 0 12px; }
.help.pad { margin: -2px 4px 12px; }
.center { text-align: center; }
.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.spacer { flex: 1; }
.empty { text-align: center; color: var(--muted); padding: 32px 16px; }
hr.soft { border: none; border-top: 1px solid var(--line); margin: 16px 0; }
h2 { font-size: 18px; margin: 0 0 6px; letter-spacing: -.01em; }

/* ---------- cards ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px; }
.card.tight { padding: 12px 14px; }

/* ---------- today hero ---------- */
.hero { padding: 4px 4px 14px; }
.hero-date { font-size: 24px; font-weight: 750; letter-spacing: -.015em; }
.hero-phase { font-size: 14px; color: var(--muted); margin-top: 2px; }
.pills { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.pill { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 700; padding: 4px 10px 4px 8px;
  border-radius: 999px; background: var(--cb); color: var(--ink); white-space: nowrap; }
.pill::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--c); }
.notice { background: var(--accent-soft); border-radius: var(--radius-sm); padding: 10px 13px; font-size: 13.5px; margin-bottom: 14px; }

/* ---------- routine checklist ---------- */
.rc-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 4px; }
.rc-title { font-size: 17px; font-weight: 700; }
.rc-count { font-size: 13px; font-weight: 700; color: var(--muted); font-variant-numeric: tabular-nums; }
.rc-count.all { color: var(--green); }
.routine-card.complete { border-color: var(--green); box-shadow: 0 0 0 2px var(--green-soft), var(--shadow); }

.item { display: flex; align-items: center; gap: 12px; padding: 11px 0; border-top: 1px solid var(--line); transition: opacity .15s; }
.items .item:first-child { border-top: none; }
.item .info { flex: 1; min-width: 0; }
.item .nm { font-weight: 600; display: flex; align-items: center; flex-wrap: wrap; gap: 6px; }
.item .note { font-size: 12.5px; color: var(--muted); margin-top: 1px; }
.item.done .nm { color: var(--muted); text-decoration: line-through; }
.item.locked { opacity: .42; }
.check { width: 30px; height: 30px; flex: 0 0 auto; border-radius: 50%; border: 2px solid var(--line); background: var(--card);
  color: transparent; font-size: 15px; font-weight: 800; line-height: 1; cursor: pointer; transition: .12s; padding: 0; }
.item.optional .check { border-style: dashed; }
.check:not(:disabled):hover { border-color: var(--green); }
.check.on { background: var(--green); border-color: var(--green); color: #fff; border-style: solid; }
.check:disabled { cursor: default; }

.tag { font-size: 10.5px; font-weight: 700; padding: 2px 7px; border-radius: 999px; letter-spacing: .03em; white-space: nowrap; text-decoration: none; display: inline-block; }
.tag.opt { background: var(--bg); color: var(--muted); border: 1px solid var(--line); }
.tag.addon { background: var(--cb); color: var(--c); }
.tag.now { background: var(--accent-soft); color: var(--accent); }

.timer { flex: 0 0 auto; border: 1px solid var(--accent); background: var(--accent-soft); color: var(--accent); border-radius: 999px;
  padding: 7px 12px; font-size: 13.5px; font-weight: 700; font-variant-numeric: tabular-nums; cursor: pointer; font-family: inherit; }
.timer:disabled { opacity: .6; cursor: default; }
.timer.run { background: var(--accent); color: #fff; animation: pulse 2s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 5px var(--accent-soft); } }
.timer-lab { font-size: 12.5px; color: var(--muted); white-space: nowrap; }

.note-field { width: 100%; border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 11px 13px; font: inherit; font-size: 15px;
  background: var(--card); color: var(--ink); resize: vertical; }
.note-field:focus { outline: none; border-color: var(--accent); }

/* ---------- calendar ---------- */
.cal-nav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.cal-title { font-size: 18px; font-weight: 700; }
.cal-nav .icon-btn { font-size: 28px; padding: 2px 14px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; margin: 8px 0 14px; }
.cal-wd { text-align: center; font-size: 11px; font-weight: 700; color: var(--muted); padding-bottom: 2px; }
.cal-cell { position: relative; aspect-ratio: 1 / 1.08; border-radius: 10px; border: 1px solid var(--line); background: var(--card);
  padding: 4px; cursor: pointer; font-family: inherit; color: var(--ink); text-align: left; min-width: 0; }
.cal-cell.blank { border: none; background: none; cursor: default; }
.cal-cell.today { outline: 2px solid var(--accent); outline-offset: 1px; }
.cal-cell.phase-start { border-left: 4px solid var(--ink); }
.cal-cell.slowed::after { content: '🐢'; position: absolute; right: 3px; bottom: 2px; font-size: 10px; }
.cal-num { font-size: 13px; font-weight: 700; }
.cal-note, .cal-note.static { position: absolute; top: 5px; right: 5px; width: 6px; height: 6px; border-radius: 50%; background: var(--ink); opacity: .7; }
.cal-note.static { position: static; display: inline-block; }
.cal-mark { position: absolute; right: 4px; bottom: 11px; }
.cal-mark.done { width: 18px; height: 18px; border-radius: 50%; background: var(--green); color: #fff; font-size: 11px; font-weight: 800;
  display: flex; align-items: center; justify-content: center; }
.cal-mark.part { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--green); background: linear-gradient(90deg, var(--green) 50%, transparent 50%); }
.cal-mark.miss { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); opacity: .45; }
.cal-mark.static { position: static; transform: none; display: inline-flex; vertical-align: middle; }
.cal-addons { position: absolute; left: 4px; right: 4px; bottom: 4px; display: flex; gap: 2px; }
.cal-addons i { flex: 1; height: 4px; border-radius: 2px; }
.legend-row { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12.5px; padding: 4px 0; }
.lg { display: inline-flex; align-items: center; gap: 6px; }
.lg > i { width: 14px; height: 14px; border-radius: 4px; display: inline-block; }
.lg > i.dot { width: 14px; height: 4px; border-radius: 2px; }
.phase-key { display: inline-block; width: 4px; height: 14px; background: var(--ink); border-radius: 2px; }
.phase-row { display: flex; align-items: baseline; gap: 10px; padding: 7px 0; border-top: 1px solid var(--line); flex-wrap: wrap; }
.phase-row:first-child { border-top: none; }
.phase-row.current b { color: var(--accent); }

.modal-routine { margin-bottom: 16px; }

/* ---------- setup ---------- */
.guide h2 { margin-bottom: 10px; }
.guide-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.guide-row:first-of-type { border-top: none; }
.guide-row .info { flex: 1; }
.guide-n { width: 28px; height: 28px; flex: 0 0 auto; border-radius: 50%; background: var(--accent-soft); color: var(--accent);
  display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 13px; }
.guide-row.done .guide-n { background: var(--green); color: #fff; }
.guide-row.done b { color: var(--muted); text-decoration: line-through; }

.list-row { display: flex; align-items: center; gap: 12px; width: 100%; padding: 11px 0; border: none; border-top: 1px solid var(--line);
  background: none; font-family: inherit; color: var(--ink); text-align: left; cursor: pointer; }
.card > .list-row:first-child { border-top: none; padding-top: 2px; }
.list-row .info { flex: 1; min-width: 0; }
.list-row .nm { font-weight: 600; }
.list-row .meta { font-size: 12.5px; color: var(--muted); }
.chev { color: var(--muted); font-size: 20px; }
.rt-ic { font-size: 22px; width: 28px; text-align: center; }
.dot.big { width: 12px; height: 12px; border-radius: 50%; flex: 0 0 auto; }

.back { margin: -4px 0 10px -6px; }
.grid-name { display: grid; grid-template-columns: 70px 1fr; gap: 0 12px; }
.dt-card .dt-name { font-weight: 700; font-size: 16px; }
.dt-card input[type=color] { width: 44px; height: 42px; padding: 2px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--card); flex: 0 0 auto; }
.dt-items { margin: 8px 0 10px; }
.dt-item { display: flex; align-items: center; gap: 8px; padding: 7px 0; border-top: 1px dashed var(--line); }
.dt-item:first-child { border-top: none; }
.dt-item .info { flex: 1; min-width: 0; font-size: 14.5px; }
.dt-item .ord { display: flex; flex-direction: column; }
.opt-toggle { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 4px; white-space: nowrap; }
.opt-toggle input { margin: 0; }
.wd-grid { display: grid; grid-template-columns: 1fr; gap: 6px; margin-bottom: 12px; }
.wd-row { display: grid; grid-template-columns: 44px 1fr; align-items: center; gap: 8px; font-size: 13.5px; font-weight: 600; }
.small-field select { font-size: 14px; }
.phase-card.collapsed { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; cursor: pointer; font-family: inherit; color: var(--ink); padding: 13px 16px; }
.phase-card.collapsed .info { flex: 1; min-width: 0; }
.rot-row { margin-bottom: 6px; }
.rot-row > span { width: 44px; flex: 0 0 auto; }

.pv-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.pv-cell { border: 1px solid var(--line); border-radius: 8px; padding: 4px 3px; text-align: center; min-width: 0; background: var(--card); }
.pv-wd { display: block; font-size: 10px; color: var(--muted); text-transform: uppercase; }
.pv-d { display: block; font-size: 14px; font-weight: 700; }
.pv-t { display: block; font-size: 9.5px; line-height: 1.15; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- buttons ---------- */
button { font-family: inherit; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; border: 1px solid var(--line); background: var(--card); color: var(--ink);
  border-radius: var(--radius-sm); padding: 10px 14px; font-size: 14px; font-weight: 600; cursor: pointer; transition: .12s; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.sm { padding: 7px 11px; font-size: 13px; }
.btn.danger { color: var(--red); }
.btn.danger:not(.ghost) { border-color: var(--red-soft); }
.btn-row { display: flex; gap: 9px; flex-wrap: wrap; align-items: center; margin-top: 10px; }
.btn-row.end { justify-content: flex-end; margin-top: 16px; }
.icon-btn { background: none; border: none; cursor: pointer; font-size: 17px; color: var(--muted); padding: 4px 6px; }
.icon-btn:disabled { opacity: .3; cursor: default; }
.icon-btn.xs { font-size: 10px; padding: 1px 4px; line-height: 1.1; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0 14px; }
.chip { display: inline-flex; align-items: center; gap: 6px; background: var(--bg); border: 1px solid var(--line); border-radius: 999px;
  padding: 7px 12px; font-size: 13.5px; color: var(--ink); cursor: pointer; }
.chip input { margin: 0; }
.swatch { width: 30px; height: 30px; border-radius: 50%; border: 3px solid transparent; cursor: pointer; padding: 0; }
.swatch.on { border-color: var(--ink); }
.wd-pick { display: flex; gap: 5px; margin: -4px 0 14px; }
.wd-btn { flex: 1; padding: 9px 0; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); font-size: 12.5px; font-weight: 700; cursor: pointer; }
.wd-btn.on { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ---------- forms ---------- */
label.field { display: block; margin-bottom: 12px; font-size: 13px; font-weight: 600; }
label.field span, .field-lab { display: block; color: var(--muted); font-weight: 500; font-size: 12px; margin-bottom: 4px; }
input[type=number], input[type=text], input[type=date], select {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  font-size: 16px; font-family: inherit; background: var(--bg); color: var(--ink); min-width: 0;
}
input:focus, select:focus { outline: none; border-color: var(--accent); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.checkrow { display: flex; align-items: center; gap: 9px; font-size: 14px; margin: 4px 0 14px; }
.checkrow input { width: auto; margin: 0; }

/* ---------- modal ---------- */
.overlay { position: fixed; inset: 0; background: rgba(20,20,22,.45); display: flex; align-items: flex-end; justify-content: center; z-index: 50; }
.modal { background: var(--card); width: 100%; max-width: 520px; border-radius: 22px 22px 0 0; padding: 20px 18px calc(20px + env(safe-area-inset-bottom));
  max-height: 90vh; overflow-y: auto; box-shadow: 0 -8px 40px rgba(0,0,0,.18); }
.modal h3 { margin: 0 0 14px; font-size: 18px; }

/* ---------- bottom nav ---------- */
.tabbar { position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  background: var(--tabbar); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line); display: flex; justify-content: space-around;
  padding: 8px 6px calc(8px + env(safe-area-inset-bottom)); }
.tab { flex: 1; background: none; border: none; cursor: pointer; color: var(--muted); font-size: 11px; font-weight: 600;
  display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 4px; border-radius: 10px; }
.tab .ic { font-size: 21px; line-height: 1; }
.tab.active { color: var(--accent); }

/* ---------- toast ---------- */
.toast { position: fixed; left: 50%; bottom: calc(86px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 11px 18px; border-radius: 999px; font-size: 13.5px; font-weight: 600;
  box-shadow: 0 8px 24px rgba(0,0,0,.25); z-index: 60; opacity: 0; transition: opacity .25s, transform .25s; pointer-events: none; white-space: nowrap; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(-4px); }
