:root {
  /* Paleta do blog (PaperMod) — tema claro padrão */
  --theme: rgb(255, 255, 255);
  --entry: rgb(255, 255, 255);
  --primary: rgb(30, 30, 30);
  --secondary: rgb(108, 108, 108);
  --tertiary: rgb(214, 214, 214);
  --content: rgb(31, 31, 31);
  --code-bg: rgb(245, 245, 245);
  --border: rgb(238, 238, 238);

  /* Aliases usados pelo simulador, mapeados para a paleta neutra */
  --bg: var(--theme);
  --panel: var(--code-bg);
  --board: var(--entry);
  --gold: var(--primary);
  --gold-dim: var(--border);
  --gold-soft: var(--primary);
  --lit: var(--primary);
  --lit-glow: rgba(0, 0, 0, 0.18);
  --on-accent: var(--theme);
  --text: var(--primary);
  --muted: var(--secondary);
  --ok: #2f7d32;
  --bad: #c0392b;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --theme: rgb(29, 30, 32);
    --entry: rgb(46, 46, 51);
    --primary: rgb(218, 218, 219);
    --secondary: rgb(155, 156, 157);
    --tertiary: rgb(65, 66, 68);
    --content: rgb(196, 196, 197);
    --code-bg: rgb(55, 56, 62);
    --border: rgb(51, 51, 51);
    --lit-glow: rgba(0, 0, 0, 0.5);
    --ok: #6fe06f;
    --bad: #ff6b6b;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--theme);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  min-height: 100%;
}

.app-header {
  text-align: center;
  padding: 18px 12px 6px;
}

.app-header h1 {
  margin: 0;
  font-size: clamp(18px, 4vw, 28px);
  letter-spacing: 4px;
  font-weight: 700;
  color: var(--gold-soft);
}

.app-header h1 span { color: var(--text); }

.layout {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
  justify-content: center;
  align-items: flex-start;
  padding: 12px 16px 40px;
  max-width: 1100px;
  margin: 0 auto;
}

/* ---- Árvore ---- */
.board-col {
  flex: 1 1 320px;
  max-width: 440px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.board {
  position: relative;
  width: 100%;
  background: var(--board);
  border: 3px solid var(--gold-dim);
  border-radius: 16px;
  padding: 8px 8px 86px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.12);
}

#tree {
  width: 100%;
  height: auto;
  display: block;
}

.legend {
  display: flex;
  justify-content: center;
  gap: 18px;
  margin-top: 8px;
  font-size: 13px;
  color: var(--muted);
}

.legend-item { display: inline-flex; align-items: center; gap: 7px; }

.legend-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--gold-soft);
  display: inline-block;
}

.legend-dash {
  width: 22px;
  height: 9px;
  border-radius: 4px;
  background: var(--gold-soft);
  display: inline-block;
}

.legend-hint {
  margin: 6px 4px 2px;
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.4;
}

.edge {
  stroke: var(--gold-dim);
  stroke-width: 3;
  fill: none;
}

.mark {
  fill: var(--primary);
  stroke: var(--theme);
  stroke-width: 1;
}

.node-shape {
  fill: var(--entry);
  stroke: var(--primary);
  stroke-width: 2.5;
  transition: fill 0.08s ease, filter 0.08s ease;
}

.node-label {
  fill: var(--gold-soft);
  font-size: 22px;
  font-weight: 700;
  text-anchor: middle;
  dominant-baseline: central;
  pointer-events: none;
}

.node.lit .node-shape {
  fill: var(--tertiary);
  stroke: var(--primary);
}

.node.current .node-shape {
  fill: var(--primary);
  filter: drop-shadow(0 0 8px var(--lit-glow));
}

.node.current .node-label { fill: var(--theme); }

.antenna { stroke: var(--gold); stroke-width: 2.5; fill: none; }

