/* Scaling: the game page's own styles. The site's look, the same on every page
   (tokens for both themes, base, controls, top bar, floating panels, the stage
   panel and the end-of-level card), is site.css, loaded first. This file adds
   what Scaling draws, and the few places where Scaling's page differs.

   Also loaded by the landing page, for the dot classes and component shapes it
   draws with src/landing.js. See _doctrine/design.md.

   Order: tokens only Scaling uses, controls, top bar, layout, palette, field,
   mission, overlays, narrow screens. */

/* ---- tokens: only Scaling draws these ---- */

:root {
  /* its other kinds of request */
  --upload: #0e7490;
  --job: #57534e;
  --pay: #be185d;
  --attack: #dc2626;
  /* the frames under each provider: the colours their own diagrams use */
  --aws-region: #00a4a6;
  --aws-network: #8c4fff;
  --gcp: #4285f4;
  --azure: #0078d4;
}

/* The same block twice, as in site.css: once for a system set to dark, once
   for a visitor who picked dark. test/page.test.js checks they stay identical. */

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --upload: #22d3ee;
    --job: #a8a29e;
    --pay: #f472b6;
    --attack: #f87171;
    --aws-region: #00a4a6;
    --aws-network: #9d6bff;
    --gcp: #669df6;
    --azure: #3b9ae1;
  }
}

:root[data-theme='dark'] {
  --upload: #22d3ee;
  --job: #a8a29e;
  --pay: #f472b6;
  --attack: #f87171;
  --aws-region: #00a4a6;
  --aws-network: #9d6bff;
  --gcp: #669df6;
  --azure: #3b9ae1;
}

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

/* Speed and zoom are joined controls, drawn as site.css draws .joined. */
.speed,
.zoom,
.provider-choices {
  display: flex;
}

.speed button,
.zoom button,
.provider-choices button {
  position: relative;
  margin-left: -1px;
  padding: 5px 9px;
  font: 500 12px/1.4 var(--font-mono);
  color: var(--muted);
  border-radius: 0;
}

.speed button:first-child,
.zoom button:first-child,
.provider-choices button:first-child {
  margin-left: 0;
  border-radius: var(--radius) 0 0 var(--radius);
}

.speed button:last-child,
.zoom button:last-child,
.provider-choices button:last-child {
  border-radius: 0 var(--radius) var(--radius) 0;
}

.speed button:only-child,
.zoom button:only-child,
.provider-choices button:only-child {
  border-radius: var(--radius);
}

/* the borders overlap by a pixel, so the one in use is lifted above its neighbours */
.speed button:hover:not(:disabled),
.zoom button:hover:not(:disabled),
.provider-choices button:hover:not(:disabled) {
  z-index: 1;
  color: var(--ink);
}

.speed button:focus-visible,
.zoom button:focus-visible,
.provider-choices button:focus-visible {
  z-index: 2;
}

.speed button.on,
.provider-choices button.on {
  z-index: 1;
  color: var(--accent-text);
  background: var(--accent-soft);
  border-color: var(--accent-line);
}

.zoom button {
  min-width: 30px;
  color: var(--ink);
}

/* ---- top bar ---- */

/* Whose names the parts go by: a small cloud that opens a list of four. */
.provider {
  position: relative;
}

.provider-toggle {
  display: inline-grid;
  place-items: center;
  padding: 6px 7px;
  color: var(--ink-2);
}

.provider-toggle svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.3;
  stroke-linejoin: round;
}

/* a provider's names are on */
.provider-toggle.on {
  color: var(--accent-text);
  background: var(--accent-soft);
  border-color: var(--accent-line);
}

