/* Chip. Day 29/30.
   A palette of five, generated from colour theory or lifted out of a photo.

   The one rule this file exists to enforce: the palette is the only colour on
   the page. Every value below is either a neutral grey or is derived at runtime
   from the palette itself (--c, --onc). There is no accent, no brand hue, no
   tinted shadow. When the strip is empty the page has no colour at all, which
   is the point.

   The ground is deliberately locked to light. Simultaneous contrast is real:
   the same hex reads warmer against a dark surround and cooler against a light
   one. A tool people use to judge colour should not quietly change the
   conditions of that judgement, so there is no dark theme here. */

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

:root {
  /* A cool, true-neutral lab grey. Not cream, not warm paper. */
  --paper:  #E8E9EA;
  --panel:  #F2F3F4;
  --ink:    #141518;
  --ink-2:  rgb(20 21 24 / 0.62);
  --line:   rgb(20 21 24 / 0.14);
  --line-2: rgb(20 21 24 / 0.26);

  --grotesk: "Schibsted Grotesk", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono:    "DM Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --label:   "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;

  /* One easing for everything, so the whole page moves with one accent. */
  --ease: cubic-bezier(0.22, 1, 0.36, 1);

  --bar-top: 64px;
  --bar-bot: 66px;
}

html, body { height: 100%; }

body {
  margin: 0;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--grotesk);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

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

/* ---------------------------------------------------------------- the bars */

.bar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding-inline: max(0.9rem, env(safe-area-inset-left)) max(0.9rem, env(safe-area-inset-right));
  background: var(--paper);
  z-index: 3;
}

.bar-top {
  height: var(--bar-top);
  padding-top: env(safe-area-inset-top);
  border-bottom: 1px solid var(--line);
  justify-content: space-between;
}

.bar-bottom {
  min-height: var(--bar-bot);
  padding-bottom: max(0px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
}

.wordmark {
  margin: 0;
  font-size: 1.0625rem;
  font-weight: 700;
  letter-spacing: -0.022em;
}

/* The mode switch. A segmented control, not two buttons: the two options are
   one decision, and the knob makes that legible. */
.modes {
  position: relative;
  display: flex;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
}

.mode {
  position: relative;
  z-index: 1;
  min-height: 44px;
  padding-inline: 0.9rem;
  border: 0;
  border-radius: 999px;
  background: none;
  color: var(--ink-2);
  font-family: var(--grotesk);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: color 200ms var(--ease);
  -webkit-tap-highlight-color: transparent;
}

.mode[aria-selected="true"] { color: var(--paper); }

/* The knob sits behind both labels and slides between them. */
.modes::before {
  content: "";
  position: absolute;
  z-index: 0;
  top: 3px; bottom: 3px; left: 3px;
  width: var(--knob-w, 50%);
  transform: translateX(var(--knob-x, 0px));
  border-radius: 999px;
  background: var(--ink);
  transition: transform 320ms var(--ease), width 320ms var(--ease);
}

/* Before script measures the knob, keep it hidden rather than wrong. */
.modes:not([data-ready])::before { opacity: 0; }
.modes:not([data-ready]) .mode[aria-selected="true"] { color: var(--ink); }

/* ------------------------------------------------------------- the buttons */

.btn {
  min-height: 44px;
  padding-inline: 1.1rem;
  border: 1px solid var(--ink);
  border-radius: 999px;
  background: var(--ink);
  color: var(--paper);
  font-family: var(--grotesk);
  font-size: 0.875rem;
  font-weight: 600;
  letter-spacing: -0.005em;
  cursor: pointer;
  transition: transform 140ms var(--ease), background-color 180ms var(--ease);
  -webkit-tap-highlight-color: transparent;
}

.btn:active { transform: scale(0.975); }

.btn-quiet {
  border-color: var(--line-2);
  background: transparent;
  color: var(--ink);
}

.btn-save { flex: none; }

/* No palette yet, nothing to save. */
body[data-mode="extract"][data-extract="empty"]   .btn-save,
body[data-mode="extract"][data-extract="error"]   .btn-save,
body[data-mode="extract"][data-extract="working"] .btn-save { display: none; }

.hint {
  flex: 1;
  margin: 0;
  min-width: 0;
  font-family: var(--label);
  font-size: 0.625rem;
  font-weight: 400;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-2);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* The one thread every build in this series shares. Bottom right, always on
   the neutral bar so it never has to survive an arbitrary palette colour. */
.day {
  margin: 0;
  flex: none;
  font-family: var(--label);
  font-size: 0.625rem;
  font-weight: 500;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--ink-2);
}

/* --------------------------------------------------------------- the stage */

.stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
}

.strip {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  margin: 0;
  padding: 0;
  list-style: none;
}

.strip[hidden] { display: none; }