/* ---- Painel ---- */
.panel {
  flex: 1 1 320px;
  max-width: 440px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.modes {
  display: flex;
  gap: 6px;
  background: var(--panel);
  border: 1px solid var(--gold-dim);
  border-radius: 12px;
  padding: 5px;
  width: calc(100% - 32px);
  max-width: 440px;
  margin: 8px auto 0;
}

.mode-btn {
  flex: 1;
  padding: 10px 6px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.mode-btn.is-active {
  background: var(--primary);
  color: var(--on-accent);
}

.prompt {
  text-align: center;
  background: var(--panel);
  border: 1px solid var(--gold-dim);
  border-radius: 12px;
  padding: 14px;
}

.prompt-label {
  font-size: 12px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--muted);
}

.prompt-target {
  font-size: clamp(28px, 7vw, 46px);
  font-weight: 800;
  color: var(--gold-soft);
  line-height: 1.1;
  margin-top: 4px;
}

.prompt-code {
  font-family: "Courier New", monospace;
  font-size: 20px;
  color: var(--muted);
  letter-spacing: 4px;
  margin-top: 4px;
  min-height: 22px;
}

.readout {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 5px 12px;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 18px;
  opacity: 0.85;
}

.readout-row { display: flex; align-items: baseline; gap: 8px; min-width: 0; }

.readout-tag {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted);
  flex: none;
}

.readout-value {
  font-family: "Courier New", monospace;
  font-size: 14px;
  letter-spacing: 2px;
  color: var(--content);
  word-break: break-all;
}

.feedback {
  min-height: 22px;
  text-align: center;
  font-weight: 700;
  font-size: 16px;
}

.feedback.ok { color: var(--ok); }
.feedback.bad { color: var(--bad); }

/* ---- Key (botão circular dentro da árvore) ---- */
.key {
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
  position: absolute;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  width: 60px;
  height: 60px;
  padding: 0;
  border: 2px solid var(--border);
  border-radius: 50%;
  background: var(--entry);
  color: var(--primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.18);
  opacity: 0.9;
  transition: transform 0.05s, box-shadow 0.05s, background 0.05s, color 0.05s, opacity 0.15s;
}

.key:hover { opacity: 1; }

.key:active,
.key.is-down {
  background: var(--primary);
  color: var(--on-accent);
  border-color: var(--primary);
  box-shadow: 0 0 0 4px var(--lit-glow);
  transform: translateX(-50%) translateY(1px) scale(0.96);
  opacity: 1;
}

.key-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  line-height: 1;
}

.key-icon svg {
  width: 30px;
  height: 30px;
  display: block;
}

/* Botão discreto de limpar saída, à direita da key */
.clear-btn {
  position: absolute;
  right: 14px;
  bottom: 27px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: transparent;
  color: var(--secondary);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  opacity: 0.75;
  transition: opacity 0.15s, background 0.15s, color 0.15s;
}

.clear-btn:hover {
  opacity: 1;
  background: var(--code-bg);
  color: var(--content);
}

/* Botão central "Tocar novamente" (modo auditivo, no lugar da key) */
.play-btn {
  position: absolute;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 11px 18px;
  border: 2px solid var(--primary);
  border-radius: 999px;
  background: var(--primary);
  color: var(--on-accent);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.18);
  transition: transform 0.05s, box-shadow 0.05s, opacity 0.15s;
}

.play-btn[hidden] { display: none; }

.play-btn:hover { opacity: 0.92; }

.play-btn:active {
  transform: translateX(-50%) translateY(1px) scale(0.97);
  box-shadow: 0 0 0 4px var(--lit-glow);
}

.play-icon { font-size: 12px; line-height: 1; }

/* Nós clicáveis no modo auditivo */
.tree-clickable .node { cursor: pointer; }

.tree-clickable .node:hover .node-shape {
  fill: var(--tertiary);
  filter: drop-shadow(0 0 6px var(--lit-glow));
}

.node.correct .node-shape {
  fill: var(--ok);
  stroke: var(--ok);
  filter: drop-shadow(0 0 8px var(--lit-glow));
}

.node.correct .node-label { fill: var(--theme); }

.node.wrong .node-shape {
  fill: var(--bad);
  stroke: var(--bad);
}

.node.wrong .node-label { fill: var(--theme); }

/* ---- Configurações ---- */
.settings {
  background: var(--panel);
  border: 1px solid var(--gold-dim);
  border-radius: 12px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.field { display: flex; flex-direction: column; gap: 6px; font-size: 14px; }
.field-inline { flex-direction: row; align-items: center; gap: 8px; }
.field input[type="range"] { width: 100%; accent-color: var(--gold); }
.field input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--gold); }

.score {
  font-size: 13px;
  color: var(--muted);
  text-align: center;
  border-top: 1px solid var(--gold-dim);
  padding-top: 10px;
}
