/* Optical modem capture station — shared shell styling.
   Everything is inline/local: no CDN, no external fonts (the app must work on
   a phone over a patchy connection and inside a sandboxed preview). */

:root {
  --bg: #0b0d10;
  --panel: #14181d;
  --panel-2: #1b2027;
  --line: #2a323c;
  --fg: #e8edf3;
  --muted: #93a1b1;
  --accent: #35d0a5;
  --accent-2: #4f9dff;
  --warn: #ffb020;
  --bad: #ff5c5c;
  --radius: 14px;
  --safe: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.45 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
        "Helvetica Neue", Arial, sans-serif;
  overscroll-behavior: none;
}

a { color: var(--accent-2); }

h1, h2, h3 { margin: 0 0 .4em; line-height: 1.15; }
h1 { font-size: 1.6rem; letter-spacing: -.01em; }
h2 { font-size: 1.15rem; }
p { margin: 0 0 .8em; color: var(--muted); }
code, kbd, .mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* ---------- layout ---------- */
.wrap {
  max-width: 560px;
  margin: 0 auto;
  padding: 24px 18px calc(24px + var(--safe));
}
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 14px;
}
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.spread { justify-content: space-between; }
.grow { flex: 1 1 auto; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.center { text-align: center; }
.hidden { display: none !important; }

/* ---------- controls ---------- */
label.field { display: block; margin-bottom: 12px; }
label.field span { display: block; font-size: .8rem; color: var(--muted);
  margin-bottom: 6px; text-transform: uppercase; letter-spacing: .06em; }

input[type=text], input[type=password], input[type=number], select {
  width: 100%;
  padding: 13px 14px;
  font-size: 1rem;
  color: var(--fg);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  outline: none;
}
input:focus, select:focus { border-color: var(--accent-2); }

button, .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 13px 16px;
  font-size: 1rem;
  font-weight: 600;
  color: #04120d;
  background: var(--accent);
  border: 0;
  border-radius: 10px;
  cursor: pointer;
  text-decoration: none;
  transition: transform .06s ease, filter .15s ease;
}
button:active { transform: scale(.985); }
button:disabled { opacity: .45; cursor: default; }
button.ghost {
  background: transparent;
  color: var(--fg);
  border: 1px solid var(--line);
}
button.danger { background: transparent; color: var(--bad);
  border: 1px solid rgba(255, 92, 92, .45); }
button.block { width: 100%; }

/* ---------- status bits ---------- */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 999px;
  font-size: .78rem;
  font-weight: 600;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--muted);
}
.pill.on { color: var(--accent); border-color: rgba(53, 208, 165, .5); }
.pill.warn { color: var(--warn); border-color: rgba(255, 176, 32, .5); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

.progress {
  height: 8px;
  border-radius: 999px;
  background: var(--panel-2);
  overflow: hidden;
  border: 1px solid var(--line);
}
.progress > i {
  display: block;
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width .25s ease;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(22px + var(--safe));
  transform: translateX(-50%);
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--fg);
  padding: 11px 16px;
  border-radius: 999px;
  font-size: .9rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s ease;
  z-index: 50;
  max-width: 90vw;
}
.toast.show { opacity: 1; }
.toast.bad { border-color: rgba(255, 92, 92, .6); color: #ffd7d7; }

/* ---------- display page ---------- */
body.display {
  background: #000;
  overflow: hidden;
}
#stage {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: #000;
}
#frame {
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  max-width: 100vw;
  max-height: 100vh;
  width: auto;
  height: auto;
}
body.display.actual #frame { max-width: none; max-height: none; }

#hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 1;
  transition: opacity .3s ease;
}
#hud.dim { opacity: 0; }
#hud > * { pointer-events: auto; }

#hud-top {
  position: absolute;
  top: 0; left: 0; right: 0;
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 14px 16px;
  background: linear-gradient(180deg, rgba(0,0,0,.82), rgba(0,0,0,0));
}
#hud-bottom {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  display: flex;
  gap: 12px;
  align-items: flex-end;
  justify-content: space-between;
  padding: 16px;
  background: linear-gradient(0deg, rgba(0,0,0,.85), rgba(0,0,0,0));
}
#counter { font-size: 1.05rem; font-weight: 700; letter-spacing: .02em; }
#hud .pill, #hud button { background: rgba(20, 24, 29, .92); }
#hud button.ghost { color: #e8edf3; }

