:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #17202a;
  --muted: #687385;
  --grid: #dfe4ea;
  --up: #d83b3b;
  --down: #1f72d8;
  --line5: #111827;
  --line10: #178a55;
  --line20: #a855f7;
  --line60: #d97706;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", "Malgun Gothic", Arial, sans-serif;
}

button {
  font: inherit;
}

button.secondary {
  min-height: 32px;
  border: 1px solid #155e75;
  border-radius: 6px;
  background: #ffffff;
  color: #155e75;
  font-weight: 700;
  cursor: pointer;
}

.icon-button {
  width: 34px;
  padding: 0;
  font-size: 16px;
}

.chart-settings-drawer {
  position: fixed;
  z-index: 50;
  max-height: calc(100vh - 36px);
  overflow-y: auto;
  overflow-x: hidden;
  border: 1px solid #d9e2ec;
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 18px 46px rgba(15, 23, 42, 0.18);
  padding: 14px;
}

.settings-head,
.settings-tabs,
.setting-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.settings-head {
  justify-content: space-between;
  margin-bottom: 12px;
}

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

.settings-status {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.settings-status[data-tone="ok"] {
  color: #0f766e;
}

.settings-status[data-tone="pending"] {
  color: #d97706;
}

.settings-status[data-tone="error"] {
  color: #d83b3b;
}

.settings-tabs {
  border-bottom: 1px solid #e5eaf0;
  margin-bottom: 12px;
}

.settings-tab {
  border: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--muted);
  padding: 9px 10px;
  font-weight: 700;
}

.settings-tab.active {
  border-bottom-color: #155e75;
  color: var(--text);
}

.settings-section {
  display: grid;
  gap: 7px;
  margin-top: 9px;
}

.settings-section h3 {
  margin: 0;
  font-size: 14px;
}

.settings-section p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.setting-row {
  justify-content: space-between;
  min-height: 30px;
}

.setting-row.checkbox-row {
  justify-content: flex-start;
}

.setting-row.checkbox-row span,
.indicator-row label,
.line-chip,
.multi-head label,
.separate-slot label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.indicator-row,
.separate-slot {
  display: grid;
  gap: 6px;
  align-items: center;
  min-width: 0;
}

.indicator-row {
  grid-template-columns: minmax(78px, 1fr) minmax(100px, 1fr) 62px minmax(84px, 0.8fr);
}

.separate-slot {
  grid-template-columns: repeat(auto-fit, minmax(92px, 1fr));
  padding: 7px;
  border: 1px solid #edf1f5;
  border-radius: 6px;
}

.chart-settings-drawer input[type="color"] {
  width: 34px;
  height: 28px;
  padding: 0;
}

.chart-settings-drawer select {
  width: 100%;
  min-width: 0;
  min-height: 28px;
  padding: 3px 6px;
}

.chart-settings-drawer label {
  font-size: 13px;
}

.settings-subtabs {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(68px, 1fr));
  gap: 5px;
  margin-bottom: 8px;
}

.settings-subtab {
  min-height: 28px;
  border-color: #d7dee8;
  background: #ffffff;
  color: var(--muted);
  padding: 0 8px;
  font-size: 12px;
}

.settings-subtab.active {
  border-color: #155e75;
  background: #eef6f8;
  color: #155e75;
}

.multi-indicator {
  display: grid;
  gap: 7px;
  padding: 7px;
  border: 1px solid #edf1f5;
  border-radius: 6px;
}

.multi-head {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) minmax(92px, 120px);
  gap: 8px;
  align-items: center;
}

.line-indicator-group {
  display: grid;
  gap: 7px;
  padding: 7px;
  border: 1px solid #edf1f5;
  border-radius: 6px;
}

.line-indicator-head {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) minmax(88px, 112px);
  gap: 8px;
  align-items: center;
}

.line-indicator-title {
  font-size: 13px;
  font-weight: 700;
}

.line-indicator-toggles {
  display: flex;
  flex-wrap: wrap;
  gap: 5px 8px;
  min-width: 0;
}

