/* ============================================================
   VIZ 1.3 — "Who plays in the market"
   The referees: 4 inline clickable terms -> role cards in panel
   Coherent with viz-1-1 / viz-1-2 vocabulary (cyan #3FA9C4)
   ============================================================ */

/* ---- shared accent (matches Hydro / see-it button) ---- */
.viz-panel[data-viz="3"] {
  --ref-cyan:   #3FA9C4;
  --ref-cyan-d: #2b8aa3;
  --ref-ink:    #1f2433;
  --ref-muted:  #6b6d82;
  --ref-line:   rgba(63,169,196,0.22);
  --ref-bg-soft: rgba(63,169,196,0.06);
  --ref-halo:   #f2f9fb;
}

/* dark theme inherits page vars; soften ink/muted */
.chapter-page.dark .viz-panel[data-viz="3"] {
  --ref-ink:   #e8ebf2;
  --ref-muted: #9a9db5;
  --ref-bg-soft: rgba(63,169,196,0.10);
  --ref-halo:  #1d2231;
}

/* ============================================================
   INLINE CLICKABLE TERMS (in the text column)
   "market operator", "TSO", "DSO", "regulator"
   ============================================================ */
.ref-term {
  cursor: pointer;
  color: var(--ref-cyan, #3FA9C4);
  font-weight: 600;
  text-decoration: none;
  border-bottom: 2px dotted rgba(63,169,196,0.55);
  padding-bottom: 1px;
  transition: color .18s ease, border-color .18s ease,
              background .18s ease, text-shadow .18s ease;
  border-radius: 2px;
}
.ref-term:hover {
  color: #2b8aa3;
  border-bottom-color: #3FA9C4;
  background: rgba(63,169,196,0.10);
  text-shadow: 0 0 14px rgba(63,169,196,0.35);
}
.ref-term.is-active {
  color: #fff;
  background: #3FA9C4;
  border-bottom-color: transparent;
  padding: 1px 6px;
  box-shadow: 0 2px 10px rgba(63,169,196,0.35);
}
.chapter-page.dark .ref-term:hover { color: #7fd3e8; }

/* tiny "click" affordance dot that pulses once on first view (optional, subtle) */
.ref-term::after {
  content: "";
}

/* ============================================================
   PANEL ROOT
   ============================================================ */
.viz-1-3 {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: 26px 26px 22px;
  box-sizing: border-box;
  font-family: inherit;
  color: var(--ref-ink);
  position: relative;
  overflow: hidden;
}

.viz-1-3 .v13-tag {
  font-size: 11px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--ref-cyan);
  font-weight: 700;
  margin-bottom: 4px;
}
.viz-1-3 .v13-headline {
  font-size: 21px;
  font-weight: 700;
  line-height: 1.2;
  margin-bottom: 18px;
}

/* ============================================================
   OVERVIEW (default state) — the auction in the middle, roles around
   ============================================================ */
.v13-overview {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
}
.v13-overview svg { width: 100%; max-width: 480px; height: auto; }

.v13-hint {
  font-size: 13px;
  color: var(--ref-muted);
  text-align: center;
  line-height: 1.5;
  max-width: 300px;
}
.v13-hint b { color: var(--ref-cyan); font-weight: 700; }

/* overview node labels */
.v13-node-label { font-size: 11px; font-weight: 600; fill: var(--ref-ink); }
.v13-node-sub   { font-size: 9px;  fill: var(--ref-muted); }
.v13-center-label { font-size: 12px; font-weight: 700; fill: #fff; }

/* gentle pulse on the auction core */
@keyframes v13-core-pulse {
  0%,100% { r: 34; opacity: 1; }
  50%     { r: 37; opacity: .92; }
}
.v13-core { animation: v13-core-pulse 2.6s ease-in-out infinite; }

/* flow dots animating along the spokes */
@keyframes v13-flow {
  0%   { offset-distance: 0%;   opacity: 0; }
  10%  { opacity: 1; }
  90%  { opacity: 1; }
  100% { offset-distance: 100%; opacity: 0; }
}

/* ============================================================
   ROLE CARD (shown after clicking a term)
   ============================================================ */
.v13-card {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  animation: v13-card-in .35s cubic-bezier(.2,.7,.3,1);
}
@keyframes v13-card-in {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

.v13-card-top {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 6px;
}
.v13-card-icon {
  width: 52px; height: 52px;
  flex: 0 0 52px;
  border-radius: 14px;
  display: grid; place-items: center;
  background: var(--ref-bg-soft);
  border: 1.5px solid var(--ref-line);
  color: var(--ref-cyan);
  font-size: 26px;
}
.v13-card-titles .v13-card-role {
  font-size: 17px; font-weight: 700; line-height: 1.15;
}
.v13-card-titles .v13-card-kind {
  font-size: 11px; letter-spacing: 1px; text-transform: uppercase;
  color: var(--ref-cyan); font-weight: 700;
}

.v13-card-desc {
  font-size: 13.5px;
  line-height: 1.55;
  color: var(--ref-ink);
  margin: 12px 0 8px;
}

/* real-world examples chips */
.v13-examples {
  display: flex; flex-wrap: wrap; gap: 8px;
  margin-bottom: 14px;
}
.v13-chip {
  font-size: 11.5px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--ref-bg-soft);
  border: 1px solid var(--ref-line);
  color: var(--ref-muted);
}
.v13-chip b { color: var(--ref-cyan); font-weight: 700; }

/* the micro-animation stage */
.v13-stage {
  flex: 0 1 auto;
  min-height: 190px;
  padding-bottom: 26px;
  border-radius: 14px;
  background: var(--ref-bg-soft);
  border: 1px solid var(--ref-line);
  position: relative;
  overflow: hidden;
  display: grid;
  place-items: center;
}
.v13-stage svg { width: 100%; height: auto; max-height: 300px; }

.v13-stage-caption {
  position: absolute;
  bottom: 10px; left: 0; right: 0;
  text-align: center;
  font-size: 11.5px;
  color: var(--ref-muted);
  padding: 0 14px;
}

.v13-replay {
  position: absolute;
  top: 10px; right: 10px;
  font-size: 11px; font-weight: 600;
  color: var(--ref-cyan);
  background: rgba(255,255,255,0.7);
  border: 1px solid var(--ref-line);
  border-radius: 999px;
  padding: 4px 11px;
  cursor: pointer;
  display: inline-flex; align-items: center; gap: 5px;
  transition: all .16s ease;
  backdrop-filter: blur(2px);
}
.v13-replay:hover {
  background: var(--ref-cyan); color: #fff; border-color: var(--ref-cyan);
}
.chapter-page.dark .v13-replay {
  background: rgba(30,34,48,0.7);
}

/* role tabs (so you can switch between the 4 referees inside the panel too) */
.v13-tabs {
  display: flex; gap: 6px; margin-top: 14px; flex-wrap: wrap;
}
.v13-tab {
  font-size: 11px; font-weight: 600;
  padding: 5px 11px; border-radius: 999px;
  background: transparent;
  border: 1px solid var(--ref-line);
  color: var(--ref-muted);
  cursor: pointer;
  transition: all .16s ease;
}
.v13-tab:hover { border-color: var(--ref-cyan); color: var(--ref-cyan); }
.v13-tab.is-active {
  background: var(--ref-cyan); color: #fff; border-color: var(--ref-cyan);
}

.v13-back {
  align-self: flex-start;
  margin-top: 12px;
  font-size: 12px; font-weight: 600;
  color: var(--ref-cyan);
  background: none; border: none; cursor: pointer;
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 0;
}
.v13-back:hover { text-decoration: underline; }

/* ===== micro-animation keyframes ===== */

/* Market operator: gavel drop + price reveal */
@keyframes v13-gavel {
  0%,55% { transform: rotate(-32deg); }
  68%    { transform: rotate(6deg); }
  76%    { transform: rotate(-2deg); }
  82%,100% { transform: rotate(0deg); }
}
@keyframes v13-price-pop {
  0%,70% { opacity: 0; transform: scale(.6); }
  84%    { opacity: 1; transform: scale(1.15); }
  100%   { opacity: 1; transform: scale(1); }
}

/* TSO: needle wobble settling to 50.0 Hz */
@keyframes v13-needle {
  0%   { transform: rotate(-26deg); }
  20%  { transform: rotate(22deg); }
  40%  { transform: rotate(-14deg); }
  60%  { transform: rotate(9deg); }
  78%  { transform: rotate(-4deg); }
  100% { transform: rotate(0deg); }
}

/* DSO: pulse traveling HV -> transformer -> house */
@keyframes v13-dso-flow {
  0%   { offset-distance: 0%;   opacity: 0; }
  8%   { opacity: 1; }
  92%  { opacity: 1; }
  100% { offset-distance: 100%; opacity: 0; }
}
@keyframes v13-house-glow {
  0%,70% { fill: var(--ref-muted); }
  85%,100% { fill: var(--ref-cyan); }
}

/* Regulator: stamp press down */
@keyframes v13-stamp {
  0%,40% { transform: translateY(-26px) scale(1); opacity:.5; }
  60%    { transform: translateY(0) scale(1); opacity:1; }
  70%    { transform: translateY(-4px) scale(1); }
  80%,100%{ transform: translateY(0) scale(1); }
}
@keyframes v13-stamp-mark {
  0%,62% { opacity: 0; transform: scale(.4); }
  78%    { opacity: 1; transform: scale(1.1); }
  100%   { opacity: 1; transform: scale(1); }
}

.v13-anim { transform-box: fill-box; transform-origin: center; }
.v13-gavel-g  { transform-box: fill-box; transform-origin: 90% 90%; animation: v13-gavel 3s ease-in-out infinite; }
.v13-price-g  { animation: v13-price-pop 3s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }
.v13-needle-g { transform-box: fill-box; transform-origin: 50% 100%; animation: v13-needle 3s ease-in-out infinite; }
.v13-dso-dot  { animation: v13-dso-flow 2.6s linear infinite; }
.v13-house    { animation: v13-house-glow 2.6s ease-in-out infinite; }
.v13-stamp-g  { animation: v13-stamp 3s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }
.v13-stamp-mark-g { animation: v13-stamp-mark 3s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }

@media (prefers-reduced-motion: reduce) {
  .v13-core, .v13-gavel-g, .v13-price-g, .v13-needle-g,
  .v13-dso-dot, .v13-house, .v13-stamp-g, .v13-stamp-mark-g {
    animation: none !important;
  }
}

/* ============================================================
   TSO interactive controls: production / demand sliders
   ============================================================ */
.tso-controls {
  width: 100%;
  max-width: 300px;
  margin: 8px auto 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.tso-slider { width: 100%; }
.tso-slider-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  font-weight: 600;
  color: var(--text, #1a2436);
  margin-bottom: 5px;
}
.tso-slider-top i { color: #3FA9C4; margin-right: 3px; }
.tso-val {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: #3FA9C4;
  min-width: 26px;
  text-align: right;
}
.tso-controls input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 6px;
  background: rgba(63,169,196,0.18);
  outline: none;
  cursor: pointer;
}
.tso-controls input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: #3FA9C4;
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(26,36,54,0.25);
  cursor: pointer;
}
.tso-controls input[type="range"]::-moz-range-thumb {
  width: 18px; height: 18px;
  border-radius: 50%;
  background: #3FA9C4;
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(26,36,54,0.25);
  cursor: pointer;
}
body.theme-dark .tso-controls input[type="range"] { background: rgba(63,169,196,0.25); }
body.theme-dark .tso-slider-top { color: #e8e8ef; }
.tso-reset {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 4;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-mute, #8090a8);
  background: rgba(63,169,196,0.10);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 9px;
}
.tso-reset:hover { color: #3FA9C4; background: rgba(63,169,196,0.18); }

/* ============================================================
   TSO country picker (dropdown + result chip)
   ============================================================ */
.v13-picker {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 12.5px;
  margin: 4px 0 0;
}
.v13-picker-label {
  color: var(--text-mute, #8090a8);
  font-weight: 600;
}
.v13-picker-select {
  font: inherit;
  font-size: 12.5px;
  padding: 4px 26px 4px 10px;
  border: 1px solid rgba(63,169,196,0.35);
  border-radius: 8px;
  background: #fff
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'><path d='M1 1l4 4 4-4' stroke='%233FA9C4' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/></svg>")
    no-repeat right 8px center;
  color: var(--text, #1a2436);
  cursor: pointer;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.v13-picker-select:hover  { border-color: #3FA9C4; }
.v13-picker-select:focus  { outline: none; border-color: #3FA9C4;
                            box-shadow: 0 0 0 3px rgba(63,169,196,0.18); }
.v13-picker-out {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(63,169,196,0.10);
  color: var(--text, #1a2436);
  font-size: 12.5px;
}
.v13-picker-out-label { color: var(--text-mute, #8090a8); }
.v13-picker-out-name  { color: #3FA9C4; font-weight: 700; }
body.theme-dark .v13-picker-select {
  background-color: #232639;
  border-color: rgba(63,169,196,0.45);
  color: #e8e8ef;
}
body.theme-dark .v13-picker-out { background: rgba(63,169,196,0.18); }


/* ============================================================
   DSO fanout + outage simulation
   ============================================================ */
.dso-controls {
  display: flex;
  justify-content: center;
  margin: 6px 0 0;
}
.dso-outage {
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  color: #3FA9C4;
  background: rgba(63,169,196,0.10);
  border: none;
  border-radius: 999px;
  padding: 6px 14px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: background 0.15s, color 0.15s;
}
.dso-outage:hover { background: rgba(63,169,196,0.20); }
.dso-outage.is-out {
  color: #d9534f;
  background: rgba(217,83,79,0.12);
  cursor: default;
}
.dso-outage.is-out:hover { background: rgba(217,83,79,0.12); }

.dso-icon { transition: opacity 0.45s ease, filter 0.45s ease; }
.dso-icon.is-off {
  opacity: 0.28;
  filter: grayscale(1);
}

/* DSO redundancy extras: disabled state when all transformers are down */
.dso-outage:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  color: var(--text-mute, #8090a8);
  background: rgba(128,144,168,0.10);
}
.dso-outage:disabled:hover { background: rgba(128,144,168,0.10); }

.op-price {
  paint-order: stroke;
  stroke: var(--ref-halo, #f2f9fb);
  stroke-width: 3px;
  stroke-linejoin: round;
}

