: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); }

/* flex-wrap, because on a 390px phone the Connect button used to hang 30px
   past the right edge and give the whole site a horizontal scrollbar. */
header { position: sticky; top: 0; display: flex; flex-wrap: wrap; 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%); }

/* smallgrants: the list, the states, the ask form */
.sg { text-align: left; }
.sg h3 { margin: 1.4rem 0 .5rem; }
.sg-banner { padding: .7rem .9rem; border: 1px solid var(--line); border-left: 3px solid var(--muted); border-radius: 6px; }
.sg-banner.ok { border-left-color: var(--accent); }
.sg-banner.waiting { border-left-color: var(--sim); background: var(--sim-bg); }
.sg-banner.bad { border-left-color: var(--warn); }
.sg-banner p { margin: .4rem 0; }
.sg-banner code { overflow-wrap: anywhere; }
.sg-stats { display: flex; flex-wrap: wrap; gap: .3rem 1.4rem; margin-top: .5rem; }
.sg-stats div { display: flex; flex-direction: column; font-size: 13px; }
.sg-none { padding: .7rem .9rem; background: var(--code); border-radius: 6px; }

.sg-rows { list-style: none; margin: 0; padding: 0; }
.sg-row { border: 1px solid var(--line); border-left: 3px solid var(--muted); border-radius: 6px; margin-bottom: .45rem; overflow: hidden; }
.sg-row.paid { border-left-color: var(--accent); }
.sg-row.refused { border-left-color: var(--warn); }
.sg-head { display: grid; grid-template-columns: 3rem 1fr auto auto; gap: .2rem .7rem; align-items: baseline; width: 100%; text-align: left; border: 0; border-radius: 0; background: none; padding: .55rem .8rem; }
.sg-head:hover { background: var(--code); }
.sg-id { color: var(--muted); font: 13px/1.4 ui-monospace, Menlo, monospace; }
.sg-title { font-weight: 600; overflow-wrap: anywhere; }
.sg-amount { font: 600 13px/1.4 ui-monospace, Menlo, monospace; white-space: nowrap; }
.sg-state { font-size: 12px; color: var(--muted); white-space: nowrap; }
.sg-row.paid .sg-state { color: var(--accent); }
.sg-row.refused .sg-state { color: var(--warn); }
/* A decided outcome is prose the reader is meant to believe, including
   "no reason was given": it is never muted, because muted reads as missing. */
.sg-outcome { margin: 0; padding: 0 .8rem .55rem 3.7rem; font-size: 14px; }
.sg-detail { padding: .3rem .8rem .8rem; border-top: 1px solid var(--line); }
.sg-kv { display: flex; flex-wrap: wrap; gap: .2rem 1.4rem; }
.sg-kv div { display: flex; flex-direction: column; font-size: 13px; }
.sg-kv code { overflow-wrap: anywhere; }
.sg-detail blockquote { margin: .6rem 0; padding-left: .8rem; border-left: 3px solid var(--line); }
.sg-ballots { border-collapse: collapse; font-size: 13px; width: 100%; }
.sg-ballots th, .sg-ballots td { border: 1px solid var(--line); padding: .2rem .5rem; text-align: left; }

.sg-ask { margin-top: 1.6rem; padding-top: 1rem; border-top: 1px solid var(--line); }
.sg-ask label { display: flex; flex-direction: column; gap: .2rem; margin: .6rem 0; font-size: 13px; color: var(--muted); }
.sg-ask input, .sg-ask textarea { font-size: 15px; color: var(--fg); background: var(--card); border: 1px solid var(--line); border-radius: 6px; padding: .4rem .6rem; width: 100%; }
.sg-ask textarea { font-family: inherit; resize: vertical; }
.sg-problems { list-style: none; margin: .6rem 0; padding: .5rem .8rem; border: 1px solid var(--warn); border-radius: 6px; }
.sg-problems li { color: var(--warn); font-size: 14px; }
.sg-review { margin: .8rem 0; padding: .7rem .9rem; border: 1px solid var(--line); border-radius: 6px; background: var(--code); }
.sg-review ul { margin: .4rem 0; padding-left: 1.2rem; }
.sg-review p { margin: .5rem 0; }
.sg-review code { overflow-wrap: anywhere; }
.sg-accept { color: var(--accent); }
.sg-refuse { color: var(--warn); }
.sg-ask pre { background: var(--code); padding: .7rem; border-radius: 6px; overflow-x: auto; white-space: pre; }
.sg-ask summary { cursor: pointer; font-weight: 600; }
.sg-ask button:disabled { opacity: .45; cursor: not-allowed; }
.sg-ask input[name="key"] { width: auto; flex: 1; }

/* A phone: the row header stacks instead of squeezing four columns. */
@media (max-width: 34rem) {
  .sg-head { grid-template-columns: 3rem 1fr; }
  .sg-amount, .sg-state { grid-column: 2; }
  .sg-outcome { padding-left: .8rem; }
}

.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"] { 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; } }

/* --- small-grants surface (grants.html): the desk + network chooser --- */

/* The chooser sits under the header. flex-wrap, so on a 390px phone the three
   controls stack instead of pushing a horizontal scrollbar. Every control is
   min-width:0 and width:100% inside its label, which is what actually stops the
   select from refusing to shrink below its content. */
.deskbar { max-width: 64rem; margin: 0 auto; padding: .7rem 1.2rem; display: flex; flex-wrap: wrap; align-items: end; gap: .7rem; }
.deskbar label { flex: 1 1 12rem; min-width: 0; display: flex; flex-direction: column; gap: .2rem; font-size: 12px; color: var(--muted); }
.deskbar select, .deskbar input { width: 100%; min-width: 0; max-width: 100%; }
.deskbar .netpick { flex: 1 1 10rem; }
.netbadge { flex: 0 0 auto; align-self: center; font-size: 11px; font-weight: 700; letter-spacing: .03em; padding: .2rem .55rem; border-radius: 999px; white-space: nowrap; border: 1px solid var(--line); }
.netbadge.mainnet { background: var(--accent); color: var(--bg); border-color: var(--accent); }
.netbadge.testnet { background: var(--sim-bg); color: var(--warn); border-color: var(--sim); }
.netbadge.local { background: var(--code); color: var(--muted); }

/* The loud strip: anything that is not mainnet gets a full-width banner, not a
   hint in the corner. */
.netnote { max-width: 64rem; margin: 0 auto .4rem; padding: .55rem .9rem; border-radius: 6px; font-size: 13px; border: 1px solid var(--line); border-left: 3px solid var(--sim); }
.netnote.testnet { background: var(--sim-bg); border-left-color: var(--sim); }
.netnote.local { background: var(--code); border-left-color: var(--muted); color: var(--muted); }
.netnote code { overflow-wrap: anywhere; }
.grants-surface main { padding-top: .4rem; }
