:root {
  --bg: #0e1110;
  --raise: #151917;
  --chart: #0c0f0d;
  --line: rgba(243, 239, 228, 0.08);
  --line-strong: rgba(243, 239, 228, 0.14);
  --paper: #f3efe4;
  --dim: #9a9588;
  --faint: #6f6b61;
  --gold: #d7c392;
  --sage: #8fbfa3;
  --clay: #d98978;
  --stale: #d7b39a;
  --delayed: #b7c4ce;
  --frozen: #c3bbaa;
  --sans: "Noto Sans CJK SC", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", "Source Han Sans SC", "WenQuanYi Micro Hei", sans-serif;
  --mono: "DejaVu Sans Mono", "SFMono-Regular", "Noto Sans Mono CJK SC", ui-monospace, Menlo, Consolas, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; max-width: 100%; }
body {
  background: var(--bg);
  color: var(--paper);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.45;
  letter-spacing: 0.01em;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
::selection { background: rgba(215, 195, 146, 0.28); }

body:has(.harness-banner) {
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.harness-banner {
  flex: 0 0 auto;
  min-height: 36px;
  height: auto;
  display: block;
  padding: 8px 12px;
  background: #1a1812;
  color: var(--gold);
  border-bottom: 1px solid rgba(215, 195, 146, 0.28);
  font-size: 12px;
  letter-spacing: 0.04em;
  text-align: center;
  overflow-wrap: anywhere;
  max-width: 100%;
}
body:has(.harness-banner) #app { height: auto; flex: 1; min-height: 0; min-width: 0; }

#app { height: 100%; }
.app {
  height: 100%;
  max-width: min(1480px, 100%);
  margin: 0 auto;
  padding: 22px 32px 20px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
}

.header {
  display: flex;
  align-items: flex-start;
  gap: 22px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
  min-width: 0;
  max-width: 100%;
}
.brand { display: flex; gap: 12px; align-items: center; min-width: 180px; }
.brand-mark {
  width: 2px;
  height: 32px;
  background: var(--gold);
  border-radius: 1px;
}
.brand-name { font-size: 20px; font-weight: 600; letter-spacing: 0.12em; line-height: 1.1; }
.brand-sub { margin-top: 3px; color: var(--dim); font-size: 12px; letter-spacing: 0.06em; }
.status-block { flex: 1; min-width: 0; padding-top: 2px; }
.pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 28px;
  padding: 0 10px 0 8px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  font-size: 12px;
  letter-spacing: 0.04em;
}
.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 0 3px rgba(215, 195, 146, 0.12);
}
.dot.wait { background: var(--gold); opacity: 0.55; box-shadow: none; }
.dot.muted { background: transparent; box-shadow: none; border: 1px solid var(--faint); }
.dot.bad { background: var(--clay); box-shadow: none; }
.detail {
  margin: 4px 0 0;
  color: var(--dim);
  font-size: 12px;
}
.detail:empty { display: none; }
.meta {
  margin-top: 8px;
  color: var(--faint);
  font-size: 12px;
  letter-spacing: 0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.add { margin-left: auto; display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.add-row { display: flex; gap: 8px; }
.add input {
  width: 176px;
  height: 36px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: transparent;
  outline: none;
}
.add input::placeholder { color: var(--faint); }
.add input:focus { border-color: rgba(215, 195, 146, 0.75); }
.add button {
  height: 36px;
  padding: 0 16px;
  border-radius: 999px;
  border: 1px solid rgba(215, 195, 146, 0.45);
  background: transparent;
  color: var(--gold);
  letter-spacing: 0.08em;
}
.add button:hover { background: rgba(215, 195, 146, 0.08); }
.form-error { min-height: 16px; margin: 0; color: var(--clay); font-size: 12px; text-align: right; }

.banner {
  margin-top: 12px;
  color: var(--clay);
  font-size: 13px;
}
.banner:empty { display: none; }

.workspace {
  flex: 1;
  min-height: 0;
  min-width: 0;
  max-width: 100%;
  display: grid;
  grid-template-columns: 292px minmax(0, 1fr);
  gap: 28px;
  padding-top: 20px;
}
.watch { min-height: 0; min-width: 0; max-width: 100%; display: flex; flex-direction: column; }
.watch-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 8px;
  color: var(--dim);
  font-size: 12px;
  letter-spacing: 0.14em;
}
.watch-head span:last-child { letter-spacing: 0.04em; font-family: var(--mono); color: var(--faint); }
.watch-list { overflow: auto; min-height: 0; min-width: 0; max-width: 100%; padding-right: 4px; }
.row {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  column-gap: 12px;
  row-gap: 3px;
  padding: 12px 8px 12px 12px;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-left: 2px solid transparent;
  background: transparent;
  text-align: left;
  color: inherit;
}
.row.selected {
  background: rgba(215, 195, 146, 0.06);
  border-left-color: var(--gold);
}
.row:hover { background: rgba(243, 239, 228, 0.03); }
.sym { font-size: 15px; letter-spacing: 0.06em; }
.px { font-family: var(--mono); font-size: 14px; font-variant-numeric: tabular-nums; }
.st { font-size: 12px; }
.rm {
  justify-self: end;
  align-self: center;
  border: 0;
  background: none;
  color: var(--faint);
  font-size: 12px;
  letter-spacing: 0.06em;
  padding: 0;
  visibility: hidden;
}
.row.selected .rm, .row:hover .rm, .row:focus-within .rm { visibility: visible; }
.rm:hover { color: var(--paper); }

.stage {
  min-width: 0;
  min-height: 0;
  background: var(--raise);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 20px 22px 14px;
  display: flex;
  flex-direction: column;
}
.title-line { display: flex; align-items: baseline; gap: 12px; min-width: 0; }
.title-line h1 {
  margin: 0;
  font-size: 28px;
  font-weight: 600;
  letter-spacing: 0.08em;
  line-height: 1;
}
.exch { color: var(--dim); font-size: 13px; letter-spacing: 0.08em; }
.instrument-top { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; min-width: 0; max-width: 100%; }
.long-name {
  margin: 8px 0 0;
  color: var(--dim);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 640px;
}
.stamp { margin-top: 6px; display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; min-width: 0; max-width: 100%; }
.stamp strong { font-family: var(--mono); font-size: 13px; font-weight: 500; letter-spacing: 0; }
.stamp span { color: var(--dim); font-size: 12px; }
.feed-status { font-size: 13px; letter-spacing: 0.08em; padding-top: 4px; }

.quotes {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin: 14px 0 10px;
}
.quote {
  min-width: 0;
  padding: 14px 16px 12px;
  border-radius: 10px;
  background: rgba(243, 239, 228, 0.025);
  border: 1px solid var(--line);
}
.quote .k { color: var(--dim); font-size: 12px; letter-spacing: 0.16em; }
.quote .v {
  margin-top: 8px;
  font-family: var(--mono);
  font-size: 32px;
  line-height: 1;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}
.quote .s { margin-top: 8px; color: var(--faint); font-size: 12px; font-family: var(--mono); }

.tone-live { color: var(--gold); }
.tone-delayed { color: var(--delayed); }
.tone-frozen { color: var(--frozen); }
.tone-bad { color: var(--clay); }
.tone-stale { color: var(--stale); }
.tone-wait { color: var(--frozen); }
.tone-muted { color: var(--dim); }
.dir-up { color: var(--sage); }
.dir-down { color: var(--clay); }
.dir-flat, .dir-none { color: var(--paper); }

.messages { min-height: 0; }
.messages:empty { display: none; }
.msg { margin: 0 0 6px; font-size: 13px; }
.msg.bad { color: var(--clay); }
.msg.note { color: var(--dim); }

.chart-wrap {
  position: relative;
  flex: 1;
  min-height: 460px;
  min-width: 0;
  width: 100%;
  max-width: 100%;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid rgba(243, 239, 228, 0.05);
  background: var(--chart);
}
.chart-host { position: absolute; inset: 0; min-width: 0; max-width: 100%; overflow: hidden; }
.chart-empty {
  position: absolute;
  inset: 0;
  z-index: 2;
  margin: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  text-align: center;
  color: var(--dim);
  background: rgba(12, 15, 13, 0.72);
  pointer-events: none;
}
.chart-empty[hidden] { display: none; }

.chart-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 10px;
  min-width: 0;
  max-width: 100%;
}
.ohlc {
  min-width: 0;
  max-width: 100%;
  color: var(--paper);
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0;
  font-variant-numeric: tabular-nums;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  white-space: nowrap;
}
.chart-actions { display: flex; align-items: center; gap: 8px; flex: 1 1 auto; min-width: 0; flex-wrap: wrap; justify-content: flex-end; }
.follow {
  border: 1px solid var(--line-strong);
  background: transparent;
  color: var(--dim);
  border-radius: 999px;
  padding: 6px 10px;
  letter-spacing: 0.04em;
  flex: 0 0 auto;
  white-space: nowrap;
}
.follow:hover { color: var(--paper); }
.ranges { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; min-width: 0; max-width: 100%; }
.ranges button {
  border: 0;
  background: transparent;
  color: var(--dim);
  border-radius: 999px;
  padding: 6px 10px;
  letter-spacing: 0.04em;
}
.ranges button[aria-selected="true"] {
  color: var(--paper);
  background: rgba(243, 239, 228, 0.06);
}
.footnote {
  margin: 8px 0 0;
  color: var(--faint);
  font-size: 12px;
  min-width: 0;
  max-width: 100%;
  overflow-wrap: anywhere;
}

