/* Layout partilhado das páginas das fases.
   Esquerda: o laboratório (onde escreves e carregas nos botões).
   Direita: o guia passo a passo (o que fazes e o que acontece por dentro).
   Em ecrãs estreitos, o laboratório vem primeiro e o guia por baixo. */

:root {
  --bg: #f3efe6;
  --panel: #ebe5d6;
  --code: #e4dcc9;
  --ink: #1c1b18;
  --muted: #6b675d;
  --line: #cfc8b6;
  --accent: #b3361b;
  --on-accent: #ffffff;
  --ok: #2f6b3f;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14130f;
    --panel: #1b1a15;
    --code: #201f19;
    --ink: #ece7d9;
    --muted: #9a9482;
    --line: #36332a;
    --accent: #e8664a;
    --on-accent: #14130f;
    --ok: #8cc79b;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 17px/1.6 Georgia, "Iowan Old Style", "Times New Roman", serif;
}

.mono, h1, h2, .topo, .etq, button, label, dt, .codigo, textarea, input, pre {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

/* Barra do topo com a ligação ao índice */
.topo { border-bottom: 1px solid var(--line); font-size: 0.85rem; }
.topo-in {
  max-width: 80rem; margin: 0 auto; padding: 0.9rem 1rem;
  display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; flex-wrap: wrap;
}
.topo a { color: var(--ink); text-underline-offset: 4px; text-decoration-color: var(--accent); }
.topo a:hover { color: var(--accent); }
.topo .pos { color: var(--muted); }

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

/* Grelha de duas colunas */
.fase {
  max-width: 80rem; margin: 0 auto; padding: 2rem 1rem 4rem;
  display: grid; gap: 2rem 3rem; grid-template-columns: minmax(0, 1fr);
}
.cabecalho { grid-column: 1 / -1; }
.cabecalho h1 {
  font-size: clamp(1.7rem, 5vw, 2.5rem); line-height: 1.1; letter-spacing: -0.03em; margin: 0 0 0.6rem;
}
.cabecalho h1 span { color: var(--accent); }
.cabecalho p { margin: 0; max-width: 40rem; color: var(--muted); font-size: 0.95rem; }

@media (min-width: 62rem) {
  .fase { grid-template-columns: minmax(22rem, 30rem) minmax(0, 42rem); }
  .lab { position: sticky; top: 1rem; align-self: start; max-height: calc(100vh - 2rem); overflow-y: auto; padding-right: 0.5rem; }
}

/* Laboratório */
.bloco { padding: 1.1rem 0; border-top: 1px solid var(--line); }
.bloco:first-child { border-top: 0; padding-top: 0; }
.bloco h2 {
  font-size: 0.8rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--muted); margin: 0 0 0.7rem;
}
.bloco h2 b { color: var(--accent); font-weight: 600; margin-right: 0.5rem; }

label { display: block; margin: 0.6rem 0 0.25rem; font-size: 0.82rem; color: var(--muted); }
textarea, input {
  width: 100%; background: var(--panel); color: var(--ink);
  border: 1px solid var(--line); border-radius: 2px; padding: 0.55rem 0.65rem;
  font-size: 0.88rem; line-height: 1.45;
}
textarea { resize: vertical; }

.botoes { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-top: 0.9rem; }
button {
  background: var(--accent); color: var(--on-accent); border: 1px solid var(--accent);
  border-radius: 2px; padding: 0.5rem 0.9rem; font-size: 0.85rem; cursor: pointer;
}
button:hover { filter: brightness(1.08); }
button.secundario { background: transparent; color: var(--ink); border-color: var(--muted); }
button.secundario:hover { border-color: var(--accent); color: var(--accent); filter: none; }

