/* HabitTracker — clean iOS-inspired styling, light + dark. */

:root {
  --accent: #34c759;
  --bg: #f2f2f7;
  --bg-elevated: #ffffff;
  --card: #ffffff;
  --text: #1c1c1e;
  --muted: #8e8e93;
  --separator: rgba(60, 60, 67, 0.12);
  --danger: #ff3b30;
  --fill: rgba(120, 120, 128, 0.12);
  --radius: 14px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --bg-elevated: #1c1c1e;
    --card: #1c1c1e;
    --text: #ffffff;
    --muted: #98989f;
    --separator: rgba(84, 84, 88, 0.4);
    --fill: rgba(120, 120, 128, 0.24);
  }
}

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

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, system-ui, sans-serif;
  font-size: 17px;
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; font-size: inherit; color: inherit; cursor: pointer; border: none; background: none; }

#app { display: flex; flex-direction: column; min-height: 100%; }

.screen { display: flex; flex-direction: column; flex: 1; padding-bottom: 76px; }

/* ---- Top bar ---- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: grid; grid-template-columns: 64px 1fr 64px; align-items: center;
  padding: calc(var(--safe-top) + 6px) 10px 8px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 0.5px solid var(--separator);
}
.topbar-title { margin: 0; font-size: 18px; font-weight: 700; text-align: center; }
.topbar-side { display: flex; align-items: center; }
.topbar-side.right { justify-content: flex-end; }

.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px; border-radius: 50%; color: var(--accent); }
.icon-btn.add { font-size: 26px; font-weight: 300; }
.icon-btn.dim { color: var(--muted); width: 36px; height: 36px; }

/* ---- Scroll area ---- */
.scroll { flex: 1; overflow-y: auto; padding: 14px; -webkit-overflow-scrolling: touch; }

/* ---- Home cards ---- */
.card-list { background: var(--card); border-radius: var(--radius); overflow: hidden; }
.card-row {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 14px 14px; text-align: left;
  border-bottom: 0.5px solid var(--separator);
}
.card-row:last-child { border-bottom: none; }
.card-row:active { background: var(--fill); }
.row-lead { display: flex; color: var(--muted); }
.row-main { flex: 1; min-width: 0; }
.row-title { font-weight: 600; }
.row-sub { display: flex; align-items: center; gap: 6px; margin-top: 4px; font-size: 13px; color: var(--muted); }
.row-sub.small { font-size: 12px; margin-top: 2px; }
.muted { color: var(--muted); }

.progress { flex: 1; max-width: 160px; height: 6px; border-radius: 3px; background: var(--fill); overflow: hidden; }
.progress-fill { height: 100%; background: var(--accent); border-radius: 3px; }

/* ---- Tree ---- */
.tree { background: var(--card); border-radius: var(--radius); overflow: hidden; margin-bottom: 14px; }
.node {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 12px; border-bottom: 0.5px solid var(--separator);
}
.node:last-child { border-bottom: none; }
.node.depth-1 { padding-left: 30px; background: color-mix(in srgb, var(--card) 96%, var(--muted)); }
.node.depth-2 { padding-left: 50px; background: color-mix(in srgb, var(--card) 92%, var(--muted)); }

.check { display: flex; flex: 0 0 auto; padding: 2px; color: var(--muted); }
.check-done { color: var(--accent); display: flex; }
.icon svg { width: 26px; height: 26px; display: block; }
.icon-btn .icon svg, .dim .icon svg { width: 22px; height: 22px; }

.node-main { display: flex; align-items: center; gap: 6px; flex: 1; min-width: 0; }
.node-text { min-width: 0; }
.node-title { display: inline-flex; align-items: center; gap: 7px; font-size: 16px; }
.node-title.done { color: var(--muted); text-decoration: line-through; }

.disclosure { display: inline-flex; color: var(--muted); transition: transform 0.18s ease; }
.disclosure svg { width: 18px; height: 18px; }
.disclosure.open { transform: rotate(90deg); }
.disclosure-spacer { width: 18px; }

