:root {
  --ink: #0e1a12;
  --ink-2: #2f3d34;
  --paper: #ffffff;
  --paper-2: #eef1ea;
  --line: #0e1a12;
  --pine: #134a2c;
  --pine-deep: #0c3620;
  --flag: #9c2a10;
  --flag-bg: #fbe9e3;
  --seal: #0e1a12;
  --tap: 56px;
  --radius: 10px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--paper); color: var(--ink); }
body { font-size: 19px; line-height: 1.35; overscroll-behavior: none; padding-bottom: env(safe-area-inset-bottom); }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; letter-spacing: -0.01em; }
h1 { font-size: 26px; font-weight: 800; }
h2 { font-size: 22px; font-weight: 800; }
h3 { font-size: 17px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-2); }
p { margin: 0 0 10px; }
.muted { color: var(--ink-2); }
.num { font-variant-numeric: tabular-nums; }
.sr { position: absolute; left: -9999px; }

/* ── Frame ────────────────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 5; background: var(--paper);
  border-bottom: 3px solid var(--line);
  display: flex; align-items: center; gap: 10px; padding: 10px 14px;
  padding-top: calc(10px + env(safe-area-inset-top));
}
.topbar .brand { font-weight: 900; font-size: 22px; letter-spacing: 0.02em; }
.topbar .grow { flex: 1; }
.obs-pill {
  border: 3px solid var(--line); border-radius: 999px; padding: 8px 14px; font-weight: 800;
  background: var(--paper); min-height: 48px; display: inline-flex; align-items: center; gap: 8px; cursor: pointer;
}
.obs-pill .dot { width: 14px; height: 14px; border-radius: 50%; background: var(--pine); }
.obs-pill.o2 .dot { background: var(--ink); }
main { padding: 16px 14px 120px; max-width: 720px; margin: 0 auto; }
.view-title { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 14px; }

/* ── Buttons ──────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap); padding: 12px 18px; border-radius: var(--radius);
  border: 3px solid var(--line); background: var(--paper); font-weight: 800; font-size: 19px;
  cursor: pointer; text-align: center; width: 100%; user-select: none;
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--pine); color: #fff; border-color: var(--pine-deep); }
.btn.quiet { border-color: transparent; background: var(--paper-2); }
.btn.danger { color: var(--flag); border-color: var(--flag); }
.btn.sm { min-height: 48px; padding: 8px 14px; font-size: 17px; width: auto; }
.btn.icon { width: var(--tap); padding: 0; flex: 0 0 var(--tap); font-size: 26px; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 4px solid #f5b700; outline-offset: 2px; }
.row { display: flex; gap: 10px; align-items: center; }
.row > * { flex: 1 1 0; min-width: 0; }
input[type="date"], input[type="time"] { min-width: 0; width: 100%; font-size: 19px; padding-left: 10px; padding-right: 6px; -webkit-appearance: none; appearance: none; }
.row .field { margin-bottom: 12px; }
.stack { display: grid; gap: 12px; }

/* ── Fields ───────────────────────────────────────────── */
label.field { display: block; margin-bottom: 12px; }
label.field > span, .field-label { display: block; font-weight: 800; font-size: 16px; margin-bottom: 6px; color: var(--ink-2); text-transform: uppercase; letter-spacing: 0.05em; }
.input, textarea.input {
  width: 100%; min-height: var(--tap); padding: 12px 14px; border: 3px solid var(--line);
  border-radius: var(--radius); background: var(--paper); font-size: 22px; font-weight: 700;
}
textarea.input { min-height: 110px; font-size: 19px; font-weight: 500; resize: vertical; }
.input.big { font-size: 34px; text-align: center; min-height: 72px; }
.input:disabled { background: var(--paper-2); border-color: #9aa59c; color: var(--ink); -webkit-text-fill-color: var(--ink); opacity: 1; }
.seg { display: flex; border: 3px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.seg button {
  flex: 1; min-height: var(--tap); border: 0; background: var(--paper); font-weight: 800; font-size: 19px; cursor: pointer;
  border-right: 3px solid var(--line);
}
.seg button:last-child { border-right: 0; }
.seg button[aria-pressed="true"] { background: var(--ink); color: #fff; }
.seg button:disabled { color: #7a857c; cursor: not-allowed; }
.seg button[aria-pressed="true"]:disabled { background: #55605a; color: #fff; }

/* ── Tabs (plot sections) ─────────────────────────────── */
.tabs {
  position: sticky; top: calc(74px + env(safe-area-inset-top)); z-index: 4; background: var(--paper);
  display: grid; grid-template-columns: repeat(5, 1fr); border: 3px solid var(--line); border-radius: var(--radius); overflow: hidden; margin-bottom: 16px;
}
.tabs button {
  min-height: 60px; border: 0; background: var(--paper); font-weight: 800; font-size: 16px; cursor: pointer; padding: 6px 2px;
  border-right: 3px solid var(--line); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
}
.tabs button:last-child { border-right: 0; }
.tabs button[aria-selected="true"] { background: var(--ink); color: #fff; }
.tabs .st { font-size: 11px; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; opacity: 0.8; }

/* ── Cards & lists ────────────────────────────────────── */
.card { border: 3px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 14px; background: var(--paper); }
.card.soft { border-color: #b8c2ba; }
.plot-item { width: 100%; text-align: left; display: grid; gap: 6px; border: 3px solid var(--line); border-radius: var(--radius); padding: 14px; background: var(--paper); cursor: pointer; margin-bottom: 12px; }
.plot-item .hd { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.plot-item .id { font-size: 24px; font-weight: 900; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 2px solid var(--ink-2); border-radius: 999px; padding: 3px 10px; font-size: 14px; font-weight: 800; color: var(--ink-2); white-space: nowrap; }
.chip.sealed { border-color: var(--ink); color: var(--ink); background: #fff; }
.chip.busy { border-style: dashed; }
.chip.flag { border-color: var(--flag); color: var(--flag); background: var(--flag-bg); }

/* ── Running arithmetic block ─────────────────────────── */
.arith { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 12px 0; }
.arith .cell { border: 3px solid var(--line); border-radius: var(--radius); padding: 10px 12px; }
.arith .cell.wide { grid-column: 1 / -1; }
.arith .k { font-size: 14px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-2); }
.arith .v { font-size: 38px; font-weight: 900; line-height: 1.05; }
.arith .u { font-size: 16px; font-weight: 700; color: var(--ink-2); margin-left: 4px; }

/* ── The placement slot: hidden until sealed ──────────── */
.placement {
  border: 3px dashed #6b776e; border-radius: var(--radius); padding: 14px; text-align: center; margin: 12px 0; color: var(--ink-2);
  font-weight: 700; font-size: 17px;
}
.placement.sealed {
  border: 4px solid var(--seal); border-style: double; color: var(--ink); background: #fff;
}
.placement.sealed .lbl { font-size: 13px; letter-spacing: 0.14em; text-transform: uppercase; font-weight: 900; }
.placement.sealed .rng { font-size: 44px; font-weight: 900; letter-spacing: 0.02em; line-height: 1.1; margin: 4px 0; }
.placement.sealed .raw { font-size: 17px; }
.placement.unmeasured { border-style: solid; border-color: #b8c2ba; }

/* ── Pieces ───────────────────────────────────────────── */
.piece { display: grid; grid-template-columns: 40px 1fr auto; gap: 10px; align-items: center; border-bottom: 2px solid #c9d1cb; padding: 10px 0; }
.piece:last-child { border-bottom: 0; }
.piece .n { font-weight: 900; color: var(--ink-2); }
.piece .main { font-size: 20px; font-weight: 800; }
.piece .sub { font-size: 15px; color: var(--ink-2); }
.piece .acts { display: flex; gap: 6px; }
.flagtxt { color: var(--flag); font-weight: 900; font-size: 14px; letter-spacing: 0.04em; }

/* ── Litter cross ─────────────────────────────────────── */
.cross { display: grid; grid-template-columns: 1fr 1fr 1fr; grid-template-areas: ". N ." "W C E" ". S ."; gap: 10px; margin: 8px 0 14px; }
.cross .pt { display: grid; gap: 4px; }
.cross .pt span { font-size: 14px; font-weight: 900; text-align: center; letter-spacing: 0.08em; color: var(--ink-2); }
.cross .pt.N { grid-area: N; } .cross .pt.S { grid-area: S; } .cross .pt.E { grid-area: E; } .cross .pt.W { grid-area: W; } .cross .pt.C { grid-area: C; }
.cross .pt.C .input { border-width: 4px; }

/* ── Species list ─────────────────────────────────────── */
.sp { display: flex; gap: 8px; align-items: center; border-bottom: 2px solid #c9d1cb; padding: 8px 0; }
.sp .n { width: 34px; font-weight: 900; color: var(--ink-2); }
.sp .input { flex: 1; min-height: 52px; font-size: 19px; }

/* ── Bottom action bar ────────────────────────────────── */
.actionbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; background: var(--paper); border-top: 3px solid var(--line);
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom)); display: flex; gap: 10px; max-width: 720px; margin: 0 auto;
}
.actionbar .btn { flex: 1; }

/* ── Banners ──────────────────────────────────────────── */
.banner { border: 3px solid var(--line); border-radius: var(--radius); padding: 10px 14px; font-weight: 700; margin-bottom: 12px; }
.banner.flag { border-color: var(--flag); background: var(--flag-bg); color: var(--flag); }
.banner.lock { background: var(--paper-2); border-color: #9aa59c; }
.reopened { display: inline-block; border: 2px solid var(--flag); color: var(--flag); border-radius: 6px; padding: 2px 8px; font-size: 13px; font-weight: 900; letter-spacing: 0.04em; }

/* ── Observer gate ────────────────────────────────────── */
.gate { display: grid; gap: 14px; padding-top: 24px; }
.gate .btn { min-height: 96px; font-size: 26px; flex-direction: column; gap: 2px; }
.gate .btn small { font-size: 15px; font-weight: 600; opacity: 0.85; }

/* ── Dialog ───────────────────────────────────────────── */
dialog { border: 4px solid var(--line); border-radius: 14px; padding: 18px; max-width: 420px; width: calc(100% - 28px); font-size: 19px; }
dialog::backdrop { background: rgba(14,26,18,0.55); }
dialog h2 { margin-bottom: 10px; }
dialog .acts { display: grid; gap: 10px; margin-top: 16px; }

.toast { position: fixed; left: 50%; bottom: 110px; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 999px; font-weight: 800; z-index: 9; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
.topbar .ver { font-size: 14px; font-weight: 700; }
@media (max-width: 440px) { .topbar .ver { display: none; } }
.piece .main { font-size: 18px; }
.sp.nn .input { border-style: dashed; color: var(--ink-2); }