pre { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 0.85rem; line-height: 1.5; }
#resultado { min-height: 3rem; }
#resultado[data-estado="ok"] { color: var(--ok); }
#resultado[data-estado="erro"] { color: var(--accent); }
.res { min-height: 2.5rem; }
.res[data-estado="ok"] { color: var(--ok); }
.res[data-estado="erro"] { color: var(--accent); }
select { width: 100%; background: var(--panel); color: var(--ink); border: 1px solid var(--line); border-radius: 2px; padding: 0.5rem; font: 0.88rem ui-monospace, Menlo, Consolas, monospace; }
canvas { display: block; width: 100%; max-width: 14rem; image-rendering: pixelated; border: 1px solid var(--line); background: #fff; }
.par { display: flex; gap: 1rem; flex-wrap: wrap; }
.par figure { margin: 0; flex: 1 1 8rem; }
.par figcaption { font: 0.75rem ui-monospace, Menlo, Consolas, monospace; color: var(--muted); margin-top: 0.3rem; }
table.tab { border-collapse: collapse; width: 100%; font-size: 0.85rem; margin: 0.8rem 0; }
table.tab th, table.tab td { border: 1px solid var(--line); padding: 0.35rem 0.5rem; text-align: left; vertical-align: top; }
table.tab th { background: var(--panel); font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 0.78rem; }

/* Guia */
.guia h2.titulo-guia {
  font-size: 0.8rem; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted);
  margin: 0 0 1.2rem; font-weight: 600;
}
.passos { list-style: none; margin: 0; padding: 0; counter-reset: passo; }
.passo {
  counter-increment: passo; position: relative;
  margin: 0 0 0 0.9rem; padding: 0 0 1.8rem 2.2rem; border-left: 1px solid var(--line);
}
.passo::before {
  content: counter(passo); position: absolute; left: -0.95rem; top: -0.1rem;
  width: 1.9rem; height: 1.9rem; display: grid; place-items: center;
  background: var(--bg); border: 1px solid var(--line); border-radius: 50%;
  font: 600 0.8rem ui-monospace, Menlo, Consolas, monospace; color: var(--muted);
}
.passo.feito::before { content: "✓"; color: var(--ok); border-color: var(--ok); }
.passo.ativo::before { background: var(--accent); border-color: var(--accent); color: var(--on-accent); content: counter(passo); }
.passo:last-child { border-left-color: transparent; padding-bottom: 0; }

.passo h3 { font-size: 1.05rem; margin: 0 0 0.5rem; line-height: 1.3; }
.passo.ativo h3 { text-decoration: underline; text-decoration-color: var(--accent); text-underline-offset: 5px; text-decoration-thickness: 2px; }
.passo p { margin: 0 0 0.8rem; }
.passo .corpo { padding: 0; }
.passo.ativo .corpo { background: var(--panel); margin-left: -0.6rem; padding: 0.6rem 0.8rem 0.1rem 0.6rem; border-left: 3px solid var(--accent); }

.por-dentro { border-left: 3px solid var(--line); padding-left: 0.9rem; }
.etq {
  display: block; font-size: 0.72rem; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--muted); margin-bottom: 0.2rem;
}
.sub { margin: 0 0 0.8rem; padding-left: 1.3rem; }
.sub li { margin-bottom: 0.4rem; }

.codigo {
  background: var(--code); border-left: 3px solid var(--line); margin: 0.8rem 0;
  padding: 0.7rem 0.9rem; overflow-x: auto; white-space: pre; word-break: normal;
  font-size: 0.8rem; line-height: 1.55;
}
code { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 0.88em; background: var(--code); padding: 0.05em 0.3em; }

.valores { margin: 0 0 0.8rem; }
.valores dt { font-size: 0.72rem; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); margin-top: 0.6rem; }
.valores dd { margin: 0.1rem 0 0; font: 0.82rem/1.45 ui-monospace, Menlo, Consolas, monospace; word-break: break-all; }

.glossario { margin: 0; }
.glossario dt { font-size: 0.85rem; color: var(--accent); margin-top: 0.8rem; }
.glossario dd { margin: 0.1rem 0 0; }

.rodape-fase {
  display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap;
  margin-top: 2.5rem; padding-top: 1rem; border-top: 1px solid var(--line);
  font: 0.85rem ui-monospace, Menlo, Consolas, monospace;
}
.rodape-fase a { color: var(--ink); text-underline-offset: 4px; text-decoration-color: var(--accent); }
.rodape-fase .off { color: var(--muted); }

@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; } }
