/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --text: #1a1d2e;
  --text-secondary: #5f6580;
  --primary: #4f5bd5;
  --primary-hover: #3d49c2;
  --accent: #0ea47a;
  --accent-hover: #0c8d68;
  --border: #e2e5f1;
  --shadow: 0 2px 16px rgba(30, 35, 70, 0.07);
  --shadow-lg: 0 8px 32px rgba(30, 35, 70, 0.10);
  --radius: 14px;
  --radius-sm: 8px;
  --font: 'Segoe UI', 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --transition: 0.2s ease;
  --warning: #e8a317;
  --warning-bg: #fef9e7;
  --danger: #d94052;
  --record-pulse: #d94052;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

/* ===== App Container ===== */
.app-container {
  max-width: 980px;
  margin: 0 auto;
  padding: 24px 16px 48px;
}

/* ===== Header ===== */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 28px;
  gap: 16px;
  flex-wrap: wrap;
}

.app-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 1.55rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--primary);
}

.title-icon {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
}

.app-subtitle {
  color: var(--text-secondary);
  font-size: 0.92rem;
  margin-top: 4px;
}

.lang-selector {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  font-size: 0.78rem;
  color: var(--text-secondary);
}

.lang-selector select {
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: 0.85rem;
  color: var(--text);
  cursor: pointer;
  outline: none;
  transition: border var(--transition);
}

.lang-selector select:focus { border-color: var(--primary); }

/* ===== Cards ===== */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px;
  margin-bottom: 20px;
}

/* ===== Input Grid ===== */
.input-grid {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 24px;
  align-items: start;
}

.input-block h3 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 4px;
}

.hint {
  font-size: 0.78rem;
  color: var(--text-secondary);
  margin-bottom: 14px;
}

.or-divider {
  display: flex;
  align-items: center;
  justify-content: center;
  padding-top: 48px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-secondary);
}

/* ===== Upload ===== */
.upload-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 18px 16px;
  cursor: pointer;
  transition: all var(--transition);
  color: var(--text-secondary);
  font-size: 0.88rem;
  text-align: center;
}

.upload-area:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: rgba(79, 91, 213, 0.03);
}

.upload-area.has-file {
  border-color: var(--accent);
  color: var(--accent);
  border-style: solid;
}

.upload-area.drag-over {
  border-color: var(--primary);
  background: rgba(79, 91, 213, 0.06);
  color: var(--primary);
}

/* ===== Player ===== */
.player-wrap {
  margin-top: 12px;
}

.player-wrap audio { display: none; }

.custom-player {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
}

.play-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  flex-shrink: 0;
  transition: background var(--transition);
}

.play-btn:hover { background: var(--primary-hover); }

.seek-bar {
  flex: 1;
  height: 4px;
  -webkit-appearance: none;
  appearance: none;
  background: var(--border);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}

.seek-bar::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--primary);
  cursor: pointer;
  border: 2px solid #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}

.seek-bar::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--primary);
  cursor: pointer;
  border: 2px solid #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}

.time-display {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-secondary);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  min-width: 80px;
  text-align: right;
}

/* ===== Record Button ===== */
.btn-record {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 14px 28px;
  border: none;
  border-radius: 50px;
  background: var(--text);
  color: #fff;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  width: 100%;
  justify-content: center;
}

.btn-record:hover { background: #2d3148; transform: translateY(-1px); }

.btn-record.recording {
  background: var(--record-pulse);
  animation: pulse-record 1.4s ease-in-out infinite;
}

.btn-record.has-recording {
  background: var(--text-secondary);
}

@keyframes pulse-record {
  0%, 100% { box-shadow: 0 0 0 0 rgba(217, 64, 82, 0.4); }
  50% { box-shadow: 0 0 0 12px rgba(217, 64, 82, 0); }
}

.record-timer {
  text-align: center;
  margin-top: 10px;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--record-pulse);
  font-variant-numeric: tabular-nums;
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 28px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  width: 100%;
}

