:root {
  --ink: #15202b;
  --panel: #e8eef2;
  --line: #9aadb8;
  --accent: #e6a23c;
  --ok: #1f7a4c;
  --warn: #b86b00;
  --hot: #b42318;
  --cool: #1d4f91;
  --shadow: 0 18px 40px rgba(21, 32, 43, 0.18);
  --font-display: "Bebas Neue", "Arial Narrow", Impact, sans-serif;
  --font-body: "IBM Plex Sans", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(1200px 600px at 10% -10%, #fff7e6 0%, transparent 55%),
    radial-gradient(900px 500px at 100% 0%, #d9e8f5 0%, transparent 50%),
    linear-gradient(180deg, #f4f7fa 0%, #dce5ec 100%);
  color: var(--ink);
  font-family: var(--font-body);
}

body { min-height: 100dvh; }

.app {
  width: min(720px, 100%);
  margin: 0 auto;
  padding: 1rem 1rem calc(1.25rem + env(safe-area-inset-bottom));
  display: grid;
  gap: 1rem;
}

.brand h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(3rem, 12vw, 4.5rem);
  letter-spacing: 0.04em;
  line-height: 0.9;
}

.tagline {
  margin: 0.15rem 0 0;
  color: #4a5d6b;
  font-weight: 600;
}

.stage { display: grid; gap: 0.85rem; }

.viewport {
  position: relative;
  aspect-ratio: 3 / 4;
  max-height: 48dvh;
  overflow: hidden;
  border-radius: 1.1rem;
  background: #0d141a;
  box-shadow: var(--shadow);
}

video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
  background: #0d141a;
}

#sample { display: none; }

.reticle {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
}

.ring {
  width: min(28vw, 140px);
  height: min(28vw, 140px);
  border: 3px solid rgba(255, 255, 255, 0.92);
  border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.35);
}

.cross::before,
.cross::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  background: rgba(255, 255, 255, 0.9);
  transform: translate(-50%, -50%);
}

.cross::before { width: 18px; height: 2px; }
.cross::after { width: 2px; height: 18px; }

.gate {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 0.75rem;
  padding: 1.5rem;
  text-align: center;
  background: rgba(12, 18, 24, 0.72);
  color: #f5f8fb;
  backdrop-filter: blur(4px);
}

