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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "微软雅黑", sans-serif;
  background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
  min-height: 100vh;
  padding: 20px;
}

.container {
  max-width: 700px;
  margin: 0 auto;
  background: white;
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

header {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: 30px 20px;
  text-align: center;
}

header h1 {
  font-size: 28px;
  margin-bottom: 12px;
  font-weight: 600;
}

.stats {
  display: flex;
  justify-content: center;
  gap: 20px;
  font-size: 14px;
  opacity: 0.9;
}

main {
  flex: 1;
  padding: 30px 20px;
}

.search-box {
  margin-bottom: 20px;
}

.search-box input {
  width: 100%;
  padding: 12px;
  border: 2px solid #e0e0e0;
  border-radius: 8px;
  font-size: 16px;
  transition: border-color 0.3s;
}

.search-box input:focus {
  outline: none;
  border-color: #667eea;
}

.text-select {
  width: 100%;
  padding: 12px;
  border: 2px solid #e0e0e0;
  border-radius: 8px;
  font-size: 16px;
  margin-bottom: 20px;
  cursor: pointer;
  transition: border-color 0.3s;
}

.text-select:focus {
  outline: none;
  border-color: #667eea;
}

.progress-bar {
  width: 100%;
  height: 6px;
  background: #e0e0e0;
  border-radius: 3px;
  margin-bottom: 8px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
  width: 0%;
  transition: width 0.3s ease;
}

.progress-text {
  font-size: 14px;
  color: #666;
  margin-bottom: 20px;
  text-align: center;
}

.hint-display {
  font-size: 24px;
  letter-spacing: 3px;
  color: #667eea;
  text-align: center;
  margin: 20px 0;
  min-height: 32px;
  font-weight: 600;
}

.compare-display {
  background: #f9f9f9;
  padding: 15px;
  border-radius: 8px;
  margin: 20px 0;
  font-size: 16px;
  line-height: 1.8;
  min-height: 40px;
}

.compare-display .error {
  color: #e74c3c;
  font-weight: 600;
}

.input-area {
  margin: 20px 0;
}

.input-area input {
  width: 100%;
  padding: 14px;
  border: 2px solid #e0e0e0;
  border-radius: 8px;
  font-size: 16px;
  transition: border-color 0.3s;
}

.input-area input:focus {
  outline: none;
  border-color: #667eea;
}

.button-group {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 20px 0;
}

.btn {
  padding: 12px;
  border: none;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s;
}

.btn-primary {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  grid-column: 1 / 3;
}

.btn-primary:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.btn-secondary {
  background: #f0f0f0;
  color: #333;
  border: 2px solid #e0e0e0;
}

.btn-secondary:hover:not(:disabled) {
  background: #e8e8e8;
}

.btn-warning {
  background: #f39c12;
  color: white;
}

.btn-warning:hover:not(:disabled) {
  background: #e67e22;
}

.btn-warning:disabled {
  background: #ccc;
  cursor: not-allowed;
}

.btn-danger {
  background: #e74c3c;
  color: white;
  font-size: 14px;
}

.btn-danger:hover:not(:disabled) {
  background: #c0392b;
}

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

.result-display {
  background: #f0f8ff;
  padding: 20px;
  border-radius: 8px;
  margin: 20px 0;
  text-align: center;
  min-height: 40px;
  font-size: 16px;
  line-height: 1.6;
}

.result-display.success {
  background: #d4edda;
  color: #155724;
}

.result-display.error {
  background: #f8d7da;
  color: #721c24;
}

footer {
  background: #f5f5f5;
  padding: 20px;
  text-align: center;
  font-size: 14px;
  color: #666;
  border-top: 1px solid #e0e0e0;
}

footer a {
  color: #667eea;
  text-decoration: none;
}

footer a:hover {
  text-decoration: underline;
}

footer .shortcuts {
  font-size: 12px;
  color: #999;
  margin-top: 8px;
}

@media (max-width: 600px) {
  header h1 {
    font-size: 24px;
  }

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

  main {
    padding: 20px 15px;
  }

  .button-group {
    grid-template-columns: 1fr 1fr;
  }

  .btn-primary {
    grid-column: 1 / 3;
  }
}

/* 弹窗样式 */
.modal {
  display: none;
  position: fixed;
  z-index: 1000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  overflow: auto;
  background-color: rgba(0,0,0,0.5);
  backdrop-filter: blur(4px);
}

.modal.active {
  display: block;
  animation: fadeIn 0.3s ease-out;
}

.modal-content {
  background-color: var(--bg-color);
  margin: 10% auto;
  padding: 24px;
  border-radius: 12px;
  width: 90%;
  max-width: 500px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.15);
  position: relative;
  animation: slideIn 0.3s ease-out;
}

.close-btn {
  color: var(--text-color);
  float: right;
  font-size: 28px;
  font-weight: bold;
  cursor: pointer;
  line-height: 1;
  transition: color 0.2s;
}

.close-btn:hover {
  color: var(--primary-color);
}

