:root {
  color-scheme: light dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #f5f7f8;
  color: #111827;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  min-height: 40px;
  border: 1px solid #18212f;
  border-radius: 6px;
  background: #17202f;
  color: #fff;
  padding: 0 14px;
  cursor: pointer;
  touch-action: manipulation;
}

.primary-action {
  min-height: 52px;
  background: #0f766e;
  border-color: #0f766e;
  font-weight: 800;
}

button.secondary {
  background: #fff;
  color: #17202f;
}

.shell {
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: 18px;
}

.topbar {
  display: flex;
  gap: 16px;
  align-items: end;
  justify-content: space-between;
  border-bottom: 1px solid #d7dde3;
  padding-bottom: 14px;
}

h1 {
  margin: 0;
  font-size: clamp(1.55rem, 4vw, 2.35rem);
  line-height: 1.05;
}

p {
  margin: 8px 0 0;
  color: #536171;
}

.mode-tabs {
  display: inline-grid;
  grid-template-columns: repeat(3, minmax(84px, 1fr));
  gap: 6px;
  padding: 4px;
  border: 1px solid #ccd4dc;
  border-radius: 8px;
  background: #fff;
}

.mode-tabs button {
  border-color: transparent;
  background: transparent;
  color: #17202f;
}

.mode-tabs button.active {
  background: #0f766e;
  color: white;
}

.panel {
  display: none;
  padding-top: 18px;
}

.active-panel {
  display: block;
}

.role-picker {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 16px;
}

.role-button {
  display: grid;
  min-height: 86px;
  align-content: center;
  gap: 5px;
  border-radius: 8px;
  font-size: 1.08rem;
  font-weight: 850;
}

.role-button span {
  font-size: 0.86rem;
  font-weight: 500;
  opacity: 0.82;
}

.emit-role {
  background: #0f766e;
  border-color: #0f766e;
}

.capture-role {
  background: #7c2d12;
  border-color: #7c2d12;
}

.big-camera-button {
  width: 100%;
  min-height: 58px;
  margin-bottom: 12px;
  background: #7c2d12;
  border-color: #7c2d12;
  font-weight: 850;
}

.strobe {
  display: grid;
  min-height: min(62vh, 680px);
  place-items: center;
  border: 1px solid #cbd5df;
  border-radius: 8px;
  background: #101820;
  color: white;
  transition: background-color 30ms linear;
  touch-action: manipulation;
  user-select: none;
}

