:root {
  color-scheme: dark;
  --bg: #0e1116;
  --panel: #161b22;
  --panel-2: #1f2630;
  --line: #2a323d;
  --text: #e6edf3;
  --muted: #8b949e;
  --green: #26a69a;
  --red: #ef5350;
  --orange: #ffa726;
  --blue: #58a6ff;
  --yellow: #d4ac00;
  --purple: #b392f0;
  --page: #0e1116;
  --surface: #161b22;
  --surface-raised: #1f2630;
  --border: #2a323d;
  --grid: rgba(139, 148, 158, 0.12);
  --profit: #26a69a;
  --loss: #d4ac00;
  --candle-up: #26a69a;
  --candle-down: #ef5350;
  --selection: #b392f0;
  --pinned-crosshair: #9598a1;
  --crosshair-label: #131722;
  --volume: rgba(82, 196, 185, 0.72);
  --btc-price-line: #f0f3f6;
  --sth-cost-line: var(--red);
  --lth-cost-line: var(--blue);
  --realized-price-line: var(--green);
  --sth-supply: #ffa726;
  --lth-supply: var(--blue);
  --danger: #ff7b72;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Microsoft YaHei", "Hiragino Sans GB", "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

* {
  box-sizing: border-box;
  scrollbar-color: var(--line) transparent;
  scrollbar-width: thin;
}

html {
  min-width: 320px;
  min-height: 100%;
}

body {
  min-width: 320px;
  min-height: 100%;
  margin: 0;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--text);
  font-size: 12px;
}

body.is-resizing-panes,
body.is-resizing-panes * {
  cursor: col-resize !important;
  user-select: none !important;
}

::-webkit-scrollbar {
  width: 9px;
  height: 9px;
}

::-webkit-scrollbar-track {
  background: var(--panel-2);
}

::-webkit-scrollbar-thumb {
  border-radius: 5px;
  background: var(--line);
}

::-webkit-scrollbar-thumb:hover {
  background: #3a4552;
}

button,
input,
select {
  font: inherit;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
a:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}

button {
  min-height: 27px;
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
}

button:hover:not(:disabled) {
  border-color: var(--blue);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

button.active,
button.is-active,
.seg button.active,
.seg button.is-active {
  border-color: var(--blue);
  background: var(--blue);
  color: #fff;
  font-weight: 600;
}

.accent-button {
  border-color: #cf8a12;
  background: var(--orange);
  color: #1a1205;
  font-weight: 600;
}

select,
input[type="number"] {
  min-height: 28px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-2);
  color: var(--text);
}

select {
  padding: 3px 6px;
}

input[type="number"] {
  padding: 3px 6px;
}

input[type="range"] {
  width: 100%;
  margin: 0;
  accent-color: var(--blue);
  cursor: ew-resize;
}

