/* Playground chrome — built on the theStacc design system.
 * Source of truth: blogfronend/DESIGN_SYSTEM.md
 * Light mode only. Nothing below 14px except deliberate chrome (§3.4). */

:root {
  /* text */
  --ink:        #1c1c1d;
  --ink-2:      #5b5b64;
  --ink-3:      #66666f;
  --brand:      #615fff;
  --brand-strong: #543EE6;

  /* surfaces */
  --page:       #ffffff;
  --panel:      #fafafa;
  --active:     rgba(0, 0, 23, .04);
  --hover:      rgba(0, 0, 23, .03);
  --brand-tint: rgba(97, 95, 255, .10);

  /* lines */
  --line:       rgba(0, 0, 29, .08);
  --line-soft:  rgba(0, 0, 29, .06);

  /* shadows */
  --sh-sm:    0 2px 4px rgba(0,0,0,.04), 0 0 1px rgba(0,0,0,.4);
  --sh-input: 0 1px 3px rgba(0,0,0,.08), 0 0 0 1px rgba(0,0,0,.04);
  --sh-focus: 0 1px 3px rgba(0,0,0,.12), 0 0 0 1px rgba(0,0,0,.08);
  --sh-md:    0 4px 16px rgba(0,0,0,.12), 0 0 1px rgba(0,0,0,.2);
  --sh-lg:    0 8px 32px rgba(0,0,0,.16);

  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --mono: 'Geist Mono', ui-monospace, 'SF Mono', monospace;
  --ease: cubic-bezier(.23, 1, .32, 1);
}

* { box-sizing: border-box; }

html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-weight: 500;
  font-size: 14px;
  line-height: 20px;
  color: var(--ink);
  background: #eceaf5;
  -webkit-font-smoothing: antialiased;
}

/* type scale (DESIGN_SYSTEM.md §3.2) */
.ds-page-title    { font: 600 18px/26px var(--font); color: var(--ink); margin: 0; }
.ds-section-title { font: 600 16px/22px var(--mono); color: var(--ink-3); margin: 0; }
.ds-label         { font: 600 14px/20px var(--font); color: var(--ink-3); }
.ds-body          { font: 500 14px/20px var(--font); color: var(--ink); }
.ds-secondary     { font: 500 14px/20px var(--font); color: var(--ink-3); margin: 0; }
.ds-small         { font: 500 14px/20px var(--font); color: var(--ink-2); }
.ds-stat          { font: 600 22px/28px var(--mono); color: var(--ink); }
.muted  { color: var(--ink-3); }
.center { text-align: center; }
.hidden { display: none !important; }

.ic { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.75;
      stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ── app shell ──────────────────────────────────────────────────── */

.app {
  position: fixed; inset: 0;
  background: var(--page);
  display: flex; flex-direction: column;
  overflow: hidden;
}

.app-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; border-bottom: 1px solid var(--line); flex: none;
}
.app-id { display: flex; align-items: center; gap: 10px; }
.mark {
  width: 22px; height: 22px; border-radius: 999px; flex: none;
  background:
    radial-gradient(circle at 32% 30%, var(--brand) 0 42%, transparent 43%),
    radial-gradient(circle at 70% 68%, var(--brand-strong) 0 34%, transparent 35%),
    radial-gradient(circle at 30% 74%, var(--ink) 0 26%, transparent 27%);
}
.app-name { font-weight: 600; font-size: 16px; letter-spacing: -.01em; }
.app-bar-right { display: flex; align-items: center; gap: 8px; }

.icon-btn {
  display: grid; place-items: center; width: 32px; height: 32px;
  border: 0; border-radius: 10px; background: transparent; color: var(--ink-3);
  cursor: pointer; font-size: 15px; font-family: var(--font);
  transition: background 160ms var(--ease), color 160ms var(--ease);
}
.icon-btn:hover { background: var(--active); color: var(--ink); }
.icon-btn:active { transform: scale(.97); }

/* grid-template-rows must be an explicit minmax(0,1fr): an implicit `auto` row
 * sizes to content, which pushes the composer out of the clipped shell. */
.app-body {
  flex: 1; min-height: 0;
  display: grid;
  grid-template-columns: 380px minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
}
/* Single column when the chat is hidden — a 0-width first column would swallow
 * the preview, because display:none removes .chat from grid flow entirely. */
.app-body.wide { grid-template-columns: minmax(0, 1fr); }
.app-body.wide .chat { display: none; }

/* ── chat ───────────────────────────────────────────────────────── */

.chat {
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column; min-height: 0; background: var(--page);
}
.chat-tools { display: flex; gap: 2px; padding: 10px 12px 4px; }

