/* === Reset & Custom Properties === */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --site-bg: #fafaf9;
  --site-bg-alt: #f3f3f1;
  --site-text: #1a1a1a;
  --site-text-muted: #6b7280;
  --site-accent: #2563eb;
  --site-accent-hover: #1d4ed8;
  --site-font: system-ui, -apple-system, 'Segoe UI', sans-serif;
  --site-code-font: 'SF Mono', 'Fira Code', 'Fira Mono', 'Menlo', monospace;
  --site-radius: 0.5rem;
  --site-density: 1;
  --site-header-height: 3.25rem;
  --site-surface: #ffffff;
  --site-border: rgba(0,0,0,0.1);

  /* Tab style variants (default: pills) */
  --tab-bg: transparent;
  --tab-bg-active: var(--site-accent);
  --tab-color: var(--site-text-muted);
  --tab-color-active: #fff;
  --tab-radius: 999px;
  --tab-border-bottom: none;
}

body {
  font-family: var(--site-font);
  color: var(--site-text);
  background: var(--site-bg);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h2 {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 0.75rem;
}

h3 {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
}

p { line-height: 1.6; }

a { color: var(--site-accent); text-decoration: none; }
a:hover { text-decoration: underline; }

button { cursor: pointer; font-family: inherit; }

select {
  font-family: inherit;
  font-size: 0.8rem;
  padding: 0.25rem 0.5rem;
  border: 1px solid var(--site-border);
  border-radius: var(--site-radius);
  background: var(--site-surface);
  color: var(--site-text);
}

label {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--site-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

pre {
  background: #1a1a1a;
  color: #e5e5e5;
  padding: 1.25rem;
  border-radius: var(--site-radius);
  overflow-x: auto;
  font-family: var(--site-code-font);
  font-size: 0.8rem;
  line-height: 1.6;
}

code {
  font-family: var(--site-code-font);
}

.section-subtitle {
  color: var(--site-text-muted);
  margin-bottom: 1.5rem;
}

/* === Sticky Header (appears on scroll) === */
.site-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  background: var(--site-bg);
  border-bottom: 1px solid var(--site-border);
  transform: translateY(-100%);
  transition: transform 0.25s ease;
}

.site-header.visible {
  transform: translateY(0);
}

.header-inner {
  max-width: 860px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 1.5rem;
}

.header-logo {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 1rem;
  font-weight: 700;
  color: var(--site-text);
  text-decoration: none;
}

.header-logo:hover { text-decoration: none; }

.header-logo svg {
  width: 1.2em;
  height: 1.2em;
}

.header-github {
  color: var(--site-text);
  display: flex;
  align-items: center;
}

.header-github svg {
  width: 1.25rem;
  height: 1.25rem;
}

.header-github:hover { opacity: 0.7; }

/* === Hero === */
.hero {
  max-width: 640px;
  margin: 0 auto;
  padding: 4rem 1.5rem 2.5rem;
  text-align: center;
}

.hero-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.hero-logo svg {
  width: 2.5rem;
  height: 2.5rem;
  color: var(--site-text);
}

.hero-logo h1 {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1;
}

.hero p {
  font-size: 1rem;
  color: var(--site-text-muted);
  line-height: 1.6;
}

.hero-link {
  color: var(--site-text-muted);
  text-decoration: underline;
  text-decoration-style: dashed;
  text-underline-offset: 0.2em;
  text-decoration-color: var(--site-border);
  cursor: pointer;
  transition: text-decoration-color 0.15s;
}

.hero-link:hover {
  text-decoration-color: var(--site-accent);
  color: var(--site-text);
}

/* === Sections === */
.editor-section {
  padding: 0 1.5rem 3rem;
}

.faq-section {
  max-width: 720px;
  margin: 0 auto;
  padding: 3rem 1.5rem;
  border-top: 1px solid var(--site-border);
}

/* === Footer === */
.site-footer {
  max-width: 720px;
  margin: 0 auto;
  padding: 2rem 1.5rem 4rem;
  border-top: 1px solid var(--site-border);
  text-align: center;
}

.site-footer p {
  font-size: 0.85rem;
  color: var(--site-text-muted);
}

.site-footer a {
  color: var(--site-accent);
}

/* === Playground === */
.playground {
  display: flex;
  flex-direction: column;
}

.playground-container {
  display: flex;
  width: 100%;
  justify-content: center;
  align-items: flex-start;
}

.playground-container::before {
  content: "";
  width: 2.5rem;
  flex-shrink: 0;
}

/* --- Cards --- */
.playground-card {
  background: var(--site-surface);
  border: 1px solid var(--site-border);
  border-radius: var(--site-radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.playground.preview-open .playground-preview {
  margin-left: 0.5rem;
}

/* --- Editor --- */
.playground-editor {
  flex: 0 1 730px;
  min-width: 8rem;
  max-width: 730px;
  transition: flex 0.35s ease;
}

/* --- Editor chrome (non-editable HTML context) --- */
.editor-chrome {
  font-family: var(--site-code-font);
  font-size: 0.75rem;
  line-height: 1.5;
  color: var(--site-text-muted);
  padding: 0.35rem 0.75rem 0.35rem calc(3rem + 0.75rem);
  white-space: pre;
  overflow: hidden;
  flex-shrink: 0;
  opacity: 0.7;
  cursor: pointer;
}

#editor-chrome-top {
  border-bottom: 1px dashed var(--site-border);
}

#editor-chrome-top .chrome-detail {
  display: none;
}

#editor-chrome-top.expanded {
  overflow-x: auto;
}

