.spot-page {
  --spot-gutter: max(clamp(10px, 3.5vw, 18px), env(safe-area-inset-left, 0px), env(safe-area-inset-right, 0px),
    var(--tg-safe-area-inset-left, 0px), var(--tg-safe-area-inset-right, 0px));
  --safe-bottom: max(env(safe-area-inset-bottom, 0px), var(--tg-safe-area-inset-bottom, 0px));
  --spot-buy: var(--green);
  --spot-sell: var(--red);
}

[data-theme="light"] .spot-page {
  --spot-buy: #15764f;
  --spot-sell: #b92e48;
}

.spot-page > .page-scroll { min-height: 0; }
.spot-page [hidden] { display: none; }
.spot-page :is(button, select):focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

.spot-header.subbar {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 6px;
  padding: calc(4px + max(var(--safe-top), env(safe-area-inset-top, 0px), var(--tg-safe-area-inset-top, 0px))) var(--spot-gutter) 6px;
}
.spot-header h1 { min-width: 0; padding: 0; }
.spot-header .spot-header-title {
  justify-self: end;
  color: var(--text-2);
  font-size: 12px;
  font-weight: 500;
  text-align: end;
  white-space: nowrap;
}
.spot-back {
  display: grid;
  place-items: center;
  width: 36px;
  height: 44px;
  border-radius: 7px;
}
.spot-back svg { width: 20px; height: 20px; }
.spot-pair {
  display: flex;
  align-items: center;
  justify-self: start;
  gap: 6px;
  min-width: 0;
  max-width: 100%;
  min-height: 38px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg-2);
  font-size: clamp(14px, 4.2vw, 17px);
  font-weight: 650;
  cursor: pointer;
}
.spot-pair .coin-ic, .spot-pair .coin-ic img { width: 20px; height: 20px; border-radius: 50%; }
.spot-pair-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.spot-pair > svg { flex: none; width: 14px; height: 14px; transform: rotate(90deg); }
.spot-pair[aria-expanded="true"] > svg { transform: rotate(-90deg); }

.spot-pair-dialog {
  position: fixed;
  inset: auto 0 calc(10px + max(var(--safe-bottom), env(safe-area-inset-bottom, 0px), var(--tg-safe-area-inset-bottom, 0px)));
  width: min(calc(100% - 24px), 26rem);
  max-width: none;
  max-height: min(74vh, 32rem);
  max-height: min(74dvh, 32rem);
  margin: 0 auto;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--line-2);
  border-radius: 14px;
  background: var(--elev);
  color: var(--text);
}
.spot-pair-dialog[open] { display: flex; flex-direction: column; }
.spot-pair-dialog::backdrop { background: var(--overlay); }
.spot-picker-head {
  display: flex;
  flex: none;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 8px 6px 14px;
  border-bottom: 1px solid var(--line);
}
.spot-picker-head h2 { font-size: 16px; font-weight: 650; }
.spot-picker-close {
  display: grid;
  flex: 0 0 44px;
  height: 44px;
  place-items: center;
  border-radius: 7px;
  color: var(--text-2);
}
.spot-picker-close svg { width: 18px; height: 18px; }
.spot-pair-options {
  min-height: 0;
  padding: 5px 6px 7px;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
.spot-pair-option {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr) auto;
  align-items: center;
  gap: 9px;
  width: 100%;
  min-height: 45px;
  padding: 4px 8px;
  border-radius: 7px;
  font-size: 14px;
  font-weight: 600;
  text-align: start;
}
.spot-pair-option .coin-ic, .spot-pair-option .coin-ic img { width: 24px; height: 24px; border-radius: 50%; }
.spot-pair-option[aria-current="true"] { background: var(--green-dim); }
.spot-pair-option:active, .spot-picker-close:active { background: var(--bg-2); }
.spot-pair-option .spot-pair-name { min-width: 0; }
.spot-pair-current { color: var(--green); font-size: 11px; font-weight: 600; white-space: nowrap; }
[data-theme="light"] .spot-pair-current { color: #15764f; }
.spot-pair-dialog button:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
@media (hover: hover) {
  .spot-pair-option:not([aria-current="true"]):hover, .spot-picker-close:hover { background: var(--bg-2); }
}

.spot-chart { border-block: 1px solid var(--line); }
.spot-chart .tf-bar { padding-inline: var(--spot-gutter); }
.spot-chart .tf { min-height: 36px; }
.spot-chart-tools { display: flex; align-items: center; padding-inline: var(--spot-gutter); border-bottom: 1px solid var(--line); }
.spot-chart-tools .tf-bar { flex: 1; min-width: 0; padding-inline: 0; border: 0; }
.spot-chart-tools > button {
  display: grid;
  flex: 0 0 36px;
  place-items: center;
  min-height: 36px;
  margin-inline-start: 5px;
  border-inline-start: 1px solid var(--line);
  color: var(--text-2);
}
.spot-chart-tools > button svg { width: 16px; height: 16px; }
.spot-chart-toggle[aria-expanded="false"] svg { transform: rotate(90deg); }
.spot-chart-toggle[aria-expanded="true"] svg { transform: rotate(-90deg); }
.spot-chart-toggle[aria-expanded="false"] { margin-inline-start: auto; }
.spot-chart #chart-wrap {
  height: clamp(145px, 42vw, 220px);
  height: clamp(145px, 24svh, 220px);
  margin-top: 3px;
}
.spot-chart .chart-empty { padding-inline: var(--spot-gutter); text-align: center; }

