/* Blueprint, mobile first: deep-blue drafting paper, fine grid, thin cyan linework, monospace lettering.
   Base rules target a 360 px phone; min-width queries add the desktop frame. */
:root {
  --paper: #0a2a5e;
  --paper-deep: #071f47;
  --ink: #e6f1ff;
  --ink-dim: #a9c6ea;
  --line: #7fc4ff;
  --line-soft: rgba(127, 196, 255, 0.35);
  --grid: rgba(127, 196, 255, 0.09);
  --grid-major: rgba(127, 196, 255, 0.17);
  --ok: #9be7b3;
  --warn: #ffd37a;
  --review: #d4c2ff;
  --bad: #ff9aa2;
  --mono: ui-monospace, "SFMono-Regular", "JetBrains Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --tabbar-h: 64px;
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { background: var(--paper-deep); -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  color: var(--ink);
  font: 14px/1.5 var(--mono);
  background-color: var(--paper);
  background-image:
    linear-gradient(var(--grid-major) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-major) 1px, transparent 1px),
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 96px 96px, 96px 96px, 24px 24px, 24px 24px;
  overflow-wrap: anywhere;
  overscroll-behavior-y: none;
}
a { color: var(--line); text-underline-offset: 3px; }
a:focus-visible, button:focus-visible, select:focus-visible, input:focus-visible, summary:focus-visible {
  outline: 2px solid #fff; outline-offset: 2px;
}

/* ---- page frame (phone: edge to edge, room for the tab bar and the notch) ---- */
.sheet {
  max-width: 980px; margin: 0 auto;
  padding: calc(12px + env(safe-area-inset-top)) calc(12px + env(safe-area-inset-right)) calc(var(--tabbar-h) + 16px + env(safe-area-inset-bottom)) calc(12px + env(safe-area-inset-left));
}
.titleblock {
  display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center;
  border: 1px solid var(--line); padding: 8px 12px; margin-bottom: 14px;
  background: rgba(7, 31, 71, 0.7);
}
.tb-name { font-weight: 700; letter-spacing: 0.16em; flex: 1 1 auto; }
.tb-mark { color: var(--line); }
.tb-meta { display: none; gap: 14px; margin: 0; }
.tb-meta div { border-left: 1px solid var(--line-soft); padding-left: 10px; }
dt { color: var(--ink-dim); font-size: 11px; letter-spacing: 0.12em; }
dd { margin: 0; }
.tb-out { margin: 0; }
.topnav { display: none; gap: 6px; }
.topnav a, .tabbar a { text-decoration: none; color: var(--ink-dim); letter-spacing: 0.12em; font-size: 12px; font-weight: 700; }
.topnav a { padding: 10px 12px; border: 1px solid transparent; min-height: 44px; display: inline-flex; align-items: center; }
.topnav a[aria-current="page"] { color: var(--ink); border-color: var(--line); }

/* bottom tab bar: the primary navigation on phones */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: 1fr 1fr;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: var(--paper-deep); border-top: 1px solid var(--line);
}
.tabbar a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 11px; min-height: 48px; }
.tabbar a[aria-current="page"] { color: var(--ink); box-shadow: inset 0 3px 0 var(--line); background: rgba(127, 196, 255, 0.1); }
.tab-ico { font-size: 20px; line-height: 1; }

.hint {
  display: flex; gap: 10px; align-items: center; justify-content: space-between;
  border: 1px dashed var(--line); padding: 8px 12px; margin-bottom: 14px; font-size: 12px; background: rgba(7, 31, 71, 0.7);
}
.hint[hidden], #install-btn[hidden] { display: none; }

