/* 先说 — a ledger, so it reads like one: a cool near-neutral ground, one
   restrained ink-blue accent, and figures set in tabular monospace everywhere a
   number could be compared to another number. Colour is spent on exactly two
   things: what's overdue, and which way a gap points. */
:root {
  --bg: #0f1014;
  --panel: #171922;
  --line: #242734;
  --ink: #e8eaf0;
  --dim: #939aad;
  --faint: #636b80;
  --accent: #8ba3e8;      /* the ledger's ink */
  --good: #57b877;
  --bad: #e0685f;
  --warn: #e0b155;
  --radius: 14px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
        "Hiragino Sans GB", "Microsoft YaHei", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
.hidden { display: none !important; }
b { font-weight: 600; }

/* ---------- header ---------- */
.topbar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: max(10px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right))
           10px max(12px, env(safe-area-inset-left));
  border-bottom: 1px solid var(--line); background: #13141b;
  position: sticky; top: 0; z-index: 10;
}
.mark {
  width: 34px; height: 34px; flex: none; border-radius: 10px;
  display: grid; place-items: center; font-weight: 700; color: #12131a;
  background: linear-gradient(140deg, #b9c8f5, var(--accent));
}
.titles { margin-right: auto; min-width: 0; }
.titles h1 { margin: 0; font-size: 17px; letter-spacing: .06em; }
.titles p { margin: 0; font-size: 11px; color: var(--faint); white-space: nowrap;
            overflow: hidden; text-overflow: ellipsis; }
.tabs { display: flex; gap: 6px; }
.tab {
  position: relative; background: none; border: 1px solid transparent; color: var(--dim);
  padding: 7px 11px; border-radius: 10px; cursor: pointer; font-size: 14px;
}
.tab.on { background: var(--panel); border-color: var(--line); color: var(--ink); }
.badge {
  margin-left: 5px; font-size: 11px; font-family: var(--mono);
  background: var(--warn); color: #12131a; border-radius: 999px; padding: 1px 6px;
}
@media (max-width: 520px) { .tabs { flex-basis: 100%; } .tabs .tab { flex: 1 1 0; } }

main { padding: 14px max(12px, env(safe-area-inset-right))
                24px max(12px, env(safe-area-inset-left)); max-width: 760px; margin: 0 auto; }
input, button, textarea, select { font: inherit; font-family: inherit; }

/* ---------- panels & forms ---------- */
.panel {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px; margin-bottom: 14px;
}
.panel h2 { margin: 0 0 6px; font-size: 15px; }
.sub { color: var(--dim); font-size: 13px; }
.tiny { font-size: 12px; color: var(--faint); line-height: 1.5; }
.field { display: block; margin: 12px 0; }
.field > span { display: block; font-size: 12px; color: var(--dim); margin-bottom: 5px; }
.field input, .field textarea {
  width: 100%; padding: 11px 12px; background: #0d0e12; color: var(--ink);
  border: 1px solid var(--line); border-radius: 11px; resize: vertical;
}
.field input[type="number"], .field input[type="date"] { font-variant-numeric: tabular-nums; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
@media (max-width: 420px) { .grid2 { grid-template-columns: 1fr; } }

.kinds { display: flex; gap: 6px; background: #0d0e12; border: 1px solid var(--line);
         border-radius: 11px; padding: 4px; }
.kinds .kind { flex: 1 1 0; background: none; border: none; color: var(--dim);
               padding: 9px 8px; border-radius: 8px; cursor: pointer; font-size: 14px; }
.kinds .kind.on { background: var(--panel); color: var(--ink); box-shadow: 0 1px 0 #0006; }

/* The slider is the main control on the main screen, so it gets a real thumb. */
input[type="range"] { width: 100%; -webkit-appearance: none; appearance: none;
                      background: transparent; height: 34px; }
input[type="range"]::-webkit-slider-runnable-track {
  height: 6px; border-radius: 999px; background: linear-gradient(90deg, var(--line), var(--accent)); }
input[type="range"]::-moz-range-track {
  height: 6px; border-radius: 999px; background: linear-gradient(90deg, var(--line), var(--accent)); }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 28px; height: 28px; border-radius: 50%;
  background: var(--ink); border: none; margin-top: -11px; }
input[type="range"]::-moz-range-thumb {
  width: 28px; height: 28px; border-radius: 50%; background: var(--ink); border: none; }
#p-show { font-family: var(--mono); font-size: 15px; color: var(--ink); }

.quick { display: flex; gap: 6px; flex-wrap: wrap; }
.quick .q { flex: 1 1 0; min-width: 48px; padding: 8px 4px; font-family: var(--mono);
            background: #0d0e12; color: var(--dim); border: 1px solid var(--line);
            border-radius: 9px; cursor: pointer; }
.quick .q.on { color: var(--ink); border-color: var(--accent); }

.row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.row > button { flex: 1 1 0; min-width: 92px; }
.primary, .ghost {
  min-height: 46px; padding: 10px 14px; cursor: pointer;
  border-radius: 11px; border: 1px solid var(--line);
  background: #1e2230; color: var(--ink);
}
.primary { background: var(--accent); color: #12131a; font-weight: 700; border-color: transparent; }
.primary.big { width: 100%; margin-top: 6px; min-height: 52px; font-size: 17px; }
.primary:active, .ghost:active { filter: brightness(1.2); }

/* ---------- the open ledger ---------- */
.item { border-top: 1px solid var(--line); padding: 13px 0; }
.item:first-of-type { border-top: none; }
.item .claim { font-size: 15px; line-height: 1.45; }
.item .meta { display: flex; gap: 8px; flex-wrap: wrap; align-items: center;
              margin-top: 6px; font-size: 12px; color: var(--faint); }
.chip { font-family: var(--mono); font-size: 12px; padding: 2px 8px; border-radius: 999px;
        background: #0d0e12; border: 1px solid var(--line); color: var(--dim); }
.chip.late { color: var(--warn); border-color: #4a3d24; }
.chip.tag { font-family: inherit; }
.settle { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.settle button { flex: 1 1 0; min-width: 78px; min-height: 42px; border-radius: 10px;
                 border: 1px solid var(--line); background: #1e2230; color: var(--ink);
                 cursor: pointer; }
.settle .yes:active { background: #1a2a1f; }
.settle .no:active  { background: #2a1a19; }
.settle .void { color: var(--faint); }
/* The number gets its own line. Sharing one with three buttons pushed the row
   to three ragged lines on a phone — measured, not guessed. */
.settle input { flex: 1 1 100%; padding: 10px 12px; background: #0d0e12; color: var(--ink);
                border: 1px solid var(--line); border-radius: 10px;
                font-variant-numeric: tabular-nums; }
.drop { background: none !important; border: none !important; color: var(--faint);
        flex: 0 0 auto !important; min-width: 0 !important; }

/* ---------- the books ---------- */
.verdict { padding: 14px 15px; border-radius: 12px; margin-bottom: 14px; font-size: 14.5px;
           background: var(--panel); border: 1px solid var(--line); }
.verdict b { display: block; font-size: 16px; margin-bottom: 4px; }
.verdict.bad  { border-color: #4a2f2c; background: #221819; }
.verdict.warn { border-color: #4a3d24; background: #221d16; }
.verdict.good { border-color: #2c4433; background: #172119; }

.stat-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
@media (max-width: 520px) { .stat-row { grid-template-columns: repeat(2, 1fr); } }
.stat { background: #0d0e12; border: 1px solid var(--line); border-radius: 11px;
        padding: 10px; text-align: center; }
.stat .n { font-size: 20px; font-family: var(--mono); font-variant-numeric: tabular-nums; }
.stat .l { font-size: 11px; color: var(--faint); margin-top: 2px; }

/* The calibration table: said vs happened, one row per confidence band. */
.cal { border-top: 1px solid var(--line); padding: 10px 0 12px; }
.cal:first-of-type { border-top: none; }
.cal .head { display: flex; justify-content: space-between; font-size: 13px; gap: 10px; }
.cal .head .lab { font-family: var(--mono); color: var(--dim); }
.cal .head .val { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.cal .bars { margin-top: 7px; display: grid; gap: 4px; }
.cal .bar { height: 9px; background: #0d0e12; border-radius: 999px; overflow: hidden; }
.cal .bar > i { display: block; height: 100%; border-radius: 999px; }
.cal .bar.said > i   { background: var(--faint); }
.cal .bar.actual > i { background: var(--accent); }
.cal.thin { opacity: .45; }

.split { display: grid; gap: 8px; }
.part { display: flex; justify-content: space-between; align-items: baseline; gap: 10px;
        padding: 9px 0; border-top: 1px solid var(--line); }
.part:first-child { border-top: none; }
.part .k { font-size: 13.5px; }
.part .k small { display: block; color: var(--faint); font-size: 11.5px; line-height: 1.45; }
.part .v { font-family: var(--mono); font-variant-numeric: tabular-nums; font-size: 15px;
           white-space: nowrap; }
.part .v.good { color: var(--good); }
.part .v.bad  { color: var(--bad); }

.tagrow { display: flex; justify-content: space-between; gap: 10px; padding: 9px 0;
          border-top: 1px solid var(--line); font-size: 13.5px; align-items: baseline; }
.tagrow > span:first-child { flex: 0 0 auto; white-space: nowrap; }
.tagrow .v { text-align: right; }
.tagrow:first-of-type { border-top: none; }
.tagrow .v { font-family: var(--mono); font-variant-numeric: tabular-nums; color: var(--dim); }

.foot { text-align: center; padding: 6px 0 max(18px, env(safe-area-inset-bottom));
        color: var(--faint); font-size: 11px; }

/* On a phone the tag name and its three figures can't share a line without the
   figures wrapping into a ragged block. Stack them instead. */
@media (max-width: 560px) {
  .tagrow { flex-direction: column; gap: 2px; }
  .tagrow .v { text-align: left; }
}
