/*
  Live Ink — styles.
  All white: the sheet is marked only by a faint hairline (drawn on the canvas),
  with no guides — just ink and a few quiet controls. Always light, because ink is dark on white paper.
  (To show the sheet's outline or ruled lines instead, see the `edge` and
  `guides` options in src/ink-canvas.js.)
*/
:root {
  --bg: #ffffff;
  --surface: #ffffff;
  --text: #1c1b19;
  --muted: #7d7a72;
  --line: rgba(28, 27, 25, 0.1);
  --hover: rgba(28, 27, 25, 0.06);
  --press: rgba(28, 27, 25, 0.1);
  --ring: #2f6bff;
  --ok: #2f9e62;
  --danger: #c4442f;
  --radius: 8px;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
html { -webkit-tap-highlight-color: transparent; }
@media (pointer: fine) { html { overscroll-behavior: none; } }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: grid;
  grid-template-rows: auto 1fr;
  overflow: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { touch-action: manipulation; cursor: pointer; }
:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: 8px; top: -40px; background: var(--surface); padding: 6px 10px; border-radius: var(--radius); z-index: 10; }
.skip:focus { top: 8px; }

/* ── top bar ─────────────────────────────────────────────── */
.topbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  padding-top: max(10px, env(safe-area-inset-top));
}
.actions { display: flex; gap: 2px; justify-self: end; align-items: center; }
.page-label { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }

.conn {
  justify-self: start;
  display: inline-flex; align-items: center; gap: 8px;
  height: 32px; padding: 0 12px 0 10px;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--surface);
  min-width: 0; max-width: 100%;
}
.conn #status { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conn:hover { background: var(--hover); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.live { background: var(--ok); }

.icon {
  width: 32px; height: 32px;
  display: inline-grid; place-items: center;
  border: 0; border-radius: var(--radius); background: transparent; color: var(--text);
}
.icon:hover { background: var(--hover); }
.icon:active { background: var(--press); }
.icon svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.icon .i-play path, .icon .i-stop rect { fill: currentColor; stroke: none; }
.icon .i-stop { display: none; }
.icon.on .i-play { display: none; }
.icon.on .i-stop { display: block; }
.icon[aria-expanded="true"] { background: var(--press); }
.icon circle { fill: currentColor; stroke: none; }
.icon .fill { fill: currentColor; stroke: none; }
.icon.on { background: var(--press); }
#settings-btn circle { fill: var(--bg); stroke: currentColor; stroke-width: 1.5; }

/* overflow menu */
.menu { position: relative; }
.menu-list {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 5;
  min-width: 180px; padding: 4px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
}
.menu-list button {
  display: block; width: 100%; text-align: left;
  padding: 7px 10px; border: 0; border-radius: 6px; background: none;
}
.menu-list button:hover, .menu-list button:focus-visible { background: var(--hover); outline: none; }
.menu-list hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; }
.danger { color: var(--danger); }

/* ── page ────────────────────────────────────────────────── */
.stage { position: relative; min-height: 0; }
body.pip { display: block; }   /* the picture-in-picture window holds only the canvas */
#ink { display: block; width: 100%; height: 100%; color: #1c1b19; --paper: #ffffff; cursor: crosshair; touch-action: none; }
.banner {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%);
  margin: 0; max-width: min(520px, calc(100% - 32px));
  background: var(--text); color: var(--bg);
  padding: 9px 14px; border-radius: 10px; font-size: 13px; text-wrap: pretty;
}

/* ── settings sheet ──────────────────────────────────────── */
.sheet {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 8;
  width: min(340px, 100vw);
  background: var(--surface); border-left: 1px solid var(--line);
  box-shadow: -12px 0 32px rgba(0, 0, 0, 0.08);
  overflow-y: auto; overscroll-behavior: contain;
  padding: 0 18px 28px;
  padding-bottom: max(28px, env(safe-area-inset-bottom));
  transition: transform 180ms ease, opacity 180ms ease;
}
.sheet[hidden] { display: block; transform: translateX(16px); opacity: 0; pointer-events: none; visibility: hidden; }
@media (prefers-reduced-motion: reduce) { .sheet { transition: none; } }
.sheet-head {
  position: sticky; top: 0; z-index: 1;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 0 8px; background: var(--surface);
}
h2 { font-size: 15px; font-weight: 600; margin: 0; }
h3 { font-size: 12px; font-weight: 600; letter-spacing: 0.02em; color: var(--muted); margin: 0 0 10px; }
h4 { font-size: 12px; font-weight: 600; margin: 18px 0 6px; display: flex; gap: 6px; align-items: baseline; }
.sheet section { padding: 16px 0; border-top: 1px solid var(--line); }

.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field > span { display: flex; justify-content: space-between; font-size: 13px; }
output, .count { color: var(--muted); font-variant-numeric: tabular-nums; }
.check { display: inline-flex; gap: 8px; align-items: center; font-size: 13px; cursor: pointer; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 8px 0; }
.grow { flex: 1; min-width: 0; }
.hint { color: var(--muted); font-size: 12px; margin: 6px 0 0; text-wrap: pretty; }
code { font-family: var(--mono); font-size: 0.92em; }

select, input:not([type]), input[type="text"], textarea {
  width: 100%; padding: 7px 9px;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--radius);
}
input[type="range"] { width: 100%; accent-color: var(--text); }
input[type="checkbox"] { accent-color: var(--text); width: 15px; height: 15px; margin: 0; }

.btn {
  height: 32px; padding: 0 12px;
  border: 1px solid transparent; border-radius: var(--radius);
  background: var(--text); color: var(--bg);
}
.btn:hover { opacity: 0.88; }
.btn.ghost { background: transparent; color: var(--text); border-color: var(--line); }
.btn.ghost:hover { background: var(--hover); opacity: 1; }
.btn.small { height: 26px; padding: 0 8px; font-size: 12px; }
.btn.wide { width: 100%; }

.advanced { border-top: 1px solid var(--line); padding-top: 14px; }
.advanced summary { font-size: 12px; font-weight: 600; color: var(--muted); cursor: pointer; }
.log, .packets {
  font: 11px/1.55 var(--mono);
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 8px; margin: 0; overflow: auto; overflow-wrap: anywhere;
}
.log { max-height: 140px; white-space: pre-wrap; }
.log:empty::before { content: "Nothing yet."; color: var(--muted); }
.packets { height: 200px; }
.packets .p { white-space: nowrap; }
.packets .ch, .packets .n { color: var(--muted); margin-right: 6px; }
.packets b { font-weight: 400; background: rgba(255, 200, 0, 0.35); border-radius: 2px; }
textarea#decoder { font: 12px/1.5 var(--mono); height: 260px; resize: vertical; tab-size: 2; }
#decoder-status.err { color: var(--danger); }
#decoder-status.ok { color: var(--ok); }

/* ── toast ───────────────────────────────────────────────── */
.toast {
  position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 9;
  display: flex; gap: 14px; align-items: center;
  max-width: calc(100vw - 32px);
  background: var(--text); color: var(--bg);
  padding: 9px 10px 9px 14px; border-radius: 10px; font-size: 13px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
}
.toast button { border: 0; background: none; color: inherit; font-weight: 600; padding: 2px 6px; border-radius: 6px; }
.toast button:hover { background: rgba(255, 255, 255, 0.14); }

/* Elements styled with display:… must still respect the hidden attribute. */
[hidden]:not(.sheet) { display: none !important; }
