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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #0f0f0f;
  color: #e0e0e0;
  min-height: 100vh;
  padding: 2rem 1rem;
}

.container {
  max-width: 720px;
  margin: 0 auto;
}

h1 {
  font-size: 1.8rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.subtitle {
  color: #888;
  margin-bottom: 2rem;
  font-size: 0.95rem;
}

.section {
  margin-bottom: 1.5rem;
}

.section-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #888;
  margin-bottom: 0.5rem;
}

.toggle-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.toggle-btn {
  background: #1a1a1a;
  border: 1px solid #333;
  color: #aaa;
  padding: 0.45rem 0.85rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
  transition: all 0.15s;
}

.toggle-btn:hover { border-color: #555; color: #ddd; }

.toggle-btn.active {
  background: #1e3a5f;
  border-color: #3b82f6;
  color: #fff;
}

.badge {
  font-size: 0.7rem;
  color: #888;
  margin-left: 0.3rem;
}

.toggle-btn.active .badge { color: #93c5fd; }

.hsk-controls {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.status-bar {
  margin-top: 0.5rem;
  font-size: 0.8rem;
  color: #666;
  min-height: 1.2em;
}

.status-bar.loading { color: #f59e0b; }
.status-bar.ready { color: #22c55e; }
.status-bar.error { color: #ef4444; }

.options-row {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  flex-wrap: wrap;
}

.slider-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: #aaa;
}

.slider-group label { white-space: nowrap; }

.slider-group input[type="range"] {
  width: 120px;
  accent-color: #3b82f6;
}

textarea {
  width: 100%;
  background: #1a1a1a;
  border: 1px solid #333;
  color: #e0e0e0;
  padding: 0.75rem;
  border-radius: 8px;
  font-size: 1rem;
  font-family: inherit;
  resize: vertical;
  line-height: 1.6;
}

textarea:focus { outline: none; border-color: #3b82f6; }

.actions {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.btn {
  padding: 0.6rem 1.5rem;
  border-radius: 8px;
  border: none;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}

.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-primary {
  background: #3b82f6;
  color: #fff;
}
.btn-primary:hover:not(:disabled) { background: #2563eb; }

.btn-secondary {
  background: #2a2a2a;
  color: #ccc;
  border: 1px solid #444;
}
.btn-danger {
  background: #7f1d1d;
  color: #fca5a5;
  border: 1px solid #991b1b;
}
.btn-danger:hover:not(:disabled) { background: #991b1b; }

.output-box {
  background: #1a1a1a;
  border: 1px solid #333;
  border-radius: 8px;
  padding: 0.75rem;
  min-height: 80px;
  font-size: 1rem;
  line-height: 1.8;
  white-space: pre-wrap;
}

/* Streaming cursor */
.output-box.streaming::after {
  content: '▊';
  animation: blink 0.7s infinite;
  color: #3b82f6;
}

@keyframes blink { 50% { opacity: 0; } }

/* Loading overlay */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: #0f0f0f;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  color: #888;
  font-size: 0.95rem;
  z-index: 100;
}

.loading-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid #333;
  border-top-color: #3b82f6;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* WebGPU warning */
.warning-box {
  background: #2d1b00;
  border: 1px solid #f59e0b;
  color: #fbbf24;
  padding: 0.75rem;
  border-radius: 8px;
  font-size: 0.9rem;
  margin-top: 1rem;
}

/* Divider */
.divider {
  border: none;
  border-top: 1px solid #2a2a2a;
  margin: 2rem 0 1.5rem;
}

.section-title {
  font-size: 1.3rem;
  font-weight: 600;
  margin-bottom: 1rem;
}

/* Analyzer layout */
.analyzer-layout {
  display: flex;
  gap: 1.5rem;
  margin-top: 1rem;
}

.analyzer-left { flex: 1; min-width: 0; }

.analyzer-right {
  width: 240px;
  flex-shrink: 0;
  background: #1a1a1a;
  border: 1px solid #333;
  border-radius: 8px;
  padding: 1rem;
  position: sticky;
  top: 1rem;
  align-self: flex-start;
  min-height: 150px;
}

.word-detail-placeholder {
  color: #555;
  font-size: 0.85rem;
  text-align: center;
  padding-top: 2rem;
}

.word-detail-hanzi {
  font-size: 2.5rem;
  text-align: center;
  margin-bottom: 0.5rem;
  text-decoration: none;
}
.word-detail-hanzi.hsk-l1 { color: #4ade80; }
.word-detail-hanzi.hsk-l2 { color: #22d3ee; }
.word-detail-hanzi.hsk-l3 { color: #60a5fa; }
.word-detail-hanzi.hsk-l4 { color: #a78bfa; }
.word-detail-hanzi.hsk-l5 { color: #f472b6; }
.word-detail-hanzi.hsk-l6 { color: #fb923c; }
.word-detail-hanzi.hsk-l7 { color: #f87171; }

.word-detail-pinyin {
  font-size: 1rem;
  color: #93c5fd;
  text-align: center;
  margin-bottom: 0.5rem;
}

.word-detail-english {
  font-size: 0.85rem;
  color: #ccc;
  line-height: 1.5;
}

.word-detail-level {
  font-size: 0.75rem;
  color: #888;
  text-align: center;
  margin-top: 0.75rem;
  padding-top: 0.5rem;
  border-top: 1px solid #333;
}

/* HSK color-coded words */
.analyzer-words {
  line-height: 2.2;
  cursor: default;
}

.hsk-word {
  padding: 0.15rem 0.1rem;
  cursor: pointer;
  transition: background 0.1s;
  color: #e0e0e0;
  text-decoration: underline;
  text-decoration-thickness: 2px;
  text-underline-offset: 3px;
}

.hsk-word:hover {
  filter: brightness(1.3);
  outline: 1px solid rgba(255,255,255,0.3);
}

/* HSK level colors — applied as underline */
.hsk-l1 { text-decoration-color: #4ade80; }
.hsk-l2 { text-decoration-color: #22d3ee; }
.hsk-l3 { text-decoration-color: #60a5fa; }
.hsk-l4 { text-decoration-color: #a78bfa; }
.hsk-l5 { text-decoration-color: #f472b6; }
.hsk-l6 { text-decoration-color: #fb923c; }
.hsk-l7 { text-decoration-color: #f87171; }
.hsk-unknown { text-decoration-color: #d4a017; }

/* Character breakdown in detail panel */
.char-breakdown {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin: 0.5rem 0;
}
.char-breakdown-item {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  font-size: 0.85rem;
}
.char-breakdown-hanzi {
  font-size: 1.3rem;
  min-width: 1.5em;
  text-decoration: none;
}
.char-breakdown-hanzi.hsk-l1 { color: #4ade80; }
.char-breakdown-hanzi.hsk-l2 { color: #22d3ee; }
.char-breakdown-hanzi.hsk-l3 { color: #60a5fa; }
.char-breakdown-hanzi.hsk-l4 { color: #a78bfa; }
.char-breakdown-hanzi.hsk-l5 { color: #f472b6; }
.char-breakdown-hanzi.hsk-l6 { color: #fb923c; }
.char-breakdown-hanzi.hsk-l7 { color: #f87171; }
.char-breakdown-pinyin {
  color: #aaa;
  min-width: 4em;
}
.char-breakdown-english {
  color: #ccc;
}

/* Legend */
.hsk-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 0.75rem;
  font-size: 0.75rem;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}

@media (max-width: 640px) {
  .analyzer-layout { flex-direction: column; }
  .analyzer-right { width: 100%; position: static; }
}
