/* Terraform: Code, Cloud and State. Opened full screen or in an iframe,
   which cannot see the site's own light/dim switch, so it follows the
   reader's system preference, as the other viewers do (their controls,
   cards and events are copied here, so the series look alike). */

:root {
  --bg: #ffffff;
  --card: #ffffff;
  --border: #dfe3e8;
  --text: #22272e;
  --dim: #5f6b78;
  --accent: #326ce5;
  --btn: #f4f5f7;
  --panel: #0d2436;
  --panel-text: #eaf1f6;
  --raw: #f7f8fa;
  --flash: rgba(255, 196, 0, 0.3);
  --code-bg: #f6f8fa;
  --tf: #7b42bc;
  --aws: #d97706;
  --ok: #1f883d;
  --gone: #cf222e;
  --term-bg: #0d1117;
  --ws: #3d5a80;
  --term-text: #d1d7e0;
  --yk: #1b4f9c;
  --ys: #0a6b3d;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1d2b;
    --card: #112b40;
    --border: #234862;
    --text: #eaf1f6;
    --dim: #9fb2c2;
    --accent: #6f9bff;
    --btn: #16374f;
    --panel: #081b29;
    --raw: #0d2233;
    --flash: rgba(255, 196, 0, 0.18);
    --code-bg: #0d2233;
    --tf: #b48ae6;
    --aws: #f0a050;
    --ok: #4ac26b;
    --gone: #ff7b72;
    --term-bg: #050c12;
  --ws: #7fa7d6;
    --yk: #9cc2ff;
    --ys: #8fe3a8;
  }
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.dim { color: var(--dim); font-weight: 400; }
.kv-app { padding: 0.5rem 16px 1rem; max-width: 1700px; margin: 0 auto; }
.kv-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.2rem 0.9rem; margin: 0 0 0.45rem; }
.kv-head h1 { font-size: 1.3rem; margin: 0; letter-spacing: -0.01em; }
.kv-head p { margin: 0; color: var(--dim); font-size: 0.92rem; }
.in-viewer .kv-head { display: none; }

/* --- controls */
.kv-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 0.75rem; margin-bottom: 0.6rem; }
.kv-bar .count { font-family: ui-monospace, Menlo, monospace; font-size: 0.8rem; color: var(--dim); }
.kv-btn { background: var(--btn); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: 0.35rem 0.9rem; font-size: 0.88rem; cursor: pointer; font-family: inherit; }
.kv-btn:hover:not(:disabled) { border-color: var(--accent); }
.kv-btn:disabled { opacity: 0.45; cursor: default; }
.kv-btn.play { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; min-width: 6rem; }
.kv-btn.go { border-color: var(--accent); color: var(--accent); font-weight: 600; }
.kv-btn.tiny { padding: 0.05rem 0.45rem; font-size: 0.74rem; border-radius: 5px; }
.kv-app select { background: var(--btn); color: var(--text); border: 1px solid var(--border); border-radius: 7px;
  padding: 0.3rem 0.4rem; font-size: 0.86rem; font-family: inherit; min-width: 0; max-width: 100%; }

/* --- the stage: our workstation (the terminal, Terraform, the project's
   files) on the left, the registry and AWS, the events. Every card has a
   fixed size and scrolls; the stage fills the window. */
.tv-stage { position: relative; display: grid; gap: 12px;
  grid-template-columns: minmax(0, 2.6fr) minmax(0, 1fr) minmax(0, 330px);
  transition: grid-template-columns 0.7s ease-in-out;
  grid-template-rows: auto minmax(0, 1fr);
  grid-template-areas: "ws reg log" "ws aws log";
  height: max(540px, calc(100vh - 6.4rem)); }
/* Framed, the stage fills the frame under the controls, with no page scrolling */
@media (min-width: 1101px) { .in-viewer .tv-stage { height: max(500px, calc(100vh - 4.3rem)); } }
/* With the state in S3, our workstation squeezes and AWS widens to hold it */
@media (min-width: 1101px) { .tv-stage.remote { grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr) minmax(0, 330px); } }
.tv-ws { grid-area: ws; } .tv-reg { grid-area: reg; } .tv-aws { grid-area: aws; } .tv-log { grid-area: log; }