.spot-controls {
  display: grid;
  grid-template-columns: minmax(0, 1.22fr) minmax(0, 1fr);
  align-items: start;
  gap: clamp(8px, 2.8vw, 15px);
  padding: 12px var(--spot-gutter) 14px;
}
.spot-ticket { display: grid; align-content: start; gap: 8px; min-width: 0; }
.spot-ticket .trade-sides { gap: 3px; padding: 3px; border: 1px solid var(--line); background: var(--bg); }
.spot-ticket .trade-sides button { min-width: 0; min-height: 36px; padding-inline: 2px; font-size: 13px; white-space: nowrap; }
.spot-ticket .trade-sides button[aria-pressed="true"] { color: var(--spot-buy); background: var(--green-dim); }
.spot-ticket .trade-sides button:last-child[aria-pressed="true"] { color: var(--spot-sell); background: var(--red-dim); }

.spot-order-kind {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  min-inline-size: 0;
  margin: 0;
  padding: 0;
  border: 0;
  border-block-end: 1px solid var(--line);
}
.spot-order-kind label { position: relative; min-width: 0; cursor: pointer; }
.spot-order-kind label > span {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 44px;
  border-radius: 7px 7px 0 0;
  color: var(--text-2);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  transition: color .14s ease, background-color .14s ease;
}
.spot-order-kind input:checked + span {
  color: var(--text);
  font-weight: 700;
}
.spot-order-kind input:checked + span::after {
  position: absolute;
  inset: auto 0 -1px;
  width: min(28px, 45%);
  height: 2px;
  margin-inline: auto;
  border-radius: 2px 2px 0 0;
  background: var(--accent);
  content: "";
}
.spot-order-kind input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: -3px; }
.spot-order-kind label:active > span { background: var(--card-2); }
@media (hover: hover) and (pointer: fine) {
  .spot-order-kind label:hover > span { background: var(--bg-2); }
  .spot-order-kind label:active > span { background: var(--card-2); }
}
@media (prefers-reduced-motion: no-preference) {
  [data-spot-price-field]:not([hidden]) { animation: spot-limit-enter .16s ease-out; }
  @keyframes spot-limit-enter { from { opacity: .35; transform: translateY(-2px); } }
}
@media (prefers-reduced-motion: reduce) {
  .spot-order-kind label > span { transition: none; }
}
.spot-field:not(.swap-quantity-field):focus-within { border-color: var(--accent); }
.spot-field {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 1px 5px;
  min-width: 0;
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg-2);
}
.spot-field > :first-child:not(input) { grid-column: 1 / -1; color: var(--text-2); font-size: 11px; }
.spot-field input {
  appearance: textfield;
  width: 100%;
  min-width: 0;
  min-height: 25px;
  font-size: 16px;
  font-variant-numeric: tabular-nums;
}
.spot-field input::-webkit-inner-spin-button,
.spot-field input::-webkit-outer-spin-button { appearance: none; margin: 0; }
.spot-field input::placeholder { color: var(--text-2); }
.spot-field-value {
  display: flex;
  grid-column: 1 / -1;
  align-items: center;
  gap: 5px;
  min-width: 0;
}
.spot-field > span:last-child:not(.spot-field-value), .spot-field-value > span:last-child {
  color: var(--text-2);
  font-size: 10px;
  font-weight: 600;
  white-space: nowrap;
}
.spot-field-value > input { flex: 1; }
.spot-order-limit-note {
  margin-top: -3px;
  padding-inline: 3px;
  color: var(--text-2);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.spot-allocation {
  display: grid;
  gap: 1px;
  min-width: 0;
  --spot-range-color: var(--spot-buy);
}
.spot-ticket[data-side="sell"] .spot-allocation { --spot-range-color: var(--spot-sell); }
.spot-range-control { position: relative; height: 29px; }
.spot-range-control::before {
  content: "";
  position: absolute;
  inset-inline: 9px;
  top: calc(50% - 1px);
  height: 2px;
  border-radius: 1px;
  background: linear-gradient(to right, var(--spot-range-color) 0 var(--spot-ratio, 0%),
    var(--line-2) var(--spot-ratio, 0%) 100%);
  pointer-events: none;
}
.spot-range-ticks {
  position: absolute;
  inset: 0 6px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  pointer-events: none;
}
.spot-range-ticks span {
  width: 6px;
  height: 6px;
  border: 1px solid var(--text-2);
  border-radius: 50%;
  background: var(--bg);
}
#spot-order-ratio {
  position: absolute;
  z-index: 1;
  inset: 0;
  appearance: none;
  width: 100%;
  height: 100%;
  border-radius: 5px;
  background: transparent;
  cursor: pointer;
}
#spot-order-ratio::-webkit-slider-runnable-track { height: 2px; background: transparent; }
#spot-order-ratio::-webkit-slider-thumb {
  appearance: none;
  box-sizing: border-box;
  width: 18px;
  height: 18px;
  margin-top: -8px;
  border: 2px solid var(--spot-range-color);
  border-radius: 50%;
  background: var(--bg);
}
#spot-order-ratio::-moz-range-track { height: 2px; background: transparent; }
#spot-order-ratio::-moz-range-thumb {
  box-sizing: border-box;
  width: 18px;
  height: 18px;
  border: 2px solid var(--spot-range-color);
  border-radius: 50%;
  background: var(--bg);
}
#spot-order-ratio:focus-visible { outline: 2px solid var(--spot-range-color); outline-offset: 2px; }
.spot-range-labels {
  display: flex;
  justify-content: space-between;
  gap: 2px;
  color: var(--text-2);
  font-size: 10px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.spot-range-value {
  justify-self: end;
  color: var(--spot-range-color);
  font-size: 11px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.spot-ratio-note { margin-top: 3px; color: var(--text-2); font-size: 11px; overflow-wrap: anywhere; }

.spot-protection { display: grid; gap: 4px; min-width: 0; }
.spot-protection-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 32px;
  color: var(--text-2);
  font-size: 12px;
  cursor: pointer;
}
.spot-protection-toggle input[type="checkbox"] {
  flex: 0 0 16px;
  width: 16px;
  height: 16px;
  accent-color: var(--spot-buy);
}
.spot-protection-toggle input[type="checkbox"]:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.spot-protection-fields { display: grid; gap: 6px; min-width: 0; }
.spot-protection-error { color: var(--spot-sell); font-size: 11px; overflow-wrap: anywhere; }

.spot-total, .spot-balance, .spot-fees {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 2px 6px;
  color: var(--text-2);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}
.spot-fees { display: grid; gap: 3px; padding-block: 6px; border-block: 1px solid var(--line); }
.spot-fee-estimate { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 2px 6px; min-width: 0; }
.spot-total output, .spot-fees output, .spot-balance strong { color: var(--text); }
.spot-submit {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 2px 6px;
  min-width: 0;
  min-height: 44px;
  padding: 6px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: var(--green);
  color: #0a2117;
  font-size: 14px;
  font-weight: 650;
}
.spot-submit small { font-size: 10px; font-weight: 500; }
.spot-submit:disabled {
  border-color: var(--line);
  background: var(--green-dim);
  color: var(--spot-buy);
  cursor: not-allowed;
}
.spot-submit[data-side="sell"]:disabled, .spot-ticket[data-side="sell"] .spot-submit:disabled {
  background: var(--red-dim);
  color: var(--spot-sell);
}

.spot-book {
  min-width: 0;
  padding: 5px max(4px, 1.05vw) 6px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  font-variant-numeric: tabular-nums;
}
.spot-book-head, .spot-book-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  align-items: center;
  gap: 4px;
  padding-inline: 3px;
}
.spot-book-head { min-height: 26px; color: var(--text-2); font-size: 10px; }
.spot-book-head > :last-child, .spot-book-row > :last-child { text-align: right; }
.spot-book-list { min-width: 0; }
.spot-book-row {
  position: relative;
  isolation: isolate;
  min-height: 23px;
  font-size: clamp(10.5px, 3.1vw, 12px);
}
.spot-book-row > * { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.spot-book-row::before {
  position: absolute;
  z-index: -1;
  content: "";
  inset: 1px 0 1px auto;
  width: var(--size, 0%);
  max-width: 100%;
  border-radius: 3px;
}
.spot-book-row[data-side="ask"] > :first-child { color: var(--spot-sell); }
.spot-book-row[data-side="ask"]::before { background: var(--red-dim); }
.spot-book-row[data-side="bid"] > :first-child { color: var(--spot-buy); }
.spot-book-row[data-side="bid"]::before { background: var(--green-dim); }
.spot-book-mid {
  display: grid;
  gap: 1px;
  margin-block: 3px;
  padding: 3px;
  border-block: 1px solid var(--line);
  font-size: 15px;
  font-weight: 650;
  overflow-wrap: anywhere;
}
.spot-book-mid small { color: var(--text-2); font-size: 10px; font-weight: 500; }
.spot-book-mid .up { color: var(--spot-buy); }
.spot-book-mid .down { color: var(--spot-sell); }
.spot-book .empty { padding: 18px 3px; color: var(--text-2); font-size: 11px; }
.spot-depth-balance {
  display: flex;
  justify-content: space-between;
  gap: 2px 4px;
  margin-top: 6px;
  padding: 3px 5px;
  border-radius: 5px;
  background-color: var(--bg-2);
  background-image: linear-gradient(to right, var(--green-dim) 0 var(--spot-bid-share),
    var(--red-dim) var(--spot-bid-share) 100%);
  font-size: 10px;
  white-space: nowrap;
}
.spot-depth-balance > :first-child { color: var(--spot-buy); }
.spot-depth-balance > :last-child { color: var(--spot-sell); }
.spot-book-controls { display: flex; align-items: center; margin-top: 6px; }
.spot-book-precision {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-width: 0;
  max-width: 100%;
  min-height: 44px;
  padding-inline: 7px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg-2);
  color: var(--text);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}
