:root {
  --bg: #f5f5f7;
  --card: #ffffff;
  --text: #1d1d1f;
  --text-secondary: #6e6e73;
  --row: #f5f5f7;
  --border: rgba(0, 0, 0, 0.08);
  --accent: #007aff;
  --accent-hover: #0066d6;
  --danger: #ff3b30;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.06), 0 1px 3px rgba(0, 0, 0, 0.04);
  --radius-lg: 20px;
  --radius-md: 12px;
  --radius-sm: 8px;
}

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

html, body {
  min-height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text",
    "Helvetica Neue", Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 24px 20px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.site-footer {
  margin-top: 18px;
  font-size: 12px;
  color: var(--text-secondary);
  text-align: center;
  letter-spacing: 0.01em;
  padding: 4px 0 8px;
}

.card {
  background: var(--card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 28px 32px 32px;
  max-width: 1240px;
  width: 100%;
}

.chart-title {
  font-family: "New York", ui-serif, "Iowan Old Style", "Apple Garamond",
    Georgia, Cambria, "Times New Roman", Times, serif;
  font-size: 30px;
  font-weight: 600;
  letter-spacing: -0.01em;
  text-align: center;
  outline: none;
  padding: 4px 14px;
  border-radius: var(--radius-sm);
  transition: background 0.15s ease;
  margin: 0 auto 4px;
  min-height: 44px;
  cursor: text;
  display: inline-block;
  align-self: center;
  max-width: 100%;
}
.chart-title:hover {
  background: rgba(0, 0, 0, 0.03);
}
.chart-title:focus {
  background: rgba(0, 122, 255, 0.08);
}

.layout {
  display: grid;
  grid-template-columns: 180px minmax(0, 1fr) 300px;
  gap: 32px;
  align-items: stretch;
}
@media (max-width: 1100px) {
  .layout {
    grid-template-columns: 160px minmax(0, 1fr) 280px;
    gap: 24px;
  }
}
@media (max-width: 880px) {
  .layout {
    grid-template-columns: 1fr;
    gap: 0;
  }
  .card {
    padding: 20px;
  }
}

.tabs-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
  border-right: 1px solid var(--border);
  padding-right: 24px;
  min-width: 0;
  min-height: 0;
}
.tabs {
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-y: auto;
  flex: 1 1 auto;
  min-height: 0;
  padding-right: 4px;
  margin-right: -4px;
}
.tabs::-webkit-scrollbar {
  width: 6px;
}
.tabs::-webkit-scrollbar-track {
  background: transparent;
}
.tabs::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.15);
  border-radius: 3px;
}
.tab {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 10px;
  background: transparent;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.12s ease, border-color 0.12s ease, box-shadow 0.12s ease;
  min-width: 0;
  width: 100%;
  font-family: inherit;
  text-align: left;
  position: relative;
}
.tab:hover {
  background: rgba(0, 0, 0, 0.04);
}
.tab.active {
  background: rgba(0, 0, 0, 0.07);
}
.tab.active .tab-name {
  font-weight: 600;
}
.tab.untouched {
  opacity: 0.55;
}
.tab.untouched.active {
  opacity: 1;
}
.tab-thumb {
  width: 22px;
  height: 22px;
  flex: 0 0 auto;
  display: block;
}
.tab-name {
  font-size: 13px;
  font-weight: 500;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1 1 auto;
  min-width: 0;
  color: var(--text);
}
.tab-remove {
  width: 18px;
  height: 18px;
  border: none;
  background: transparent;
  border-radius: 4px;
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 400;
  line-height: 1;
  flex: 0 0 auto;
  opacity: 0;
  transition: opacity 0.15s, background 0.12s, color 0.12s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: inherit;
}
.tab:hover .tab-remove,
.tab-remove:focus-visible {
  opacity: 1;
}
.tab-remove:hover {
  background: rgba(255, 59, 48, 0.12);
  color: var(--danger);
}
.tab-remove:disabled {
  display: none;
}

.chart-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 0;
}
.chart-wrap {
  width: 100%;
}
#chart {
  width: 100%;
  height: auto;
  display: block;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

.controls {
  display: flex;
  flex-direction: column;
  gap: 16px;
  border-left: 1px solid var(--border);
  padding-left: 24px;
}