.modal h2 {
  margin-top: 0;
  margin-bottom: 20px;
  font-size: 20px;
  color: var(--primary-color);
  text-align: center;
}

.stats-summary {
  display: flex;
  justify-content: space-around;
  margin-bottom: 20px;
  padding: 15px;
  background-color: rgba(74, 144, 226, 0.1);
  border-radius: 8px;
}

.stats-item {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.stats-number {
  font-size: 24px;
  font-weight: bold;
  color: var(--primary-color);
}

.stats-label {
  font-size: 12px;
  color: var(--text-light);
  margin-top: 4px;
}

.stats-table {
  width: 100%;
  border-collapse: collapse;
}

.stats-row {
  display: flex;
  padding: 10px 0;
  border-bottom: 1px solid rgba(0,0,0,0.05);
}

.stats-header {
  font-weight: bold;
  color: var(--text-light);
  border-bottom: 2px solid rgba(0,0,0,0.1);
}

.stats-rank { width: 40px; text-align: center; }
.stats-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stats-count { width: 60px; text-align: center; }
.stats-rate { width: 80px; text-align: right; }

.btn-info {
  background-color: #00bcd4;
  grid-column: 1 / 3;
}

.btn-info:hover {
  background-color: #0097a7;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideIn {
  from { transform: translateY(-20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* 适配暗黑模式 */
@media (prefers-color-scheme: dark) {
  .stats-row { border-bottom-color: rgba(255,255,255,0.05); }
  .stats-header { border-bottom-color: rgba(255,255,255,0.1); }
}

/* 句子选择弹窗 */
.context-display {
  font-size: 14px;
  line-height: 2;
  color: #999;
  margin: 12px 0;
  padding: 10px 14px;
  background: #fafafa;
  border-radius: 8px;
  max-height: 120px;
  overflow-y: auto;
}

.context-display span {
  display: inline;
}

.ctx-done {
  color: #27ae60;
}

.ctx-skipped {
  color: #bbb;
}

.ctx-current {
  color: #667eea;
  font-weight: 600;
}

.picker-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 13px;
  border-radius: 6px;
}

.picker-from-label {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  color: #666;
  margin-left: auto;
}

.picker-from-input {
  width: 50px;
  padding: 4px 6px;
  border: 1px solid #e0e0e0;
  border-radius: 4px;
  font-size: 13px;
  text-align: center;
}

.sentence-list {
  max-height: 400px;
  overflow-y: auto;
}

.sentence-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 14px;
  border: 2px solid #e0e0e0;
  border-radius: 8px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: all 0.2s;
  font-size: 15px;
  line-height: 1.6;
}

.sentence-item:hover {
  border-color: #667eea;
  background: rgba(102, 126, 234, 0.05);
}

.sentence-item.active {
  border-color: #667eea;
  background: rgba(102, 126, 234, 0.1);
}

.sentence-item.active .sentence-number {
  background: #667eea;
  color: white;
}

.sentence-item input[type="checkbox"] {
  flex-shrink: 0;
  margin-top: 4px;
  width: 16px;
  height: 16px;
  cursor: pointer;
  accent-color: #667eea;
}

.sentence-number {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #f0f0f0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  color: #666;
}

.sentence-text {
  flex: 1;
  word-break: break-all;
}

/* 手写输入区域 */
.handwriting-section {
  margin: 16px 0;
  padding: 16px;
  background: #fafafa;
  border: 2px solid #e0e0e0;
  border-radius: 12px;
  animation: slideIn 0.2s ease-out;
}

.handwriting-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.handwriting-title {
  font-size: 14px;
  font-weight: 600;
  color: #667eea;
}

.handwriting-toolbar {
  display: flex;
  gap: 6px;
}

#handwritingCanvas {
  width: 100%;
  height: 200px;
  border: 2px solid #e0e0e0;
  border-radius: 8px;
  background: white;
  cursor: crosshair;
  touch-action: none;
  display: block;
}

.handwriting-status {
  font-size: 13px;
  color: #999;
  margin-top: 6px;
  min-height: 20px;
  text-align: center;
}

.handwriting-section.active #handwritingCanvas {
  border-color: #667eea;
}

.handwriting-section.recognizing #handwritingCanvas {
  opacity: 0.6;
  pointer-events: none;
}

/* 语音输入状态 */
.voice-status {
  margin: 12px 0;
  padding: 10px 16px;
  background: #fafafa;
  border: 2px solid #e0e0e0;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  animation: slideIn 0.2s ease-out;
}

.voice-indicator {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #e74c3c;
  animation: pulse 1s ease-in-out infinite;
}

.voice-status span:last-child {
  font-size: 14px;
  color: #666;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(1.3); }
}

@media (max-width: 600px) {
  .handwriting-header {
    flex-direction: column;
    gap: 8px;
    align-items: stretch;
  }

  .handwriting-toolbar {
    justify-content: center;
  }

  #handwritingCanvas {
    height: 160px;
  }

  .handwriting-section {
    padding: 12px;
  }
}
