/* /when-things-go-wrong — scenario list + a live diagram of Mac, storage and
   what the user keeps. Builds on styles.css (tokens, nav, sections). */

body {
  --bad: #F2716B;
  --bad-soft: color-mix(in oklab, var(--bad) 14%, transparent);
  --warn: #F2C14E;
  --warn-soft: color-mix(in oklab, var(--warn) 14%, transparent);
  --good: var(--ok);
  --good-soft: color-mix(in oklab, var(--ok) 14%, transparent);
}
body.light {
  --bad: #C2272D;
  --warn: #875C00;
}

/* ---------- Outcome chips ---------- */

.oc {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12.5px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  white-space: nowrap;
}
.oc::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.oc-auto { color: var(--good); background: var(--good-soft); }
.oc-you { color: var(--warn); background: var(--warn-soft); }
.oc-lost { color: var(--bad); background: var(--bad-soft); }

.wr-hero { padding-bottom: 56px; }
.wr-legend { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; animation: fadeUp .6s .24s ease both; }
.wr-section { padding-top: 40px; }
.wr-lede { max-width: 640px; }

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

.wr {
  display: grid;
  grid-template-columns: minmax(0, 270px) minmax(0, 1fr);
  gap: 22px;
  align-items: start;
}

.wr-list { display: flex; flex-direction: column; gap: 6px; position: sticky; top: 84px; }
.wr-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  text-align: left;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--line2);
  background: none;
  color: var(--text2);
  font: inherit;
  font-size: 14px;
  line-height: 1.35;
  cursor: pointer;
  transition: border-color .2s, background .2s, color .2s;
}
.wr-item:hover { border-color: var(--line); color: var(--text); }
.wr-item[aria-selected="true"] { background: var(--bg2); border-color: var(--line); color: var(--text); box-shadow: 0 8px 24px -16px rgba(0,0,0,.5); }
.wr-item b { font-weight: 600; }
.wr-item .oc { font-size: 11.5px; padding: 2px 8px; }

.wr-main {
  min-width: 0;
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 24px;
}
.wr-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-start; gap: 14px; margin-bottom: 18px; }
.wr-head h2 {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 8px 0 0;
  text-wrap: balance;
}
.wr-ctrl { display: flex; gap: 6px; align-items: center; }
.icon-btn {
  width: 40px;
  height: 38px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text2);
  font-size: 13px;
  cursor: pointer;
}
.icon-btn:hover { color: var(--text); border-color: var(--text3); }
.icon-btn:disabled { opacity: .35; cursor: default; }
.btn-break {
  height: 38px;
  padding: 0 16px;
  border-radius: 9px;
  border: 0;
  background: var(--bad);
  color: #fff;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.btn-break.go { background: var(--accent); color: var(--btn-ink); }
.btn-break.again { background: none; border: 1px solid var(--line); color: var(--text2); }
.btn-break:hover { filter: brightness(1.08); }

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

/* ---------- Scene ---------- */

.scene {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 64px minmax(0, 1.5fr);
  grid-template-areas: "mac wire store" "you . store";
  gap: 14px 0;
  padding: 18px;
  border-radius: 12px;
  border: 1px solid var(--line2);
  background: var(--bg);
  background-image: radial-gradient(circle, var(--dot) 1px, transparent 1px);
  background-size: 22px 22px;
}
.zone { min-width: 0; }
.zone-mac { grid-area: mac; }
.zone-store { grid-area: store; }
.zone-you { grid-area: you; align-self: end; }
.zone-title { font-size: 12px; font-weight: 600; color: var(--text3); margin-bottom: 8px; }

.nodes { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.node-wide { grid-column: span 2; }

.node {
  position: relative;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 9px 11px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg2);
  transition: border-color .35s, background-color .35s, opacity .35s, box-shadow .35s;
}
.node b { font-size: 13px; font-weight: 600; color: var(--text); }
.node small { font-size: 11.5px; line-height: 1.35; color: var(--text3); overflow-wrap: anywhere; }
.node::after {
  position: absolute;
  top: -7px;
  right: -7px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 700;
  color: var(--bg);
  opacity: 0;
  transform: scale(.6);
  transition: opacity .3s, transform .3s;
}

/* State vocabulary, shared by nodes, snapshot dots and pack tiles:
   broken · check · fixed · gone · warn · busy · dim */
.node[data-s="broken"] { border-color: var(--bad); background: var(--bad-soft); }
.node[data-s="broken"]::after { content: "!"; background: var(--bad); opacity: 1; transform: none; }
.node[data-s="check"] { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); animation: pulse 1.2s ease-in-out infinite; }
.node[data-s="fixed"] { border-color: var(--good); background: var(--good-soft); }
.node[data-s="fixed"]::after { content: "✓"; background: var(--good); opacity: 1; transform: none; }
.node[data-s="gone"] { border-style: dashed; opacity: .45; }
.node[data-s="gone"] b { text-decoration: line-through; }
.node[data-s="warn"] { border-color: var(--warn); background: var(--warn-soft); }
.node[data-s="warn"]::after { content: "?"; background: var(--warn); opacity: 1; transform: none; }
.node[data-s="busy"] { border-color: var(--accent); background: var(--accent-soft); }
.node[data-s="dim"] { opacity: .4; }

