:root {
  color-scheme: light;
  --bg: #f6f6f3;
  --surface: #fcfcfb;
  --surface-2: #efeee9;
  --border: #e0dfd8;
  --border-strong: #c9c8bf;
  --text: #171716;
  --text-2: #52514e;
  --muted: #7a7974;
  --accent: #13795b;
  --accent-ink: #ffffff;
  --accent-soft: #e2f1ea;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --good: #1a7f4b;
  --warn: #9a6200;
  --focus: #2a78d6;
  --s1: #2a78d6; --s2: #eb6834; --s8: #e34948;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.04);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --nav-w: 216px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121211; --surface: #1a1a19; --surface-2: #262624; --border: #2e2e2b; --border-strong: #42423e;
    --text: #f0efec; --text-2: #c3c2b7; --muted: #8f8e86;
    --accent: #45c08f; --accent-ink: #0b1a14; --accent-soft: #173027;
    --danger: #f2877d; --danger-soft: #3a1e1b; --good: #4cc38a; --warn: #e0a83a; --focus: #5aa7de;
    --s1: #3987e5; --s2: #d95926; --s8: #e66767;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211; --surface: #1a1a19; --surface-2: #262624; --border: #2e2e2b; --border-strong: #42423e;
  --text: #f0efec; --text-2: #c3c2b7; --muted: #8f8e86;
  --accent: #45c08f; --accent-ink: #0b1a14; --accent-soft: #173027;
  --danger: #f2877d; --danger-soft: #3a1e1b; --good: #4cc38a; --warn: #e0a83a; --focus: #5aa7de;
  --s1: #3987e5; --s2: #d95926; --s8: #e66767;
  --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text); font: 15px/1.45 var(--font);
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.2; margin: 0; }
h1 { font-size: 24px; font-weight: 650; letter-spacing: -.01em; }
h2 { font-size: 16px; font-weight: 600; }
.muted { color: var(--muted); }
.error { color: var(--danger); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.num { font-variant-numeric: tabular-nums; }

/* boot + sign-in */
.boot { position: fixed; inset: 0; display: grid; place-items: center; }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--border); border-top-color: var(--accent); animation: spin .8s linear infinite; margin: 0 auto; }
@keyframes spin { to { transform: rotate(360deg); } }
.signin { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.signin-card { width: 100%; max-width: 360px; text-align: center; background: var(--surface); border: 1px solid var(--border); border-radius: 18px; padding: 36px 28px; box-shadow: var(--shadow); }
.signin-logo { border-radius: 16px; margin-bottom: 16px; }
.signin-card p { margin: 8px 0 24px; }

/* buttons & inputs */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 40px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 550; cursor: pointer; text-decoration: none;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }
.btn-danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn-danger:hover { background: var(--danger-soft); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-sm { min-height: 32px; padding: 0 12px; font-size: 13px; }
.btn-google { width: 100%; min-height: 46px; }
.icon-btn {
  display: inline-grid; place-items: center; width: 40px; height: 40px; flex: none; border-radius: 10px;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); cursor: pointer; padding: 0;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn.disabled, .icon-btn:disabled { opacity: .35; cursor: default; background: var(--surface); }
.icon-btn.sm { width: 32px; height: 32px; border-color: transparent; background: transparent; color: var(--muted); }
.icon-btn.sm:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
.icon-btn.sm.danger:hover { background: var(--danger-soft); color: var(--danger); }
.icon-btn.sm svg { width: 18px; height: 18px; }

input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface); width: 100%;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm); padding: 9px 11px; min-height: 42px;
}
select { width: auto; max-width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--focus); outline-offset: -1px; border-color: transparent; }
label.field { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--text-2); font-weight: 550; min-width: 0; }

/* layout */
.app { min-height: 100dvh; }
.nav { position: fixed; z-index: 20; display: flex; background: var(--surface); border-color: var(--border); }
.nav-link { display: flex; align-items: center; gap: 10px; color: var(--text-2); text-decoration: none; font-weight: 550; font-size: 14px; border-radius: 10px; }
.nav-link svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.nav-link.active { color: var(--accent); background: var(--accent-soft); }
.nav-brand { display: flex; align-items: center; gap: 10px; font-weight: 650; font-size: 16px; }
.nav-brand img { border-radius: 7px; }
.sync { font-size: 12px; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
.sync::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--good); }
.sync.off::before { background: var(--warn); }

.view { padding: 20px 16px calc(96px + var(--safe-b)); max-width: 1200px; margin: 0 auto; outline: none; }