.chat-log {
  flex: 1; overflow-y: auto; padding: 8px 18px 4px;
  display: flex; flex-direction: column; gap: 14px; scroll-behavior: smooth;
}

.msg { max-width: 88%; }
.msg-a { align-self: flex-start; }
.msg-u { align-self: flex-end; }

.bubble {
  padding: 12px 14px; border-radius: 14px;
  font-size: 14px; line-height: 21px; font-weight: 500;
  animation: rise 250ms var(--ease) both;
}
.msg-a .bubble { background: var(--active); color: var(--ink); border-bottom-left-radius: 6px; }
.msg-u .bubble { background: var(--ink); color: #fff; border-bottom-right-radius: 6px; }
.bubble strong { font-weight: 600; }
.bubble code {
  font-family: var(--mono); font-size: 13px;
  background: rgba(0,0,23,.06); padding: 1px 5px; border-radius: 5px;
}
.msg-u .bubble code { background: rgba(255,255,255,.16); }
.bubble ol, .bubble ul { margin: 8px 0 0; padding-left: 20px; }
.bubble li { margin: 3px 0; }
.bubble p { margin: 0 0 8px; }
.bubble p:last-child { margin-bottom: 0; }

@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.typing { display: flex; gap: 4px; padding: 14px; }
.typing i {
  width: 6px; height: 6px; border-radius: 999px; background: var(--ink-3);
  display: block; animation: blink 1.2s ease-in-out infinite;
}
.typing i:nth-child(2) { animation-delay: .18s; }
.typing i:nth-child(3) { animation-delay: .36s; }
@keyframes blink { 0%,60%,100% { opacity: .25; } 30% { opacity: 1; } }

.chat-foot { flex: none; padding: 10px 18px 14px; border-top: 1px solid var(--line-soft); }

/* One scrolling row, not a wrapping block — eight wrapped chips cost ~220px of
 * vertical space and starve the conversation on a laptop viewport. */
.chips {
  display: flex; gap: 6px; margin-bottom: 10px;
  overflow-x: auto; overscroll-behavior-x: contain; padding-bottom: 4px;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  border: 0; border-radius: 999px; padding: 7px 12px; flex: none; white-space: nowrap;
  background: var(--brand-tint); color: var(--brand-strong);
  font: 500 14px/18px var(--font); cursor: pointer;
  transition: background 160ms var(--ease), transform 160ms var(--ease);
}
.chip:hover { background: rgba(97,95,255,.16); }
.chip:active { transform: scale(.97); }

.composer { display: flex; align-items: center; gap: 8px;
  border-radius: 12px; padding: 8px 8px 8px 14px; box-shadow: var(--sh-input); }
.composer:focus-within { box-shadow: var(--sh-focus); }
.composer input {
  flex: 1; border: 0; outline: 0; background: transparent;
  font: 500 14px/20px var(--font); color: var(--ink); padding: 6px 0;
}
.composer input::placeholder { color: var(--ink-3); }
.send {
  width: 32px; height: 32px; border: 0; border-radius: 10px; cursor: pointer;
  background: var(--ink); color: #fff; display: grid; place-items: center;
  transition: opacity 160ms var(--ease);
}
.send:active { transform: scale(.97); }
.chat-foot .ds-small { margin: 10px 0 0; font-size: 12px; line-height: 16px; }

/* ── preview ────────────────────────────────────────────────────── */

.preview { position: relative; display: flex; flex-direction: column;
  min-width: 0; background: var(--panel); }

.pv-bar {
  flex: none; display: flex; align-items: center; gap: 10px;
  padding: 12px 16px; border-bottom: 1px solid var(--line); background: var(--page);
}
.pv-menu-wrap { position: relative; }
.pv-select {
  display: flex; align-items: center; gap: 8px; white-space: nowrap;
  padding: 8px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--page); color: var(--ink); font: 500 14px/20px var(--font);
  cursor: pointer; transition: background 160ms var(--ease);
}
.pv-select:hover { background: var(--hover); }
.pv-select .caret { width: 16px; height: 16px; color: var(--ink-3); }

