:root {
  color-scheme: light dark;
  --bg: #f6f7f9;
  --card: #ffffff;
  --text: #16181d;
  --muted: #5c6370;
  --border: #d5d9e0;
  --accent: #0b6bcb;
  --accent-text: #ffffff;
  --error: #b42318;
  --ok: #067647;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --card: #181b21;
    --text: #e8eaee;
    --muted: #9aa1ad;
    --border: #2b303a;
    --accent: #4b9bf0;
    --accent-text: #0b0d11;
    --error: #ff8a80;
    --ok: #6ddba0;
  }
}

* { box-sizing: border-box; }

/* Author `display` rules (e.g. on form) would otherwise beat the built-in [hidden] rule. */
[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex;
  justify-content: center;
  padding: 24px 16px;
}

main {
  width: 100%;
  max-width: 520px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px 20px;
  align-self: flex-start;
}

h1 { margin: 0 0 4px; font-size: 1.4rem; }
.sub { margin: 0 0 20px; color: var(--muted); font-size: 0.95rem; }

form { display: flex; flex-direction: column; gap: 6px; }
label { font-size: 0.9rem; font-weight: 600; margin-top: 8px; }

input {
  width: 100%;
  padding: 12px;
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
}
input:focus-visible, button:focus-visible, pre:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

button {
  margin-top: 14px;
  padding: 12px 16px;
  font: inherit;
  font-weight: 600;
  color: var(--accent-text);
  background: var(--accent);
  border: 0;
  border-radius: 8px;
  cursor: pointer;
}
button:disabled { opacity: 0.6; cursor: progress; }
button.secondary { color: var(--text); background: transparent; border: 1px solid var(--border); }
button.link {
  margin-top: 8px;
  padding: 8px;
  color: var(--muted);
  background: none;
  font-weight: 400;
  text-decoration: underline;
}

.row { display: flex; flex-direction: row; gap: 10px; }
.row button { flex: 1; }
.row input { flex: 2; min-width: 0; }
#live-type-form { margin-top: 14px; }
#live-type-form button { margin-top: 0; }
.row.zoom button.active { border-color: var(--accent); color: var(--accent); }

/* Live view: the picture scrolls inside the frame, so zooming keeps taps precise on a phone. */
#live-frame {
  max-height: 60vh;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
}
#live-image { display: block; cursor: pointer; touch-action: manipulation; }
.zoom-1 #live-image { width: 100%; }
.zoom-2 #live-image { width: 200%; }
.zoom-3 #live-image { width: 300%; }

#status { margin: 0 0 12px; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--border); font-size: 0.95rem; }
#status.error { color: var(--error); border-color: var(--error); }
#status.info { color: var(--muted); }

#diag { margin: 0 0 12px; font-size: 0.9rem; color: var(--muted); }
#diag summary { cursor: pointer; margin-bottom: 8px; }
#diag pre { max-height: 200px; }
#diag img { display: block; width: 100%; margin-top: 8px; border: 1px solid var(--border); border-radius: 8px; }

#result-summary { margin: 0 0 8px; color: var(--ok); font-weight: 600; }
pre {
  margin: 0;
  max-height: 320px;
  overflow: auto;
  padding: 12px;
  font: 0.8rem/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  white-space: pre-wrap;
  word-break: break-all;
}
