:root {
  --bg: #F7F7F5; --card: #FFFFFF; --inner: #F4F4F1; --line: #E3E3DF;
  --text: #1A1A1A; --muted: #5F6368; --accent: #1D4ED8; --on-accent: #FFFFFF;
  --q1: #C2410C; --q2: #1D4ED8; --q3: #A16207; --q4: #6B7280;
  --overdue: #B91C1C; --soon: #9A3412;
  --chip-bg: #EDEDEA; --chip-fg: #3F3F3B;
  --chip-imp-bg: #FDEBDD; --chip-imp-fg: #9A3412;
  --chip-date-bg: #E8EEFC; --chip-date-fg: #1E40AF;
  --page: var(--bg);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111214; --card: #1B1C1F; --inner: #24252A; --line: #2E2F33;
    --text: #ECECEA; --muted: #A1A1A0; --accent: #60A5FA; --on-accent: #111214;
    --q1: #FB923C; --q2: #60A5FA; --q3: #FACC15; --q4: #9CA3AF;
    --overdue: #FCA5A5; --soon: #FDBA74;
    --chip-bg: #24252A; --chip-fg: #ECECEA;
    --chip-imp-bg: #24252A; --chip-imp-fg: #FB923C;
    --chip-date-bg: #24252A; --chip-date-fg: #60A5FA;
  }
}
body[data-view="today"] { --page: var(--card); }

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100dvh; background: var(--page); color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
.wrap { width: 100%; max-width: 1100px; margin: 0 auto; padding: 0 16px; }
body[data-view="today"] .wrap { max-width: 640px; }
.muted { color: var(--muted); font-size: 13px; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }

/* header */
.top { position: sticky; top: 0; z-index: 2; background: var(--page); padding-top: env(safe-area-inset-top); }
.title-row { display: flex; align-items: center; gap: 8px; padding-top: 16px; padding-bottom: 12px; }
.heading { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
h1 { margin: 0; font-size: 24px; font-weight: 700; }
.icon {
  width: 44px; height: 44px; border-radius: 22px; border: 1px solid var(--line); background: var(--card);
  display: flex; align-items: center; justify-content: center; padding: 0;
}
.search-row { display: flex; flex-direction: column; gap: 8px; padding-bottom: 12px; }
.search-row input {
  height: 44px; padding: 0 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--card);
}

/* chips */
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chips:empty { display: none; }
.chip {
  display: inline-flex; align-items: center; gap: 5px; padding: 4px 10px; border-radius: 999px;
  border: 1px solid transparent; background: var(--chip-bg); color: var(--chip-fg); font-size: 12px; font-weight: 500;
}
.chip.imp { background: var(--chip-imp-bg); color: var(--chip-imp-fg); }
.chip.date { background: var(--chip-date-bg); color: var(--chip-date-fg); }
button.chip { min-height: 32px; padding: 0 12px; border-color: var(--line); background: var(--card); color: var(--text); }
button.chip[aria-pressed="true"] { background: var(--text); color: var(--page); border-color: var(--text); }

.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--qc); flex: none; }
.q1 { --qc: var(--q1); } .q2 { --qc: var(--q2); } .q3 { --qc: var(--q3); } .q4 { --qc: var(--q4); }