/* Our workstation: a dashed frame around what runs on it */
.tv-ws { position: relative; min-height: 0; min-width: 0; display: grid; gap: 10px; padding: 1.75rem 10px 10px;
  border: 3px dashed var(--ws); border-radius: 14px; background: color-mix(in srgb, var(--ws) 6%, transparent);
  grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr);
  grid-template-rows: minmax(0, 0.95fr) minmax(0, 1.05fr);
  grid-template-areas: "term tf" "dir dir"; transition: border-color 0.3s; }
.tv-ws.here { border-color: var(--accent); }
.ws-label { position: absolute; left: 10px; top: 0.3rem; font-size: 0.8rem; font-weight: 800; text-transform: uppercase;
  letter-spacing: 0.06em; color: #fff; background: var(--ws); padding: 0.08rem 0.6rem; border-radius: 6px; }
.tv-term { grid-area: term; } .tv-tf { grid-area: tf; } .tv-dir { grid-area: dir; }

@media (max-width: 1100px) {
  .tv-stage { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); height: auto;
    grid-template-rows: auto auto auto 440px;
    grid-template-areas: "ws ws" "reg reg" "aws aws" "log log"; }
  .tv-ws { grid-template-rows: 340px 420px; }
  .tv-aws { height: 300px; }
  /* The cards stand one under another and the page follows the step, so
     the controls stay pinned to the top of the screen */
  .kv-bar { position: sticky; top: 0; z-index: 40; background: var(--bg); margin: 0 -16px 0.6rem; padding: 0.4rem 16px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12); }
}
@media (max-width: 640px) {
  .kv-bar { gap: 0.35rem 0.5rem; }
  .kv-bar .kv-btn { padding: 0.3rem 0.7rem; }
  .kv-bar select { flex: 1 1 10rem; }
  .tv-stage { grid-template-columns: minmax(0, 1fr); grid-template-areas: "ws" "reg" "aws" "log"; }
  .tv-ws { grid-template-columns: minmax(0, 1fr); grid-template-rows: 340px 300px 520px; grid-template-areas: "term" "tf" "dir"; }
  .dir-body { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 0.8fr) minmax(0, 1.2fr); }
}

.kv-card { display: flex; flex-direction: column; min-height: 0; min-width: 0; overflow: hidden;
  border: 1px solid var(--border); border-radius: 12px; background: var(--card); font-size: 0.84rem;
  transition: box-shadow 0.25s, border-color 0.25s, opacity 0.4s; }
.kv-card.here { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 35%, transparent); }
.kv-card > header { flex: none; display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap;
  padding: 0.45rem 0.7rem 0.4rem; border-bottom: 1px solid var(--border); }
/* A title keeps its words: beside a button too wide for both, the button wraps under it */
.kv-card > header h2 { font-size: 0.92rem; margin: 0; flex: 1 1 auto; }
.kv-card > header h2 code { font-size: 0.72rem; color: var(--dim); font-weight: 400; margin-left: 0.3rem; }
.kv-card > header .turn { font-size: 0.8rem; padding: 0.2rem 0.6rem; animation: tv-due 1.4s ease-in-out infinite; }
@keyframes tv-due { 50% { box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 30%, transparent); } }
.kv-body { flex: 1; min-height: 0; overflow: auto; padding: 0.5rem 0.7rem; }
h3 { font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--dim); margin: 0 0 0.35rem; }
section > p, .box > p { margin: 0; }

/* --- the terminal: the picture beside it */
.term-body { display: grid; grid-template-columns: auto minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); gap: 0.5rem; padding: 0.5rem; overflow: hidden; }
.art.you { display: block; align-self: end; height: min(120px, 100%); }
.art.you img { display: block; height: 100%; width: auto; }
.tv-stage.remote .art.you { height: min(80px, 100%); }
pre.term { margin: 0; min-height: 0; overflow: auto; background: var(--term-bg); color: var(--term-text); border-radius: 8px;
  padding: 0.45rem 0.6rem; font: 0.72rem/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; white-space: pre-wrap; overflow-wrap: anywhere; }
