/* Page layout: header, workspace (controls | preview | code), docs, footer.
   Desktop shows three panels; tablet puts the code under the other two; phones switch with tabs. */

.page-pad {
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}

/* ---------- header ---------- */
.site-header {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(1.4) blur(8px);
  border-bottom: 1px solid var(--border);
}
.site-header-inner { height: var(--header-h); display: flex; align-items: center; gap: var(--space-4); }
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; }
.brand:hover { color: var(--text); }
.brand img { width: 28px; height: 28px; }
/* The logo's deepest indigo is too dark on the dark theme, so the mark sits on a white tile there.
   The symbol itself is unchanged. */
:root[data-theme="dark"] .brand img { background: #fff; padding: 3px; border-radius: 6px; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .brand img { background: #fff; padding: 3px; border-radius: 6px; }
}
.brand-name { font-size: 17px; font-weight: 650; letter-spacing: -0.01em; }
.site-nav { display: flex; align-items: center; gap: 2px; margin-left: var(--space-3); }
.site-nav a {
  padding: 6px 10px; border-radius: var(--radius); color: var(--text-2);
  font-size: var(--text-sm); font-weight: 500; text-decoration: none;
}
.site-nav a:hover { color: var(--text); background: var(--surface-3); }
.site-nav a[aria-current="page"] { color: var(--text); }
.header-actions { margin-left: auto; display: flex; align-items: center; gap: 4px; }

/* ---------- intro strip ---------- */
.intro { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 14px; padding-block: 14px 12px; }
.intro h1 { font-size: var(--text-xl); font-weight: 650; letter-spacing: -0.015em; }
.intro p { color: var(--text-2); font-size: var(--text-sm); }
.intro .badges { display: flex; gap: 6px; flex-wrap: wrap; margin-left: auto; }
.badge {
  font-size: 11px; font-weight: 500; color: var(--accent-text); background: var(--accent-soft);
  padding: 2px 8px; border-radius: 999px;
}

.startup-error {
  margin-bottom: var(--space-3); padding: 10px 14px; border-radius: var(--radius);
  background: var(--danger-soft); color: var(--danger); border: 1px solid var(--danger);
  font-size: var(--text-sm);
}

/* ---------- workspace ---------- */
.workspace {
  display: grid; gap: var(--space-3); padding-bottom: var(--space-4);
  grid-template-columns: 320px minmax(0, 1fr) 380px;
  height: clamp(620px, calc(100dvh - var(--header-h) - 64px), 1200px);
}
.panel {
  min-width: 0; min-height: 0; display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
}
.panel-head {
  display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap;
  padding: 10px var(--space-3); border-bottom: 1px solid var(--border); min-height: 48px;
}
.panel-title { font-size: var(--text-sm); font-weight: 600; }
.panel-body { flex: 1 1 auto; min-height: 0; overflow: auto; overscroll-behavior: contain; }

/* ---------- control sections ---------- */
.section { border-bottom: 1px solid var(--border); }
.section:last-child { border-bottom: 0; }
.section > summary {
  list-style: none; cursor: pointer; user-select: none;
  display: flex; align-items: center; gap: 8px; padding: 12px var(--space-3);
  font-size: var(--text-sm); font-weight: 600;
}
.section > summary::-webkit-details-marker { display: none; }
.section > summary::after {
  content: ""; margin-left: auto; width: 7px; height: 7px;
  border-right: 1.5px solid var(--text-3); border-bottom: 1.5px solid var(--text-3);
  transform: rotate(45deg) translateY(-2px); transition: transform .15s;
}
.section[open] > summary::after { transform: rotate(-135deg) translateY(-1px); }
.section > summary:hover { background: var(--surface-2); }
.section-body { display: grid; gap: var(--space-3); padding: 0 var(--space-3) var(--space-4); }
.section-count {
  font-size: 11px; font-weight: 500; color: var(--text-3); font-variant-numeric: tabular-nums;
}

/* presets */
.preset-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-2); }
.preset {
  display: grid; gap: 6px; padding: 8px; text-align: left; cursor: pointer;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text-2); font: 500 var(--text-xs) var(--font-sans);
}
.preset:hover { border-color: var(--brand-400); color: var(--text); }
.preset[aria-pressed="true"] { border-color: var(--accent); color: var(--text); box-shadow: inset 0 0 0 1px var(--accent); }
.preset-thumb { display: grid; gap: 2px; height: 44px; }
.preset-thumb span { background: color-mix(in srgb, var(--brand-400) 55%, var(--surface)); border-radius: 2px; }

/* track lists */
.track-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px var(--space-2); }
.track { display: grid; grid-template-columns: 28px minmax(0, 1fr); align-items: center; gap: 4px; }
.track .label { font-variant-numeric: tabular-nums; color: var(--text-3); }
.set-all { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: var(--space-2); }

