/* The installer page only: ../style.css supplies the theme, cards, inputs and buttons. */

/* ---- palette: the colours of the real device's UI ------------------------------------------------------------------------------
   accent #00FFFF on ground #000, surfaces #0D0D0F with a #26262B border, text #ECECEE; ok #4CD38A, warn #F5C451, error #FF6B6B.
   style.css already has those surfaces and states; the accent is the Launcher's cyan here (a deeper teal on a light page, where cyan
   would not be readable), and buttons carry dark text on it. */
:root {
  --accent: #00ffff; --on-accent: #000; --head: #f7f7ff; --err-text: #ff8a8a;
  /* Fonts. Headings and the device's own text use Montserrat, like the Launcher. The Worker's CSP has no font-src (default-src 'none'), so a
     web font cannot be loaded, from Google Fonts or from anywhere else, and none is: Montserrat is used where it is installed on the
     computer, and the system's UI font where it is not. To self-host it later: put the .woff2 files next to this one, declare them here with
     @font-face, AND add font-src 'self' to the CSP in site/src/worker.js. Nothing else needs to change. */
  --font-head: Montserrat, "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
}
@media (prefers-color-scheme: light) {
  :root { --accent: #00727c; --on-accent: #fff; --head: #16161a; --err-text: #b3261e; }
}
h1, h2, h3, .brand, .num { font-family: var(--font-head); }
h1, h2 { font-weight: 600; color: var(--head); }
.brand { font-weight: 600; letter-spacing: .22em; }
button { color: var(--on-accent); }

/* ---- layout: the steps on the left (about 560 px), the live device on the right; on a narrow screen the device goes above the steps, smaller ---- */
main.shell { display: grid; max-width: 66.25rem; grid-template-columns: minmax(0, 1fr); grid-template-areas: "head" "device" "body"; column-gap: 3.5rem; }
.shell-head { grid-area: head; }
.shell-body { grid-area: body; min-width: 0; }
.dv { grid-area: device; margin: 0 auto 1.25rem; }
@media (min-width: 66.25rem) {
  /* the device spans both rows; when it is taller than the steps, the extra height goes to the steps' row, not into a gap under the header */
  main.shell { grid-template-columns: minmax(0, 35rem) 25.75rem; grid-template-rows: auto 1fr; grid-template-areas: "head device" "body device"; justify-content: center; }
  /* the device follows the page down while the steps are filled in (its size, --u, is set with the device below) */
  .dv { position: sticky; top: 1.5rem; align-self: start; margin: 0; }
}

.check { display: flex; align-items: flex-start; gap: .65rem; margin: 0 0 1rem; color: var(--text); font-size: 1rem; cursor: pointer; }
/* The "this is a Waveshare ..." tick box. The shared `input` rule is for text fields, so undo it for the checkbox. */
.check input { width: 1.25rem; height: 1.25rem; margin: .2rem 0 0; padding: 0; flex: none; accent-color: var(--accent); }

.actions { display: flex; flex-wrap: wrap; gap: .75rem; }
button.secondary { background: transparent; color: var(--text); border: 1px solid var(--border); }
button.danger { background: var(--err); color: #000; }
@media (prefers-color-scheme: light) { button.danger { color: #fff; } }
/* a button that is a quiet link: for the way out of a step ("Erase everything instead"), never the main action */
button.linklike { min-height: 2.75rem; padding: .25rem .1rem; background: none; border: 0; color: var(--err-text); font-weight: 500; font-size: .95rem;
  text-decoration: underline; text-underline-offset: .22em; text-decoration-thickness: 1px; }
button.linklike:hover { text-decoration-thickness: 2px; }
button.linklike.quiet { min-height: 2rem; color: var(--muted); font-size: .85rem; }
/* empty, it takes no room but stays in the page's structure: a live region that is not there yet when its text arrives is not announced */
#repair-msg { min-height: 0; margin: 0; }
#repair-msg:not(:empty) { margin: 0 0 .9rem; }
.more { margin-top: .35rem; }
.more .hint { margin: 0; font-size: .85rem; }
.hint.small { margin: .5rem 0; font-size: .8rem; color: var(--muted); }

.notice { margin-top: 0; }
.notice.err { border-color: var(--err); color: var(--err); }
.notice.ok { border-color: var(--ok); color: var(--ok); }
#alert { white-space: pre-line; }

.checks { list-style: none; margin: 0; padding: 0; }
.checks li { display: grid; grid-template-columns: minmax(0, 1fr) auto 4.6rem; align-items: baseline; gap: 0 1rem; border-top: 1px solid var(--border); padding: .5rem 0; }
.checks .label { color: var(--muted); font-size: .9rem; }
.checks .value { text-align: right; word-break: break-all; font-variant-numeric: tabular-nums; }
.checks .state { text-align: right; font-size: .85rem; font-weight: 600; }
@media (max-width: 30rem) { /* on a phone the value gets a line of its own: a long board ID would squeeze its label into two lines */
  .checks li { grid-template-columns: minmax(0, 1fr) 4.6rem; }
  .checks .value { grid-column: 1 / -1; grid-row: 2; text-align: left; padding-bottom: .1rem; }
  .checks .state { grid-column: 2; grid-row: 1; }
}
.checks .ok .state { color: var(--ok); }
.checks .bad .state { color: var(--err); }
.checks .skip .state { color: var(--muted); }

progress { width: 100%; height: .9rem; margin: .25rem 0 .75rem; accent-color: var(--accent); }

.step.result.ok { border-color: var(--ok); }
.step.result.warn { border-color: var(--warn); }
.step.result.error { border-color: var(--err); }

/* what the board says about itself once it runs (the live mirror), under the result */
.live { margin: 1rem 0; padding: .8rem 1rem; border: 1px solid var(--border); border-radius: 12px; background: var(--bg); }
.live-title { margin: 0; font: 600 1rem var(--font-head); color: var(--head); }
.live-text { margin: .2rem 0 0; color: var(--muted); font-size: .95rem; }
.live.ok { border-color: var(--ok); } .live.ok .live-title { color: var(--ok); }
.live.warn { border-color: var(--warn); } .live.warn .live-title { color: var(--warn); }
.live.err { border-color: var(--err); } .live.err .live-title { color: var(--err); }
.live.accent .live-title { color: var(--accent); }

/* help that appears only when it applies */
.help { margin: 1rem 0 0; padding: .9rem 1rem; border: 1px solid var(--border); border-radius: 12px; background: var(--bg); }
.help h3 { margin: 0 0 .35rem; font-size: 1rem; font-weight: 600; color: var(--head); }
.help p { margin: 0; color: var(--muted); font-size: .95rem; }
.help.warn { border-color: var(--warn); }
.help.warn h3 { color: var(--warn); }
.help-code { display: block; margin-top: .65rem; padding: .7rem .85rem; border-radius: 10px; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); font: .85rem ui-monospace, Menlo, Consolas, "Liberation Mono", monospace; overflow-x: auto; user-select: all; }
.help.warn + .actions, #live + .help { margin-top: 1rem; }
#step-done .help { margin-bottom: 1rem; }

.manual { margin-top: 1rem; }
.manual summary { cursor: pointer; color: var(--accent); }
.manual ol { margin: .75rem 0; padding-left: 1.25rem; }
.manual li { margin: .35rem 0; }
/* the board's edge with BOOT lit: a sketch in CSS, not a photograph (where the buttons really are still has to be checked on the board) */
.keys { margin: .9rem 0 .2rem; }
.key { display: inline-block; padding: .05rem .5rem; border-radius: 6px; border: 1px solid #3a3a42; border-bottom-width: 3px; background: #16161a; color: #ececee; font: 700 .78rem var(--font-head); letter-spacing: .06em; line-height: 1.5; vertical-align: .05em; }
.key.key-boot { border-color: #00ffff; color: #00ffff; box-shadow: 0 0 12px rgba(0, 255, 255, .35); }

.log-details { margin: 1.25rem 0 0; color: var(--muted); font-size: .9rem; }
.log-details summary { cursor: pointer; }
.log-details pre { max-height: 15rem; overflow: auto; margin: .75rem 0; padding: .75rem; font-size: .75rem; line-height: 1.4;
  white-space: pre-wrap; word-break: break-word; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; color: var(--text); }

/* ---- the live device ----------------------------------------------------------------------------------------------------------
   Everything is sized from --u, one CSS pixel at full size (a 412 px bezel around a 360 px screen), so the same drawing scales down on
   a phone. The state comes from data-* attributes that install-device.js sets; there is no inline style anywhere (the CSP forbids it),
   only custom properties set through the CSSOM. The screen's own colours are the device's, whatever the page's theme. */
@property --p { syntax: "<number>"; inherits: false; initial-value: 0; }
@property --a { syntax: "<angle>"; inherits: false; initial-value: 0deg; }

.dv { --u: .68px; --tone: #9a9aa3; --tone-text: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: 1.35rem; min-width: 0; }
@media (min-width: 40rem) { .dv { --u: .8px; } }
/* wide: full size, shrinking on a short window so that the whole column (the device, its caption and the strip) stays in view */
@media (min-width: 66.25rem) { .dv { --u: clamp(.6px, calc((100vh - 17.5rem) / 511), 1px); } }
.dv[data-tone="accent"] { --tone: #00ffff; --tone-text: var(--accent); }
.dv[data-tone="ok"] { --tone: #4cd38a; --tone-text: var(--ok); }
.dv[data-tone="warn"] { --tone: #f5c451; --tone-text: var(--warn); }
.dv[data-tone="err"] { --tone: #ff6b6b; --tone-text: var(--err); }

.dv-visual { display: flex; flex-direction: column; align-items: center; }
.dv-bezel { position: relative; display: flex; align-items: center; justify-content: center;
  width: calc(412 * var(--u)); height: calc(412 * var(--u)); border-radius: calc(44 * var(--u));
  background: linear-gradient(150deg, #1d1d22, #060607 60%); border: 1px solid #2e2e35;
  box-shadow: 0 calc(40 * var(--u)) calc(80 * var(--u)) rgba(0, 0, 0, .65); transition: box-shadow .5s ease; }
@media (prefers-color-scheme: light) { .dv-bezel { box-shadow: 0 calc(30 * var(--u)) calc(60 * var(--u)) rgba(0, 0, 0, .32); } }
.dv-screen { position: relative; overflow: hidden; width: calc(360 * var(--u)); height: calc(360 * var(--u)); border-radius: calc(24 * var(--u));
  background: #000; box-shadow: 0 0 0 1px #141416; font-family: var(--font-head); color: #c6c7c6; }
/* the USB-C port on the bottom edge, and the cable under it; the light runs up the cable while data really moves */
.dv-port { position: absolute; left: 50%; bottom: calc(-5 * var(--u)); width: calc(44 * var(--u)); height: calc(10 * var(--u)); margin-left: calc(-22 * var(--u));
  border-radius: calc(5 * var(--u)); background: #26262b; border: 1px solid #3a3a42; }
.dv-cable { position: relative; overflow: hidden; width: calc(20 * var(--u)); height: calc(96 * var(--u)); margin-top: 3px;
  background: #141417; border-left: 1px solid #23232a; border-right: 1px solid #23232a; }
.dv-flow { position: absolute; left: calc(6 * var(--u)); top: 0; display: none; width: calc(8 * var(--u)); height: calc(22 * var(--u)); border-radius: 4px;
  background: #00ffff; box-shadow: 0 0 12px #00ffff; }
.dv[data-flow="on"] .dv-flow { display: block; animation: dvFlow 1.1s linear infinite; }

/* the layers of the screen: one is up at a time (data-layer), the others are clear. The old one goes quickly and the new one fades in after it,
   so two layers are never half-visible on top of each other. */
.dv-layer { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  opacity: 0; visibility: hidden; transition: opacity .1s ease, visibility 0s linear .1s; }
.dv[data-layer="wait"] .dv-l-wait, .dv[data-layer="scan"] .dv-l-scan, .dv[data-layer="badge"] .dv-l-badge,
.dv[data-layer="ring"] .dv-l-ring, .dv[data-layer="frames"] .dv-l-frames { opacity: 1; visibility: visible; transition: opacity .3s ease .1s, visibility 0s linear .1s; }
.dv-label { margin: 0; font-weight: 600; letter-spacing: .16em; font-size: max(10px, calc(13 * var(--u))); text-align: center; }

/* waiting for USB: dim text, breathing, and a pulse ring around the bezel */
.dv-l-wait .dv-label { position: absolute; left: 0; right: 0; top: calc(160 * var(--u)); color: #5a5a63; }
.dv[data-phase="waiting"] .dv-l-wait .dv-label { animation: dvBlink 1.3s ease-in-out infinite; }
.dv[data-phase="waiting"] .dv-bezel { animation: dvPulse 1.8s ease-out infinite; }

/* reading the chip: a cyan line sweeping down the screen */
.dv-l-scan .dv-label { position: absolute; left: 0; right: 0; top: calc(168 * var(--u)); color: #00ffff; }
.dv-scanline { position: absolute; left: 0; right: 0; top: 0; height: calc(70 * var(--u));
  background: linear-gradient(to bottom, rgba(0, 255, 255, 0), rgba(0, 255, 255, .16) 75%, rgba(0, 255, 255, .85) 97%, rgba(0, 255, 255, 0)); }
.dv[data-layer="scan"] .dv-scanline { animation: dvScan 1.7s linear infinite; }

/* an icon, the board's real ID in a pill, a line of text: board checked, license linked, started, and what is wrong */
.dv-l-badge { gap: calc(14 * var(--u)); }
.dv-icon { display: none; width: calc(40 * var(--u)); height: calc(40 * var(--u)); color: var(--tone); }
.dv[data-icon="chip"] .dv-i-chip, .dv[data-icon="link"] .dv-i-link, .dv[data-icon="check"] .dv-i-check, .dv[data-icon="warn"] .dv-i-warn { display: block; }
.dv-pill { padding: calc(8 * var(--u)) calc(16 * var(--u)); border: 1px solid var(--tone); border-radius: 999px; color: var(--tone);
  font-weight: 600; font-size: max(10px, calc(14 * var(--u))); letter-spacing: .04em; user-select: all; }
.dv-l-badge .dv-label { letter-spacing: .12em; font-weight: 500; font-size: max(9px, calc(12 * var(--u))); color: #9a9aa3; }
.dv:not([data-tone="accent"]) .dv-l-badge .dv-label { color: var(--tone); }

/* download, erase, write, restart: a ring that fills with the real progress (--p, 0..100); a turning arc where there is nothing to count */
.dv-ring { display: flex; align-items: center; justify-content: center; width: calc(212 * var(--u)); height: calc(212 * var(--u)); border-radius: 50%;
  background: conic-gradient(#00ffff calc(var(--p) * 3.6deg), #1a1a1f 0deg); transition: --p .12s linear; } /* well under the gap between two reports, or the ring trails the number (it lags by about the speed of the write times this) */
.dv-ring[data-mode="spin"] { background: conic-gradient(from var(--a), #1a1a1f 0deg 230deg, rgba(0, 255, 255, .2) 230deg, #00ffff 340deg, #1a1a1f 340.6deg);
  animation: dvSpin 1.2s linear infinite; }
.dv-ring-in { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: calc(6 * var(--u));
  width: calc(188 * var(--u)); height: calc(188 * var(--u)); border-radius: 50%; background: #000; }
.dv-pct { font-weight: 600; font-size: calc(46 * var(--u)); line-height: 1.1; color: #f7f7ff; font-variant-numeric: tabular-nums; }
.dv-pct:empty { display: none; }
.dv-l-ring .dv-label { font-size: max(9px, calc(12 * var(--u))); letter-spacing: .18em; color: #00ffff; }
.dv-ring[data-mode="spin"] .dv-label { font-size: max(10px, calc(14 * var(--u))); }
.dv[data-busy="on"] .dv-l-ring .dv-label { animation: dvBlink 1.3s ease-in-out infinite; }

/* the board's own screens, as the release's builder drew them from the firmware; the real ID goes over each frame's blank "Board ID" line */
.dv-l-frames { display: block; }
.dv-frame { position: absolute; inset: 0; display: none; width: 100%; height: 100%; }
.dv-frame.is-on { display: block; animation: dvFade .5s ease-out both; }
.dv-idtext { position: absolute; display: none; align-items: center; justify-content: center; white-space: nowrap; pointer-events: none; line-height: 1;
  left: calc(var(--bx) * 1%); top: calc(var(--by) * 1%); width: calc(var(--bw) * 1%); height: calc(var(--bh) * 1%);
  color: var(--bc); font-family: var(--font-head); font-weight: 400; font-size: calc(var(--bf) * 360 * var(--u)); }
.dv-idtext.is-on { display: flex; }
.dv-badge { position: absolute; left: calc(10 * var(--u)); top: calc(10 * var(--u)); padding: calc(3 * var(--u)) calc(9 * var(--u)); border-radius: 999px;
  background: rgba(0, 0, 0, .75); border: 1px solid #00ffff; color: #00ffff; font-weight: 700; font-size: max(8px, calc(10 * var(--u))); letter-spacing: .16em; }

/* installed and activated: a green glow around the device */
.dv[data-glow="ok"] .dv-bezel { box-shadow: 0 0 0 calc(10 * var(--u)) rgba(76, 211, 138, .14), 0 calc(40 * var(--u)) calc(80 * var(--u)) rgba(0, 0, 0, .65); border-color: rgba(76, 211, 138, .5); }

/* the caption: the board's ID, and one line saying where things stand */
.dv-cap { display: flex; flex-direction: column; align-items: center; gap: .25rem; margin: 0; text-align: center; }
.dv-board { font: 600 .95rem var(--font-head); letter-spacing: .06em; color: var(--head); user-select: all; }
.dv-board:not(.is-known) { color: var(--muted); font-weight: 500; user-select: none; }
.dv-status { font-size: .875rem; color: var(--tone-text); }

/* "Board screen dark?": there for the customer who needs it, quiet for everybody else */
.dv-dark { display: flex; flex-direction: column; align-items: center; width: min(100%, 24rem); margin-top: -.8rem; }
.dv-dark-text { margin: .35rem 0 0; padding: .7rem .9rem; border: 1px solid var(--warn); border-radius: 12px; color: var(--muted); font-size: .85rem; line-height: 1.5; text-align: left; }

/* what the board will show next: Wi-Fi, connected, apps. Hover or tap a step to see that screen on the device. */
.dv-next { display: flex; flex-direction: column; align-items: center; gap: .6rem; width: min(100%, 26rem); }
.dv-next-title { margin: 0; font: 600 .7rem var(--font-head); letter-spacing: .16em; text-transform: uppercase; color: var(--muted); }
.dv-steps { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: .35rem 0; margin: 0; padding: 0; list-style: none; }
.dv-steps li { display: flex; align-items: center; }
.dv-steps li + li::before { content: "›"; padding: 0 .45rem; color: var(--muted); }
.dv-chip { min-height: 2.25rem; padding: .3rem .85rem; border-radius: 999px; border: 1px solid var(--border); background: transparent; color: var(--text);
  font-size: .8125rem; font-weight: 500; }
.dv-chip:hover, .dv-chip[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }
.dv-chip[aria-pressed="true"] { background: rgba(0, 255, 255, .08); }
.dv-note { min-height: 3.1em; margin: 0; max-width: 100%; text-align: center; font-size: .85rem; line-height: 1.5; color: var(--muted); }

/* ---- motion ---------------------------------------------------------------------------------------------------------------------
   Pulse, scan, fade, flow and blink, plus the turning arc. Each one runs only while its state is up (see the rules above). */
@keyframes dvPulse {
  0% { box-shadow: 0 0 0 0 rgba(0, 255, 255, .4), 0 calc(40 * var(--u)) calc(80 * var(--u)) rgba(0, 0, 0, .65); }
  70% { box-shadow: 0 0 0 calc(28 * var(--u)) rgba(0, 255, 255, 0), 0 calc(40 * var(--u)) calc(80 * var(--u)) rgba(0, 0, 0, .65); }
  100% { box-shadow: 0 0 0 0 rgba(0, 255, 255, 0), 0 calc(40 * var(--u)) calc(80 * var(--u)) rgba(0, 0, 0, .65); }
}
@keyframes dvScan { from { transform: translateY(calc(-80 * var(--u))); } to { transform: translateY(calc(380 * var(--u))); } }
@keyframes dvFade { from { opacity: 0; transform: scale(.985); } to { opacity: 1; transform: none; } }
@keyframes dvFlow {
  0% { transform: translateY(calc(96 * var(--u))); opacity: 0; }
  15% { opacity: 1; }
  100% { transform: translateY(calc(-8 * var(--u))); opacity: 0; }
}
@keyframes dvBlink { 50% { opacity: .35; } }
@keyframes dvSpin { to { --a: 360deg; } }

/* For people who ask for less motion nothing moves: each state keeps a still picture that says the same thing. */
@media (prefers-reduced-motion: reduce) {
  .dv, .dv *, .dv *::before, .dv *::after { animation: none !important; transition: none !important; }
  .dv[data-phase="waiting"] .dv-bezel { box-shadow: 0 0 0 calc(7 * var(--u)) rgba(0, 255, 255, .22), 0 calc(40 * var(--u)) calc(80 * var(--u)) rgba(0, 0, 0, .65); }
  .dv[data-layer="scan"] .dv-scanline { transform: translateY(calc(130 * var(--u))); }
  .dv[data-flow="on"] .dv-flow { top: calc(37 * var(--u)); }
}
