/**
 * Island shell — collapsible CTA + spec viewer for live demos.
 *
 * Two states per island:
 *   - Closed: a single "Try it live" pill below the section heading.
 *   - Open:   a stage with a toolbar (Live · View spec · Hide), the live
 *             demo, and an optional side-by-side spec panel.
 *
 * The teaser keeps the page short; opening is opt-in. The spec panel
 * pairs the rendered output with the JSON it came from so the visitor
 * sees the framework's claim ("UI from JSON") with their own eyes.
 */

.island-shell {
  --shell-radius: 14px;
  --shell-border: rgba(255, 255, 255, 0.1);
  --shell-bg: rgba(20, 22, 28, 0.92);
  --shell-bg-soft: rgba(28, 30, 38, 0.85);
  --shell-gold: #d4af37;
  --shell-gold-soft: rgba(212, 175, 55, 0.18);
  --shell-spec-bg: #0d1117;
  --shell-spec-fg: #c9d1d9;

  position: relative;
  margin: 0 auto;
  max-width: 920px;
}

/* ---------- Closed state: CTA pill ---------- */

.island-shell__cta-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 28px 0 8px;
}

.island-shell__cta-meta {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.42);
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.island-shell__cta-meta::before,
.island-shell__cta-meta::after {
  content: '';
  width: 32px;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
}

.island-shell__cta-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 12px;
  padding: 16px 28px;
  background: linear-gradient(180deg, rgba(40, 42, 50, 0.95), rgba(20, 22, 28, 0.95));
  border: 1px solid rgba(212, 175, 55, 0.25);
  border-radius: 999px;
  color: #fff;
  font-family: inherit;
  font-size: 15px;
  font-weight: 500;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: transform 0.5s cubic-bezier(0.16, 1, 0.3, 1),
              border-color 0.3s,
              box-shadow 0.5s;
  box-shadow: 0 4px 24px -8px rgba(0, 0, 0, 0.6),
              inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.island-shell__cta-btn:hover {
  transform: translateY(-2px);
  border-color: rgba(212, 175, 55, 0.55);
  box-shadow: 0 14px 42px -12px rgba(212, 175, 55, 0.25),
              inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.island-shell__cta-btn:focus-visible {
  outline: 2px solid var(--shell-gold);
  outline-offset: 4px;
}

.island-shell__cta-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--shell-gold);
  box-shadow: 0 0 0 0 rgba(212, 175, 55, 0.6);
  animation: shell-pulse 2.4s cubic-bezier(0.4, 0, 0.6, 1) infinite;
  flex-shrink: 0;
}

@keyframes shell-pulse {
  0%, 100% {
    box-shadow: 0 0 0 0 rgba(212, 175, 55, 0.6);
    opacity: 1;
  }
  50% {
    box-shadow: 0 0 0 6px rgba(212, 175, 55, 0);
    opacity: 0.7;
  }
}

.island-shell__cta-arrow {
  font-family: 'JetBrains Mono', monospace;
  font-size: 16px;
  opacity: 0.6;
  transition: transform 0.3s, opacity 0.3s;
}

.island-shell__cta-btn:hover .island-shell__cta-arrow {
  transform: translateX(3px);
  opacity: 1;
}

.island-shell__cta-hint {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.4);
  letter-spacing: 0.02em;
}

/* ---------- Open state: stage ---------- */

.island-shell__stage {
  border: 1px solid var(--shell-border);
  border-radius: var(--shell-radius);
  overflow: hidden;
  background: var(--shell-bg);
  box-shadow: 0 18px 48px -16px rgba(0, 0, 0, 0.5);
  animation: shell-stage-in 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes shell-stage-in {
  from {
    opacity: 0;
    transform: translateY(-12px) scale(0.985);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.island-shell__toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 11px 16px;
  background: rgba(15, 16, 22, 0.95);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  flex-wrap: wrap;
}

.island-shell__live {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--shell-gold);
}

.island-shell__live-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--shell-gold);
  box-shadow: 0 0 8px rgba(212, 175, 55, 0.7);
  animation: shell-pulse 2.4s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

.island-shell__toolbar-actions {
  display: flex;
  gap: 8px;
}

.island-shell__btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 13px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 7px;
  color: rgba(255, 255, 255, 0.85);
  font-family: 'JetBrains Mono', monospace;
  font-size: 11.5px;
  font-weight: 500;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: all 0.2s ease;
}