pre.term .cmd { color: #8fe3a8; font-weight: 700; }
pre.term .add { color: #7ee787; } pre.term .del { color: #ff7b72; } pre.term .ok { color: #7ee787; font-weight: 700; }
pre.term .dimt { color: #8b949e; }
pre.term .new { background: rgba(255, 196, 0, 0.16); }

/* --- Terraform: the core, the provider, the plan */
.tf-body { display: flex; flex-direction: column; gap: 0.5rem; }
.box { border: 1px solid var(--border); border-left: 4px solid var(--tf); border-radius: 7px; padding: 0.35rem 0.55rem; background: var(--raw); }
.box b { font-size: 0.86rem; }
.box .what { display: block; color: var(--dim); font-size: 0.78rem; line-height: 1.35; }
.box.missing { border-style: dashed; border-left-style: dashed; background: none; }
.box.prov { border-left-color: var(--aws); }
.plan { list-style: none; margin: 0.15rem 0 0; padding: 0; font: 0.78rem ui-monospace, Menlo, monospace; }
.plan .add { color: var(--ok); font-weight: 700; }
.plan .del { color: var(--gone); font-weight: 700; }

/* --- the project's directory: main.tf beside terraform.tfstate */
.dir-body { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 0.6rem; overflow: hidden; }
.pane { min-height: 0; display: flex; flex-direction: column; }
.dir-body.solo { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); }
.files { display: flex; flex-wrap: wrap; gap: 0.25rem 0.4rem; margin-bottom: 0.35rem; font: 0.74rem ui-monospace, Menlo, monospace; }
.files span { padding: 0.02rem 0.35rem; border: 1px solid var(--border); border-radius: 4px; background: var(--raw); }
pre.code { flex: 1; min-height: 0; overflow: auto; margin: 0; padding: 0.4rem 0.55rem; background: var(--code-bg); border-radius: 7px;
  font: 0.72rem/1.42 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; white-space: pre-wrap; overflow-wrap: anywhere; }
pre.code .yk { color: var(--yk); } pre.code .ys { color: var(--ys); }
pre.code .hl { background: color-mix(in srgb, var(--flash) 75%, transparent); }
.nofile { flex: 1; display: grid; place-items: center; text-align: center; padding: 0.6rem; border: 2px dashed var(--border); border-radius: 7px;
  color: var(--dim); font-size: 0.8rem; }

/* --- the registry and AWS */
.tv-reg > header, .tv-aws > header { border-top: 4px solid var(--c); }
.tv-reg > header h2, .tv-aws > header h2 { color: var(--c); }
.tv-reg { --c: var(--tf); }
.reg-body { display: flex; flex-direction: column; }
.pkg { border: 1px solid var(--border); border-left: 4px solid var(--c); border-radius: 7px; padding: 0.3rem 0.5rem; background: var(--raw);
  font-size: 0.8rem; margin-bottom: 0.35rem; }
.pkg code { display: block; font-size: 0.72rem; overflow-wrap: anywhere; }
.pkg.other { border-left-color: var(--border); color: var(--dim); } .tv-aws { --c: var(--aws); }
.aws-body { display: flex; flex-direction: column; gap: 0.5rem; }
.api { border: 1px solid var(--c); border-radius: 7px; padding: 0.3rem 0.5rem; font-size: 0.78rem; }
.api b { display: block; font: 700 0.78rem ui-monospace, Menlo, monospace; }
.inst { border: 1px solid var(--border); border-left: 4px solid var(--c); border-radius: 7px; padding: 0.35rem 0.55rem; background: var(--raw); }
.inst b { font-size: 0.9rem; }
.inst code { display: block; font-size: 0.74rem; color: var(--dim); }
.inst .st { font-size: 0.72rem; font-weight: 700; padding: 0.02rem 0.4rem; border-radius: 9px; border: 1px solid; margin-left: 0.3rem; }
.inst .st.running { color: var(--ok); }
.inst .st.terminated { color: var(--gone); }
.inst.gone { opacity: 0.6; border-left-style: dashed; }
.inst .by, .bucket .by { display: block; font-size: 0.74rem; color: var(--dim); margin-top: 0.15rem; }
.bucket { border: 1px solid var(--border); border-left: 4px solid var(--c); border-radius: 7px; padding: 0.35rem 0.55rem; background: var(--raw);
  display: flex; flex-direction: column; gap: 0.3rem; }
.bucket b { font: 700 0.86rem ui-monospace, Menlo, monospace; }
.bucket .obj { font-size: 0.74rem; }
.bucket pre.code { max-height: 230px; flex: none; }

/* --- the events */
.log { list-style: none; margin: 0; padding: 0; }
.log-intro { font-size: 0.84rem; line-height: 1.45; }
.log-intro p { margin: 0 0 0.4rem; }
.log-intro .main { font-weight: 600; }
.log li { border-bottom: 1px dashed var(--border); }
.log-head { all: unset; box-sizing: border-box; width: 100%; display: grid; grid-template-columns: 1.6rem minmax(0, 1fr) auto; gap: 0.4rem; align-items: baseline; padding: 0.15rem 0.3rem; cursor: pointer; }
.log-head::after { content: '▸'; color: var(--dim); font-size: 0.7rem; }
.log li.open .log-head::after { content: '▾'; }
.log-head:focus-visible { outline: 2px solid var(--accent); }
.log li:hover .log-head { background: color-mix(in srgb, var(--flash) 40%, transparent); }
.log li.now .log-head { background: color-mix(in srgb, var(--flash) 75%, transparent); }
.log li.now.open .log-body { background: color-mix(in srgb, var(--flash) 30%, transparent); }
.log-body { padding: 0.2rem 0.5rem 0.5rem 2.1rem; font-size: 0.8rem; line-height: 1.42; }
.log-body p { margin: 0 0 0.3rem; }
.log-body .main { font-weight: 600; font-size: 0.9rem; }
.log .n { color: var(--dim); font-family: ui-monospace, Menlo, monospace; font-size: 0.72rem; }
.log .scene { font-size: 0.66rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--dim); padding: 0.5rem 0.3rem 0.15rem; border-bottom: none; }
.log-body ul.steps, .log-intro ul.steps { margin: 0 0 0.35rem; padding-left: 1.05rem; list-style: disc; }
.log-body ul.steps li, .log-intro ul.steps li { border: 0; margin: 0 0 0.15rem; }
.log-body ul.steps ul.steps, .log-intro ul.steps ul.steps { margin: 0.1rem 0; list-style: circle; }
.log code, .log-intro code { font-size: 0.92em; background: var(--code-bg); padding: 0 0.2em; border-radius: 3px; }

/* --- a tour step's spotlight: what it names pulses, the rest dims */
.tv-stage.spotlight .kv-card:not(.here):not(.tv-log) { opacity: 0.35; }
.tv-stage .act { animation: tv-pulse 1.1s ease-in-out 3; outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 2px; border-radius: 8px; }
@keyframes tv-pulse { 50% { filter: brightness(1.12); } }

/* --- what is in the air: a message flying along its arrow */
#tv-fly { position: absolute; left: 0; top: 0; width: 0; height: 0; overflow: visible; pointer-events: none; z-index: 50; }
#tv-fly .trail { position: absolute; left: 0; top: 0; overflow: visible; }
#tv-fly .trail polyline { fill: none; stroke: var(--accent); stroke-width: 2.5; stroke-linecap: round; stroke-dasharray: 3 7; }
#tv-fly .trail path { fill: var(--accent); }
#tv-fly .msg { position: absolute; transform: translate(-50%, -50%); background: var(--panel); color: var(--panel-text);
  border-radius: 6px; padding: 0.12rem 0.5rem; font-size: 0.74rem; font-weight: 600; white-space: nowrap;
  font-family: ui-monospace, Menlo, Consolas, monospace; box-shadow: 0 6px 16px rgba(0, 0, 0, 0.3); }
#tv-fly .msg.doc { background: #fffdf4; color: #22272e; border: 1px solid #c9b98a; border-radius: 3px 10px 3px 3px; font-size: 0.78rem; }
