/* ============================================================================
   brandhub — the gallery's own chrome.
   ----------------------------------------------------------------------------
   Written entirely in the brand tokens, because a site for choosing a tone that
   hardcodes its own colours would be arguing against itself. Everything here
   resolves through `tokens.base.css` + the chrome tone loaded by each page.

   The one place that does NOT use the page's tokens is `.preview`, which is
   scoped to whichever tone a card is showing — see `tone.js`.
   ============================================================================ */

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: "IBM Plex Sans", system-ui, -apple-system, sans-serif;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

code, pre, .mono { font-family: "JetBrains Mono", ui-monospace, monospace; }
a { color: var(--accent); }

/* ------------------------------------------------------------------ chrome */

header.bar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: .75rem 1.25rem;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: .6rem;
  font-weight: 800;
  text-decoration: none;
  color: var(--fg);
}
.brand .mark {
  width: 1.9rem;
  height: 1.9rem;
  border-radius: 8px;
  background: var(--grad-main);
}
.brand .sub {
  font-weight: 500;
  font-size: .8rem;
  color: var(--fg-muted);
}
.bar nav { margin-left: auto; display: flex; align-items: center; gap: .5rem; }

.wrap { max-width: 78rem; margin: 0 auto; padding: 1.5rem 1.25rem 5rem; }

/* Sign-in and join: one card, centred in whatever space is left under the
   header. `dvh` rather than `vh` because mobile browsers count their own
   collapsing toolbar in `vh`, which pushes the card below the fold on exactly
   the devices where centring matters most. */
.auth {
  min-height: calc(100vh - 3.5rem);
  min-height: calc(100dvh - 3.5rem);
  display: grid;
  place-items: center;
  padding: 1.25rem;
}
.auth > * { width: 100%; max-width: 25rem; }

.lede { color: var(--fg-muted); max-width: 46rem; margin: .25rem 0 1.75rem; }

/* ----------------------------------------------------------------- controls */

.btn {
  display: inline-flex;
  align-items: center;
  gap: .45rem;
  padding: .55rem 1rem;
  border-radius: 9px;
  border: 1px solid transparent;
  font: inherit;
  font-weight: 700;
  font-size: .9rem;
  cursor: pointer;
  text-decoration: none;
  transition: transform .12s, box-shadow .2s, background .18s, border-color .15s;
}
/* Solid, never a gradient: on a pill the ramp shows its end colours at the
   edges and reads as coloured borders. */
.btn.primary { background: var(--btn-bg); color: var(--btn-fg); box-shadow: var(--btn-shadow); }
.btn.primary:hover { background: var(--btn-bg-hover); transform: translateY(-1px); box-shadow: var(--btn-shadow-hover); }
.btn.primary:active { background: var(--btn-bg-active); transform: translateY(0); }
.btn.secondary { background: var(--bg-elev); border-color: var(--border); color: var(--fg); }
.btn.secondary:hover { background: var(--bg-alt); border-color: color-mix(in srgb, var(--accent) 50%, var(--border)); }
.btn.ghost { background: transparent; color: var(--accent); }
.btn.ghost:hover { background: color-mix(in srgb, var(--accent) 12%, transparent); }
/* Destructive actions read in the semantic red, never the brand accent — that
   distinction is the whole reason each tone carries its own `--danger`. */
.btn.ghost.danger { color: var(--danger); }
.btn.ghost.danger:hover { background: color-mix(in srgb, var(--danger) 14%, transparent); }
.btn.armed {
  background: var(--danger);
  color: #fff;
  font-weight: 800;
}
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
/* Full-width primary action — the shape a form wants on a phone. */
.btn.block { width: 100%; justify-content: center; margin-top: 1.2rem; }

.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 9px; overflow: hidden; }
.seg button {
  border: 0; background: transparent; color: var(--fg-muted);
  padding: .45rem .8rem; cursor: pointer; font: inherit; font-size: .85rem;
}
.seg button[aria-pressed="true"] { background: var(--bg-alt); color: var(--fg); font-weight: 700; }

label { display: block; font-size: .85rem; font-weight: 600; margin: .9rem 0 .3rem; }
input[type="text"], input[type="password"], textarea, select {
  width: 100%;
  padding: .55rem .7rem;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--fg);
  font: inherit;
  font-size: .95rem;
}
textarea { min-height: 5.5rem; resize: vertical; }
input:focus-visible, textarea:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.filters { display: flex; flex-wrap: wrap; align-items: center; gap: .75rem; margin-bottom: 1.5rem; }
.filters label { margin: 0; color: var(--fg-muted); font-weight: 500; }
.filters select { width: auto; }
.count { margin-left: auto; color: var(--fg-muted); font-size: .85rem; }

/* -------------------------------------------------------------------- cards */

