/*
 * GRADE - section 5, second pass.
 *
 * The brief says "a laboratory sheet, not a game screen", and the first pass
 * took that literally: flat paper, hairlines, everything at one size. It read
 * as a form to fill in rather than an instrument to operate.
 *
 * This pass keeps every colour the brief specifies and changes how they are
 * used. A grade-control bench is not a sheet of paper - it is a machine that
 * measures - so the page is built from the vocabulary of one: a recessed
 * specimen well, a graduated gauge, stamped keys, a status strip.
 *
 * The rule that still holds absolutely: colour belongs to the sample. Depth
 * here is made from the ink and paper already in the palette, never a new hue,
 * and the alarm red still appears in exactly one place.
 */

:root {
  /* The brief's palette, unchanged. */
  --paper: #f6f5f1;
  --ink: #14161a;
  --rule: rgba(20, 22, 26, 0.2);
  --faint: #9aa0a8;
  --alarm: #b5352a;

  /* Derived from the above, not added to it: paper in shadow, paper in light,
   * and a rule with enough weight to read as a machined edge. */
  --paper-sunk: #eceae3;
  --paper-raised: #fbfaf7;
  --rule-strong: rgba(20, 22, 26, 0.42);

  /* The five ore colours - still the only saturated things on screen. */
  --ore-rust: #a9481f;
  --ore-grey: #7e848a;
  --ore-olive: #6c6b30;
  --ore-pale: #ddd7c5;
  --ore-blue-black: #232f3d;

  --gutter: 16px;

  --sans: 'IBM Plex Sans', ui-sans-serif, system-ui, -apple-system, sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, 'SFMono-Regular', Consolas, monospace;
}

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

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

body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.35;
  -webkit-font-smoothing: antialiased;
  /* The belt is a game surface: no pull-to-refresh, no accidental selection. */
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
}

/* A trace of paper grain, sitting under the sheet so it never touches the ore.
 * One 120px tile, painted once - it is texture, not an effect. */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  opacity: 0.55;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3'/%3E%3C/filter%3E%3Crect width='120' height='120' filter='url(%23n)' opacity='.055'/%3E%3C/svg%3E");
}

/* Every number is Plex Mono with tabular figures, so values that change twice
 * a second cannot shift the layout under the player's thumb. */
.num {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-feature-settings: 'tnum' 1;
}

.sheet {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 460px;
  min-height: 100dvh;
  margin: 0 auto;
  padding-bottom: env(safe-area-inset-bottom);
}

/* -- masthead ------------------------------------------------------------ */

.masthead {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 16px var(--gutter) 10px;
}

.mark {
  min-width: 0;
}

.wordmark {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: 0.3em;
}

.eyebrow {
  margin: 4px 0 0;
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 0.14em;
  color: var(--faint);
}

.run {
  margin: 0;
  text-align: right;
  white-space: nowrap;
}

.run-shift {
  display: block;
  font-size: 9.5px;
  letter-spacing: 0.18em;
  color: var(--faint);
}

/* The clock is the second-largest number on screen, after the mass. */
.run-clock {
  display: block;
  margin-top: 1px;
  font-size: 22px;
  font-weight: 500;
  letter-spacing: -0.01em;
  line-height: 1;
}

/* -- market status strip ------------------------------------------------- */

.market {
  display: flex;
  align-items: baseline;
  gap: 7px;
  margin: 0;
  padding: 8px var(--gutter);
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule-strong);
  background: var(--paper-sunk);
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.12em;
}

.key {
  color: var(--faint);
}

.market .val {
  font-weight: 600;
}

/* Where the price came from, flagged at the end of the strip. Faint, but never
 * absent: a cycled price must not be able to pass for a market reading. */
.src {
  margin-left: auto;
  padding: 2px 6px;
  border: 1px solid var(--rule);
  font-size: 9px;
  letter-spacing: 0.14em;
  color: var(--faint);
}

/* -- the assessment window ----------------------------------------------- */

.bench {
  position: relative;
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 20px;
  padding: 20px var(--gutter);
  border-bottom: 1px solid var(--rule-strong);
}