#editor-chrome-top.expanded .chrome-detail {
  display: inline;
}

#editor-chrome-top {
  position: relative;
}

.chrome-copy-btn {
  position: absolute;
  right: 0.5rem;
  top: 0.35rem;
  background: none;
  border: none;
  color: var(--site-text-muted);
  opacity: 0.5;
  cursor: pointer;
  padding: 0.2rem;
  border-radius: 0.25rem;
  transition: all 0.15s;
  display: flex;
}

.chrome-copy-btn:hover {
  opacity: 1;
  background: var(--site-bg-alt);
}

.chrome-copy-btn.copied {
  color: #16a34a;
  opacity: 1;
}

.chrome-copy-btn svg {
  width: 0.85rem;
  height: 0.85rem;
}

#editor-chrome-bottom {
  border-top: 1px dashed var(--site-border);
}

.editor-wrap {
  display: flex;
  overflow: hidden;
  max-height: 28rem;
  position: relative;
}

/* 80-character ruler */
.editor-ruler {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 0;
  border-right: 1px dotted var(--site-border);
  pointer-events: none;
  z-index: 1;
}

.line-numbers {
  width: 3rem;
  padding: 0.75rem 0.5rem 0.75rem 0;
  text-align: right;
  font-family: var(--site-code-font);
  font-size: 0.8rem;
  line-height: 1.5;
  color: var(--site-text-muted);
  opacity: 0.5;
  background: var(--site-bg-alt);
  overflow: hidden;
  user-select: none;
  flex-shrink: 0;
  border-right: 1px solid var(--site-border);
  transition: font-size 0.35s ease, width 0.35s ease, padding 0.35s ease;
}

#editor {
  flex: 1;
  border: none;
  outline: none;
  resize: none;
  padding: 0.75rem;
  min-height: 20rem;
  field-sizing: content;
  font-family: var(--site-code-font);
  font-size: 0.8rem;
  line-height: 1.5;
  background: var(--site-surface);
  color: var(--site-text);
  tab-size: 2;
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: break-word;
  overflow-x: hidden;
  transition: font-size 0.35s ease, padding 0.35s ease;
}

/* Editor minimized (when preview is open) */
.playground.preview-open .playground-editor {
  flex: 0 0 22rem;
  max-width: 22rem;
}

.playground.preview-open .line-numbers {
  font-size: 0.7rem;
  line-height: 1.4;
  width: 2.25rem;
  padding: 0.5rem 0.3rem 0.5rem 0;
}

.playground.preview-open #editor {
  font-size: 0.7rem;
  line-height: 1.4;
  padding: 0.5rem 0.6rem;
}

.playground.preview-open .editor-ruler {
  display: none;
}


/* --- Preview (hidden by default) --- */
.playground-preview {
  flex: 0 0 0;
  min-width: 0;
  height: 0;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
  border-color: transparent;
  transition: flex 0.35s ease, height 0.35s ease, opacity 0.25s ease, border-color 0.25s ease, pointer-events 0s 0.35s;
}

.playground.preview-open .playground-preview {
  flex: 1.2 0 0;
  height: auto;
  opacity: 1;
  pointer-events: auto;
  border-color: var(--site-border);
  transition: flex 0.35s ease, opacity 0.25s ease 0.1s, border-color 0.25s ease, pointer-events 0s;
}

.preview-controls {
  padding: 0.4rem 2.25rem 0.4rem 0.75rem;
  border-bottom: 1px solid var(--site-border);
  display: flex;
  align-items: center;
  gap: 0.35rem 0.75rem;
  flex-shrink: 0;
  flex-wrap: wrap;
  position: relative;
}