button:focus-visible, .row:focus-visible {
  outline: 1px solid rgba(215, 195, 146, 0.85);
  outline-offset: 2px;
}
.watch-list::-webkit-scrollbar { width: 8px; }
.watch-list::-webkit-scrollbar-thumb { background: rgba(243, 239, 228, 0.12); border-radius: 99px; }

.logout {
  height: 36px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: transparent;
  color: var(--dim);
  letter-spacing: 0.06em;
}
.logout:hover { color: var(--paper); }

.login-body {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 32px 16px;
}
.login {
  width: min(420px, 100%);
  padding: 28px 28px 24px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--raise);
}
.login-note {
  margin: 18px 0 0;
  color: var(--dim);
  font-size: 13px;
}
.login form { display: flex; flex-direction: column; gap: 14px; margin-top: 22px; }
.login label { display: flex; flex-direction: column; gap: 6px; color: var(--dim); font-size: 12px; letter-spacing: 0.08em; }
.login input {
  height: 40px;
  border-radius: 10px;
  border: 1px solid var(--line-strong);
  background: transparent;
  padding: 0 12px;
  color: var(--paper);
  letter-spacing: 0;
  font-size: 15px;
}
.login input:focus { outline: none; border-color: rgba(215, 195, 146, 0.75); }
.login button {
  height: 40px;
  margin-top: 4px;
  border-radius: 999px;
  border: 1px solid rgba(215, 195, 146, 0.45);
  background: transparent;
  color: var(--gold);
  letter-spacing: 0.12em;
}
.login button:hover { background: rgba(215, 195, 146, 0.08); }
.login button:disabled { opacity: 0.55; cursor: progress; }
@keyframes onAutoFillStart { from {} to {} }
.login input:-webkit-autofill { animation-name: onAutoFillStart; animation-duration: 1ms; }
.login .form-error { min-height: 18px; margin: 0; text-align: left; }
.setup-rules {
  margin: 16px 0 0;
  padding-left: 18px;
  color: var(--paper);
  font-size: 13px;
}
.setup-rules li { margin: 6px 0; }
.setup-live { margin: 0; color: var(--dim); font-size: 13px; }
.request-id {
  margin: 18px 0 8px;
  font-family: var(--mono);
  font-size: 32px;
  letter-spacing: 0.14em;
  text-align: center;
}

