:root {
  --ink: #181512;
  --paper: #f4f0e6;
  --paper-2: #e6fbff;
  --stage: #0f0e12;
  --line: #2b261f;
  --lime: #d9ff35;
  --cyan: #32d7ee;
  --coral: #ff515b;
  --violet: #7657ff;
  --gold: #ffcc37;
  --white: #fffdf4;
  --shadow: 0 18px 42px rgba(24, 21, 18, 0.22);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  color: var(--ink);
  font-family: "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  overscroll-behavior: none;
  background:
    linear-gradient(135deg, rgba(50, 215, 238, 0.2) 0 25%, transparent 25% 100%),
    linear-gradient(315deg, rgba(255, 81, 91, 0.18) 0 22%, transparent 22% 100%),
    linear-gradient(90deg, var(--paper) 0 48%, var(--paper-2) 48% 100%);
}

button {
  font: inherit;
}

.app-shell {
  width: min(1180px, calc(100% - 32px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 22px 0;
  display: grid;
  grid-template-rows: auto minmax(420px, 1fr) auto;
  gap: 14px;
}

.topbar,
.control-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 240px;
}

.brand-mark {
  width: 54px;
  height: 54px;
  flex: 0 0 auto;
  border: 3px solid var(--ink);
  border-radius: 8px;
  background:
    linear-gradient(45deg, transparent 0 38%, var(--ink) 38% 44%, transparent 44% 100%),
    radial-gradient(circle at 70% 30%, var(--lime) 0 18%, transparent 19%),
    linear-gradient(135deg, var(--cyan), var(--coral));
  box-shadow: 6px 6px 0 var(--ink);
}

.eyebrow {
  margin: 0 0 2px;
  color: rgba(24, 21, 18, 0.64);
  font-size: 0.78rem;
  font-weight: 700;
}

h1,
h2 {
  margin: 0;
  font-family: "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  letter-spacing: 0;
  line-height: 1.12;
}

h1 {
  font-size: 2rem;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(88px, 1fr));
  gap: 8px;
  width: min(520px, 100%);
}

.metric,
.status-pill,
.breath-pill,
.best-pill {
  border: 2px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 244, 0.78);
  box-shadow: 4px 4px 0 rgba(24, 21, 18, 0.92);
}

.metric {
  min-height: 62px;
  padding: 9px 11px 8px;
}

.metric span {
  display: block;
  color: rgba(24, 21, 18, 0.58);
  font-size: 0.75rem;
  font-weight: 700;
}

.metric strong {
  display: block;
  margin-top: 2px;
  font-size: 1.6rem;
  line-height: 1;
}

.stage {
  position: relative;
  min-height: 420px;
  height: 100%;
  overflow: hidden;
  border: 3px solid var(--ink);
  border-radius: 8px;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.08) 1px, transparent 1px),
    linear-gradient(0deg, rgba(255, 255, 255, 0.08) 1px, transparent 1px),
    var(--stage);
  background-size: 40px 40px;
  box-shadow: var(--shadow), 8px 8px 0 var(--ink);
}

#cameraFeed {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 420px;
  touch-action: none;
}

.start-layer {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background:
    linear-gradient(rgba(15, 14, 18, 0.32), rgba(15, 14, 18, 0.32)),
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.05) 0 1px, transparent 1px 16px);
}

.start-layer.hidden {
  pointer-events: none;
  opacity: 0;
  transition: opacity 180ms ease;
}

.start-panel {
  width: min(360px, 100%);
  padding: 22px;
  border: 2px solid var(--white);
  border-radius: 8px;
  color: var(--white);
  background: rgba(15, 14, 18, 0.8);
  box-shadow: 8px 8px 0 rgba(217, 255, 53, 0.95);
  text-align: center;
  backdrop-filter: blur(10px);
}

.signal {
  width: 86px;
  height: 38px;
  margin: 0 auto 16px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
  align-items: end;
}

.signal span {
  display: block;
  border: 2px solid var(--white);
  border-radius: 6px 6px 2px 2px;
  background: var(--cyan);
  box-shadow: 3px 3px 0 var(--coral);
}

.signal span:nth-child(1) {
  height: 18px;
}

.signal span:nth-child(2) {
  height: 30px;
  background: var(--lime);
}

.signal span:nth-child(3) {
  height: 24px;
  background: var(--gold);
}

.start-panel h2 {
  font-size: 2.2rem;
}

.start-panel p {
  min-height: 22px;
  margin: 10px 0 18px;
  color: rgba(255, 253, 244, 0.76);
  font-size: 0.95rem;
}

.primary-button {
  min-height: 48px;
  min-width: 190px;
  border: 0;
  border-radius: 8px;
  color: var(--ink);
  background: var(--lime);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 5px 5px 0 var(--white);
}