.btn-primary, .btn-accent {
  width: 60%;
  margin-left: auto;
  margin-right: auto;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none !important;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover:not(:disabled) { background: var(--primary-hover); transform: translateY(-1px); }

.btn-accent {
  background: var(--accent);
  color: #fff;
  margin-top: 16px;
  display: flex;
}

.btn-accent:hover:not(:disabled) { background: var(--accent-hover); transform: translateY(-1px); }

/* ===== Spinner ===== */
.spinner {
  width: 18px; height: 18px;
  border: 2.5px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

/* ===== Transcribe Button Wrap ===== */
.transcribe-wrap {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  text-align: center;
}

/* ===== Transcript ===== */
.transcription-section { text-align: left; }

.field-label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.transcript-box {
  display: block;
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px;
  font-size: 0.95rem;
  font-family: var(--font);
  line-height: 1.7;
  min-height: 100px;
  margin-bottom: 18px;
  resize: vertical;
  outline: none;
  transition: border var(--transition);
}

.transcript-box:focus { border-color: var(--primary); }

/* Word Count */
.word-count-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
  margin-top: -10px;
}

.word-count {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}

.word-count-hint {
  font-size: 0.8rem;
  color: var(--warning);
  transition: opacity var(--transition);
}

.word-count-hint.hidden {
  opacity: 0;
  pointer-events: none;
}

/* Options Row: WPM + Feedback Language side by side */
.options-row {
  display: flex;
  gap: 24px;
  align-items: flex-end;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.option-group {
  flex: 0 0 auto;
}

.wpm-input-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.wpm-formula {
  font-size: 0.8rem;
  color: var(--text-secondary);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.wpm-input {
  width: 120px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-weight: 600;
  text-align: center;
  outline: none;
  transition: border var(--transition);
}

.wpm-input:focus { border-color: var(--primary); }

.manual-wpm-hint {
  font-size: 0.8rem;
  color: #d32f2f;
  transition: opacity var(--transition);
}

.manual-wpm-hint.hidden {
  opacity: 0;
  pointer-events: none;
}

.feedback-select {
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.92rem;
  outline: none;
  background: var(--surface);
  cursor: pointer;
  transition: border var(--transition);
}

.feedback-select:focus { border-color: var(--primary); }

.btn-sample {
  padding: 10px 16px;
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--transition);
  width: auto;
}

.btn-sample:hover {
  background: var(--bg);
  color: var(--text);
  border-color: var(--text-secondary);
}

/* ===== Results ===== */
.results-section h2 {
  font-size: 1.3rem;
  margin-bottom: 20px;
  text-align: center;
}

.results-section h3 {
  font-size: 1.05rem;
  font-weight: 600;
  margin-bottom: 14px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--bg);
}

/* Warning */
.warning-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 18px;
  background: var(--warning-bg);
  border: 1px solid var(--warning);
  border-radius: var(--radius-sm);
  color: #8a6d00;
  font-size: 0.88rem;
  margin-bottom: 20px;
}

.warning-banner svg { flex-shrink: 0; color: var(--warning); }

/* Bonus note */
.bonus-note {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 18px;
  background: #eaf4fb;
  border-left: 4px solid #3a8abf;
  border-radius: 8px;
  color: #1a5276;
  font-size: 0.88rem;
  margin-bottom: 20px;
}

.bonus-note svg { flex-shrink: 0; color: #3a8abf; }

/* Score Display */
.score-display {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 28px;
}

.score-card {
  text-align: center;
  padding: 24px 16px;
  background: var(--bg);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.score-label {
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.score-value {
  display: block;
  font-size: 2.4rem;
  font-weight: 700;
  color: var(--primary);
}

.score-formula {
  display: block;
  font-size: 0.68rem;
  color: var(--text-secondary);
  margin-top: 6px;
  word-break: break-all;
}

.level-value {
  display: block;
  font-size: 2.4rem;
  font-weight: 700;
  color: var(--accent);
}

/* Chart */
.chart-section { margin-bottom: 28px; }

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

/* Corrections Table */
.corrections-section { margin-bottom: 28px; }

.table-wrap { overflow-x: auto; }

.corrections-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.9rem;
}

.corrections-table th {
  text-align: left;
  padding: 12px 14px;
  background: var(--bg);
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--text-secondary);
  border-bottom: 2px solid var(--border);
}

.corrections-table th:first-child { border-radius: var(--radius-sm) 0 0 0; }
.corrections-table th:last-child { border-radius: 0 var(--radius-sm) 0 0; }

.corrections-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.corrections-table tr:last-child td { border-bottom: none; }

.corrections-table td:first-child,
.corrections-table td:nth-child(2) { font-weight: 500; }

.diff-del {
  background: #fde8e8;
  color: #b91c1c;
  text-decoration: line-through;
  padding: 1px 3px;
  border-radius: 3px;
}

.diff-ins {
  background: #d1fae5;
  color: #065f46;
  padding: 1px 3px;
  border-radius: 3px;
}

.no-corrections {
  text-align: center;
  color: var(--accent);
  font-weight: 500;
  padding: 16px;
}

/* Improved & Comment */
.improved-section, .comment-section { margin-bottom: 28px; }

.improved-box, .comment-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 18px;
  font-size: 0.95rem;
  line-height: 1.75;
}