@media (max-width: 980px) {
  body, body:has(.harness-banner) { overflow-x: hidden; overflow-y: hidden; }
  #app { height: 100%; min-width: 0; max-width: 100%; }
  .app { height: 100%; padding: 8px 10px 8px; overflow: hidden; }
  .header { flex-wrap: wrap; gap: 8px; padding-bottom: 8px; }
  .brand { min-width: 0; }
  .meta, .brand-sub, .long-name { display: none; }
  .add, .add-row { width: 100%; max-width: 100%; margin-left: 0; min-width: 0; }
  .add { align-items: stretch; }
  .add input { flex: 1; width: auto; min-width: 0; height: 34px; }
  .add button, .logout { height: 34px; flex: 0 0 auto; }
  .form-error { text-align: left; }
  .workspace {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
    gap: 8px;
    padding-top: 8px;
  }
  .watch-head { min-width: 0; }
  .watch-list {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    overflow-y: hidden;
    max-height: 74px;
    padding-bottom: 2px;
  }
  .row {
    width: auto;
    min-width: 132px;
    flex: 0 0 auto;
    padding: 8px 8px 8px 10px;
    grid-template-columns: minmax(0, 1fr) auto;
  }
  .st { grid-column: 1 / -1; }
  .stage { padding: 10px 10px 8px; min-height: 0; }
  .chart-wrap { flex: 1; min-height: 0; height: auto; }
  .chart-foot { flex-wrap: wrap; gap: 6px; margin-top: 6px; align-items: stretch; }
  .ohlc { flex: 1 1 100%; width: 100%; font-size: 11px; }
  .chart-actions { flex: 1 1 100%; width: 100%; justify-content: flex-start; }
  .ranges { justify-content: flex-start; }
  .ranges button, .follow { padding: 5px 8px; font-size: 12px; }
  .quotes { gap: 6px; margin: 8px 0 6px; }
  .quote { padding: 7px 8px 6px; }
  .quote .k { letter-spacing: 0.02em; font-size: 11px; }
  .quote .v { font-size: 16px; margin-top: 2px; overflow-wrap: anywhere; }
  .title-line h1 { font-size: 22px; }
  .footnote { margin-top: 4px; font-size: 11px; }
}
@media (max-width: 980px) and (orientation: landscape), (max-height: 520px) {
  .header, .banner, .watch-head, .stamp, .footnote, .long-name, .quote .s, .row .st, .row .rm { display: none; }
  .workspace { padding-top: 0; gap: 4px; }
  .watch-list { max-height: 36px; }
  .row { min-width: 86px; padding: 4px 8px; }
  .stage { padding: 6px 8px 4px; }
  .title-line h1 { font-size: 18px; }
  .quotes { margin: 4px 0; }
  .quote { padding: 4px 6px; }
  .quote .v { font-size: 15px; }
  .chart-foot { margin-top: 2px; }
}
