:root {
  color-scheme: light;
  --page: #f2f6f2;
  --surface: #fff;
  --ink: #122920;
  --muted: #4c6358;
  --line: #d5e2d9;
  --accent: #146346;
  --accent-strong: #0a4d35;
  --soft: #e9f3ed;
  --field-line: #a9beb0;
  --primary-text: #fff;
  --focus: #087653;
  --error: #8b3424;
  --error-soft: #fff1ed;
  font-family: "Segoe UI", Arial, sans-serif;
  color: var(--ink);
  background: var(--page);
}

:root[data-dex-theme="dark"] {
  color-scheme: dark;
  --page: #111916;
  --surface: #18221e;
  --ink: #f0f5f0;
  --muted: #afc0b6;
  --line: #33443b;
  --accent: #64d9a3;
  --accent-strong: #9ee5c1;
  --soft: #22362c;
  --field-line: #536b5d;
  --primary-text: #11241b;
  --focus: #69e0a8;
  --error: #ffad9c;
  --error-soft: #3b2824;
}

:root[data-dex-theme="punk"] {
  color-scheme: dark;
  --page: #111316;
  --surface: #191b1f;
  --ink: #f5f2e8;
  --muted: #c0c7c9;
  --line: #434951;
  --accent: #d4f900;
  --accent-strong: #46eaee;
  --primary-hover: #e8ff6f;
  --soft: #212428;
  --field-surface: #121417;
  --field-line: #667078;
  --primary-text: #181b0a;
  --focus: #46eaee;
  --error: #ff8dbf;
  --error-soft: #432338;
  --mark-base: #d4f900;
  --mark-light: #53f2ed;
  --mark-shadow: #f84c9c;
  --pool-selection: var(--accent);
  --pool-selection-text: var(--primary-text);
}

:root[data-dex-theme="punk"] h1 {
  text-transform: uppercase;
  font-family: "Arial Black", "Segoe UI", sans-serif;
  font-weight: 900;
}
:root[data-dex-theme="punk"] :is(code, .price dd) { color: var(--accent-strong); }
:root[data-dex-theme="punk"] .market-nav a[aria-current="page"] { background: var(--accent); color: var(--primary-text); }

*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; }
[hidden] { display: none !important; }
a { color: var(--accent); }
button, input, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .65; }
button, input, select, a { -webkit-tap-highlight-color: transparent; }
button:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 3px;
}

.header { background: var(--surface); border-bottom: 1px solid var(--line); }
.header-inner {
  width: min(100% - 64px, 1440px);
  min-height: 74px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 20px;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  white-space: nowrap;
  font-size: 1.22rem;
  font-weight: 710;
  letter-spacing: -.02em;
  color: var(--ink);
  text-decoration: none;
}
.brand svg { display: block; }
.market-nav { display: flex; align-items: center; flex-wrap: wrap; gap: 4px; padding-left: 12px; border-left: 1px solid var(--line); }
.market-nav a {
  display: block;
  padding: 9px 13px;
  border-radius: 999px;
  white-space: nowrap;
  color: var(--ink);
  text-decoration: none;
  font-size: .94rem;
  font-weight: 600;
}
.market-nav a:hover, .market-nav a[aria-current="page"] { background: var(--soft); color: var(--accent-strong); }
.market-nav a[aria-current="page"] { font-weight: 740; }
.market-tools { margin-left: auto; display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.market-network, .market-theme {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 34px;
  padding: 5px 9px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface);
  color: var(--ink);
  font-size: .82rem;
}
.market-theme { width: auto; cursor: pointer; }
.market-theme:hover { background: var(--soft); }
.market-preview { max-width: 1536px; margin: 0 auto; }
.market-preview > .market-load-error, .market-preview > h1 { margin: 28px; }
.market-footer { width: min(100% - 48px, 1440px); margin: 30px auto 0; padding: 0 0 28px; }
.market-footer nav { display: flex; gap: 18px; }
.market-footer a { color: var(--muted); font-size: .86rem; text-underline-offset: 4px; }
.market-footer a:hover { color: var(--accent-strong); }

.layout {
  width: min(100% - 48px, 1060px);
  margin: clamp(38px, 9vw, 106px) auto 64px;
  display: grid;
  grid-template-columns: minmax(0, .95fr) minmax(0, 1.05fr);
  align-items: start;
  gap: clamp(36px, 8vw, 102px);
}
h1, h2, h3, p { margin: 0; }
h1 { font-size: clamp(2.5rem, 5vw, 4.1rem); line-height: 1.02; letter-spacing: -.056em; }
h2 { font-size: clamp(1.35rem, 3vw, 1.65rem); line-height: 1.2; letter-spacing: -.026em; }
h3 { font-size: 1.05rem; line-height: 1.3; }
.intro { color: var(--muted); margin: 17px 0 34px; max-width: 330px; font-size: 1.05rem; line-height: 1.6; }
.terms { margin: 0; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 0 20px; }
.terms div { border-top: 1px solid var(--line); padding: 14px 0 0; }
.terms .price {
  grid-column: 1 / -1;
  background: var(--soft);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 15px 18px 16px;
  margin-bottom: 20px;
}
dt { color: var(--muted); font-size: .84rem; font-weight: 550; }
dd { min-width: 0; margin: 4px 0 0; font-weight: 640; }
.price dd { font-size: 2rem; letter-spacing: -.04em; line-height: 1; }
.price small { font-size: .9rem; color: var(--accent-strong); letter-spacing: 0; }

