:root {
  --bg: #f4f4f4;
  --surface: #ffffff;
  --text: #1a1a1a;
  --text-soft: #505050;
  --line: #d6d6d6;
  --line-strong: #767676;
  --button: #2b2b2b;
  --button-text: #ffffff;
  --accent: #8a2f6e;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 1rem/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.visually-hidden {
  position: absolute;
  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: 8px;
  top: -100px;
  z-index: 10;
  padding: 12px 16px;
  background: var(--button);
  color: var(--button-text);
  border-radius: 6px;
}
.skip-link:focus { top: 8px; }

a { color: var(--text); }

/* Buttons shared by both pages */
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  min-width: 44px;
  padding: 0 16px;
  border: 2px solid var(--button);
  border-radius: 8px;
  background: var(--button);
  color: var(--button-text);
  font: inherit;
  font-weight: 600;
  line-height: 1.2;
  text-decoration: none;
  cursor: pointer;
}
.button:hover { background: #000; border-color: #000; }
.button--quiet,
.viewer .button:not(#about-toggle[aria-expanded="true"]) {
  background: var(--surface);
  color: var(--text);
  border-color: var(--line-strong);
}
.viewer .button:hover { background: var(--bg); border-color: var(--text); }
.viewer #about-toggle[aria-expanded="true"] { background: var(--button); color: var(--button-text); border-color: var(--button); }
.not-found .button { background: var(--button); color: var(--button-text); border-color: var(--button); }

/* Shared by the homepage and the not-found page */
.site-header { max-width: 1200px; margin: 0 auto; padding: 16px 24px 0; }
.site-name { margin: 0; font-weight: 700; color: var(--text-soft); }
.site-main { max-width: 1200px; margin: 0 auto; padding: 8px 24px 32px; }
.site-main h1 { margin: 16px 0 8px; font-size: clamp(1.75rem, 4vw, 2.5rem); line-height: 1.15; }
/* The homepage cards, masthead and footer live in home.css. */

/* Viewer */
body.viewer {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.toolbar {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  padding: 8px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--line-strong);
}
#lab-title {
  flex: 1 1 200px;
  min-width: 0;
  margin: 0;
  font-size: 1.0625rem;
  line-height: 1.25;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.field { display: inline-flex; align-items: center; gap: 8px; min-width: 0; }
.field[hidden] { display: none; }
.field label { font-weight: 600; }
select {
  min-height: 44px;
  max-width: 100%;
  padding: 0 12px;
  border: 2px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

.segmented { display: inline-flex; align-items: center; gap: 8px; margin: 0; padding: 0; border: 0; min-width: 0; }
.segmented legend { float: left; padding: 0; margin-right: 8px; font-weight: 600; }
.segmented legend + * { clear: none; }
.segmented__options { display: inline-flex; }
.segmented input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.segmented label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  min-width: 44px;
  padding: 0 14px;
  border: 2px solid var(--line-strong);
  background: var(--surface);
  cursor: pointer;
}
.segmented label:first-of-type { border-radius: 8px 0 0 8px; }
.segmented label:last-of-type { border-radius: 0 8px 8px 0; }
.segmented label + input + label { margin-left: -2px; }
.segmented input:checked + label { border-color: var(--accent); font-weight: 700; position: relative; z-index: 1; box-shadow: inset 0 0 0 1px var(--accent); }
.segmented input:focus-visible + label { outline: 3px solid var(--accent); outline-offset: 2px; z-index: 2; }
.size-note { color: var(--text-soft); font-size: 0.875rem; min-width: 6.5em; }

.copy { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 8px; }
#copy-status { color: var(--text-soft); font-size: 0.875rem; }
#copy-status:empty { display: none; }
#copy-fallback { min-height: 44px; width: min(320px, 100%); padding: 0 10px; border: 2px solid var(--line-strong); border-radius: 8px; font: inherit; }
#copy-fallback[hidden] { display: none; }

.about {
  flex: 0 1 auto;
  max-height: 60dvh;
  overflow: auto;
  padding: 16px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--line-strong);
}
.about[hidden] { display: none; }
/* Heading and Close share the first row; everything else runs full width under them. */
.about__inner { max-width: 52rem; display: grid; grid-template-columns: 1fr auto; column-gap: 16px; align-items: start; }
.about__inner > * { grid-column: 1 / -1; }
.about h2 { grid-column: 1; grid-row: 1; align-self: center; margin: 0; font-size: 1.125rem; }
.about h3 { margin: 16px 0 4px; font-size: 1rem; }
.about p { margin: 8px 0; }
.about ul { margin: 4px 0; padding-left: 1.25rem; }
.about li { margin: 4px 0; }
.about a { display: inline-block; padding: 8px 0; }
.about__inner > .about__close { grid-column: 2; grid-row: 1; }
.about__inner > h2 + .about__close + p { margin-top: 12px; }

.stage-main { flex: 1 1 auto; min-height: 0; position: relative; display: flex; flex-direction: column; }
#stage { flex: 1 1 auto; min-height: 0; overflow-x: auto; overflow-y: hidden; background: var(--bg); }
#frame-wrap { position: relative; height: 100%; width: 100%; margin: 0 auto; background: var(--surface); }
#frame-wrap[data-size="tablet"] { width: 768px; flex: none; box-shadow: 0 0 0 1px var(--line-strong); }
#frame-wrap[data-size="phone"] { width: 390px; flex: none; box-shadow: 0 0 0 1px var(--line-strong); }
#frame { display: block; width: 100%; height: 100%; border: 0; background: var(--surface); }

#frame-status {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
  background: var(--surface);
  font-weight: 600;
}
#frame-status p { margin: 0; max-width: 28rem; }
#frame-status[data-state="ready"] { display: none; }

.not-found { padding: 32px 24px; max-width: 40rem; }
.not-found[hidden] { display: none; }
.not-found h1 { margin: 0 0 16px; font-size: 1.5rem; }

body[data-state="not-found"] .toolbar,
body[data-state="not-found"] .about,
body[data-state="not-found"] #stage { display: none; }

@media (max-width: 600px) {
  .site-main, .site-header, .site-footer { padding-left: 16px; padding-right: 16px; }
  #size { display: none; }
  #frame-wrap[data-size] { width: 100%; box-shadow: none; }
  .toolbar { gap: 8px; padding: 8px 10px; }
  /* Back and the lab title share the first row; the actions sit two by two. */
  #back { flex: none; }
  #lab-title { flex: 1 1 0; font-size: 0.9375rem; }
  .field { flex: 1 1 100%; }
  .field select { flex: 1 1 auto; min-width: 0; }
  .toolbar .button { padding: 0 12px; font-size: 0.9375rem; }
  #open-new, #reload, #about-toggle, .copy { flex: 1 1 calc(50% - 4px); }
  .copy #copy-link { flex: 1 1 auto; }
  .about { max-height: 45dvh; }
}

@media (prefers-reduced-motion: no-preference) {
  .button, .lab-card__open, select { transition: background-color 0.15s ease, border-color 0.15s ease; }
}
