/* Styles specific to the Level 5 demos. Shared demo chrome is in ../demos.css */

.controls { display: flex; flex-wrap: wrap; gap: .5rem; justify-content: center; margin-top: .9rem; }

.btn {
  padding: .5rem .9rem; min-height: 40px;
  font-size: .85rem; font-weight: 650;
  border: 1px solid var(--accent); border-radius: 99px;
  background: transparent; color: var(--accent); cursor: pointer;
}
.btn:hover { background: var(--accent-soft); }
.btn.solid { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.tiny { min-height: 32px; padding: .3rem .7rem; font-size: .78rem; border-radius: 7px; }
@media (prefers-color-scheme: dark) { .btn.solid { color: #14201a; } }
@media (pointer: coarse) { .btn { min-height: 44px; } .btn.tiny { min-height: 44px; } }

.hint { font-size: .8rem; color: var(--muted); text-align: center; margin: .6rem 0 0; }

.readout {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: .8rem; color: var(--muted);
  text-align: center; margin-top: .6rem; min-height: 1.2em;
}
.readout.bad { color: var(--warn); }

/* Text inputs used across several demos */
.tin, .tarea {
  width: 100%; max-width: 330px;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 16px; padding: .6rem .75rem;
  border: 2px solid var(--line); border-radius: 9px;
  background: var(--bg); color: var(--ink);
}
.tin:focus, .tarea:focus { outline: none; border-color: var(--accent); }
.tarea { resize: vertical; line-height: 1.5; }

/* ---- shared tree renderer ---- */
.tree-wrap { width: 100%; overflow-x: auto; padding: .4rem 0; }
.tnode { display: inline-flex; flex-direction: column; align-items: center; }
.tlabel {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: .78rem; font-weight: 700;
  background: var(--accent); color: #fff;
  padding: .22rem .5rem; border-radius: 6px; white-space: nowrap;
}
@media (prefers-color-scheme: dark) { .tlabel { color: #14201a; } }
.tkids {
  display: flex; gap: .5rem; margin-top: .55rem;
  position: relative; padding-top: .5rem;
}
.tkids::before {
  content: ''; position: absolute; top: 0; left: 12%; right: 12%;
  border-top: 1px solid var(--line);
}
.tkids > .tnode { position: relative; }
.tkids > .tnode::before {
  content: ''; position: absolute; top: -.5rem; left: 50%;
  height: .5rem; border-left: 1px solid var(--line);
}

/* ---- 1. calculator ---- */
.calc-result {
  font-size: 1.5rem; font-weight: 800; color: var(--accent);
  margin: .8rem 0 .2rem; text-align: center; min-height: 1.4em;
  font-family: ui-monospace, Menlo, Consolas, monospace;
}
.calc-result.bad { font-size: .92rem; color: var(--warn); font-weight: 650; }

/* ---- 2 + 10. console output ---- */
.console {
  width: 100%; max-width: 330px; min-height: 3.5em;
  background: var(--code-bg); color: var(--code-ink);
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: .82rem; line-height: 1.55;
  padding: .7rem .85rem; border-radius: 9px;
  white-space: pre-wrap; margin-top: .8rem;
}
.console.bad { color: #ffb4a2; }

/* ---- 3. spreadsheet ---- */
.sheet-grid {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 3px; width: 100%; max-width: 330px;
}
.cell {
  width: 100%; padding: .45rem .5rem; font-size: 16px;
  border: 1px solid var(--line); border-radius: 5px;
  background: var(--surface); color: var(--ink);
  font-family: ui-monospace, Menlo, Consolas, monospace;
  text-align: right; min-width: 0;
}
.cell:focus { outline: none; border-color: var(--accent); background: var(--bg); }
.cell.formula { background: var(--accent-soft); color: var(--accent); font-weight: 650; }
.cell.bad { background: var(--warn-bg); color: var(--warn); font-weight: 700; }

/* ---- 4. search ---- */
.results { list-style: none; padding: 0; margin: .8rem 0 0; width: 100%; max-width: 330px; }
.results li {
  padding: .45rem .6rem; margin-bottom: .3rem; border-radius: 7px;
  background: var(--accent-soft); font-size: .86rem; line-height: 1.4;
}
.results li b {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  color: var(--accent); margin-right: .4rem;
}
.results .no-hits { background: none; color: var(--muted); }

/* ---- 5. huffman ---- */
.huff-bar-track {
  width: 100%; max-width: 330px; height: 22px; margin-top: .9rem;
  background: var(--line); border-radius: 6px; overflow: hidden; position: relative;
}
.huff-bar-track i {
  display: block; height: 100%; background: var(--accent);
  transition: width .25s ease;
}
.code-chips { display: flex; flex-wrap: wrap; gap: .3rem; justify-content: center; margin-top: .8rem; }
.code-chip {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: .74rem; padding: .2rem .45rem;
  background: var(--surface); border: 1px solid var(--line); border-radius: 5px;
}
.code-chip b { color: var(--accent); }

/* ---- 6. diff ---- */
.diff-cols { display: grid; gap: .5rem; width: 100%; max-width: 330px; }
.diff-out {
  width: 100%; max-width: 330px; margin-top: .8rem;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: .8rem; border-radius: 9px; overflow: hidden;
  border: 1px solid var(--line);
}
.dline { padding: .18rem .6rem; white-space: pre-wrap; word-break: break-word; }
.dline.same { color: var(--muted); }
.dline.add  { background: rgba(45,125,70,.16); color: #2d7d46; }
.dline.del  { background: rgba(192,57,43,.14); color: #c0392b; }
@media (prefers-color-scheme: dark) {
  .dline.add { color: #8ed9a8; } .dline.del { color: #f0998c; }
}

/* ---- 7. tic tac toe ---- */
.tic-grid {
  display: grid; grid-template-columns: repeat(3, 62px);
  gap: 5px; justify-content: center;
}
.tic-cell {
  width: 62px; height: 62px; font-size: 1.8rem; font-weight: 800;
  border: 1px solid var(--line); border-radius: 9px;
  background: var(--surface); color: var(--accent); cursor: pointer;
}
.tic-cell:hover:not(:disabled) { border-color: var(--accent); }
.tic-cell:disabled { cursor: default; }
.tic-cell.filled { background: var(--accent-soft); }

/* ---- 9. regex ---- */
.rx-out {
  width: 100%; max-width: 330px; margin-top: .8rem;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: .88rem; line-height: 1.6; padding: .6rem .75rem;
  background: var(--surface); border: 1px solid var(--line); border-radius: 9px;
  word-break: break-word;
}
.rx-out mark { background: var(--accent); color: #fff; border-radius: 3px; padding: 0 2px; }
@media (prefers-color-scheme: dark) { .rx-out mark { color: #14201a; } }
.dim { color: var(--muted); }

/* ---- 10. virtual machine ---- */
.vm-wrap { display: grid; gap: .7rem; width: 100%; max-width: 340px; }
.vm-code {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: .74rem; line-height: 1.5;
  background: var(--code-bg); color: var(--code-ink);
  border-radius: 9px; padding: .5rem .6rem;
  max-height: 190px; overflow-y: auto;
}
.vm-line { padding: .05rem .3rem; border-radius: 3px; white-space: nowrap; }
.vm-line.now { background: var(--accent); color: #14201a; font-weight: 700; }
.vm-addr { opacity: .45; }
.vm-row { font-size: .78rem; }
.vm-row .lbl {
  display: block; font-size: .7rem; text-transform: uppercase;
  letter-spacing: .07em; color: var(--muted); margin-bottom: .2rem;
}
.chip {
  display: inline-block; font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: .76rem; padding: .15rem .45rem; margin: 0 .25rem .25rem 0;
  background: var(--accent-soft); color: var(--accent); border-radius: 5px;
}

.example-row { display: flex; flex-wrap: wrap; gap: .35rem; justify-content: center; margin-top: .7rem; }
