:root {
  --bg: #0d1117;
  --bg2: #161b22;
  --card: #161b22;
  --border: #30363d;
  --border-soft: #21262d;
  --text: #e6edf3;
  --muted: #8b949e;
  --accent: #58a6ff;
  --accent-dim: rgba(88, 166, 255, 0.15);
  --green: #3fb950;
  --green-dim: rgba(63, 185, 80, 0.15);
  --red: #f85149;
  --red-dim: rgba(248, 81, 73, 0.15);
  --pink: #f778ba;
  --yellow: #d29922;
  --purple: #a371f7;
  --radius: 12px;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.bg-glow {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse 80% 50% at 20% -10%, rgba(88, 166, 255, 0.12), transparent),
    radial-gradient(ellipse 60% 40% at 90% 10%, rgba(163, 113, 247, 0.08), transparent);
  z-index: 0;
}

.app {
  position: relative;
  z-index: 1;
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.75rem 1.25rem 3rem;
}

/* Header */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.logo {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent-dim), rgba(163, 113, 247, 0.2));
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
}

header h1 {
  font-size: 1.55rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

header .sub {
  color: var(--muted);
  font-size: 0.82rem;
  margin-top: 0.15rem;
}

.badge {
  font-size: 0.75rem;
  color: var(--accent);
  background: var(--accent-dim);
  border: 1px solid rgba(88, 166, 255, 0.3);
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  white-space: nowrap;
}

/* Card */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 1.25rem;
}

/* Controls */
.controls { padding: 1.25rem 1.35rem; }

.controls-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem 1.25rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.field-wide { grid-column: 1 / -1; }
.field-full { width: 100%; }

.field > label {
  font-size: 0.78rem;
  color: var(--muted);
  font-weight: 500;
  letter-spacing: 0.02em;
}

select, input[type="number"], textarea {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 0.55rem 0.75rem;
  font-size: 0.92rem;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

select:focus, input:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

textarea {
  width: 100%;
  resize: vertical;
  min-height: 56px;
  font-family: inherit;
}

.checks {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 0.85rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.88rem;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  user-select: none;
}

.chip:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent-dim);
  color: var(--accent);
}

.chip input { accent-color: var(--accent); }

.actions-bar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 1.15rem;
  padding-top: 1.1rem;
  border-top: 1px solid var(--border-soft);
  flex-wrap: wrap;
}

.btn {
  border: none;
  border-radius: 8px;
  padding: 0.55rem 1.15rem;
  font-size: 0.9rem;
  cursor: pointer;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  transition: transform 0.1s, opacity 0.15s, background 0.15s;
}

.btn:active:not(:disabled) { transform: scale(0.97); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn.primary {
  background: linear-gradient(135deg, #388bfd, #58a6ff);
  color: #fff;
  box-shadow: 0 2px 8px rgba(56, 139, 253, 0.35);
}

.btn.primary:hover:not(:disabled) { filter: brightness(1.08); }

.btn.danger {
  background: var(--red-dim);
  color: var(--red);
  border: 1px solid rgba(248, 81, 73, 0.35);
}

.btn.secondary {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn.sm { padding: 0.35rem 0.75rem; font-size: 0.82rem; }

.btn-icon { font-size: 0.7rem; }

.progress-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 0.85rem;
  min-width: 160px;
}

#progressBar {
  flex: 1;
  height: 6px;
  background: var(--bg);
  border-radius: 999px;
  overflow: hidden;
  position: relative;
}

#progressBar::after {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: var(--p, 0%);
  background: linear-gradient(90deg, #388bfd, #58a6ff);
  border-radius: 999px;
  transition: width 0.25s ease;
}

#progressText {
  font-size: 0.8rem;
  color: var(--muted);
  min-width: 110px;
  white-space: nowrap;
}

/* Results */
.results { overflow: hidden; }

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.9rem 1.2rem;
  border-bottom: 1px solid var(--border-soft);
  flex-wrap: wrap;
  gap: 0.5rem;
}

.section-head h2 {
  font-size: 0.95rem;
  font-weight: 600;
}

.legend {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.75rem;
  color: var(--muted);
}

.dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 0.25rem;
  vertical-align: middle;
}

