/* ==========================================================================
   Layout — base reset, page chrome, landing, workspace grid, responsive rules
   ========================================================================== */
*, *::before, *::after { box-sizing: border-box; }
html { height: 100%; -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100%;
  font: 400 var(--fs-base)/var(--lh) var(--font-sans);
  color: var(--text); background: var(--bg);
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -0.01em; line-height: 1.2; }
h1 { font-size: var(--fs-2xl); letter-spacing: -0.025em; }
h2 { font-size: var(--fs-xl); }
h3 { font-size: var(--fs-md); }
h4 { font-size: var(--fs-base); }
p { margin: 0; }
a { color: var(--accent-text); text-decoration: none; }
a:hover { text-decoration: underline; }
code, pre, .mono { font-family: var(--font-mono); font-size: 0.92em; }
button, input, select, textarea { font: inherit; color: inherit; }
img, svg, canvas { display: block; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: var(--r-1); }
::selection { background: var(--accent-soft); }
[hidden] { display: none !important; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip-link { position: absolute; left: var(--s-4); top: -60px; z-index: 100; padding: var(--s-2) var(--s-3); background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--r-1); }
.skip-link:focus { top: var(--s-2); }

/* --- top bar ------------------------------------------------------------ */
.topbar {
  position: sticky; top: 0; z-index: 30; height: var(--topbar-h);
  background: color-mix(in srgb, var(--bg) 86%, transparent); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.topbar__inner { max-width: var(--maxw); margin: 0 auto; height: 100%; padding: 0 var(--s-6); display: flex; align-items: center; gap: var(--s-4); }
.brand { display: inline-flex; align-items: center; gap: var(--s-3); color: var(--text); font-weight: 600; letter-spacing: -0.01em; }
.brand:hover { text-decoration: none; }
.brand__mark { width: 28px; height: 28px; border-radius: 7px; }
.brand__tag { color: var(--text-3); font-weight: 400; font-size: var(--fs-sm); margin-left: var(--s-1); }
.topbar__spacer { flex: 1; }
.topbar nav { display: flex; align-items: center; gap: var(--s-1); }
.topbar nav a { white-space: nowrap; color: var(--text-2); padding: var(--s-2) var(--s-3); border-radius: var(--r-1); }
.topbar nav a:hover, .topbar nav a[aria-current="page"] { color: var(--text); background: var(--surface-2); text-decoration: none; }

/* --- page ---------------------------------------------------------------- */
.page { max-width: var(--maxw); margin: 0 auto; padding: var(--s-6); }
.page--narrow { max-width: 880px; }
.footer { max-width: var(--maxw); margin: 0 auto; padding: var(--s-8) var(--s-6) var(--s-10); color: var(--text-3); font-size: var(--fs-sm); display: flex; flex-wrap: wrap; gap: var(--s-2) var(--s-6); }
.footer a { color: var(--text-2); }

/* --- landing ------------------------------------------------------------- */
.hero { padding: var(--s-10) 0 var(--s-8); text-align: center; max-width: 1040px; margin: 0 auto; }
.hero h1 { margin-bottom: var(--s-4); }
.hero__lede { color: var(--text-2); font-size: var(--fs-md); max-width: 640px; margin: 0 auto var(--s-8); }
.hero__samples { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: var(--s-2); margin-top: var(--s-5); color: var(--text-3); font-size: var(--fs-sm); }
.features { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--s-4); margin: var(--s-10) 0 var(--s-8); }
.feature { padding: var(--s-5); }
.feature h3 { margin: var(--s-3) 0 var(--s-2); }
.feature p { color: var(--text-2); font-size: var(--fs-sm); }
.feature__icon { width: 36px; height: 36px; display: grid; place-items: center; border-radius: var(--r-2); background: var(--accent-soft); color: var(--accent-text); }

