:root {
  --bg: #0b0d10;
  --surface: #14171c;
  --surface-2: #1c2027;
  --line: #262b33;
  --text: #e8eaed;
  --muted: #8b939e;
  --accent: #2dd4bf;
  --accent-ink: #04201c;
  --radius: 14px;
  --font: "Manrope", system-ui, sans-serif;
  --zoom: .55;
}
* { box-sizing: border-box; margin: 0; }
html { color-scheme: dark; }
body { background: var(--bg); color: var(--text); font: 500 14px/1.45 var(--font); min-height: 100vh; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* Top bar */
.bar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 12px 20px; background: rgba(11, 13, 16, .88);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}
.brand { display: inline-flex; align-items: center; gap: 10px; font: 700 19px/1 "Unbounded", var(--font); text-decoration: none; letter-spacing: -.3px; }
.brand img { width: 30px; height: 30px; border-radius: 8px; }
.brand b { color: var(--accent); font-weight: inherit; }
.count { color: var(--muted); font-size: 13px; margin-right: 6px; }
.seg { display: inline-flex; padding: 3px; gap: 2px; background: var(--surface); border: 1px solid var(--line); border-radius: 11px; }
.seg button { border: 0; background: none; padding: 6px 12px; border-radius: 8px; color: var(--muted); font-weight: 600; font-size: 13px; }
.seg button:hover { color: var(--text); }
.seg button.on { background: var(--surface-2); color: var(--text); box-shadow: inset 0 0 0 1px var(--line); }
.search { display: flex; align-items: center; gap: 8px; flex: 1 1 200px; max-width: 320px; height: 38px; padding: 0 12px; background: var(--surface); border: 1px solid var(--line); border-radius: 11px; color: var(--muted); }
.search:focus-within { border-color: var(--accent); }
.search input { flex: 1; min-width: 0; background: none; border: 0; outline: 0; color: var(--text); }
.bar-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }
select { height: 38px; padding: 0 10px; background: var(--surface); border: 1px solid var(--line); border-radius: 11px; }
.zoom { display: flex; align-items: center; gap: 8px; color: var(--muted); }
.zoom input { width: 110px; accent-color: var(--accent); }

