/* Trace — dark, mobile-first */

:root {
  --bg: #0e1116;
  --panel: #161b22;
  --panel2: #1b222c;
  --line: #283040;
  --text: #e8ebf1;
  --muted: #93a0b4;
  --accent: #46d17f;
  --accent-soft: rgba(70, 209, 127, 0.13);
  --today: #6cb6ff;    /* "today" ring + number — distinct from green filled days */
  --grey: #14181f;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --hmc: 11px; /* heatmap cell size */
}

* { box-sizing: border-box; }
html { color-scheme: dark; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15.5px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
h1 { font-size: 1.2rem; margin: 6px 0; }
h2 { font-size: 1rem; margin: 22px 0 10px; color: var(--text); }

/* ---------------------------------------------------------------- header */
.top {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; padding: 10px 14px; border-bottom: 1px solid var(--line);
  background: rgba(14, 17, 22, 0.92);
}
.brand { font-weight: 700; font-size: 17px; color: var(--text); letter-spacing: 0.02em; }
.brand:hover { color: var(--text); }
.brand .dot { color: var(--accent); margin-right: 4px; }
.top nav { display: flex; gap: 2px; }
.top nav a {
  padding: 7px 10px; font-size: 13.5px; font-weight: 500;
  color: var(--muted); border-radius: 8px;
}
.top nav a:hover { color: var(--text); background: var(--panel); }

main { padding: 14px 12px 48px; }
.page { max-width: 760px; margin: 0 auto; }

.sub { color: var(--muted); font-size: 13px; margin: -2px 0 14px; }
.empty { color: var(--muted); padding: 8px 2px; }
.back { display: inline-block; margin: 2px 0 8px; font-size: 13.5px; color: var(--muted); }
.back:hover { color: var(--accent); }
.hint { color: var(--muted); font-weight: 400; font-size: 11px; }

mark { background: #f7d654; color: #131722; border-radius: 3px; padding: 0 2px; }

/* ---------------------------------------------------------------- buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 9px 16px; border-radius: 9px;
  border: 1px solid var(--line); background: var(--panel);
  color: var(--text); font: inherit; font-weight: 600; font-size: 14px;
  cursor: pointer; user-select: none; text-decoration: none;
}
.btn:hover { border-color: #3a4556; color: var(--text); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #07240f; }
.btn.primary:hover { background: #63e79a; border-color: #63e79a; }
.btn.danger { background: #2a1418; border-color: #5c2733; color: #ff93a6; }
.btn.danger:hover { background: #3a1a20; }

/* ---------------------------------------------------------------- calendar */
.calwrap { margin: 0 auto; padding: 4px 6px 30px; max-width: 1040px; }
.calbar { display: flex; align-items: center; justify-content: space-between; padding: 0 2px; }
.mnav { display: flex; align-items: center; gap: 4px; }
.mnav h1 { font-size: 16.5px; font-weight: 650; margin: 0 6px; min-width: 8.5ch; text-align: center; }
.btn-arrow {
  width: 36px; height: 36px; display: grid; place-items: center;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 9px; color: var(--text); font-size: 17px; user-select: none;
}
.btn-arrow:hover { border-color: #3a4556; }
.today-link { font-size: 12.5px; color: var(--muted); padding: 6px 8px; margin-left: 4px; white-space: nowrap; }
.today-link:hover { color: var(--accent); }

.dow {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px;
  margin: 12px 0 4px;
}
.dow span {
  text-align: center; font-size: 10.5px; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--muted);
}

.calgrid {
  display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 3px;
  grid-auto-rows: minmax(42px, auto);
}
.cell {
  position: relative; display: flex; flex-direction: column;
  min-width: 0; overflow: hidden;
  background: var(--grey); border: 1px solid #1c212b; border-radius: 7px;
  padding: 2px;
}
.cell.pad { background: transparent; border-color: transparent; }
.cell .num {
  padding: 3px 5px 0 6px; font-size: 11.5px; color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.cell.full { background: #17251d; border-color: #2d5945; }
.cell.full .num { color: #bcf2d2; }
.cell.today { box-shadow: inset 0 0 0 2px var(--today); }
.cell.today .num { color: var(--today); font-weight: 700; }
.cell .chips-box { display: none; } /* compact mobile cells show the day number only */
.cell .stretch { position: absolute; inset: 0; z-index: 1; border-radius: 6px; }
.cell .stretch:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.cell:hover { border-color: #33405a; }
.cell.full:hover { border-color: #3f7a5c; }

/* Desktop: roomy square cells; whole month fits the viewport (no scroll). */
@media (min-width: 760px) {
  .calwrap {
    max-width: min(1040px, calc((100vh - 215px) * 7 / 6));
    padding: 10px 16px 30px;
  }
  .mnav h1 { font-size: 19px; min-width: 10ch; }
  .dow { gap: 4px; margin: 14px 0 5px; }
  .dow span { font-size: 11px; }
  .calgrid { gap: 4px; grid-auto-rows: auto; }
  .cell { aspect-ratio: 1 / 1; border-radius: 10px; padding: 4px; }
  .cell .num { font-size: 13px; padding: 5px 6px 0 7px; }
  .cell .stretch { border-radius: 9px; }
  .cell .chips-box {
    display: flex; flex-wrap: wrap; gap: 3px; align-content: flex-start;
    overflow: hidden; max-height: 58%; margin-top: auto; padding: 0 3px 4px;
    position: relative; z-index: 2;
  }
}

/* ------------------------------------------------------------------ chips */
/* Each tag gets its own color via --chip-bg/--chip-fg (set inline per chip). */
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; position: relative; z-index: 2; }
.chip {
  display: inline-block; max-width: 100%; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap;
  background: var(--chip-bg, var(--accent-soft)); color: var(--chip-fg, #a9edc2);
  border-radius: 999px; padding: 2px 10px; font-size: 12.5px; line-height: 1.5;
}
.chip:hover { filter: brightness(1.3); }
.chip.mini { font-size: 10px; padding: 1px 7px; line-height: 1.4; max-width: 100%; flex: 0 1 auto; min-width: 0; }
.chip.big { font-size: 15px; padding: 4px 14px; }

/* ---------------------------------------------------------------- day view */
.dv-title { margin: 4px 0 8px; font-size: 1.25rem; }
.meta { font-size: 12px; color: var(--muted); margin: 18px 0 4px; }
.actions { display: flex; gap: 10px; margin: 6px 0 0; }
.actions form { margin: 0; }
.dnav {
  display: flex; justify-content: space-between; gap: 14px;
  border-top: 1px solid var(--line); margin-top: 20px; padding-top: 14px;
  font-size: 13.5px; flex-wrap: wrap;
}
.dnav a, .dnav span { color: var(--muted); }
.dnav a:hover { color: var(--accent); }

/* ------------------------------------------------------------ markdown body */
.md { overflow-wrap: break-word; margin-top: 12px; }
.md > :first-child { margin-top: 0; }
.md h1 { font-size: 1.45em; margin: 1em 0 0.4em; }
.md h2 { font-size: 1.25em; margin: 1.2em 0 0.4em; }
.md h3 { font-size: 1.1em; margin: 1.2em 0 0.4em; }
.md h4, .md h5, .md h6 { font-size: 1em; margin: 1.2em 0 0.4em; }
.md p { margin: 0.6em 0; }
.md ul, .md ol { margin: 0.6em 0; padding-left: 1.6em; }
.md li { margin: 0.25em 0; }
.md pre {
  background: #0b0e13; border: 1px solid var(--line); border-radius: 10px;
  padding: 12px 14px; overflow-x: auto; margin: 0.8em 0;
}
.md pre code { background: none; border: 0; padding: 0; font-size: 0.9em; }
.md code {
  font-family: var(--mono); font-size: 0.88em;
  background: var(--panel2); border-radius: 6px; padding: 0.12em 0.4em;
}
.md table { border-collapse: collapse; margin: 0.8em 0; display: block; overflow-x: auto; max-width: 100%; }
.md th, .md td { border: 1px solid var(--line); padding: 6px 12px; text-align: left; }
.md th { background: var(--panel); }
.md blockquote { margin: 0.8em 0; padding: 2px 0 2px 14px; border-left: 3px solid var(--line); color: var(--muted); }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 1.4em 0; }

/* -------------------------------------------------------------------- rows */
.rows { display: flex; flex-direction: column; gap: 8px; }
.row {
  position: relative; display: block; color: inherit;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; padding: 12px 14px;
}
.row:hover { background: var(--panel2); border-color: #39424f; }
.row .when { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.row a.when { color: var(--muted); }
.row .preview { margin: 6px 0 0; font-size: 14px; color: #c3cbd7; overflow-wrap: break-word; }
.row .chips { margin: 8px 0 0; gap: 5px; }
.row .stretch { position: absolute; inset: 0; z-index: 1; border-radius: 12px; }
.row .stretch:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.row.slim { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 14px; }
.row.slim:hover { color: var(--text); }
.row.slim .count { font-size: 12.5px; color: var(--muted); white-space: nowrap; }
.row.slim .tagname { color: var(--chip-fg, var(--text)); font-weight: 700; font-size: 14.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.pager { display: flex; align-items: center; justify-content: space-between; margin-top: 16px; }

/* ------------------------------------------------------------------- forms */
.field { margin: 16px 0; }
label { display: block; font-size: 12.5px; font-weight: 600; margin-bottom: 6px; color: var(--text); }
input, textarea, select {
  width: 100%; background: var(--panel); border: 1px solid var(--line);
  color: var(--text); border-radius: 10px; padding: 10px 12px;
  font: inherit;
}
input:focus, textarea:focus, select:focus {
  border-color: var(--accent); outline: none;
  box-shadow: 0 0 0 3px var(--accent-soft);
}
textarea { font-family: var(--mono); font-size: 14px; line-height: 1.65; min-height: 14em; resize: vertical; }
input[type="date"] { max-width: 240px; color-scheme: dark; }

/* Markdown toolbar (above the description textarea) */
.mdbar { display: flex; flex-wrap: wrap; gap: 4px; margin: 2px 0 8px; }
.mdbar .tb {
  appearance: none; -webkit-appearance: none; border: 1px solid var(--line);
  background: var(--panel); color: var(--muted);
  border-radius: 8px; padding: 5px 9px;
  font: 600 12px/1.2 var(--mono);
  cursor: pointer; user-select: none; white-space: nowrap;
}
.mdbar .tb:hover { color: var(--text); border-color: #3a4556; background: var(--panel2); }
.mdbar .tb:active { transform: translateY(1px); }
.mdbar .tb:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.error {
  background: #2a1418; border: 1px solid #5c2733; color: #ff93a6;
  padding: 10px 14px; border-radius: 10px; font-size: 14px;
}

.entryform .actions { display: flex; gap: 10px; margin-top: 20px; }

.suggest {
  display: flex; flex-direction: column; margin-top: 4px; overflow: hidden;
  background: var(--panel2); border: 1px solid var(--line); border-radius: 10px;
}
.sug {
  appearance: none; border: 0; background: none; color: var(--text);
  text-align: left; padding: 9px 12px; font: inherit; font-size: 14px;
  cursor: pointer;
}
.sug:hover, .sug.active { background: var(--accent-soft); color: var(--accent); }

.searchform { display: flex; gap: 8px; margin: 14px 0 4px; }
.searchform input { flex: 1; }

/* ------------------------------------------------------------------- todo */
.todoform { display: flex; gap: 8px; margin: 14px 0 18px; }
.todoform input[type="text"] { flex: 1; }
.todos { display: flex; flex-direction: column; gap: 7px; }
.todo-item { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 11px 14px; }
.todo-item:hover { background: var(--panel2); border-color: #39424f; }
.todo-item label { display: flex; align-items: center; gap: 12px; margin: 0;
                    font-size: 15px; font-weight: 400; cursor: pointer; }
.todo-item input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--accent); flex: 0 0 auto; }
.todo-text { overflow-wrap: break-word; }
.yearform { display: flex; gap: 10px; align-items: center; margin: 8px 0 10px; }
.yearform label { margin: 0; }
.yearform select { width: auto; font-size: 14px; padding: 8px 10px; }

/* ----------------------------------------------------------------- heatmap */
.hmwrap { overflow-x: auto; margin: 8px 0 6px; padding: 4px 2px 8px; }
.hmmonths, .hmgrid {
  display: grid;
  grid-template-columns: 2.6em repeat(var(--cols), var(--hmc));
  column-gap: 3px; row-gap: 3px;
}
.hmmonths { grid-template-rows: 14px; margin-bottom: 4px; }
.hmlabel { font-size: 10px; color: var(--muted); white-space: nowrap; overflow: hidden; padding-left: 2px; }
.hmgrid { grid-template-rows: repeat(7, var(--hmc)); grid-auto-flow: column; }
.hm-wd { font-size: 9px; color: var(--muted); align-self: center; text-align: right; line-height: 1.1; }
.hm-c { border-radius: 3px; background: #1d242f; }
.hm-c.gap { background: transparent; }
.hm-c.on { background: var(--hm-on, var(--accent)); }
.hm-c.on:hover { background: var(--hm-on, var(--accent)); filter: brightness(1.35); }

.tagtitle { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin: 4px 0 2px; }
.tagtitle .count { color: var(--muted); font-size: 1rem; }

@media (max-width: 420px) {
  main { padding: 10px 8px 40px; }
  .top { padding: 9px 10px; }
  .top nav a { padding: 7px 7px; font-size: 13px; }
}