.gate[hidden] { display: none; }
.gate p { margin: 0; font-size: 1.05rem; line-height: 1.4; }
.hint { color: #ffb4a8; font-weight: 600; }

.readout {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 1.1rem;
  padding: 0.9rem 1.1rem 1.15rem;
  box-shadow: var(--shadow);
  text-align: center;
}

.calib-banner {
  margin: 0 0 0.55rem;
  padding: 0.45rem 0.65rem;
  border-radius: 0.65rem;
  background: #dfe8ef;
  color: #334654;
  font-size: 0.86rem;
  font-weight: 700;
}

.calib-banner.ready {
  background: #d8eee1;
  color: #1a5a38;
}

.grade {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(2.6rem, 12vw, 4.2rem);
  letter-spacing: 0.06em;
  line-height: 0.95;
  color: var(--cool);
  transition: color 160ms ease, transform 160ms ease;
}

.grade.pulse { transform: scale(1.03); }

.score {
  margin: 0.1rem 0 0;
  font-family: var(--font-display);
  font-size: clamp(2.4rem, 11vw, 3.6rem);
  letter-spacing: 0.04em;
}

.unit {
  font-size: 0.42em;
  margin-left: 0.12em;
  opacity: 0.7;
  vertical-align: super;
}

.equiv {
  margin: 0.15rem 0 0.7rem;
  font-weight: 700;
  color: #3d5160;
}

.color-card {
  display: grid;
  grid-template-columns: 54px 1fr;
  gap: 0.75rem;
  align-items: center;
  text-align: left;
  background: #f7fafc;
  border: 1px solid var(--line);
  border-radius: 0.9rem;
  padding: 0.65rem 0.75rem;
  margin-bottom: 0.65rem;
}

.swatch {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  border: 2px solid rgba(21, 32, 43, 0.18);
  background: #ddd;
  box-shadow: inset 0 0 18px rgba(255, 255, 255, 0.45);
}

.color-label {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
}

.color-meta {
  margin: 0.15rem 0 0;
  color: #526675;
  font-size: 0.9rem;
  font-weight: 600;
}

.match {
  margin: 0 0 0.35rem;
  font-size: 1.05rem;
  font-weight: 700;
  color: #1c2a36;
}

.detail {
  margin: 0 0 0.85rem;
  color: #425563;
  font-weight: 600;
  min-height: 1.35em;
  font-size: 0.92rem;
}

.meter {
  position: relative;
  height: 14px;
  border-radius: 999px;
  background: linear-gradient(90deg, #1d4f91, #1f7a4c 36%, #e6a23c 68%, #b42318);
  overflow: hidden;
}

.meter-fill {
  position: absolute;
  top: -4px;
  bottom: -4px;
  width: 4px;
  margin-left: -2px;
  background: #fff;
  border-radius: 2px;
  box-shadow: 0 0 0 2px rgba(21, 32, 43, 0.55);
  left: 0%;
  transition: left 120ms linear;
}

.meter-marks {
  display: flex;
  justify-content: space-between;
  margin-top: 1.05rem;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #5a6d7a;
  font-weight: 700;
}

.controls {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.55rem;
}

.btn {
  appearance: none;
  border: 1px solid #7f93a1;
  background: #f7fafc;
  color: var(--ink);
  border-radius: 0.85rem;
  padding: 0.85rem 0.5rem;
  font: 700 0.95rem/1.1 var(--font-body);
  cursor: pointer;
  min-height: 48px;
}

.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn.primary,
.btn.primary-ish {
  background: var(--accent);
  border-color: #c48420;
  color: #1b1408;
}

.btn.primary { padding-inline: 1.2rem; font-size: 1.02rem; }

.btn[aria-pressed="true"] {
  background: #1c2a36;
  border-color: #1c2a36;
  color: #f4f7fa;
}

.footer-note {
  margin: 0;
  color: #536573;
  font-size: 0.9rem;
  line-height: 1.35;
}

.sheet {
  width: min(420px, calc(100vw - 1.5rem));
  border: 1px solid var(--line);
  border-radius: 1rem;
  padding: 0;
  background: #f4f7fa;
  color: var(--ink);
  box-shadow: var(--shadow);
}

.sheet::backdrop { background: rgba(12, 18, 24, 0.55); }

.sheet form {
  display: grid;
  gap: 0.85rem;
  padding: 1.1rem;
}

.sheet h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 2rem;
  letter-spacing: 0.05em;
}

.sheet-lead,
.sheet-live {
  margin: 0;
  color: #445868;
  font-weight: 600;
  font-size: 0.95rem;
}

.field {
  display: grid;
  gap: 0.35rem;
  text-align: left;
  font-weight: 700;
  font-size: 0.92rem;
}

.field input,
.field select {
  width: 100%;
  border: 1px solid #7f93a1;
  border-radius: 0.7rem;
  padding: 0.75rem 0.8rem;
  font: 600 1.05rem/1.2 var(--font-body);
  background: #fff;
  color: var(--ink);
}

.presets {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.chip {
  border: 1px solid #7f93a1;
  background: #fff;
  border-radius: 999px;
  padding: 0.45rem 0.7rem;
  font: 700 0.82rem/1 var(--font-body);
  cursor: pointer;
}

.chip:hover,
.chip.active {
  background: #1c2a36;
  border-color: #1c2a36;
  color: #fff;
}

.sheet-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.45rem;
}

@media (max-width: 520px) {
  .controls { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (orientation: landscape) and (max-height: 520px) {
  .app { width: min(1100px, 100%); }
  .stage {
    grid-template-columns: 1.1fr 0.9fr;
    align-items: stretch;
  }
  .viewport {
    max-height: none;
    aspect-ratio: 4 / 3;
    height: min(70dvh, 420px);
  }
}
