:root {
  --truth-font-desktop: 11px;
  --truth-font-mobile: 10px;
  color-scheme: dark;
  --ink: #f2f6f7;
  --muted: #a8b6bc;
  --line: rgba(170, 202, 209, 0.2);
  --panel: rgba(9, 19, 24, 0.78);
  --panel-strong: rgba(8, 18, 22, 0.92);
  --red: #d44a48;
  --amber: #d29b42;
  --cyan: #5bc4d6;
  --blue: #4b8fb5;
  --green: #6fbd8c;
  font-family:
    Inter,
    "Segoe UI",
    "PingFang SC",
    "Microsoft YaHei",
    Arial,
    sans-serif;
  background: #071014;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  overflow: hidden;
  background: #071014;
  color: var(--ink);
}

button {
  color: inherit;
  font: inherit;
}

#app {
  position: relative;
  width: 100vw;
  height: 100vh;
  min-height: 700px;
  overflow: hidden;
  background:
    radial-gradient(circle at 43% 36%, rgba(50, 103, 118, 0.3), transparent 32%),
    radial-gradient(circle at 66% 18%, rgba(190, 130, 73, 0.1), transparent 28%),
    linear-gradient(158deg, #12242b 0%, #081318 58%, #050b0e 100%);
}

canvas#stage {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.floor-grid {
  position: absolute;
  z-index: 2;
  right: 20%;
  bottom: 0;
  left: 18%;
  height: 37%;
  pointer-events: none;
  background:
    linear-gradient(rgba(113, 164, 174, 0.12) 1px, transparent 1px),
    linear-gradient(90deg, rgba(113, 164, 174, 0.1) 1px, transparent 1px);
  background-size: 54px 54px;
  mask-image: linear-gradient(to top, rgba(0, 0, 0, 0.75), transparent 92%);
}

.topbar,
.intro,
.process-panel,
.qualification,
.flow-truth-note,
.corner-actions,
.control-hint {
  position: absolute;
  z-index: 10;
}

.topbar {
  top: 26px;
  right: 34px;
  left: 34px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 68px;
  padding: 10px 12px 10px 16px;
  border: 1px solid var(--line);
  background: rgba(7, 17, 21, 0.72);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(18px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  display: grid;
  width: 43px;
  height: 43px;
  place-items: center;
  border: 1px solid rgba(212, 74, 72, 0.85);
  color: #f17c78;
  font-size: 21px;
  font-weight: 900;
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  font-size: 19px;
  letter-spacing: 0.04em;
}

.brand small {
  margin-top: 3px;
  color: #81969e;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.16em;
}

.mode-switch {
  display: grid;
  grid-template-columns: repeat(2, minmax(130px, 1fr));
  gap: 5px;
}

.mode-switch button,
.corner-actions button {
  border: 1px solid rgba(139, 177, 185, 0.2);
  background: rgba(139, 177, 185, 0.07);
  cursor: pointer;
}

.mode-switch button {
  min-height: 42px;
  padding: 0 14px;
  color: #b5c2c6;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.04em;
}

.mode-switch button span {
  margin-right: 9px;
  color: #6f838b;
  font-size: 10px;
}

.bottom-ui {
  display: contents;
}

.mode-switch button:hover,
.mode-switch button:focus-visible,
.mode-switch button.active {
  border-color: rgba(212, 74, 72, 0.72);
  background: rgba(212, 74, 72, 0.15);
  color: #ffffff;
  outline: none;
}

.mode-switch button.active span {
  color: #f27d79;
}

.intro {
  top: 132px;
  left: 46px;
  width: min(390px, 28vw);
  pointer-events: none;
}

.eyebrow {
  margin: 0 0 11px;
  color: #77a6b0;
  font-size: 10px;
  font-weight: 850;
  letter-spacing: 0.16em;
}

h1 {
  margin: 0;
  max-width: 390px;
  font-size: clamp(31px, 2.8vw, 42px);
  line-height: 1.06;
  letter-spacing: -0.03em;
}

.intro-copy {
  margin: 15px 0 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.68;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 17px;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 26px;
  padding: 5px 8px;
  border: 1px solid rgba(148, 184, 192, 0.14);
  background: rgba(7, 16, 20, 0.54);
  color: #9babb1;
  font-size: 10px;
  font-weight: 750;
}

.legend i {
  display: block;
  width: 17px;
  height: 3px;
}

.legend .feed {
  background: var(--amber);
}

.legend .vapor {
  background: var(--cyan);
}

.legend .condensate {
  background: var(--green);
}

.process-panel {
  top: 118px;
  right: 34px;
  width: min(330px, 25vw);
  padding: 17px;
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: 0 22px 54px rgba(0, 0, 0, 0.32);
  backdrop-filter: blur(17px);
}

.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.panel-head small,
.panel-head strong {
  display: block;
}

.panel-head small {
  margin-bottom: 4px;
  color: #69bac9;
  font-size: 9px;
  font-weight: 850;
  letter-spacing: 0.13em;
}

.panel-head strong {
  font-size: 18px;
}

.panel-head em {
  color: #758990;
  font-size: 10px;
  font-style: normal;
}

#stageDescription {
  margin: 12px 0 15px;
  color: #9aabb1;
  font-size: 12px;
  line-height: 1.58;
}

