@font-face {
  font-family: "Source Serif 4";
  src: url("/assets/fonts/source-serif-4-variable.woff2") format("woff2");
  font-display: swap;
  font-style: normal;
  font-weight: 200 700;
}

:root {
  --market-paper: #f4efe6;
  --market-paper-raised: #fffdf8;
  --market-ink: #201d18;
  --market-muted: #6a6259;
  --market-line: #c8bcaa;
  --market-line-dark: #8b7d69;
  --market-copper: #9a4c2d;
  --market-copper-dark: #73361f;
  --market-yellow: #f5e4a2;
  --market-danger: #8a2f25;
  --market-space: clamp(4rem, 9vw, 9rem);
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  background: var(--market-paper);
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--market-paper);
  color: var(--market-ink);
  font-family: "Source Serif 4", Georgia, serif;
  font-size: 18px;
  font-weight: 400;
  line-height: 1.55;
  text-rendering: optimizeLegibility;
}

a {
  color: inherit;
  text-underline-offset: 0.2em;
}

button,
input,
textarea {
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

:focus-visible {
  outline: 3px solid var(--market-copper);
  outline-offset: 4px;
}

.market-skip {
  position: fixed;
  z-index: 100;
  top: 0.75rem;
  left: 0.75rem;
  padding: 0.65rem 0.9rem;
  background: var(--market-ink);
  color: var(--market-paper-raised);
  transform: translateY(-150%);
}

.market-skip:focus {
  transform: translateY(0);
}

.market-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 72px;
  padding: max(1rem, env(safe-area-inset-top)) clamp(1.1rem, 5vw, 4.5rem) 1rem;
  border-bottom: 1px solid var(--market-line);
}

.market-wordmark {
  font-size: 1.55rem;
  line-height: 1;
  text-decoration: none;
}

.market-wordmark span {
  color: var(--market-copper);
}

.market-header nav,
.market-footer nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.8rem 1.4rem;
  font-family: ui-monospace, "SFMono-Regular", Menlo, monospace;
  font-size: 0.69rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.market-header nav a {
  text-decoration: none;
}

.market-header nav a[aria-current="page"] {
  color: var(--market-copper-dark);
  text-decoration: underline;
}