/* ---- panels ---- */
.panel {
  position: relative; border: 1px solid var(--line); padding: 16px 12px 12px; margin: 0 0 16px;
  background: rgba(7, 31, 71, 0.6);
}
.panel::before, .panel::after { /* drafting corner ticks */
  content: ""; position: absolute; width: 10px; height: 10px; border: 2px solid var(--line);
}
.panel::before { top: -2px; left: -2px; border-right: 0; border-bottom: 0; }
.panel::after { bottom: -2px; right: -2px; border-left: 0; border-top: 0; }
.panel.narrow { max-width: 420px; margin-left: auto; margin-right: auto; }
.panel-title {
  margin: 0 0 12px; font-size: 13px; letter-spacing: 0.14em; font-weight: 700;
  border-bottom: 1px dashed var(--line-soft); padding-bottom: 8px;
}
.repo { margin: 0 0 12px; }
.repo-name { margin: 0 0 6px; font-size: 13px; color: var(--line); letter-spacing: 0.08em; }
.items { list-style: none; margin: 0; padding: 0; }
.item { padding: 4px 0; border-top: 1px dotted var(--line-soft); }
.item:first-child { border-top: 0; }
.item-link { color: var(--ink); font-weight: 600; text-decoration: none; display: block; padding: 8px 0 2px; min-height: 44px; }
.item-link:hover { text-decoration: underline; }
.item-meta { display: flex; flex-wrap: wrap; gap: 6px 12px; padding: 0 0 8px; color: var(--ink-dim); font-size: 12px; }
.badge {
  display: inline-block; border: 1px solid currentColor; padding: 0 8px; font-size: 11px; letter-spacing: 0.1em; font-weight: 700;
}
.s-running { color: var(--line); }
.s-done { color: var(--ok); }
.s-stalled { color: var(--warn); border-style: dashed; }
.s-in_review { color: var(--review); }
.e-ok { color: var(--ok); }
.e-missing { color: var(--bad); border-style: dashed; }
.e-unknown { color: var(--warn); border-style: dotted; }

/* ---- forms and buttons (44 px touch targets) ---- */
.filters { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; align-items: end; margin-bottom: 12px; }
.filters .btn { grid-column: 1 / -1; }
.count, .empty, .back { color: var(--ink-dim); letter-spacing: 0.1em; font-size: 12px; }
.back { display: inline-block; min-height: 44px; line-height: 44px; }
label { display: block; font-size: 11px; letter-spacing: 0.12em; color: var(--ink-dim); }
input, select {
  display: block; width: 100%; margin-top: 4px; min-height: 48px; padding: 8px 10px;
  color: var(--ink); background: var(--paper-deep); border: 1px solid var(--line); border-radius: 0; font: inherit; font-size: 16px; /* 16px stops iOS zoom-on-focus */
}
.btn {
  display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 8px 16px;
  color: var(--ink); background: transparent; border: 1px solid var(--line); text-decoration: none;
  font: inherit; font-size: 12px; font-weight: 700; letter-spacing: 0.12em; cursor: pointer; border-radius: 0;
}
.btn:hover, .btn:active { background: rgba(127, 196, 255, 0.18); }
.btn.primary { background: var(--line); color: var(--paper-deep); }
.stack { display: grid; gap: 14px; }
.alert { border: 1px dashed var(--bad); color: var(--bad); padding: 8px 10px; margin: 0 0 12px; }

/* ---- detail ---- */
.dims { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; margin: 0; }
.dims div { border-left: 1px solid var(--line-soft); padding-left: 10px; min-width: 0; }
.mono-small { font-size: 11px; }
.steps { list-style: none; margin: 0; padding: 0 0 0 12px; border-left: 1px solid var(--line); }
.step { position: relative; padding: 0 0 14px 14px; }
.step::before { content: ""; position: absolute; left: -18px; top: 7px; width: 10px; height: 10px; background: var(--paper); border: 2px solid var(--line); }
.k-prompt::before { background: var(--line); }
.k-session_end::before, .k-stop::before { border-style: dashed; }
.step-head { font-size: 12px; color: var(--ink-dim); display: flex; flex-wrap: wrap; gap: 4px 10px; }
.step-kind { letter-spacing: 0.1em; color: var(--line); }
.step-sum { margin-top: 2px; }
details { margin-top: 4px; }
summary { cursor: pointer; color: var(--ink-dim); font-size: 11px; letter-spacing: 0.1em; min-height: 32px; display: flex; align-items: center; }
pre { margin: 6px 0 0; padding: 8px; background: var(--paper-deep); border: 1px solid var(--line-soft); white-space: pre-wrap; overflow-wrap: anywhere; font: 12px/1.45 var(--mono); max-width: 100%; }
.foot { margin-top: 12px; color: var(--ink-dim); font-size: 11px; letter-spacing: 0.1em; text-align: center; }