@keyframes pulse { 50% { box-shadow: 0 0 0 6px transparent; } }

.dots, .tiles { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 3px; }
.dots i, .tiles i {
  display: grid;
  place-items: center;
  height: 18px;
  border-radius: 4px;
  font-style: normal;
  font-size: 9.5px;
  font-weight: 600;
  transition: background-color .35s, border-color .35s, opacity .35s;
}
.dots i { width: 22px; background: color-mix(in oklab, var(--accent) 55%, transparent); border: 1px solid transparent; }
.tiles i { width: 26px; background: var(--bg3); border: 1px solid var(--line); background-image: var(--noise); }
.tiles i.par { width: auto; padding: 0 6px; color: var(--text3); background: none; border-style: dashed; }
/* Slots for the backup being written: hidden until a step gives them a state. */
.tiles i.pend, .dots i.pend { display: none; }
.tiles i.pend[data-s], .dots i.pend[data-s] { display: grid; }

.dots i[data-s="broken"], .tiles i[data-s="broken"] { background: var(--bad); border-color: var(--bad); }
.dots i[data-s="fixed"], .tiles i[data-s="fixed"] { background: var(--good); border-color: var(--good); }
.dots i[data-s="gone"], .tiles i[data-s="gone"] { background: none; border: 1px dashed var(--text3); opacity: .6; }
.dots i[data-s="warn"], .tiles i[data-s="warn"] { background: var(--warn); border-color: var(--warn); }
.dots i[data-s="check"], .tiles i[data-s="check"] { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.dots i[data-s="busy"], .tiles i[data-s="busy"] { background: var(--accent); }
.dots i[data-s="dim"], .tiles i[data-s="dim"] { opacity: .3; }
.tiles i.par[data-s="busy"] { color: var(--btn-ink); border-style: solid; }
.tiles i.par[data-s="fixed"] { color: var(--bg); }
.tiles i.par[data-s="gone"] { display: none; }

.meter { display: block; height: 8px; margin-top: 5px; border-radius: 4px; background: var(--bg3); overflow: hidden; }
.meter i { display: block; height: 100%; width: 40%; background: var(--accent); border-radius: 4px; transition: width .8s ease, background-color .3s; }
.node[data-s="broken"] .meter i { background: var(--bad); }

/* ---------- Wire between Mac and storage ---------- */

.wire {
  grid-area: wire;
  position: relative;
  align-self: center;
  height: 2px;
  margin: 0 10px;
  background: var(--line);
  transition: background-color .3s;
}
.wire .pkt {
  position: absolute;
  top: -3px;
  left: 0;
  width: 8px;
  height: 8px;
  border-radius: 2px;
  background: var(--accent);
  opacity: 0;
}
.wire[data-w="up"] .pkt { animation: up 1.2s linear infinite; }
.wire[data-w="down"] .pkt { animation: down 1.2s linear infinite; }
.wire .pkt:nth-child(2) { animation-delay: .4s !important; }
.wire .pkt:nth-child(3) { animation-delay: .8s !important; }
@keyframes up { 0% { left: 0; opacity: 0; } 15% { opacity: 1; } 85% { opacity: 1; } 100% { left: calc(100% - 8px); opacity: 0; } }
@keyframes down { 0% { left: calc(100% - 8px); opacity: 0; } 15% { opacity: 1; } 85% { opacity: 1; } 100% { left: 0; opacity: 0; } }
.wire-x {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  font-size: 15px;
  font-weight: 700;
  color: var(--bad);
  opacity: 0;
  transition: opacity .3s;
}
.wire[data-w="cut"] { background: repeating-linear-gradient(90deg, var(--bad) 0 6px, transparent 6px 12px); }
.wire[data-w="cut"] .wire-x { opacity: 1; }

/* ---------- Caption ---------- */

.wr-caption { margin-top: 18px; min-height: 120px; max-width: 760px; }
.wr-step { font-family: 'JetBrains Mono', monospace; font-size: 12px; color: var(--text3); margin-bottom: 6px; font-variant-numeric: tabular-nums; }
.wr-caption h3 { font-family: 'Space Grotesk', sans-serif; font-size: 19px; font-weight: 600; margin: 0 0 8px; }
.wr-caption p { margin: 0; color: var(--text2); font-size: 15px; line-height: 1.65; text-wrap: pretty; }

.wr-you {
  margin-top: 16px;
  padding: 14px 16px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg);
}
.wr-you-label { font-size: 12.5px; font-weight: 600; color: var(--text3); margin-bottom: 4px; }
.wr-you p { margin: 0; font-size: 14.5px; line-height: 1.6; color: var(--text); text-wrap: pretty; }