/* The specimen absorbs whatever height the screen has spare. Centring the block
 * instead left a band of empty paper above and below it on a tall phone, which
 * read as an unfinished layout rather than as breathing room. */
.specimen {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 18px;
  min-height: 0;
}

/* The specimen well: a recessed tray the sample sits in. This is the hero, and
 * it is the reason the rest of the sheet stays quiet. */
.well {
  position: relative;
  display: flex;
  flex: 1;
  min-height: 96px;
  max-height: 300px;
  padding: 7px;
  border: 1px solid var(--rule-strong);
  background: var(--paper-sunk);
  box-shadow: inset 0 2px 5px rgba(20, 22, 26, 0.1);
}

.swatch {
  flex: 1;
  border: 1px solid rgba(20, 22, 26, 0.28);
  background-color: var(--ore, transparent);
}

.swatch[data-colour='RUST'],
.ghost[data-colour='RUST'],
.misbin-chip[data-colour='RUST'] {
  --ore: var(--ore-rust);
}
.swatch[data-colour='GREY'],
.ghost[data-colour='GREY'],
.misbin-chip[data-colour='GREY'] {
  --ore: var(--ore-grey);
}
.swatch[data-colour='OLIVE'],
.ghost[data-colour='OLIVE'],
.misbin-chip[data-colour='OLIVE'] {
  --ore: var(--ore-olive);
}
.swatch[data-colour='PALE'],
.ghost[data-colour='PALE'],
.misbin-chip[data-colour='PALE'] {
  --ore: var(--ore-pale);
}
.swatch[data-colour='BLUE-BLACK'],
.ghost[data-colour='BLUE-BLACK'],
.misbin-chip[data-colour='BLUE-BLACK'] {
  --ore: var(--ore-blue-black);
}

/*
 * Ore as material, not as a colour chip.
 *
 * The texture attribute is already printed as a word; drawing it as well means
 * the player builds the association by looking rather than by reading, and it
 * makes the weathered trap something you can learn to recognise on sight. Every
 * layer is white or ink at low alpha over the ore colour, so no new hue enters
 * the page.
 */
.swatch[data-texture='GRANULAR'],
.ghost[data-texture='GRANULAR'],
.misbin-chip[data-texture='GRANULAR'] {
  background-image:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='96' height='96'%3E%3Cfilter id='g'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='4'/%3E%3C/filter%3E%3Crect width='96' height='96' filter='url(%23g)' opacity='.55'/%3E%3C/svg%3E"),
    radial-gradient(120% 90% at 30% 15%, rgba(255, 255, 255, 0.1), transparent 65%);
  background-size: 96px 96px, 100% 100%;
}

.swatch[data-texture='BANDED'],
.ghost[data-texture='BANDED'],
.misbin-chip[data-texture='BANDED'] {
  background-image: repeating-linear-gradient(
    64deg,
    rgba(255, 255, 255, 0.14) 0 3px,
    transparent 3px 9px,
    rgba(20, 22, 26, 0.17) 9px 12px,
    transparent 12px 21px
  );
}

.swatch[data-texture='MASSIVE'],
.ghost[data-texture='MASSIVE'],
.misbin-chip[data-texture='MASSIVE'] {
  background-image:
    radial-gradient(120% 90% at 25% 20%, rgba(255, 255, 255, 0.15), transparent 60%),
    radial-gradient(85% 70% at 80% 82%, rgba(20, 22, 26, 0.19), transparent 65%);
}

.swatch[data-texture='VITREOUS'],
.ghost[data-texture='VITREOUS'],
.misbin-chip[data-texture='VITREOUS'] {
  background-image:
    linear-gradient(104deg, transparent 30%, rgba(255, 255, 255, 0.32) 42%, transparent 53%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.1), rgba(20, 22, 26, 0.2));
}

/* The colour name, on a paper chip so it stays legible against pale ore and
 * blue-black alike. It reads as the label stuck to the sample. */
.tag {
  position: absolute;
  left: 15px;
  bottom: 15px;
  padding: 3px 7px;
  border: 1px solid var(--rule-strong);
  background: var(--paper);
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.14em;
}