.island-shell__btn:hover {
  background: rgba(255, 255, 255, 0.09);
  border-color: rgba(255, 255, 255, 0.2);
  color: #fff;
}

.island-shell__btn[aria-pressed='true'] {
  background: var(--shell-gold-soft);
  border-color: rgba(212, 175, 55, 0.45);
  color: var(--shell-gold);
}

.island-shell__btn-icon {
  font-size: 13px;
  line-height: 1;
}

/* Split: demo + optional spec panel */
.island-shell__split {
  display: grid;
  grid-template-columns: 1fr;
  background: transparent;
  min-height: 200px;
}

.island-shell__split[data-spec-open='true'] {
  grid-template-columns: 1fr;
}

@media (min-width: 1024px) {
  .island-shell__split[data-spec-open='true'] {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }
}

.island-shell__demo {
  padding: 24px 20px;
  background: transparent;
  min-width: 0;
  position: relative;
  transform: translate(0); /* CSS containing block for any inner position:fixed */
}

/* The DNA Playground is taller — give it room. */
.island-shell[data-shell='dna-playground'] .island-shell__demo,
.island-shell[data-shell='dna-playground-v2'] .island-shell__demo {
  min-height: 720px;
  padding: 0;
  background: transparent;
}

/* Viewport fullscreen — body class hides everything except the playground.
   Avoids `position: fixed` containing-block traps from transformed ancestors.
   ESC or the toggle button exits.

   Whitelist `[role="dialog"]` and `[role="listbox"]`: framework primitives
   (Modal, Select) portal to document.body via createPortal, so they appear as
   direct children of <body>. Without the exception, the hide-siblings rule
   would render their backdrops invisible while in fullscreen mode. */
body.mythik-playground-fullscreen > *:not(main):not([role="dialog"]):not([role="listbox"]):not(.mythik-inspect-badge-layer):not([role="complementary"]) { display: none !important; }
body.mythik-playground-fullscreen > main > *:not(#live-forge) { display: none !important; }
body.mythik-playground-fullscreen #live-forge {
  padding: 0 !important;
  margin: 0 !important;
  max-width: none !important;
}
body.mythik-playground-fullscreen #live-forge > .section-heading { display: none !important; }
body.mythik-playground-fullscreen #live-forge > .island-shell {
  max-width: none !important;
  margin: 0 !important;
}
body.mythik-playground-fullscreen #live-forge > .island-shell > .island-shell__demo {
  height: 100vh !important;
  max-height: 100vh !important;
  min-height: 100vh !important;
}

/* v2 playground — transparent split so the spec's LayerBackground
   (identity.background.color) paints the area, not the hardcoded chrome white. */
.island-shell[data-shell='dna-playground-v2'] .island-shell__split {
  background: transparent !important;
}

/* Random hero CTA — narrative call-to-action that owns its own row in the
   panel, between the preset chips and the utility toolbar. Until the user
   clicks Random at least once, a gold halo breathes around it; the
   randomize handler writes a localStorage flag mirrored as
   `body.mythik-random-tried` to kill the animation. Honors
   prefers-reduced-motion. */
@keyframes mythik-random-pulse-glow {
  0%, 100% {
    box-shadow:
      0 0 0 0 rgba(212, 175, 55, 0),
      0 2px 6px rgba(0, 0, 0, 0.18);
  }
  50% {
    box-shadow:
      0 0 0 10px rgba(212, 175, 55, 0.32),
      0 8px 22px rgba(212, 175, 55, 0.28);
  }
}
button.mythik-random-hero {
  padding: 16px 22px !important;
  font-size: 14.5px !important;
  font-weight: 600 !important;
  letter-spacing: 0.01em;
  line-height: 1.25;
  animation: mythik-random-pulse-glow 2.4s cubic-bezier(0.4, 0, 0.6, 1) infinite;
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), filter 0.25s;
}
button.mythik-random-hero:hover {
  transform: translateY(-2px);
  filter: brightness(1.08);
}
body.mythik-random-tried button.mythik-random-hero {
  animation: none;
}
@media (prefers-reduced-motion: reduce) {
  button.mythik-random-hero {
    animation: none;
  }
}

