* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  overflow-x: hidden;
  background: #071018;
  color: #e8fbff;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body {
  background:
    linear-gradient(rgba(255, 255, 255, .025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, .022) 1px, transparent 1px),
    radial-gradient(circle at 16% 0%, rgba(30, 226, 255, .14), transparent 34rem),
    radial-gradient(circle at 80% 10%, rgba(255, 220, 120, .08), transparent 30rem),
    #071018;
  background-size: 32px 32px, 32px 32px, auto, auto, auto;
}

a {
  color: #62e8ff;
}

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

button {
  min-height: 42px;
  border: 1px solid rgba(98, 230, 255, .36);
  border-radius: 10px;
  background: linear-gradient(180deg, rgba(20, 198, 232, .28), rgba(7, 82, 110, .28));
  color: #effeff;
  cursor: pointer;
  font-weight: 800;
  padding: 10px 14px;
}

button:hover,
button:focus-visible {
  border-color: rgba(98, 230, 255, .78);
}

button:disabled {
  cursor: not-allowed;
  opacity: .48;
}

h1,
h2,
h3,
p,
li,
strong,
span {
  overflow-wrap: anywhere;
}

.lab-page {
  width: min(1120px, calc(100% - 28px));
  margin: 0 auto;
  padding: 34px 0 46px;
}

.lab-hero,
.tool-panel,
.info-card,
.related-section,
.comments-wrap {
  border: 1px solid rgba(111, 228, 255, .18);
  border-radius: 14px;
  background: rgba(8, 20, 28, .78);
  box-shadow: 0 0 38px rgba(0, 216, 255, .08);
}

.lab-hero {
  padding: clamp(26px, 5vw, 56px);
}

.eyebrow {
  margin: 0 0 9px;
  color: #6befff;
  font-size: .74rem;
  letter-spacing: .12em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(2.1rem, 7vw, 4.8rem);
  letter-spacing: 0;
  line-height: 1.06;
}

h2 {
  margin: 0 0 12px;
  font-size: clamp(1.15rem, 3vw, 1.7rem);
}

.lead {
  max-width: 800px;
  margin: 18px 0 0;
  color: rgba(231, 251, 255, .82);
  line-height: 1.85;
}

.hero-actions,
.control-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.hero-actions {
  margin-top: 20px;
}

.primary-link,
.ghost-link {
  display: inline-flex;
  align-items: center;
  min-height: 42px;
  border-radius: 10px;
  padding: 10px 14px;
  text-decoration: none;
  font-weight: 800;
}

.primary-link {
  border: 1px solid rgba(98, 230, 255, .45);
  background: rgba(16, 153, 185, .26);
  color: #effeff;
}

.ghost-link {
  border: 1px solid rgba(255, 255, 255, .16);
  background: rgba(255, 255, 255, .05);
  color: #dffcff;
}

.tool-panel {
  margin-top: 20px;
  padding: clamp(18px, 4vw, 32px);
}

.section-head p {
  max-width: 820px;
  margin: 0;
  color: rgba(231, 251, 255, .75);
  line-height: 1.7;
}

.control-row {
  margin: 16px 0;
}

.command-button.secondary {
  background: rgba(255, 255, 255, .05);
}

.status-message {
  margin: 12px 0;
  color: rgba(231, 251, 255, .78);
  line-height: 1.7;
}

.preview-frame {
  position: relative;
  min-height: 320px;
  overflow: hidden;
  border: 1px solid rgba(111, 228, 255, .2);
  border-radius: 12px;
  background: #030b10;
}

.preview-frame video {
  display: block;
  width: 100%;
  height: min(62vh, 520px);
  object-fit: cover;
  background: #030b10;
}

.preview-placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  padding: 22px;
  background: rgba(4, 16, 23, .86);
  color: rgba(232, 251, 255, .72);
  font-weight: 900;
  letter-spacing: .08em;
  text-align: center;
}

.preview-placeholder[hidden] {
  display: none;
}