/* -- the readout --------------------------------------------------------- */

.readout {
  display: grid;
  grid-template-columns: auto 1fr 1fr;
  gap: 0 16px;
  align-items: end;
  margin: 0;
}

.metric dd {
  margin: 0;
}

.metric dt {
  margin-top: 7px;
  font-size: 9px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--faint);
}

.metric-value {
  font-size: 15px;
  font-weight: 500;
  letter-spacing: 0.01em;
}

/* Mass is the number you scan first, so it is the one that gets the size. */
.metric--mass .metric-value {
  font-size: 38px;
  font-weight: 600;
  letter-spacing: -0.035em;
  line-height: 0.9;
}

.metric-unit {
  margin-left: 3px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--faint);
}

/* -- the streak test ----------------------------------------------------- */

.streak {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
}

.streak-label,
.streak-value {
  color: var(--faint);
}

.streak-label {
  font-size: 9px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
}

.streak-rule {
  flex: 1;
  height: 0;
  border-top: 1px dotted var(--rule);
}

.streak-value {
  font-size: 13px;
}

/* The reading is what HOLD was spent on, so it arrives at full ink. */
.streak[data-revealed='true'] .streak-label {
  color: var(--ink);
}

.streak[data-revealed='true'] .streak-value {
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
}

/* The binned sample on its way out. It sits at rest invisible and is only ever
 * seen mid-animation, which is why it can live outside .specimen and survive
 * the window emptying underneath it. */
.ghost {
  position: absolute;
  opacity: 0;
  pointer-events: none;
  border: 1px solid rgba(20, 22, 26, 0.28);
  background-color: var(--ore, transparent);
}

/* -- the draining timer -------------------------------------------------- */

.timer {
  display: flex;
  align-items: center;
  gap: 12px;
}

.timer-track {
  position: relative;
  flex: 1;
  height: 12px;
  overflow: hidden;
  border: 1px solid var(--rule-strong);
  background: var(--paper-sunk);
}

.timer-fill {
  height: 100%;
  width: 100%;
  background: var(--ink);
  transform-origin: left center;
}

/*
 * Graduations, painted over the fill rather than into it.
 *
 * Putting the ticks on the bar itself would scale them along with the drain and
 * turn a measuring scale into a stretching stripe. Above it, they stay put and
 * the ink recedes past them - which is what a gauge does.
 */
.timer-track::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(
    90deg,
    transparent 0 8px,
    var(--paper) 8px 9px
  );
}

/* A held sample is frozen, and the bar says so by stopping and going faint. */
.bench[data-held='true'] .timer-fill {
  background: var(--faint);
}

.timer-value {
  min-width: 46px;
  text-align: right;
  font-size: 14px;
  font-weight: 500;
  color: var(--faint);
}

.bench[data-held='true'] .timer-value {
  color: var(--ink);
}

/* -- queue --------------------------------------------------------------- */

.queue {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px var(--gutter);
  border-bottom: 1px solid var(--rule-strong);
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.14em;
}

