/* MattCoin. Above ground (light): your money and the market. Below ground (dark): the mine and the chain. */

:root {
  --stone: #e6ecea;      /* page surface: cool limestone */
  --paper: #f5f8f7;      /* fields and raised surfaces */
  --ink: #18222a;
  --ink-soft: #56636b;
  --line: #c3cfcb;
  --shaft: #1c262c;      /* the mine */
  --shaft-ink: #dbe4e2;
  --shaft-soft: #8c9ca1;
  --verdigris: #2b8a77;  /* money in, links, focus */
  --brass: #c99a2e;      /* mined coins, your blocks */
  --danger: #a3343f;

  --display: "Big Shoulders", "Arial Narrow", sans-serif;
  --body: "Atkinson Hyperlegible Next", system-ui, sans-serif;
  --mono: "Atkinson Hyperlegible Mono", ui-monospace, Menlo, monospace;

  --radius: 6px;
  --gutter: clamp(1rem, 4vw, 3rem);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --stone: #141b1f;
    --paper: #1b252a;
    --ink: #e2e9e7;
    --ink-soft: #94a3a8;
    --line: #2d3a40;
    --shaft: #0b1013;
    --shaft-ink: #d7e1df;
    --shaft-soft: #7f9095;
    --verdigris: #4fb39d;
    --brass: #d9ad48;
    --danger: #e06b75;
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--stone);
  color: var(--ink);
  font: 400 1.0625rem/1.5 var(--body);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; }
h2 { font: 700 1.5625rem/1.1 var(--display); }
p { margin: 0; }
a { color: var(--verdigris); text-underline-offset: 0.2em; }
code, .mono { font-family: var(--mono); font-size: 0.94em; }
.wrap { overflow-wrap: anywhere; }
[hidden] { display: none !important; }

:focus-visible { outline: 3px solid var(--verdigris); outline-offset: 2px; }

.skip-link { position: absolute; left: -999px; top: 0.5rem; padding: 0.5rem 1rem; background: var(--ink); color: var(--stone); border-radius: var(--radius); z-index: 10; }
.skip-link:focus { left: 0.5rem; }

/* --- Top bar ----------------------------------------------------------------- */

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 2rem;
  padding: 0.75rem var(--gutter);
  border-bottom: 1px solid var(--line);
}
.brand { font: 800 1.75rem/1 var(--display); letter-spacing: 0.01em; color: var(--ink); text-decoration: none; }

.nav { display: flex; gap: 1.5rem; }
.nav a {
  padding: 0.35rem 0;
  border-bottom: 3px solid transparent;
  color: var(--ink-soft);
  font-weight: 600;
  text-decoration: none;
}
.nav a:hover { color: var(--ink); }
.nav a[aria-current="page"] { color: var(--ink); border-bottom-color: var(--ink); }

.topbar-actions { display: flex; align-items: center; gap: 1rem; margin-left: auto; }

.price-pill { color: var(--ink-soft); font-size: 0.95rem; text-decoration: none; white-space: nowrap; }
.price-pill strong { color: var(--verdigris); font-variant-numeric: tabular-nums; }

.node-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--paper);
  color: var(--ink-soft);
  font: inherit;
  font-size: 0.9rem;
  white-space: nowrap;
  cursor: pointer;
}
.node-pill .dot { width: 0.55rem; height: 0.55rem; border-radius: 50%; background: var(--ink-soft); }
.node-pill.online .dot { background: var(--verdigris); }
.node-pill.offline { color: var(--danger); border-color: currentColor; }
.node-pill.offline .dot { background: var(--danger); }

