/* Figure (site/js/render.js), Markdown (site/js/md.js) i pregledač koraka.
   Koristi promenljive aplikacije (--fg, --bg, --muted, --line, --hl, --hl-bg, --accent, --card) sa
   rezervnim vrednostima, tako da radi i samostalno (svetla/tamna tema po prefers-color-scheme). */

.fig, .steps, .md {
  --f-fg: var(--fg, #1d2125);
  --f-bg: var(--bg, #ffffff);
  --f-muted: var(--muted, #667079);
  --f-line: var(--line, #c9cfd6);
  --f-hl: var(--hl, #d9480f);
  --f-hl-bg: var(--hl-bg, #ffe8cc);
  --f-accent: var(--accent, #1c64d1);
  --f-card: var(--card, #f6f7f9);
}
@media (prefers-color-scheme: dark) {
  .fig, .steps, .md {
    --f-fg: var(--fg, #e3e6ea);
    --f-bg: var(--bg, #15181c);
    --f-muted: var(--muted, #98a2ad);
    --f-line: var(--line, #3d444c);
    --f-hl: var(--hl, #ff922b);
    --f-hl-bg: var(--hl-bg, #4a2d12);
    --f-accent: var(--accent, #6ea8fe);
    --f-card: var(--card, #1e2329);
  }
}

/* ---------------------------------------------------------------- figure okvir */

.fig {
  margin: 0.75rem 0;
  min-width: 0;
  max-width: 100%;
  color: var(--f-fg);
}
.fig--nested { margin: 0; }
.fig figcaption {
  margin-top: 0.35rem;
  font-size: 0.85rem;
  color: var(--f-muted);
  text-align: center;
}
.fig-scroll {
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
}
.fig-empty { color: var(--f-muted); font-style: italic; padding: 0.5rem 0; }

/* ---------------------------------------------------------------- SVG */

.fig-svg {
  display: block;
  margin: 0 auto;
  height: auto;
  max-height: 80vh;
  overflow: visible;
  font-family: inherit;
  color: var(--f-fg);
}
.fig--compact .fig-svg { max-height: 180px; }
.fig-svg text { fill: currentColor; }
.fig-svg .lbl { font-weight: 500; }
.fig-svg .muted { fill: var(--f-muted); }
.fig-svg .halo {
  paint-order: stroke;
  stroke: var(--f-bg);
  stroke-width: 4px;
  stroke-linejoin: round;
}
.fig-svg .shape { fill: var(--f-card); stroke: currentColor; stroke-width: 1.5; }
.fig-svg .sep { stroke: currentColor; stroke-width: 1.2; }
.fig-svg .edge { stroke: currentColor; stroke-width: 1.5; fill: none; }
.fig-svg .edge.dashed { stroke-dasharray: 6 4; }
.fig-svg .edge.dim { opacity: 0.4; stroke-dasharray: 4 3; }
.fig-svg .arrow { fill: currentColor; stroke: none; }
.fig-svg .dot { fill: currentColor; }
.fig-svg .nil { stroke: currentColor; stroke-width: 1.2; }

.fig-svg .hl .shape, .fig-svg .hl.shape { fill: var(--f-hl-bg); stroke: var(--f-hl); stroke-width: 2.5; }
.fig-svg .edge.hl { stroke: var(--f-hl); stroke-width: 3; }
.fig-svg .arrow.hl { fill: var(--f-hl); }
.fig-svg .weight.hl { fill: var(--f-hl); font-weight: 700; }
.fig-svg .cell-hl { fill: var(--f-hl-bg); stroke: var(--f-hl); stroke-width: 1.5; }

.fig-svg .dim { opacity: 0.42; }
.fig-svg .tnode.dim .shape { stroke-dasharray: 4 3; }

.fig-svg .tag { fill: var(--f-accent); font-weight: 600; }
.fig-svg .edge-label { fill: var(--f-accent); font-weight: 600; }
.fig-svg .weight { font-weight: 600; }

.fig-svg .thread { stroke: var(--f-accent); stroke-width: 1.4; stroke-dasharray: 5 4; fill: none; }
.fig-svg .thread-head { fill: var(--f-accent); }
.fig-svg .leaf-link { stroke: currentColor; stroke-width: 1.3; }

.fig-svg .lnode.header .shape { fill: var(--f-line); }

/* ---------------------------------------------------------------- tabele, matrice, nizovi */

.fig-matrix, .fig-table, .fig-array {
  border-collapse: collapse;
  margin: 0 auto;
  font-variant-numeric: tabular-nums;
  color: var(--f-fg);
}
.fig-matrix td, .fig-matrix th, .fig-table td, .fig-table th {
  border: 1px solid var(--f-line);
  padding: 0.25rem 0.5rem;
  min-width: 2em;
  text-align: center;
  white-space: nowrap;
}
.fig-matrix th, .fig-table th {
  background: var(--f-card);
  font-weight: 600;
}
.fig-matrix th { color: var(--f-muted); }
.fig-matrix th.corner { background: transparent; border-color: transparent; }
.fig-matrix td.dim { color: var(--f-muted); opacity: 0.55; }
.fig-matrix td.hl, .fig-table td.hl, .fig-table tr.hl-row td {
  background: var(--f-hl-bg);
  box-shadow: inset 0 0 0 2px var(--f-hl);
  font-weight: 700;
}
.fig-table tr.hl-row td { box-shadow: none; }

.fig-array td.cell {
  border: 1.5px solid var(--f-fg);
  min-width: 2.2em;
  height: 2.2em;
  padding: 0 0.4rem;
  text-align: center;
  white-space: nowrap;
}
.fig-array td.cell.hl { background: var(--f-hl-bg); border-color: var(--f-hl); box-shadow: inset 0 0 0 1.5px var(--f-hl); font-weight: 700; }
.fig-array td.cell.dim { color: var(--f-muted); opacity: 0.5; }
.fig-array th.idx { font-size: 0.75rem; font-weight: 400; color: var(--f-muted); padding: 0 0.2rem 0.15rem; text-align: center; }
.fig-array td.mark { font-size: 0.8rem; color: var(--f-accent); font-weight: 600; text-align: center; line-height: 1.05; padding-top: 0.15rem; white-space: nowrap; }
.fig-array .mark-arrow { font-size: 0.9rem; }
.fig-array.vertical th.idx { padding: 0 0.5rem 0 0; text-align: right; vertical-align: middle; }
.fig-array.vertical td.cell { min-width: 4em; height: 1.9em; }
.fig-array.vertical td.mark { text-align: left; padding: 0 0 0 0.4rem; vertical-align: middle; }

/* ---------------------------------------------------------------- stek / red */

.fig-stack { display: inline-flex; flex-direction: column; align-items: stretch; }
.fig--stack { text-align: center; }
.fig--stack > .fig-stack { text-align: left; }
.stk-row { display: grid; grid-template-columns: 3.4em minmax(3.2em, auto); align-items: center; }
.stk-row .ptr { font-size: 0.8rem; color: var(--f-accent); font-weight: 600; text-align: right; padding-right: 0.35rem; white-space: nowrap; }
.stk-cell {
  border: 1.5px solid var(--f-fg);
  border-top-width: 0;
  min-height: 2em;
  padding: 0.2rem 0.6rem;
  text-align: center;
  display: flex; align-items: center; justify-content: center;
  border-left-width: 2px; border-right-width: 2px;
}
.stk-row:first-child .stk-cell { border-top-width: 1.5px; }
.stk-row.bottom .stk-cell, .stk-cell.empty { border-bottom-width: 3px; }
.stk-cell.empty { border-top: 0; color: var(--f-muted); font-style: italic; font-size: 0.85rem; min-height: 2.4em; }
.stk-cell.hl { background: var(--f-hl-bg); border-color: var(--f-hl); font-weight: 700; }

.fig-queue { display: inline-grid; grid-auto-rows: auto; margin: 0 auto; }
.fig--queue .fig-scroll { text-align: center; }
.q-cell {
  border: 1.5px solid var(--f-fg);
  border-left-width: 0;
  min-width: 2.2em; min-height: 2.1em;
  padding: 0.2rem 0.5rem;
  display: flex; align-items: center; justify-content: center;
  white-space: nowrap;
}
.q-cell:first-child { border-left-width: 1.5px; }
.q-cell.empty { border: 1.5px dashed var(--f-line); color: var(--f-muted); font-style: italic; font-size: 0.85rem; }
.q-cell.hl { background: var(--f-hl-bg); box-shadow: inset 0 0 0 1.5px var(--f-hl); font-weight: 700; }
.q-ptr { position: relative; height: 1.35em; font-size: 0.78rem; color: var(--f-accent); font-weight: 600; white-space: nowrap; }
.q-ptr > span { position: absolute; left: 0.3em; top: 0.15em; }
.q-ptr.end > span { left: auto; right: 0.3em; }
.q-ptr.only > span { left: 50%; transform: translateX(-50%); }

/* ---------------------------------------------------------------- tekst i grupa */

.fig-text { text-align: left; }
.fig-text > :first-child { margin-top: 0; }
.fig-text > :last-child { margin-bottom: 0; }

.fig-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.5rem;
  align-items: flex-start;
  justify-content: center;
}
.fig-group > .fig { flex: 0 1 auto; min-width: 0; max-width: 100%; }
.fig-group > .fig--tree, .fig-group > .fig--graph, .fig-group > .fig--list { flex: 1 1 200px; }
.fig-group > .fig--text { flex: 0 1 auto; align-self: center; }
.fig-group.col { flex-direction: column; flex-wrap: nowrap; align-items: stretch; }
.fig-group.col > .fig { flex: none; }

.fig--compact { font-size: 0.85em; margin: 0.25rem 0; }
.fig--compact .fig-array td.cell { min-width: 1.8em; height: 1.8em; }

/* ---------------------------------------------------------------- Markdown */

/* break-word (ne anywhere): ne smanjuje min-content širinu, pa se ćelije md tabela ne lome po slovima */
.md { line-height: 1.55; overflow-wrap: break-word; }
.md p { margin: 0.5em 0; }
.md code {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 0.9em;
  background: var(--f-card);
  border: 1px solid var(--f-line);
  border-radius: 4px;
  padding: 0.05em 0.3em;
  overflow-wrap: break-word;
}
.md pre.code, pre.code {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 0.86rem;
  line-height: 1.45;
  background: var(--f-card, var(--card, #f6f7f9));
  border: 1px solid var(--f-line, var(--line, #c9cfd6));
  border-radius: 6px;
  padding: 0.6rem 0.75rem;
  margin: 0.6em 0;
  max-width: 100%;
  overflow-x: auto;
  white-space: pre;
  tab-size: 4;
  -webkit-overflow-scrolling: touch;
}
.md pre.code code, pre.code code { background: none; border: 0; padding: 0; font-size: inherit; overflow-wrap: normal; }
pre.code .kw { font-weight: 700; color: var(--f-accent, var(--accent, #1c64d1)); }
pre.code .cm { color: var(--f-muted, var(--muted, #667079)); font-style: italic; }
pre.code .st { color: var(--f-muted, var(--muted, #667079)); }
.md blockquote {
  margin: 0.6em 0;
  padding: 0.35em 0.8em;
  border-left: 3px solid var(--f-accent);
  background: var(--f-card);
  border-radius: 0 6px 6px 0;
}
.md blockquote > :first-child { margin-top: 0; }
.md blockquote > :last-child { margin-bottom: 0; }
.md ul, .md ol { margin: 0.5em 0; padding-left: 1.4em; }
.md li { margin: 0.2em 0; }
.md li > p { margin: 0.25em 0; }
.md h1, .md h2, .md h3, .md h4 { line-height: 1.25; margin: 1em 0 0.4em; }
.md h3 { font-size: 1.05rem; }
.md hr { border: 0; border-top: 1px solid var(--f-line); margin: 1em 0; }
.md .md-table { max-width: 100%; overflow-x: auto; margin: 0.6em 0; }
.md .md-table table { border-collapse: collapse; font-variant-numeric: tabular-nums; }
.md .md-table th, .md .md-table td { border: 1px solid var(--f-line); padding: 0.25rem 0.55rem; vertical-align: top; overflow-wrap: normal; }
.md .md-table th { background: var(--f-card); font-weight: 600; text-align: left; }
.md sub, .md sup { line-height: 0; }

/* ---------------------------------------------------------------- pregledač koraka */

.steps {
  border: 1px solid var(--f-line);
  border-radius: 10px;
  background: var(--f-bg);
  color: var(--f-fg);
  padding: 0.5rem 0.75rem 0.6rem;
  min-width: 0;
  max-width: 100%;
  outline: none;
  position: relative;
  overflow: hidden;
}
.steps:focus-visible { box-shadow: 0 0 0 3px color-mix(in srgb, var(--f-accent) 45%, transparent); }
.steps-progress { height: 3px; background: var(--f-line); border-radius: 2px; overflow: hidden; margin-bottom: 0.4rem; }
.steps-progress > span { display: block; height: 100%; width: 0; background: var(--f-accent); }
.steps-stage { min-width: 0; }
.steps-stage > .fig { margin: 0.25rem 0; }
.steps-note {
  min-height: 1.5em;
  margin: 0.35rem 0 0.5rem;
  font-size: 0.95rem;
  line-height: 1.45;
  overflow-wrap: anywhere;
}
.steps-note code {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.9em; background: var(--f-card); border: 1px solid var(--f-line); border-radius: 4px; padding: 0 0.25em;
}
.steps-nav { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; }
.steps-count { font-size: 0.9rem; color: var(--f-muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.steps-btn {
  min-width: 44px; min-height: 44px;
  padding: 0 0.9rem;
  border-radius: 8px;
  border: 1px solid var(--f-line);
  background: var(--f-card);
  color: var(--f-fg);
  font: inherit; font-size: 0.95rem;
  cursor: pointer;
  touch-action: manipulation;
}
.steps-btn > [aria-hidden] { font-size: 1.3em; line-height: 1; vertical-align: -0.08em; }
.steps-btn.next:not(:disabled) { background: var(--f-accent); border-color: var(--f-accent); color: var(--f-bg); }
.steps-btn:disabled { opacity: 0.4; cursor: default; }
.steps-btn:focus-visible { outline: 3px solid color-mix(in srgb, var(--f-accent) 55%, transparent); outline-offset: 1px; }
@media (max-width: 360px) { .steps-btn .btn-txt { display: none; } }

@media (prefers-reduced-motion: no-preference) {
  .steps-stage.anim > .fig { animation: steps-in 0.18s ease-out; }
  .steps-stage.anim[data-dir="prev"] > .fig { animation-name: steps-in-prev; }
  .steps-progress > span { transition: width 0.18s ease-out; }
}
@keyframes steps-in { from { opacity: 0; transform: translateX(10px); } to { opacity: 1; transform: none; } }
@keyframes steps-in-prev { from { opacity: 0; transform: translateX(-10px); } to { opacity: 1; transform: none; } }

@media print {
  .steps-nav, .steps-progress { display: none; }
  .fig-scroll { overflow: visible; }
}
.fig-matrix td.hl.dim { opacity: 1; color: var(--f-fg); }
@media (max-width: 480px) {
  .fig-matrix td, .fig-matrix th, .fig-table td, .fig-table th { padding: 0.2rem 0.3rem; min-width: 1.7em; }
}
