:root {
  --paper: #efeae0;
  --ink: #141414;
  --red: #d7262b;
  --yellow: #f2c200;
  --blue: #1f4fd1;
  --night: #0b0b0d;
  --fog: rgba(244, 241, 234, 0.85);
  --readout: #ffd21f;
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--night);
  color: var(--fog);
  font-family: var(--mono);
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

#view {
  position: fixed;
  z-index: 1;
  inset: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  display: block;
  touch-action: none;
  cursor: grab;
}
body[data-mode="camera"] #view { cursor: default; }

/* The camera feed is drawn onto the canvas. The element stays full-size
   underneath it (not hidden or tiny) so iOS keeps decoding frames. */
#video {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 0;
  pointer-events: none;
}

#insets {
  position: fixed;
  visibility: hidden;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

/* ---- start plate ---------------------------------------------------- */

#start {
  position: fixed;
  inset: 0;
  z-index: 10;
  overflow-y: auto;
  background: var(--paper);
  color: var(--ink);
  display: flex;
  justify-content: center;
  padding: max(24px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
}
#start[hidden] { display: none; }

.plate {
  width: 100%;
  max-width: 440px;
  margin: auto 0;
  border: 1px solid var(--ink);
  padding: 22px 20px 18px;
  position: relative;
  background:
    repeating-linear-gradient(90deg, var(--ink) 0 1px, transparent 1px 24px) top left / 100% 6px no-repeat,
    repeating-linear-gradient(180deg, var(--ink) 0 1px, transparent 1px 24px) top left / 6px 100% no-repeat;
}

.fig {
  margin: 0 0 6px;
  font-size: 11px;
  letter-spacing: 0.04em;
}

h1 {
  margin: 0;
  font-size: clamp(28px, 9vw, 40px);
  font-weight: 700;
  letter-spacing: 0.02em;
}

.lead {
  margin: 8px 0 14px;
  font-size: 13px;
  line-height: 1.6;
}

.specimen {
  width: 100%;
  height: auto;
  display: block;
  margin: 4px 0 10px;
}

.how {
  margin: 0 0 16px;
  padding-left: 1.4em;
  font-size: 12px;
  line-height: 1.7;
}

button {
  font: inherit;
  cursor: pointer;
}

/* keyboard focus: a 2px line 2px off the control — ink on paper, the readout at night */
#start :focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
#btn-settings:focus-visible,
#panel :focus-visible { outline: 2px solid var(--readout); outline-offset: 2px; }

.primary,
.secondary {
  display: block;
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--ink);
  border-radius: 0;
  font-size: 15px;
  font-weight: 500;
  letter-spacing: 0.04em;
}
.primary {
  background: var(--ink);
  color: var(--paper);
}
.primary:active { background: var(--red); border-color: var(--red); }
.secondary {
  margin-top: 8px;
  background: transparent;
  color: var(--ink);
  font-size: 13px;
  min-height: 42px;
}
.secondary:active { background: var(--yellow); }

#start-error {
  min-height: 1em;
  margin: 10px 0 0;
  color: var(--red);
  font-size: 14px;
  font-weight: 500;
  line-height: 1.5;
}

.note {
  margin: 6px 0 0;
  font-size: 10.5px;
  line-height: 1.6;
  opacity: 0.75;
}
.version {
  margin: 10px 0 0;
  font-size: 10.5px;
  opacity: 0.6;
}
.link {
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font-size: inherit;
  text-decoration: underline;
}
.refresh-app.attention {
  color: var(--red);
  font-weight: 700;
}
.version:has(.attention) { opacity: 1; }

/* ---- settings ------------------------------------------------------- */

#btn-settings {
  position: fixed;
  z-index: 5;
  top: calc(env(safe-area-inset-top) + 6px);
  right: 8px;
  width: 40px;
  height: 40px;
  display: none;
  align-items: center;
  justify-content: center;
  color: var(--fog);
  background: rgba(8, 8, 10, 0.5);
  border: 1px solid rgba(244, 241, 234, 0.35);
  border-radius: 0;
}
body.running #btn-settings { display: flex; }

#panel {
  position: fixed;
  z-index: 6;
  top: calc(env(safe-area-inset-top) + 52px);
  right: 8px;
  left: auto;
  width: min(320px, calc(100vw - 16px));
  max-height: calc(100dvh - env(safe-area-inset-top) - 64px);
  overflow-y: auto;
  padding: 12px 14px 14px;
  background: rgba(10, 10, 12, 0.92);
  border: 1px solid rgba(244, 241, 234, 0.3);
  font-size: 12px;
}
#panel[hidden] { display: none; }
#panel header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}
#panel h2 {
  margin: 0;
  font-size: 12px;
  letter-spacing: 0.1em;
}
#panel-close {
  background: none;
  border: 0;
  color: var(--fog);
  font-size: 20px;
  width: 32px;
  height: 32px;
}
#panel label {
  display: block;
  margin: 10px 0 0;
}
#panel output {
  float: right;
  color: var(--readout);
}
#panel input[type="range"] {
  width: 100%;
  margin: 6px 0 0;
  accent-color: var(--readout);
}
#panel .check {
  display: flex;
  gap: 8px;
  align-items: center;
}
#panel .row { margin-top: 12px; }
#panel button:not(#panel-close),
#panel .file {
  display: block;
  width: 100%;
  margin-top: 8px;
  padding: 9px 10px;
  background: transparent;
  color: var(--fog);
  border: 1px solid rgba(244, 241, 234, 0.4);
  text-align: left;
  font-size: 12px;
}
#panel .file input { display: none; }
#panel .hint {
  margin: 12px 0 0;
  line-height: 1.6;
  opacity: 0.75;
}
.demo-only { display: none; }
body[data-mode="demo"] .demo-only { display: block; }