.grid {
  display: grid;
  /* `min(21rem, 100%)` rather than a bare 21rem: on a narrow screen the bare
     value is wider than the viewport and the grid overflows sideways. */
  grid-template-columns: repeat(auto-fill, minmax(min(21rem, 100%), 1fr));
  gap: 1.25rem;
}

.card {
  display: flex;
  flex-direction: column;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  box-shadow: var(--shadow);
}
.card > .head { padding: .9rem 1rem .7rem; }
.card h3 { margin: 0; font-size: 1.05rem; }
.card h3 a { color: inherit; text-decoration: none; }
.card h3 a:hover { text-decoration: underline; }
.card .tagline { margin: .15rem 0 0; color: var(--fg-muted); font-size: .85rem; }

.badges { display: flex; flex-wrap: wrap; gap: .35rem; margin-top: .5rem; }
.badge {
  font-size: .7rem;
  font-weight: 700;
  letter-spacing: .03em;
  text-transform: uppercase;
  padding: .12rem .45rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--fg-muted);
}
.badge.library { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 35%, transparent); }
.badge.studio { color: var(--accent-2); border-color: color-mix(in srgb, var(--accent-2) 45%, transparent); }
.badge.warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 45%, transparent); }

/* --------------------------------------------------------- wearing a tone */

/* The way back out. A tone worn on Tuesday is an inexplicably pink site on
   Wednesday unless the escape hatch travels with it. */
.worn {
  display: flex;
  align-items: center;
  gap: .75rem;
  flex-wrap: wrap;
  padding: .55rem 1.25rem;
  background: var(--bg-alt);
  border-bottom: 1px solid var(--border);
  font-size: .9rem;
}
.worn b { color: var(--accent); }

/* ------------------------------------------------------- the scoped preview */

/* Inside this box every token belongs to the tone being shown, not the page.
   That is the whole point of a card: a real fragment of interface in that
   tone, rather than a row of disconnected swatches. */
.preview {
  background: var(--bg);
  color: var(--fg);
  padding: .9rem;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

/* The preview doubles as the control that dresses the whole page in this tone,
   so it is a real <button> — reachable by keyboard, announced as an action. */
button.preview {
  display: block;
  width: 100%;
  text-align: left;
  border-left: 0;
  border-right: 0;
  font: inherit;
  cursor: pointer;
  position: relative;
}
.try-hint {
  display: block;
  margin-top: .6rem;
  font-size: .78rem;
  font-weight: 700;
  color: var(--accent);
  opacity: 0;
  transition: opacity .15s;
}
button.preview:hover .try-hint,
button.preview:focus-visible .try-hint { opacity: 1; }
/* Touch and reduced-motion users never hover, so the hint is simply always on. */
@media (hover: none) {
  .try-hint { opacity: 1; }
}
.preview .gradbar { height: 2.6rem; border-radius: 8px; background: var(--grad-main); }
.preview .ramp { display: flex; gap: .3rem; margin-top: .55rem; }
.preview .ramp span { flex: 1; height: 1.1rem; border-radius: 4px; }
.preview .row { display: flex; align-items: center; gap: .5rem; margin-top: .7rem; }
.preview .mini-btn {
  display: inline-block;
  background: var(--btn-bg); color: var(--btn-fg);
  border-radius: 7px; padding: .35rem .8rem;
  font-size: .8rem; font-weight: 700;
}
.preview .chip {
  font-size: .75rem; font-weight: 700; padding: .1rem .5rem; border-radius: 999px;
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 32%, transparent);
}
.preview .panel {
  margin-top: .7rem; padding: .55rem .65rem;
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: 8px;
  font-size: .8rem;
}
.preview .panel .muted { color: var(--fg-muted); }

/* ------------------------------------------------------------------- voting */

.votes { display: flex; align-items: center; gap: .5rem; padding: .7rem 1rem; }
.vote {
  display: inline-flex; align-items: center; gap: .35rem;
  padding: .35rem .7rem; border-radius: 999px;
  border: 1px solid var(--border); background: var(--bg-elev); color: var(--fg-muted);
  font: inherit; font-size: .85rem; font-weight: 700; cursor: pointer;
  transition: border-color .15s, color .15s, background .15s;
}
.vote:hover { border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); color: var(--fg); }
.vote[aria-pressed="true"].up {
  color: var(--btn-fg); background: var(--btn-bg); border-color: transparent;
}
.vote[aria-pressed="true"].down {
  color: #fff; background: var(--danger); border-color: transparent;
}
.votes .score { margin-left: auto; font-size: .8rem; color: var(--fg-muted); }

/* Signed out: the same numbers, with nothing to press. A disabled button would
   read as "broken" rather than "not yours to use". */
.votes .tally {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  font-size: .85rem;
  font-weight: 700;
  color: var(--fg-muted);
}
.votes .tally .n { margin-right: .4rem; }
.votes .signin-hint { font-size: .8rem; }

