:root {
    --ink:      #0d1013;
    --panel:    #14181d;
    --line:     #232a31;
    --text:     #c8d0d6;
    --dim:      #6f7d88;
    --accent:   #7fd4c1;
    --warn:     #d98a5c;
  }
  * { box-sizing: border-box; }
  html, body {
    margin: 0; height: 100%; overflow: hidden;
    background: var(--ink); color: var(--text);
    font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  }
  #app { display: flex; height: 100%; }

  /* ---- control rail ---- */
  #rail {
    width: 300px; flex: none; background: var(--panel);
    border-right: 1px solid var(--line);
    display: flex; flex-direction: column; overflow: hidden;
  }
  #railscroll { flex: 1 1 auto; overflow-y: auto; padding: 16px 16px 24px; }
  #railfoot {
    flex: none; padding: 10px 16px;
    border-top: 1px solid var(--line); background: var(--panel);
  }
  #tipstoggle {
    margin-top: 8px;
    color: var(--dim);
    font-size: 10px;
    letter-spacing: .04em;
  }
  #tipstoggle:hover { color: var(--text); }
  #railfoot button + button { margin-top: 6px; }
  #railfoot button {
    margin: 0; text-align: center;
    background: var(--accent); color: var(--ink);
    border-color: var(--accent);
    font-weight: 600; letter-spacing: .04em;
    padding: 9px;
  }
  #railfoot button:hover {
    background: #9ae2d2; border-color: #9ae2d2; color: var(--ink);
  }
  #railfoot button:active { background: #6bc0af; border-color: #6bc0af; }
  #railfoot button:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }
  h1 {
    font-size: 12px; font-weight: 600; letter-spacing: .18em;
    text-transform: uppercase; margin: 0 0 2px; color: var(--text);
  }
  .sub { color: var(--dim); margin: 0 0 18px; font-size: 11px; }

  .group { margin-bottom: 20px; }
  .group > legend, .grouphead {
    font-size: 10px; letter-spacing: .16em; text-transform: uppercase;
    color: var(--dim); margin-bottom: 8px; display: block;
    border-bottom: 1px solid var(--line); padding-bottom: 5px;
  }

  button, .filebtn {
    display: block; width: 100%; text-align: left;
    background: #1b2128; color: var(--text);
    border: 1px solid var(--line); border-radius: 3px;
    padding: 7px 9px; margin-bottom: 6px; cursor: pointer;
    font: inherit;
  }
  button:hover, .filebtn:hover { border-color: var(--accent); color: #fff; }
  button:focus-visible, .filebtn:focus-visible {
    outline: 2px solid var(--accent); outline-offset: 1px;
  }
  input[type=file] { display: none; }
  .fname { color: var(--dim); font-size: 11px; margin: -2px 0 10px;
           white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .fname.set { color: var(--accent); }

  .row { display: flex; justify-content: space-between; align-items: baseline;
         margin-top: 10px; }
  .row label { color: var(--text); flex: 1; min-width: 0; }
  .row output { flex: none; margin-left: 8px; }
  .row output { color: var(--accent); font-variant-numeric: tabular-nums; }
  input[type=range] { width: 100%; margin: 2px 0 0; accent-color: var(--accent); }
  .chk { display: flex; align-items: center; gap: 7px; margin-top: 9px;
         cursor: pointer; }
  .chk input { accent-color: var(--accent); }
  .tip { color: var(--dim); font-size: 10px; margin: 2px 0 0 22px; }
  .tip kbd {
    background: #1b2128; border: 1px solid var(--line); border-radius: 3px;
    padding: 0 4px; color: var(--accent); font: inherit;
  }

  /* the signature element: live palette strip */
  #swatches {
    display: flex; height: 30px; width: 100%; margin: 8px 0 4px;
    border: 1px solid var(--line); border-radius: 3px; overflow: hidden;
  }
  #swatches i { flex: 1 1 0; }
  #palinfo { color: var(--dim); font-size: 11px; }
#palsource {
  color: var(--text);
  font-size: 11px;
  margin-bottom: 6px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#palsource b { color: var(--accent); font-weight: 600; }
#palsource .none { color: var(--dim); }
  #i_ref {
    display: block; width: 100%; height: 62px; margin: 2px 0 8px;
    border: 1px solid var(--line); border-radius: 3px; background: #0a0d10;
  }
  #swatches i { cursor: pointer; position: relative; overflow: hidden; }
  #swatches i .bar {
    position: absolute; left: 0; right: 0; bottom: 0;
    background: rgba(255, 255, 255, .55);
    border-top: 1px solid rgba(255, 255, 255, .9);
    pointer-events: none;
  }
  #swatches i.unused::after {
    content: ''; position: absolute; inset: 0; pointer-events: none;
    background: repeating-linear-gradient(45deg,
      rgba(0,0,0,.55) 0 2px, rgba(0,0,0,0) 2px 4px);
  }
  #swatches i.sel { outline: 2px solid var(--accent); outline-offset: -2px; z-index: 1; }
  .btnrow { display: flex; flex-wrap: wrap; gap: 4px; margin: 6px 0; }
  .btnrow > * { margin: 0; }
  .btnrow button:disabled {
    background: transparent; border-color: var(--line); border-style: dashed;
    color: var(--dim); font-weight: 400; opacity: .5; cursor: not-allowed;
  }

  /* history sits above the first group, separated like a header */
  .history { margin: 0 0 14px; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
  .history .arrow {
    font-size: 2em; line-height: 0; margin-right: 6px;
    transform: translateY(-.025em);
    display: inline-block; vertical-align: middle;
  }
  .btnrow button {
    width: auto; flex: 1 0 auto; min-width: 46px;
    text-align: center; padding: 5px 4px;
  }
  .btnrow input[type=color] {
    width: 34px; height: 28px; padding: 0; border: 1px solid var(--line);
    border-radius: 3px; background: #1b2128; cursor: pointer; flex: none;
  }
  .btnrow > label {
    flex: none; align-self: center;
    color: var(--text);
    white-space: nowrap;
  }
  .btnrow input[type=text] {
    flex: 1; min-width: 0; background: #1b2128; color: var(--text);
    border: 1px solid var(--line); border-radius: 3px; padding: 5px 6px;
    font: inherit;
  }
  .btnrow select { flex: none; width: 72px; }
  .only-aniso, .only-shock, .only-l0 { display: none; }
  .only-oklab { display: block; }
  #rail.match-rgb .only-oklab { display: none; }
  /* the whole matching section is meaningless with reduction off */
  #rail.no-reduce .needs-palette { display: none; }
  .only-pip { display: none; }
  #rail.pip-on .only-pip { display: block; }
  .only-bayer { display: block; }
  .only-halftone { display: none; }
  #rail.d-blue .only-bayer,
  #rail.d-halftone .only-bayer { display: none; }
  #rail.d-halftone .only-halftone { display: block; }
  #rail.f-aniso .only-aniso,
  #rail.f-shock .only-shock,
  #rail.f-l0 .only-l0 { display: block; }
  #rail.f-l0 .not-l0 { display: none; }
  #rail.f-none .needs-filter { display: none; }
  #palinfo b { color: var(--accent); font-weight: 600; }

  select {
    width: 100%; background: #1b2128; color: var(--text);
    border: 1px solid var(--line); border-radius: 3px;
    padding: 6px 8px; font: inherit;
  }

  /* ---- viewport ---- */
  #view { flex: 1; position: relative; min-width: 0; overflow: hidden; }

  /* collapsing the panel hands the whole window to the preview, which is
     what you want when judging a texture rather than adjusting one */
  #app.railhidden #rail { display: none; }

  #railtoggle {
    position: absolute; left: 10px; top: 12px; z-index: 4;
    width: 26px; height: 26px; padding: 0; margin: 0;
    display: flex; align-items: center; justify-content: center;
    background: #14181dd1;
    border: 1px solid var(--line); border-radius: 3px;
    color: var(--dim);
    font-family: system-ui, -apple-system, 'Segoe UI Symbol', sans-serif;
    font-size: 12px; line-height: 1; cursor: pointer;
  }
  #railtoggle:hover { color: var(--accent); border-color: var(--accent); }
  #railtoggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
  #view > canvas {
    position: absolute; top: 0; left: 0; z-index: 0;
    width: 100% !important; height: 100% !important;
    display: block;
  }
  #view > canvas.lowres { image-rendering: pixelated; }
  #inspect canvas { position: static; }
  #hint {
    position: absolute; inset: 0; z-index: 2; display: flex; align-items: center;
    justify-content: center; pointer-events: none; color: var(--dim);
    text-align: center; padding: 40px; font-size: 13px; line-height: 1.9;
  }
  #hint span { max-width: 34em; }
  #hint b { font-weight: 600; }
  #hint.hide { display: none; }
  #hint b { color: var(--accent); font-weight: 600; }

  #inspect {
    position: absolute; left: 12px; bottom: 12px; z-index: 2;
    display: flex; gap: 8px;
    background: rgba(13,16,19,.82); border: 1px solid var(--line);
    border-radius: 4px; padding: 8px;
  }
  #inspect figure { margin: 0; }
  #inspect canvas {
    width: 92px; height: 92px; image-rendering: pixelated;
    border: 1px solid var(--line); background: #000;
  }
  #inspect figcaption {
    color: var(--dim); font-size: 10px; letter-spacing: .1em;
    text-transform: uppercase; margin-top: 4px;
  }
  /* only a frame: the picture itself is drawn by WebGL into a scissor rect */
  #pipframe {
    position: absolute; z-index: 2; display: none;
    border: 1px solid var(--line);
    box-shadow: 0 4px 16px rgba(0, 0, 0, .5);
    pointer-events: none;
  }
  #pipframe.on { display: block; }
  #pipframe::after {
    content: attr(data-label);
    position: absolute; left: 5px; bottom: 4px;
    color: var(--dim); font-size: 10px; letter-spacing: .1em;
    text-shadow: 0 1px 3px #000;
  }

  #stats {
    position: absolute; right: 12px; top: 12px; z-index: 2; text-align: right;
    color: var(--dim); font-size: 11px; line-height: 1.8;
    background: rgba(13,16,19,.82); border: 1px solid var(--line);
    border-radius: 4px; padding: 8px 11px;
  }
  #stats b { color: var(--accent); font-weight: 600; }
  #app.statshidden #stats { display: none; }

  /* Matches the panel toggle, and both match Noisy: full opacity, and a
     system font so the glyphs render the same way the monospace stack does
     not guarantee. */
  #helptoggle {
    position: absolute; left: 42px; top: 12px; z-index: 4;
    width: 26px; height: 26px; padding: 0; margin: 0;
    display: flex; align-items: center; justify-content: center;
    background: #14181dd1;
    border: 1px solid var(--line); border-radius: 3px;
    color: var(--dim);
    font-family: system-ui, -apple-system, 'Segoe UI Symbol', sans-serif;
    font-size: 12px; line-height: 1; cursor: pointer;
  }
  #helptoggle:hover,
  #helptoggle[aria-expanded="true"] {
    color: var(--accent); border-color: var(--accent);
  }
  #helptoggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

  #keyshelp {
    position: absolute; inset: 0; z-index: 9; display: none;
    align-items: center; justify-content: center;
    background: rgba(9, 11, 13, .78);
    cursor: pointer;
  }
  #keyshelp.on { display: flex; }
  #keyshelp .kpanel {
    background: var(--panel);
    border: 1px solid var(--line); border-radius: 4px;
    padding: 20px 24px 16px;
    max-width: 460px; max-height: 86%; overflow: auto;
    box-shadow: 0 12px 40px rgba(0, 0, 0, .55);
  }
  #keyshelp h2 {
    margin: 0 0 14px; font-size: 12px; font-weight: 600;
    letter-spacing: .12em; text-transform: uppercase; color: var(--accent);
  }
  #keyshelp h3 {
    margin: 14px 0 6px; font-size: 10px; font-weight: 600;
    letter-spacing: .12em; text-transform: uppercase; color: var(--dim);
  }
  #keyshelp section:first-of-type h3 { margin-top: 0; }
  #keyshelp .krow {
    display: flex; align-items: baseline; gap: 12px;
    padding: 2px 0; font-size: 11px; color: var(--text);
  }
  #keyshelp .krow kbd {
    flex: none; min-width: 92px;
    color: var(--accent); font-size: 10px;
  }
  #keyshelp .kfoot {
    margin: 16px 0 0; color: var(--dim); font-size: 10px;
  }

  #slots {
    position: absolute; left: 10px; top: 46px; z-index: 4;
    display: flex; gap: 4px;
  }
  #slots button {
    width: 24px; height: 24px; padding: 0; margin: 0;
    display: flex; align-items: center; justify-content: center;
    background: rgba(20, 24, 29, .82);
    border: 1px solid var(--line); border-radius: 3px;
    color: var(--dim); font: inherit; font-size: 10px; line-height: 1;
    cursor: pointer; opacity: .45;
  }
  #slots button:hover { opacity: 1; border-color: var(--accent); color: var(--accent); }
  #slots button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
  /* a filled slot reads as available at a glance, without shouting */
  #slots button.filled { opacity: .8; color: var(--text); border-color: #3a4650; }
  #slots button.active {
    opacity: 1; color: var(--bg); background: var(--accent); border-color: var(--accent);
  }

  #slotinfo {
    position: absolute; left: 10px; top: 76px; z-index: 4;
    color: var(--dim); font-size: 10px; letter-spacing: .04em;
    opacity: 0; transition: opacity .18s;
    pointer-events: none;
  }
  #slotinfo.on { opacity: 1; }

  #statstoggle {
    position: absolute; right: 12px; top: 12px; z-index: 5;
    width: 22px; height: 22px; padding: 0; margin: 0;
    display: flex; align-items: center; justify-content: center;
    background: rgba(20, 24, 29, .82);
    border: 1px solid var(--line); border-radius: 3px;
    color: var(--dim); font-size: 8px; line-height: 1;
    cursor: pointer; opacity: .45;
  }
  #statstoggle:hover { opacity: 1; color: var(--accent); border-color: var(--accent); }
  #statstoggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
  /* out of the readout's way while it is showing */
  #app:not(.statshidden) #statstoggle { top: 12px; right: 12px; }
  #app:not(.statshidden) #stats { margin-right: 28px; }
  #abbadge {
    position: absolute; left: 50%; top: 14px; transform: translateX(-50%);
    z-index: 3; padding: 4px 14px; border-radius: 3px;
    font-size: 13px; font-weight: 600; letter-spacing: .16em;
    background: var(--accent); color: #0d1013; display: none;
  }
  #abbadge.on { display: block; }
  #stats .warn { color: var(--warn); }
  @media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