a {
  color: var(--blue);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.app-main {
  display: flex;
  height: 100vh;
  min-height: 620px;
  flex-direction: column;
}

.app-header {
  position: relative;
  z-index: 5;
  flex: 0 0 auto;
  padding: 8px 4px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

/* Match Hyperliquid: overlay the header control without changing card layout. */
.lang-btn {
  position: absolute;
  top: 8px;
  right: 12px;
  z-index: 20;
  min-width: 40px;
  min-height: 0;
  padding: 2px 8px;
  font-size: 11px;
}

.header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  flex-wrap: wrap;
}

.title-block {
  min-width: 250px;
}

.title-block h1 {
  margin: 0 0 3px;
  font-size: 15px;
  font-weight: 600;
}

.cards {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.card {
  min-width: 112px;
  padding: 4px 7px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-2);
  font-variant-numeric: tabular-nums;
}

.card .label {
  color: var(--muted);
  font-size: 9px;
}

.card .value {
  min-height: 17px;
  margin: 0;
  overflow: hidden;
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card .value.green {
  color: var(--green);
}

.card .value.red {
  color: var(--red);
}

.card .value.yellow {
  color: var(--yellow);
}

.card .value.orange {
  color: var(--orange);
}

.controls {
  display: flex;
  flex: 0 0 auto;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  padding: 7px 4px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.control-group {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.play-button,
.step-button {
  display: inline-flex;
  width: 31px;
  min-width: 31px;
  align-items: center;
  justify-content: center;
  padding: 4px 7px;
}

.replay-buttons {
  display: inline-flex;
  overflow: hidden;
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.replay-buttons button {
  border: 0;
  border-radius: 0;
  background: transparent;
}

.replay-buttons button + button {
  border-left: 1px solid var(--line);
}

.replay-buttons button:hover:not(:disabled) {
  border-color: var(--line);
  background: rgba(139, 148, 158, 0.08);
}

.playback-icon {
  display: block;
  width: 14px;
  height: 14px;
}

.playback-icon-pause,
.play-button[aria-pressed="true"] .playback-icon-play {
  display: none;
}

.play-button[aria-pressed="true"] .playback-icon-pause {
  display: block;
}

.step-button svg {
  display: block;
  width: 14px;
  height: 14px;
}

.control-group > .label {
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}

.seg {
  display: inline-flex;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.seg button {
  min-width: 42px;
  min-height: 26px;
  padding: 4px 10px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--text);
}

.speed {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}

#play-speed {
  width: 54px;
  min-height: 27px;
  padding: 3px 6px;
}

.chk {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}

.chk input {
  margin: 0;
  cursor: pointer;
  accent-color: var(--blue);
}

.timeline-strip {
  display: grid;
  grid-template-columns: auto minmax(160px, 1fr) auto minmax(250px, 0.58fr);
  align-items: center;
  gap: 8px;
  min-height: 29px;
  padding: 3px 8px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  font-size: 9px;
  font-variant-numeric: tabular-nums;
}

.timeline-field {
  display: block;
  min-width: 0;
}

.workspace {
  display: grid;
  position: relative;
  grid-template-columns: minmax(320px, 1fr) 9px minmax(230px, var(--profile-pane-width, clamp(275px, 27vw, 370px)));
  flex: 1 1 auto;
  min-height: 0;
  gap: 0;
  padding: 6px 5px;
  background: var(--bg);
}

.pane-resizer {
  position: relative;
  z-index: 4;
  min-width: 9px;
  min-height: 0;
  cursor: col-resize;
  touch-action: none;
  outline: none;
}

.pane-resizer::before {
  position: absolute;
  top: 12px;
  bottom: 12px;
  left: 50%;
  width: 2px;
  border-radius: 999px;
  background: var(--line);
  content: "";
  transform: translateX(-50%);
  transition: width 120ms ease, background-color 120ms ease, box-shadow 120ms ease;
}

.pane-resizer::after {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 3px;
  height: 34px;
  border-block: 5px dotted var(--muted);
  content: "";
  opacity: 0.65;
  transform: translate(-50%, -50%);
}

.pane-resizer:hover::before,
.pane-resizer:focus-visible::before,
.pane-resizer.is-dragging::before {
  width: 3px;
  background: var(--blue);
  box-shadow: 0 0 0 3px rgba(88, 166, 255, 0.13);
}

.price-stage,
.profile-stage {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

#price-chart,
#profile-chart {
  display: block;
  width: 100%;
  height: 100%;
}

#price-chart [data-urpd-chart-root="true"],
#price-chart [data-urpd-main-pane="true"] {
  cursor: default !important;
}

#profile-chart {
  position: absolute;
  inset: 0;
}

#profile-chart text {
  fill: var(--muted);
  font-family: inherit;
  font-size: 10px;
}

.chart-tag,
.profile-heading,
.ohlc-legend,
.cost-basis-legend,
.volume-pane-label,
.profile-legend {
  position: absolute;
  z-index: 5;
  pointer-events: none;
}

.chart-tag {
  top: 5px;
  left: 8px;
  display: flex;
  align-items: baseline;
  gap: 7px;
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(22, 27, 34, 0.78);
  color: var(--muted);
  font-size: 9px;
}

.chart-tag strong {
  color: var(--text);
  font-size: 10px;
}

.ohlc-legend {
  top: 7px;
  left: 112px;
  max-width: calc(100% - 225px);
  overflow: hidden;
  color: var(--muted);
  font-size: 9px;
  font-variant-numeric: tabular-nums;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ohlc-legend .positive {
  color: var(--green);
}

.ohlc-legend .negative {
  color: var(--red);
}

.cost-basis-legend {
  top: 25px;
  left: 8px;
  display: flex;
  max-width: calc(100% - 92px);
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 12px;
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(22, 27, 34, 0.84);
  color: var(--muted);
  font-size: 9px;
  font-variant-numeric: tabular-nums;
  pointer-events: auto;
}

.cost-basis-legend[hidden] {
  display: none;
}

.cost-basis-toggle {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 20px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  white-space: nowrap;
  cursor: pointer;
}

.cost-basis-toggle:hover {
  color: var(--text);
}

.cost-basis-toggle.is-hidden {
  opacity: 0.42;
}

.cost-basis-toggle strong {
  color: var(--text);
  font-weight: 600;
}

.cost-line-mark {
  display: inline-block;
  width: 13px;
  height: 1px;
  flex: 0 0 auto;
  background: var(--btc-price-line);
}

.cost-line-mark.sth-cost {
  background: var(--sth-cost-line);
}

.cost-line-mark.lth-cost {
  background: var(--lth-cost-line);
}

.cost-line-mark.realized-price {
  background: var(--realized-price-line);
}

.volume-pane-label {
  top: 76%;
  left: 8px;
  display: flex;
  align-items: baseline;
  gap: 7px;
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(22, 27, 34, 0.82);
  color: var(--muted);
  font-size: 9px;
  font-variant-numeric: tabular-nums;
}

.volume-pane-label strong {
  color: var(--muted);
  font-size: 10px;
}

.profile-heading {
  top: 7px;
  right: 8px;
  left: 9px;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  justify-content: space-between;
  color: var(--muted);
  font-size: 9px;
}

.profile-heading-copy {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 2px;
}

.profile-heading-subline {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
}

.profile-heading strong {
  color: var(--text);
  font-size: 10px;
  white-space: nowrap;
}

.profile-heading-controls {
  display: flex;
  flex: 0 0 auto;
  flex-direction: column;
  align-items: flex-end;
  gap: 3px;
  pointer-events: auto;
}

.profile-heading .profile-direction-switcher,
.profile-heading .urpd-aggregation-switcher {
  flex: 0 0 auto;
  pointer-events: auto;
}

.profile-heading .profile-direction-button,
.profile-heading .urpd-aggregation-button {
  min-width: 42px;
  min-height: 24px;
  padding: 2px 6px;
  font-size: 9px;
}

.profile-heading .urpd-aggregation-button {
  min-width: 29px;
  min-height: 16px;
  padding: 0 4px;
  color: var(--muted);
  font-size: 9px;
  line-height: 14px;
}

.profile-heading .urpd-aggregation-button.active,
.profile-heading .urpd-aggregation-button.is-active {
  color: var(--text);
}

.profile-legend {
  right: 8px;
  bottom: 8px;
  display: flex;
  gap: 9px;
  padding: 2px 5px;
  border-radius: 4px;
  background: rgba(22, 27, 34, 0.82);
  color: var(--muted);
  font-size: 9px;
}

.profile-legend span {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.profile-legend [hidden] {
  display: none;
}

.legend-mark {
  display: inline-block;
  width: 12px;
  height: 3px;
  border-radius: 2px;
  background: var(--profit);
}

.legend-mark.loss {
  background: var(--loss);
}

.legend-mark.sth {
  background: var(--sth-supply);
}

.legend-mark.lth {
  background: var(--lth-supply);
}

.chart-tooltip {
  position: absolute;
  z-index: 8;
  top: 34px;
  left: 12px;
  max-width: calc(100% - 24px);
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(31, 38, 48, 0.95);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
  color: var(--muted);
  font-size: 9px;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
  white-space: nowrap;
}

.chart-tooltip strong {
  margin-right: 6px;
  color: var(--text);
}

.profile-empty {
  position: absolute;
  z-index: 3;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 10px;
  pointer-events: none;
}

.profile-empty.is-hidden {
  display: none;
}

.muted {
  color: var(--muted);
}

.nowrap {
  white-space: nowrap;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

footer {
  padding: 12px 4px 24px;
  color: var(--muted);
  font-size: 12px;
}

footer details {
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

footer summary {
  cursor: pointer;
  color: var(--muted);
}

.footer-details {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
  padding-top: 12px;
}

.footer-section {
  width: 100%;
}

.footer-section + .footer-section {
  padding-top: 10px;
  border-top: 1px solid rgba(42, 50, 61, 0.7);
}

.footer-section > p {
  max-width: none;
  margin: 0;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.55;
}

.footer-section > p + p {
  margin-top: 6px;
}

.footer-section h2 {
  margin: 0 0 8px;
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
}

.metric-definitions dl {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 0 0 8px;
}

.metric-definitions dt {
  margin-bottom: 3px;
  color: var(--text);
  font-size: 10px;
  font-weight: 600;
}

.metric-definitions dd {
  margin: 0;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.55;
}

@media (max-width: 1120px) {
  .header-row {
    align-items: center;
  }

  .title-block {
    min-width: 230px;
  }

  .cards {
    min-width: 0;
    flex: 1 1 auto;
    flex-wrap: nowrap;
  }

  .card {
    min-width: 0;
    flex: 1 1 0;
    padding-inline: 7px;
  }

  .timeline-strip {
    grid-template-columns: auto minmax(140px, 1fr) auto;
  }
}

@media (max-width: 820px) {
  .app-main {
    height: auto;
    min-height: 100vh;
  }

  .header-row {
    flex-direction: column;
    gap: 8px;
  }

  .cards {
    width: 100%;
    justify-content: flex-start;
  }

  .card {
    flex: 1 1 135px;
  }

  .workspace {
    min-height: 600px;
    grid-template-columns: minmax(500px, 1fr) 9px minmax(230px, var(--profile-pane-width, 270px));
    overflow-x: auto;
  }

}

@media (max-width: 620px) {
  .cards {
    flex-wrap: wrap;
  }

  .card {
    flex: 1 1 calc(50% - 4px);
  }

  .workspace {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: 460px 460px;
    min-height: 934px;
    overflow: visible;
  }

  .pane-resizer {
    display: none;
  }

  .controls {
    align-items: flex-start;
  }

  .control-group {
    flex-wrap: wrap;
  }

}

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