/* matrix view */
main { padding-bottom: calc(190px + env(safe-area-inset-bottom)); }
.minimap { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.mini {
  height: 64px; padding: 10px 12px; border-radius: 12px; text-align: left; background: var(--card);
  border: 1px solid var(--line); display: flex; flex-direction: column; justify-content: space-between;
}
.mini[aria-pressed="true"] { border: 2px solid var(--text); padding: 9px 11px; }
.mini.over, .quad.over { outline: 2px dashed var(--accent); outline-offset: 2px; }
.mini-name { display: flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 500; }
.mini-count { font-size: 20px; font-weight: 700; line-height: 1; }
.hint { margin: 14px 0 8px; font-size: 12px; font-weight: 500; color: var(--muted); }
.banner {
  margin-bottom: 8px; padding: 12px 14px; border-radius: 12px; border: 1px dashed var(--line);
  font-size: 13px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: center;
}
.link { background: none; border: 0; padding: 4px 0; color: var(--accent); font-weight: 500; font-size: 13px; min-height: 32px; }
.quad h2 { display: none; }
.quad:not(.selected) { display: none; }
.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.empty { color: var(--muted); font-size: 13px; padding: 16px 2px; }

/* task row (shared) */
.task {
  display: flex; gap: 10px; align-items: flex-start; padding: 10px 14px 10px 4px; background: var(--card);
  border: 1px solid var(--line); border-radius: 12px; touch-action: pan-y; user-select: none;
  -webkit-user-select: none; -webkit-touch-callout: none; cursor: pointer; position: relative;
  transition: transform .18s ease, opacity .18s ease;
}
.task.swiping { transition: none; }
.task.done .title { text-decoration: line-through; color: var(--muted); }
.check {
  width: 44px; height: 44px; margin: -6px -6px -6px 0; flex: none; background: none; border: 0; padding: 0;
  display: flex; align-items: center; justify-content: center;
}
.check::before {
  content: ""; width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--qc); box-sizing: border-box;
}
.task.done .check::before { background: var(--qc); }
.body { flex: 1; min-width: 0; padding-top: 2px; display: flex; flex-direction: column; gap: 3px; }
.title {
  font-size: 15px; font-weight: 500; word-break: break-word; text-align: left;
  background: none; border: 0; padding: 0; color: inherit; cursor: pointer;
}
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
input, select, textarea { font-size: 16px; }
.meta { display: flex; gap: 8px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.meta .overdue { color: var(--overdue); font-weight: 700; }
.meta .soon { color: var(--soon); font-weight: 500; }

/* today view */
.progress-row { margin-bottom: 8px; }
.progress { height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; margin-bottom: 14px; }
.progress span { display: block; height: 100%; width: 0; background: var(--text); transition: width .3s ease; }
.timeline { list-style: none; margin: 14px 0 0; padding: 0; }
.timeline .task { background: transparent; border: 0; border-radius: 0; border-bottom: 1px solid var(--line); padding: 10px 0; }
.lead { width: 44px; flex: none; padding-top: 8px; text-align: right; font-size: 12px; color: var(--muted); }
.lead.overdue { color: var(--overdue); font-weight: 700; }

/* dock */
.dock { position: fixed; left: 0; right: 0; bottom: 0; z-index: 2; background: var(--page); }
.dock-input { display: flex; flex-direction: column; gap: 8px; padding-top: 10px; padding-bottom: 8px; }
#quick {
  display: flex; align-items: center; gap: 8px; height: 48px; padding: 0 6px 0 16px; border-radius: 24px;
  background: var(--card); border: 1px solid var(--line);
}
body[data-view="today"] #quick { background: var(--inner); border-color: transparent; }
#quick input { flex: 1; min-width: 0; border: 0; outline: none; background: transparent; font-size: 16px; }
#quick:focus-within { border-color: var(--accent); }
.add {
  width: 36px; height: 36px; border-radius: 18px; border: 0; background: var(--accent); color: var(--on-accent);
  display: flex; align-items: center; justify-content: center; padding: 0;
}
.add svg { width: 18px; height: 18px; stroke-width: 2.4; }
.tabs {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); background: var(--card);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.tabs button {
  min-height: 52px; background: none; border: 0; font-size: 13px; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
}
.tabs button::before { content: ""; width: 20px; height: 3px; border-radius: 2px; background: transparent; }
.tabs button[aria-current="page"] { color: var(--text); font-weight: 700; }
.tabs button[aria-current="page"]::before { background: var(--text); }

/* sheets */
.sheet {
  border: 1px solid var(--line); background: var(--card); color: var(--text); padding: 20px 16px calc(20px + env(safe-area-inset-bottom));
  width: 100%; max-width: 520px; margin: auto auto 0; border-radius: 16px 16px 0 0;
}
.sheet::backdrop { background: rgb(0 0 0 / .45); }
#edit-form, .more-list, .sync, .sync-group { display: grid; gap: 12px; }
.sync { padding-bottom: 16px; margin-bottom: 16px; border-bottom: 1px solid var(--line); }
.sync h2 { margin: 0; font-size: 15px; }
.sync p { margin: 0; }
.sync p:empty:not([aria-live]) { display: none; }
#code-row input { flex: 1; min-width: 0; }
.sheet button:disabled { opacity: .5; cursor: default; }
#edit-form label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
#edit-form input:not([type="checkbox"]), #edit-form select, #edit-form textarea, .sync input {
  min-height: 44px; padding: 8px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--page);
}
.sheet button, .file-btn {
  min-height: 44px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--line); background: var(--card);
  display: flex; align-items: center; justify-content: center; font-size: 15px; cursor: pointer;
}
.sheet .primary { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.sheet .danger { color: var(--overdue); margin-right: auto; }
.row { display: flex; gap: 10px; flex-wrap: wrap; }
.row > label { flex: 1; }
.row.end { justify-content: flex-end; }
.check-label { display: flex !important; align-items: center; gap: 8px; min-height: 44px; color: var(--text) !important; font-size: 15px !important; }
.check-label input { width: 20px; height: 20px; margin: 0; }

/* wide screens: all four quadrants */
@media (min-width: 900px) {
  .minimap, .hint { display: none; }
  .quads { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-top: 4px; }
  .quad { display: block !important; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px; min-height: 240px; }
  .quad h2 { display: flex; align-items: center; gap: 8px; margin: 0 0 10px; font-size: 15px; }
  .quad h2 small { color: var(--muted); font-weight: 400; font-size: 12px; }
  .quad h2 .count { margin-left: auto; color: var(--muted); font-weight: 400; font-size: 13px; }
  .quad .task { border-color: var(--inner); }
  .quad { cursor: pointer; }
  .quad.selected { border-color: var(--text); }
  .sheet { margin: auto; border-radius: 16px; padding-bottom: 20px; }
  .tabs { grid-template-columns: repeat(2, 160px); justify-content: center; }
}
@media (prefers-reduced-motion: reduce) {
  .task, .progress span { transition: none; }
}