.checkout {
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: 0 14px 34px #19372b0a;
}
.section-content { min-width: 0; padding: clamp(18px, 4vw, 34px); }
#availability { display: grid; gap: 10px; }
#availability button { justify-self: start; }
.hint { color: var(--muted); font-size: .9rem; line-height: 1.5; }
.field { display: grid; gap: 5px; }
.field label { font-size: .92rem; font-weight: 650; }
input, select {
  background: var(--field-surface, var(--surface));
  border: 1px solid var(--field-line);
  border-radius: 9px;
  color: var(--ink);
  width: 100%;
  min-width: 0;
  min-height: 46px;
  padding: 10px 13px;
  transition: border-color .16s;
}
input::placeholder { color: var(--muted); }
input:hover, select:hover { border-color: var(--accent); }
.input-unit { position: relative; }
.input-unit input { padding-right: 62px; }
.input-unit span { position: absolute; right: 14px; top: 50%; translate: 0 -50%; font-size: .85rem; color: var(--muted); }
#create-order, #check-payment { display: grid; gap: 17px; }
.primary, .secondary, .quiet {
  border: 1px solid transparent;
  border-radius: 9px;
  min-height: 44px;
  padding: 8px 13px;
  font-weight: 650;
}
.primary { border-color: var(--accent); background: var(--accent); color: var(--primary-text); }
.primary:not(:disabled):hover { background: var(--primary-hover, var(--accent-strong)); }
.secondary { border-color: var(--field-line); background: var(--surface); color: var(--accent-strong); }
.secondary:not(:disabled):hover { background: var(--soft); }
.recipient-wallets { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 4px; }
.recipient-wallets .secondary { font-size: .88rem; }
#wallet-status[data-kind="error"] { color: var(--error); }
.quiet { background: transparent; color: var(--accent-strong); text-align: left; font-size: .83rem; padding-inline: 8px; }
.quiet:hover { background: var(--soft); }
.order-heading { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; justify-content: space-between; }
.order-heading + .hint { margin-top: 8px; }
.state { border-radius: 99px; padding: 4px 8px; background: var(--soft); color: var(--accent-strong); font-weight: 700; font-size: .75rem; }
.order-summary { display: grid; gap: 10px; margin: 16px 0 20px; }
code {
  display: block;
  max-width: 100%;
  overflow-x: auto;
  white-space: nowrap;
  font-family: Consolas, monospace;
  font-size: .87rem;
  color: var(--ink);
}
.payment { display: grid; gap: 10px; }
.pay-wallets { display: flex; flex-wrap: wrap; gap: 8px; }
.pay-wallets .primary { flex: 1 1 175px; }
.payment-option { padding: 10px 0 4px; border-top: 1px solid var(--line); }
.payment-option > summary { cursor: pointer; color: var(--accent-strong); font-size: .9rem; font-weight: 650; }
.payment-option > summary:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; }
.payment-option > form, .qr-options { margin-top: 12px; }
.qr-options { display: grid; justify-items: start; gap: 8px; }
.qr-options .qr-copy { padding-inline: 0; }
#pay-qr { max-width: 100%; height: auto; background: #fff; border: 1px solid var(--line); border-radius: 10px; }
.payment-summary { padding: 12px 14px 14px; margin: 0; background: var(--soft); border: 1px solid var(--line); border-radius: 11px; display: grid; gap: 7px; }
.payment-summary dd { display: flex; flex-wrap: wrap; gap: 0 6px; align-items: center; }
.payment-summary dd strong { overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
#payment-countdown { min-width: 3.1ch; white-space: nowrap; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.saved-orders { border-top: 1px solid var(--line); margin: 0 clamp(18px, 4vw, 34px) 17px; padding-top: 12px; }
.saved-payment { margin: 18px clamp(18px, 4vw, 34px) 0; padding: 9px 11px; background: var(--soft); color: var(--accent-strong); border-radius: 9px; font-size: .9rem; }
.saved-payment .quiet { padding-inline: 0; }
.feedback { margin: 0 clamp(18px, 4vw, 34px) clamp(18px, 4vw, 34px); padding: 9px 11px; border-radius: 8px; background: var(--soft); overflow-wrap: anywhere; font-size: .9rem; }
.feedback[data-kind="error"] { color: var(--error); background: var(--error-soft); }
#cancel-order, #confirm-cancel { color: var(--error); }
.checkout-dialog { width: min(420px, calc(100% - 32px)); padding: 22px; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 16px; }
.checkout-dialog::backdrop { background: #12292080; }
.checkout-dialog .hint { margin-top: 10px; }

@media (max-width: 850px) {
  .header-inner { width: calc(100% - 36px); min-height: auto; padding: 12px 0 8px; flex-wrap: wrap; gap: 8px 12px; }
  .market-nav { order: 3; width: 100%; padding: 0; border-left: 0; }
}
@media (max-width: 760px) {
  .layout { grid-template-columns: minmax(0, 1fr); width: min(100% - 36px, 510px); gap: 26px; margin-top: 35px; }
  .intro { margin: 11px 0 17px; }
  .terms .price { margin-bottom: 11px; }
}
@media (max-width: 390px) {
  .header-inner { width: calc(100% - 28px); gap: 8px 10px; }
  .market-nav a { padding-inline: 10px; font-size: .84rem; }
  .market-network, .market-theme { min-height: 30px; padding-inline: 5px; font-size: .7rem; }
  .market-network img { display: none; }
  .brand svg { width: 23px; height: 25px; }
  .brand { gap: 5px; font-size: 1rem; }
  .terms { gap: 0 9px; }
  .terms > div:not(.price) dd { font-size: .91rem; }
}