.fold, #lights {
  margin: 10px 0 4px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 2px 0;
}
.fold > summary, #lights > summary {
  cursor: pointer;
  list-style: none;
  padding: 6px 0;
  color: var(--dim);
  font-size: 10px;
  letter-spacing: .16em;
  text-transform: uppercase;
  user-select: none;
}
.fold > summary::-webkit-details-marker,
#lights > summary::-webkit-details-marker { display: none; }
.fold > summary::after, #lights > summary::after {
  content: '+';
  float: right;
  color: var(--dim);
  font-size: 12px;
  line-height: 1;
}
.fold[open] > summary::after,
#lights[open] > summary::after { content: '\2212'; }   /* minus */
.fold > summary:hover, #lights > summary:hover { color: var(--text); }
.fold[open] > summary, #lights[open] > summary { color: var(--text); }
#lights > *:last-child { margin-bottom: 8px; }

/* top-level folds read as sections, so they get the group spacing and a
   slightly stronger heading than the nested Lighting fold */
.fold {
  margin: 0 0 20px;
  border-top: none;
  border-bottom: 1px solid var(--line);
  padding: 0;
}
.fold > summary { padding: 0 0 6px; }
.fold[open] { padding-bottom: 8px; }
.fold > *:last-child { margin-bottom: 0; }