.primary-button:hover,
.tool-button:hover {
  transform: translate(-1px, -1px);
}

.primary-button:active,
.tool-button:active {
  transform: translate(2px, 2px);
}

.primary-button:disabled {
  opacity: 0.72;
  cursor: wait;
}

.primary-button svg,
.tool-button svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

.control-strip {
  min-height: 52px;
}

.status-pill,
.breath-pill,
.best-pill {
  min-height: 42px;
  padding: 10px 12px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 800;
}

.status-pill {
  min-width: 150px;
}

.breath-pill {
  min-width: 170px;
  color: rgba(255, 253, 244, 0.92);
  background: rgba(24, 21, 18, 0.86);
}

.status-pill.live {
  background: var(--lime);
}

.status-pill.searching {
  background: var(--gold);
}

.best-pill {
  background: var(--cyan);
}

.button-row {
  display: flex;
  gap: 10px;
}

.tool-button {
  width: 44px;
  height: 44px;
  border: 2px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: var(--white);
  cursor: pointer;
  display: inline-grid;
  place-items: center;
  box-shadow: 4px 4px 0 var(--ink);
}

.tool-button svg {
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.tool-button[aria-pressed="true"] {
  background: var(--coral);
  color: var(--white);
}

.music-button[aria-pressed="true"] {
  background: var(--gold);
  color: var(--ink);
}

@media (max-width: 840px) {
  .app-shell {
    width: min(100% - 18px, 720px);
    grid-template-rows: auto minmax(440px, 1fr) auto;
    padding: 10px 0 14px;
  }

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

  .brand {
    min-width: 0;
  }

  .metrics {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    width: 100%;
  }

  .metric {
    min-height: 56px;
    padding: 8px 7px;
  }

  .metric span {
    font-size: 0.68rem;
  }

  .metric strong {
    font-size: 1.25rem;
  }

  .control-strip {
    align-items: stretch;
    display: grid;
    grid-template-columns: 1fr 1fr auto auto;
  }
}

@media (max-width: 560px) {
  body {
    min-height: 100dvh;
  }

  .app-shell {
    width: min(100% - 12px, 440px);
    min-height: 100dvh;
    padding: 8px 0 10px;
    grid-template-rows: auto minmax(0, 1fr) auto;
    gap: 8px;
  }

  .topbar {
    gap: 8px;
  }

  .brand {
    gap: 10px;
  }

  .brand-mark {
    width: 40px;
    height: 40px;
    box-shadow: 4px 4px 0 var(--ink);
  }

  .eyebrow {
    font-size: 0.68rem;
  }

  h1 {
    font-size: 1.42rem;
  }

  .stage,
  #gameCanvas {
    min-height: 0;
  }

  .stage {
    border-width: 2px;
    box-shadow: var(--shadow), 5px 5px 0 var(--ink);
  }

  .metrics {
    gap: 6px;
  }

  .metric {
    min-height: 46px;
    padding: 6px 6px 5px;
  }

  .metric span {
    font-size: 0.62rem;
  }

  .metric strong {
    font-size: 1.08rem;
  }

  .start-layer {
    padding: 14px;
  }

  .start-panel {
    width: min(310px, 100%);
    padding: 18px 16px;
    box-shadow: 6px 6px 0 rgba(217, 255, 53, 0.95);
  }

  .start-panel h2 {
    font-size: 1.74rem;
  }

  .start-panel p {
    font-size: 0.86rem;
  }

  .primary-button {
    min-width: 160px;
    min-height: 44px;
  }

  .control-strip {
    grid-template-columns: minmax(0, 1fr) auto;
    min-height: 44px;
    gap: 8px;
  }

  .status-pill {
    grid-column: 1;
    grid-row: 1;
  }

  .status-pill,
  .breath-pill,
  .best-pill {
    min-height: 38px;
    padding: 8px 10px;
    font-size: 0.86rem;
    box-shadow: 3px 3px 0 rgba(24, 21, 18, 0.92);
  }

  .breath-pill {
    min-width: 0;
    grid-column: 1;
    grid-row: 2;
  }

  .best-pill {
    grid-column: 2;
    grid-row: 2;
  }

  .button-row {
    grid-column: 2;
    grid-row: 1;
    justify-content: flex-end;
  }

  .tool-button {
    width: 40px;
    height: 40px;
    box-shadow: 3px 3px 0 var(--ink);
  }
}

@media (max-width: 420px) {
  .metrics {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .metric {
    padding-inline: 4px;
  }

  .metric span {
    font-size: 0.58rem;
  }

  .metric strong {
    font-size: 1rem;
  }
}