/* ---------- Summary table ---------- */

.wr-summary { border: 1px solid var(--line); border-radius: 14px; background: var(--bg2); overflow: hidden; }
.wr-row {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 2fr) auto;
  gap: 18px;
  align-items: baseline;
  padding: 16px 22px;
}
.wr-row + .wr-row { border-top: 1px solid var(--line2); }
.wr-row h3 { margin: 0; font-size: 15px; font-weight: 600; }
.wr-row h3 a { color: var(--text); }
.wr-row p { margin: 0; color: var(--text2); font-size: 14px; line-height: 1.6; text-wrap: pretty; }

/* ---------- Narrow screens ---------- */

@media (max-width: 900px) {
  .wr { grid-template-columns: minmax(0, 1fr); }
  .wr-list {
    position: static;
    flex-direction: row;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    padding-bottom: 6px;
  }
  .wr-item { flex: 0 0 auto; max-width: 240px; scroll-snap-align: start; }
}
@media (max-width: 640px) {
  .wr-main { padding: 18px 14px; }
  .scene {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "mac" "wire" "store" "you";
    padding: 14px;
  }
  .wire { width: 2px; height: 40px; margin: 0 auto; justify-self: center; }
  .wire .pkt { left: -3px; top: 0; }
  .wire[data-w="cut"] { background: repeating-linear-gradient(180deg, var(--bad) 0 6px, transparent 6px 12px); }
  @keyframes up { 0% { top: 0; opacity: 0; } 15% { opacity: 1; } 85% { opacity: 1; } 100% { top: calc(100% - 8px); opacity: 0; } }
  @keyframes down { 0% { top: calc(100% - 8px); opacity: 0; } 15% { opacity: 1; } 85% { opacity: 1; } 100% { top: 0; opacity: 0; } }
  .wr-row { grid-template-columns: minmax(0, 1fr); gap: 6px; padding: 14px 16px; }
  .wr-row .oc { justify-self: start; }
}

@media (prefers-reduced-motion: reduce) {
  .node, .dots i, .tiles i, .meter i, .wire { transition: none !important; }
  .node[data-s="check"] { animation: none; }
  .wire .pkt { animation: none !important; opacity: 0 !important; }
  .wr-legend { animation: none; }
}
