:root {
  --bg: #0b1220;
  --panel: #121a2a;
  --panel-border: #24344c;
  --text: #e8eef8;
  --muted: #8ea0b8;
  --cyan: #3ec8ff;
  --cyan-ink: #062033;
  --amber: #f0a020;
  --chip: #141c2c;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "PingFang TC", "Noto Sans CJK TC", "Noto Sans TC", "WenQuanYi Micro Hei", "Microsoft JhengHei", sans-serif;
  -webkit-text-size-adjust: 100%;
}

body { min-height: 100dvh; }

button, input { font: inherit; }

.app {
  width: min(480px, 100%);
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding:
    max(12px, env(safe-area-inset-top))
    16px
    max(16px, env(safe-area-inset-bottom));
  user-select: none;
}

.top h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1.25;
  font-weight: 750;
}

.top p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.viewport {
  position: relative;
  height: clamp(268px, 44dvh, 520px);
  border-radius: 18px;
  overflow: hidden;
  background: var(--bg);
  border: 1px solid #1d2b42;
  touch-action: none;
}

.viewport canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  background: var(--bg);
  touch-action: none;
}

.scene-badge {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 2;
  background: #2f6fed;
  color: #fff;
  font-size: 11px;
  font-weight: 750;
  letter-spacing: 0.04em;
  padding: 4px 8px;
  border-radius: 3px;
  pointer-events: none;
}

.float-label {
  position: absolute;
  z-index: 2;
  transform: translate(-50%, -50%);
  color: #e7eef8;
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
  pointer-events: none;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.9), 0 0 8px rgba(0, 0, 0, 0.65);
  opacity: 0;
}

.float-label.is-placed { opacity: 1; }

.float-label.tag {
  background: rgba(38, 48, 64, 0.92);
  border-radius: 6px;
  padding: 3px 7px;
  font-size: 11px;
  font-weight: 600;
}

.fallback {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  padding: 16px;
  text-align: center;
  color: var(--muted);
}

.fallback[hidden] { display: none; }

.supplier-card {
  --accent: var(--cyan);
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 12px;
  z-index: 4;
  padding: 12px 36px 12px 14px;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-left: 4px solid var(--accent);
  background: rgba(10, 16, 28, 0.94);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.4);
  user-select: text;
}

.supplier-card[hidden] { display: none; }

.supplier-card h3 {
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 18px;
}

.supplier-card p {
  margin: 4px 0 0;
  font-size: 15px;
  line-height: 1.35;
}

.card-en {
  color: var(--muted);
  font-size: 13px;
}

.card-close {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

.chips {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 6px;
}

.chip {
  min-height: 42px;
  border-radius: 12px;
  background: var(--chip);
  border: 1px solid var(--panel-border);
  padding: 5px 8px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 1px;
}

.chip-title { font-size: 13px; font-weight: 750; }

.chip-sub { font-size: 11px; color: var(--muted); }

.chip.is-active {
  border-color: var(--cyan);
  background: #102838;
  box-shadow: inset 0 0 0 1px var(--cyan);
}

.chip.is-active .chip-sub { color: #b7ecff; }

.play, .explode {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 14px;
  cursor: pointer;
  touch-action: manipulation;
  white-space: nowrap;
}

.play {
  height: 56px;
  border: 0;
  background: var(--cyan);
  color: var(--cyan-ink);
  font-size: 18px;
  font-weight: 800;
}

.play.is-playing { background: #1aa3d6; }

.explode {
  height: 52px;
  border: 2px solid var(--amber);
  background: transparent;
  color: var(--amber);
  font-size: 16px;
  font-weight: 750;
}

.explode.is-on { background: rgba(240, 160, 32, 0.16); }

.play:active, .explode:active { transform: scale(0.985); }

button:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

.supplier {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  padding: 10px 12px 10px;
  user-select: text;
}

.supplier h2 {
  margin: 0 0 6px;
  font-size: 14px;
  font-weight: 700;
}

.hint {
  margin: 0 0 10px;
  min-height: 1.2em;
  color: var(--muted);
  font-size: 12px;
}

.hint.is-alert { color: var(--amber); }

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  list-style: none;
  margin: 0;
  padding: 0;
}

.legend li {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 28px;
  padding: 3px 8px 3px 6px;
  border-radius: 999px;
  background: #101826;
  border: 1px solid #2a3b54;
  font-size: 12px;
  white-space: nowrap;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex: none;
}

.legend .en {
  color: var(--muted);
  font-size: 12px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 360px) {
  .play { font-size: 16px; }
  .explode { font-size: 15px; }
}

@media (prefers-reduced-motion: reduce) {
  .play:active, .explode:active { transform: none; }
}