/* Editorial scrollbars — only inside v2 playground so v1 keeps default. */
.island-shell[data-shell='dna-playground-v2'] *::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
.island-shell[data-shell='dna-playground-v2'] *::-webkit-scrollbar-track {
  background: transparent;
}
.island-shell[data-shell='dna-playground-v2'] *::-webkit-scrollbar-thumb {
  background: rgba(212, 175, 55, 0.25);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
.island-shell[data-shell='dna-playground-v2'] *::-webkit-scrollbar-thumb:hover {
  background: rgba(212, 175, 55, 0.45);
  background-clip: padding-box;
}
.island-shell[data-shell='dna-playground-v2'] * {
  scrollbar-width: thin;
  scrollbar-color: rgba(212, 175, 55, 0.25) transparent;
}

.island-shell[data-shell='wiki-table'] .island-shell__demo {
  min-height: 480px;
}

.island-shell[data-shell='auto-skeleton'] .island-shell__demo,
.island-shell[data-shell='retheme'] .island-shell__demo,
.island-shell[data-shell='validation-gate'] .island-shell__demo {
  min-height: 320px;
}

/* ---------- Spec panel ---------- */

.island-shell__spec {
  display: flex;
  flex-direction: column;
  background: var(--shell-spec-bg);
  color: var(--shell-spec-fg);
  border-top: 1px solid rgba(0, 0, 0, 0.08);
  min-width: 0;
  min-height: 0;
  /* The pre child reports its full content height (~100k px for big specs);
   * overflow:hidden + height:0/min-height:100% stops that height from
   * contributing to the grid row, so the demo cell drives row height. */
  overflow: hidden;
}

/* Mobile (stacked): cap height so the spec doesn't blow out the page */
@media (max-width: 1023px) {
  .island-shell__spec {
    max-height: 70vh;
  }
}

/* Desktop (side-by-side): fill the grid cell so demo + spec match in height */
@media (min-width: 1024px) {
  .island-shell__spec {
    height: 0;
    min-height: 100%;
    border-top: none;
    border-left: 1px solid rgba(0, 0, 0, 0.08);
  }
}

.island-shell__spec-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 14px;
  background: #161b22;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  letter-spacing: 0.08em;
  color: rgba(255, 255, 255, 0.55);
}

.island-shell__spec-file {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.island-shell__spec-file::before {
  content: '{ }';
  color: var(--shell-gold);
  font-weight: 700;
}

.island-shell__copy {
  padding: 4px 10px;
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 5px;
  color: rgba(255, 255, 255, 0.65);
  font-family: 'JetBrains Mono', monospace;
  font-size: 10.5px;
  letter-spacing: 0.06em;
  cursor: pointer;
  transition: all 0.2s;
}

.island-shell__copy:hover {
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
  border-color: rgba(255, 255, 255, 0.2);
}

.island-shell__copy[data-copied='true'] {
  background: rgba(34, 197, 94, 0.15);
  border-color: rgba(34, 197, 94, 0.4);
  color: rgb(134, 239, 172);
}

.island-shell__spec-pre {
  flex: 1 1 auto;
  min-height: 0;
  margin: 0;
  padding: 16px 18px 22px;
  overflow: auto;
  white-space: pre;
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  line-height: 1.6;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.18) transparent;
}

.island-shell__spec-pre::-webkit-scrollbar {
  width: 9px;
  height: 9px;
}

.island-shell__spec-pre::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.16);
  border-radius: 6px;
}

.island-shell__spec-pre::-webkit-scrollbar-track {
  background: transparent;
}