@media (max-width: 880px) {
  .tabs-panel {
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding-right: 0;
    padding-bottom: 20px;
    margin-bottom: 20px;
  }
  .tabs {
    max-height: 220px;
  }
  .controls {
    border-left: none;
    border-top: 1px solid var(--border);
    padding-left: 0;
    padding-top: 20px;
    margin-top: 20px;
  }
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

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

.value-row {
  display: grid;
  grid-template-columns: 1fr auto auto auto auto;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  background: var(--row);
  border-radius: var(--radius-md);
}
.value-row .name {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  letter-spacing: -0.01em;
  outline: none;
  padding: 3px 6px;
  margin: -3px -6px;
  border-radius: 6px;
  cursor: text;
  transition: background 0.12s ease, box-shadow 0.12s ease;
  min-width: 30px;
  overflow-wrap: anywhere;
}
.value-row .name:hover {
  background: rgba(0, 0, 0, 0.05);
}
.value-row .name:focus {
  background: white;
  box-shadow: 0 0 0 2px rgba(0, 122, 255, 0.35);
}
.value-row .name:empty::before {
  content: attr(data-placeholder);
  color: var(--text-secondary);
  opacity: 0.6;
}
.value-row .val {
  font-size: 15px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  min-width: 30px;
  text-align: center;
  color: var(--text);
}

.stepper {
  width: 26px;
  height: 26px;
  border: none;
  background: rgba(0, 0, 0, 0.06);
  border-radius: var(--radius-sm);
  font-size: 16px;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.12s ease, transform 0.05s ease;
  font-family: inherit;
  line-height: 1;
}
.stepper:hover {
  background: rgba(0, 0, 0, 0.1);
}
.stepper:active {
  transform: scale(0.94);
}
.stepper:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.remove-btn {
  width: 22px;
  height: 22px;
  border: none;
  background: transparent;
  border-radius: 6px;
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 16px;
  font-weight: 400;
  line-height: 1;
  opacity: 0;
  transition: opacity 0.15s, background 0.12s, color 0.12s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: inherit;
}
.value-row:hover .remove-btn,
.remove-btn:focus-visible {
  opacity: 1;
}
.remove-btn:hover {
  background: rgba(255, 59, 48, 0.12);
  color: var(--danger);
}
.remove-btn:disabled {
  opacity: 0;
  pointer-events: none;
}

.btn-add {
  align-self: stretch;
  margin-top: 2px;
}

.color-row {
  background: var(--row);
  border-radius: var(--radius-md);
  padding: 12px;
}
.row-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.swatch-group {
  display: flex;
  align-items: center;
  gap: 0;
  flex-wrap: nowrap;
}
.swatches {
  display: flex;
  flex-wrap: nowrap;
  gap: 6px;
  align-items: center;
}
.swatch {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
  padding: 0;
  flex: 0 0 auto;
}
.swatch:hover {
  transform: scale(1.15);
}
.swatch.selected {
  box-shadow: 0 0 0 2px white, 0 0 0 3px var(--text);
}
.swatch-divider {
  width: 1px;
  height: 16px;
  background: rgba(0, 0, 0, 0.12);
  margin: 0 8px;
  flex: 0 0 auto;
}
.swatch-custom {
  width: 22px;
  height: 22px;
  border: none;
  padding: 0;
  background: none;
  cursor: pointer;
  border-radius: 50%;
  flex: 0 0 auto;
  overflow: hidden;
  appearance: none;
  -webkit-appearance: none;
}
.swatch-custom::-webkit-color-swatch-wrapper {
  padding: 0;
  border-radius: 50%;
}
.swatch-custom::-webkit-color-swatch {
  border: none;
  border-radius: 50%;
  background: conic-gradient(
    from 0deg,
    #ff3b30, #ff9500, #ffcc00, #34c759, #30b0c7, #007aff, #5856d6, #af52de, #ff2d55, #ff3b30
  );
}
.swatch-custom::-moz-color-swatch {
  border: none;
  border-radius: 50%;
  background: conic-gradient(
    from 0deg,
    #ff3b30, #ff9500, #ffcc00, #34c759, #30b0c7, #007aff, #5856d6, #af52de, #ff2d55, #ff3b30
  );
}
.swatch-custom:hover {
  transform: scale(1.15);
}

.settings-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  background: var(--row);
  border-radius: var(--radius-md);
}
.settings-controls {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.btn-primary {
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius-md);
  padding: 12px 16px;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  letter-spacing: -0.01em;
  transition: background 0.15s ease, transform 0.06s ease;
}
.btn-primary:hover {
  background: var(--accent-hover);
}
.btn-primary:active {
  transform: scale(0.985);
}

.btn-secondary {
  background: rgba(0, 0, 0, 0.05);
  color: var(--text);
  border: none;
  border-radius: var(--radius-md);
  padding: 9px 12px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  letter-spacing: -0.01em;
  transition: background 0.12s ease, transform 0.05s ease;
}
.btn-secondary:hover {
  background: rgba(0, 0, 0, 0.09);
}
.btn-secondary:active {
  transform: scale(0.985);
}
.btn-secondary:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.handle-hit {
  fill: transparent;
  cursor: grab;
}
.handle-hit:active {
  cursor: grabbing;
}
.handle-dot {
  pointer-events: none;
}