/* --- Buttons and fields -------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.75rem;
  padding: 0.6rem 1.2rem;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font: 600 1rem/1.2 var(--body);
  text-decoration: none;
  cursor: pointer;
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: var(--ink); color: var(--stone); }
.btn-quiet { background: transparent; color: var(--ink); border-color: var(--line); }
.btn-brass { background: var(--brass); color: #1c1608; }
.btn-brass.stop { background: transparent; color: var(--brass); border-color: var(--brass); }
.btn-danger { background: transparent; color: var(--danger); border-color: currentColor; }
.btn-small { min-height: 2.25rem; padding: 0.4rem 0.9rem; font-size: 0.92rem; }
.button-row { display: flex; flex-wrap: wrap; gap: 0.6rem; }

.link-button {
  padding: 0;
  border: 0;
  background: none;
  color: var(--ink);
  font: inherit;
  text-decoration: underline;
  text-underline-offset: 0.2em;
  cursor: pointer;
}

label { display: block; margin: 1rem 0 0.35rem; font-weight: 600; font-size: 0.95rem; }
.optional { font-weight: 400; color: var(--ink-soft); }

input:not([type="checkbox"]) {
  width: 100%;
  min-height: 2.75rem;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
  color: var(--ink);
  font: inherit;
}
input.mono { font-family: var(--mono); font-size: 0.95rem; }
input[aria-invalid="true"] { border-color: var(--danger); }

.with-unit { display: flex; align-items: center; gap: 0.6rem; }
.with-unit input { flex: 1; min-width: 0; font-variant-numeric: tabular-nums; }
.with-unit span { color: var(--ink-soft); font-weight: 600; }

.field-row { display: grid; grid-template-columns: 1fr 11rem; gap: 1rem; }

.check { display: flex; gap: 0.6rem; align-items: center; margin: 0 0 1.25rem; font-weight: 400; }
.check input { flex: none; width: 1.15rem; height: 1.15rem; accent-color: var(--verdigris); }

.form-error { min-height: 1.5em; margin-top: 0.75rem; color: var(--danger); font-weight: 600; }
.hint, .fine { margin-top: 0.5rem; color: var(--ink-soft); font-size: 0.93rem; }
.fine { margin: 1rem 0 1.25rem; }

/* --- Wallet page: surface + shaft ------------------------------------------------- */

.app {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(20rem, 27rem);
  min-height: calc(100vh - 3.6rem);
}

.surface { padding: clamp(1.5rem, 4vw, 3rem) var(--gutter) 4rem; max-width: 46rem; }

/* First visit */
.intro-title { font: 800 clamp(3rem, 7.5vw, 5.25rem)/0.92 var(--display); max-width: 12ch; }
.lede { margin-top: 1.25rem; font-size: 1.2rem; max-width: 36rem; color: var(--ink-soft); }
.facts { display: flex; flex-wrap: wrap; gap: 1rem 2.5rem; margin: 2rem 0; }
.facts dt { color: var(--ink-soft); font-size: 0.9rem; }
.facts dd { margin: 0.1rem 0 0; font: 700 1.6rem/1.1 var(--display); font-variant-numeric: tabular-nums; }
.setup-actions { display: flex; flex-wrap: wrap; gap: 0.75rem; }
.import-form { margin-top: 1.5rem; max-width: 36rem; }
.secret-box {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  margin: 2rem 0 1.25rem;
  padding: 1rem;
  border: 1px dashed var(--ink-soft);
  border-radius: var(--radius);
}
.secret { overflow-wrap: anywhere; flex: 1 1 18rem; font-size: 1rem; }

/* Balance */
.balance-label { font: 600 1rem/1.4 var(--body); color: var(--ink-soft); }
.balance-amount {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0 0.6rem;
  margin-top: 0.15rem;
  font: 800 clamp(3.5rem, 11vw, 7.5rem)/0.9 var(--display);
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}
.balance-amount .unit { font-size: 0.32em; font-weight: 700; color: var(--ink-soft); }
.balance-usd { margin-top: 0.5rem; font-size: 1.15rem; font-weight: 600; }
.balance-usd a { font-weight: 400; font-size: 0.95rem; }
.balance-parts {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 1.5rem;
  margin: 0.9rem 0 0;
  padding: 0;
  list-style: none;
  color: var(--ink-soft);
}
.balance-parts strong { color: var(--ink); font-variant-numeric: tabular-nums; }
.balance-parts .in strong { color: var(--verdigris); }

/* Send and receive */
.actions { margin-top: 2.75rem; }
.tabs, .os-tabs { display: flex; gap: 1.75rem; border-bottom: 1px solid var(--line); }
.tabs button, .os-tabs button {
  padding: 0.5rem 0;
  margin-bottom: -1px;
  border: 0;
  border-bottom: 3px solid transparent;
  background: none;
  color: var(--ink-soft);
  font: 700 1.5rem/1.1 var(--display);
  cursor: pointer;
}
.tabs button[aria-selected="true"], .os-tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--ink); }
.panel { padding-top: 0.5rem; }
.send-form .btn { margin-top: 0.25rem; }
.trade-check { margin: 1.25rem 0 0; }
.trade-fields { padding: 0.25rem 0 0 1.75rem; }

.receive { display: grid; grid-template-columns: 11rem minmax(0, 1fr); gap: 1.75rem; padding-top: 1.5rem; align-items: start; }
.qr svg { display: block; width: 100%; height: auto; border-radius: var(--radius); }
.receive-intro { margin-bottom: 1rem; color: var(--ink-soft); }
.address-big {
  display: flex;
  flex-wrap: wrap;
  gap: 0.15rem 0.6rem;
  margin-bottom: 1.25rem;
  font-size: clamp(1.2rem, 3vw, 1.6rem);
  font-weight: 600;
  letter-spacing: 0.02em;
}
.request { margin-top: 1.5rem; }
.request summary { cursor: pointer; font-weight: 600; }