@media (min-width: 860px) {
  .nav { inset: 0 auto 0 0; width: var(--nav-w); flex-direction: column; gap: 4px; padding: 20px 12px; border-right: 1px solid var(--border); }
  .nav-brand { padding: 4px 10px 20px; }
  .nav-link { padding: 10px; }
  .nav-foot { margin-top: auto; padding: 10px; }
  .view { margin-left: var(--nav-w); padding: 28px 32px 48px; }
}
@media (max-width: 859.98px) {
  .nav { inset: auto 0 0 0; border-top: 1px solid var(--border); padding: 6px 8px calc(6px + var(--safe-b)); justify-content: space-around; }
  .nav-brand, .nav-foot { display: none; }
  .nav-link { flex-direction: column; gap: 2px; font-size: 11px; padding: 6px 4px; min-width: 64px; background: none !important; }
}

/* page header */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head .sub { color: var(--muted); font-size: 13px; margin-top: 4px; }

/* cards & tiles */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); min-width: 0; }
.card + .card { margin-top: 16px; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.card-head .muted { font-size: 12.5px; }
.tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
@media (min-width: 700px) { .tiles { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); min-width: 0; }
.tile .label { font-size: 12px; color: var(--muted); font-weight: 550; }
.tile .value { font-size: 28px; font-weight: 650; letter-spacing: -.02em; margin-top: 2px; }
.tile .note { font-size: 12px; color: var(--text-2); }
.grid-2 { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr); margin-top: 16px; }
@media (min-width: 1000px) { .grid-2 { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); } }
.grid-2 .card + .card { margin-top: 0; }
.grid-2 + .card { margin-top: 16px; }

/* today */
.day-head { display: flex; align-items: center; gap: 8px; margin-bottom: 16px; }
.day-title { flex: 1; min-width: 0; text-align: center; }
.day-title h1 { font-size: 22px; }
.day-title h1 .muted { font-weight: 500; }
.day-title .sub { color: var(--muted); font-size: 13px; margin-top: 3px; }
.date-pick { position: relative; overflow: hidden; }
.date-pick input { position: absolute; inset: 0; opacity: 0; cursor: pointer; min-height: 0; padding: 0; border: 0; }
.date-pick input::-webkit-calendar-picker-indicator { position: absolute; inset: 0; width: auto; height: auto; cursor: pointer; }
.notice { background: var(--accent-soft); border-radius: var(--radius-sm); padding: 10px 12px; font-size: 13.5px; color: var(--text); margin: 0 0 12px; }
.notice.warn { background: var(--danger-soft); }

