/* Code Rainbow - Apple-style clean design */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --accent: #1976D2;
  --accent-light: #E3F2FD;
  --text-primary: #1d1d1f;
  --text-secondary: #86868b;
  --text-tertiary: #aeaeb2;
  --bg-primary: #ffffff;
  --bg-secondary: #f5f5f7;
  --bg-hover: #e8e8ed;
  --border: #d2d2d7;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
  --shadow-lg: 0 8px 30px rgba(0,0,0,0.12);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --font-mono: 'SF Mono', 'Menlo', 'Monaco', 'Courier New', monospace;
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

body {
  font-family: var(--font-sans);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 40px 24px 60px;
}

/* Header */
.header {
  text-align: center;
  padding-bottom: 40px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 40px;
}

.header h1 {
  font-size: 40px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.subtitle {
  font-size: 18px;
  color: var(--text-secondary);
  font-weight: 400;
}

.nav-links {
  margin-top: 16px;
}

.nav-links a {
  color: var(--accent);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  transition: opacity 0.2s;
}

.nav-links a:hover {
  opacity: 0.7;
}

/* Input Section */
.input-section {
  margin-bottom: 32px;
}

.textarea-wrapper {
  margin-bottom: 16px;
}

#codeInput {
  width: 100%;
  min-height: 200px;
  max-height: 400px;
  padding: 16px;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.6;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-secondary);
  color: var(--text-primary);
  resize: vertical;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

#codeInput:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(25, 118, 210, 0.15);
}

#codeInput::placeholder {
  color: var(--text-tertiary);
}

.actions {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 16px;
}

.btn-primary, .btn-secondary {
  padding: 10px 24px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-primary {
  background: var(--accent);
  color: white;
}

.btn-primary:hover {
  background: #1565C0;
  box-shadow: var(--shadow-sm);
}

.btn-primary:disabled {
  background: #90CAF9;
  cursor: not-allowed;
}

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

.btn-secondary:hover {
  background: var(--bg-hover);
}

.examples {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.example-label {
  font-size: 13px;
  color: var(--text-secondary);
}

.example-btn {
  padding: 4px 12px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--bg-primary);
  color: var(--accent);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s;
}

.example-btn:hover {
  background: var(--accent-light);
  border-color: var(--accent);
}

/* Result Section */
.result-section {
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.result-meta {
  display: flex;
  gap: 16px;
  align-items: center;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.badge {
  display: inline-block;
  padding: 4px 12px;
  background: var(--accent-light);
  color: var(--accent);
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
}

.meta-text {
  font-size: 14px;
  color: var(--text-secondary);
}

/* Spectrum */
.spectrum-container {
  background: var(--bg-secondary);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin-bottom: 24px;
  box-shadow: var(--shadow-sm);
}

.legend {
  margin-bottom: 16px;
}

.legend-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 8px;
  display: block;
}

.legend-items {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  color: var(--text-secondary);
  background: var(--bg-primary);
  border: 1px solid var(--border);
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  flex-shrink: 0;
}

.canvas-wrapper {
  width: 100%;
  overflow-x: auto;
}

#rainbowCanvas {
  display: block;
  width: 100%;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

/* Detail Panel */
.detail-panel {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 24px;
  box-shadow: var(--shadow-sm);
  animation: fadeIn 0.2s ease;
}

.detail-header {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.detail-line {
  font-weight: 600;
  font-size: 14px;
}

.detail-category {
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
}

.detail-complexity {
  font-size: 12px;
  color: var(--text-secondary);
}

.detail-code {
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-all;
  background: var(--bg-secondary);
  padding: 12px;
  border-radius: var(--radius-sm);
  overflow-x: auto;
}

/* Stats */
.stats-section {
  margin-top: 24px;
}

.stats-section h3 {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 16px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 8px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--bg-secondary);
  border-radius: var(--radius-sm);
  padding: 12px;
  text-align: center;
}

.stat-value {
  font-size: 24px;
  font-weight: 700;
  display: block;
}

.stat-label {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 2px;
}

.distribution-wrapper {
  background: var(--bg-secondary);
  border-radius: var(--radius-lg);
  padding: 20px;
}

#distributionChart {
  display: block;
  width: 100%;
  height: 180px;
}

/* Footer */
.footer {
  text-align: center;
  padding-top: 60px;
  color: var(--text-tertiary);
  font-size: 13px;
}

/* Loading spinner */
.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  margin-right: 8px;
  vertical-align: middle;
}

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

.btn-primary.loading {
  display: flex;
  align-items: center;
}

/* Responsive */
@media (max-width: 640px) {
  .header h1 { font-size: 28px; }
  .container { padding: 24px 16px 40px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}

/* Error state */
.error-message {
  background: #FFF0F0;
  border: 1px solid #FFCCCC;
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  color: #CC3333;
  font-size: 14px;
  margin-bottom: 16px;
}