.badge { font-size: 12px; font-variant-numeric: tabular-nums; color: var(--muted); background: var(--fill); padding: 3px 8px; border-radius: 10px; }
.tag-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.tag-dot.sm { width: 8px; height: 8px; }

.hint, .panel h3 { color: var(--muted); }
.hint { text-align: center; font-size: 14px; padding: 24px 12px; }

/* ---- Empty states ---- */
.empty { text-align: center; padding: 70px 28px; color: var(--muted); }
.empty.small { padding: 40px 20px; }
.empty-emoji { font-size: 52px; margin-bottom: 8px; }
.empty h2 { color: var(--text); margin: 8px 0; font-size: 20px; }
.empty p { font-size: 15px; line-height: 1.4; }

.btn-primary { margin-top: 18px; background: var(--accent); color: #fff; font-weight: 600; padding: 12px 22px; border-radius: 12px; }
.btn-primary:active { opacity: 0.85; }

/* ---- Tab bar ---- */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 5;
  display: flex; padding-bottom: var(--safe-bottom);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: 0.5px solid var(--separator);
}
.tab { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0 6px; font-size: 11px; color: var(--muted); }
.tab.active { color: var(--accent); }
.tab-emoji { font-size: 22px; filter: grayscale(0.2); }

/* ---- Overlays / sheets ---- */
.overlay { position: fixed; inset: 0; z-index: 20; background: rgba(0,0,0,0.4); display: flex; align-items: flex-start; justify-content: center; padding: 0; animation: fade 0.2s ease; }
.overlay.bottom { align-items: flex-end; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.sheet-card {
  width: 100%; max-width: 560px; margin-top: calc(var(--safe-top) + 24px);
  background: var(--bg); border-radius: 18px 18px 0 0; min-height: 60vh;
  display: flex; flex-direction: column; animation: rise 0.26s cubic-bezier(.2,.8,.2,1);
}
@keyframes rise { from { transform: translateY(40px); opacity: 0.6; } to { transform: translateY(0); opacity: 1; } }
.sheet-head { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; padding: 16px; border-bottom: 0.5px solid var(--separator); }
.sheet-head .link { color: var(--accent); }
.sheet-head .link:first-child { text-align: left; }
.sheet-head .link.strong { text-align: right; font-weight: 700; }
.sheet-body { padding: 16px; overflow-y: auto; padding-bottom: calc(var(--safe-bottom) + 24px); }

.form-section { margin-bottom: 18px; }
.form-label { font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.4px; margin: 0 6px 7px; }
.form-card { background: var(--card); border-radius: var(--radius); padding: 6px 12px; }
.form-card > * { margin: 8px 0; }

.field { width: 100%; border: none; background: transparent; color: var(--text); font-size: 16px; padding: 8px 0; outline: none; resize: none; }
textarea.field { line-height: 1.4; }
select.field { -webkit-appearance: none; appearance: none; }

.list-row { display: flex; align-items: center; gap: 8px; padding: 8px 0; }
.spacer { flex: 1; }

/* chips */
.chips { display: flex; flex-wrap: wrap; gap: 8px; padding: 6px 0; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: 20px; background: var(--fill); border: 1.5px solid transparent; font-size: 14px; }
.chip.selected { font-weight: 600; }

/* segmented */
.segmented { display: flex; background: var(--fill); border-radius: 9px; padding: 2px; gap: 2px; }
.seg { flex: 1; padding: 7px 4px; border-radius: 7px; font-size: 13px; color: var(--text); }
.seg.active { background: var(--bg-elevated); font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,0.12); }