.improved-box { color: var(--accent); font-weight: 500; }

.level-info-link {
  display: block;
  margin-top: 8px;
  font-size: 0.72rem;
  color: var(--text-secondary);
  text-decoration: none;
  transition: color var(--transition);
}

.level-info-link:hover {
  color: var(--primary);
  text-decoration: underline;
}

/* Usage Display */
.usage-group {
  margin-left: auto;
}

.usage-display {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-secondary);
  white-space: nowrap;
  padding: 10px 0;
}

.usage-display.over-limit {
  color: var(--danger);
}

/* ===== Reset Button ===== */
.reset-wrap {
  text-align: center;
  margin-top: 8px;
  margin-bottom: 24px;
}

.btn-reset {
  width: 30%;
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  font-size: 0.85rem;
}

.btn-reset:hover {
  background: var(--bg);
  color: var(--text);
  border-color: var(--text-secondary);
}

/* ===== About Section ===== */
.about-section {
  font-size: 0.95rem;
  color: var(--text-secondary);
  line-height: 1.65;
  margin-bottom: 20px;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.about-section a {
  color: var(--primary);
  text-decoration: none;
  font-weight: 600;
}

.about-section a:hover {
  text-decoration: underline;
}

.about-contact {
  margin-top: 6px;
  font-size: 0.88rem;
  color: var(--text-secondary);
  opacity: 0.8;
}

/* ===== Version History ===== */
.version-history {
  margin-top: 16px;
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.version-history summary {
  cursor: pointer;
  font-weight: 500;
  opacity: 0.7;
  transition: opacity var(--transition);
  list-style: none;
}

.version-history summary::before {
  content: "\25B6\00a0";
  font-size: 0.6rem;
  vertical-align: middle;
}

.version-history[open] summary::before {
  content: "\25BC\00a0";
}

.version-history summary:hover {
  opacity: 1;
}

.version-history ul {
  margin-top: 6px;
  padding-left: 18px;
  list-style: disc;
}

.version-history li {
  padding: 2px 0;
}

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--text);
  color: #fff;
  padding: 12px 24px;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  z-index: 999;
  opacity: 0;
  transition: all 0.35s ease;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast.error { background: var(--danger); }

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .app-container { padding: 16px 12px 32px; }
  .app-header { flex-direction: column; align-items: flex-start; }
  .lang-selector { align-items: flex-start; }
  .app-title { font-size: 1.25rem; }
  .input-grid { grid-template-columns: 1fr; }
  .or-divider { padding: 8px 0; }
  .card { padding: 20px 16px; }
}

@media (max-width: 480px) {
  .app-container { padding: 12px 8px 24px; }
  .app-title { font-size: 1.1rem; }
  .card { padding: 16px 12px; }
  .score-display { grid-template-columns: 1fr; }
  .score-value, .level-value { font-size: 1.8rem; }
  .options-row { flex-direction: column; gap: 12px; }
  .wpm-input { width: 100%; }
  .feedback-select { width: 100%; }
  .upload-area { padding: 20px 12px; }
}

/* ===== Fade-in animation ===== */
.fade-in {
  animation: fadeIn 0.4s ease forwards;
}

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