.provider-menu {
  position: absolute;
  z-index: 30;
  top: calc(100% + 6px);
  right: 0;
  width: 264px;
  padding: 12px 14px 14px;
  background: var(--panel);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

.provider-menu h2 {
  margin: 0 0 8px;
  font: 600 11px/1.4 var(--font-mono);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.provider-choices button {
  flex: 1;
}

.provider-menu p {
  margin-top: 10px;
  font-size: 12px;
  line-height: 1.45;
  color: var(--muted);
}

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

/* ---- layout ---- */

main {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 236px minmax(0, 1fr) 304px;
  grid-template-rows: minmax(0, 1fr);
}

.palette,
.mission {
  min-height: 0;
  overflow-y: auto;
  background: var(--panel);
}

.palette {
  padding: 14px 12px;
  border-right: 1px solid var(--line);
}

.mission {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px;
  border-left: 1px solid var(--line);
}

/* ---- palette ---- */

/* In the levels with many components the list is in tabs, one kind at a time. */
.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 10px;
}

.tabs button {
  padding: 4px 8px;
  font: 600 11px/1.4 var(--font-mono);
  letter-spacing: 0.02em;
  color: var(--muted);
  background: var(--sunken);
  border: 1px solid var(--line);
  border-radius: 6px;
  cursor: pointer;
}

.tabs button[aria-selected='true'] {
  color: var(--accent-text);
  background: var(--accent-soft);
  border-color: var(--accent);
}

.tabs button.fresh {
  border-color: var(--ok);
}

#palette {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* An available component is a card: icon, name and price on the first line, a
   short description and its number key on the second. */
.item {
  order: 0;
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) auto;
  gap: 2px 9px;
  align-items: center;
  width: 100%;
  padding: 8px 10px;
  text-align: left;
  touch-action: none;
  cursor: grab;
}

.item:disabled {
  opacity: 1;
}

.item:hover:not(:disabled) {
  background: var(--accent-soft);
}

.item:active:not(:disabled) {
  cursor: grabbing;
}

.item .icon {
  grid-column: 1;
  grid-row: 1;
  width: 28px;
  height: 28px;
  overflow: visible;
}

/* the name and the price sit straight on the card's grid */
.item .name {
  display: contents;
}

.item .name b {
  grid-column: 2;
  grid-row: 1;
  min-width: 0;
  font-size: 13.5px;
  font-weight: 600;
  line-height: 1.25;
}

.item .cost {
  grid-column: 3;
  grid-row: 1;
  font: 500 12px/1.4 var(--font-mono);
  font-variant-numeric: tabular-nums;
  color: var(--ink-2);
}

.item small {
  grid-column: 2;
  grid-row: 2;
  font-size: 11.5px;
  line-height: 1.35;
  color: var(--muted);
}

.item kbd {
  grid-column: 3;
  grid-row: 2;
  justify-self: end;
  align-self: end;
}

.item .lock {
  display: none;
  grid-column: 3;
  grid-row: 1;
  width: 13px;
  height: 13px;
  fill: none;
  stroke: var(--muted);
  stroke-width: 1.6;
  stroke-linecap: round;
}

/* unlocked, but the budget does not stretch to it */
.item.poor {
  cursor: default;
}

.item.poor .icon {
  opacity: 0.5;
}

.item.poor .name b,
.item.poor .cost {
  color: var(--muted);
}

/* A locked component is one quiet line. */
.item.locked {
  order: 2;
  grid-template-columns: 20px minmax(0, 1fr) 13px;
  padding: 3px 10px;
  background: transparent;
  border-color: transparent;
  cursor: default;
}

.item.locked .icon {
  width: 20px;
  height: 20px;
  opacity: 0.45;
}

.item.locked .name b {
  overflow: hidden;
  font-size: 12.5px;
  font-weight: 500;
  white-space: nowrap;
  text-overflow: ellipsis;
  color: var(--muted);
}

.item.locked .cost,
.item.locked small,
.item.locked kbd {
  display: none;
}

.item.locked .lock {
  display: block;
}

/* just unlocked */
.item.fresh {
  border-color: var(--ok);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 22%, transparent);
}

.later {
  order: 1;
  margin: 10px 0 0;
  padding-top: 12px;
  font: 600 11px/1.4 var(--font-mono);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  border-top: 1px solid var(--line);
}

.palette-line {
  margin-top: 14px;
  font-size: 12px;
  line-height: 1.45;
  color: var(--muted);
}