/* extraction is a manual step, unlike loading a .hex; flag when the palette
   no longer matches the reference or the colour count */
button.stale {
  border-color: var(--accent);
  color: var(--accent);
}
button.stale:hover { background: var(--accent); color: var(--ink); }
button:disabled {
  opacity: .38;
  cursor: default;
}
button:disabled:hover { border-color: var(--line); color: var(--text); }

#capture {
  position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%);
  z-index: 3; width: auto; margin: 0;
  padding: 6px 13px;
  background: rgba(20, 24, 29, .82);
  border: 1px solid var(--line); border-radius: 3px;
  color: var(--dim); font: inherit; font-size: 11px;
  cursor: pointer; opacity: .55;
}
#capture:hover { opacity: 1; color: var(--accent); border-color: var(--accent); }
#capture:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* the stale-palette prompt stacks above the capture button, not over it */
#palhint {
  position: absolute; left: 50%; bottom: 52px; transform: translateX(-50%);
  z-index: 3; display: none; width: auto;
  padding: 7px 14px; margin: 0;
  border: 1px solid var(--accent); border-radius: 3px;
  background: rgba(13, 16, 19, .92); color: var(--accent);
  font: inherit; font-size: 11px; cursor: pointer;
}
#palhint.on { display: block; }
#palhint:hover { background: var(--accent); color: var(--ink); }

