/* The simulator (js/views/simulator.js): a composer, the demo company's estate with a switch on each defense,
   and the scenario player's step buttons and card. It reuses the scenario view's classes (.sc__*, views.css)
   for the estate, routes, card and legend; this file adds the composer, the switches, the result lines and
   the simulator's own layout. Same flat palette: green only where a defense held. */

.view--simulator { overflow: clip; border-radius: var(--radius-frame); background: var(--color-paper-2); box-shadow: inset 0 0 0 1px var(--color-frame-edge); }

/* ---------- The composer: start, goal, pace ---------- */

.sim__compose { display: flex; flex-wrap: wrap; align-items: end; gap: var(--space-md) var(--space-lg); }
.sim__field { display: grid; gap: var(--space-2xs); min-width: 0; margin: 0; }
.sim__label { font-size: var(--text-md); line-height: 1.3; color: var(--color-ink-3); }
.sim__pick { position: relative; display: block; }
.sim__select {
  appearance: none; -webkit-appearance: none; width: 100%; min-height: var(--control-hit); padding: 0 var(--space-xl) 0 var(--space-md);
  border: 0; border-radius: var(--radius-pill); background: var(--color-paper-2); box-shadow: inset 0 0 0 1px var(--color-line); color: var(--color-ink);
  font: inherit; font-size: var(--text-md); line-height: 1.2; cursor: pointer;
  transition: background-color var(--dur-hover) var(--ease-out), box-shadow var(--dur-hover) var(--ease-out);
}
.sim__select:hover { background: var(--color-paper-3); box-shadow: inset 0 0 0 1px var(--color-ink-2); }
.sim__select:focus-visible { outline: 2px solid var(--color-focus); outline-offset: 2px; transition: none; }
.sim__select:active { background: var(--color-paper-4); }
.sim__pick::after {
  content: ""; position: absolute; top: 50%; right: var(--space-md); width: var(--space-xs); height: var(--space-xs);
  border-right: var(--space-3xs) solid var(--color-ink-3); border-bottom: var(--space-3xs) solid var(--color-ink-3); transform: translateY(-70%) rotate(45deg); pointer-events: none;
}
.sim__chips { display: flex; gap: var(--space-xs); }

/* ---------- The estate, laid out for places that carry switches ---------- */

.sim .sc__map {
  grid-template-columns: repeat(20, minmax(0, 1fr)); gap: var(--space-xl) var(--space-md);
  grid-template-areas:
    "outside outside outside outside outside outside outside outside outside outside outside outside outside outside outside outside outside outside outside outside"
    "edge edge edge edge edge edge people people people people people people people apps apps apps apps apps apps apps"
    "identity identity identity identity identity identity identity identity identity cloud cloud cloud cloud cloud cloud cloud cloud cloud cloud cloud"
    "inside inside inside inside inside inside inside inside inside inside inside inside inside inside inside inside inside inside inside inside";
}
/* On a narrow map every zone takes a full row, so routes have a lane between any two zones and down the
   right-hand side. */
.sim .sc__map[data-layout="narrow"] {
  grid-template-columns: minmax(0, 1fr); gap: var(--space-md);
  grid-template-areas: "outside" "edge" "people" "identity" "apps" "inside" "cloud";
}
.sim .sc__map[data-layout="narrow"] .sc__places { gap: var(--space-sm) var(--space-xs); }
.sim .sc__zone { padding: var(--space-sm) var(--space-sm) var(--space-md); }
.sim .sc__places { align-items: center; }

/* A place and its switches stay together. The switch is a shield: outlined when the defense is off, filled
   when it is on, green once it has held a step of this attack. */