.band {
  position: relative;
  display: flex;
  align-items: center;
  flex: var(--w, 1) 1 0;
  min-height: 46px;
  overflow: hidden;
  background: var(--c, var(--panel));
  transition: flex-grow 560ms var(--ease);
}

/* The incoming colour, parked off the top edge until a deal sweeps it in. */
.wipe {
  position: absolute;
  inset: 0;
  z-index: 1;
  background: var(--n, transparent);
  transform: translate3d(0, -101%, 0);
  pointer-events: none;
  will-change: transform;
}

.chip {
  position: relative;
  z-index: 0;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex: 1 1 auto;
  min-width: 0;
  align-self: stretch;
  padding-inline: max(1.15rem, env(safe-area-inset-left)) 0.75rem;
  border: 0;
  background: none;
  color: var(--onc, #fff);
  font: inherit;
  text-align: left;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.chip:focus-visible {
  outline: 2px solid var(--onc, #fff);
  outline-offset: -8px;
  border-radius: 2px;
}

.line {
  display: flex;
  align-items: baseline;
  gap: 0.7rem;
  min-width: 0;
  transition: opacity 160ms var(--ease), transform 240ms var(--ease);
}

.hex {
  font-family: var(--mono);
  font-size: clamp(1.0625rem, 4.4vw, 1.375rem);
  font-weight: 400;
  letter-spacing: 0.045em;
}

/* The affordance sits where the affordance is, not in a legend at the bottom
   of the page, and only on the top chip. It is gone for good after the first
   copy: an instruction that stays after it has been followed is clutter. */
.cue {
  font-family: var(--label);
  font-size: 0.5625rem;
  font-weight: 400;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  opacity: 0.66;
  white-space: nowrap;
}

.band:not(:first-child) .cue,
body[data-taught] .cue { display: none; }

/* "Copied" replaces the hex in place. Same mono, lighter weight, so the swap
   reads as the same object changing its mind rather than a new element. */
.note {
  position: absolute;
  left: max(1.15rem, env(safe-area-inset-left));
  font-family: var(--mono);
  font-size: clamp(1.0625rem, 4.4vw, 1.375rem);
  font-weight: 300;
  letter-spacing: 0.045em;
  opacity: 0;
  transform: translateY(0.5em);
  transition: opacity 160ms var(--ease), transform 240ms var(--ease);
}

.band[data-copied] .line  { opacity: 0; transform: translateY(-0.45em); }
.band[data-copied] .note  { opacity: 1; transform: translateY(0); }

/* Hold a colour and the next deal builds around it instead of replacing it.
   The control is a word, not an icon: this page has no icon set and inventing
   a padlock glyph for one control would be worse than saying what it does.
   Locked inverts into the band's own contrast ink, so the state change costs
   the page no new colour. */
.lock {
  position: relative;
  z-index: 3;
  flex: none;
  min-height: 44px;
  margin-right: max(0.7rem, env(safe-area-inset-right));
  padding-inline: 0.85rem;
  border: 1px solid var(--onc, #fff);
  border-radius: 999px;
  background: none;
  color: var(--onc, #fff);
  font-family: var(--label);
  font-size: 0.5625rem;
  font-weight: 500;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  opacity: 0.5;
  cursor: pointer;
  transition: opacity 200ms var(--ease), background-color 200ms var(--ease),
              color 200ms var(--ease);
  -webkit-tap-highlight-color: transparent;
}

.lock:hover, .lock:focus-visible { opacity: 0.8; }

.lock[aria-pressed="true"] {
  opacity: 1;
  background: var(--onc, #fff);
  color: var(--c, #000);
}

.lock:focus-visible { outline: 2px solid var(--onc, #fff); outline-offset: 3px; }

/* Nothing to reroll when the colours came out of a photograph. */
body[data-mode="extract"] .lock { display: none; }

/* A held-in ring, drawn in the band's own contrast ink so it works on any
   colour without introducing a second one. */
.band::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 2;
  box-shadow: inset 0 0 0 0 var(--onc, #fff);
  opacity: 0;
  pointer-events: none;
  transition: box-shadow 220ms var(--ease), opacity 320ms var(--ease);
}

.band[data-copied]::after {
  box-shadow: inset 0 0 0 2px var(--onc, #fff);
  opacity: 0.55;
}

/* Hairlines between bands, so two close colours never bleed into one another
   and the top and bottom bands stay distinct from the paper. */
.band + .band { box-shadow: inset 0 1px 0 rgb(20 21 24 / 0.10); }

/* ---------------------------------------------------------------- the panes */

.pane {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.85rem;
  padding: 1.25rem;
  background: var(--paper);
  text-align: center;
}

.pane[hidden] { display: none; }

.pane-pick, .pane-fail { padding: 0; }

.drop, .fail {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  cursor: pointer;
}

/* The empty strip. Same proportions the real palette will take, so the layout
   is legible before there is anything in it. */
.ghost {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
}

/* The middle band is the widest so the instruction sits inside one plate
   rather than straddling a divider. */
.ghost i {
  flex: var(--w, 1) 1 0;
  min-height: 46px;
  border-bottom: 1px dashed var(--line);
  transition: border-color 220ms var(--ease);
}

.ghost i:nth-child(odd) { background: var(--panel); }
.ghost i:last-child { border-bottom: 0; }

.drop:hover .ghost i,
.drop:focus-within .ghost i,
.drop[data-over] .ghost i { border-color: var(--line-2); }

.drop-copy, .fail {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.55rem;
  text-align: center;
}

.drop-copy {
  position: absolute;
  inset: 0;
  padding: 1.25rem;
}

.fail { padding: 1.25rem; }

.drop-title, .fail-title {
  max-width: 18ch;
  font-size: 1.25rem;
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: -0.02em;
  text-wrap: balance;
}

.fail-title { max-width: 24ch; font-size: 1.125rem; }

.drop-note, .fail-note {
  max-width: 32ch;
  font-size: 0.8125rem;
  line-height: 1.5;
  color: var(--ink-2);
  text-wrap: pretty;
}

.work-title {
  margin: 0;
  font-family: var(--label);
  font-size: 0.6875rem;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--ink-2);
}

.work-bar {
  width: 132px;
  height: 2px;
  border-radius: 2px;
  background: var(--line);
  overflow: hidden;
}

.work-bar::before {
  content: "";
  display: block;
  width: 40%;
  height: 100%;
  background: var(--ink);
  animation: sweep 900ms var(--ease) infinite;
}

@keyframes sweep {
  from { transform: translateX(-110%); }
  to   { transform: translateX(360%); }
}

/* ----------------------------------------------------- wider and shorter */

/* Two triggers, one layout: a real wide screen, and a phone on its side. Both
   want the strip running horizontally, because both have height to spare in
   the wrong direction. */
@media (min-width: 720px), (orientation: landscape) and (max-height: 560px) {
  .strip { flex-direction: row; }

  .band {
    min-height: 0;
    min-width: 56px;
  }

  .band + .band { box-shadow: inset 1px 0 0 rgb(20 21 24 / 0.10); }

  .wipe { transform: translate3d(-101%, 0, 0); }

  .band { flex-direction: column; align-items: stretch; }

  .chip {
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    padding: 0.5rem 0.5rem 1.25rem;
  }

  .lock {
    order: -1;
    align-self: center;
    margin: 1rem 0 0;
  }

  .cue { display: none; }

  .ghost { flex-direction: row; }
  .ghost i {
    min-height: 0;
    min-width: 56px;
    border-bottom: 0;
    border-right: 1px dashed var(--line);
  }
  .ghost i:last-child { border-right: 0; }

  .hex { font-size: 0.9375rem; }

  .note {
    left: auto;
    bottom: 1.25rem;
  }
}

@media (orientation: landscape) and (max-height: 560px) {
  :root { --bar-top: 50px; --bar-bot: 56px; }
  .drop { padding: 0.75rem; gap: 0.4rem; }
  .drop-title { font-size: 1rem; }
}

@media (min-width: 720px) {
  :root { --bar-top: 68px; --bar-bot: 72px; }

  .bar { padding-inline: 1.5rem; gap: 1.25rem; }
  .wordmark { font-size: 1.1875rem; }
  .hint { letter-spacing: 0.2em; }
  .hex { font-size: 1.0625rem; }
  .note { font-size: 1.0625rem; }
}

/* Below 360px the hint is the first thing to go: two buttons and the day label
   all have to keep their full width. */
/* Two buttons and the day label own the bottom bar on a phone, so the written
   hint moves onto the top chip (see .cue) and the bar keeps only controls. */
@media (max-width: 719px) {
  .hint { display: none; }
}

/* A phone on its side is under 720px wide but is running the row layout, where
   the strip no longer needs the chip cue. Give the hint back if the bar can
   take it. Ordered after the rule above so it wins. */
@media (orientation: landscape) and (max-height: 560px) and (min-width: 600px) {
  .hint { display: block; }
}

@media (max-width: 359px) {
  .bar-bottom { gap: 0.5rem; padding-inline: 0.7rem; }
  .btn { padding-inline: 0.8rem; font-size: 0.8125rem; }
}

/* -------------------------------------------------------- reduced motion */

@media (prefers-reduced-motion: reduce) {
  .band { transition: none; }
  .modes::before { transition: none; }
  .work-bar::before { animation: none; width: 100%; opacity: 0.4; }
  .btn:active { transform: none; }
}