.queue-meter {
  display: flex;
  flex: 1;
  gap: 3px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.slot {
  flex: 1;
  height: 16px;
  border: 1px solid var(--rule);
  background: var(--paper-sunk);
}

.slot[data-filled='true'] {
  background: var(--ink);
  border-color: var(--ink);
}

/* The one alarm on the sheet. */
.queue[data-critical='true'] .slot[data-filled='true'] {
  background: var(--alarm);
  border-color: var(--alarm);
}

.queue[data-critical='true'] .key {
  color: var(--alarm);
}

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

.controls {
  padding: 14px var(--gutter) 16px;
}

button {
  font-family: var(--sans);
  color: var(--ink);
  background: transparent;
  cursor: pointer;
  /* No 300ms tap delay, no double-tap zoom on a button hit twice a second. */
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.hold {
  width: 100%;
  min-height: 46px;
  margin-bottom: 10px;
  border: 1px solid var(--rule-strong);
  background: var(--paper-raised);
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.24em;
}

.hold:disabled {
  color: var(--faint);
  border-color: var(--rule);
  background: transparent;
  cursor: default;
}

.hold[data-holding='true'] {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--paper);
}

.bins {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

/* Stamped keys: a lit top edge, a seated bottom edge, and they travel when hit.
 * 66px clears the 48px minimum with room for a fast, imprecise jab - the only
 * kind available at 1.1 seconds. */
.bin {
  min-height: 66px;
  border: 1px solid var(--ink);
  background: var(--paper-raised);
  font-family: var(--mono);
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.1em;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.8),
    0 1px 0 rgba(20, 22, 26, 0.2);
}

.bin:active {
  transform: translateY(1px);
  background: var(--ink);
  color: var(--paper);
  box-shadow: none;
}

.bin:disabled,
.hold:disabled {
  opacity: 0.4;
}

button:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

/* -- overlay: start and end of shift ------------------------------------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 2;
  display: flex;
  /* margin:auto on the card centres it while short and lets it scroll rather
   * than clip once the misbin list makes it taller than the screen. */
  overflow-y: auto;
  padding: 24px var(--gutter);
  background: var(--paper);
}

.overlay[hidden] {
  display: none;
}

.card {
  width: 100%;
  max-width: 380px;
  margin: auto;
}

.overlay-title {
  margin: 0 0 6px;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: 0.3em;
}

.overlay-note {
  margin: 0 0 26px;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.04em;
  color: var(--faint);
}

.report {
  margin: 0 0 26px;
  border-top: 1px solid var(--rule-strong);
}

.report .line {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--rule);
}

.report dt {
  font-size: 9px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--faint);
}

.report dd {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}

.report .line[data-alarm='true'] dd {
  color: var(--alarm);
}

/* -- what it cost you ---------------------------------------------------- */

.misbins {
  margin: 0 0 26px;
}

.misbins[hidden] {
  display: none;
}

.misbin-heading {
  margin: 0 0 4px;
  font-size: 9px;
  font-weight: 500;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--faint);
}

.misbin {
  display: grid;
  grid-template-columns: 26px 1fr auto;
  gap: 11px;
  align-items: start;
  padding: 11px 0;
  border-bottom: 1px solid var(--rule);
}

/* The same material as the well, at thumbnail size, so a row in the summary is
 * recognisably the sample you saw on the belt. */
.misbin-chip {
  width: 26px;
  height: 26px;
  border: 1px solid var(--rule-strong);
  background-color: var(--ore, transparent);
}

.misbin-body {
  min-width: 0;
}

.misbin-attrs {
  margin: 0;
  font-size: 12px;
  font-weight: 500;
}

.misbin-verdict {
  margin: 3px 0 0;
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--faint);
}

/* The one line that teaches. Kept at ink weight while everything around it
 * stays faint, and never says why - section 9. */
.misbin-blame {
  margin: 4px 0 0;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

/* Ink, not alarm: the alarm colour belongs to queue overflow and nothing else. */
.misbin-cost {
  font-size: 14px;
  font-weight: 600;
}

.start {
  width: 100%;
  min-height: 62px;
  border: 1px solid var(--ink);
  background: var(--ink);
  color: var(--paper);
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.22em;
}

.start:active {
  transform: translateY(1px);
}

.hint {
  margin: 14px 0 0;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.06em;
  color: var(--faint);
  text-align: center;
}

/* Pointer-only affordance: on a phone there is no hover and no keyboard. */
@media (hover: none) {
  .hint {
    display: none;
  }
}

/* 360px is the floor the build targets. Buy the space back from the gutters and
 * the type scale before anything gives up a tap target. */
@media (max-width: 374px) {
  :root {
    --gutter: 13px;
  }

  .metric--mass .metric-value {
    font-size: 33px;
  }

  .metric-value {
    font-size: 13px;
  }

  .readout {
    gap: 0 11px;
  }

  .bin {
    font-size: 13px;
    letter-spacing: 0.02em;
  }
}

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

  .bin:active,
  .start:active {
    transform: none;
  }
}