.sim__place { position: relative; z-index: 2; display: inline-flex; align-items: center; max-width: 100%; }
.sim__place .sc__node { min-width: 0; }
.sim__def {
  flex: none; display: grid; place-items: center; width: var(--control-hit); height: var(--control-hit); margin-left: var(--space-2xs); padding: 0;
  border: 0; border-radius: var(--radius-pill); background: var(--color-paper-2); box-shadow: inset 0 0 0 1px var(--color-frame-edge); color: var(--color-ink-3); cursor: pointer;
  transition: background-color var(--dur-hover) var(--ease-out), color var(--dur-hover) var(--ease-out);
}
.sim__def[aria-pressed="true"] { color: var(--color-ink); }
.sim__def:hover { background: var(--color-paper-4); color: var(--color-ink); }
.sim__def:focus-visible { outline: 2px solid var(--color-focus); outline-offset: 2px; transition: none; }
.sim__def:active { transform: scale(0.94); }
.sim__def.is-held { color: var(--color-defense); }
.sim__shield { display: block; flex: none; width: calc(var(--space-md) + var(--space-2xs)); height: calc(var(--space-md) + var(--space-2xs)); overflow: visible; }
.sim__shield path { fill: currentColor; fill-opacity: 0; stroke: currentColor; stroke-width: 1.5; stroke-linejoin: round; transition: fill-opacity var(--dur-hover) var(--ease-out); }
.sim__def[aria-pressed="true"] .sim__shield path { fill-opacity: 1; }
html:not(.rm) .sim__def.is-held .sim__shield { animation: sim-hold 620ms var(--ease-out) 1; }
@keyframes sim-hold { 0% { transform: scale(1); } 40% { transform: scale(1.3); } 100% { transform: scale(1); } }

/* Under the map: the legend, and the way back to the sample company's defenses. */
.sim__under { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-sm) var(--space-lg); }
.sim__reset { flex: none; }

/* ---------- The result: one sentence, how it was produced, and what the last switch changed ---------- */

.sim__out { display: grid; align-content: start; gap: var(--space-xs); min-width: 0; }
.sim__out p { margin: 0; }
.sim__result { font-size: var(--text-card); line-height: var(--leading-title); letter-spacing: var(--tracking-title); color: var(--color-ink); text-wrap: balance; }
.sim__model { font-size: var(--text-md); line-height: 1.4; color: var(--color-ink-3); }
.sim__note { display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: start; gap: var(--space-xs); min-height: calc(2 * 1.4em); font-size: var(--text-md); line-height: 1.4; color: var(--color-ink-2); }
.sim__note .sim__shield { margin-top: var(--space-3xs); color: var(--color-ink-3); }
.sim__count { margin: 0; font-size: var(--text-md); line-height: 1.4; color: var(--color-ink-3); font-variant-numeric: tabular-nums; }
html:not(.rm) .sim__out.is-swap .sim__result { animation: tl-in 360ms var(--ease-out) both; }

.sim__list { grid-template-columns: minmax(0, 1fr); gap: var(--space-sm); }
.sim__list ul { display: grid; gap: var(--space-xs); margin: 0; padding: 0; list-style: none; }
.sim__list strong { color: var(--color-ink); font-weight: inherit; }

/* ---------- Layout ---------- */

@media (min-width: 75rem) {
  .sim__under { grid-column: 1; grid-row: 2; }
  /* The side keeps room for a three-line result, so the steps and the card hold their place. */
  .sim__result { min-height: calc(3 * var(--leading-title) * 1em); }
}
@media (max-width: 74.99rem) {
  /* One column: the result, the map and its legend, then the steps and the card. */
  .sim .sc__side { display: contents; }
  .sim .sim__out { order: -1; }
  .sim .sc__map { order: 0; }
  .sim .sim__under { order: 1; }
  .sim .sc__legend { order: 0; }
  .sim .sc__ticks { order: 2; }
  .sim .sc__card { order: 3; }
  .sim .sc__foot { order: 4; }
}
@media (max-width: 39.99rem) {
  .view--simulator { margin-inline: calc(-1 * var(--gutter)); border-radius: 0; box-shadow: inset 0 1px 0 var(--color-frame-edge), inset 0 -1px 0 var(--color-frame-edge); }
  .sim__compose { gap: var(--space-sm); }
  .sim__field { flex: 1 1 100%; }
  /* Three lanes down each side of the map, where most routes on a phone run. */
  .sim .sc__map, .sim .sc__map[data-layout="narrow"] { padding-inline: var(--space-lg); }
  .sim .sc__zone { padding: var(--space-md) var(--space-xs) var(--space-xs); }
  /* Zone names sit at the right end of the plate's top edge: places start at the left, so routes between the
     lanes get by on that side. */
  .sim .sc__zone-name { left: auto; right: var(--space-xs); }
  .sim__result { min-height: calc(2 * var(--leading-title) * 1em); font-size: var(--text-title); }
  /* The result stays under the nav while the map scrolls beneath it, so a switch never leaves the reader
     without words. A flex item can stick across the whole column; a grid item cannot leave its row. */
  .sim .sc__body { display: flex; flex-direction: column; }
  .sim .sim__out { position: sticky; top: calc(var(--nav-offset) + var(--nav-h)); z-index: 3; padding-block: var(--space-xs); background: var(--color-paper-2); }
}