.controls-group {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.edit-inline-label {
  font-size: 0.75rem;
  color: var(--site-accent);
  visibility: hidden;
  margin-left: auto;
}

.preview-edit-btn.active svg {
  stroke: var(--tab-color-active);
}

/* Show label when edit mode is active — toggled via JS */
.playground.edit-mode .edit-inline-label {
  visibility: visible;
}

/* Accent border on preview card in edit mode */
.playground.edit-mode .playground-preview {
  border-color: var(--site-accent);
  box-shadow: 0 0 0 1px var(--site-accent);
}

.preview-controls label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--site-text-muted);
}

.preview-controls select {
  font-size: 0.85rem;
}

.preview-edit-btn {
  position: absolute;
  top: 0.4rem;
  right: 0.5rem;
  background: none;
  border: 1px solid var(--site-border);
  border-radius: 0.3rem;
  color: var(--site-text-muted);
  cursor: pointer;
  padding: 0.2rem;
  display: flex;
  transition: all 0.15s;
}

.preview-edit-btn svg {
  width: 0.85rem;
  height: 0.85rem;
}

.preview-edit-btn:hover {
  border-color: var(--site-accent);
  color: var(--site-accent);
}

.preview-edit-btn.active {
  background: var(--site-accent);
  color: var(--tab-color-active);
  border-color: var(--site-accent);
}

.preview-edit-btn.active svg {
  stroke: var(--tab-color-active);
}

.preview-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
}

#playground-recipe {
  --kr-card-padding: 1.5rem;
}


/* --- Toolbar (flex sibling, sits next to cards) --- */
.playground-toolbar {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  align-self: flex-start;
  flex-shrink: 0;
  margin-left: 0.5rem;
}

.toolbar-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border: 1px solid var(--site-border);
  border-radius: 0.4rem;
  background: var(--site-surface);
  color: var(--site-text-muted);
  cursor: pointer;
  transition: all 0.15s;
}

.toolbar-btn svg {
  width: 0.85rem;
  height: 0.85rem;
}

.toolbar-btn:hover {
  border-color: var(--site-accent);
  color: var(--site-accent);
}

.toolbar-btn.active {
  background: var(--site-accent);
  color: var(--tab-color-active);
  border-color: var(--site-accent);
}

.toolbar-btn.active svg {
  stroke: var(--tab-color-active);
  fill: none;
}

.toolbar-btn[hidden] {
  display: none;
}

.toolbar-btn.hint {
  animation: toolbar-hint 2s ease-in-out infinite;
}

@keyframes toolbar-hint {
  0%, 100% { border-color: var(--site-border); color: var(--site-text-muted); }
  50% { border-color: var(--site-accent); color: var(--site-accent); }
}

/* === Segmented controls (units) === */

.segmented {
  display: flex;
  border: 1px solid var(--site-border);
  border-radius: var(--site-radius);
  overflow: hidden;
}

.seg-btn {
  padding: 0.2rem 0.5rem;
  font-size: 0.85rem;
  font-weight: 500;
  border: none;
  border-right: 1px solid var(--site-border);
  background: var(--site-surface);
  color: var(--site-text-muted);
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.seg-btn:last-child {
  border-right: none;
}

.seg-btn:hover {
  color: var(--site-text);
}

.seg-btn.active {
  background: var(--site-accent);
  color: var(--tab-color-active);
}

/* === FAQ === */
.faq-list {
  max-width: 720px;
}

.faq-list details {
  border-bottom: 1px solid var(--site-border);
}

.faq-list summary {
  padding: 1rem 0;
  font-weight: 600;
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.faq-list summary::after {
  content: '+';
  font-size: 1.25rem;
  font-weight: 400;
  color: var(--site-text-muted);
  flex-shrink: 0;
  transition: transform 0.2s;
}

.faq-list details[open] summary::after {
  content: '−';
}

.faq-list summary::-webkit-details-marker { display: none; }

.faq-answer {
  padding: 0 0 1rem;
  color: var(--site-text-muted);
  line-height: 1.7;
}

.faq-answer code {
  background: var(--site-bg-alt);
  padding: 0.15em 0.35em;
  border-radius: 3px;
  font-size: 0.85em;
}

/* === Get Started === */
.get-started-section {
  max-width: 720px;
  margin: 0 auto;
  padding: 3rem 1.5rem;
  border-top: 1px solid var(--site-border);
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.agent-box, .quickstart-box, .install-box {
  padding: 1.5rem;
  border: 1px solid var(--site-border);
  border-radius: var(--site-radius);
  background: var(--site-surface);
}

.agent-box p {
  color: var(--site-text-muted);
  margin-bottom: 0.75rem;
}

.copy-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--site-bg-alt);
  border: 1px solid var(--site-border);
  border-radius: var(--site-radius);
  padding: 0.6rem 0.75rem;
  gap: 0.75rem;
}

.copy-box code {
  font-size: 0.85rem;
  word-break: break-all;
}

.copy-btn {
  flex-shrink: 0;
  background: none;
  border: none;
  color: var(--site-text-muted);
  padding: 0.25rem;
  border-radius: 4px;
  transition: all 0.15s;
}

.copy-btn:hover {
  color: var(--site-accent);
  background: rgba(0,0,0,0.05);
}

.copy-btn svg {
  width: 1rem;
  height: 1rem;
}

.copy-btn.copied {
  color: #16a34a;
}

.install-box p, .quickstart-box p {
  color: var(--site-text-muted);
  margin-bottom: 0.75rem;
}

.github-link {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--site-accent);
  font-weight: 500;
  text-decoration: none;
}

