:root {
  --bg: #0f0f1a;
  --bg-card: #1a1a2e;
  --bg-input: #16213e;
  --border: #2a2a4a;
  --text: #e0e0e0;
  --text-dim: #888;
  --accent: #00d4aa;
  --accent-hover: #00f5c4;
  --danger: #ff4757;
  --warning: #ffa502;
  --success: #2ed573;
  --info: #3742fa;
  --font: 'Inter', system-ui, -apple-system, sans-serif;
  --radius: 8px;
  --shadow: 0 4px 24px rgba(0,0,0,0.3);
}

[data-theme="light"] {
  --bg: #f5f5f5;
  --bg-card: #ffffff;
  --bg-input: #f0f0f0;
  --border: #ddd;
  --text: #1a1a2e;
  --text-dim: #666;
  --shadow: 0 4px 24px rgba(0,0,0,0.08);
}

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

html { font-size: 15px; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

.app {
  max-width: 1440px;
  margin: 0 auto;
  padding: 1.5rem;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 0 2rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 2rem;
}

header h1 {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: -0.02em;
}

.header-sub { color: var(--text-dim); font-weight: 400; font-size: 0.9rem; margin-left: 0.5rem; }

.header-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.lang-toggle {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.5rem 1rem;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 700;
  transition: all 0.15s;
  min-width: 42px;
  text-align: center;
}

.lang-toggle:hover { border-color: var(--accent); color: var(--accent); }

.theme-toggle {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.5rem 1rem;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.85rem;
  transition: all 0.15s;
}

.theme-toggle:hover { border-color: var(--accent); }

.layout {
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: 2rem;
  align-items: start;
}

@media (max-width: 1024px) {
  .layout { grid-template-columns: 1fr; }
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
}

.card h2 {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 1.25rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-bottom: 0.3rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.form-group input,
.form-group select {
  width: 100%;
  padding: 0.6rem 0.75rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 0.95rem;
  font-family: var(--font);
  transition: border-color 0.15s;
}

.form-group input:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(0,212,170,0.15);
}

.form-group input::placeholder { color: var(--text-dim); }

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.section-toggle {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
}

.section-toggle button {
  flex: 1;
  padding: 0.6rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 500;
  transition: all 0.15s;
}

.section-toggle button.active {
  background: var(--accent);
  color: #000;
  border-color: var(--accent);
  font-weight: 600;
}

.section-toggle button:hover:not(.active) { border-color: var(--accent); color: var(--text); }

.btn-run {
  width: 100%;
  padding: 0.85rem;
  background: var(--accent);
  color: #000;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s;
  letter-spacing: 0.02em;
  margin-top: 0.5rem;
}

.btn-run:hover { background: var(--accent-hover); transform: translateY(-1px); }
.btn-run:active { transform: translateY(0); }
.btn-run:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-secondary {
  width: 100%;
  padding: 0.7rem;
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  margin-top: 0.5rem;
}

.btn-secondary:hover { background: rgba(0,212,170,0.1); }

.right-panel { display: flex; flex-direction: column; gap: 1.5rem; }

.results-placeholder {
  text-align: center;
  padding: 4rem 2rem;
  color: var(--text-dim);
}

.results-placeholder .icon { font-size: 3rem; margin-bottom: 1rem; opacity: 0.3; }
.results-placeholder h3 { font-size: 1.1rem; margin-bottom: 0.5rem; color: var(--text); }
.results-placeholder p { font-size: 0.9rem; }

.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem;
}

.stat-box {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1rem;
  text-align: center;
}

.stat-box .stat-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  margin-bottom: 0.3rem;
}

.stat-box .stat-value {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text);
}

.stat-box .stat-value.success { color: var(--success); }
.stat-box .stat-value.danger { color: var(--danger); }
.stat-box .stat-value.accent { color: var(--accent); }