.pv-menu {
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 30; width: 280px;
  background: var(--page); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: var(--sh-md); padding: 6px; display: grid; gap: 2px;
}
.pv-menu button {
  display: block; width: 100%; text-align: left; border: 0; cursor: pointer;
  background: transparent; border-radius: 8px; padding: 9px 10px;
  font: 500 14px/18px var(--font); color: var(--ink);
  transition: background 160ms var(--ease);
}
.pv-menu button:hover { background: var(--active); }
.pv-menu button.is-on { background: #f6f5fe; color: var(--brand-strong); font-weight: 600; }
.pv-menu small { display: block; font-weight: 500; font-size: 12px; line-height: 16px; color: var(--ink-3); }
.pv-menu button.is-on small { color: var(--brand-strong); opacity: .75; }
.pv-menu.wide-menu { width: 380px; max-height: 60vh; overflow-y: auto; }
.pv-menu .menu-head {
  font: 600 12px/16px var(--mono); letter-spacing: .08em; text-transform: uppercase;
  color: var(--ink-3); padding: 10px 10px 6px; position: sticky; top: -6px;
  background: var(--page);
}
.pv-menu .path { font-family: var(--mono); font-size: 13px; }
.pv-select .dot {
  width: 8px; height: 8px; border-radius: 999px; background: var(--brand); flex: none;
}
.pv-select.route #pageName { font-family: var(--mono); }
.route-count {
  font: 500 12px/16px var(--mono); color: var(--ink-3);
  background: var(--active); border-radius: 999px; padding: 2px 7px;
}

.ghost-link {
  font: 500 14px/20px var(--font); color: var(--brand-strong); text-decoration: none;
  padding: 6px 10px; border-radius: 10px; transition: background 160ms var(--ease);
}
.ghost-link:hover { background: #f6f5fe; }

/* ── hover explainers ───────────────────────────────────────────── */

.help {
  width: 16px; height: 16px; border-radius: 999px; flex: none; cursor: help;
  display: inline-grid; place-items: center; background: var(--active); color: var(--ink-3);
  font: 600 11px/1 var(--font); position: relative;
  transition: background 160ms var(--ease), color 160ms var(--ease);
}
.help::after { content: '?'; }
.help:hover, .help:focus-visible { background: var(--brand); color: #fff; outline: none; }
.help.on-dark { background: rgba(0,0,23,.06); }

.tip {
  position: fixed; z-index: 90; max-width: 320px; pointer-events: none;
  background: var(--ink); color: #fff; border-radius: 10px; padding: 10px 12px;
  font: 500 13px/19px var(--font); box-shadow: var(--sh-md);
  opacity: 0; transform: translateY(4px); transition: opacity 160ms var(--ease), transform 160ms var(--ease);
}
.tip.on { opacity: 1; transform: none; }
.tip strong { font-weight: 600; }

/* ── routes pane ────────────────────────────────────────────────── */

.routes { display: grid; gap: 2px; }
.route-row {
  display: grid; grid-template-columns: 1fr auto auto; gap: 12px; align-items: center;
  padding: 9px 10px; border-radius: 8px; cursor: pointer; border: 0; background: transparent;
  text-align: left; font: 500 14px/20px var(--font); color: var(--ink);
  transition: background 160ms var(--ease);
}
.route-row:hover { background: var(--active); }
.route-row.is-on { background: #f6f5fe; }
.route-row .p { font-family: var(--mono); font-size: 13px; overflow: hidden; text-overflow: ellipsis; }
.route-row.is-on .p { color: var(--brand-strong); font-weight: 600; }
.route-row .blocks { font: 500 12px/16px var(--mono); color: var(--ink-3); }
.kind {
  font: 500 12px/16px var(--font); border-radius: 999px; padding: 2px 8px; white-space: nowrap;
}
.kind-static       { background: var(--active); color: var(--ink-2); }
.kind-collection,
.kind-collection-item { background: #eef7f1; color: #1a7f4b; }
.kind-programmatic { background: #f6f5fe; color: var(--brand-strong); }

.seg { display: flex; gap: 2px; padding: 3px; border-radius: 10px; background: var(--active); }
.seg.pill { margin-left: auto; }
.seg-btn {
  border: 0; background: transparent; cursor: pointer; border-radius: 8px;
  padding: 6px 12px; color: var(--ink-3); font: 500 14px/18px var(--font);
  display: grid; place-items: center;
  transition: background 160ms var(--ease), color 160ms var(--ease);
}
.seg-btn:hover { color: var(--ink); }
.seg-btn.is-on { background: var(--page); color: var(--ink); box-shadow: var(--sh-sm); }

.pv-stage { flex: 1; overflow-y: auto; padding: 20px; display: flex; justify-content: center; }
.frame {
  width: 100%; background: #fff; border-radius: 12px; overflow: hidden;
  box-shadow: var(--sh-sm); height: max-content;
  transition: width 250ms var(--ease);
}
.frame[data-device="tablet"] { width: 834px; max-width: 100%; }
.frame[data-device="mobile"] { width: 390px; max-width: 100%; }

/* edit mode — expose the structure the model actually wrote */
.sect-wrap { position: relative; }
.edit .sect-wrap { outline: 1px dashed rgba(97,95,255,.5); outline-offset: -1px; }
.edit .sect-wrap:hover { outline: 2px solid var(--brand); outline-offset: -2px; }
.sect-tag { display: none; }
.edit .sect-tag {
  display: inline-flex; align-items: center; gap: 6px;
  position: absolute; top: 6px; left: 6px; z-index: 30;
  background: var(--brand); color: #fff; border-radius: 6px;
  padding: 3px 7px; font: 500 12px/14px var(--mono); letter-spacing: .01em;
  opacity: .85; pointer-events: none;
}

.site-manager {
  position: absolute; right: 20px; bottom: 20px; z-index: 20;
  display: flex; align-items: center; gap: 8px;
  padding: 10px 14px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--page); color: var(--ink); font: 500 14px/20px var(--font);
  box-shadow: var(--sh-md); cursor: pointer;
  transition: transform 160ms var(--ease);
}
.site-manager:hover { transform: translateY(-1px); }
.site-manager:active { transform: scale(.98); }

/* ── drawer ─────────────────────────────────────────────────────── */

.scrim {
  position: fixed; inset: 0; background: rgba(0,0,23,.28); z-index: 40;
  opacity: 0; pointer-events: none; transition: opacity 200ms var(--ease);
}
.scrim.on { opacity: 1; pointer-events: auto; }

.drawer {
  position: fixed; top: 20px; right: 20px; bottom: 20px; width: min(660px, calc(100vw - 40px));
  background: var(--page); border-radius: 16px; box-shadow: var(--sh-lg);
  z-index: 50; display: flex; flex-direction: column;
  transform: translateX(calc(100% + 28px));
  transition: transform 250ms var(--ease);
}
.drawer.on { transform: none; }
.drawer-bar {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 16px; padding: 18px 20px 14px; border-bottom: 1px solid var(--line); flex: none;
}
.drawer-tabs { display: flex; gap: 4px; padding: 12px 20px 0; flex: none; }
.dtab {
  border: 0; cursor: pointer; border-radius: 10px; padding: 8px 14px;
  background: var(--active); color: var(--ink-3); font: 500 14px/18px var(--font);
  transition: background 160ms var(--ease), color 160ms var(--ease);
}
.dtab:hover { color: var(--ink); }
.dtab.is-on { background: #f6f5fe; color: var(--brand-strong); font-weight: 600; }
.drawer-body { flex: 1; overflow-y: auto; padding: 16px 20px 22px; min-height: 0; }
.pane-note { margin-bottom: 14px; }

.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 16px; }
.stat-card {
  border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; background: var(--page);
}
.stat-card b { display: block; font: 600 22px/28px var(--mono); color: var(--ink); letter-spacing: -.02em; }
.stat-card span { font: 500 14px/18px var(--font); color: var(--ink-3); }
.stat-card.brand b { color: var(--brand); }

.code {
  margin: 0; background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 16px; overflow: auto; max-height: 52vh;
  font: 500 13px/1.65 var(--mono); color: var(--ink-2); white-space: pre;
}
.code .k { color: var(--brand-strong); }
.code .s { color: #1a7f4b; }
.code .n { color: #b45309; }

.fleet { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.fleet-card { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--page); }
.fleet-head {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: 8px 12px; border-bottom: 1px solid var(--line-soft);
}
.fleet-head b { font: 600 14px/18px var(--font); }
.fleet-head span { font: 500 12px/16px var(--mono); color: var(--ink-3); }
.thumb { height: 190px; overflow: hidden; background: #fff; position: relative; }
.thumb > .scaler { width: 1280px; transform-origin: top left; position: absolute; inset: 0 auto auto 0; }

.cost-row {
  display: flex; align-items: baseline; justify-content: space-between; gap: 16px;
  padding: 12px 0; border-bottom: 1px solid var(--line-soft);
}
.cost-row:last-child { border-bottom: 0; }
.cost-row b { font: 600 16px/22px var(--mono); }
.cost-row .lbl { font: 500 14px/20px var(--font); color: var(--ink); }
.cost-row .sub { font: 500 14px/18px var(--font); color: var(--ink-3); }
.cost-total { margin-top: 8px; padding: 14px 16px; border-radius: 12px; background: #f6f5fe; }
.cost-total b { color: var(--brand-strong); }
.cost-note {
  margin-top: 14px; padding: 12px 14px; border-radius: 10px;
  background: var(--active); font: 500 14px/20px var(--font); color: var(--ink-2);
}

@media (max-width: 1000px) {
  .app { inset: 0; border-radius: 0; }
  .app-body { grid-template-columns: 1fr; }
  .preview { display: none; }
  .hide-sm { display: none; }
  .stat-row { grid-template-columns: repeat(2, 1fr); }
  .fleet { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