.sr {
  position: absolute; width: 1px; height: 1px;
  margin: -1px; padding: 0; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

#tooltip {
  position: fixed; z-index: 40; max-width: 268px;
  padding: 9px 11px;
  background: #1b2128; color: var(--text);
  border: 1px solid var(--line); border-left: 2px solid var(--accent);
  border-radius: 3px;
  font-size: 11px; line-height: 1.55;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .45);
  opacity: 0; visibility: hidden;
  transition: opacity .12s ease;
  pointer-events: none;
}
#tooltip.on { opacity: 1; visibility: visible; }
@media (prefers-reduced-motion: reduce) { .sr {
  position: absolute; width: 1px; height: 1px;
  margin: -1px; padding: 0; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

#tooltip { transition: none; } }

#b_zipbtn { text-align: center; }
/* only carries the accent once a folder is chosen; otherwise it recedes */
#railfoot #b_run:disabled {
  background: #1b2128;
  border-color: var(--line);
  color: var(--dim);
  font-weight: 400;
  cursor: default;
  opacity: 1;
}
#railfoot #b_run:disabled:hover { background: #1b2128; color: var(--dim); }
#b_status b { color: var(--accent); font-weight: 600; }

#version {
  margin: 18px 0 0;
  color: var(--dim);
  font-size: 10px;
  letter-spacing: .06em;
  opacity: .55;
}

