:root {
  --bg: #f4f1ea; --fg: #2b2a26; --muted: #6f6c63; --card: #fff; --line: rgba(0,0,0,.15);
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #1d1d1f; --fg: #f2f0ea; --muted: #a09d94; --card: #2a2a2d; --line: rgba(255,255,255,.18);
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1d1d1f; --fg: #f2f0ea; --muted: #a09d94; --card: #2a2a2d; --line: rgba(255,255,255,.18);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--bg); color: var(--fg);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
.bar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 14px 20px; position: sticky; top: 0; z-index: 5;
  background: var(--bg); border-bottom: 1px solid var(--line);
}
.bar h1 { font-size: 17px; margin: 0; }
.spacer { flex: 1; }
.pill {
  font: inherit; font-size: 13px; padding: 6px 12px; cursor: pointer;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--card); color: var(--fg);
}
.pill:hover { border-color: var(--muted); }
.pill.primary { background: #ffd93b; border-color: #e0b800; color: #2b2a26; font-weight: 600; }
.pill.active { background: #7bd88f; color: #123; border-color: #4caf6a; }
.pill[hidden] { display: none; }
a.pill { text-decoration: none; display: inline-block; }
.pill.dl { background: #1d1d1f; color: #fff; border-color: #1d1d1f; }

.notes {
  display: grid; gap: 22px; padding: 28px 20px 60px;
  grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
  max-width: 1200px; margin: 0 auto;
}
.note {
  --paper: #fff176; --ink: #3b3200;
  position: relative; background: var(--paper); color: var(--ink);
  padding: 18px 18px 14px; border-radius: 3px 3px 24px 3px; text-align: center;
  box-shadow: 0 10px 22px rgba(0,0,0,.22), 0 2px 4px rgba(0,0,0,.15);
  font-family: "Marker Felt", "Bradley Hand", "Segoe Print", cursive;
  transition: transform .15s;
}
.note:nth-child(odd) { transform: rotate(-1.2deg); }
.note:nth-child(even) { transform: rotate(1deg); }
.note:hover { transform: rotate(0) translateY(-2px); }
.note[data-color="pink"]   { --paper: #ffb3c7; --ink: #4a0d22; }
.note[data-color="blue"]   { --paper: #a9d8ff; --ink: #0b2f4d; }
.note[data-color="green"]  { --paper: #b9f0b0; --ink: #12400f; }
.note[data-color="orange"] { --paper: #ffcf99; --ink: #4d2600; }
.note[data-color="purple"] { --paper: #d9c2ff; --ink: #2d1260; }
.note.urgent { animation: pulse 2s ease-in-out infinite; }
.note.done { filter: saturate(.4); opacity: .85; }
@keyframes pulse { 50% { box-shadow: 0 0 0 4px rgba(255,60,60,.55), 0 10px 22px rgba(0,0,0,.22); } }
@media (prefers-reduced-motion: reduce) { .note.urgent { animation: none; outline: 3px solid rgba(255,60,60,.7); } .note { transition: none; } }

.title { font-size: 20px; margin: 4px 24px 10px; outline: none; min-height: 1.2em; cursor: text; word-break: break-word; }
.title:focus { background: rgba(255,255,255,.4); border-radius: 4px; }
.time { display: flex; justify-content: center; gap: 10px; }
.unit { min-width: 50px; }
.num { font-size: 40px; line-height: 1; font-variant-numeric: tabular-nums; }
.lbl { font-size: 11px; opacity: .65; margin-top: 2px; }
.over { font-size: 26px; margin: 8px 0; }
.when { font-size: 12px; opacity: .7; margin-top: 10px; }
.progress { height: 5px; border-radius: 3px; background: rgba(0,0,0,.14); margin-top: 10px; overflow: hidden; }
.progress i { display: block; height: 100%; background: var(--ink); opacity: .55; }
.tools {
  display: flex; justify-content: center; gap: 2px; margin-top: 8px;
  font-family: -apple-system, BlinkMacSystemFont, sans-serif;
}
.tools button {
  font: inherit; font-size: 11px; background: none; border: 0; color: var(--ink);
  opacity: .55; cursor: pointer; padding: 3px 6px; border-radius: 4px;
}
.tools button:hover, .tools button:focus-visible { opacity: 1; background: rgba(255,255,255,.4); }
.pin { position: absolute; top: 6px; right: 8px; font-size: 12px; opacity: .35; background: none; border: 0; cursor: pointer; color: inherit; }
.pin.on { opacity: .9; }

.empty { text-align: center; padding: 80px 20px; color: var(--muted); }
.hint { font-size: 13px; }

.menu {
  position: fixed; top: 54px; right: 20px; z-index: 10; display: flex; flex-direction: column;
  background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 4px;
  box-shadow: 0 8px 24px rgba(0,0,0,.25); min-width: 220px;
}
.menu[hidden] { display: none; }
.menu button, .menu a {
  font: inherit; text-align: left; padding: 8px 12px; border: 0; background: none;
  color: var(--fg); border-radius: 6px; cursor: pointer; text-decoration: none;
}
.menu button:hover, .menu a:hover { background: var(--bg); }

dialog { border: 1px solid var(--line); border-radius: 14px; background: var(--card); color: var(--fg); padding: 20px; width: min(420px, 92vw); }
dialog::backdrop { background: rgba(0,0,0,.45); }
dialog h2 { margin: 0 0 12px; font-size: 18px; }
dialog label { display: block; margin: 10px 0; font-size: 13px; color: var(--muted); }
dialog input {
  display: block; width: 100%; margin-top: 4px; font: inherit; font-size: 15px; padding: 8px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--fg);
}
.templates, .quick { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.colors { border: 0; padding: 0; margin: 10px 0; display: flex; gap: 8px; align-items: center; }
.colors legend { float: left; font-size: 13px; color: var(--muted); margin-right: 8px; padding: 0; }
.swatch { width: 24px; height: 24px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; padding: 0; }
.swatch[aria-checked="true"] { border-color: var(--fg); }
.actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: #222; color: #fff; padding: 10px 16px; border-radius: 999px; font-size: 13px; z-index: 20;
}
.toast[hidden] { display: none; }

/* Pop-out / compact single-note view */
body.compact { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
body.compact .bar, body.compact .tools, body.compact .empty { display: none !important; }
body.compact .notes { display: block; padding: 10px; max-width: none; width: 100%; }
body.compact .note { transform: none; box-shadow: none; border-radius: 0; min-height: calc(100vh - 20px); display: flex; flex-direction: column; justify-content: center; }
body.compact .num { font-size: clamp(30px, 14vw, 90px); }
body.compact .title { font-size: clamp(18px, 6vw, 36px); }

/* Manager: controls, list view, bulk bar */
.search { font: inherit; font-size: 13px; padding: 6px 12px; border: 1px solid var(--line); border-radius: 999px; background: var(--card); color: var(--fg); width: 180px; }
.controls { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 10px 20px; max-width: 1200px; margin: 0 auto; }
.controls[hidden], .bulk[hidden] { display: none; }
.controls select { font: inherit; font-size: 13px; padding: 5px 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--card); color: var(--fg); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { font: inherit; font-size: 13px; padding: 5px 12px; border: 0; background: var(--card); color: var(--fg); cursor: pointer; }
.seg button.on { background: #ffd93b; color: #2b2a26; font-weight: 600; }
.summary { margin-left: auto; font-size: 12px; color: var(--muted); }
.bulk { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 8px 20px; max-width: 1200px; margin: 0 auto; background: var(--card); border: 1px solid var(--line); border-radius: 10px; }
.notes.listview { display: block; max-width: 1000px; padding-top: 10px; }
.row { display: grid; grid-template-columns: 28px 14px 1fr 170px 130px auto; gap: 10px; align-items: center; padding: 10px 12px; border-bottom: 1px solid var(--line); background: var(--card); }
.row.head { font-size: 11px; text-transform: uppercase; color: var(--muted); background: none; }
.row .dot { width: 12px; height: 12px; border-radius: 50%; background: #fff176; }
.row[data-color="pink"] .dot { background: #ffb3c7; } .row[data-color="blue"] .dot { background: #a9d8ff; }
.row[data-color="green"] .dot { background: #b9f0b0; } .row[data-color="orange"] .dot { background: #ffcf99; }
.row[data-color="purple"] .dot { background: #d9c2ff; }
.row.urgent .remain { color: #d33; font-weight: 600; }
.row.archived { opacity: .6; }
.row .rwhen, .row .remain { font-size: 13px; font-variant-numeric: tabular-nums; }
.row .ract { display: flex; gap: 2px; }
.row .ract button, .linkbtn { font: inherit; font-size: 12px; background: none; border: 0; color: var(--fg); cursor: pointer; padding: 3px 6px; border-radius: 4px; }
.row .ract button:hover, .linkbtn:hover { background: var(--bg); }
.linkbtn { font-size: 15px; text-align: left; font-weight: 600; padding: 0; }
.dragging { opacity: .4; } .over { outline: 2px dashed #e0b800; outline-offset: 2px; }
.meta { display: flex; flex-wrap: wrap; gap: 4px; justify-content: center; margin-top: 6px; font-family: -apple-system, BlinkMacSystemFont, sans-serif; }
.row .meta { justify-content: flex-start; margin-top: 2px; }
.chip { font-size: 10px; padding: 1px 7px; border-radius: 999px; background: rgba(0,0,0,.12); }
.row .chip { background: var(--bg); color: var(--muted); }
.emoji { font-size: 28px; line-height: 1; margin-top: 2px; }
.since { font-size: 12px; opacity: .8; min-height: 0; }
.memo { font-family: -apple-system, BlinkMacSystemFont, sans-serif; font-size: 12px; margin: 8px 0 0; opacity: .8; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; white-space: pre-wrap; }
.tasks { list-style: none; margin: 8px 0 0; padding: 0; text-align: left; font-family: -apple-system, BlinkMacSystemFont, sans-serif; font-size: 12px; }
.tasks label { display: flex; gap: 6px; align-items: center; cursor: pointer; padding: 1px 0; }
.tasks .done { text-decoration: line-through; opacity: .6; }
.tools { flex-wrap: wrap; }
.note.archived { filter: saturate(.3); opacity: .8; }

/* Dialog additions */
dialog { max-height: 92vh; overflow: auto; }
dialog select, dialog textarea { display: block; width: 100%; margin-top: 4px; font: inherit; font-size: 15px; padding: 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--fg); }
.row2 { display: flex; gap: 10px; } .row2 .grow { flex: 1; } .row2 .emo { width: 70px; } .row2 .emo input { text-align: center; }
.emojis { display: flex; flex-wrap: wrap; gap: 2px; margin-bottom: 4px; }
.emojibtn { font-size: 18px; background: none; border: 0; cursor: pointer; border-radius: 6px; padding: 2px 4px; }
.emojibtn:hover { background: var(--bg); }
fieldset.rem { border: 0; padding: 0; margin: 10px 0; } fieldset.rem legend { font-size: 13px; color: var(--muted); padding: 0; margin-bottom: 4px; }
.pill.tog[aria-pressed="true"] { background: #ffd93b; border-color: #e0b800; color: #2b2a26; }
.taskedit { list-style: none; margin: 0 0 6px; padding: 0; }
.taskedit li { display: flex; gap: 6px; align-items: center; margin-bottom: 4px; }
.taskedit input[type=text] { margin: 0; flex: 1; }
.taskedit input[type=checkbox], .row input[type=checkbox] { width: auto; margin: 0; }

/* Footer: Mac app download */
.foot { max-width: 1200px; margin: 0 auto; padding: 10px 20px 40px; color: var(--muted); }
.foot[hidden] { display: none; }
.getapp { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; padding: 14px 16px; border: 1px dashed var(--line); border-radius: 12px; margin-bottom: 8px; }
.getapp strong { color: var(--fg); } .getapp span { flex: 1; min-width: 220px; font-size: 13px; }
.toast button { margin-left: 12px; background: none; border: 0; color: #ffd93b; font: inherit; font-weight: 600; cursor: pointer; }
.toast button[hidden] { display: none; }
@media (max-width: 640px) {
  .row { grid-template-columns: 24px 12px 1fr auto; } .row .rwhen, .row.head { display: none; }
  .search { width: 100%; order: 5; }
}
body.compact .meta, body.compact .memo, body.compact .tasks, body.compact .controls, body.compact .bulk, body.compact .foot { display: none !important; }

/* Celebration + log */
#confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 30; }
#confetti[hidden] { display: none; }
.tools .cta { opacity: 1; font-weight: 700; background: var(--ink); color: var(--paper); }
.tools .btn-missed[hidden] { display: none; }
.notes.logview { display: block; max-width: 900px; }
.hero { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 18px; margin-bottom: 18px; }
.lvname { font-size: 20px; font-weight: 700; }
.xpbar { height: 10px; border-radius: 6px; background: var(--bg); margin: 8px 0 4px; overflow: hidden; }
.xpbar i { display: block; height: 100%; background: linear-gradient(90deg, #ffd93b, #ff9f43); }
.xptxt { font-size: 12px; color: var(--muted); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 10px; margin: 16px 0; }
.stat { background: var(--bg); border-radius: 10px; padding: 10px; text-align: center; }
.stat b { display: block; font-size: 22px; } .stat span { font-size: 11px; color: var(--muted); }
.weeks { display: flex; gap: 6px; align-items: flex-end; height: 70px; }
.wk { flex: 1; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 3px; }
.wk i { width: 100%; background: #ffd93b; border-radius: 4px 4px 0 0; } .wk small { font-size: 10px; color: var(--muted); }
.badges { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-bottom: 20px; }
.badge { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px; text-align: center; opacity: .5; }
.badge.got { opacity: 1; border-color: #e0b800; }
.badge .bi { font-size: 28px; display: block; } .badge small { display: block; font-size: 11px; color: var(--muted); }
.loghead { display: flex; justify-content: space-between; align-items: center; } .loghead h2 { font-size: 16px; margin: 8px 0; }
.logrow { display: grid; grid-template-columns: 30px 1fr auto 70px; gap: 10px; align-items: center; padding: 9px 12px; border-bottom: 1px solid var(--line); background: var(--card); }
.logrow .lt small { display: block; color: var(--muted); font-size: 12px; } .logrow .ld { font-size: 12px; color: var(--muted); }
.logrow .lx { font-weight: 600; color: #2e9d4f; text-align: right; font-size: 13px; }
.logrow.passed { opacity: .65; }

.qa { max-width: 1200px; margin: 0 auto; padding: 12px 20px 0; }
.qa input { width: 100%; font: inherit; font-size: 15px; padding: 11px 16px; border: 1px solid var(--line); border-radius: 12px; background: var(--card); color: var(--fg); }
.qa input:focus { outline: 2px solid #ffd93b; border-color: transparent; }
body.compact .qa { display: none; }
.chip.pace { background: rgba(255,200,0,.35); }
.foot small a { color: inherit; }
