/* Homepage live-demo section — every rule scoped under #demo.
   Tokens come from website/style.css (:root). Do not import player.css. */

#demo {
  --demo-bezel-pad: 10px;
  --demo-bezel-radius: 14px;
  --demo-screen-radius: 6px;
  --demo-btn-radius: 10px;
  margin-top: clamp(2.75rem, 7vw, 4.25rem);
  width: 100%;
  max-width: 100%;
  min-width: 0;
}

#demo .demo-head {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

#demo .demo-label {
  margin: 0;
  font-family: var(--font-head);
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--cyan);
}

#demo .demo-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  align-items: stretch;
  min-width: 0;
  padding: 0.35rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(15, 20, 27, 0.65);
}

#demo .demo-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 1 1 auto;
  min-width: 0;
  margin: 0;
  padding: 0.55rem 0.95rem;
  border: 1px solid transparent;
  border-radius: 999px;
  background: transparent;
  color: var(--dim);
  font-family: var(--font-head);
  font-size: 0.84rem;
  font-weight: 500;
  letter-spacing: -0.01em;
  line-height: 1.2;
  cursor: pointer;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
  transition: border-color 0.15s, background 0.15s, color 0.15s, box-shadow 0.15s;
}

#demo .demo-chip:hover:not(:disabled),
#demo .demo-chip:focus-visible {
  border-color: rgba(45, 225, 214, 0.28);
  color: var(--text);
  background: rgba(45, 225, 214, 0.05);
  outline: none;
}

#demo .demo-chip:disabled {
  opacity: 0.5;
  cursor: default;
}

/* Selected chip: cyan fill (mockup binding) */
#demo .demo-chip.active {
  color: #04231f;
  border-color: var(--cyan);
  background: var(--cyan);
  box-shadow: 0 0 18px rgba(45, 225, 214, 0.28);
}

#demo .demo-chip.active:hover:not(:disabled) {
  color: #04231f;
  background: var(--cyan-hi);
  border-color: var(--cyan-hi);
}

/* ---- stage: sim first, drawer below in document flow -------------------- */

#demo .demo-stage {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.75rem;
  min-width: 0;
  width: 100%;
}

#demo .demo-device {
  display: flex;
  justify-content: center;
  width: 100%;
  min-width: 0;
  /* Sim takes space precedence over drawer/options */
  flex: 0 0 auto;
}

#demo .demo-bezel {
  position: relative;
  display: flex;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  /* Default pre-load frame; JS sets model aspect on load */
  aspect-ratio: 800 / 480;
  padding: var(--demo-bezel-pad);
  border-radius: var(--demo-bezel-radius);
  background:
    linear-gradient(145deg, #1a222c 0%, #0c1016 45%, #151c26 100%);
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.55),
    inset 0 1px 0 rgba(255, 255, 255, 0.08),
    inset 0 -1px 0 rgba(0, 0, 0, 0.35),
    0 18px 50px rgba(0, 0, 0, 0.55),
    0 0 60px rgba(45, 225, 214, 0.12),
    0 28px 70px rgba(45, 225, 214, 0.08);
  transition: box-shadow 0.35s ease;
}

#demo .demo-bezel.loaded {
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.55),
    inset 0 1px 0 rgba(255, 255, 255, 0.08),
    inset 0 -1px 0 rgba(0, 0, 0, 0.35),
    0 18px 50px rgba(0, 0, 0, 0.55),
    0 0 80px rgba(45, 225, 214, 0.22),
    0 32px 80px rgba(45, 225, 214, 0.14);
}

#demo .demo-screen {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  width: 100%;
  height: 100%;
  border-radius: var(--demo-screen-radius);
  background: #05070a;
  overflow: hidden;
  box-shadow:
    inset 0 0 0 1px rgba(45, 225, 214, 0.06),
    inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

#demo .demo-canvas-host {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
  min-width: 0;
  min-height: 0;
}

#demo .demo-canvas-host canvas {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  touch-action: none;
  cursor: crosshair;
}

#demo .demo-frame-error,
#demo .demo-frame-status {
  position: absolute;
  left: 50%;
  bottom: 0.85rem;
  transform: translateX(-50%);
  max-width: calc(100% - 1.5rem);
  padding: 0.5rem 0.85rem;
  border-radius: 8px;
  font-size: 0.82rem;
  line-height: 1.4;
  text-align: center;
  z-index: 2;
  pointer-events: none;
}

#demo .demo-frame-error {
  background: rgba(40, 12, 12, 0.92);
  border: 1px solid rgba(255, 122, 122, 0.45);
  color: #ff9a9a;
}

#demo .demo-frame-status {
  background: rgba(7, 9, 12, 0.88);
  border: 1px solid var(--line);
  color: var(--dim);
}

/* ---- drawer: always below sim; collapsed by default --------------------- */

#demo .demo-drawer {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 0;
  min-width: 0;
  width: 100%;
}

