:root {
  --bg: #f4f3ef;
  --card: #ffffff;
  --ink: #1d1d1b;
  --muted: #6b6a66;
  --line: #dddbd4;
  --accent: #1f5f8b;
  --accent-ink: #ffffff;
  --ok: #2e7d4f;
  --warn: #a35a00;
  --bad: #b3261e;
  --rec: #d93025;
  --radius: 14px;
  color-scheme: light;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

header.top {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--ink);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 5;
}
header.top a { color: #fff; text-decoration: none; font-weight: 600; }
header.top h1 { font-size: 18px; margin: 0; flex: 1; }
header.top .token { font-size: 13px; color: #cfcfcf; background: none; border: 1px solid #555; border-radius: 999px; padding: 6px 12px; min-height: 36px; }

main { max-width: 760px; margin: 0 auto; padding: 16px; }

h2 { font-size: 20px; margin: 24px 0 8px; }
h3 { font-size: 16px; margin: 16px 0 6px; }
p { margin: 8px 0; }
.muted { color: var(--muted); font-size: 14px; }
.small { font-size: 13px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin: 12px 0;
}

.tiles { display: grid; gap: 12px; }
.tile {
  display: block;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  color: inherit;
  text-decoration: none;
}
.tile strong { display: block; font-size: 20px; margin-bottom: 4px; }

button, .button {
  appearance: none;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: var(--accent-ink);
  font: inherit;
  font-weight: 600;
  min-height: 52px;
  padding: 12px 18px;
  touch-action: manipulation;
  cursor: pointer;
}
button.secondary { background: #e6e4dd; color: var(--ink); }
button.danger { background: #f3dcda; color: var(--bad); }
button.small { min-height: 40px; padding: 8px 12px; font-size: 14px; }
button:disabled { opacity: 0.45; cursor: default; }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.row > button { flex: 1 1 auto; }
.stack { display: grid; gap: 10px; }

label.field { display: grid; gap: 4px; font-size: 14px; color: var(--muted); }
select, input[type="text"], input[type="password"], textarea {
  font: inherit;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  background: #fff;
  color: var(--ink);
  width: 100%;
}
textarea { min-height: 72px; }
label.check { display: flex; gap: 10px; align-items: center; min-height: 44px; }
label.check input { width: 22px; height: 22px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  min-height: 44px;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  font-weight: 500;
}
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }

.viewer {
  position: relative;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  aspect-ratio: 3 / 4;
  max-height: 62vh;
  margin: 0 auto;
}
.viewer video { width: 100%; height: 100%; object-fit: contain; display: block; }
.viewer .hud {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 8px 12px; color: #fff; font-size: 13px;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.7));
}
.viewer .banner {
  position: absolute; left: 50%; top: 14px; transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.65); color: #fff; padding: 6px 14px; border-radius: 999px; font-weight: 600;
}
.viewer.small { max-height: 30vh; aspect-ratio: 4 / 3; }

.record-bar { display: flex; justify-content: center; align-items: center; gap: 18px; margin: 14px 0; }
.record-button {
  width: 84px; height: 84px; border-radius: 50%;
  background: #fff; border: 6px solid var(--rec); padding: 0; min-height: 0;
  position: relative;
}
.record-button::after {
  content: ""; position: absolute; inset: 10px; border-radius: 50%; background: var(--rec); transition: inset 0.15s, border-radius 0.15s;
}
.record-button.active::after { inset: 20px; border-radius: 8px; }

progress { width: 100%; height: 12px; accent-color: var(--accent); }

table.kv { width: 100%; border-collapse: collapse; font-size: 14px; }
table.kv td, table.kv th { padding: 6px 4px; border-bottom: 1px solid var(--line); vertical-align: top; text-align: left; }
table.kv td:first-child { color: var(--muted); width: 42%; }
table.kv th { font-size: 13px; color: var(--muted); font-weight: 600; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

.status { font-weight: 600; }
.status.ok { color: var(--ok); }
.status.warn { color: var(--warn); }
.status.bad { color: var(--bad); }

.uploads { display: grid; gap: 8px; }
.upload-item { display: grid; gap: 6px; padding: 10px 12px; background: #fff; border: 1px solid var(--line); border-radius: 12px; }
.upload-item .row { justify-content: space-between; }

pre.json {
  max-height: 50vh; overflow: auto; font-size: 12px; background: #1e1e1e; color: #e8e8e8;
  padding: 12px; border-radius: 10px; white-space: pre-wrap; word-break: break-all;
}
details summary { cursor: pointer; min-height: 40px; display: flex; align-items: center; font-weight: 600; }
.log { font-size: 13px; color: var(--muted); max-height: 160px; overflow: auto; white-space: pre-wrap; }

.thumbs { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
.thumbs figure { margin: 0; }
.thumbs img { width: 100%; border-radius: 10px; display: block; background: #ddd; }
.thumbs figcaption { font-size: 12px; color: var(--muted); }
img.sheet { width: 100%; border-radius: 10px; border: 1px solid var(--line); }

.overlay {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.55); display: grid; place-items: center; z-index: 50; padding: 16px;
}
.overlay .dialog { background: #fff; border-radius: var(--radius); padding: 18px; width: min(420px, 100%); display: grid; gap: 12px; }
.overlay .error { color: var(--bad); font-size: 14px; min-height: 1em; }

@media (min-width: 640px) {
  .tiles { grid-template-columns: repeat(3, 1fr); }
}

.mt { margin-top: 14px; }