.pairbox {
  display: flex;
  gap: 14px;
  align-items: center;
  background: rgba(20, 24, 29, .94);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
}
.pairbox img { width: 116px; height: 116px; background: #fff; border-radius: 8px; }
.paircode {
  font-family: ui-monospace, monospace;
  font-size: 1.9rem;
  font-weight: 700;
  letter-spacing: .22em;
  color: var(--accent);
}

/* ---------- camera page ---------- */
body.camera { overflow: hidden; height: 100%; }
#view {
  position: fixed;
  inset: 0;
  background: #000;
}
#video {
  width: 100%;
  height: 100%;
  /* contain, not cover: the snapshot uploads the whole sensor frame, so the
     preview must show the whole sensor frame too — with cover the sides of a
     landscape stream are hidden in portrait and the user cannot see that the
     code is about to be cut off */
  object-fit: contain;
  display: block;
  background: #000;
}
#guide {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
}
#guide .box {
  width: min(84vw, 84vh);
  height: min(84vw, 84vh);
  border: 2px dashed rgba(255, 255, 255, .55);
  border-radius: 18px;
  box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .35);
}
#cam-top {
  position: fixed;
  top: 0; left: 0; right: 0;
  display: flex;
  gap: 8px;
  align-items: flex-start;
  justify-content: space-between;
  padding: 12px 14px;
  background: linear-gradient(180deg, rgba(0,0,0,.75), rgba(0,0,0,0));
  z-index: 5;
}
#target {
  width: 92px;
  height: 92px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #000 no-repeat center/contain;
  image-rendering: pixelated;
  flex: 0 0 auto;
}
#cam-bottom {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  padding: 14px 14px calc(18px + var(--safe));
  background: linear-gradient(0deg, rgba(0,0,0,.85), rgba(0,0,0,0));
  z-index: 5;
}
#shutter-row { display: flex; align-items: center; justify-content: center;
  gap: 26px; margin-top: 10px; }
#shutter {
  width: 84px;
  height: 84px;
  border-radius: 50%;
  background: #fff;
  border: 6px solid rgba(255,255,255,.28);
  background-clip: content-box;
  padding: 6px;
  transition: transform .08s ease;
}
#shutter:active { transform: scale(.94); }
#shutter.busy { background: var(--warn); }
#shutter.done { background: var(--accent); }
.shutter-side {
  width: 54px; height: 54px; border-radius: 50%;
  background: rgba(20,24,29,.85); color: var(--fg);
  border: 1px solid var(--line);
  font-size: .68rem; line-height: 1.1; text-align: center;
}
#status-line { text-align: center; color: #dfe7ef; font-size: .92rem;
  text-shadow: 0 1px 2px rgba(0,0,0,.8); min-height: 1.4em; }
#file-input { display: none; }

/* install hint */
.install {
  display: flex; gap: 10px; align-items: center;
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 12px; font-size: .85rem;
  color: var(--muted);
}
.install button { padding: 8px 12px; font-size: .85rem; }

#nocam {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 32px 26px 160px;
  color: #cbd5e1;
}
#nocam .nocam-icon { font-size: 3rem; line-height: 1; margin-bottom: 10px; }
#nocam p { margin: 6px 0; }
body.camera.filemode #status-line { color: var(--accent); font-weight: 600; }

/* paired + shooting: the pair panel collapses so it stops covering the code */
.pairbox.mini { padding: 6px 10px; opacity: .45; transition: opacity .2s ease; }
.pairbox.mini img { width: 0; height: 0; margin: 0; padding: 0; border: 0; }
.pairbox.mini .paircode { font-size: 1rem; letter-spacing: .14em; }
.pairbox.mini #pairurl { display: none; }
.pairbox.mini:hover { opacity: 1; }
.pairbox.mini:hover img { width: 116px; height: 116px; }
.pairbox.mini:hover #pairurl { display: block; }