/* weekday chips */
.weekdays { display: flex; gap: 6px; justify-content: space-between; padding: 4px 0; }
.wd { width: 38px; height: 38px; border-radius: 50%; background: var(--fill); font-weight: 600; font-size: 14px; }
.wd.on { background: var(--accent); color: #fff; }

/* switch */
.switch { width: 51px; height: 31px; border-radius: 16px; background: var(--fill); position: relative; transition: background 0.2s; }
.switch.on { background: var(--accent); }
.switch .knob { position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%; background: #fff; transition: transform 0.2s; box-shadow: 0 1px 3px rgba(0,0,0,0.3); }
.switch.on .knob { transform: translateX(20px); }

.summary { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 14px; }

/* action sheet (bottom) */
.sheet { width: 100%; max-width: 480px; margin: 8px; margin-bottom: calc(var(--safe-bottom) + 8px); display: flex; flex-direction: column; gap: 8px; animation: rise 0.24s ease; }
.sheet-btn { background: var(--bg-elevated); padding: 16px; border-radius: 14px; font-size: 17px; color: var(--accent); }
.sheet-btn.danger { color: var(--danger); }
.sheet-btn.cancel { font-weight: 700; color: var(--text); }

/* ---- Stats ---- */
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 16px; }
.stat-card { background: var(--card); border-radius: var(--radius); padding: 16px; }
.stat-emoji { font-size: 24px; }
.stat-value { font-size: 34px; font-weight: 800; letter-spacing: -1px; margin: 4px 0; font-variant-numeric: tabular-nums; }
.stat-label { font-size: 12px; color: var(--muted); }

.panel { background: var(--card); border-radius: var(--radius); padding: 16px; }
.panel h3 { margin: 0 0 12px; font-size: 16px; color: var(--text); }
.heatmap { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cell { aspect-ratio: 1; border-radius: 6px; background: var(--fill); display: flex; align-items: center; justify-content: center; font-size: 10px; color: var(--muted); }
.cell.on { background: var(--accent); color: #fff; font-weight: 600; }

/* ---- Settings ---- */
.status-line { display: flex; align-items: center; gap: 10px; padding: 6px 2px 12px; font-size: 15px; }
.status-emoji { font-size: 20px; }
.btn-row { display: block; width: 100%; text-align: center; padding: 13px; border-radius: 12px; background: var(--fill); color: var(--accent); font-weight: 600; margin-top: 8px; }
.btn-row.primary { background: var(--accent); color: #fff; }
.btn-row.danger { color: var(--danger); }
.btn-row:active { opacity: 0.85; }
.panel.about { margin-bottom: 14px; }
.panel.about p { margin: 6px 0; font-size: 14px; }

/* ---- Phase 3: Today, rings, notes, reordering ---- */
.row-note {
  font-size: 13px; color: var(--muted); margin-top: 2px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%;
}
.row-title.done { text-decoration: line-through; color: var(--muted); }
.row-title { display: inline-flex; align-items: center; gap: 7px; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }

.ring svg { width: 28px; height: 28px; display: block; }
.row-lead.chev { color: var(--muted); }
.row-tag { flex: 0 0 auto; }

.card-row.static:active { background: transparent; }
.card-row .row-main { cursor: default; }

/* Today */
.today-head { padding: 2px 6px 14px; }
.today-date { font-size: 14px; color: var(--muted); text-transform: capitalize; }
.today-count { font-size: 24px; font-weight: 800; letter-spacing: -0.5px; margin-top: 2px; }
.time-pill { display: inline-flex; align-items: center; gap: 4px; color: var(--accent); font-weight: 600; font-variant-numeric: tabular-nums; }
.time-pill .icon svg { width: 15px; height: 15px; }
.row-sub .ellipsis { font-size: 13px; }

/* Sync code */
.code-box { display: flex; align-items: center; gap: 10px; background: var(--fill); border-radius: 10px; padding: 10px 12px; margin: 4px 0 8px; }
.code { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 16px; letter-spacing: 1px; font-weight: 600; flex: 1; word-break: break-all; }
.mini-btn { background: var(--accent); color: #fff; font-size: 13px; font-weight: 600; padding: 6px 12px; border-radius: 8px; flex: 0 0 auto; }
.small-note { font-size: 13px; margin: 4px 2px 10px; }