/* Activity */
.activity { margin-top: 3.5rem; }
.tx-list { margin: 0.75rem 0 0; padding: 0; list-style: none; }
.tx {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.1rem 1rem;
  padding: 0.85rem 0;
  border-top: 1px solid var(--line);
}
.tx-title { font-weight: 600; }
.tx-note { color: var(--ink-soft); overflow-wrap: anywhere; }
.tx-amount { grid-row: span 2; align-self: center; font: 700 1.6rem/1 var(--display); font-variant-numeric: tabular-nums; }
.tx.in .tx-amount { color: var(--verdigris); }
.tx.mined .tx-amount { color: var(--brass); }
.tx-when { color: var(--ink-soft); font-size: 0.9rem; }
.tx-when a { color: inherit; }
.tx.pending .tx-when { color: var(--ink); font-weight: 600; }
.empty { padding: 1rem 0; color: var(--ink-soft); border-top: 1px solid var(--line); }

.chip {
  display: inline-block;
  padding: 0.05rem 0.45rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--ink-soft);
  font-size: 0.8rem;
  font-weight: 600;
  vertical-align: 0.1em;
}
.chip-trade { border-color: var(--verdigris); color: var(--verdigris); }

/* --- The mine (below ground) ------------------------------------------------------ */

.shaft {
  background: var(--shaft);
  color: var(--shaft-ink);
  padding: clamp(1.5rem, 3vw, 2.25rem) clamp(1rem, 3vw, 2rem) 3rem;
}
.shaft h2 { color: var(--shaft-ink); }
.shaft-text { margin-top: 0.5rem; color: var(--shaft-soft); font-size: 0.95rem; }
.shaft-link { display: inline-block; margin-top: 0.9rem; color: var(--shaft-ink); font-size: 0.95rem; }

.mine-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 1rem 1.25rem; margin-top: 1.25rem; }
.mine-controls .shaft-link { margin-top: 0; }
.threads { display: inline-flex; align-items: center; gap: 0.6rem; color: var(--shaft-soft); }
.threads output { color: var(--shaft-ink); font-weight: 700; }
.threads button {
  width: 2.25rem;
  height: 2.25rem;
  border: 1px solid var(--shaft-soft);
  border-radius: var(--radius);
  background: transparent;
  color: var(--shaft-ink);
  font: 600 1.15rem/1 var(--body);
  cursor: pointer;
}
.threads button:disabled { opacity: 0.4; cursor: not-allowed; }

.mine-stats { display: grid; grid-template-columns: repeat(3, auto); justify-content: start; gap: 1.5rem; margin: 1.5rem 0 0; }
.mine-stats dt { color: var(--shaft-soft); font-size: 0.85rem; }
.mine-stats dd { margin: 0; font: 700 1.35rem/1.2 var(--display); font-variant-numeric: tabular-nums; }

/* Proof of work, made visible: a guess wins when it is at or below the target. */
.pow { margin-top: 1.5rem; padding-top: 1.25rem; border-top: 1px solid #ffffff1f; }
.pow-row { display: grid; grid-template-columns: 6.5rem minmax(0, 1fr); align-items: baseline; gap: 0.75rem; }
.pow-row + .pow-row { margin-top: 0.35rem; }
.pow-row span { color: var(--shaft-soft); font-size: 0.9rem; }
.hash { font-size: 0.98rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--shaft-soft); }
.zeros { color: var(--brass); font-weight: 600; }
.pow-odds, .mine-share { margin-top: 0.9rem; color: var(--shaft-soft); font-size: 0.93rem; }
.mine-share { color: var(--shaft-ink); }

/* The chain as rock strata: newest block on top, thicker layers hold more transactions. */
.chain { margin-top: 2.5rem; }
.strata { margin: 0.9rem 0 0; padding: 0; list-style: none; border-radius: var(--radius); overflow: hidden; }
.stratum {
  display: grid;
  grid-template-columns: 4.5rem minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.75rem;
  min-height: calc(2.6rem + var(--extra-txs, 0) * 0.45rem);
  padding: 0.4rem 0.9rem;
  background: hsl(var(--hue) var(--sat) var(--light));
  border-bottom: 1px solid #00000059;
  color: var(--shaft-ink);
  font-size: 0.92rem;
  text-decoration: none;
}
.stratum:hover { filter: brightness(1.25); }
.stratum.yours { box-shadow: inset 6px 0 0 var(--brass); }
.stratum-height { font: 700 1.3rem/1 var(--display); font-variant-numeric: tabular-nums; }
.stratum-who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--shaft-soft); }
.stratum.yours .stratum-who { color: var(--brass); font-weight: 600; }
.stratum-when { color: var(--shaft-soft); font-size: 0.85rem; }
.stratum.fresh { animation: deposit 700ms cubic-bezier(0.2, 0.9, 0.3, 1.2); }
@keyframes deposit {
  from { transform: translateY(-110%); opacity: 0; }
  to { transform: none; opacity: 1; }
}