.github-link:hover {
  text-decoration: underline;
}

.github-link svg {
  width: 1.1rem;
  height: 1.1rem;
}

/* === Responsive === */

/* Mobile-only elements: hidden on desktop */
.mobile-next-recipe,
.mobile-flip-btn {
  display: none;
}

@media (max-width: 768px) {
  .hero {
    padding: 2.5rem 1rem 2rem;
  }

  .hero h1 {
    font-size: 1.5rem;
  }

  .editor-section {
    padding: 0 0 2rem;
  }

  /* Hide toolbar and counterweight */
  .playground-toolbar,
  .playground-container::before {
    display: none;
  }

  .playground {
    position: relative;
  }

  .playground-container {
    position: relative;
    height: 65vh;
    min-height: 22rem;
    max-height: 40rem;
    overflow: hidden;
    clip-path: inset(0);
  }

  /* Both cards fill the container */
  .playground-card {
    position: absolute;
    inset: 0;
    border-radius: 0;
    border-left: none;
    border-right: none;
    max-width: none;
  }

  /* --- Editor (front face, in place) --- */
  .playground-editor {
    flex: none;
  }

  .editor-chrome {
    display: none;
  }

  .editor-wrap {
    max-height: none;
    flex: 1;
  }

  .playground-editor .line-numbers {
    font-size: 0.65rem;
    line-height: 1.35;
    width: 2rem;
    padding: 0.4rem 0.2rem 0.4rem 0;
  }

  #editor {
    font-size: 0.65rem;
    line-height: 1.35;
    padding: 0.4rem 0.5rem;
    min-height: 0;
  }

  .editor-ruler {
    display: none;
  }

  /* --- Preview: hidden until slide-in triggered --- */
  .playground-preview {
    border-left: none;
    border-right: none;
  }

  /* Slide in from right via keyframes */
  @keyframes mobile-slide-in {
    from { transform: translateX(100%); }
    to { transform: translateX(0); }
  }

  .playground.preview-open .playground-preview {
    flex: none !important;
    height: auto !important;
    opacity: 1 !important;
    pointer-events: auto !important;
    border-color: var(--site-border) !important;
    margin-left: 0;
    animation: mobile-slide-in 1.2s ease-in-out both !important;
    transition: none !important;
  }

  .playground.preview-open .playground-editor {
    flex: none;
    max-width: none;
  }

  /* --- Mobile flip button (centered over editor, one-shot) --- */
  .mobile-flip-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 10;
    width: 3.5rem;
    height: 3.5rem;
    border-radius: 50%;
    border: none;
    background: var(--site-accent);
    color: var(--tab-color-active);
    cursor: pointer;
    box-shadow: 0 2px 12px rgba(0,0,0,0.3);
  }

  .mobile-flip-btn svg {
    width: 1.5rem;
    height: 1.5rem;
  }

  .playground.preview-open .mobile-flip-btn {
    display: none;
  }

  /* --- After slide: release into natural flow --- */
  .playground.flip-done .playground-container {
    height: auto;
    max-height: none;
    min-height: 0;
    overflow: visible;
  }

  .playground.flip-done .playground-editor {
    display: none;
  }

  .playground.flip-done .playground-preview {
    position: static;
    transform: none;
    visibility: visible;
    width: 100%;
    border-top: 1px solid var(--site-border);
  }

  .playground.flip-done .preview-scroll {
    overflow: visible;
  }

  /* Hide desktop-only controls */
  .edit-inline-label,
  .preview-edit-btn,
  #layout-control,
  #layout-control + .controls-spacer {
    display: none;
  }

  .controls-group:has(#layout-control) {
    display: none;
  }

  /* Show mobile next-recipe button */
  .mobile-next-recipe {
    display: block;
    margin-left: auto;
  }

  .faq-section {
    padding: 2rem 1rem;
  }
}

@media (max-width: 480px) {
  .header-inner {
    padding: 0.5rem;
  }

  .header-logo span {
    display: none;
  }
}