.line-chip {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.line-indicator-style {
  display: grid;
  grid-template-columns: minmax(52px, 0.6fr) minmax(100px, 1fr) 62px minmax(84px, 0.8fr);
  gap: 6px;
  align-items: center;
}

.line-indicator-style > span {
  color: var(--muted);
  font-size: 12px;
}

.color-setting {
  min-height: 34px;
}

.color-choice {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  min-width: 0;
}

.color-choice select {
  min-width: 0;
  max-width: 128px;
  font-family: Consolas, "Segoe UI", sans-serif;
}

.custom-color {
  margin-left: 4px;
}

.selected-color-preview {
  width: 22px;
  height: 22px;
  border: 1px solid #cbd5e1;
  border-radius: 999px;
}

.line-style-choice {
  display: flex;
  align-items: center;
  gap: 5px;
  min-width: 0;
}

.line-style-choice select {
  max-width: 96px;
}

.line-style-preview {
  width: 34px;
  height: 0;
  border-top: 2px solid #334155;
}

.line-style-preview.dashed {
  border-top-style: dashed;
}

.line-style-preview.dotted,
.line-style-preview.sparse_dot {
  border-top-style: dotted;
}

.line-style-preview.dash_dot {
  border-image: repeating-linear-gradient(90deg, #334155 0 9px, transparent 9px 13px, #334155 13px 16px, transparent 16px 20px) 1;
}

.line-style-preview.diagonal {
  height: 12px;
  border: 0;
  background: repeating-linear-gradient(135deg, #334155 0 2px, transparent 2px 6px);
}

.chart-settings-drawer input[type="range"] {
  height: 4px;
}

.chart-settings-drawer input[type="range"].thin-range,
.indicator-row input[type="range"] {
  width: min(72px, 100%);
}

.chart-settings-drawer * {
  max-width: 100%;
}

.setting-row.compact {
  grid-column: 1 / -1;
  justify-content: flex-start;
}

.setting-row.compact input {
  max-width: 140px;
}

.chart-settings-drawer input[type="checkbox"] {
  width: 16px;
  height: 16px;
  min-height: 0;
  accent-color: #155e75;
}

.shell {
  width: min(1280px, calc(100vw - 32px));
  margin: 24px auto;
}

.toolbar,
.chart-layout,
.marks {
  background: var(--panel);
  border: 1px solid #e5e7eb;
  border-radius: 8px;
}

.toolbar {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: center;
  padding: 18px 20px;
  margin-bottom: 14px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 22px;
  line-height: 1.2;
}

#scenarioMeta {
  margin-top: 6px;
  color: var(--muted);
  font-size: 14px;
}

.stats {
  display: grid;
  grid-template-columns: repeat(6, minmax(86px, 1fr));
  gap: 8px;
  min-width: 520px;
}

.stat {
  border-left: 3px solid #ccd3dc;
  padding-left: 8px;
}

.stat span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.stat strong {
  display: block;
  font-size: 15px;
  margin-top: 3px;
}

.chart-layout {
  padding: 14px;
}

.tw-chart,
.tw-volume-chart {
  position: relative;
  width: 100%;
  overflow: hidden;
}

.tw-chart {
  height: 520px;
}

.tw-volume-chart {
  height: 140px;
  margin-top: 8px;
}

.tw-overlay-line {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 0;
  border-left: 1px dashed rgba(15, 118, 110, 0.5);
  pointer-events: none;
  z-index: 3;
}

.tw-overlay-line.mark-line {
  border-left-color: rgba(23, 32, 42, 0.5);
}

.tw-overlay-line.mark-opportunity {
  border-left-color: rgba(216, 59, 59, 0.7);
}

.tw-overlay-line.mark-trap {
  border-left-color: rgba(124, 45, 18, 0.75);
}

.tw-overlay-line.mark-risk {
  border-left-color: rgba(217, 119, 6, 0.75);
}

.tw-overlay-line.mark-avoid {
  border-left-color: rgba(71, 85, 105, 0.7);
}

.tw-overlay-label {
  position: absolute;
  top: 8px;
  left: 6px;
  white-space: nowrap;
  color: rgba(15, 118, 110, 0.5);
  font-size: 12px;
  font-weight: 600;
}

.tw-overlay-line.mark-line .tw-overlay-label {
  color: rgba(23, 32, 42, 0.5);
  font-weight: 500;
}

.tw-overlay-line.mark-opportunity .tw-overlay-label {
  color: rgba(216, 59, 59, 0.8);
  font-weight: 700;
}

.tw-overlay-line.mark-trap .tw-overlay-label {
  color: rgba(124, 45, 18, 0.85);
  font-weight: 700;
}

.tw-overlay-line.mark-risk .tw-overlay-label {
  color: rgba(217, 119, 6, 0.85);
  font-weight: 700;
}

.tw-overlay-line.mark-avoid .tw-overlay-label {
  color: rgba(71, 85, 105, 0.82);
  font-weight: 700;
}

.tw-crosshair-price-label {
  position: absolute;
  right: 0;
  z-index: 5;
  transform: translateY(-50%);
  padding: 2px 5px;
  border-radius: 3px 0 0 3px;
  background: #d83b3b;
  color: #ffffff;
  font-size: 11px;
  font-weight: 700;
  line-height: 1.25;
  white-space: nowrap;
  pointer-events: none;
}

.tw-crosshair-price-label.down {
  background: #1f72d8;
}

.marks {
  padding: 16px 20px;
  margin-top: 14px;
}

.marks h2 {
  font-size: 16px;
  margin-bottom: 10px;
}

#marks {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 10px;
}

.mark {
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  padding: 10px 12px;
  background: #fbfcfd;
}

.mark-opportunity {
  border-color: #fecaca;
  background: #fff7f7;
}

.mark-trap {
  border-color: #fed7aa;
  background: #fff7ed;
}

.mark-risk {
  border-color: #fde68a;
  background: #fffbeb;
}

.mark-avoid {
  border-color: #cbd5e1;
  background: #f8fafc;
}

.mark strong {
  display: block;
  font-size: 14px;
}

.mark span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-top: 4px;
}

@media (max-width: 860px) {
  .line-indicator-head,
  .line-indicator-style,
  .indicator-row,
  .multi-head {
    grid-template-columns: 1fr;
  }

  .toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .stats {
    min-width: 0;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .tw-chart {
    height: 430px;
  }
}