/* item editor */
.item-editor { display: grid; gap: var(--space-3); }
.plain-fieldset { border: 0; padding: 0; margin: 0; }
.plain-fieldset legend { padding: 0; margin-bottom: 6px; }
.swatches { display: flex; flex-wrap: wrap; gap: 6px; border: 0; padding: 0; margin: 0; }
.swatch { position: relative; }
.swatch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.swatch span {
  display: block; width: 24px; height: 24px; border-radius: var(--radius-sm);
  background: hsl(var(--h) var(--s) var(--item-bg-l)); border: 2px solid hsl(var(--h) var(--s) var(--item-border-l));
}
.swatch input:checked + span { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--text); }
.swatch input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: 4px; }
.button-row { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.empty-note {
  padding: 12px; border: 1px dashed var(--border-strong); border-radius: var(--radius);
  color: var(--text-3); font-size: var(--text-sm);
}
.areas-map {
  margin: 0; padding: 10px; background: var(--code-bg); border: 1px solid var(--border);
  border-radius: var(--radius); font-size: 12px; line-height: 1.6; overflow-x: auto; color: var(--text-2);
}

/* ---------- code panel ---------- */
.code-download { margin-left: auto; }
.code-block { display: flex; flex-direction: column; min-height: 0; }
.code-block + .code-block { border-top: 1px solid var(--border); }
.code-block.css-block { flex: 1 1 60%; }
.code-block.html-block { flex: 1 1 40%; }
.code-head { display: flex; align-items: center; gap: var(--space-2); padding: 8px var(--space-3); }
.code-head h2 { font-size: var(--text-xs); font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--text-2); }
.code-head .actions { margin-left: auto; display: flex; gap: 6px; }
.code {
  flex: 1 1 auto; min-height: 120px; margin: 0; padding: var(--space-3);
  overflow: auto; background: var(--code-bg); border-top: 1px solid var(--border);
  font: 400 12.5px/1.65 var(--font-mono); color: var(--text); tab-size: 2;
}
.code:focus-visible { outline-offset: -2px; }
.tok-selector { color: var(--tok-selector); font-weight: 500; }
.tok-property { color: var(--tok-property); }
.tok-value { color: var(--tok-value); }
.tok-punct { color: var(--tok-punct); }
.tok-tag { color: var(--tok-tag); }

/* ---------- mobile tabs ---------- */
.mobile-tabs { display: none; }

/* ---------- docs ---------- */
.docs { padding-block: var(--space-6) var(--space-6); border-top: 1px solid var(--border); }
.docs-inner { max-width: 1100px; display: grid; gap: var(--space-6); grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.docs h2 { font-size: var(--text-lg); font-weight: 650; margin-bottom: var(--space-3); }
.docs p, .docs li { color: var(--text-2); max-width: 65ch; }
.docs ol, .docs ul { margin: 0; padding-left: 20px; display: grid; gap: 6px; }
.docs code { font-size: 12.5px; color: var(--text); background: var(--surface-3); padding: 1px 5px; border-radius: var(--radius-sm); }
.docs-table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
.docs-table th, .docs-table td { text-align: left; padding: 6px 8px 6px 0; border-bottom: 1px solid var(--border); vertical-align: top; }
.docs-table th { font-weight: 600; color: var(--text); }
.docs-table td { color: var(--text-2); }
.docs-block { min-width: 0; }
.docs-wide { grid-column: 1 / -1; }

/* ---------- footer ---------- */
.site-footer { border-top: 1px solid var(--border); background: var(--surface); }
.site-footer-inner {
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3) var(--space-5);
  padding-block: var(--space-5); font-size: var(--text-sm); color: var(--text-3);
}
.site-footer .brand img { width: 22px; height: 22px; }
.site-footer .brand-name { font-size: 15px; }
.footer-links { display: flex; flex-wrap: wrap; gap: var(--space-2) var(--space-4); }
.footer-links a { color: var(--text-2); text-decoration: none; }
.footer-links a:hover { color: var(--text); text-decoration: underline; }
.copyright { margin-left: auto; }

/* ---------- tablet: code goes under controls + preview ---------- */
@media (max-width: 1279px) {
  .workspace { grid-template-columns: 300px minmax(0, 1fr); height: auto; }
  .controls-panel, .preview-panel { height: clamp(560px, calc(100dvh - var(--header-h) - 64px), 960px); }
  .code-panel { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .code-panel > .panel-head { grid-column: 1 / -1; }
  .code-block + .code-block { border-top: 0; border-left: 1px solid var(--border); }
  .code { max-height: 420px; }
}

/* ---------- phones: one panel at a time ---------- */
@media (max-width: 859px) {
  .site-nav { display: none; }
  .intro .badges { margin-left: 0; }
  .mobile-tabs {
    display: grid; grid-template-columns: repeat(3, 1fr); gap: 2px; padding: 2px; margin-bottom: var(--space-3);
    background: var(--surface-3); border-radius: var(--radius-lg);
    position: sticky; top: calc(var(--header-h) + 6px); z-index: 10;
  }
  .mobile-tabs button {
    min-height: 40px; border: 0; border-radius: var(--radius); background: transparent;
    font: 500 var(--text-sm) var(--font-sans); color: var(--text-2); cursor: pointer;
  }
  .mobile-tabs button[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); font-weight: 600; }
  .workspace { grid-template-columns: minmax(0, 1fr); }
  .controls-panel, .preview-panel { height: auto; }
  .panel-body { overflow: visible; }
  .workspace[data-tab="controls"] > :not(.controls-panel),
  .workspace[data-tab="preview"] > :not(.preview-panel),
  .workspace[data-tab="code"] > :not(.code-panel) { display: none; }
  .code-panel { display: flex; }
  .code-block + .code-block { border-left: 0; border-top: 1px solid var(--border); }
  .code { max-height: none; }
  .copyright { margin-left: 0; }
}
@media (max-width: 420px) {
  .preset-grid, .track-list { grid-template-columns: minmax(0, 1fr); }
  .field-row-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