.score-card { margin-bottom: 16px; }
.score-main { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.score-big { font-size: 48px; font-weight: 650; letter-spacing: -.03em; line-height: 1; }
.score-of { font-size: 20px; color: var(--muted); font-weight: 550; }
.score-pct { font-size: 20px; font-weight: 650; color: var(--text-2); }
.meter { height: 10px; border-radius: 5px; background: var(--accent-soft); overflow: hidden; margin: 12px 0 8px; }
.meter i { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 5px; transition: width .25s ease; }
.score-foot { font-size: 13px; color: var(--muted); min-height: 1.45em; }

.groups { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr); margin-bottom: 16px; }
@media (min-width: 760px) { .groups { grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; } }
.groups .card + .card { margin-top: 0; }
.group .card-head { margin-bottom: 6px; }
.group-count { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.habit-list { display: flex; flex-direction: column; }
.habit {
  display: flex; align-items: center; gap: 12px; width: 100%; min-height: 48px; padding: 6px 4px;
  border: 0; border-top: 1px solid var(--border); background: none; color: var(--text); font: inherit; text-align: left; cursor: pointer;
  user-select: none; -webkit-user-select: none;
}
.habit:first-child { border-top: 0; }
.habit:hover { background: var(--surface-2); }
.tick {
  width: 26px; height: 26px; flex: none; border-radius: 8px; border: 2px solid var(--border-strong);
  display: grid; place-items: center; color: transparent; transition: background .12s, border-color .12s;
}
.tick svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.habit.on .tick { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.habit-name { flex: 1; min-width: 0; font-weight: 550; }
.habit.on .habit-name { color: var(--text-2); }
.streak { font-size: 12px; color: var(--text-2); background: var(--surface-2); border-radius: 999px; padding: 2px 8px; font-weight: 550; white-space: nowrap; }
.streak:empty { display: none; }
.nums { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; max-width: 460px; }
.hint { font-size: 12.5px; color: var(--muted); margin: 10px 0 0; }
.hint:empty { display: none; }

.welcome { max-width: 560px; margin: 40px auto; text-align: center; padding: 32px 24px; }
.welcome p { color: var(--text-2); }
.welcome .row { justify-content: center; margin-top: 18px; }

/* grid (the spreadsheet view) */
.sheet-wrap {
  overflow: auto; max-height: calc(100dvh - 210px - var(--safe-b)); background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
}
@media (min-width: 860px) { .sheet-wrap { max-height: calc(100dvh - 140px); } }
table.sheet { border-collapse: separate; border-spacing: 0; font-size: 12.5px; font-variant-numeric: tabular-nums; }
.sheet th, .sheet td { padding: 0; border-bottom: 1px solid var(--border); background: var(--surface); }
.sheet thead th, .sheet thead td { position: sticky; z-index: 2; }
.sheet tr.names > * { top: 0; height: 112px; vertical-align: bottom; }
.sheet tr.rates > * { top: 112px; height: 30px; font-size: 11.5px; color: var(--text-2); text-align: center; border-bottom: 1px solid var(--border-strong); }
.sheet .c-h, .sheet tr.names .c-n { width: 30px; min-width: 30px; }
.sheet tr.names .c-h span, .sheet tr.names .c-n span {
  display: block; writing-mode: vertical-rl; transform: rotate(180deg); white-space: nowrap; margin: 0 auto 8px;
  font-weight: 600; font-size: 12px; color: var(--text-2);
}
.sheet .c-day { position: sticky; left: 0; z-index: 1; min-width: 92px; text-align: left; padding: 0 8px; border-right: 1px solid var(--border); font-weight: 400; }
.sheet thead .c-day { z-index: 3; font-size: 12px; color: var(--muted); font-weight: 600; }
.sheet tr.names .c-day { padding-bottom: 8px; }
.sheet tbody .c-day .d { display: flex; gap: 6px; align-items: baseline; color: var(--text); text-decoration: none; padding: 5px 0; white-space: nowrap; }
.sheet tbody tr.future .c-day .d { color: var(--muted); }
.sheet .d-no { min-width: 22px; font-weight: 650; }
.sheet .d-date { color: var(--muted); font-size: 11.5px; }
.sheet td.c-n { padding: 0 8px; text-align: right; white-space: nowrap; color: var(--text-2); }
.sheet tr.rates td.c-n { text-align: right; }
.sheet td.cell { width: 30px; height: 28px; text-align: center; cursor: pointer; }
.sheet td.cell i { display: block; width: 16px; height: 16px; margin: auto; border-radius: 4px; }
.sheet td.cell.on i { background: var(--accent); }
.sheet td.cell.off i { background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--border); }
.sheet td.cell:not(.on):not(.off) i { box-shadow: inset 0 0 0 1px var(--border); opacity: .55; }
.sheet td.cell:hover i { outline: 2px solid var(--focus); outline-offset: 1px; }
.sheet tr.wk > * { border-top: 2px solid var(--border-strong); }
.sheet tr.future > * { color: var(--muted); }
.sheet tr.future td.cell { cursor: default; }
.sheet tr.is-today > * { background: var(--accent-soft); }

/* chart */
.chart { width: 100%; overflow: hidden; }
.chart svg { display: block; }
.chart .axis text { fill: var(--muted); font-size: 11px; font-family: var(--font); font-variant-numeric: tabular-nums; }
.chart .end-label { fill: var(--text-2); font-size: 11.5px; font-weight: 600; font-family: var(--font); font-variant-numeric: tabular-nums; }
.chart .grid line { stroke: var(--border); }
.chart .baseline { stroke: var(--border-strong); }
.chart .cross line { stroke: var(--border-strong); }
.chart .hit, .chart .hit-area { fill: transparent; }
.chart .hit:hover { fill: var(--text); fill-opacity: .05; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12px; color: var(--text-2); margin-top: 8px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.line-key { display: inline-block; width: 14px; height: 3px; border-radius: 2px; flex: none; }
.tooltip { position: fixed; z-index: 50; pointer-events: none; background: var(--surface); color: var(--text); border: 1px solid var(--border-strong); border-radius: 8px; padding: 8px 10px; font-size: 12px; box-shadow: 0 6px 24px rgba(0,0,0,.12); min-width: 140px; }
.tooltip .tt-title { font-weight: 650; margin-bottom: 4px; }
.tooltip .tt-row { display: flex; align-items: center; gap: 10px; justify-content: space-between; }
.tooltip .tt-row span:first-child { display: inline-flex; align-items: center; gap: 6px; color: var(--text-2); }
details.table-view { margin-top: 10px; font-size: 13px; }
details.table-view summary { cursor: pointer; color: var(--accent); font-weight: 600; }

/* bars */
.bars { display: flex; flex-direction: column; gap: 10px; }
@media (min-width: 900px) { .bars { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 28px; } }
.bar-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 10px; font-size: 13.5px; }
.bar-row > span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-row .muted { font-size: 12px; }
.bar-row .track { grid-column: 1 / -1; height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.bar-row .track i { display: block; height: 100%; background: var(--accent); border-radius: 4px; }

/* tables */
.table-wrap { overflow-x: auto; margin: 0 -16px; padding: 0 16px; }
.table-wrap.scroll { max-height: 320px; overflow-y: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.data th, table.data td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.data th { font-size: 12px; color: var(--muted); font-weight: 600; position: sticky; top: 0; background: var(--surface); }
table.data td.n, table.data th.n { text-align: right; font-variant-numeric: tabular-nums; }
.rounds-table tbody tr { cursor: pointer; }
.rounds-table tbody tr:hover { background: var(--surface-2); }
.rounds-table tbody tr.current td { font-weight: 650; }
.chip { display: inline-flex; align-items: center; font-size: 11.5px; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--text-2); font-weight: 550; }

/* settings */
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
ol.habit-edit { list-style: none; margin: 0; padding: 0; }
.habit-edit li { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr) auto; gap: 8px; align-items: center; padding: 6px 0; border-top: 1px solid var(--border); }
.habit-edit li:first-child { border-top: 0; }
.habit-edit input { min-height: 38px; padding: 7px 10px; }
.h-move { display: flex; }
@media (max-width: 560px) {
  .habit-edit li { grid-template-columns: minmax(0, 1fr) auto; }
  .habit-edit .h-group { grid-column: 1; grid-row: 2; font-size: 13px; min-height: 34px; }
  .habit-edit .h-move { grid-column: 2; grid-row: 1 / span 2; flex-direction: column; }
  .habit-edit .h-move [data-remove] { order: 3; }
}
.add-habit { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr) auto; gap: 8px; margin-top: 12px; }
@media (max-width: 560px) { .add-habit { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); } .add-habit .btn { grid-column: 1 / -1; } }
.pick { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.pick-item { font: inherit; font-size: 13px; padding: 5px 10px; border: 1px dashed var(--border-strong); border-radius: 999px; background: transparent; color: var(--text-2); cursor: pointer; }
.pick-item:hover { background: var(--accent-soft); color: var(--text); }
.new-round { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr) 90px auto; gap: 10px; align-items: end; }
@media (max-width: 640px) { .new-round { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); } .new-round .field:first-child, .new-round .btn { grid-column: 1 / -1; } }
.round-edit input { min-height: 34px; padding: 5px 8px; font-size: 13.5px; }
.round-edit .r-name { min-width: 110px; }
.round-edit .r-start { min-width: 140px; }
.round-edit .r-length { width: 74px; }
.round-edit .r-maint { width: 90px; text-align: right; }
.round-edit td { vertical-align: middle; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 16px; font-size: 14px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.user-list { list-style: none; margin: 12px 0 0; padding: 0; }
.user-list li { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 10px 0; border-top: 1px solid var(--border); }
.user-list .user-email { flex: 1; min-width: 0; overflow-wrap: anywhere; font-weight: 550; }
#user-error { margin: 8px 0 0; font-size: 13.5px; }
.progress { height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; margin-top: 10px; }
.progress i { display: block; height: 100%; background: var(--accent); width: 0; transition: width .2s; }
.empty { text-align: center; padding: 48px 16px; color: var(--muted); }

/* toast & modal */
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(84px + var(--safe-b)); z-index: 60; background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 14px; box-shadow: 0 6px 24px rgba(0,0,0,.2); max-width: calc(100vw - 32px); }
@media (min-width: 860px) { .toast { bottom: 24px; left: calc(50% + var(--nav-w) / 2); } }
dialog { border: 1px solid var(--border); border-radius: 16px; background: var(--surface); color: var(--text); padding: 20px; width: min(420px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(0,0,0,.4); }
dialog h2 { margin-bottom: 8px; }
dialog .row { justify-content: flex-end; margin-top: 16px; }