.stage-buttons {
  display: grid;
  gap: 6px;
}

.stage-button {
  display: grid;
  grid-template-columns: 25px 1fr;
  align-items: center;
  min-height: 39px;
  padding: 6px 9px;
  border: 1px solid rgba(139, 177, 185, 0.12);
  background: rgba(139, 177, 185, 0.04);
  color: #9cabb0;
  cursor: pointer;
  text-align: left;
}

.stage-button b {
  font-size: 12px;
}

.stage-button span {
  color: #60757c;
  font-size: 9px;
  font-weight: 850;
}

.stage-button:hover,
.stage-button:focus-visible,
.stage-button.active {
  border-color: rgba(91, 196, 214, 0.45);
  background: rgba(91, 196, 214, 0.1);
  color: #f1f7f8;
  outline: none;
}

.labels-layer {
  position: absolute;
  z-index: 7;
  inset: 0;
  pointer-events: none;
}

.part-label {
  position: absolute;
  min-width: max-content;
  padding: 6px 8px;
  border: 1px solid rgba(106, 190, 203, 0.34);
  background: rgba(5, 15, 18, 0.8);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.22);
  color: #dce8ea;
  font-size: 10px;
  font-weight: 760;
  transform: translate(-50%, -50%);
}

.qualification {
  right: 50%;
  bottom: 28px;
  margin: 0;
  padding: 8px 11px;
  border: 1px solid rgba(148, 184, 192, 0.15);
  background: rgba(5, 14, 18, 0.66);
  color: #87999f;
  font-size: 10px;
  transform: translateX(50%);
  backdrop-filter: blur(12px);
}

.flow-truth-note {
  right: 50%;
  bottom: 61px;
  max-width: 460px;
  margin: 0;
  color: #9aabb1;
  font-size: 9px;
  text-align: center;
  transform: translateX(50%);
}

.corner-actions {
  right: 34px;
  bottom: 28px;
  display: flex;
  gap: 7px;
}

.corner-actions button {
  min-height: 36px;
  padding: 0 12px;
  color: #c2ced1;
  font-size: 11px;
  font-weight: 760;
}

.corner-actions button:hover,
.corner-actions button:focus-visible {
  border-color: rgba(91, 196, 214, 0.5);
  background: rgba(91, 196, 214, 0.12);
  outline: none;
}

.control-hint {
  bottom: 30px;
  left: 44px;
  margin: 0;
  color: #6f8188;
  font-size: 10px;
}