/* --- Pages: Market, Mine, Explorer ----------------------------------------------- */

.page { padding: clamp(1.5rem, 4vw, 3rem) var(--gutter) 5rem; }
.page-inner { max-width: 66rem; }
.page-title { font: 800 clamp(2.75rem, 7vw, 4.5rem)/0.95 var(--display); }
.page-title a { color: inherit; text-decoration: none; }
.page-subtitle { margin-top: 0.5rem; font: 800 clamp(2rem, 5vw, 3rem)/1 var(--display); }
.section-title { margin: 2.5rem 0 1rem; font-size: 1.85rem; }
.page .lede { max-width: 44rem; }
.empty-state { color: var(--ink-soft); padding: 1rem 0; }

.two-col { display: grid; grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr); gap: 0 3.5rem; }

.steps { margin: 0 0 1rem; padding-left: 1.4rem; max-width: 40rem; }
.steps li { padding-left: 0.4rem; margin-bottom: 0.85rem; }
.steps li::marker { font: 700 1.15rem var(--display); color: var(--verdigris); }
.tips { margin: 1.25rem 0 0; padding-left: 1.2rem; color: var(--ink-soft); max-width: 44rem; }
.tips li { margin-bottom: 0.4rem; }

.faq { max-width: 44rem; margin: 0; }
.faq dt { font-weight: 700; margin-top: 1.25rem; }
.faq dd { margin: 0.35rem 0 0; color: var(--ink-soft); }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(12rem, 1fr)); gap: 1.25rem 2rem; margin: 2rem 0 0; }
.stat dt { color: var(--ink-soft); font-size: 0.9rem; }
.stat dd { margin: 0.15rem 0 0; font: 700 1.75rem/1.1 var(--display); font-variant-numeric: tabular-nums; }
.stat-note { margin-top: 0.25rem; color: var(--ink-soft); font-size: 0.85rem; }

/* Market */
.price-hero { margin: 1.5rem 0 1rem; padding-bottom: 2rem; border-bottom: 1px solid var(--line); }
.price-label { color: var(--ink-soft); font-weight: 600; }
.price-big { font: 800 clamp(4rem, 13vw, 8.5rem)/0.95 var(--display); color: var(--verdigris); font-variant-numeric: tabular-nums; }
.price-big.none { color: var(--ink-soft); font-size: clamp(3rem, 9vw, 5.5rem); }
.price-basis { margin-top: 0.75rem; max-width: 42rem; color: var(--ink-soft); }
.price-yours { margin-top: 0.5rem; font-weight: 600; }

/* Mine */
.method { margin-top: 1rem; }
.method > p { max-width: 44rem; }
.mine-panel {
  margin-top: 1.25rem;
  padding: clamp(1.25rem, 3vw, 1.75rem);
  border-radius: var(--radius);
  background: var(--shaft);
  color: var(--shaft-ink);
  max-width: 44rem;
}
.mine-panel .mine-controls { margin-top: 0; }
.os-tabs { margin: 1rem 0 0; gap: 1.5rem; }
.os-tabs button { font-size: 1.2rem; }
.commands { display: flex; flex-direction: column; align-items: flex-start; gap: 0.6rem; margin-top: 0.9rem; max-width: 44rem; }
.code {
  width: 100%;
  margin: 0;
  padding: 1rem 1.1rem;
  overflow-x: auto;
  border-radius: var(--radius);
  background: var(--shaft);
  color: var(--shaft-ink);
  font: 0.92rem/1.7 var(--mono);
}

/* Tables */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.table th { text-align: left; color: var(--ink-soft); font-size: 0.85rem; font-weight: 600; padding: 0 0.75rem 0.5rem 0; border-bottom: 1px solid var(--line); }
.table td { padding: 0.7rem 0.75rem 0.7rem 0; border-bottom: 1px solid var(--line); vertical-align: top; }
.table .num { text-align: right; white-space: nowrap; }
.table .strong { font-weight: 700; }
.table .in { color: var(--verdigris); }
.trade-what { overflow-wrap: anywhere; }