.entries { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--s-4); margin: 0 0 var(--s-6); text-align: left; }
.entry { display: flex; flex-direction: column; gap: var(--s-2); padding: var(--s-5); color: var(--text); cursor: pointer; font: inherit; text-align: left; transition: border-color var(--t-fast), transform var(--t-fast); }
.entry:hover { text-decoration: none; border-color: var(--accent); transform: translateY(-1px); }
.entry--primary { border-color: var(--accent); background: linear-gradient(180deg, var(--accent-soft), transparent 70%), var(--surface); }
.entry__icon { width: 40px; height: 40px; display: grid; place-items: center; border-radius: var(--r-2); background: var(--accent-soft); color: var(--accent-text); }
.entry__title { font-size: var(--fs-lg); font-weight: 600; letter-spacing: -0.01em; }
.entry__text { color: var(--text-2); font-size: var(--fs-sm); flex: 1; }
.entry__go { color: var(--accent-text); font-weight: 600; font-size: var(--fs-sm); }
.machinebar { margin-top: var(--s-6); text-align: left; }
.machinebar .card__body { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2) var(--s-4); }
.machinebar .btn { margin-top: 0 !important; margin-left: auto; }
.machine__name { display: flex; align-items: center; gap: var(--s-2); font-weight: 600; }
.machine__name svg { width: 18px; height: 18px; color: var(--accent-text); flex: none; }
.machine__form { display: flex; flex-direction: column; gap: var(--s-2); margin-top: var(--s-3); }
.machine__form h4 { margin-top: var(--s-3); color: var(--text-2); font-size: var(--fs-sm); text-transform: uppercase; letter-spacing: .04em; }
dialog.dlg--wide { width: min(560px, calc(100vw - 24px)); max-height: calc(100vh - 24px); overflow: auto; }

/* --- workspace ----------------------------------------------------------- */
.workspace { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); gap: var(--s-6); align-items: start; }
.sidebar { display: flex; flex-direction: column; gap: var(--s-4); position: sticky; top: calc(var(--topbar-h) + var(--s-6)); max-height: calc(100vh - var(--topbar-h) - var(--s-12)); }
.sidebar__scroll { overflow: auto; overscroll-behavior: contain; display: flex; flex-direction: column; gap: var(--s-4); padding-right: 2px; min-height: 0; }
.sidebar__scroll > * { flex-shrink: 0; } /* a scrolling flex column must not squash its cards */
.sidebar__actions { display: flex; flex-direction: column; gap: var(--s-2); padding-top: var(--s-2); }
.main { min-width: 0; display: flex; flex-direction: column; gap: var(--s-4); }
.results__head { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2) var(--s-3); }
.results__head h2 { font-size: var(--fs-lg); margin-right: auto; }
.results__actions { display: flex; flex-wrap: wrap; gap: var(--s-2); }

@media (max-width: 900px) {
  .page { padding: var(--s-4); }
  .topbar__inner { padding: 0 var(--s-4); }
  .brand__tag { display: none; }
  .features { grid-template-columns: 1fr; margin-top: var(--s-8); }
  .entries { grid-template-columns: 1fr; }
  .machinebar .btn { margin-left: 0; }
  .hero { padding-top: var(--s-8); }
  .workspace { grid-template-columns: minmax(0, 1fr); gap: var(--s-4); }   /* minmax(0, …): a long select option must not widen the page */
  .sidebar { position: static; max-height: none; }
  .sidebar__scroll { overflow: visible; }
  .results__head h2 { flex-basis: 100%; }
}
@media (max-width: 480px) {
  /* the brand, two nav links and the theme toggle must fit 360 px without pushing the page sideways */
  .topbar__inner { padding: 0 var(--s-3); gap: var(--s-2); }
  .brand { min-width: 0; gap: var(--s-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: var(--fs-sm); }
  .brand__mark { flex: none; }
  .topbar nav a { padding: var(--s-2); font-size: var(--fs-sm); }
  h1 { font-size: 1.85rem; }
  .hero__lede { font-size: var(--fs-base); }
}