.camera-guide {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.camera-guide[hidden] {
  display: none;
}

.guide-line {
  position: absolute;
  background: rgba(111, 228, 255, .45);
}

.guide-line.vertical {
  top: 0;
  bottom: 0;
  left: 50%;
  width: 1px;
}

.guide-line.horizontal {
  right: 0;
  left: 0;
  top: 50%;
  height: 1px;
}

.guide-label {
  position: absolute;
  top: 14px;
  color: #ffe28a;
  font-weight: 900;
}

.guide-label.left {
  left: 14px;
}

.guide-label.right {
  right: 14px;
}

.is-mirrored video {
  transform: scaleX(-1);
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin: 18px 0 0;
}

.metric-card {
  min-width: 0;
  border: 1px solid rgba(111, 228, 255, .16);
  border-radius: 10px;
  background: rgba(1, 8, 12, .72);
  padding: 12px;
}

.metric-card span {
  display: block;
  color: rgba(178, 235, 244, .67);
  font-size: .72rem;
  letter-spacing: .08em;
}

.metric-card strong {
  display: block;
  margin-top: 6px;
  color: #fff;
  font-size: clamp(1.05rem, 2.6vw, 1.55rem);
}

.metric-card small {
  display: block;
  margin-top: 5px;
  color: rgba(231, 251, 255, .62);
  line-height: 1.45;
}

.meter-block {
  margin-top: 14px;
}

.level-meter {
  height: 16px;
  overflow: hidden;
  border: 1px solid rgba(111, 228, 255, .2);
  border-radius: 999px;
  background: rgba(0, 6, 10, .7);
}

.level-meter span {
  display: block;
  width: 100%;
  height: 100%;
  transform: scaleX(0);
  transform-origin: left center;
  background: linear-gradient(90deg, #1de9ff, #7cffc7, #ffe28a, #ff7777);
  transition: transform .08s linear;
}

canvas {
  display: block;
  width: 100%;
  height: 220px;
}

#waveCanvas {
  margin-top: 14px;
  border: 1px solid rgba(111, 228, 255, .15);
  border-radius: 12px;
  background: #041017;
}

.pixel-stage {
  position: relative;
  display: grid;
  min-height: 340px;
  place-items: end start;
  overflow: hidden;
  border: 1px solid rgba(111, 228, 255, .2);
  border-radius: 12px;
  background: #fff;
  color: #fff;
}

.pixel-stage p {
  margin: 12px;
  padding: 10px;
  border-radius: 8px;
  background: rgba(0, 0, 0, .58);
}

.pixel-stage.is-black,
.pattern-view.is-black {
  background: #000;
}

.pixel-stage.is-red,
.pattern-view.is-red {
  background: #f00;
}

.pixel-stage.is-green,
.pattern-view.is-green {
  background: #00b050;
}

.pixel-stage.is-blue,
.pattern-view.is-blue {
  background: #005bff;
}

.pixel-stage.is-gray,
.pattern-view.is-gray {
  background: #777;
}

.pixel-stage.is-white,
.pattern-view.is-white {
  background: #fff;
}

.color-controls {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.color-button {
  min-height: 52px;
  border-color: rgba(255, 255, 255, .3);
  text-shadow: 0 1px 2px rgba(0, 0, 0, .7);
}

.color-button[data-color="white"] {
  background: #fff;
  color: #111;
  text-shadow: none;
}

.color-button[data-color="black"] {
  background: #000;
}

.color-button[data-color="red"] {
  background: #d80000;
}

.color-button[data-color="green"] {
  background: #008f3a;
}

.color-button[data-color="blue"] {
  background: #005bff;
}

.color-button[data-color="gray"] {
  background: #777;
}

.pattern-view {
  position: fixed;
  z-index: 1000;
  inset: 0;
  color: #fff;
}

.pattern-toolbar {
  position: absolute;
  z-index: 2;
  top: 10px;
  right: 10px;
  left: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.pattern-toolbar span,
.pattern-toolbar button {
  border: 1px solid rgba(255, 255, 255, .5);
  border-radius: 999px;
  background: rgba(0, 0, 0, .58);
  color: #fff;
  padding: 9px 12px;
  font-weight: 900;
}

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

.info-card,
.related-section,
.comments-wrap {
  padding: clamp(18px, 3vw, 26px);
}

.info-card p,
.info-card li {
  color: rgba(231, 251, 255, .77);
  line-height: 1.8;
}

.related-section {
  margin-top: 18px;
}

.related-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.related-grid a {
  display: block;
  min-width: 0;
  border: 1px solid rgba(111, 228, 255, .17);
  border-radius: 10px;
  background: rgba(3, 13, 18, .75);
  color: #e8fbff;
  padding: 13px;
  text-decoration: none;
}

.related-grid strong {
  display: block;
}

.related-grid span {
  display: block;
  margin-top: 5px;
  color: rgba(231, 251, 255, .62);
  line-height: 1.5;
}

.comments-wrap {
  margin-top: 18px;
}

.app-comments,
.app-comment-form-section {
  border: 1px solid rgba(112, 220, 240, .22) !important;
  background: rgba(6, 18, 24, .92) !important;
  color: #e8fbff !important;
}

.app-comment-form input,
.app-comment-form textarea,
.app-comment-form select {
  border: 1px solid rgba(112, 220, 240, .28) !important;
  background: rgba(3, 10, 14, .9) !important;
  color: #e8fbff !important;
}

.return-links {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  width: min(760px, 100%);
  margin: 18px auto 0;
}

.site-return,
.mothership-link {
  border-radius: 10px;
  padding: 15px;
  text-align: center;
}

.site-return {
  border: 1px solid rgba(111, 228, 255, .17);
  background: rgba(6, 18, 24, .72);
}

.mothership-link {
  border: 1px solid rgba(255, 216, 112, .18);
  background: rgba(20, 18, 11, .55);
}

.site-return span,
.mothership-link span {
  display: block;
  color: #6befff;
  font-size: .72rem;
  letter-spacing: .12em;
}

.site-return a,
.mothership-link a {
  display: inline-block;
  margin-top: 4px;
  font-weight: 800;
}

.site-return p,
.mothership-link p {
  margin: 5px 0 0;
  color: rgba(231, 251, 255, .62);
  font-size: .84rem;
}

@media (max-width: 820px) {
  .info-grid,
  .return-links {
    grid-template-columns: 1fr;
  }

  .metric-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

  .color-controls {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 420px) {
  .lab-page {
    width: min(100% - 18px, 1120px);
    padding-top: 18px;
  }

  .lab-hero,
  .tool-panel,
  .info-card,
  .related-section,
  .comments-wrap {
    border-radius: 10px;
  }

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

  canvas {
    height: 180px;
  }

  .preview-frame {
    min-height: 260px;
  }

  .color-controls {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .pattern-toolbar {
    align-items: stretch;
    flex-direction: column;
  }
}
