:root {
  --bg: #0b0e14;
  --panel: #111722;
  --panel2: #0f141d;
  --line: #1e2635;
  --text: #e6edf7;
  --muted: #8b96a8;
  --red: #ef4444;
  --green: #22c55e;
  --gold: #f59e0b;
  --blue: #2563eb;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

[hidden] {
  display: none !important;
}

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", Arial, sans-serif;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
}

#app {
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* Netlify 免费版角标占位：只在该域名下生效 */
body.netlify-badge-safe #app {
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}

.view {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* ---------- 顶部标签 ---------- */
.tabs {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}

.tabs .tab {
  height: 32px;
  padding: 0 16px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.tabs .tab.active {
  color: var(--text);
  background: var(--panel);
  border-color: var(--line);
}

.tabs .spacer {
  flex: 1;
}

.icon-btn {
  width: 34px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--muted);
  font-size: 16px;
  cursor: pointer;
}

/* ---------- 顶部输入 ---------- */
.bar {
  display: flex;
  gap: 8px;
  padding: 10px 10px 6px;
  align-items: center;
  flex: 0 0 auto;
}

.bar input {
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 10px;
  height: 40px;
  padding: 0 10px;
  font-size: 15px;
  outline: none;
  min-width: 0;
  -webkit-user-select: text;
  user-select: text;
}

.bar input:focus {
  border-color: #3b4a63;
}

.bar .code {
  width: 92px;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.5px;
}

.bar .date {
  flex: 1;
  font-size: 14px;
}

.bar button,
.actions button,
.replay button,
.modal button,
.rec-toolbar button,
.detail-tools button {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  border-radius: 10px;
  height: 40px;
  font-size: 14px;
  font-weight: 600;
  padding: 0 12px;
  cursor: pointer;
  touch-action: manipulation;
  white-space: nowrap;
}

button:active {
  transform: scale(0.97);
  filter: brightness(1.12);
}

button:disabled {
  opacity: 0.45;
}

.primary {
  background: var(--blue) !important;
  border-color: var(--blue) !important;
  color: #fff !important;
}

.ghost {
  color: var(--muted) !important;
}

.danger {
  color: #f87171 !important;
  border-color: rgba(239, 68, 68, 0.35) !important;
  background: rgba(239, 68, 68, 0.08) !important;
}

.blind-btn {
  width: 44px;
  padding: 0 !important;
  font-size: 18px !important;
  flex: 0 0 auto;
}

.blind-bar {
  justify-content: space-between;
}

.blind-bar .primary,
.blind-bar .ghost {
  height: 34px;
  font-size: 13px;
}

.blind-label {
  font-size: 13px;
  color: var(--gold);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------- 行情 ---------- */
.quote {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  padding: 2px 14px 8px;
  flex: 0 0 auto;
}

.quote-left {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.name {
  font-size: 17px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.blind-name {
  color: var(--gold);
}

.date-label {
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.quote-right {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-variant-numeric: tabular-nums;
}

.price {
  font-size: 22px;
  font-weight: 700;
}

.chg {
  font-size: 13px;
  font-weight: 600;
}

.up { color: var(--red); }
.down { color: var(--green); }

.limit-up {
  color: #ffd60a;
  text-shadow: 0 0 10px rgba(255, 214, 10, 0.45);
}

.limit-down {
  color: #3b82f6;
  text-shadow: 0 0 10px rgba(59, 130, 246, 0.45);
}

/* ---------- 图表 ---------- */
.sub-tabs {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 10px 4px;
  flex: 0 0 auto;
}

.sub-label {
  font-size: 11px;
  color: var(--muted);
}

.sub-tab {
  height: 24px;
  padding: 0 10px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
}

.sub-tab.active {
  color: var(--text);
  border-color: #3b4a63;
  background: #182033;
}

#chart {
  flex: 1 1 auto;
  min-height: 190px;
  position: relative;
}

.sub-divider {
  position: absolute;
  left: 0;
  right: 0;
  top: 70%;
  height: 1px;
  background: var(--line);
  pointer-events: none;
  z-index: 2;
}

.marker-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 3;
}

.trade-marker {
  position: absolute;
  width: 17px;
  height: 43px;
  --c: #ffd60a;
}

.trade-marker.buy { --c: #ffd60a; }
.trade-marker.sell { --c: #3b82f6; }

.trade-badge {
  position: absolute;
  left: 0;
  width: 17px;
  height: 17px;
  border-radius: 50%;
  background: var(--c);
  color: #fff;
  font-size: 9.5px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.25);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.32);
  box-sizing: border-box;
}

.trade-connector {
  position: absolute;
  left: 8px;
  width: 1px;
  height: 22px;
  background-image: linear-gradient(to bottom, var(--c) 50%, transparent 50%);
  background-size: 1px 4px;
  opacity: 0.85;
}

.trade-dot {
  position: absolute;
  left: 6.5px;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--c);
}

/* 买在下：点 -> 虚线 -> 徽标 */
.trade-marker.buy .trade-dot { top: 0; }
.trade-marker.buy .trade-connector { top: 4px; }
.trade-marker.buy .trade-badge { top: 26px; }

/* 卖在上：徽标 -> 虚线 -> 点 */
.trade-marker.sell .trade-badge { top: 0; }
.trade-marker.sell .trade-connector { top: 17px; }
.trade-marker.sell .trade-dot { top: 39px; }

/* ---------- 账户 ---------- */
.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  background: var(--line);
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  margin-top: 4px;
  flex: 0 0 auto;
}

.stats > div {
  background: var(--bg);
  padding: 7px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.stats span {
  font-size: 11px;
  color: var(--muted);
}

.stats b {
  font-size: 13px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------- 结束本轮 ---------- */
.finish {
  margin: 6px 10px 0;
  height: 34px;
  border-radius: 10px;
  border: 1px solid rgba(245, 158, 11, 0.35);
  background: rgba(245, 158, 11, 0.08);
  color: var(--gold);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  flex: 0 0 auto;
}

/* ---------- 交易按钮 ---------- */
.actions {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 5px;
  padding: 8px 10px 4px;
  flex: 0 0 auto;
}

.actions button {
  height: 42px;
  padding: 0 1px;
  font-size: 11.5px;
  letter-spacing: -0.2px;
}

.actions .buy {
  color: var(--red);
  border-color: rgba(239, 68, 68, 0.35);
  background: rgba(239, 68, 68, 0.08);
}

.actions .sell {
  color: var(--green);
  border-color: rgba(34, 197, 94, 0.35);
  background: rgba(34, 197, 94, 0.08);
}

.custom-order {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 2px 10px 0;
  flex: 0 0 auto;
  font-size: 12px;
  color: var(--muted);
}

.custom-order input {
  width: 62px;
  height: 32px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  text-align: center;
  font-size: 14px;
  outline: none;
  -webkit-user-select: text;
  user-select: text;
}

.custom-order button {
  flex: 1;
  height: 32px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.custom-order .buy {
  color: var(--red);
  border-color: rgba(239, 68, 68, 0.35);
  background: rgba(239, 68, 68, 0.08);
}

.custom-order .sell {
  color: var(--green);
  border-color: rgba(34, 197, 94, 0.35);
  background: rgba(34, 197, 94, 0.08);
}

/* ---------- 回放 ---------- */
.replay {
  display: grid;
  grid-template-columns: 0.95fr 1.35fr 0.7fr 0.8fr 0.8fr;
  gap: 6px;
  padding: 4px 10px calc(8px + env(safe-area-inset-bottom));
  flex: 0 0 auto;
}

.replay button {
  padding: 0 4px;
  font-size: 12.5px;
}

.replay #latest {
  color: var(--gold);
}

.replay .next {
  background: #1d4ed8;
  border-color: #1d4ed8;
  color: #fff;
}

.replay .on {
  background: var(--gold);
  border-color: var(--gold);
  color: #1a1200;
}

/* ---------- 提示 ---------- */
.toast {
  position: fixed;
  left: 50%;
  top: calc(196px + env(safe-area-inset-top));
  transform: translate(-50%, -8px);
  background: rgba(17, 23, 34, 0.97);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 13px;
  padding: 9px 14px;
  border-radius: 10px;
  max-width: 82vw;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
  z-index: 80;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ================= 记录页 ================= */
#recordsView {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 10px 10px calc(16px + env(safe-area-inset-bottom));
  gap: 0;
}

.rec-summary {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.rec-stat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
}

.rec-stat span {
  font-size: 11px;
  color: var(--muted);
}

.rec-stat b {
  display: block;
  margin-top: 3px;
  font-size: 18px;
  font-variant-numeric: tabular-nums;
}

.rec-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 12px 0 8px;
  flex-wrap: wrap;
}

.chips {
  display: flex;
  gap: 6px;
}

.chip {
  height: 30px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.chip.active {
  color: var(--text);
  border-color: #3b4a63;
  background: #182033;
}

.rec-actions {
  display: flex;
  gap: 6px;
}

.rec-actions button {
  height: 32px;
  font-size: 12px;
  padding: 0 10px;
}

.rec-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.rec-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
}

.rec-check {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  margin: 3px 0 0;
  border: 1px solid #3b4a63;
  border-radius: 5px;
  background: var(--bg);
  flex: 0 0 auto;
  position: relative;
  cursor: pointer;
}

.rec-check:checked {
  background: var(--blue);
  border-color: var(--blue);
}

.rec-check:checked::after {
  content: '✓';
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 12px;
  line-height: 1;
}

.rec-main {
  flex: 1;
  min-width: 0;
}

.rec-top {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.rec-top b {
  font-size: 14px;
}

.badge {
  font-size: 10px;
  line-height: 1.6;
  padding: 0 6px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
}

.badge.blind {
  color: var(--gold);
  border-color: rgba(245, 158, 11, 0.4);
  background: rgba(245, 158, 11, 0.08);
}

.rec-date {
  font-size: 11px;
  color: var(--muted);
}

.rec-metrics {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 5px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

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

.rec-open {
  height: 30px !important;
  padding: 0 10px !important;
  font-size: 12px !important;
  flex: 0 0 auto;
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.empty {
  padding: 40px 10px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

/* ================= 弹窗 ================= */
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(0, 0, 0, 0.62);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
}

body.netlify-badge-safe .modal {
  padding-bottom: calc(84px + env(safe-area-inset-bottom));
}

body.netlify-badge-safe .modal-card {
  max-height: calc(90vh - 72px);
}

.modal-card {
  width: min(520px, 100%);
  max-height: 90vh;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}

.modal-title {
  font-size: 16px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.close {
  width: 32px !important;
  height: 32px !important;
  padding: 0 !important;
  font-size: 20px !important;
  color: var(--muted) !important;
  flex: 0 0 auto;
}

.modal-body {
  padding: 12px 14px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  -webkit-user-select: text;
  user-select: text;
}

.modal-actions {
  display: flex;
  gap: 8px;
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  flex: 0 0 auto;
}

.modal-actions button {
  flex: 1;
  height: 40px;
  font-size: 13px;
}

.reveal {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.6;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 11px;
  margin-bottom: 10px;
}

.reveal b {
  color: var(--text);
}

.reveal .blind-reveal {
  color: var(--gold);
  font-weight: 700;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin: 10px 0;
}

.metric {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
}

.metric span {
  font-size: 11px;
  color: var(--muted);
}

.metric b {
  display: block;
  margin-top: 2px;
  font-size: 16px;
  font-variant-numeric: tabular-nums;
}

.curve-chart {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 6px;
  margin: 10px 0;
}

.curve-chart svg {
  display: block;
  width: 100%;
  height: auto;
}

.detail-kline {
  height: 260px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  margin: 8px 0 10px;
  overflow: hidden;
  position: relative;
}

.section-title {
  font-size: 12px;
  color: var(--muted);
  margin: 2px 2px 6px;
}

.curve-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  font-size: 11px;
  color: var(--muted);
  margin: 0 2px 4px;
}

.curve-legend i {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 2px;
  margin-right: 4px;
  vertical-align: middle;
}

.curve-empty {
  padding: 24px 0;
  text-align: center;
  color: var(--muted);
  font-size: 12px;
}

.curve-empty button {
  margin-top: 8px;
  height: 30px;
  padding: 0 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
}

.trade-list {
  margin: 10px 0;
  overflow-x: auto;
}

.trade-list table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.trade-list th,
.trade-list td {
  padding: 5px 4px;
  border-bottom: 1px solid var(--line);
  text-align: right;
  white-space: nowrap;
}

.trade-list th:first-child,
.trade-list td:first-child {
  text-align: left;
}

.trade-list th {
  color: var(--muted);
  font-weight: 500;
}

.trade-list .empty-row td {
  text-align: center;
  color: var(--muted);
  padding: 14px 0;
}

.note-label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
  margin: 8px 0;
}

.note-label textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  padding: 9px 10px;
  font-size: 13px;
  font-family: inherit;
  resize: vertical;
  outline: none;
}

.note-label textarea:focus {
  border-color: #3b4a63;
}

.detail-tools {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.detail-tools button {
  flex: 1;
  height: 36px;
  font-size: 12px;
}

.compare-table-wrap {
  overflow-x: auto;
  margin-top: 10px;
}

.compare-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.compare-table th,
.compare-table td {
  padding: 6px 5px;
  border-bottom: 1px solid var(--line);
  text-align: right;
}

.compare-table th:first-child,
.compare-table td:first-child {
  text-align: left;
}

.compare-table th {
  color: var(--muted);
  font-weight: 500;
}

/* ---------- 设置 ---------- */
.settings-body label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 10px;
  font-size: 12px;
  color: var(--muted);
}

.settings-body input,
.settings-body select {
  height: 38px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  padding: 0 10px;
  font-size: 14px;
  outline: none;
}

.settings-body input:focus,
.settings-body select:focus {
  border-color: #3b4a63;
}

.hint {
  font-size: 11px;
  line-height: 1.6;
  color: var(--muted);
  margin: 4px 0 0;
}

@media (max-width: 350px) {
  .bar .code { width: 78px; }
  .actions button { font-size: 11.5px; }
  .replay button { font-size: 12px; }
}

@media (max-height: 720px) {
  #chart { min-height: 140px; }
  .stats > div { padding: 5px 8px; }
}