/* Preview grid */
.grid { display: flex; flex-wrap: wrap; gap: 28px 24px; padding: 28px 20px 60px; justify-content: center; }
.tile { width: calc(var(--w) * var(--zoom) * 1px + 16px); text-decoration: none; display: flex; flex-direction: column; gap: 10px; }
.tile .phone { --s: var(--zoom); }
.tile:hover .phone { border-color: #3a414c; transform: translateY(-3px); box-shadow: 0 18px 40px rgba(0, 0, 0, .5), 0 0 0 1px var(--accent); }
.tile-cap { display: flex; flex-direction: column; gap: 3px; padding: 0 4px; }
.tile-title { font-weight: 700; font-size: 14px; display: flex; gap: 8px; align-items: baseline; }
.tile-title b { font: 700 12px/1 "Unbounded", var(--font); color: var(--accent); }
.tile-sub { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.empty { text-align: center; color: var(--muted); padding: 60px 0; }

/* Phone: frame + real-size iframe, scaled down with transform */
.phone {
  --s: 1;
  position: relative; flex: none;
  width: calc(var(--w) * var(--s) * 1px + 16px); height: calc(var(--h) * var(--s) * 1px + 16px);
  padding: 8px; border-radius: calc(26px * var(--s) + 14px);
  background: #050608; border: 1px solid #2a2f37;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .45);
  transition: transform .2s, box-shadow .2s, border-color .2s;
}
.phone iframe {
  display: block; width: calc(var(--w) * 1px); height: calc(var(--h) * 1px); border: 0;
  border-radius: 26px; background: #000;
  transform: scale(var(--s)); transform-origin: 0 0;
}
.tile .phone iframe { pointer-events: none; position: relative; z-index: 1; opacity: 1; transition: opacity .35s; }
.tile .phone.is-loading iframe { opacity: 0; }
/* Screenshot under the live preview + shimmer while it loads */
.phone-shot {
  position: absolute; z-index: 0; left: 8px; top: 8px;
  width: calc(var(--w) * var(--s) * 1px); height: calc(var(--h) * var(--s) * 1px);
  object-fit: cover; object-position: top; border-radius: calc(26px * var(--s)); background: #111318;
}
.phone.is-loading::before {
  content: ""; position: absolute; z-index: 2; inset: 8px; border-radius: calc(26px * var(--s)); pointer-events: none;
  background: linear-gradient(100deg, transparent 30%, rgba(255, 255, 255, .07) 50%, transparent 70%) 0 0 / 250% 100%;
  animation: shimmer 1.4s linear infinite;
}
@keyframes shimmer { to { background-position: -250% 0; } }

/* Full-screen loader */
.boot { position: fixed; inset: 0; z-index: 45; display: grid; place-items: center; background: radial-gradient(60% 50% at 50% 40%, #12201f, var(--bg) 70%); transition: opacity .4s; }
.boot.out { opacity: 0; pointer-events: none; }
.boot[hidden] { display: none; }
.boot-box { display: flex; flex-direction: column; align-items: center; gap: 16px; width: min(320px, 80vw); }
.boot-box img { width: 72px; height: 72px; border-radius: 18px; animation: boot-pulse 1.6s ease-in-out infinite; }
.boot-title { font: 700 26px/1 "Unbounded", var(--font); letter-spacing: -.5px; }
.boot-title b { color: var(--accent); font-weight: inherit; }
.boot-track { width: 100%; height: 6px; border-radius: 6px; background: var(--surface-2); overflow: hidden; }
.boot-track i { display: block; width: 0; height: 100%; border-radius: inherit; background: var(--accent); box-shadow: 0 0 12px var(--accent); transition: width .3s; }
.boot-text { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.boot-skip { margin-top: 6px; background: none; border: 0; color: var(--muted); font-size: 12px; text-decoration: underline; text-underline-offset: 3px; opacity: .7; }
.boot-skip:hover { opacity: 1; color: var(--text); }
@keyframes boot-pulse { 50% { transform: scale(1.06); } }
.tile[hidden] { display: none; }
.tile .phone.is-failed iframe { opacity: 0; }
@media (prefers-reduced-motion: reduce) { .phone.is-loading::before, .boot-box img { animation: none; } }
.phone::after { content: ""; position: absolute; inset: 8px; border-radius: calc(26px * var(--s)); pointer-events: none; }

/* Detail view */
.detail {
  position: fixed; inset: 0; z-index: 50; background: var(--bg);
  display: grid; grid-template-columns: 1fr minmax(380px, 520px);
}
.detail[hidden] { display: none; }
.d-stage { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.d-tools { display: flex; align-items: center; gap: 6px; padding: 12px 18px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.d-num { font: 700 14px/1 "Unbounded", var(--font); color: var(--accent); min-width: 40px; text-align: center; }
.sep { width: 1px; height: 22px; background: var(--line); margin: 0 6px; }
.tbtn { height: 34px; min-width: 34px; padding: 0 12px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); display: inline-flex; align-items: center; justify-content: center; text-decoration: none; font-weight: 600; font-size: 13px; }
.tbtn:hover { border-color: #3a414c; }
.tbtn.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.d-phone-wrap { flex: 1; overflow: auto; display: flex; justify-content: center; align-items: flex-start; padding: 26px 20px 40px; }
.d-phone-wrap .phone { --s: var(--ds, 1); }
.fold { position: absolute; left: 0; right: 0; height: 0; border-top: 2px dashed #f43f5e; pointer-events: none; display: none; }
.fold span { position: absolute; right: 12px; top: -22px; font-size: 11px; font-weight: 700; color: #fff; background: #f43f5e; padding: 2px 7px; border-radius: 6px; }
.detail.full .fold { display: block; }

.d-info { position: relative; border-left: 1px solid var(--line); overflow-y: auto; padding: 22px 24px 40px; background: var(--surface); }
.d-close { position: absolute; top: 14px; right: 14px; width: 36px; height: 36px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface-2); font-size: 15px; }
.d-info h1 { font: 700 21px/1.25 "Unbounded", var(--font); padding-right: 44px; letter-spacing: -.3px; }
.d-meta { color: var(--muted); font-size: 13px; margin-top: 6px; }
.d-summary { margin-top: 12px; font-size: 14.5px; line-height: 1.55; }
.d-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 14px; }
.tag { padding: 4px 10px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); font-size: 12px; color: #c5cbd3; }
.tag--p { border-color: rgba(45, 212, 191, .4); color: var(--accent); }
.d-palette { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.sw { display: flex; align-items: center; gap: 6px; padding: 3px 9px 3px 3px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); font-size: 11.5px; color: var(--muted); }
.sw i { width: 20px; height: 20px; border-radius: 50%; box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .15); }
.sw:hover { color: var(--text); }

.ai { margin-top: 22px; padding: 18px; border-radius: var(--radius); background: var(--bg); border: 1px solid var(--line); }
.ai h2 { font: 700 15px/1 "Unbounded", var(--font); margin-bottom: 14px; }
.seg--small button { padding: 6px 10px; font-size: 12.5px; }
.ai-btns { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.btn-main, .btn, .btn-ghost { height: 40px; padding: 0 16px; border-radius: 10px; font-weight: 700; font-size: 13.5px; display: inline-flex; align-items: center; text-decoration: none; border: 1px solid var(--line); }
.btn-main { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); flex: 1 1 100%; justify-content: center; height: 46px; font-size: 14.5px; }
.btn-main:hover { filter: brightness(1.08); }
.btn { background: var(--surface-2); flex: 1; justify-content: center; }
.btn-ghost { height: 34px; background: none; color: var(--muted); font-weight: 600; font-size: 12.5px; }
.btn:hover, .btn-ghost:hover { border-color: #3a414c; color: var(--text); }
.ai-btns--small { margin-top: 8px; }
.hint { margin-top: 12px; font-size: 12px; color: var(--muted); line-height: 1.5; }

.acc { margin-top: 18px; border-top: 1px solid var(--line); padding-top: 14px; }
.acc summary { cursor: pointer; font-weight: 700; font-size: 14px; list-style: none; display: flex; align-items: center; gap: 8px; }
.acc summary::before { content: "▸"; color: var(--muted); transition: transform .15s; }
.acc[open] summary::before { transform: rotate(90deg); }

/* Rendered LAYOUT.md */
.md { margin-top: 12px; font-size: 13.5px; line-height: 1.6; color: #d3d8de; }
.md h1 { display: none; }
.md h2 { font-size: 14px; margin: 18px 0 8px; color: var(--text); }
.md h3 { font-size: 13.5px; margin: 14px 0 6px; }
.md p { margin: 6px 0; }
.md ul, .md ol { padding-left: 20px; margin: 6px 0; }
.md li { margin: 4px 0; }
.md code { font: 12px/1.4 ui-monospace, "SF Mono", Menlo, monospace; background: var(--surface-2); padding: 1px 5px; border-radius: 5px; }
.md pre { margin: 8px 0; padding: 12px; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; overflow-x: auto; font: 11.5px/1.35 ui-monospace, "SF Mono", Menlo, monospace; color: #b9f3ea; }
.md pre code { background: none; padding: 0; font: inherit; }
.md strong { color: var(--text); }

.mtable { width: 100%; border-collapse: collapse; margin-top: 12px; font-size: 12.5px; }
.mtable th, .mtable td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); }
.mtable th { color: var(--muted); font-weight: 600; }
.mtable td:first-child { font-weight: 700; color: var(--accent); }
.mnote { margin-top: 10px; font-size: 12.5px; color: var(--muted); }

.toast { position: fixed; left: 50%; bottom: 26px; transform: translate(-50%, 20px); opacity: 0; z-index: 100; padding: 10px 18px; border-radius: 12px; background: var(--accent); color: var(--accent-ink); font-weight: 700; transition: .25s; pointer-events: none; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 1000px) {
  .detail { grid-template-columns: 1fr; overflow-y: auto; }
  .d-info { border-left: 0; border-top: 1px solid var(--line); overflow: visible; }
  .d-phone-wrap { overflow: visible; }
}