.takeover-hero {
  width: min(100%, 76rem);
  min-height: calc(100svh - 73px);
  margin: 0 auto;
  padding: clamp(3rem, 8vh, 6rem) clamp(1.1rem, 7vw, 7rem) clamp(4rem, 9vh, 7rem);
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.takeover-kicker,
.takeover-status,
.live-state > span,
.message-preview > span,
.payment-amount > span {
  margin: 0 0 1rem;
  color: var(--market-muted);
  font-family: ui-monospace, "SFMono-Regular", Menlo, monospace;
  font-size: 0.7rem;
  font-weight: 400;
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

.takeover-formula {
  margin: 0 0 clamp(2.5rem, 7vh, 5.5rem);
  font-size: clamp(2.6rem, 9vw, 7rem);
  font-weight: 280;
  letter-spacing: -0.045em;
  line-height: 0.88;
}

.message-stage {
  width: min(100%, 58rem);
  margin-bottom: clamp(2rem, 5vh, 4rem);
  padding: clamp(1.5rem, 5vw, 3rem) 0;
  border-top: 1px solid var(--market-line-dark);
  border-bottom: 1px solid var(--market-line-dark);
}

.message-stage h1,
.checkout-copy h1,
.reign-page h1 {
  max-width: 24ch;
  margin: 0;
  font-size: clamp(2rem, 6vw, 5.1rem);
  font-weight: 300;
  letter-spacing: -0.035em;
  line-height: 1.04;
  overflow-wrap: anywhere;
}

.live-message {
  white-space: pre-wrap;
}

.takeover-signature,
.takeover-location {
  margin: 1.2rem 0 0;
  color: var(--market-muted);
  font-size: 1rem;
}

.takeover-location {
  margin-top: 0.1rem;
  font-family: ui-monospace, "SFMono-Regular", Menlo, monospace;
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.message-link {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  margin-top: 1.5rem;
  color: var(--market-copper-dark);
}

.live-price,
.live-state {
  width: min(100%, 34rem);
  margin: 0 0 2rem;
  padding-left: 1.2rem;
  border-left: 4px solid var(--market-copper);
}

.live-price > span {
  display: block;
  color: var(--market-muted);
  font-family: ui-monospace, "SFMono-Regular", Menlo, monospace;
  font-size: 0.72rem;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.live-price strong,
.checkout-price strong,
.payment-amount strong {
  display: block;
  margin: 0.15rem 0;
  font-size: clamp(2rem, 5vw, 3.8rem);
  font-weight: 300;
  letter-spacing: -0.03em;
  line-height: 1;
}

.live-price p,
.live-state p {
  margin: 0.65rem 0 0;
  color: var(--market-muted);
  font-size: 0.9rem;
}

.live-state {
  padding: 1.2rem 1.3rem;
  border-top: 1px solid var(--market-line);
  border-right: 1px solid var(--market-line);
  border-bottom: 1px solid var(--market-line);
  background: color-mix(in srgb, var(--market-yellow) 42%, transparent);
}

.live-state > span {
  display: block;
  margin-bottom: 0.35rem;
  color: var(--market-copper-dark);
}

.live-state--incoming {
  animation: incoming-pulse 900ms ease-out 1;
}

.live-metrics {
  display: flex;
  flex-wrap: wrap;
  gap: 0;
  margin: 0 0 2rem;
  padding: 0;
  list-style: none;
  border-top: 1px solid var(--market-line);
  border-bottom: 1px solid var(--market-line);
}

.live-metrics li {
  min-width: 9rem;
  padding: 0.8rem 1.2rem 0.8rem 0;
}

.live-metrics strong,
.live-metrics span {
  display: block;
  font-weight: 400;
}

.live-metrics strong {
  font-family: ui-monospace, "SFMono-Regular", Menlo, monospace;
  font-size: 0.82rem;
}

.live-metrics span {
  color: var(--market-muted);
  font-size: 0.76rem;
}

.takeover-actions,
.result-actions,
.reign-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.7rem;
}

.market-button {
  display: inline-flex;
  min-height: 48px;
  align-items: center;
  justify-content: center;
  padding: 0.78rem 1.15rem;
  border: 1px solid var(--market-ink);
  border-radius: 0;
  background: var(--market-ink);
  color: var(--market-paper-raised);
  cursor: pointer;
  font-family: "Source Serif 4", Georgia, serif;
  font-size: 0.95rem;
  font-weight: 400;
  line-height: 1.25;
  text-align: center;
  text-decoration: none;
  transition: background-color 120ms ease, color 120ms ease, transform 100ms ease;
}

.market-button:hover {
  background: var(--market-copper-dark);
  border-color: var(--market-copper-dark);
}

.market-button:active {
  transform: translateY(1px);
}

.market-button--quiet {
  background: transparent;
  color: var(--market-ink);
}

.market-button--text,
.sound-toggle {
  min-height: 44px;
  padding: 0.5rem 0.2rem;
  border: 0;
  background: transparent;
  color: var(--market-ink);
  text-decoration: underline;
  text-underline-offset: 0.2em;
}

.market-button.is-disabled {
  border-color: var(--market-line);
  background: var(--market-line);
  color: var(--market-muted);
  cursor: not-allowed;
}

.sound-toggle {
  cursor: pointer;
  font: 400 0.72rem/1.2 ui-monospace, "SFMono-Regular", Menlo, monospace;
}

.market-unavailable {
  max-width: 46rem;
  margin: 1.5rem 0 0;
  color: var(--market-danger);
  font-size: 0.88rem;
}

.takeover-explainer {
  max-width: 42rem;
  margin: 2rem 0 0;
  color: var(--market-muted);
  font-size: clamp(1rem, 2.4vw, 1.25rem);
}

.spectator-hook,
.market-principle,
.other-ways,
.market-footer {
  padding: var(--market-space) clamp(1.1rem, 7vw, 7rem);
  border-top: 1px solid var(--market-line);
}

.spectator-hook p {
  max-width: 24ch;
  margin: 0 auto;
  font-size: clamp(2.2rem, 6vw, 5.8rem);
  font-weight: 280;
  letter-spacing: -0.04em;
  line-height: 1;
  text-align: center;
}

.market-principle,
.other-ways {
  max-width: 76rem;
  margin: 0 auto;
}

.market-principle h2,
.other-ways h2,
.narrow-page h1,
.archive-page > h1,
.stats-page > h1,
.rules-page > h1,
.receipt-page > h1,
.admin-page > h1 {
  max-width: 22ch;
  margin: 0 0 1.5rem;
  font-size: clamp(2.2rem, 5vw, 4.8rem);
  font-weight: 300;
  letter-spacing: -0.035em;
  line-height: 1.02;
}

.market-principle > p:not(.takeover-kicker) {
  max-width: 42rem;
  color: var(--market-muted);
}

.other-ways > div {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  border-top: 1px solid var(--market-line-dark);
}

.other-ways a {
  display: flex;
  min-height: 10rem;
  flex-direction: column;
  justify-content: space-between;
  padding: 1.3rem 1rem 1.3rem 0;
  text-decoration: none;
}

.other-ways a + a {
  padding-left: 1.3rem;
  border-left: 1px solid var(--market-line);
}

.other-ways span {
  color: var(--market-muted);
  font-size: 0.85rem;
}

.other-ways strong {
  font-size: clamp(1.4rem, 3vw, 2.5rem);
  font-weight: 400;
}

.market-footer {
  display: flex;
  justify-content: space-between;
  gap: 2rem;
  padding-bottom: max(3rem, env(safe-area-inset-bottom));
  color: var(--market-muted);
  font-size: 0.85rem;
}

.market-footer > p {
  max-width: 38rem;
  margin: 0;
}

.checkout-page,
.receipt-page,
.reign-page,
.archive-page,
.stats-page,
.rules-page,
.admin-page,
.narrow-page {
  width: min(100% - 2.2rem, 72rem);
  margin: 0 auto;
  padding: clamp(3rem, 8vw, 7rem) 0 clamp(5rem, 10vw, 9rem);
}

.checkout-page {
  display: grid;
  grid-template-columns: minmax(0, 0.85fr) minmax(24rem, 1.15fr);
  gap: clamp(3rem, 8vw, 8rem);
  align-items: start;
}

.checkout-copy {
  position: sticky;
  top: 2rem;
}

.checkout-copy > p:not(.takeover-kicker),
.narrow-page > p,
.receipt-private {
  max-width: 42rem;
  color: var(--market-muted);
}

.checkout-price {
  margin: 2rem 0;
  padding: 1.2rem 0;
  border-top: 1px solid var(--market-line-dark);
  border-bottom: 1px solid var(--market-line-dark);
}

.checkout-price span,
.payment-amount small {
  color: var(--market-muted);
  font: 400 0.72rem/1.4 ui-monospace, "SFMono-Regular", Menlo, monospace;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.takeover-form,
.payment-instructions {
  padding: clamp(1.2rem, 4vw, 2.4rem);
  border: 1px solid var(--market-line-dark);
  background: var(--market-paper-raised);
}

.takeover-form > label,
.payment-instructions label,
.admin-login label,
.admin-page label {
  display: grid;
  gap: 0.45rem;
  margin-bottom: 1.15rem;
  color: var(--market-muted);
  font-size: 0.8rem;
}

.takeover-form label span {
  color: var(--market-line-dark);
}

input,
textarea {
  width: 100%;
  min-height: 48px;
  padding: 0.75rem 0.8rem;
  border: 1px solid var(--market-line-dark);
  border-radius: 0;
  background: #fffefb;
  color: var(--market-ink);
  font-size: 1rem;
  font-weight: 400;
}

textarea {
  min-height: 11rem;
  resize: vertical;
}

.field-help,
.form-error {
  margin: -0.7rem 0 1.2rem;
  color: var(--market-muted);
  font-size: 0.74rem;
}

.form-error:not(:empty) {
  color: var(--market-danger);
}

.amount-choice {
  margin: 2rem 0 1rem;
  padding: 0;
  border: 0;
}

.amount-choice legend {
  margin-bottom: 0.8rem;
  font-size: 1.2rem;
}

.amount-choice label {
  display: grid;
  grid-template-columns: 1.2rem 1fr;
  align-items: center;
  gap: 0.65rem;
  min-height: 48px;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--market-line);
  color: var(--market-ink);
  font-size: 0.9rem;
}

.amount-choice input[type="radio"] {
  width: 1.1rem;
  min-height: 1.1rem;
  margin: 0;
  accent-color: var(--market-copper);
}

.amount-choice label:has(input[value="custom"]:checked) {
  grid-template-columns: 1.2rem 1fr minmax(7rem, 0.7fr);
}

.amount-choice label input[name="customAmount"] {
  display: none;
}

.amount-choice label:has(input[value="custom"]:checked) input[name="customAmount"] {
  display: block;
}

.message-preview,
.defend-preview {
  min-height: 10rem;
  margin: 1.8rem 0;
  padding: 1.3rem;
  border: 1px solid #d8c373;
  background: color-mix(in srgb, var(--market-yellow) 48%, white);
}

.message-preview p {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 1.35rem;
}

.receipt-page,
.reign-page {
  max-width: 58rem;
}

.receipt-page > dl,
.reign-summary,
.stats-page dl,
.admin-page > dl {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin: 2rem 0;
  border-top: 1px solid var(--market-line-dark);
}

.receipt-page dl div,
.reign-summary div,
.stats-page dl div,
.admin-page > dl div {
  padding: 1rem 1rem 1rem 0;
  border-bottom: 1px solid var(--market-line);
}

dt {
  color: var(--market-muted);
  font: 400 0.68rem/1.4 ui-monospace, "SFMono-Regular", Menlo, monospace;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

dd {
  margin: 0.2rem 0 0;
  font-size: 1.15rem;
}

.payment-instructions {
  margin: 2rem 0;
}

.payment-amount {
  margin-bottom: 1.5rem;
}

.payment-qr {
  width: min(100%, 19rem);
  margin: 1rem auto 2rem;
  padding: 1rem;
  background: #fff;
}

.payment-qr img,
.payment-qr svg {
  display: block;
  width: 100%;
  height: auto;
}

.payment-instructions label {
  position: relative;
  grid-template-columns: 1fr auto;
}

.payment-instructions label input {
  grid-column: 1 / -1;
  padding-right: 8rem;
  font: 400 0.78rem/1.4 ui-monospace, "SFMono-Regular", Menlo, monospace;
}

.payment-instructions label button {
  position: absolute;
  right: 0.5rem;
  bottom: 0.55rem;
  min-height: 36px;
  border: 0;
  background: transparent;
  cursor: pointer;
  text-decoration: underline;
}

.receipt-result {
  margin: 3rem 0;
  padding: clamp(2rem, 6vw, 4rem);
  border: 1px solid var(--market-copper);
  animation: result-enter 700ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.receipt-result h2 {
  max-width: 18ch;
  margin: 0;
  font-size: clamp(2.4rem, 6vw, 5rem);
  font-weight: 300;
  line-height: 0.95;
}

.reign-page > h1 {
  margin-bottom: 2rem;
}

.ledger {
  margin-top: 4rem;
}

.ledger h2,
.records h2,
.admin-page h2 {
  font-size: 1.4rem;
  font-weight: 400;
}

.ledger ul,
.records ul {
  margin: 0;
  padding: 0;
  list-style: none;
  border-top: 1px solid var(--market-line-dark);
}

.ledger li {
  display: grid;
  grid-template-columns: 7rem 8rem 1fr auto;
  gap: 1rem;
  padding: 0.8rem 0;
  border-bottom: 1px solid var(--market-line);
  font: 400 0.76rem/1.4 ui-monospace, "SFMono-Regular", Menlo, monospace;
}

.ledger li strong {
  font-weight: 400;
}

.archive-list {
  margin-top: 4rem;
  border-top: 1px solid var(--market-line-dark);
}

.archive-list article {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.5rem 2rem;
  padding: 2rem 0;
  border-bottom: 1px solid var(--market-line);
}

.archive-list article h2 {
  max-width: 34ch;
  margin: 0;
  font-size: clamp(1.35rem, 3vw, 2.2rem);
  font-weight: 350;
  line-height: 1.12;
}

.archive-list article p,
.archive-list article span {
  margin: 0;
  color: var(--market-muted);
  font-size: 0.77rem;
}

.archive-list article p {
  grid-column: 1;
}

.archive-list article span {
  grid-column: 2;
  grid-row: 1;
  font-family: ui-monospace, "SFMono-Regular", Menlo, monospace;
  text-transform: uppercase;
}

.records {
  margin-top: 4rem;
}

.records li {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.7rem 0;
  border-bottom: 1px solid var(--market-line);
}

.periods {
  display: flex;
  gap: 1rem;
  margin: 2rem 0;
}

.stats-page dl {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.rules-page {
  max-width: 54rem;
}

.rules-page ol {
  margin: 3rem 0 0;
  padding: 0;
  list-style: none;
  counter-reset: rules;
  border-top: 1px solid var(--market-line-dark);
}

.rules-page li {
  counter-increment: rules;
  display: grid;
  grid-template-columns: 3rem 1fr;
  gap: 1rem;
  padding: 1.15rem 0;
  border-bottom: 1px solid var(--market-line);
}

.rules-page li::before {
  content: counter(rules, decimal-leading-zero);
  color: var(--market-copper);
  font: 400 0.75rem/1.55 ui-monospace, "SFMono-Regular", Menlo, monospace;
}

.admin-login {
  width: min(100% - 2rem, 28rem);
  margin: 12vh auto;
}

.admin-login form,
.admin-page section {
  margin-top: 2rem;
  padding: 1.5rem;
  border: 1px solid var(--market-line-dark);
}

.admin-page table {
  width: 100%;
  border-collapse: collapse;
  font: 400 0.72rem/1.4 ui-monospace, "SFMono-Regular", Menlo, monospace;
}

.admin-page th,
.admin-page td {
  padding: 0.6rem 0.4rem;
  border-bottom: 1px solid var(--market-line);
  text-align: left;
  font-weight: 400;
}

.admin-page form + form {
  margin-top: 1.2rem;
}

.poster-document {
  background: #fff;
}

.poster {
  width: 210mm;
  min-height: 297mm;
  margin: 0 auto;
  padding: 24mm;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #fff;
  text-align: center;
}

.poster h1 {
  margin: 0;
  font-size: 18mm;
  font-weight: 300;
  line-height: 0.95;
}

.poster blockquote {
  max-width: 17cm;
  margin: 18mm 0 12mm;
  font-size: 8mm;
  font-weight: 300;
  line-height: 1.15;
}

.poster-qr {
  width: 62mm;
  padding: 4mm;
  background: #fff;
}

.poster-qr svg {
  width: 100%;
  height: auto;
}

@keyframes incoming-pulse {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes result-enter {
  from { opacity: 0; transform: translateY(18px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 820px) {
  body {
    font-size: 17px;
  }

  .market-header {
    align-items: flex-start;
  }

  .market-header nav {
    justify-content: flex-end;
    gap: 0.55rem 0.85rem;
  }

  .takeover-hero {
    min-height: auto;
    padding-top: 3.25rem;
  }

  .takeover-formula {
    margin-bottom: 3rem;
  }

  .checkout-page {
    grid-template-columns: 1fr;
    gap: 2.5rem;
  }

  .checkout-copy {
    position: static;
  }

  .stats-page dl {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .ledger li {
    grid-template-columns: 1fr 1fr;
  }

  .ledger li time {
    grid-column: 1 / -1;
  }

  .market-footer {
    flex-direction: column;
  }
}

@media (max-width: 540px) {
  .market-header {
    padding-inline: 1rem;
  }

  .market-wordmark {
    font-size: 1.35rem;
  }

  .market-header nav {
    max-width: 13rem;
    font-size: 0.61rem;
  }

  .takeover-hero,
  .spectator-hook,
  .market-principle,
  .other-ways,
  .market-footer {
    padding-inline: 1rem;
  }

  .takeover-formula {
    font-size: clamp(2.65rem, 15vw, 4rem);
  }

  .message-stage h1,
  .checkout-copy h1,
  .reign-page h1 {
    font-size: clamp(2rem, 10vw, 3.6rem);
  }

  .takeover-actions,
  .result-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .market-button {
    width: 100%;
  }

  .market-button--text,
  .sound-toggle {
    width: auto;
    align-self: flex-start;
  }

  .live-metrics li {
    flex: 1 1 50%;
  }

  .other-ways > div {
    grid-template-columns: 1fr;
  }

  .other-ways a + a {
    padding-left: 0;
    border-top: 1px solid var(--market-line);
    border-left: 0;
  }

  .receipt-page > dl,
  .reign-summary,
  .stats-page dl,
  .admin-page > dl {
    grid-template-columns: 1fr;
  }

  .takeover-form,
  .payment-instructions {
    padding: 1rem;
  }

  .archive-list article {
    grid-template-columns: 1fr;
  }

  .archive-list article span {
    grid-column: 1;
    grid-row: auto;
  }
}

@media print {
  .poster-document .market-header,
  .poster-document .market-footer,
  .poster-document .market-skip {
    display: none;
  }

  .poster {
    width: 100%;
    min-height: 100vh;
    padding: 18mm;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