/* ------------------------------------------------------------------ notices */

.note {
  border: 1px solid var(--border);
  border-left-width: 4px;
  border-radius: 8px;
  padding: .7rem .9rem;
  margin: .6rem 0;
  background: var(--bg-elev);
  font-size: .9rem;
}
.note.warn { border-left-color: var(--warn); }
.note.danger { border-left-color: var(--danger); }
.note.info { border-left-color: var(--accent); }

.empty { text-align: center; color: var(--fg-muted); padding: 4rem 1rem; }
.err { color: var(--danger); font-size: .9rem; min-height: 1.2rem; }
.hint { color: var(--fg-muted); font-size: .85rem; }

/* ------------------------------------------------------------------- studio */

.studio { display: grid; grid-template-columns: minmax(18rem, 22rem) 1fr; gap: 2rem; align-items: start; }
@media (max-width: 60rem) { .studio { grid-template-columns: 1fr; } }

.panel-box {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1.1rem 1.2rem 1.4rem;
}

.seeds { display: flex; flex-direction: column; gap: .5rem; }
.seed { display: flex; align-items: center; gap: .5rem; }
.seed input[type="color"] {
  width: 2.6rem; height: 2.3rem; padding: 0;
  border: 1px solid var(--border); border-radius: 8px; background: none; cursor: pointer;
}
.seed input[type="text"] { flex: 1; font-family: "JetBrains Mono", ui-monospace, monospace; }
.seed button {
  border: 1px solid var(--border); background: var(--bg-alt); color: var(--fg-muted);
  border-radius: 8px; width: 2.1rem; height: 2.1rem; cursor: pointer; font: inherit;
}
.seed button:hover { color: var(--danger); border-color: var(--danger); }

/* The sheet on the tone page: a real page rendered in the tone, since a tone
   is only judgeable as a whole composition. */
.sheet { display: grid; gap: 1rem; }
.sheet .hero {
  border-radius: 14px; padding: 2.2rem 1.6rem; background: var(--grad-main); color: #fff;
}
.sheet .hero h2 { margin: 0; font-size: 2rem; }
.sheet .cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr)); gap: 1rem; }
.sheet .tile {
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: 12px; padding: 1.1rem;
}
.sheet .tile h4 { margin: 0 0 .3rem; }
.sheet .tile p { margin: 0; color: var(--fg-muted); font-size: .9rem; }
.sheet .stat { font-size: 2.2rem; font-weight: 800; line-height: 1;
  background: var(--grad-main); -webkit-background-clip: text; background-clip: text; color: transparent; }

.swatches { display: flex; flex-wrap: wrap; gap: .6rem; }
.swatch { width: 8rem; border: 1px solid var(--border); border-radius: 9px; overflow: hidden; font-size: .72rem; }
.swatch .c { height: 3rem; }
.swatch .m { padding: .3rem .45rem; background: var(--bg-elev); }
.swatch .m b { display: block; }
.swatch .m span { color: var(--fg-muted); }

pre.css {
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem;
  overflow-x: auto;
  font-size: .8rem;
  max-height: 26rem;
}


/* ============================================================================
   Small screens.
   ----------------------------------------------------------------------------
   Most of the layout is already fluid (auto-fill grids, flex-wrap rows). What
   needs saying explicitly is the header, which has the most in it, and the
   input font size — anything under 16px makes iOS Safari zoom the page on
   focus, and it never zooms back out.
   ============================================================================ */

@media (max-width: 40rem) {
  header.bar {
    flex-wrap: wrap;
    gap: .5rem .75rem;
    padding: .6rem .9rem;
  }
  .bar nav {
    margin-left: 0;
    width: 100%;
    flex-wrap: wrap;
    gap: .4rem;
  }
  .bar nav .btn { padding: .45rem .7rem; font-size: .85rem; }

  .wrap { padding: 1.1rem .9rem 4rem; }
  .worn { padding: .5rem .9rem; }
  h1 { font-size: 1.3rem; }

  /* 16px exactly: iOS zooms the whole page for anything smaller. */
  input[type="text"], input[type="password"], textarea, select { font-size: 16px; }

  .filters { gap: .5rem; }
  .filters select { flex: 1; min-width: 8rem; }
  .count { width: 100%; margin-left: 0; }

  .sheet .hero { padding: 1.6rem 1.1rem; }
  .sheet .hero h2 { font-size: 1.5rem; }
  .swatch { width: calc(50% - .3rem); }
  .seed input[type="text"] { min-width: 0; }
}

/* A single column below the point where two cards stop fitting side by side,
   rather than at a device width — the grid decides, not the phone. */
@media (max-width: 26rem) {
  .grid { grid-template-columns: 1fr; }
}
