:root {
  color-scheme: dark;
  --bg: #08111f;
  --panel: rgba(10, 20, 35, 0.88);
  --panel-solid: #0d1728;
  --line: rgba(176, 198, 231, 0.22);
  --text: #f5f8ff;
  --muted: #a9b8cc;
  --blue: #57a6ff;
  --cyan: #48e2d4;
  --green: #65d77d;
  --orange: #ffb057;
  --red: #ff6b7a;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  width: 100vw;
  height: 100vh;
  background:
    radial-gradient(circle at 20% 15%, rgba(72, 226, 212, 0.18), transparent 26rem),
    radial-gradient(circle at 70% 80%, rgba(87, 166, 255, 0.2), transparent 28rem),
    linear-gradient(135deg, #08111f 0%, #111827 55%, #08111f 100%);
}

.stage {
  position: relative;
  min-width: 0;
  min-height: 0;
}

#scene {
  display: block;
  width: 100%;
  height: 100%;
}

.scene-label,
.legend,
.panel {
  backdrop-filter: blur(16px);
  border: 1px solid var(--line);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.28);
}

.scene-label {
  position: absolute;
  top: 24px;
  left: 24px;
  width: min(460px, calc(100% - 48px));
  padding: 18px 20px;
  border-radius: 10px;
  background: rgba(8, 17, 31, 0.72);
}

body.network-mode .app-shell {
  background: #03080d;
}

body.network-mode .scene-label {
  width: min(340px, calc(100% - 48px));
  padding: 12px 14px;
  background: rgba(3, 8, 13, 0.54);
  border-color: rgba(176, 198, 231, 0.18);
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.22);
}

body.network-mode .scene-label h1 {
  font-size: clamp(1.45rem, 2.45vw, 2.35rem);
}

body.network-mode .scene-label p {
  margin-top: 0.45rem;
  font-size: 0.82rem;
  line-height: 1.34;
}

body.network-mode .eyebrow {
  margin-bottom: 0.28rem;
  font-size: 0.66rem;
  color: rgba(184, 252, 244, 0.82);
}

.eyebrow,
.kicker {
  margin: 0 0 0.45rem;
  color: var(--cyan);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.scene-label h1,
.panel h2 {
  margin: 0;
  letter-spacing: 0;
}

.scene-label h1 {
  font-size: clamp(1.7rem, 3.2vw, 3.2rem);
  line-height: 0.98;
}

.scene-label p,
.panel p {
  color: var(--muted);
  line-height: 1.45;
}

.scene-label p:last-child {
  margin-bottom: 0;
}

.legend {
  position: absolute;
  left: 24px;
  bottom: 24px;
  display: flex;
  flex-wrap: wrap;
  gap: 0.85rem;
  max-width: calc(100% - 48px);
  padding: 10px 12px;
  border-radius: 8px;
  background: rgba(8, 17, 31, 0.68);
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.dot {
  width: 0.75rem;
  height: 0.75rem;
  border-radius: 50%;
  display: inline-block;
}

.dot.llm {
  background: var(--blue);
}

.dot.agent {
  background: var(--blue);
}

.dot.code {
  background: var(--orange);
}

.dot.artifact {
  background: var(--green);
}

.dot.state {
  background: var(--cyan);
}

.dot.feedback {
  background: var(--red);
}

body.network-mode .legend {
  background: rgba(3, 8, 13, 0.58);
  border-color: rgba(176, 198, 231, 0.18);
  font-size: 0.78rem;
}

body.network-mode .dot.agent {
  background: #e7ee97;
}

.panel {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  height: 100%;
  min-height: 0;
  padding: 22px;
  background: var(--panel);
}

.panel h2 {
  font-size: 1.45rem;
}

.panel p {
  margin: 0.6rem 0 0;
}

.pattern-list {
  display: grid;
  gap: 0.45rem;
  min-height: 0;
  overflow: auto;
  padding-right: 4px;
}

.pattern-list button {
  width: 100%;
  min-height: 2.7rem;
  padding: 0.65rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  cursor: pointer;
  text-align: left;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
}

.pattern-list button:hover,
.pattern-list button:focus {
  border-color: rgba(72, 226, 212, 0.55);
  background: rgba(72, 226, 212, 0.08);
  transform: translateY(-1px);
}

.pattern-list button.active {
  border-color: rgba(87, 166, 255, 0.9);
  background: rgba(87, 166, 255, 0.18);
}

.pattern-list small {
  display: block;
  margin-top: 0.15rem;
  color: var(--muted);
}

.controls {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.55rem;
  margin-top: auto;
}

.controls button {
  min-height: 2.5rem;
  border: 1px solid rgba(87, 166, 255, 0.55);
  border-radius: 8px;
  background: rgba(87, 166, 255, 0.12);
  color: var(--text);
  cursor: pointer;
}

.controls button:hover,
.controls button:focus {
  background: rgba(87, 166, 255, 0.24);
}

.notes {
  padding: 0.85rem;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--line);
  font-size: 0.88rem;
}

.notes p:first-child {
  margin-top: 0;
}

#pattern-warning:not(:empty) {
  color: #ffd38a;
}

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr) auto;
  }

  .panel {
    height: auto;
    max-height: 38vh;
    overflow: auto;
    padding: 14px;
  }

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

  .scene-label {
    top: 12px;
    left: 12px;
    width: calc(100% - 24px);
    padding: 12px 14px;
  }

  .scene-label h1 {
    font-size: 1.6rem;
  }

  body.network-mode .scene-label {
    width: min(320px, calc(100% - 24px));
  }

  body.network-mode .scene-label h1 {
    font-size: 1.45rem;
  }

  .legend {
    left: 12px;
    bottom: 12px;
    max-width: calc(100% - 24px);
  }
}

@media (max-height: 560px) and (min-width: 901px) {
  .scene-label {
    top: 18px;
    left: 18px;
    width: min(330px, calc(100% - 36px));
    padding: 12px 14px;
  }

  .scene-label h1 {
    font-size: 1.8rem;
    line-height: 1;
  }

  body.network-mode .scene-label h1 {
    font-size: 1.45rem;
  }

  .scene-label p {
    margin-top: 0.55rem;
    font-size: 0.82rem;
  }

  .panel {
    gap: 0.65rem;
    padding: 16px;
  }

  .panel h2 {
    font-size: 1.15rem;
  }

  .panel p {
    font-size: 0.82rem;
    line-height: 1.35;
  }

  .pattern-list {
    display: none;
  }

  .controls button {
    min-height: 2rem;
    font-size: 0.84rem;
  }

  .notes {
    padding: 0.7rem;
    font-size: 0.75rem;
  }

  .legend {
    left: 18px;
    bottom: 14px;
    padding: 8px 10px;
    font-size: 0.75rem;
  }
}