#demo .demo-drawer-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  min-width: 0;
}

#demo .demo-drawer-tab {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  min-width: 0;
  margin: 0;
  padding: 0.65rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  color: var(--dim);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 400;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}

#demo .demo-drawer-tab:hover,
#demo .demo-drawer-tab:focus-visible {
  color: var(--text);
  border-color: rgba(45, 225, 214, 0.35);
  outline: none;
}

#demo .demo-drawer-tab[aria-expanded="true"] {
  color: var(--cyan);
  border-color: rgba(45, 225, 214, 0.45);
  background: rgba(45, 225, 214, 0.06);
}

#demo .demo-drawer-chevron {
  display: inline-block;
  width: 0.45rem;
  height: 0.45rem;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(-45deg);
  transition: transform 0.15s;
  flex: 0 0 auto;
  opacity: 0.75;
}

#demo .demo-drawer-tab[aria-expanded="true"] .demo-drawer-chevron {
  transform: rotate(45deg);
}

#demo .demo-drawer-panels {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

#demo .demo-drawer-panel {
  margin-top: 0.5rem;
  padding: 0.85rem 0.9rem 0.95rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(10, 13, 18, 0.92);
  min-width: 0;
  /* Expansion grows document flow — never overlays or shrinks the bezel */
}

#demo .demo-drawer-panel[hidden] {
  display: none !important;
}

#demo .demo-section-label {
  margin: 0 0 0.55rem;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 400;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--dim);
}

#demo .demo-section-label-sub {
  margin-top: 0.85rem;
}

#demo .demo-term-log {
  height: 9.5rem;
  max-height: 28vh;
  overflow: auto;
  padding: 0.45rem 0.55rem;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--line);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  line-height: 1.45;
  color: var(--dim);
}

#demo .demo-term-line {
  display: block;
  white-space: pre-wrap;
  word-break: break-word;
}

#demo .demo-term-line.tx { color: #5c6878; }
#demo .demo-term-line.rx { color: var(--cyan); }
#demo .demo-term-line.sys { color: var(--dim); }
#demo .demo-term-line.err { color: #ff9a9a; }

#demo .demo-term-form {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.55rem;
  min-width: 0;
}

#demo .demo-term-prompt {
  color: var(--cyan-lo);
  font-family: var(--font-mono);
  font-size: 0.85rem;
  flex: 0 0 auto;
}

#demo .demo-term-input {
  flex: 1 1 auto;
  min-width: 0;
  margin: 0;
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.4);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 0.82rem;
}

#demo .demo-term-input::placeholder { color: #5c6878; }

#demo .demo-term-input:focus {
  outline: none;
  border-color: var(--cyan-lo);
  box-shadow: 0 0 0 3px rgba(45, 225, 214, 0.14);
}

#demo .demo-term-send {
  flex: 0 0 auto;
  margin: 0;
  padding: 0.5rem 0.85rem;
  border: none;
  border-radius: 8px;
  background: var(--cyan);
  color: #04231f;
  font-family: var(--font-head);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

#demo .demo-term-send:hover { background: var(--cyan-hi); }

#demo .demo-inspector-scroll {
  max-height: min(240px, 32vh);
  overflow: auto;
  min-width: 0;
}

#demo .demo-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
}

#demo .demo-table th,
#demo .demo-table td {
  padding: 0.35rem 0.45rem;
  text-align: left;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

#demo .demo-table th {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 400;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--dim);
}

#demo .demo-table td {
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 0.75rem;
}

#demo .demo-table .demo-empty-row td {
  color: var(--dim);
  font-family: var(--font-body);
}

#demo .demo-table .ch-value {
  color: var(--cyan);
}

/* ---- responsive priority ------------------------------------------------
   (a) drawer already stacks below sim (column layout always)
   (b) chips wrap / condense
   (c) only then canvas scales via width-driven aspect-ratio bezel
   At 390px: canvas full available width, dominant. */

@media (max-width: 720px) {
  #demo {
    --demo-bezel-pad: 7px;
  }

  #demo .demo-chip {
    flex: 1 1 calc(50% - 0.5rem);
    padding: 0.5rem 0.7rem;
    font-size: 0.78rem;
  }

  #demo .demo-term-log {
    height: 8rem;
  }
}

@media (max-width: 420px) {
  #demo .demo-chip {
    flex: 1 1 100%;
    justify-content: flex-start;
    border-radius: 10px;
    white-space: normal;
  }

  #demo .demo-drawer-tab {
    padding: 0.6rem 0.7rem;
    font-size: 0.68rem;
  }

  #demo .demo-term-form {
    flex-wrap: wrap;
  }

  #demo .demo-term-send {
    width: 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  #demo .demo-bezel,
  #demo .demo-chip,
  #demo .demo-drawer-tab,
  #demo .demo-drawer-chevron {
    transition: none;
  }
}