/* JSON syntax highlight (using site's tok-* classes scoped to dark spec view) */
.island-shell__spec-pre .tok-prop { color: #79c0ff; font-weight: 500; }
.island-shell__spec-pre .tok-str  { color: #a5d6ff; }
.island-shell__spec-pre .tok-num  { color: #f2cc60; }
.island-shell__spec-pre .tok-key  { color: #ff7b72; font-weight: 500; }
.island-shell__spec-pre .tok-punct { color: #6e7681; }

.island-shell__spec-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.45);
  letter-spacing: 0.08em;
}

.island-shell__spec-summary {
  padding: 10px 18px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  color: rgba(255, 255, 255, 0.5);
  letter-spacing: 0.04em;
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
}

.island-shell__spec-summary strong {
  color: var(--shell-gold);
  font-weight: 600;
}

/* ---------- Mobile ---------- */

@media (max-width: 760px) {
  .island-shell {
    max-width: 100%;
  }

  .island-shell__cta-btn {
    padding: 14px 22px;
    font-size: 14px;
  }

  .island-shell__toolbar {
    padding: 10px 12px;
    gap: 10px;
  }

  .island-shell__btn {
    padding: 6px 10px;
    font-size: 11px;
  }

  .island-shell__demo {
    padding: 16px 12px;
  }

  .island-shell__spec-pre {
    font-size: 11.5px;
    padding: 12px 14px 18px;
  }

  .island-shell[data-shell='dna-playground'] .island-shell__demo,
  .island-shell[data-shell='dna-playground-v2'] .island-shell__demo {
    min-height: 600px;
  }
}

/* ---------- "Hide spec" label / mobile toolbar overflow ---------- */
@media (max-width: 480px) {
  .island-shell__btn-label {
    display: none;
  }
  .island-shell__btn {
    padding: 6px 9px;
  }
}

/* ---------- Pattern attribution (Karpathy LLM wiki credit) ---------- */
.retrieval-credit {
  margin-top: 18px;
  font-size: 12px;
  font-style: italic;
  opacity: 0.55;
  text-align: center;
  max-width: 720px;
  margin-left: auto;
  margin-right: auto;
  line-height: 1.55;
}

.retrieval-credit a {
  color: inherit;
  text-decoration: underline;
  text-decoration-color: rgba(212, 175, 55, 0.5);
  text-underline-offset: 3px;
}

.retrieval-credit a:hover {
  color: var(--shell-gold, #d4af37);
}

/* ===== Inspect Mode ===== */
/* Toggle state lives on body.mythik-inspect-mode, set by the
   toggleInspectMode action in islands.tsx. The body class is the
   single source of visual truth — all inspect-mode treatment keys
   off it. */

/* Subtle dashed outline on every renderable element under the demo
   while inspect is active. Outline-offset 1px so adjacent outlines
   don't visually collide when elements are tightly packed. */
body.mythik-inspect-mode .island-shell[data-shell='dna-playground-v2'] .island-shell__demo * {
  outline: 1px dashed rgba(212, 175, 55, 0.3);
  outline-offset: 1px;
  cursor: help;
}

/* Hover state — solid outline + brighter gold so the user can tell
   which element they're about to pin. */
body.mythik-inspect-mode .island-shell[data-shell='dna-playground-v2'] .island-shell__demo *:hover {
  outline-color: rgba(212, 175, 55, 0.8);
  outline-style: solid;
}

/* Element-id badges — attached as overlay elements by the chrome JS
   (Task 5). Class .mythik-inspect-badge is added to each badge node
   so styling stays in CSS, not inline. Badges sit absolutely
   positioned via translate(x, y) computed against window scroll. */
.mythik-inspect-badge {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
  z-index: 100;
  padding: 1px 5px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 9.5px;
  font-weight: 500;
  letter-spacing: 0.02em;
  color: #d4af37;
  background: rgba(10, 8, 6, 0.85);
  border: 1px solid rgba(212, 175, 55, 0.4);
  border-radius: 3px;
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.15s ease;
}

body.mythik-inspect-mode .mythik-inspect-badge {
  opacity: 1;
}

/* When viewport-fullscreen + inspect modes coexist, the badge layer
   (a body-level container) stays visible. The hide-siblings rule
   already whitelists `.mythik-inspect-badge-layer` and `[role="complementary"]`. */
body.mythik-playground-fullscreen.mythik-inspect-mode .mythik-inspect-badge-layer {
  display: block !important;
}

/* Inspect Mode — control highlight (transient gold glow when navigated to). */
@keyframes mythik-inspect-highlight-pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(212, 175, 55, 0.5),
                0 0 0 0 rgba(212, 175, 55, 0);
  }
  50% {
    box-shadow: 0 0 0 8px rgba(212, 175, 55, 0.4),
                0 0 24px 4px rgba(212, 175, 55, 0.3);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(212, 175, 55, 0),
                0 0 0 0 rgba(212, 175, 55, 0);
  }
}
/* Wrapper carries the class (stable across React re-renders). The actual
   visual glow falls on the rendered primitive — first child of the
   `display: contents` wrapper. */
.mythik-inspect-highlight > *:first-child {
  animation: mythik-inspect-highlight-pulse 1.5s ease-out;
  border-radius: 6px;
}