/* what follows the pointer while a component is dragged out */
.ghost {
  position: fixed;
  z-index: 20;
  padding: 8px 14px;
  font-weight: 600;
  background: var(--box);
  border: 1.5px solid var(--box-line);
  border-radius: var(--radius);
  opacity: 0.9;
  pointer-events: none;
  transform: translate(-50%, -50%);
}

/* ---- field ---- */

.field-wrap {
  position: relative;
  min-height: 320px;
  overflow: hidden;
  background: var(--paper);
}

/* a rule in the level's colour along the top of the play area */
.field-wrap::before {
  content: '';
  position: absolute;
  z-index: 1;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--level);
  pointer-events: none;
}

/* The play area is tinted by level: green, orange, red. */
#field {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: grab;
  user-select: none;
  background-color: color-mix(in srgb, var(--level) var(--tint), var(--paper));
  background-image: radial-gradient(color-mix(in srgb, var(--level) 30%, var(--line-strong)) 1px, transparent 1px);
  background-size: 24px 24px;
}

#field:focus {
  outline: none;
}

#field:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: -2px;
}

/* ---- the picture: the Panel look in cloud-diagram frames (chosen 2026-10-13) ----
   Every component an instrument cell: a title bar with a line icon, the name and
   a lamp; the setting; one live number over an eight-step gauge; a short note.
   Closed, a cell is its title bar. The selected cell's title bar inverts.
   Hairlines throughout. Wires turn at right angles and end in an open arrowhead. */

.wire-line,
.wire-head {
  fill: none;
  stroke: var(--wire);
  stroke-width: 0.75;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.wire-hit {
  fill: none;
  stroke: transparent;
  stroke-width: 14;
  cursor: pointer;
}

/* a wire to something that watches or collects, and carries no traffic */
.wire.aux .wire-line {
  stroke-dasharray: 2 4;
}

.wire.selected .wire-line,
.wire.selected .wire-head {
  stroke: var(--focus);
  stroke-width: 1.5;
}

#draft,
#draft-head {
  fill: none;
  stroke: var(--focus);
  stroke-width: 1.25;
  pointer-events: none;
}

#draft {
  stroke-dasharray: 4 4;
}

.node {
  cursor: move;
}

.node .box {
  fill: var(--panel);
  stroke: var(--box-line);
  stroke-width: 0.75;
}

.node .bar {
  fill: var(--sunken);
}

.node .rule {
  fill: none;
  stroke: var(--line-strong);
  stroke-width: 0.75;
}

