:root {
  --bg: #fafaf8; --fg: #1b1b1b; --muted: #6b6b6b; --line: #e3e3de; --card: #fff;
  --accent: #0a7d4f; --warn: #b5530b; --code: #f1f1ec; --sim: #c9a000; --sim-bg: #fff8d6;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #121212; --fg: #e8e8e3; --muted: #9a9a94; --line: #2c2c2a; --card: #1a1a19; --accent: #3ccf8e; --warn: #f0a050; --code: #222220; --sim: #e3c03a; --sim-bg: #2e2a12; }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--fg); font: 15px/1.55 system-ui, sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, pre { font: 13px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace; }
.muted { color: var(--muted); }
.err { color: var(--warn); }

header { position: sticky; top: 0; display: flex; gap: .6rem; align-items: center; padding: .7rem 1.2rem; background: var(--bg); border-bottom: 1px solid var(--line); z-index: 1; }
.brand { font-weight: 700; color: var(--fg); }
.spacer { flex: 1; }
main { max-width: 64rem; margin: 0 auto; padding: 1rem 1.2rem 3rem; }
footer { max-width: 64rem; margin: 0 auto; padding: 1rem 1.2rem 2rem; font-size: 13px; }

button, select, input { font: inherit; color: inherit; background: var(--card); border: 1px solid var(--line); border-radius: 6px; padding: .35rem .7rem; }
button { cursor: pointer; }
button:hover { border-color: var(--accent); }
input { min-width: 0; }
#filter { width: 100%; margin-bottom: .6rem; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr)); gap: .7rem; }
.card { display: flex; flex-direction: column; gap: .25rem; padding: .8rem; background: var(--card); border: 1px solid var(--line); border-radius: 8px; color: var(--fg); }
.card:hover { border-color: var(--accent); text-decoration: none; }
.card.off { opacity: .55; }
.card code { color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.tag { display: inline-block; font-size: 11px; padding: 0 .4rem; border-radius: 4px; border: 1px solid var(--line); color: var(--muted); }
.live { display: inline-block; font-size: 11px; font-weight: 600; padding: 0 .45rem; border-radius: 999px; background: var(--accent); color: var(--bg); white-space: nowrap; }
.card.app { border-color: var(--accent); }
.tag.warn { color: var(--warn); border-color: var(--warn); }

.catalog { list-style: none; padding: 0; margin: 0; columns: 2 22rem; }
.catalog li { padding: .1rem 0; break-inside: avoid; font-size: 14px; }

.crumbs { display: flex; flex-wrap: wrap; gap: 1rem; align-items: center; margin-bottom: 1rem; }
.tabs { display: flex; gap: .3rem; border-bottom: 1px solid var(--line); margin: 1rem 0; }
.tabs button { border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: none; }
.tabs button.on { border-bottom-color: var(--accent); font-weight: 600; }
.row { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; margin: .4rem 0; }

.custom { padding: 1rem; background: var(--card); border: 1px solid var(--line); border-radius: 8px; }
.counter { text-align: center; }
.counter .big { font-size: 5rem; font-weight: 800; line-height: 1.1; }
.counter .row { justify-content: center; }
.counter button { font-size: 1.1rem; padding: .5rem 1.2rem; }

.func { padding: .7rem 0; border-bottom: 1px solid var(--line); }
.out, .src, .md pre { background: var(--code); padding: .7rem; border-radius: 6px; overflow: auto; white-space: pre-wrap; }
.src { white-space: pre; }
.file h3 { font: 600 14px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; margin: 1.4rem 0 .4rem; }
.bars { display: flex; gap: .6rem; align-items: flex-end; justify-content: center; height: 7rem; margin: 1.6rem 0 1rem; }
.bars div { width: 2.6rem; background: var(--accent); border-radius: 4px 4px 0 0; position: relative; min-height: 2px; }
.bars span { position: absolute; bottom: -1.6rem; left: 0; right: 0; text-align: center; font-size: 1.3rem; }
.bars b { position: absolute; top: -1.3rem; left: 0; right: 0; text-align: center; font-size: 12px; }
.keys { display: flex; flex-wrap: wrap; gap: .3rem; justify-content: center; max-width: 34rem; margin: 1rem auto; }
.keys button { width: 2.3rem; padding: .35rem 0; font-weight: 600; }
.keys button:disabled { opacity: .3; cursor: default; }
.word { font: 700 2rem/1.3 ui-monospace, Menlo, monospace; letter-spacing: .4rem; }
.gallows { display: inline-block; text-align: left; background: none; }
.answer { font-size: 1.6rem; font-weight: 700; margin: 1rem 0; }
.app-panel { text-align: center; }
.app-panel input { width: min(28rem, 100%); }

.md img { max-width: 100%; }
.md .table { overflow-x: auto; }
.md table { border-collapse: collapse; }
.md th, .md td { border: 1px solid var(--line); padding: .3rem .6rem; text-align: left; }
.md blockquote { margin: 0; padding-left: 1rem; border-left: 3px solid var(--line); color: var(--muted); }
.md code { background: var(--code); padding: 0 .25rem; border-radius: 3px; }
.md pre code { background: none; padding: 0; }

dialog.modal { max-width: min(46rem, 94vw); width: 100%; border: 1px solid var(--line); border-radius: 10px; background: var(--card); color: var(--fg); padding: 1.2rem; }
dialog.modal::backdrop { background: rgb(0 0 0 / .45); }
dialog.modal h3 { margin-top: 0; }
dialog.modal pre { background: var(--code); padding: .8rem; border-radius: 6px; overflow-x: auto; white-space: pre; }
dialog.modal input[name="addr"], dialog.modal input[name="identity"] { flex: 1; font-family: ui-monospace, Menlo, monospace; }
button.primary { background: var(--accent); color: var(--bg); border-color: var(--accent); }
dialog.modal h4 { margin: 1rem 0 .2rem; }
dialog.modal .current { padding: .5rem .7rem; background: var(--code); border-radius: 6px; overflow-wrap: anywhere; }
#connect.on { border-color: var(--accent); font-family: ui-monospace, Menlo, monospace; font-size: 13px; }
#dryrun[aria-pressed="true"] { background: var(--sim-bg); border: 1px dashed var(--sim); color: var(--fg); font-weight: 600; }
body.dryrun .custom button, body.dryrun .txbtn { border-style: dashed; border-color: var(--sim); }
.simulated { margin: .8rem 0; padding: .6rem .9rem; border: 2px dashed var(--sim); border-radius: 8px; background: var(--sim-bg); text-align: left; }
.simulated.failed { border-color: var(--warn); }
.simulated p { margin: .35rem 0; }
.simulated ul { margin: .2rem 0; padding-left: 1.2rem; font-size: 13px; }
.sim-head { display: flex; flex-wrap: wrap; gap: .3rem; align-items: center; }
.sim-close { margin-left: auto; border: 0; background: none; font-size: 1.1rem; padding: 0 .3rem; }

/* optimistic UI: shown before the chain has it */
.pending { opacity: .55; animation: pending-pulse 1.2s ease-in-out infinite; }
.pending-chip { display: inline-block; font-size: 11px; padding: 0 .45rem; border-radius: 999px; border: 1px dashed var(--muted); color: var(--muted); }
.keys button.pending { opacity: 1; border-style: dashed; border-color: var(--accent); color: var(--accent); }
.spin { display: inline-block; animation: spin 1s linear infinite; }
@keyframes pending-pulse { 50% { opacity: .25; } }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .pending, .spin { animation: none; } }
