/*
 * One accent hue, two surfaces, and type doing the rest of the work.
 *
 * Dark is the default because the tool is used on a phone next to a game, and
 * prefers-color-scheme: light is honoured rather than assumed away. There are
 * no gradients and no shadows: every border here separates two things that are
 * genuinely different.
 */

:root {
  color-scheme: dark light;

  --surface: #101316;
  --surface-raised: #171b1f;
  --border: #262c32;
  /*
   * Anything a finger or a caret lands on is outlined with this instead. A
   * boundary that identifies a control has to carry 3:1 against what is on both
   * sides of it; --border is a quarter of that and is for separating regions,
   * not for saying "this is a field". Twelve price boxes on a phone in daylight
   * is the case that decides it.
   */
  --border-interactive: #66707a;
  --text: #e6eaee;
  --text-muted: #949ea8;
  --accent: #5fd08a;
  --invalid: #e0685f;

  --band-90: rgb(95 208 138 / 0.14);
  --band-50: rgb(95 208 138 / 0.28);
  --edge: rgb(170 180 190 / 0.7);

  --radius: 10px;
  --gap: 14px;

  --font-text: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-figure: ui-monospace, "SF Mono", "Cascadia Mono", "Segoe UI Mono", "Roboto Mono",
    Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: light) {
  :root {
    --surface: #f6f7f8;
    --surface-raised: #ffffff;
    --border: #dde1e5;
    --border-interactive: #7b848d;
    --text: #12171b;
    --text-muted: #5c6670;
    --accent: #17794a;
    --invalid: #b3261e;

    --band-90: rgb(23 121 74 / 0.13);
    --band-50: rgb(23 121 74 / 0.26);
    --edge: rgb(72 82 92 / 0.75);
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 0 12px 48px;
  background: var(--surface);
  color: var(--text);
  font-family: var(--font-text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

main,
.masthead,
.colophon {
  max-width: 880px;
  margin: 0 auto;
}

.masthead {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 10px;
  padding: 22px 4px 10px;
}

.masthead h1 {
  margin: 0;
  font-size: 26px;
  letter-spacing: -0.01em;
}

.tagline {
  margin: 2px 0 0;
  color: var(--text-muted);
}

.masthead-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.masthead-actions select {
  width: auto;
  padding: 7px 8px;
  font-size: 13px;
}

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

.panel {
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: var(--gap);
}

.panel > h2 {
  margin: 0 0 10px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.panel[hidden] {
  display: none;
}

/* Input */

.input-row {
  display: grid;
  gap: var(--gap);
  grid-template-columns: 1fr;
}

@media (min-width: 620px) {
  .input-row {
    grid-template-columns: 1fr 1fr;
  }
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.field-label {
  font-size: 13px;
  font-weight: 600;
}

.field-hint,
.field-error {
  font-size: 12px;
  color: var(--text-muted);
}

.field-error:empty {
  display: none;
}

.field-error {
  color: var(--invalid);
}

input[type="text"],
select {
  width: 100%;
  padding: 9px 10px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-interactive);
  border-radius: 8px;
  font: inherit;
}

.price-input {
  font-family: var(--font-figure);
  font-variant-numeric: tabular-nums;
  font-size: 16px;
  text-align: center;
}

input:focus-visible,
select:focus-visible,
button:focus-visible,
summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

input.invalid {
  border-color: var(--invalid);
}

/* The price the inference says cannot follow the ones before it. Distinct from
   .invalid, which is a value the field itself will not take. */
input.culprit {
  border-color: var(--invalid);
  box-shadow: inset 0 0 0 1px var(--invalid);
}

.culprit-line {
  margin-bottom: 10px;
}

.toggle {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 4px 8px;
  align-self: end;
}

.toggle input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.toggle .field-hint {
  grid-column: 2;
}

.inputs h2 {
  margin: 18px 0 2px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
}

/*
 * One box per day. The first version laid all twelve fields out in a single
 * flat grid and it was not possible to see at a glance where one day ended and
 * the next began.
 */
.days {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin: 10px 0 12px;
}

@media (min-width: 460px) {
  .days {
    grid-template-columns: 1fr 1fr;
  }
}

@media (min-width: 760px) {
  .days {
    grid-template-columns: repeat(3, 1fr);
  }
}

.day {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px 10px;
  background: var(--surface);
}

.day-name {
  display: block;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.day-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.half {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.half-label {
  font-size: 11px;
  color: var(--text-muted);
  text-align: center;
  white-space: nowrap;
}

.day .price-input {
  background: var(--surface-raised);
}

button {
  font: inherit;
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  border: 1px solid var(--border-interactive);
  background: var(--surface);
  color: var(--text);
}

/* Chart */

.chart {
  width: 100%;
}

.chart svg {
  display: block;
  width: 100%;
  touch-action: pan-y;
  border-radius: var(--radius);
}

.chart svg:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.grid line {
  stroke: var(--border);
  stroke-width: 1;
}

.base-line {
  stroke: var(--text-muted);
  stroke-width: 1;
  stroke-dasharray: 2 4;
}

.band-90 {
  fill: var(--band-90);
}

/*
 * The inner band carries a drawn boundary, not just a heavier fill. Two
 * translucencies of one hue differ here by about 1.8:1 in the dark scheme and
 * 1.4:1 in the light one, which is below the threshold for a graphic that
 * carries meaning and is the first difference lost to colour vision deficiency.
 * The stroke is the accent at 1px; the median inside it is the same colour at
 * 2px, and the two never touch, so weight and position tell them apart.
 */
.band-50 {
  fill: var(--band-50);
  stroke: var(--accent);
  stroke-width: 1;
  stroke-linejoin: round;
}

.median {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2;
  stroke-linejoin: round;
}

.edge {
  fill: none;
  stroke: var(--edge);
  stroke-width: 1;
}

.edge-min {
  stroke-dasharray: 4 3;
}

.edge-max {
  stroke-dasharray: 1 3;
}

.peak line {
  stroke: var(--accent);
  stroke-width: 1;
  stroke-dasharray: 3 3;
  opacity: 0.75;
}

.markers circle {
  fill: var(--text);
  stroke: var(--surface-raised);
  stroke-width: 1.5;
}

.cursor {
  stroke: var(--text-muted);
  stroke-width: 1;
}

.cursor[hidden],
.base-line[hidden] {
  display: none;
}

text.tick,
text.day-tick {
  fill: var(--text-muted);
  font-family: var(--font-figure);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.readout {
  margin: 8px 0 0;
  min-height: 2.6em;
  font-family: var(--font-figure);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
}

.axis-note {
  margin: 0;
  font-size: 12px;
  color: var(--text-muted);
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  margin: 8px 0 0;
  padding: 0;
  list-style: none;
  font-size: 12px;
  color: var(--text-muted);
}

.legend li {
  display: flex;
  align-items: center;
  gap: 6px;
}

.swatch {
  width: 14px;
  height: 10px;
  border-radius: 2px;
  flex: none;
}

/* The keys mirror the chart: the inner band is outlined in the accent because
 * it is outlined there; the outer band takes the neutral that draws every
 * limit, because its extent is all the swatch is claiming. */
.swatch-90 {
  background: var(--band-90);
  border: 1px solid var(--edge);
}
.swatch-50 {
  background: var(--band-50);
  border: 1px solid var(--accent);
}
.swatch-median {
  height: 2px;
  background: var(--accent);
}
.swatch-min {
  height: 0;
  border-top: 1px dashed var(--edge);
}
.swatch-max {
  height: 0;
  border-top: 1px dotted var(--edge);
}
.swatch-observed {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--text);
}
.swatch-peak {
  width: 0;
  height: 12px;
  border-left: 1px dashed var(--accent);
}

/* Decision */

.verdict {
  margin: 0;
  font-size: 30px;
  font-weight: 650;
  letter-spacing: -0.02em;
  line-height: 1.15;
}

.verdict[data-action="sell"] {
  color: var(--accent);
}

.verdict[data-action="invalid"] {
  color: var(--invalid);
}

.verdict-detail {
  margin: 4px 0 12px;
  color: var(--text-muted);
}

.statistics {
  display: grid;
  gap: 10px;
  grid-template-columns: 1fr;
}

@media (min-width: 520px) {
  .statistics {
    grid-template-columns: repeat(3, 1fr);
  }
}

.statistic {
  display: flex;
  flex-direction: column;
  border-top: 1px solid var(--border);
  padding-top: 8px;
}

.statistic-label {
  font-size: 12px;
  color: var(--text-muted);
}

.statistic-value {
  font-family: var(--font-figure);
  font-variant-numeric: tabular-nums;
  font-size: 22px;
}

.statistic-note {
  font-family: var(--font-figure);
  font-size: 12px;
  color: var(--text-muted);
}

.muted {
  margin: 0;
  color: var(--text-muted);
}

/* Patterns */

table.patterns {
  width: 100%;
  border-collapse: collapse;
}

table.patterns th {
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  padding-bottom: 6px;
}

table.patterns th.figure,
table.patterns td.figure {
  text-align: right;
  font-family: var(--font-figure);
  font-variant-numeric: tabular-nums;
}

table.patterns td {
  padding: 7px 0;
  border-top: 1px solid var(--border);
  position: relative;
}

table.patterns tr.eliminated td {
  color: var(--text-muted);
}

/*
 * Scaled rather than resized. Animating width puts four elements through layout
 * on every keystroke; a transform is composited and touches neither layout nor
 * paint. The ends are square because scaleX would stretch a corner radius into
 * an ellipse as the bar gets short, and a short bar is the common case.
 */
.bar {
  display: block;
  height: 3px;
  margin-top: 4px;
  background: var(--accent);
  width: 100%;
  transform: scaleX(var(--share));
  transform-origin: left center;
  transition: transform 220ms ease-out;
}

/* Scenarios */

.scenario-group {
  border-top: 1px solid var(--border);
}

.scenario-group summary {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  cursor: pointer;
}

.scenario-group ul {
  margin: 0 0 8px;
  padding: 0;
  list-style: none;
}

.scenario-group li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 3px 0 3px 14px;
  color: var(--text-muted);
  font-size: 13px;
}

.figure {
  font-family: var(--font-figure);
  font-variant-numeric: tabular-nums;
}

/* Colophon */

.colophon {
  padding: 4px;
  font-size: 12px;
  color: var(--text-muted);
}

.colophon a {
  color: inherit;
}

/*
 * The narrowest phones. Every pixel taken back from the page gutter and the
 * panel padding goes to the chart, where twelve half-days are competing for
 * width against a thumb.
 */
@media (max-width: 400px) {
  body {
    padding: 0 8px 40px;
  }

  .panel {
    padding: 10px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .bar {
    transition: none;
  }
}