/* a kind's line icon: in a cell's title bar, and in the palette */
.icon {
  fill: none;
  stroke: var(--ink-2);
  stroke-width: 1;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.node text {
  font-family: var(--font-mono);
  pointer-events: none;
}

.node .title {
  fill: var(--ink-2);
  font-size: 9px;
  font-weight: 500;
  letter-spacing: 0.08em;
}

.node .label {
  fill: var(--ink);
  font-size: 11.5px;
  font-weight: 500;
}

.node .label.tight {
  font-size: 9.5px;
}

.node .key,
.node .sub,
.node .under {
  fill: var(--muted);
  font-size: 9.5px;
}

.node .value {
  fill: var(--ink-2);
  font-size: 9.5px;
}

.node .under {
  text-anchor: middle;
}

.node .sub.warn {
  fill: var(--warn-text);
}

.node .sub.bad {
  fill: var(--bad-text);
}

.node .gauge {
  fill: var(--line);
}

.node .gauge.on {
  fill: var(--muted);
}

.node .lamp {
  fill: var(--ok);
}

.node .lamp.warn {
  fill: var(--write);
}

.node .lamp.bad {
  fill: var(--bad);
}

/* where a wire is drawn from */
.node .port {
  fill: var(--paper);
  stroke: var(--wire);
  stroke-width: 0.75;
  cursor: crosshair;
}

.node .port:hover {
  fill: var(--focus);
  stroke: var(--focus);
}

/* a read replica copies the database: its cell is dashed */
.kind-replica .box {
  stroke-dasharray: 3 2;
}

/* losing requests, or down: a red border; down is dashed and washed red too */
.node.losing .box {
  stroke: var(--bad);
  stroke-width: 1;
}

.node.losing .gauge.on {
  fill: var(--bad);
}

.node.down .box {
  fill: color-mix(in srgb, var(--bad) 8%, var(--panel));
  stroke: var(--bad);
  stroke-width: 1;
  stroke-dasharray: 4 3;
}

/* selected: the title bar inverts */
.node.selected .box {
  stroke: var(--ink);
  stroke-width: 1;
}

.node.selected .bar {
  fill: var(--ink);
}

.node.selected .icon {
  stroke: var(--paper);
}

.node.selected .title {
  fill: var(--paper);
}

/* requests: a circle in the drawing, or an <i> in running text */
.dot {
  pointer-events: none;
}

.dot.read {
  fill: var(--read);
}

.dot.write {
  fill: var(--write);
}

.dot.static {
  fill: var(--static);
}

.dot.flood {
  fill: var(--flood);
}

.dot.upload {
  fill: var(--upload);
}

.dot.job {
  fill: var(--job);
}

.dot.pay {
  fill: var(--pay);
}

.dot.attack {
  fill: var(--attack);
}

/* a request from the one big customer wears a ring; one sent a second time is hollow */
circle.dot.tenant {
  stroke: var(--ink);
  stroke-width: 2;
}

circle.dot.dup {
  fill: var(--paper);
  stroke: var(--pay);
  stroke-width: 2.5;
}

i.dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

i.dot.read {
  background: var(--read);
}

i.dot.write {
  background: var(--write);
}

i.dot.static {
  background: var(--static);
}

i.dot.flood {
  background: var(--flood);
}

i.dot.upload {
  background: var(--upload);
}

i.dot.job {
  background: var(--job);
}

i.dot.pay {
  background: var(--pay);
}

i.dot.attack {
  background: var(--attack);
}

i.dot.tenant {
  box-shadow: 0 0 0 2px var(--ink);
}

i.dot.dup {
  background: var(--paper);
  box-shadow: inset 0 0 0 2.5px var(--pay);
}

/* a cross where a request was lost */
.fx {
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  pointer-events: none;
  transform-box: fill-box;
  transform-origin: center;
  animation: fade 0.6s ease-out forwards;
}

.fx.dropped {
  stroke: var(--bad);
}

.fx.blocked,
.fx.dropped.flood {
  stroke: var(--flood);
}

@keyframes fade {
  from {
    opacity: 1;
  }
  to {
    transform: translateY(-12px);
    opacity: 0;
  }
}

/* The frames: the Cloud, solid; a Region, dotted; the network, solid. Each
   has a small tab with its icon. Under a provider, the Region and network take
   the colours that provider's diagrams give them; the cells stay as they are. */
.zone {
  --frame: var(--muted);
  pointer-events: none;
}

.zone .frame {
  fill: none;
  stroke: var(--frame);
  stroke-width: 0.75;
}

.zone.cloud {
  --frame: var(--ink-2);
}

.zone.region .frame {
  stroke-width: 1.25;
  stroke-dasharray: 0.5 3.5;
  stroke-linecap: round;
}

.zone .tab {
  fill: var(--frame);
}

.zone .tab-icon {
  fill: none;
  stroke: var(--paper);
  stroke-width: 1;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.zone .zone-label {
  fill: var(--ink-2);
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.02em;
}

[data-provider='aws'] .zone.region {
  --frame: var(--aws-region);
}

[data-provider='aws'] .zone.network {
  --frame: var(--aws-network);
}

[data-provider='gcp'] .zone.network {
  --frame: var(--gcp);
}

[data-provider='azure'] .zone.network {
  --frame: var(--azure);
}

.zone.dark {
  --frame: var(--bad);
}

.zone.dark .frame {
  fill: color-mix(in srgb, var(--bad) 5%, transparent);
}

.zone.dark .zone-label {
  fill: var(--bad-text);
}

/* ---- things that float over the field ---- */

/* the steady timer: a ring that fills while requests keep succeeding. In the
   other games it sits in the stage panel; here it floats over the picture, so
   the panel layout site.css gives a timer is put back. */
.timer {
  grid-template-columns: none;
  align-items: normal;
  gap: normal;
  margin-top: 0;
  position: absolute;
  top: 14px;
  right: 12px;
  width: 92px;
  padding: 10px 8px 8px;
  justify-items: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  pointer-events: none;
}

.timer svg {
  width: 64px;
  height: 64px;
}

.timer .arc {
  stroke: var(--ok);
}

.timer b {
  align-self: center;
  font: 700 18px/1 var(--font-mono);
}

.timer span {
  grid-area: 2 / 1;
  margin-top: 4px;
  font-size: 11px;
  line-height: 1.2;
  text-align: center;
}

.timer.losing .arc {
  stroke: var(--bad);
}

.timer.losing b,
.timer.losing span {
  color: var(--bad-text);
}

/* how close the service is to going down */
.health {
  grid-area: 3 / 1;
  width: 100%;
  height: 5px;
  margin-top: 7px;
  overflow: hidden;
  background: var(--line);
  border-radius: 3px;
}

.health i {
  display: block;
  width: 100%;
  height: 100%;
  background: var(--ok);
  transition: width 0.2s linear;
}

.timer.losing .health i {
  background: var(--bad);
}

/* the small toolbar above whatever is selected */
.toolbar {
  position: absolute;
  z-index: 5;
  display: flex;
  gap: 2px;
  padding: 3px;
  white-space: nowrap;
  background: var(--raised);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  transform: translate(-50%, -100%);
}

.toolbar button {
  padding: 3px 9px;
  font-size: 12.5px;
  background: transparent;
  border: 0;
  border-radius: 5px;
}

.toolbar button:hover:not(:disabled) {
  background: var(--accent-soft);
}

/* what the selected component is handling, against what it can */
.toolbar .load {
  align-self: center;
  margin-right: 2px;
  padding: 0 8px 0 6px;
  font: 12px/1.4 var(--font-mono);
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  border-right: 1px solid var(--line);
}

.legend {
  position: absolute;
  left: 12px;
  bottom: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  max-width: calc(100% - 190px);
  padding: 6px 12px;
  font-size: 12px;
  color: var(--muted);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  pointer-events: none;
}

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

.zoom {
  position: absolute;
  right: 12px;
  bottom: 12px;
}

/* ---- mission ---- */

.meter {
  position: relative;
}

.meter div {
  background: var(--bad);
}

.meter div.ok {
  background: var(--ok);
}

/* the share of requests the stage asks for */
.meter i {
  position: absolute;
  left: 95%;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--ink);
}

/* the endless run's score: three numbers in a row, the best run under them.
   The panel is 304px wide with 16px of padding, so each column has 82px. */
.run {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px 13px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.run .wide {
  grid-column: 1 / -1;
}

.run dt {
  font: 500 10.5px/1.4 var(--font-mono);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.run dd {
  font: 600 14px/1.4 var(--font-mono);
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.run .wide dd {
  font-weight: 500;
  font-size: 12.5px;
  color: var(--ink-2);
}

/* ---- the story picker and the end of a level ---- */

/* The card is centred with auto margins, so one taller than the screen can
   still be scrolled to its top. */

.previews {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.card .previews li {
  padding: 10px 12px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
}

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

@media (max-width: 900px) {
  main {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(360px, 1fr) auto;
    overflow-y: auto;
  }

  .palette,
  .mission {
    overflow-y: visible;
  }

  .palette {
    padding: 10px 14px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  /* the components become one row that scrolls sideways */
  #palette {
    flex-direction: row;
    overflow-x: auto;
  }

  .item {
    flex: none;
    width: 200px;
  }

  .item.locked {
    width: auto;
    max-width: 200px;
  }

  .palette h2,
  .later,
  .palette-line {
    display: none;
  }

  .mission {
    border-left: 0;
    border-top: 1px solid var(--line);
  }

  .stats {
    gap: 14px;
  }
}

@media (max-width: 560px) {
  .previews {
    grid-template-columns: minmax(0, 1fr);
  }
}

