/* Two token sets, on purpose.

   The panel is fixed dark and owns the builder suite's own palette (tool 03's
   #0b0d10 / #15181c / #e8eaed). The gallery follows the Dark/Light switch.
   That's the same split the builder tools use — their Dark/Light tabs retheme
   the artwork, not the controls — and it's what makes light mode useful here:
   you judge a light chart surface against steady chrome instead of watching
   the whole page invert. */

:root {
  --panel-bg: #15181c;
  --panel-edge: #262b31;
  --panel-text: #e8eaed;
  --panel-dim: #8a929c;
  --panel-input: #1c2126;
  --panel-input-edge: #383e46;
  --panel-field: #22262c;
  --mono: "JetBrains Mono", ui-monospace, Menlo, Consolas, monospace;
  --sans: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

:root[data-surface="dark"] {
  --bg: #18171d;
  --card: #1f1e24;
  --border: #3a383d;
  --border-soft: #2e2c32;
  --text: #dcdbd9;
  --muted: #8a8888;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}

:root[data-surface="light"] {
  --bg: #f7f7f5;
  --card: #ffffff;
  --border: #dcdbd9;
  --border-soft: #ecebea;
  --text: #28272d;
  --muted: #646163;
  --shadow: 0 10px 30px rgba(24, 23, 29, 0.14);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 13px;
  line-height: 1.45;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

button,
input,
select {
  font-family: inherit;
  color: inherit;
}

:focus-visible {
  outline: 2px solid var(--panel-text);
  outline-offset: 2px;
  border-radius: 4px;
}

.app {
  height: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 328px;
}

/* ---- panel -------------------------------------------------------------- */

.panel {
  background: var(--panel-bg);
  border-left: 1px solid var(--panel-edge);
  color: var(--panel-text);
  padding: 20px;
  overflow-y: auto;
  scrollbar-width: thin;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.brand {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  color: var(--panel-dim);
}

.brand strong {
  color: var(--panel-text);
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.015em;
  line-height: 1.15;
}

.brand__count {
  font-family: var(--mono);
  font-size: 11px;
  white-space: nowrap;
}

.divider {
  height: 1px;
  background: var(--panel-edge);
}

.group {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.section-title {
  margin: 0;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--panel-dim);
}

.hint {
  margin: 0;
  font-size: 11px;
  font-weight: 400;
  line-height: 1.5;
  color: var(--panel-dim);
}

.sub-title {
  margin: 4px 0 -4px;
  font-size: 12px;
  font-weight: 650;
  letter-spacing: -0.005em;
  color: var(--panel-text);
}

/* tabs */
.tabs {
  display: flex;
  gap: 8px;
}

.tab {
  flex: 1;
  padding: 10px 0;
  border: 1px solid var(--panel-edge);
  background: var(--panel-input);
  border-radius: 8px;
  color: var(--panel-text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.tab:hover {
  border-color: var(--panel-dim);
}

.tab.is-on {
  background: var(--panel-text);
  border-color: var(--panel-text);
  color: #111316;
  font-weight: 700;
}

/* fields */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field__head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  color: var(--panel-dim);
  font-size: 13px;
  font-weight: 500;
}

.field__head .val {
  color: var(--panel-text);
  font-weight: 700;
  font-size: 14px;
}

.range {
  width: 100%;
  height: 20px;
  accent-color: var(--panel-text);
}

select,
.search {
  width: 100%;
  background: var(--panel-field);
  border: 1px solid var(--panel-input-edge);
  border-radius: 8px;
  padding: 10px 13px;
  font-size: 14px;
  font-weight: 500;
  color: var(--panel-text);
}

select {
  padding-right: 38px;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%238a929c' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 13px center;
}

.search::placeholder {
  color: var(--panel-dim);
}

.toggle {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  font-size: 13px;
  font-weight: 500;
  line-height: 1.35;
  color: var(--panel-dim);
  cursor: pointer;
}

.toggle:hover {
  color: var(--panel-text);
}

.toggle input {
  margin: 1px 0 0;
  accent-color: var(--panel-text);
}

.action {
  background: var(--panel-input);
  border: 1px solid var(--panel-input-edge);
  border-radius: 8px;
  padding: 11px 14px;
  color: var(--panel-text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.action:hover {
  border-color: var(--panel-text);
}

/* ramp step picker */
.steps {
  display: grid;
  grid-template-columns: repeat(11, 1fr);
  gap: 3px;
}

.steps__btn {
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  display: grid;
  gap: 3px;
  justify-items: center;
}

.steps__stack {
  display: grid;
  grid-template-rows: repeat(5, 1fr);
  width: 100%;
  height: 44px;
  border-radius: 3px;
  overflow: hidden;
  box-shadow: 0 0 0 1px var(--panel-edge);
  opacity: 0.5;
  transition: opacity 0.12s;
}

.steps__btn:hover .steps__stack {
  opacity: 0.85;
}

.steps__btn.is-on .steps__stack {
  opacity: 1;
  box-shadow: 0 0 0 2px var(--panel-text);
}

.steps__num {
  font-family: var(--mono);
  font-size: 8.5px;
  font-weight: 500;
  color: var(--panel-dim);
}

.steps__btn.is-on .steps__num {
  color: var(--panel-text);
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* hue order */
.hues {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.hues__row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}

.hues__chip {
  position: relative;
  height: 36px;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  box-shadow: 0 0 0 1px var(--panel-edge);
}

.hues__idx {
  position: absolute;
  inset: auto 5px 3px auto;
  font-family: var(--mono);
  font-size: 9px;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.95);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
}

/* contrast readout */
.readout {
  display: flex;
  gap: 6px;
}

.readout__cell {
  flex: 1;
  display: grid;
  gap: 3px;
  justify-items: center;
}

.readout__sw {
  width: 100%;
  height: 12px;
  border-radius: 3px;
  box-shadow: 0 0 0 1px var(--panel-edge);
}

.readout__val {
  font-family: var(--mono);
  font-size: 9.5px;
  font-weight: 500;
  color: var(--panel-dim);
}

.readout__cell.is-low .readout__val {
  color: #f7b951;
  font-weight: 700;
}

/* texture picker */
.tex {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.tex__btn {
  background: var(--panel-input);
  border: 1px solid var(--panel-edge);
  border-radius: 8px;
  padding: 7px 8px 8px;
  cursor: pointer;
  display: grid;
  gap: 5px;
  text-align: left;
  transition: border-color 0.15s;
}

.tex__btn:hover {
  border-color: var(--panel-dim);
}

.tex__btn.is-on {
  border-color: var(--panel-text);
  box-shadow: inset 0 0 0 1px var(--panel-text);
}

.tex__chip {
  position: relative;
  height: 38px;
  border-radius: 5px;
  box-shadow: inset 0 0 0 1px var(--panel-edge);
  /* The tiles are 2px cells — smoothing them would blur away the difference
     between a 4×4 and a 16×16 repeat, which is the whole reason these sit
     next to each other. */
  image-rendering: pixelated;
}

/* One repeat of the matrix, outlined in place. */
.tex__unit {
  position: absolute;
  top: 3px;
  left: 3px;
  /* A dark line against the light ink plus a light line inside it, so the box
     stays visible whether it lands on a dense part of the tile or a gap. */
  border: 1px solid var(--panel-bg);
  box-shadow: inset 0 0 0 1px rgba(232, 234, 237, 0.95);
  pointer-events: none;
}

.tex__name {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--panel-text);
  line-height: 1.1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tex__size {
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 500;
  color: var(--panel-dim);
  line-height: 1;
}

.tex__btn.is-on .tex__size {
  color: var(--panel-text);
}

/* two selects on one line, so the diverging arms cost one row not two */
.row2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

/* ---- gallery ------------------------------------------------------------ */

.gallery {
  overflow-y: auto;
  padding: 18px 20px 60px;
  scrollbar-width: thin;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(330px, 1fr));
  gap: 14px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border-soft);
  border-radius: 10px;
  overflow: hidden;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
}

/* `display: grid` above beats the UA's `[hidden] { display: none }`, so the
   filter's hidden attribute needs saying again here. */
.card[hidden] {
  display: none;
}

.card:hover {
  border-color: var(--border);
}

.card__chart {
  height: 248px;
  width: 100%;
}

.card__foot {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px 10px;
  border-top: 1px solid var(--border-soft);
}

.card__title {
  margin: 0;
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: -0.005em;
}

.card__meta {
  font-family: var(--mono);
  font-size: 9.5px;
  color: var(--muted);
  padding: 2px 6px;
  border: 1px solid var(--border-soft);
  border-radius: 4px;
  white-space: nowrap;
}

.card__meta.is-muted {
  opacity: 0.55;
}

.card__open {
  margin-left: auto;
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 3px 9px;
  font-size: 11px;
  color: var(--muted);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.12s;
}

.card:hover .card__open,
.card__open:focus-visible {
  opacity: 1;
}

.card__open:hover {
  color: var(--text);
  border-color: var(--muted);
}

.empty {
  padding: 40px 2px;
  color: var(--muted);
}

/* ---- detail view -------------------------------------------------------- */

.detail {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: none;
  place-items: center;
  padding: 24px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(3px);
}

body.has-detail .detail {
  display: grid;
}

.detail__panel {
  width: min(1040px, 100%);
  max-height: 100%;
  overflow-y: auto;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 18px;
}

.detail__head {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 12px;
}

.detail__title {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.detail__cat {
  margin: 2px 0 0;
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--muted);
}

.detail__nav {
  margin-left: auto;
  display: flex;
  gap: 6px;
}

.btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 5px 11px;
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
}

.btn:hover {
  color: var(--text);
  border-color: var(--muted);
}

.detail__stage {
  height: min(60vh, 520px);
  width: 100%;
}

.detail__code {
  margin-top: 14px;
  border-top: 1px solid var(--border-soft);
  padding-top: 10px;
}

.detail__code summary {
  cursor: pointer;
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.detail__codebar {
  display: flex;
  justify-content: flex-end;
  margin: 8px 0 -2px;
}

.detail__code pre {
  max-height: 300px;
  overflow: auto;
  background: var(--bg);
  border: 1px solid var(--border-soft);
  border-radius: 8px;
  padding: 12px;
  margin: 8px 0 0;
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1.5;
  color: var(--muted);
}

/* ---- narrow ------------------------------------------------------------- */

.panel-toggle {
  display: none;
  position: fixed;
  z-index: 40;
  top: 12px;
  right: 12px;
  background: var(--panel-bg);
  border: 1px solid var(--panel-input-edge);
  border-radius: 8px;
  padding: 9px 14px;
  color: var(--panel-text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

@media (max-width: 900px) {
  .panel-toggle {
    display: block;
  }

  .app {
    grid-template-columns: minmax(0, 1fr);
  }

  .panel {
    position: fixed;
    inset: 0 0 0 auto;
    width: 328px;
    max-width: 90vw;
    z-index: 30;
    transform: translateX(102%);
    transition: transform 0.18s ease;
    box-shadow: var(--shadow);
  }

  body.rail-open .panel {
    transform: none;
  }

  /* Keep the brand row clear of the fixed toggle overlapping it. */
  .brand {
    padding-right: 78px;
  }

  .gallery {
    padding-top: 56px;
  }

  .grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition-duration: 0.01ms !important;
  }
}