.spot-book-precision-label { color: var(--text-2); white-space: nowrap; }
#spot-book-precision-value { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.spot-book-precision svg { flex: none; width: 12px; height: 12px; transform: rotate(90deg); }
.spot-book-precision[aria-expanded="true"] svg { transform: rotate(-90deg); }
.spot-precision-sheet { padding-inline: max(16px, var(--spot-gutter)); }
.spot-precision-sheet .precision-sheet-close { flex: none; width: 44px; height: 44px; }
.spot-precision-sheet .precision-options { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.spot-precision-sheet .precision-option { min-width: 0; gap: 6px; border: 1px solid var(--line); border-radius: 8px; overflow-wrap: anywhere; }
.spot-precision-sheet .precision-option:active { background: var(--bg-2); }
@media (hover: hover) {
  .spot-precision-sheet .precision-option:not(.selected):hover { background: var(--bg-2); }
}

.spot-records { padding-inline: var(--spot-gutter); border-top: 1px solid var(--line); }
.spot-records :is(.spot-record-tabs, [role="tablist"]) { display: flex; gap: 12px; border-bottom: 1px solid var(--line); }
.spot-records :is(.spot-record-tabs, [role="tablist"]) button {
  position: relative;
  min-height: 42px;
  padding-inline: 5px;
  color: var(--text-2);
  font-size: 13px;
}
.spot-records button:is([aria-pressed="true"], [aria-selected="true"]) {
  border-bottom: 2px solid var(--accent);
  color: var(--text);
  font-weight: 650;
}
.spot-records .empty { padding: 25px 8px; }