.target-frame {
  position: relative;
  display: grid;
  width: min(88vw, 780px);
  aspect-ratio: 1.34;
  place-items: center;
  border: clamp(10px, 2.5vw, 22px) solid #fff;
  outline: clamp(8px, 1.8vw, 18px) solid #000;
  background:
    linear-gradient(90deg, #000 0 10%, transparent 10% 90%, #000 90% 100%),
    linear-gradient(#000 0 12%, transparent 12% 88%, #000 88% 100%);
  box-shadow: 0 0 0 clamp(4px, 1vw, 10px) #fff;
}

.payload-window {
  display: grid;
  width: 72%;
  height: 62%;
  place-items: center;
  border: clamp(4px, 1vw, 8px) solid #fff;
  background: #101820;
}

.payload-window span {
  padding: 8px 12px;
  border-radius: 6px;
  background: rgb(0 0 0 / 46%);
  font-size: clamp(1.4rem, 6vw, 4rem);
  font-weight: 800;
}

.corner {
  position: absolute;
  width: 18%;
  aspect-ratio: 1;
  background:
    linear-gradient(90deg, #fff 0 34%, transparent 34%),
    linear-gradient(#fff 0 34%, transparent 34%);
}

.corner.top-left {
  top: 4%;
  left: 4%;
}

.corner.top-right {
  top: 4%;
  right: 4%;
  transform: rotate(90deg);
}

.corner.bottom-left {
  bottom: 4%;
  left: 4%;
  transform: rotate(270deg);
}

.corner.bottom-right {
  right: 4%;
  bottom: 4%;
  transform: rotate(180deg);
}

.frame-code {
  position: absolute;
  left: 32%;
  width: 36%;
  height: 5%;
  background: repeating-linear-gradient(
    90deg,
    #fff 0 8%,
    #000 8% 16%,
    #fff 16% 24%,
    #000 24% 40%
  );
}

.frame-code-top {
  top: 4%;
}

.frame-code-bottom {
  bottom: 4%;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: end;
  margin: 14px 0;
}

label {
  display: grid;
  gap: 5px;
  color: #425062;
  font-size: 0.92rem;
}

input,
select,
textarea {
  border: 1px solid #c8d1db;
  border-radius: 6px;
  background: #fff;
  color: #111827;
  padding: 9px 10px;
}

input {
  width: 132px;
}

select {
  min-width: 112px;
}

.log {
  min-height: 150px;
  max-height: 280px;
  overflow: auto;
  border: 1px solid #cbd5df;
  border-radius: 8px;
  background: #0d1520;
  color: #d8f3dc;
  padding: 12px;
  white-space: pre-wrap;
}

.status {
  border: 1px solid #cbd5df;
  border-radius: 8px;
  background: #fff;
  color: #17202f;
  margin-bottom: 12px;
  padding: 10px 12px;
}

.sequence-card {
  border: 1px solid #cbd5df;
  border-radius: 8px;
  background: #17202f;
  color: #fff;
  margin-bottom: 12px;
  padding: 10px 12px;
  line-height: 1.45;
}

.camera-wrap {
  position: relative;
  display: grid;
  min-height: min(54vh, 600px);
  place-items: center;
  overflow: hidden;
  border: 1px solid #cbd5df;
  border-radius: 8px;
  background: #0d1520;
}

.aim-guide {
  position: absolute;
  inset: 18% 10%;
  border: 2px dashed rgb(255 255 255 / 75%);
  pointer-events: none;
}

.aim-guide span {
  position: absolute;
  right: 10px;
  bottom: 10px;
  left: 10px;
  border-radius: 6px;
  background: rgb(0 0 0 / 58%);
  color: white;
  padding: 7px 9px;
  text-align: center;
  font-size: 0.92rem;
}

.aim-corner {
  position: absolute;
  width: 44px;
  height: 44px;
  border-color: #fff;
  border-style: solid;
}

.aim-corner.top-left {
  top: -2px;
  left: -2px;
  border-width: 5px 0 0 5px;
}

.aim-corner.top-right {
  top: -2px;
  right: -2px;
  border-width: 5px 5px 0 0;
}

.aim-corner.bottom-left {
  bottom: -2px;
  left: -2px;
  border-width: 0 0 5px 5px;
}

.aim-corner.bottom-right {
  right: -2px;
  bottom: -2px;
  border-width: 0 5px 5px 0;
}

video {
  width: 100%;
  height: 100%;
  min-height: min(54vh, 600px);
  object-fit: cover;
}

#sampleCanvas {
  display: none;
}

.sample-color {
  position: absolute;
  right: 14px;
  bottom: 14px;
  width: 72px;
  height: 72px;
  border: 3px solid #fff;
  border-radius: 8px;
  background: #333;
  box-shadow: 0 2px 18px rgb(0 0 0 / 40%);
}

.readout {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 12px;
}

.readout span {
  border: 1px solid #cbd5df;
  border-radius: 999px;
  background: #fff;
  padding: 7px 10px;
}

.analysis-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

textarea {
  min-height: 260px;
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (max-width: 720px) {
  .topbar {
    display: grid;
    align-items: stretch;
  }

  .mode-tabs {
    width: 100%;
  }

  .role-picker {
    grid-template-columns: 1fr;
  }

  .analysis-grid {
    grid-template-columns: 1fr;
  }
}

@media (prefers-color-scheme: dark) {
  :root {
    background: #111827;
    color: #f9fafb;
  }

  p,
  label {
    color: #bac6d2;
  }

  .mode-tabs,
  input,
  select,
  textarea,
  .status,
  .sequence-card,
  .readout span {
    background: #192232;
    color: #f9fafb;
  }
}