.dot.box { background: #58a6ff; }
.dot.channel { background: #a371f7; }
.dot.triangle { background: #d29922; }
.dot.dow { background: #3fb950; }

.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

th, td {
  padding: 0.65rem 0.85rem;
  text-align: left;
  border-bottom: 1px solid var(--border-soft);
  white-space: nowrap;
}

th {
  background: rgba(0, 0, 0, 0.2);
  color: var(--muted);
  font-weight: 500;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

tbody tr {
  transition: background 0.12s;
}

tbody tr:hover {
  background: rgba(88, 166, 255, 0.06);
}

.rank {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  width: 36px;
}

.code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-weight: 600;
  color: var(--accent);
}

.muted { color: var(--muted); font-size: 0.85rem; }

.score {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.score-high { color: var(--green); }
.score-mid { color: var(--yellow); }
.score-low { color: var(--muted); }

.pattern-tag {
  display: inline-block;
  padding: 0.18rem 0.55rem;
  border-radius: 6px;
  font-size: 0.78rem;
  font-weight: 500;
}

.tag-box {
  background: rgba(88, 166, 255, 0.15);
  color: #79b8ff;
  border: 1px solid rgba(88, 166, 255, 0.25);
}

.tag-channel {
  background: rgba(163, 113, 247, 0.15);
  color: #c4a7f7;
  border: 1px solid rgba(163, 113, 247, 0.25);
}

.tag-triangle {
  background: rgba(210, 153, 34, 0.15);
  color: #e3b341;
  border: 1px solid rgba(210, 153, 34, 0.25);
}

.tag-dow {
  background: rgba(63, 185, 80, 0.15);
  color: #56d364;
  border: 1px solid rgba(63, 185, 80, 0.25);
}

.mini-bar {
  display: inline-block;
  width: 48px;
  height: 5px;
  background: var(--bg);
  border-radius: 999px;
  overflow: hidden;
  vertical-align: middle;
  margin-right: 0.35rem;
}

.mini-bar i {
  display: block;
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
}

.mini-bar.vol i { background: var(--purple); }
.mini-bar.brk i { background: var(--green); }

.mini-num {
  font-size: 0.78rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.ops { display: flex; gap: 0.35rem; }

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--accent);
  padding: 0.25rem 0.55rem;
  border-radius: 6px;
  font-size: 0.8rem;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.12s, border-color 0.12s;
}

.btn-ghost:hover {
  background: var(--accent-dim);
  border-color: var(--accent);
}

.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--muted);
}

.empty-icon { font-size: 2.2rem; margin-bottom: 0.5rem; opacity: 0.7; }
.empty-sub { font-size: 0.82rem; margin-top: 0.25rem; opacity: 0.7; }

.tip {
  padding: 0.7rem 1.2rem;
  font-size: 0.75rem;
  color: var(--muted);
  border-top: 1px solid var(--border-soft);
}

/* Chart panel */
.chart-panel { padding: 1rem 1.2rem 1.2rem; }

.chart-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 0.6rem;
}

.chart-title {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
  font-size: 0.95rem;
}

.ct-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-weight: 700;
  color: var(--accent);
  font-size: 1.05rem;
}

.ct-name { font-weight: 600; }

.ct-detail {
  color: var(--muted);
  font-size: 0.82rem;
  width: 100%;
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 0.65rem;
}

.chart-legend .line {
  display: inline-block;
  width: 18px;
  height: 2px;
  vertical-align: middle;
  margin-right: 0.3rem;
  border-radius: 1px;
}

.chart-legend .line.blue { background: #58a6ff; }
.chart-legend .line.pink { background: #f778ba; }

.chart-legend .arrow {
  display: inline-block;
  width: 0;
  height: 0;
  vertical-align: middle;
  margin-right: 0.3rem;
}

.chart-legend .arrow.up {
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-bottom: 8px solid #3fb950;
}

.chart-legend .arrow.down {
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 8px solid #f85149;
}

#chartContainer {
  height: 460px;
  width: 100%;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border-soft);
}

/* Responsive */
@media (max-width: 768px) {
  .controls-grid {
    grid-template-columns: 1fr 1fr;
  }
  .field-wide { grid-column: 1 / -1; }
  header h1 { font-size: 1.3rem; }
  .logo { width: 40px; height: 40px; }
}

@media (max-width: 520px) {
  .controls-grid {
    grid-template-columns: 1fr;
  }
  .actions-bar { flex-direction: column; align-items: stretch; }
  .progress-wrap { width: 100%; }
}
