:root {
  --bg: #eef1f0;
  --surface: #ffffff;
  --ink: #16221f;
  --muted: #5d6b67;
  --line: #d9dfdd;
  --accent: #0f766e;
  --accent-ink: #ffffff;
  --accent-soft: #e3f2f0;
  --danger: #b91c1c;
  --warn: #b45309;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(22, 34, 31, .06), 0 2px 8px rgba(22, 34, 31, .05);
  color-scheme: light;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
body.has-timer main { padding-bottom: 110px; }
h1, h2, h3, p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--danger); font-size: 14px; }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: 100%; max-width: 360px; background: var(--surface); border: 1px solid var(--line);
  border-radius: 16px; padding: 28px 24px; display: grid; gap: 10px; box-shadow: var(--shadow);
}
.login-card h1 { font-size: 26px; letter-spacing: -.01em; }
.login-card label { font-weight: 600; margin-top: 8px; }

/* ---------- header ---------- */
.top {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 16px;
  padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top));
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; color: var(--ink); text-decoration: none; }
.nav { display: flex; gap: 4px; }
.nav a { padding: 7px 12px; border-radius: 999px; color: var(--muted); text-decoration: none; font-weight: 600; }
.nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }
.top-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.sync { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 5px 12px; font-size: 13px; color: var(--muted); }
.sync.bad { color: var(--danger); border-color: #f1c4c4; }
.linkbtn { border: 0; background: none; color: var(--muted); padding: 6px; font-size: 14px; }
.linkbtn:hover { color: var(--ink); }

main { max-width: 1240px; margin: 0 auto; padding: 18px 16px 40px; }

/* ---------- buttons, chips ---------- */
.btn {
  border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 9px 14px;
  font-weight: 600; min-height: 40px;
}
.btn:hover { border-color: #b9c4c1; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: #0c6862; }
.btn.danger { color: var(--danger); }
.btn.danger.armed { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.small { padding: 5px 10px; min-height: 32px; font-size: 14px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 600; padding: 2px 9px;
  border-radius: 999px; background: color-mix(in srgb, var(--c, #9ca3af) 14%, white); color: color-mix(in srgb, var(--c, #6b7280) 80%, black);
  white-space: nowrap;
}
.chip::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--c, #9ca3af); }
.chip.unsorted { --c: #9ca3af; font-weight: 500; }
.pick {
  display: inline-flex; align-items: center; gap: 7px; border: 1.5px solid var(--line); background: var(--surface);
  border-radius: 999px; padding: 6px 12px; font-weight: 600; font-size: 14px; min-height: 36px;
}
.pick[aria-pressed="true"] { border-color: var(--c, var(--accent)); background: color-mix(in srgb, var(--c, var(--accent)) 12%, white); }
.pick .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--c, #9ca3af); }

/* ---------- board ---------- */
.addbar { display: flex; gap: 8px; margin-bottom: 12px; }
.addbar input {
  flex: 1; min-width: 0; border: 1px solid var(--line); border-radius: 10px; padding: 11px 14px; background: var(--surface); font-size: 16px;
}
.notice {
  display: block; width: 100%; text-align: left; margin-bottom: 12px; border: 1px dashed #c9a46a; background: #fdf6e7; color: #7a4a0a;
  border-radius: 10px; padding: 8px 12px; font-size: 14px;
}
.tabs { display: none; gap: 6px; margin-bottom: 12px; }
.tabs button {
  flex: 1; border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 9px 6px; font-weight: 600; color: var(--muted);
}
.tabs button[aria-selected="true"] { background: var(--ink); border-color: var(--ink); color: #fff; }
.tabs .n { opacity: .7; font-weight: 500; margin-left: 4px; }
.columns { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; align-items: start; }
.col h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 4px 2px 10px; display: flex; gap: 8px; }
.col h2 .count { font-weight: 500; }
.cards { display: grid; gap: 10px; }
.empty { color: var(--muted); font-size: 14px; padding: 14px; border: 1px dashed var(--line); border-radius: var(--radius); text-align: center; }
.card {
  display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: start; padding: 12px; cursor: pointer;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
}
.card:hover { border-color: #b9c4c1; }
.card.running { border-color: var(--accent); background: linear-gradient(0deg, var(--accent-soft), var(--accent-soft)), var(--surface); }
.card.done .card-title { color: var(--muted); text-decoration: line-through; }
.card-title { font-weight: 600; overflow-wrap: anywhere; }
.card-meta { display: flex; flex-wrap: wrap; gap: 6px 8px; align-items: center; margin-top: 6px; font-size: 13px; color: var(--muted); }
.card-meta .overdue { color: var(--danger); font-weight: 700; }
.card-meta .today { color: var(--warn); font-weight: 700; }
.card-meta .over { color: var(--danger); font-weight: 700; }
.bar { height: 5px; background: #e4e9e7; border-radius: 99px; margin-top: 9px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.bar.over i { background: var(--danger); }
.check {
  width: 26px; height: 26px; border-radius: 50%; border: 2px solid #a8b3b0; background: var(--surface); padding: 0; position: relative; margin-top: 1px;
}
.check:hover { border-color: var(--accent); }
.card.done .check { background: var(--accent); border-color: var(--accent); }
.card.done .check::after { content: ""; position: absolute; left: 7px; top: 3px; width: 6px; height: 11px; border: solid #fff; border-width: 0 2.5px 2.5px 0; transform: rotate(45deg); }
.play {
  width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface); display: grid; place-items: center; padding: 0; color: var(--accent);
}
.play:hover { border-color: var(--accent); background: var(--accent-soft); }
.card.running .play { background: var(--accent); border-color: var(--accent); color: #fff; }
.play svg, .tb-actions svg { width: 16px; height: 16px; fill: currentColor; }

/* ---------- timer bar ---------- */
.timerbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; background: var(--ink); color: #fff;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); display: grid; grid-template-columns: 1fr auto; gap: 6px 14px; align-items: center;
  box-shadow: 0 -4px 18px rgba(0, 0, 0, .18);
}
.tb-info { min-width: 0; cursor: pointer; }
.tb-title { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tb-sub { font-variant-numeric: tabular-nums; font-size: 14px; opacity: .85; display: flex; gap: 12px; }
.tb-sub .over { color: #fca5a5; font-weight: 700; }
.tb-bar { grid-column: 1 / -1; height: 4px; border-radius: 99px; background: rgba(255, 255, 255, .18); overflow: hidden; }
.tb-bar i { display: block; height: 100%; background: #5eead4; }
.tb-bar.over i { background: #f87171; }
.tb-actions { display: flex; gap: 8px; }
.tb-actions button { border: 1px solid rgba(255, 255, 255, .35); background: transparent; color: #fff; border-radius: 10px; padding: 8px 12px; font-weight: 600; min-height: 38px; }
.tb-actions button.primary { background: #fff; color: var(--ink); border-color: #fff; }

/* ---------- sheet (task details) ---------- */
dialog.sheet {
  border: 0; padding: 0; border-radius: 16px; width: min(560px, calc(100vw - 24px)); max-height: calc(100vh - 32px);
  background: var(--surface); color: var(--ink); box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
}
dialog.sheet.small { width: min(460px, calc(100vw - 24px)); }
dialog.sheet::backdrop { background: rgba(22, 34, 31, .45); }
.sheet-body { display: grid; gap: 16px; padding: 18px; overflow-y: auto; max-height: calc(100vh - 32px); }
.sheet-head { display: flex; gap: 10px; align-items: start; }
.sheet-head input {
  flex: 1; min-width: 0; font-size: 19px; font-weight: 700; border: 1px solid transparent; border-radius: 8px; padding: 4px 6px; margin: -4px -6px; background: transparent;
}
.sheet-head input:hover, .sheet-head input:focus { border-color: var(--line); background: #fff; }
.x { border: 0; background: none; font-size: 24px; line-height: 1; color: var(--muted); padding: 2px 8px; }
.field > label, .field > .lbl { display: block; font-size: 12.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-bottom: 6px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.field input[type="date"], .field input[type="number"], .field select, .field textarea {
  border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; background: #fff; min-height: 40px;
}
.field textarea { width: 100%; min-height: 84px; resize: vertical; }
.field input[type="number"] { width: 92px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { border: 0; background: var(--surface); padding: 8px 14px; font-weight: 600; color: var(--muted); }
.seg button + button { border-left: 1px solid var(--line); }
.seg button[aria-pressed="true"] { background: var(--ink); color: #fff; }
.timebox { border: 1px solid var(--line); border-radius: 12px; padding: 12px; display: grid; gap: 10px; background: #f8faf9; }
.timebox .big { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.timebox .big small { font-size: 14px; font-weight: 500; color: var(--muted); }
.timebox .over { color: var(--danger); }
.log summary { cursor: pointer; font-weight: 600; color: var(--muted); }
.log table { width: 100%; border-collapse: collapse; margin-top: 8px; font-size: 14px; }
.log td { padding: 5px 4px; border-top: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.log td:last-child { text-align: right; }
.sheet-foot { display: flex; gap: 8px; justify-content: space-between; flex-wrap: wrap; border-top: 1px solid var(--line); padding-top: 14px; }
.warnbox { background: #fdf6e7; border: 1px solid #ecd9aa; border-radius: 10px; padding: 8px 12px; font-size: 14px; color: #7a4a0a; }
.hint { font-size: 13px; color: var(--muted); }

/* ---------- reports ---------- */
.rep-head { display: flex; flex-wrap: wrap; gap: 12px 16px; align-items: center; margin-bottom: 14px; }
.rep-head h1 { font-size: 24px; margin-right: auto; }
.rep-range { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.rep-range input[type="date"] { border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; background: #fff; }
.tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.tile .v { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.tile .l { color: var(--muted); font-size: 13px; margin-top: 2px; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; box-shadow: var(--shadow); }
.panel h2 { font-size: 16px; margin-bottom: 4px; }
.panel .sub { color: var(--muted); font-size: 14px; margin-bottom: 12px; }
.split { display: grid; gap: 14px; }
.split-row { display: grid; grid-template-columns: 150px 1fr 150px; gap: 12px; align-items: center; }
.split-name { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.split-name i { width: 10px; height: 10px; border-radius: 50%; background: var(--c); flex: none; }
.split-track { position: relative; height: 14px; background: #e8edeb; border-radius: 99px; }
.split-fill { position: absolute; left: 0; top: 0; bottom: 0; background: var(--c); border-radius: 99px; min-width: 2px; }
.split-target { position: absolute; top: -4px; bottom: -4px; width: 3px; background: var(--ink); border-radius: 2px; }
.split-text { font-size: 14px; font-variant-numeric: tabular-nums; text-align: right; }
.split-text .up { color: var(--danger); font-weight: 700; }
.split-text .down { color: var(--warn); font-weight: 700; }
.legend { display: flex; gap: 14px; font-size: 13px; color: var(--muted); margin-top: 10px; align-items: center; }
.legend .bar-key { display: inline-block; width: 3px; height: 14px; background: var(--ink); border-radius: 2px; vertical-align: middle; margin-right: 6px; }
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.data td { padding: 9px 10px; border-bottom: 1px solid #edf0ef; vertical-align: top; }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.data .over { color: var(--danger); font-weight: 600; }
table.data .under { color: var(--accent); font-weight: 600; }
.targets { display: grid; gap: 10px; }
.targets .t-row { display: grid; grid-template-columns: 1fr 90px; gap: 10px; align-items: center; }
.targets input { border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; width: 90px; background: #fff; }

/* ---------- settings ---------- */
.person { border-top: 1px solid var(--line); padding: 12px 0; }
.person input[readonly] { border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; background: #f8faf9; font-size: 13px; }
.linkbtn.armed { color: var(--danger); font-weight: 700; }
.addbar + .person { margin-top: 4px; }

/* ---------- notes and lists ---------- */
.searchbox { width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 11px 14px; background: var(--surface); font-size: 16px; margin-bottom: 14px; }
.nbgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.nbcard {
  display: grid; gap: 2px; padding: 14px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); color: var(--ink); text-decoration: none;
}
.nbcard:hover { border-color: #b9c4c1; }
.nbcard b { overflow-wrap: anywhere; }
.nbcard span { color: var(--muted); font-size: 13px; }
.rep-head .linkbtn { padding: 6px 4px; }
.back { flex-basis: 100%; color: var(--muted); text-decoration: none; font-size: 14px; font-weight: 600; margin-bottom: -6px; }
.back:hover { color: var(--ink); }
.entryform { display: flex; gap: 8px; align-items: flex-start; margin-bottom: 16px; }
.entryform textarea, .entry textarea {
  flex: 1; min-width: 0; width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: var(--surface); font-size: 16px; resize: vertical; min-height: 64px;
}
.entries { display: grid; gap: 10px; max-width: 760px; }
.entry { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); display: grid; gap: 6px; }
.entry-meta { font-size: 12.5px; color: var(--muted); }
.entry-book { color: var(--accent); font-weight: 600; text-decoration: none; }
.entry-body { white-space: pre-wrap; overflow-wrap: anywhere; }
.entry-actions { display: flex; gap: 8px; margin-left: -6px; }
.entry-actions .linkbtn { font-size: 13px; }
#search-results { margin-bottom: 14px; }
.check-opt { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; color: var(--muted); }
.check-opt input { width: 18px; height: 18px; accent-color: var(--accent); }
.cl { max-width: 640px; }
.cl-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.cl-head h2 { flex: 1; margin: 0; overflow-wrap: anywhere; }
.cl-title-input { flex: 1; min-width: 0; font-size: 17px; font-weight: 700; border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; background: var(--surface); }
.cl.finished { border-color: var(--accent); }
.items { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 2px; }
.item { display: flex; align-items: center; gap: 12px; padding: 7px 0; border-top: 1px solid #edf0ef; }
.item:first-child { border-top: 0; }
.item-text { flex: 1; overflow-wrap: anywhere; }
.item.done .item-text { color: var(--muted); text-decoration: line-through; }
.tick { width: 26px; height: 26px; flex: none; border-radius: 7px; border: 2px solid #a8b3b0; background: var(--surface); padding: 0; position: relative; }
.tick:hover { border-color: var(--accent); }
.tick[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); }
.tick[aria-pressed="true"]::after { content: ""; position: absolute; left: 7px; top: 2px; width: 6px; height: 12px; border: solid #fff; border-width: 0 2.5px 2.5px 0; transform: rotate(45deg); }
.item-edit { flex: 1; min-width: 0; border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; background: var(--surface); }
.mini { width: 32px; height: 32px; border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 0; font-size: 12px; color: var(--muted); }
.mini:disabled { opacity: .35; cursor: default; }
.additem { display: flex; gap: 8px; margin-top: 12px; }
.additem input { flex: 1; min-width: 0; border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; background: var(--surface); font-size: 16px; }
.cl-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 10px; }
.cl.managing .check-opt { margin-bottom: 4px; }
.cl.managing .sheet-foot { margin-top: 12px; }
.signout-panel { display: none; }
#cl-form { flex-wrap: wrap; align-items: center; }
#cl-form #cl-name { flex: 1 1 220px; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(24px + env(safe-area-inset-bottom)); z-index: 60;
  background: var(--ink); color: #fff; border-radius: 12px; padding: 11px 16px; display: flex; gap: 14px; align-items: center; box-shadow: 0 8px 24px rgba(0, 0, 0, .28); max-width: calc(100vw - 24px);
}
body.has-timer .toast { bottom: calc(110px + env(safe-area-inset-bottom)); }
.toast button { background: none; border: 0; color: #5eead4; font-weight: 700; padding: 0; }

/* ---------- phone ---------- */
@media (max-width: 760px) {
  .top { gap: 8px; padding-left: 12px; padding-right: 12px; }
  .brand span { display: none; }
  .tabs { display: flex; }
  .columns { grid-template-columns: 1fr; }
  .columns .col { display: none; }
  .columns[data-tab="todo"] .col[data-col="todo"],
  .columns[data-tab="doing"] .col[data-col="doing"],
  .columns[data-tab="delegated"] .col[data-col="delegated"],
  .columns[data-tab="done"] .col[data-col="done"] { display: block; }
  .tabs button { padding: 9px 2px; font-size: 14px; }
  .nav a { padding: 7px 8px; font-size: 14px; }
  .signout-top { display: none; }
  .signout-panel { display: block; }
  .rep-head h1 { font-size: 22px; }
  .col h2 { display: none; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .split-row { grid-template-columns: 1fr; gap: 6px; }
  .split-text { text-align: left; }
  dialog.sheet { width: 100vw; max-width: 100vw; margin: auto 0 0; border-radius: 18px 18px 0 0; max-height: 92vh; }
  .sheet-body { max-height: 92vh; padding-bottom: calc(18px + env(safe-area-inset-bottom)); }
  .tb-actions button { padding: 8px 10px; }
}
@media (prefers-reduced-motion: no-preference) {
  .card, .btn, .pick { transition: border-color .15s, background .15s; }
}