/* ---- statistics and insights ---- */
.stat-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-bottom: 12px; }
.stat { border: 1px solid var(--line-soft); padding: 8px 10px; display: flex; flex-direction: column; min-width: 0; }
.stat.big { grid-column: 1 / -1; border-color: var(--line); background: rgba(127, 196, 255, 0.1); }
.stat-n { font-size: 22px; font-weight: 700; line-height: 1.15; overflow-wrap: anywhere; }
.stat.big .stat-n { font-size: 34px; }
.stat-l { color: var(--ink-dim); font-size: 11px; letter-spacing: 0.1em; }
.bars { list-style: none; margin: 0 0 10px; padding: 0; display: grid; gap: 2px; }
.bars li { display: grid; grid-template-columns: 8ch minmax(0, 1fr) 3ch; gap: 8px; align-items: center; min-height: 28px; }
.bars.wide li { grid-template-columns: 11ch minmax(0, 1fr) 3ch; }
.bar-l { color: var(--ink-dim); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-b { color: var(--line); overflow: hidden; white-space: nowrap; }
.bar-n { text-align: right; font-weight: 700; }
/* 24-hour histogram: bar height comes from a class (inline styles are blocked by CSP) */
.hours { list-style: none; margin: 0 0 8px; padding: 0; display: grid; grid-template-columns: repeat(24, minmax(0, 1fr)); gap: 2px; align-items: end; height: 120px; border-bottom: 1px solid var(--line); }
.hr { position: relative; height: 100%; display: flex; align-items: flex-end; justify-content: center; }
.hr::before { content: ""; display: block; width: 100%; background: var(--line); height: 0; }
.hr.lv0::before { height: 2px; opacity: 0.35; }
.hr.lv1::before { height: 10%; } .hr.lv2::before { height: 20%; } .hr.lv3::before { height: 30%; }
.hr.lv4::before { height: 40%; } .hr.lv5::before { height: 50%; } .hr.lv6::before { height: 60%; }
.hr.lv7::before { height: 70%; } .hr.lv8::before { height: 80%; } .hr.lv9::before { height: 90%; } .hr.lv10::before { height: 100%; }
.hr-n { position: absolute; bottom: -20px; font-size: 10px; color: var(--ink-dim); }
.hours + .count { margin-top: 26px; }

/* ---- bigger screens: framed drawing sheet, top nav instead of tab bar ---- */
@media (min-width: 700px) {
  body { font-size: 14px; background-size: 120px 120px, 120px 120px, 24px 24px, 24px 24px; }
  .sheet { margin: 24px auto; border: 2px solid var(--line); padding: 24px; background: rgba(10, 42, 94, 0.55); }
  .tabbar { display: none; }
  .topnav { display: flex; }
  .tb-meta { display: flex; }
  .titleblock { padding: 10px 14px; margin-bottom: 20px; }
  .panel { padding: 18px 16px 14px; margin-bottom: 22px; }
  .filters { display: flex; flex-wrap: wrap; }
  .filters label { flex: 1 1 140px; }
  .filters .btn { grid-column: auto; }
  .stat-row { grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); }
  .stat.big { grid-column: auto; }
  .dims { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px 20px; }
  .hours { height: 160px; }
  .bars li { grid-template-columns: 9ch minmax(0, 1fr) 3ch; }
  .bars.wide li { grid-template-columns: 18ch minmax(0, 1fr) 3ch; }
}
@media (display-mode: standalone) {
  #install-btn, #ios-hint { display: none !important; }
}
@media (prefers-reduced-motion: no-preference) { .btn { transition: background 0.15s; } }

/* live indicator */
.live { font-size: 11px; font-weight: 700; letter-spacing: 0.12em; padding: 2px 8px; border: 1px solid currentColor; color: var(--ink-dim); white-space: nowrap; }
.live::before { content: "●"; margin-right: 6px; }
.live[data-state="on"] { color: var(--ok); }
.live[data-state="off"] { color: var(--warn); border-style: dashed; }
@media (prefers-reduced-motion: no-preference) { .live[data-state="on"]::before { animation: blink 2s ease-in-out infinite; } }
@keyframes blink { 50% { opacity: 0.25; } }
