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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #f5f5f7;
  color: #1d1d1f;
  line-height: 1.6;
}

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

header { text-align: center; padding: 40px 0 32px; }
header h1 { font-size: 32px; font-weight: 700; }
.subtitle { color: #86868b; margin-top: 8px; font-size: 16px; }

/* API Key */
.api-key-section { text-align: right; margin-bottom: 16px; }
.btn-text { background: none; border: none; color: #86868b; cursor: pointer; font-size: 14px; padding: 4px 8px; }
.btn-text:hover { color: #1d1d1f; }
#apiKeyPanel {
  background: white; border-radius: 12px; padding: 16px; margin-top: 8px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}
#apiKeyPanel.hidden { display: none; }
.api-info {
  background: #f0f7ff; border-radius: 8px; padding: 12px 16px; margin-bottom: 12px;
  font-size: 13px; color: #515154; line-height: 1.7;
}
.api-info a { color: #0071e3; }
.api-input-row {
  display: flex; align-items: center; gap: 10px;
}
.api-input-row label { font-size: 14px; color: #86868b; white-space: nowrap; }
.api-input-row input { flex: 1; padding: 8px 12px; border: 1px solid #d2d2d7; border-radius: 8px; font-size: 14px; }
#apiStatus { font-size: 13px; color: #34c759; }

/* Input Section */
.input-section { background: white; border-radius: 16px; padding: 24px; box-shadow: 0 1px 4px rgba(0,0,0,0.06); }
.input-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 10px; gap: 12px; }
.input-header label { font-size: 15px; font-weight: 600; white-space: nowrap; padding-top: 6px; }
.header-right { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.sample-select {
  padding: 6px 10px; border: 1px solid #d2d2d7; border-radius: 8px;
  font-size: 13px; background: white; cursor: pointer; color: #515154;
}

.mode-switch { display: flex; gap: 4px; background: #e8e8ed; border-radius: 8px; padding: 3px; }
.mode-btn { border: none; background: none; border-radius: 6px; padding: 6px 14px; font-size: 13px; cursor: pointer; color: #86868b; font-weight: 500; transition: all 0.2s; }
.mode-btn.active { background: white; color: #1d1d1f; box-shadow: 0 1px 2px rgba(0,0,0,0.08); }

textarea {
  width: 100%; min-height: 220px; padding: 16px;
  border: 1px solid #d2d2d7; border-radius: 12px;
  font-size: 15px; font-family: inherit; resize: vertical; line-height: 1.6;
}
textarea:focus { outline: none; border-color: #0071e3; box-shadow: 0 0 0 3px rgba(0,113,227,0.1); }

/* Intensity Slider (QuillBot style) */
.intensity-row { margin: 12px 0 0; }
.intensity-row.hidden { display: none; }
.intensity-label { font-size: 13px; font-weight: 600; color: #515154; display: block; margin-bottom: 6px; }
.intensity-row input[type="range"] {
  width: 100%; -webkit-appearance: none; appearance: none;
  height: 6px; border-radius: 3px; background: linear-gradient(to right, #e8e8ed 0%, #0071e3 50%, #0071e3 100%);
  outline: none;
}
.intensity-row input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 22px; height: 22px; border-radius: 50%; background: white;
  border: 2px solid #0071e3; cursor: pointer; box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}
.intensity-ticks {
  display: flex; justify-content: space-between; font-size: 11px; color: #a1a1a6;
  margin-top: 4px; padding: 0 2px;
}

.controls { display: flex; justify-content: space-between; align-items: center; margin-top: 12px; }
#charCount { font-size: 13px; color: #86868b; }

/* Buttons */
.btn-primary {
  background: #0071e3; color: white; border: none; border-radius: 10px;
  padding: 10px 24px; font-size: 15px; font-weight: 600; cursor: pointer; transition: background 0.2s;
}
.btn-primary:hover { background: #0077ed; }
.btn-primary:disabled { background: #a1c9f5; cursor: not-allowed; }
.btn-sm { padding: 6px 16px; font-size: 13px; }
.btn-outline {
  background: white; color: #0071e3; border: 2px solid #0071e3; border-radius: 10px;
  padding: 10px 24px; font-size: 15px; font-weight: 600; cursor: pointer;
  transition: all 0.2s;
}
.btn-outline:hover { background: #0071e3; color: white; }

/* Loading */
#loading { text-align: center; padding: 40px; color: #86868b; }
#loading.hidden { display: none; }
.loading-detail { font-size: 13px; color: #a1a1a6; margin-top: 4px; }

.spinner {
  width: 32px; height: 32px; border: 3px solid #e8e8ed; border-top-color: #0071e3;
  border-radius: 50%; animation: spin 0.8s linear infinite; margin: 0 auto 12px;
}
@keyframes spin { to { transform: rotate(360deg); } }

#error { background: #fff2f0; border: 1px solid #ffccc7; color: #cf1322; border-radius: 12px; padding: 16px; margin-top: 16px; }
#error.hidden { display: none; }

#result { margin-top: 24px; }
#result.hidden { display: none; }

/* Stats */
.stats-row { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; margin-bottom: 16px; }
.stat-card {
  background: white; border-radius: 12px; padding: 16px 8px; text-align: center;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}
.stat-value { font-size: 24px; font-weight: 700; color: #0071e3; }
.stat-label { font-size: 12px; color: #86868b; margin-top: 2px; }

/* Hemingway Style Card */
.hemingway-card { padding: 20px 24px; }
.hemingway-card h3 { font-size: 16px; margin-bottom: 14px; }
.hemingway-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; }
.hem-item {
  text-align: center; padding: 14px 8px; border-radius: 10px; background: #f9f9fb;
}
.hem-dot {
  width: 12px; height: 12px; border-radius: 50%; margin: 0 auto 8px;
}
.hem-dot.passive { background: #34c759; }
.hem-dot.hard { background: #ffcc02; }
.hem-dot.very-hard { background: #ff3b30; }
.hem-dot.adverb { background: #007aff; }
.hem-dot.complex { background: #af52de; }
.hem-val { display: block; font-size: 22px; font-weight: 700; color: #1d1d1f; }
.hem-label { display: block; font-size: 11px; color: #86868b; margin-top: 2px; }

/* Hemingway Legend */
.hem-legend {
  display: flex; gap: 16px; flex-wrap: wrap; margin-bottom: 12px;
  padding: 10px 14px; background: #f5f5f7; border-radius: 8px;
}
.legend-item { font-size: 12px; color: #515154; display: flex; align-items: center; gap: 6px; }
.leg-dot {
  width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0;
}
.leg-dot.passive { background: #34c759; }
.leg-dot.hard { background: #ffcc02; }
.leg-dot.very-hard { background: #ff3b30; }
.leg-dot.adverb { background: #007aff; }
.leg-dot.complex { background: #af52de; }

/* Text Stats */
.text-stats-card { padding: 16px 20px; }
.text-stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 12px; }
.text-stat { text-align: center; }
.ts-val { display: block; font-size: 20px; font-weight: 700; color: #1d1d1f; }
.ts-label { display: block; font-size: 12px; color: #86868b; margin-top: 2px; }

/* Corrections */
.correction-item {
  background: white; border-radius: 12px; padding: 20px; margin-bottom: 12px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}
.correction-item .error-header {
  display: flex; align-items: center; gap: 10px; margin-bottom: 12px;
}
.correction-item .error-num {
  display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 26px; background: #cf1322; color: white;
  border-radius: 50%; font-size: 12px; font-weight: 700; flex-shrink: 0;
}
.correction-item .error-type {
  font-size: 12px; padding: 2px 10px; border-radius: 12px; font-weight: 500;
}
.error-type.grammar { background: #fff2f0; color: #cf1322; }
.error-type.spelling { background: #fff7e6; color: #d46b08; }
.error-type.style { background: #e6f7ff; color: #0071e3; }
.error-type.punctuation { background: #f9f0ff; color: #722ed1; }

.correction-item .wrong {
  color: #cf1322; text-decoration: line-through; font-size: 15px; margin-bottom: 6px;
  padding: 6px 10px; background: #fff2f0; border-radius: 6px;
}
.correction-item .right {
  color: #2e7d32; font-weight: 500; font-size: 15px; margin-bottom: 6px;
  padding: 6px 10px; background: #f0fdf4; border-radius: 6px;
}
.correction-item .explain {
  font-size: 13px; color: #86868b; background: #f5f5f7; border-radius: 8px; padding: 10px 14px; margin-top: 8px;
  line-height: 1.5;
}

.card {
  background: white; border-radius: 12px; padding: 24px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
  margin-bottom: 16px;
}
.card h3 { font-size: 18px; margin-bottom: 12px; }

/* Corrected text with Hemingway highlighting */
#correctedText {
  background: #1d1d1f; color: #f5f5f7; padding: 20px; border-radius: 10px;
  font-size: 14px; line-height: 1.8; white-space: pre-wrap;
  font-family: 'SF Mono', 'Monaco', 'Menlo', monospace;
}
#correctedText .hem-passive { background: rgba(52,199,89,0.25); border-bottom: 2px solid #34c759; padding: 1px 0; }
#correctedText .hem-hard { background: rgba(255,204,2,0.25); border-bottom: 2px solid #ffcc02; padding: 1px 0; }
#correctedText .hem-very-hard { background: rgba(255,59,48,0.25); border-bottom: 2px solid #ff3b30; padding: 1px 0; }
#correctedText .hem-adverb { background: rgba(0,122,255,0.2); border-bottom: 2px solid #007aff; padding: 1px 0; }
#correctedText .hem-complex { background: rgba(175,82,222,0.2); border-bottom: 2px solid #af52de; padding: 1px 0; }

@media (max-width: 768px) {
  .stats-row { grid-template-columns: repeat(3, 1fr); }
  .hemingway-grid { grid-template-columns: repeat(3, 1fr); }
  .input-header { flex-direction: column; }
  .header-right { width: 100%; }
  .text-stats { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 600px) {
  .container { padding: 12px; }
  header { padding: 20px 0; }
  header h1 { font-size: 24px; }
  .header-right { flex-direction: column; align-items: stretch; }
  .stats-row { grid-template-columns: repeat(2, 1fr); }
  .hemingway-grid { grid-template-columns: repeat(2, 1fr); }
}