.fallback {
  position: absolute;
  z-index: 50;
  inset: 0;
  display: none;
  place-items: center;
  padding: 32px;
  background: #071014;
  color: #dfe7e9;
  text-align: center;
}

.fallback {
  grid-template-rows: auto auto;
  align-content: center;
  gap: 16px;
}

.fallback p {
  margin: 0;
}

.fallback-action {
  min-width: 120px;
  padding: 9px 14px;
  border: 1px solid rgba(91, 196, 214, 0.45);
  color: #e4f3f5;
  text-decoration: none;
}

@media (max-width: 900px) {
  #app {
    min-height: 0;
  }

  .topbar {
    top: 12px;
    right: 12px;
    left: 12px;
    min-height: 58px;
    padding: 8px;
  }

  .brand-mark {
    width: 37px;
    height: 37px;
    font-size: 18px;
  }

  .brand strong {
    font-size: 15px;
  }

  .brand small,
  .intro,
  .control-hint,
  .floor-grid {
    display: none;
  }

  .mode-switch {
    grid-template-columns: repeat(2, minmax(85px, 1fr));
  }

  .mode-switch button {
    min-height: 37px;
    padding: 0 8px;
    font-size: 11px;
  }

  .mode-switch button span {
    display: none;
  }

  .process-panel {
    top: auto;
    right: 12px;
    bottom: 64px;
    left: 12px;
    width: auto;
    padding: 12px;
  }

  .panel-head strong {
    font-size: 15px;
  }

  #stageDescription {
    display: none;
  }

  .stage-buttons {
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 4px;
    margin-top: 10px;
  }

  .stage-button {
    display: grid;
    grid-template-columns: 1fr;
    min-width: 0;
    min-height: 48px;
    place-items: center;
    padding: 4px;
    text-align: center;
  }

  .stage-button b {
    display: block;
    font-size: 11px;
    line-height: 1.25;
    overflow-wrap: anywhere;
  }

  .stage-button span {
    font-size: 9px;
  }

  .qualification {
    bottom: 17px;
    left: 12px;
    right: auto;
    max-width: calc(100% - 168px);
    padding: 5px 7px;
    font-size: 8px;
    transform: none;
  }

  .flow-truth-note {
    right: auto;
    bottom: 42px;
    left: 12px;
    max-width: calc(100% - 24px);
    font-size: 7px;
    text-align: left;
    transform: none;
  }

  .corner-actions {
    right: 12px;
    bottom: 14px;
  }

  .corner-actions button {
    min-height: 30px;
    padding: 0 8px;
    font-size: 9px;
  }

  .part-label {
    padding: 4px 6px;
    font-size: 8px;
  }
}

@media (max-width: 430px) {
  .stage-buttons {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .brand > span:last-child {
    display: none;
  }

  .mode-switch {
    flex: 1;
    margin-left: 8px;
  }

  .process-panel {
    bottom: 58px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}

.flow-truth-note,
.qualification,
.control-hint {
  font-size: var(--truth-font-desktop);
}

@media (max-width: 900px) {
  .flow-truth-note,
  .qualification,
  .control-hint {
    font-size: var(--truth-font-mobile);
  }

  .flow-truth-note,
  .qualification {
    overflow: visible;
    text-overflow: clip;
    white-space: normal;
  }

  .bottom-ui {
    position: absolute;
    z-index: 10;
    right: 12px;
    bottom: 12px;
    left: 12px;
    display: grid;
    gap: 8px;
    pointer-events: none;
  }

  .bottom-ui > .process-panel,
  .bottom-ui > .qualification,
  .bottom-ui > .flow-truth-note,
  .bottom-ui > .corner-actions {
    position: static;
    width: auto;
    max-width: none;
    transform: none;
  }

  .bottom-ui > .qualification,
  .bottom-ui > .flow-truth-note {
    line-height: 1.4;
  }

  .bottom-ui > .corner-actions {
    justify-self: end;
  }

  .bottom-ui button {
    pointer-events: auto;
  }
}