/* Explorer */
.search { margin-top: 1.5rem; max-width: 44rem; }
.search label { margin-top: 0; }
.search-row { display: flex; gap: 0.6rem; }
.search-row input { flex: 1; min-width: 0; }

.supply { margin-top: 1rem; max-width: 44rem; }
.supply-head { display: flex; justify-content: space-between; gap: 1rem; font-weight: 700; }
.supply-track { height: 0.75rem; margin-top: 0.5rem; border-radius: 999px; background: var(--paper); border: 1px solid var(--line); overflow: hidden; }
.supply-fill { height: 100%; background: var(--brass); }

.block-nav { display: flex; justify-content: space-between; margin-top: 1rem; max-width: 50rem; }
.details { display: grid; grid-template-columns: 9rem minmax(0, 1fr); gap: 0.6rem 1.5rem; margin: 1.5rem 0 0; max-width: 50rem; }
.details dt { color: var(--ink-soft); }
.details dd { margin: 0; }
.address-line { margin: 0.5rem 0 0; font-size: 1.1rem; }

.tx-cards { display: grid; gap: 1rem; margin: 0; padding: 0; list-style: none; max-width: 50rem; }
.tx-card { padding: 1rem 1.25rem; border: 1px solid var(--line); border-radius: var(--radius); background: var(--paper); }
.tx-from { color: var(--ink-soft); }
.tx-outputs { margin: 0.5rem 0; padding: 0; list-style: none; }
.tx-outputs li { display: flex; flex-wrap: wrap; gap: 0.25rem 1rem; align-items: baseline; padding: 0.2rem 0; }
.tx-outputs .num { margin-left: auto; font-weight: 700; font-variant-numeric: tabular-nums; }
.tx-trade, .tx-memo { margin-top: 0.25rem; overflow-wrap: anywhere; }
.tx-memo { color: var(--ink-soft); }
.tx-id { margin-top: 0.5rem; color: var(--ink-soft); font-size: 0.8rem; }

/* --- Dialogs and toast ---------------------------------------------------------- */

dialog {
  width: min(32rem, calc(100vw - 2rem));
  padding: 1.75rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--stone);
  color: var(--ink);
}
dialog::backdrop { background: #0b101399; }
dialog h2 { margin-bottom: 1rem; font-size: 2rem; }
dialog p { margin-bottom: 1rem; }
.summary { display: grid; gap: 0.6rem; margin: 0 0 1.25rem; }
.summary div { display: grid; grid-template-columns: 4rem minmax(0, 1fr); gap: 1rem; }
.summary dt { color: var(--ink-soft); }
.summary dd { margin: 0; overflow-wrap: anywhere; }
.dialog-note, .dialog-label { color: var(--ink-soft); font-size: 0.95rem; }
.dialog-label { margin-bottom: 0.25rem; }
.dialog-note { margin-top: 1rem; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 0.75rem; margin-top: 1.5rem; }
.danger { margin-top: 1.75rem; padding-top: 1.25rem; border-top: 1px solid var(--line); }

.toast {
  position: fixed;
  left: 50%;
  bottom: 1.5rem;
  transform: translateX(-50%);
  max-width: min(36rem, calc(100vw - 2rem));
  padding: 0.85rem 1.25rem;
  border-radius: var(--radius);
  background: var(--ink);
  color: var(--stone);
  font-weight: 600;
  box-shadow: 0 8px 30px #0000004d;
  z-index: 20;
}
.toast.error { background: var(--danger); color: #fff; }
.toast.win { background: var(--brass); color: #1c1608; }

/* --- Small screens ------------------------------------------------------------- */

@media (max-width: 960px) {
  .app { grid-template-columns: 1fr; }
  .surface { max-width: none; }
  .two-col { grid-template-columns: 1fr; }
}

@media (max-width: 720px) {
  .topbar { gap: 0.5rem 1rem; }
  .nav { order: 3; width: 100%; gap: 1.25rem; overflow-x: auto; }
  .price-pill { display: none; }
  .field-row { grid-template-columns: 1fr; gap: 0; }
  .receive { grid-template-columns: 1fr; }
  .qr { max-width: 12rem; }
  .details { grid-template-columns: 1fr; gap: 0.1rem; }
  .details dd { margin-bottom: 0.6rem; }
  .trade-fields { padding-left: 0; }
}

@media (max-width: 480px) {
  .topbar-actions { gap: 0.75rem; }
  .node-pill { font-size: 0.8rem; }
  .mine-stats { grid-template-columns: repeat(2, auto); }
}

@media (prefers-reduced-motion: reduce) {
  .stratum.fresh { animation: none; }
}
