:root {
  font-family: "Segoe UI", Tahoma, Arial, sans-serif;
  font-size: 17px;
  color-scheme: light;
  --bg: #f6f7f9;
  --surface: #fff;
  --text: #25303d;
  --muted: #5f6b79;
  --border: #dbe0e6;
  --soft: #f0f3f6;
  --primary: #296344;
  --primary-soft: #eaf3ed;
  color: var(--text);
  background: var(--bg);
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #151a21;
  --surface: #212832;
  --text: #edf0f5;
  --muted: #b0bac7;
  --border: #424d5b;
  --soft: #2b3440;
  --primary: #a1d9b6;
  --primary-soft: #293e33;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
button, input, select, textarea { font: inherit; }
button {
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 8px 12px;
  border-radius: 7px;
  font-size: 17px;
  transition: background .15s, border-color .15s;
}
button:hover { background: var(--soft); border-color: var(--muted); }
:where(button, input, select, textarea, summary, [tabindex]):focus-visible,
.file-button:focus-within { outline: 3px solid #4583c5; outline-offset: 3px; }
button:disabled { opacity: .5; cursor: default; }
[hidden] { display: none !important; }
h1, h2, h3, p { margin: 0; }
h1 { font-size: 28px; line-height: 1.25; letter-spacing: -.5px; font-weight: 700; }
h2 { font-size: 23px; font-weight: 650; }
h3 { font-size: 18px; font-weight: 650; }
p { line-height: 1.65; }
.app-shell { max-width: 1600px; margin: auto; padding: 0 28px; }
.header { min-height: 72px; display: flex; justify-content: space-between; align-items: center; gap: 20px; border-bottom: 1px solid var(--border); }
.brand { display: flex; align-items: center; gap: 11px; }
.brand-icon { display: grid; place-items: center; width: 37px; height: 37px; border-radius: 9px; font-size: 28px; background: var(--primary); color: var(--surface); }
.brand p { display: none; }
.header-actions { display: flex; align-items: center; gap: 12px; }
#today { color: var(--muted); font-size: 16px; }
kbd { font: inherit; font-size: 13px; color: inherit; opacity: .8; border: 1px solid currentColor; padding: 0 4px; border-radius: 3px; margin-left: 8px; }
.primary { background: var(--primary); border-color: var(--primary); color: var(--surface); font-weight: 600; }
.primary:hover { background: var(--primary); filter: brightness(.92); }
.icon-button { border: none; background: transparent; padding: 7px 9px; font-size: 21px; line-height: 1; }
.muted { color: var(--muted); font-size: 16px; }
.focus-panel { display: flex; align-items: center; gap: 16px; margin-top: 12px; padding: 8px 14px; min-height: 50px; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; }
.focus-panel > h2 { font-size: 17px; color: var(--primary); white-space: nowrap; }
#focus { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-width: 0; flex: 1; }
.focus-info { min-width: 0; }
.focus-info h3 { font-size: 18px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.focus-actions { display: flex; gap: 7px; flex-shrink: 0; }
.focus-actions button { padding: 6px 10px; }
.work-section { margin-top: 16px; }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 10px; }
.filters { display: flex; gap: 9px; }
.search { display: flex; align-items: center; gap: 8px; padding: 0 10px; border: 1px solid var(--border); border-radius: 7px; background: var(--surface); }
.search input { width: 190px; border: 0; padding: 8px 0; background: transparent; }
.search kbd { margin: 0; color: var(--muted); }
input, select, textarea { min-width: 0; border: 1px solid var(--border); border-radius: 7px; padding: 8px 10px; color: var(--text); background: var(--surface); }
.view-tabs { display: flex; align-items: center; gap: 5px; margin-bottom: 12px; }
.view-tabs button { background: transparent; border-color: transparent; padding: 7px 11px; }
.view-tabs button[aria-pressed="true"] { background: var(--surface); border-color: var(--border); font-weight: 650; }
.view-tabs button span { font-size: 16px; margin-left: 6px; color: var(--muted); }
.tab-hint { margin-left: auto; color: var(--muted); font-size: 16px; }
.matrix {
  display: grid;
  grid-template-columns: minmax(0, 50fr) minmax(0, 50fr);
  grid-template-rows: minmax(180px, 50fr) minmax(180px, 50fr);
  /* One continuous surface; keep this gap in sync with MATRIX_GAP. */
  gap: 6px;
  border-radius: 28px;
  background: var(--border);
  box-shadow: 0 0 0 1px var(--border), 0 5px 18px #14202f08;
  isolation: isolate;
  height: max(488px, min(900px, calc(100dvh - 270px)));
  /* Geometry is animated by requestAnimationFrame for consistent intermediate frames. */
}
.matrix.is-dragging { transition: none; }
.quadrant {
  --bubble-radius: 24px;
  --bubble-fill: var(--q-bg);
  --bubble-shadow: inset 0 1px 0 #ffffff55;
  display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow: hidden;
  border: 1px solid var(--q-border); border-top: 4px solid var(--q);
  border-radius: var(--bubble-radius);
  background: var(--bubble-fill);
  background-image: linear-gradient(145deg, color-mix(in srgb, var(--surface) 38%, transparent), transparent 65%);
  box-shadow: var(--bubble-shadow);
  /* Only surface treatment transitions; the spring owns the shared grid tracks. */
  transition: border-radius 400ms ease, background-color 400ms ease, border-color 400ms ease, box-shadow 400ms ease;
}
.q1 { --q: #a51e29; --q-border: #d5737b; --q-bg: #fff0f1; border-top-width: 6px; }
.q2 { --q: #205fa8; --q-border: #a6c5e6; --q-bg: #edf5ff; }
.q3 { --q: #91550b; --q-border: #dfc18c; --q-bg: #fff6e4; }
.q4 { --q: #57616e; --q-border: #bdc5cf; --q-bg: #eef0f3; }
:root[data-theme="dark"] .q1 { --q: #ffa1aa; --q-border: #7c4751; --q-bg: #302126; }
:root[data-theme="dark"] .q2 { --q: #a5caff; --q-border: #44668e; --q-bg: #1b2a3b; }
:root[data-theme="dark"] .q3 { --q: #f3c46a; --q-border: #7c663b; --q-bg: #30291c; }
:root[data-theme="dark"] .q4 { --q: #c0c9d5; --q-border: #586575; --q-bg: #272e37; }
.quadrant-heading { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 4px 10px; padding: 10px 12px; flex-shrink: 0; }
.quadrant-label { grid-column: 1; grid-row: 1 / 3; }
.quadrant-text { grid-column: 2; grid-row: 1 / 3; }
.quadrant-expand { grid-column: 3; grid-row: 2; font-size: 17px; padding: 6px 10px; color: var(--q); border-color: var(--q-border); }
.quadrant-expand[aria-pressed="true"] { font-weight: 700; border-color: var(--q); }
.quadrant.is-expanded {
  --bubble-radius: 28px;
  --bubble-fill: color-mix(in srgb, var(--q-bg) 94%, var(--q));
  --bubble-shadow: inset 0 1px 0 #ffffff66, inset 0 0 0 1px var(--q-border), 0 3px 10px #14202f14;
  border-color: var(--q);
}
@media (min-width: 701px) {
  .matrix:not(.is-stacked) .quadrant.is-compressed {
    --bubble-fill: color-mix(in srgb, var(--q-bg) 65%, var(--surface));
    --bubble-shadow: inset 0 1px 0 #ffffff22;
    /* Keep text and controls at full contrast; only the surrounding tint recedes. */
  }
}
.quadrant.has-pressure { animation: bubble-pressure 650ms ease-out; }
@keyframes bubble-pressure {
  0%, 100% { border-radius: var(--bubble-radius); box-shadow: var(--bubble-shadow); }
  35% { border-radius: 32px; box-shadow: inset 0 1px 0 #ffffff77, inset 0 0 0 2px var(--q-border), 0 3px 12px #14202f14; }
}
.quadrant-label { font-size: 22px; font-weight: 750; color: var(--q); align-self: start; padding-top: 5px; }
.quadrant-text { min-width: 0; }
.quadrant h3 { font-size: 26px; font-weight: 650; line-height: 1.35; color: var(--q); overflow-wrap: anywhere; }
.q1 h3 { font-size: 34px; font-weight: 700; }
.q2 h3 { font-size: 30px; font-weight: 700; }
.q3 h3 { font-size: 28px; font-weight: 700; }
.quadrant-heading p { color: var(--text); font-size: 18px; line-height: 1.6; margin-top: 3px; }
.count { grid-column: 3; grid-row: 1; justify-self: end; min-width: 30px; height: 26px; border: 1px solid var(--q-border); color: var(--q); border-radius: 7px; display: grid; place-items: center; font-size: 14px; font-weight: 650; background: var(--surface); }
.quadrant-body { min-height: 0; overflow-y: auto; flex: 1; padding: 3px 12px; display: flex; flex-direction: column; gap: 7px; scrollbar-width: thin; scrollbar-color: var(--q-border) transparent; scroll-padding: 5px; }
.task-card { flex-shrink: 0; min-width: 0; border: 1px solid var(--border); border-radius: 17px; background: var(--surface); }
.task-entering { animation: task-entrance 300ms ease-out both; }
@keyframes task-entrance { from { opacity: .65; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }
.task-card[draggable="true"] { cursor: grab; }
.task-open { display: block; width: 100%; padding: 14px 16px; text-align: left; border: none; border-radius: 16px; background: transparent; }
.task-open:hover { background: var(--soft); }
.task-open:focus-visible { outline-offset: -3px; }
.task-title { display: block; font-size: 21px; font-weight: 600; line-height: 1.55; overflow-wrap: anywhere; }
.card-meta { display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: center; margin-top: 5px; }
.status, .due { font-size: 14px; line-height: 1.5; color: var(--muted); }
.active-status { color: var(--primary); font-weight: 600; }
.is-focused { border-color: var(--primary); box-shadow: inset 3px 0 var(--primary); }
.is-done .task-title { text-decoration: line-through; color: var(--muted); }
.due.overdue { color: #b32c35; font-weight: 600; }
:root[data-theme="dark"] .due.overdue { color: #ffa1aa; }
.quadrant-add { margin: 3px 8px 5px; padding: 6px 8px; text-align: left; border-color: transparent; color: var(--q); background: transparent; font-size: 17px; flex-shrink: 0; align-self: flex-start; }
.empty-state { padding: 14px 8px; margin: auto; text-align: center; color: var(--text); font-size: 18px; line-height: 1.7; grid-column: 1/-1; }
.drop-target { outline: 3px dashed var(--q); outline-offset: -5px; }
.dragging { opacity: .4; }
/* A narrow container uses the same stacking rules as the existing 700px breakpoint. */
.matrix.is-stacked { grid-template-columns: 1fr; grid-template-rows: none; height: auto; transition: none; }
.matrix.is-stacked .quadrant { min-height: 180px; max-height: none; }
.matrix.is-stacked .quadrant-body { flex: 1 1 auto; max-height: 320px; }
.matrix.is-stacked .quadrant.is-expanded .quadrant-body { max-height: none; overflow-y: visible; }
.secondary { min-height: 200px; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); align-content: start; gap: 12px; }
.stats { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 24px; margin-top: 12px; padding: 8px 0; }
.stat { display: flex; gap: 9px; align-items: baseline; }
.stat span { font-size: 16px; color: var(--muted); }
.stat strong { font-size: 18px; font-weight: 650; }
.stat.late strong { color: #b32c35; }
:root[data-theme="dark"] .stat.late strong { color: #ffa1aa; }
.daily-section { border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); margin-top: 4px; }
.daily-section summary { cursor: pointer; padding: 12px 2px; font-size: 17px; font-weight: 600; }
.daily-section summary .muted { margin-left: 10px; font-weight: 400; }
.daily-hint { margin: 0 0 12px; }
.priorities { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; padding-bottom: 14px; }
.priority-slot { display: flex; align-items: center; gap: 11px; min-height: 75px; padding: 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); }
.slot-number { font-size: 22px; font-weight: 400; color: var(--muted); }
.priority-content { flex: 1; min-width: 0; }
.priority-title { display: block; max-width: 100%; padding: 0; border: 0; text-align: left; overflow-wrap: anywhere; font-weight: 600; }
.priority-content .muted { display: block; margin-top: 4px; }
.priority-controls { display: flex; flex-direction: column; }
.priority-controls button { font-size: 16px; padding: 4px 7px; }
.empty-slot { width: 100%; text-align: left; border-color: transparent; color: var(--muted); }
.text-button { border: 0; background: transparent; color: var(--muted); padding: 5px 7px; font-size: 16px; }
footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; color: var(--muted); font-size: 15px; }
footer > div { display: flex; gap: 8px; }
dialog { width: min(580px, calc(100% - 32px)); max-height: 90dvh; overflow: auto; padding: 24px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); color: var(--text); box-shadow: 0 20px 90px #0003; }
dialog::backdrop { background: #14202f77; }
.dialog-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
dialog label:not(.toggle):not(.file-button) { display: flex; flex-direction: column; gap: 6px; margin-top: 14px; font-size: 14px; font-weight: 600; }
textarea { resize: vertical; line-height: 1.6; }
.required, .danger { color: #b32c35; }
:root[data-theme="dark"] :is(.required, .danger) { color: #ffa1aa; }
.danger { border-color: transparent; }
.toggle-row, .form-row { display: flex; gap: 12px; margin-top: 14px; }
.form-row { margin-top: 0; }
.form-row > label { flex: 1; }
.toggle { display: flex; align-items: center; gap: 8px; flex: 1; padding: 11px; border: 1px solid var(--border); border-radius: 7px; }
.toggle input { width: 18px; height: 18px; accent-color: var(--primary); }
.toggle span { font-size: 13px; color: var(--muted); }
.form-hint { margin-top: 9px; font-size: 13px; color: var(--muted); }
.dialog-footer { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; margin-top: 22px; }
.spacer { flex: 1; }
.task-detail-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.option-list { display: flex; flex-direction: column; gap: 8px; margin-top: 16px; }
.priority-option { text-align: left; overflow-wrap: anywhere; }
.backup-actions { display: flex; flex-direction: column; gap: 12px; margin-top: 20px; }
.file-button { display: block; position: relative; padding: 12px; border: 1px solid var(--border); border-radius: 7px; cursor: pointer; text-align: center; }
.file-button input { position: absolute; inset: 0; width: 100%; opacity: 0; cursor: pointer; }
.warning { padding: 14px; margin-top: 12px; border: 1px solid #b47b29; border-radius: 8px; background: var(--surface); line-height: 1.6; }
#toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 100; max-width: calc(100% - 32px); padding: 13px 20px; border-radius: 8px; background: var(--text); color: var(--surface); box-shadow: 0 6px 30px #0002; line-height: 1.6; }
@media (max-width: 1100px) {
  .app-shell { padding: 0 20px; }
  .tab-hint { display: none; }
  .focus-panel { gap: 12px; }
  .toggle span { display: none; }
}
@media (max-width: 700px) {
  .app-shell { padding: 0 14px; }
  .header { flex-wrap: wrap; min-height: 0; gap: 10px; padding: 14px 0; }
  .header-actions { width: 100%; gap: 8px; justify-content: space-between; }
  .header kbd { display: none; }
  .focus-panel { align-items: flex-start; flex-direction: column; gap: 6px; padding: 10px 12px; }
  #focus { width: 100%; flex-wrap: wrap; gap: 8px; }
  .focus-info { width: 100%; }
  .focus-info h3 { white-space: normal; overflow-wrap: anywhere; }
  .focus-actions { flex-wrap: wrap; }
  .section-heading { align-items: flex-start; flex-direction: column; gap: 10px; }
  .filters { width: 100%; }
  .search { flex: 1; min-width: 0; }
  .search input { width: 100%; min-width: 0; }
  .filters select { max-width: 150px; }
  .view-tabs { flex-wrap: wrap; gap: 2px; }
  .view-tabs button { padding: 7px 8px; }
  .matrix { grid-template-columns: 1fr; grid-template-rows: none; height: auto; transition: none; }
  .quadrant { min-height: 180px; max-height: none; }
  .quadrant-body { flex: 1 1 auto; max-height: 320px; }
  .quadrant.is-expanded .quadrant-body { max-height: none; overflow-y: visible; }
  .priorities, .secondary { grid-template-columns: 1fr; }
  .priority-controls { flex-direction: row; }
  .stats { gap: 8px 20px; }
  footer { align-items: flex-start; flex-direction: column; gap: 8px; }
  .form-row { flex-wrap: wrap; }
  .form-row > label { min-width: 170px; }
  dialog { padding: 18px; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

.sync-compact { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 14px; }
.sync-compact p { margin: 0; }
.header-actions .filters { flex-wrap: wrap; }
@media (max-width: 900px) { .header-actions { flex-wrap: wrap; } }