.chart-container {
  position: relative;
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.chart-container canvas {
  width: 100%;
  height: 420px;
  display: block;
}

.chart-legend {
  display: flex;
  justify-content: center;
  gap: 1.5rem;
  padding: 0.75rem;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}

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

.legend-swatch {
  width: 14px;
  height: 10px;
  border-radius: 2px;
}

.percentile-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.percentile-table th,
.percentile-table td {
  padding: 0.5rem 0.75rem;
  text-align: right;
  border-bottom: 1px solid var(--border);
}

.percentile-table th { color: var(--text-dim); font-weight: 500; font-size: 0.75rem; text-transform: uppercase; }
.percentile-table th:first-child, .percentile-table td:first-child { text-align: left; }
.percentile-table tr:hover td { background: var(--bg-input); }

.comparison-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.comparison-table th,
.comparison-table td {
  padding: 0.6rem 0.75rem;
  text-align: right;
  border-bottom: 1px solid var(--border);
}

.comparison-table th { color: var(--text-dim); font-weight: 500; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; }
.comparison-table th:first-child, .comparison-table td:first-child { text-align: left; }
.comparison-table tr:hover td { background: var(--bg-input); }

.comparison-table .highlight { color: var(--accent); font-weight: 600; }

.tab-bar {
  display: flex;
  gap: 0;
  margin-bottom: 1.25rem;
  border-bottom: 2px solid var(--border);
}

.tab-bar button {
  padding: 0.6rem 1.2rem;
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 500;
  transition: all 0.15s;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
}

.tab-bar button.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-bar button:hover:not(.active) { color: var(--text); }

.tab-content { display: none; }
.tab-content.active { display: block; }

.hidden { display: none !important; }

.loading-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 100;
  justify-content: center;
  align-items: center;
}

.loading-overlay.active { display: flex; }

.loading-card {
  background: var(--bg-card);
  padding: 2rem 3rem;
  border-radius: var(--radius);
  text-align: center;
  box-shadow: var(--shadow);
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 1rem;
}

@keyframes spin { to { transform: rotate(360deg); } }

.error-banner {
  background: rgba(255,71,87,0.1);
  border: 1px solid var(--danger);
  color: var(--danger);
  padding: 0.75rem 1rem;
  border-radius: 6px;
  font-size: 0.85rem;
  margin-bottom: 1rem;
}

.curl-hint {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1rem;
  margin-top: 1rem;
  font-size: 0.8rem;
  color: var(--text-dim);
}

.curl-hint code {
  display: block;
  margin-top: 0.5rem;
  padding: 0.75rem;
  background: #000;
  border-radius: 4px;
  color: var(--accent);
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  font-size: 0.75rem;
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 120px;
  overflow-y: auto;
}

.collapse-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  padding: 0.5rem 0;
  user-select: none;
}

.collapse-header:hover { color: var(--accent); }
.collapse-arrow { transition: transform 0.15s; font-size: 0.7rem; }
.collapse-header.open .collapse-arrow { transform: rotate(90deg); }
.collapse-body { display: none; padding-top: 0.5rem; }
.collapse-body.open { display: block; }

.info-link {
  display: inline-block;
  width: 16px;
  height: 16px;
  line-height: 16px;
  text-align: center;
  font-size: 0.65rem;
  font-weight: 700;
  background: var(--accent);
  color: #000;
  border-radius: 50%;
  text-decoration: none;
  margin-left: 0.4rem;
  vertical-align: middle;
}

.info-link:hover { background: var(--accent-hover); }

.strategy-desc {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.75rem;
  font-size: 0.82rem;
  color: var(--text-dim);
  line-height: 1.5;
  margin-bottom: 0.75rem;
}

.form-group input[title],
.form-group select[title] {
  cursor: help;
}

[data-theme="light"] .strategy-desc { color: #555; }

.bs-heading {
  font-size: 0.9rem;
  margin: 0.5rem 0 0.75rem;
  color: var(--danger);
}

.btn-optimize {
  background: transparent;
  border-color: var(--warning) !important;
  color: var(--warning) !important;
}
.btn-optimize:hover { background: rgba(255,165,2,0.1) !important; }

.opt-block {
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}
.opt-block:last-child { border-bottom: none; margin-bottom: 0; }
.opt-block h3 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 0.5rem;
}
.opt-recommendation {
  font-size: 1.1rem;
  margin-bottom: 0.5rem;
}
.opt-recommendation strong { color: var(--accent); }
.opt-detail {
  font-size: 0.85rem;
  color: var(--text-dim);
  margin-bottom: 0.25rem;
}

.opt-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
  margin-top: 0.75rem;
}
.opt-table th, .opt-table td {
  padding: 0.4rem 0.6rem;
  text-align: right;
  border-bottom: 1px solid var(--border);
}
.opt-table th { color: var(--text-dim); font-weight: 500; font-size: 0.72rem; text-transform: uppercase; }
.opt-table th:first-child, .opt-table td:first-child { text-align: left; }
.opt-table tr:hover td { background: var(--bg-input); }
.opt-table .highlight { color: var(--accent); font-weight: 600; }

.btn-sm {
  padding: 0.3rem 0.7rem;
  font-size: 0.78rem;
}
.btn-danger { border-color: var(--danger) !important; color: var(--danger) !important; }
.btn-danger:hover { background: rgba(255,71,87,0.1) !important; }

.preset-select {
  flex: 1;
  padding: 0.3rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-input);
  color: var(--text);
  font-size: 0.82rem;
}