#credits { margin-top: 4px; }
#credits p {
  margin: 0 0 9px;
  color: var(--dim);
  font-size: 10px;
  line-height: 1.65;
}
#credits p:last-child { margin-bottom: 2px; }
#credits b { color: var(--text); font-weight: 600; }
#credits a {
  color: var(--dim);
  text-decoration: underline;
  text-underline-offset: 2px;
}
#credits a:hover { color: var(--accent); }
#credits a:focus-visible { outline: 1px solid var(--accent); outline-offset: 2px; }

#credit, #othertools {
  color: var(--dim);
  font-size: 10px;
  letter-spacing: .04em;
  opacity: .65;
}
#credit {
  margin: 26px 0 0;
  padding-top: 12px;
  border-top: 1px solid var(--line);   /* the separator belongs to the first */
}
#othertools { margin: 3px 0 0; }
#credit a, #othertools a {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
}
#credit a:hover, #othertools a:hover { color: var(--accent); }
#credit a:focus-visible,
#kofi a:focus-visible {
  outline: 1px solid var(--accent);
  outline-offset: 2px;
}

#kofi {
  margin: 16px 0 0;          /* a clear break from the credit above */
  font-size: 11px;
  letter-spacing: .04em;
}
#kofi a {
  display: inline-flex; align-items: center; gap: 5px;
  color: var(--text);        /* brighter than the credit, still not loud */
  text-decoration: none;
  opacity: .85;
}
#kofi a:hover { color: var(--accent); opacity: 1; }
#kofi svg { flex: none; width: 13px; height: 13px; }
