/* ---- reset ---- */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: #f5f5f4;
  color: #1c1917;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

/* ---- header ---- */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 48px;
  padding: 0 20px;
  background: #fff;
  border-bottom: 1px solid #e7e5e4;
  flex-shrink: 0;
}

.logo {
  font-weight: 700;
  font-size: 15px;
  color: #1c1917;
  letter-spacing: -0.02em;
}

.nav { display: flex; gap: 2px; }

.nav-item {
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 500;
  color: #78716c;
  background: none;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s;
}

.nav-item:hover { color: #1c1917; background: #f5f5f4; }
.nav-item.active { color: #1c1917; background: #f5f5f4; }

.header-right { display: flex; align-items: center; gap: 8px; }

.header-select {
  font-size: 12px;
  font-family: inherit;
  padding: 4px 8px;
  border: 1px solid #d6d3d1;
  border-radius: 6px;
  background: #fff;
  color: #44403c;
  outline: none;
  cursor: pointer;
}

.header-select:focus { border-color: #3b82f6; }

.mic-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 500;
  color: #78716c;
  background: none;
  border: 1px solid #d6d3d1;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s;
}

.mic-btn:hover { border-color: #a8a29e; }
.mic-btn.active { color: #15803d; border-color: #86efac; }

.mic-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: #d6d3d1;
  transition: background 0.2s;
}

.mic-dot.active { background: #22c55e; }

.mic-select {
  font-size: 12px;
  padding: 4px 6px;
  border: 1px solid #d6d3d1;
  border-radius: 6px;
  background: #fff;
  color: #44403c;
  max-width: 180px;
}

.mic-select:disabled { opacity: 0.4; }

/* ---- layout pages ---- */
.page {
  flex: 1;
  min-height: 0;
  padding: 16px 20px;
  gap: 16px;
}

.tab-content { display: none; }
.tab-content.active { display: flex; }

/* ---- sidebar (aba 1) ---- */
.sidebar {
  width: 280px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.section {
  background: #fff;
  border: 1px solid #e7e5e4;
  border-radius: 8px;
  padding: 14px 16px;
}

.section h3 {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #a8a29e;
  margin-bottom: 10px;
}

/* ---- forms ---- */
label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: #57534e;
  margin-bottom: 4px;
  margin-top: 8px;
}

label:first-of-type { margin-top: 0; }

input[type="text"], select {
  width: 100%;
  padding: 7px 10px;
  font-size: 13px;
  font-family: inherit;
  background: #fafaf9;
  border: 1px solid #d6d3d1;
  border-radius: 6px;
  color: #1c1917;
  outline: none;
  transition: border-color 0.15s;
}

input[type="text"]:focus, select:focus {
  border-color: #3b82f6;
  box-shadow: 0 0 0 2px rgba(59,130,246,0.1);
}

.field-row { display: flex; gap: 10px; }
.field-row > div { flex: 1; }

/* ---- record controls ---- */
.rec-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin: 4px 0 6px;
}

.rec-btn {
  width: 44px; height: 44px;
  border-radius: 50%;
  border: 2px solid #3b82f6;
  background: none;
  color: #3b82f6;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}

.rec-btn:hover { background: rgba(59,130,246,0.06); }
.rec-btn.recording { border-color: #ef4444; color: #ef4444; }
.rec-btn.recording:hover { background: rgba(239,68,68,0.06); }
.rec-btn.recording .icon-rec { display: none; }
.rec-btn.recording .icon-stop { display: block !important; }

.play-btn {
  width: 36px; height: 36px;
  border-radius: 50%;
  border: 1.5px solid #d6d3d1;
  background: none;
  color: #78716c;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}

.play-btn:hover:not(:disabled) { border-color: #a8a29e; color: #44403c; }
.play-btn:disabled { opacity: 0.3; cursor: default; }
.play-btn.playing { border-color: #eab308; color: #ca8a04; }

/* ---- audio player ---- */
.audio-player {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #fafaf9;
  border: 1px solid #e7e5e4;
  border-radius: 8px;
  padding: 8px 10px;
  margin-bottom: 10px;
}

.audio-player[hidden] { display: none !important; }

.player-play {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  border-radius: 50%;
  border: none;
  background: #3b82f6;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

.player-play:hover:not(:disabled) { background: #2563eb; }
.player-play:disabled { opacity: 0.35; cursor: default; }
.player-play.playing .icon-play { display: none; }
.player-play.playing .icon-pause { display: block !important; }

.player-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.player-seek {
  width: 100%;
  height: 4px;
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  cursor: pointer;
  margin: 0;
  padding: 0;
}

.player-seek:disabled { cursor: default; opacity: 0.4; }

.player-seek::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 2px;
  background: #e7e5e4;
}

.player-seek::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #3b82f6;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px #bfdbfe;
  margin-top: -4px;
  cursor: pointer;
}

.player-seek::-moz-range-track {
  height: 4px;
  border-radius: 2px;
  background: #e7e5e4;
}

.player-seek::-moz-range-thumb {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #3b82f6;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px #bfdbfe;
  cursor: pointer;
}

.player-times {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  color: #a8a29e;
  line-height: 1;
}

.rec-status {
  text-align: center;
  font-size: 12px;
  color: #a8a29e;
  min-height: 16px;
  margin-bottom: 6px;
}

.btn-primary {
  display: block;
  width: 100%;
  padding: 8px;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  color: #fff;
  background: #3b82f6;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-primary:hover { background: #2563eb; }
.btn-primary:disabled { opacity: 0.35; cursor: default; }

/* ---- loading ---- */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px;
  color: #a8a29e;
  font-size: 13px;
}

.spinner {
  width: 16px; height: 16px;
  border: 2px solid #e7e5e4;
  border-top: 2px solid #3b82f6;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

/* ---- content / results (aba 1) ---- */
.content {
  flex: 1;
  background: #fff;
  border: 1px solid #e7e5e4;
  border-radius: 8px;
  padding: 20px 24px;
  overflow-y: auto;
  display: none;
  align-self: flex-start;
  min-width: 0;
}

.result-top {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid #f5f5f4;
}

.score-circle {
  width: 64px; height: 64px;
  border-radius: 50%;
  border: 3px solid #e7e5e4;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 700;
  color: #1c1917;
  flex-shrink: 0;
}

.score-circle.sm {
  width: 48px; height: 48px;
  font-size: 15px;
}

.score-meta { flex: 1; }

.score-title {
  font-size: 12px;
  font-weight: 500;
  color: #78716c;
  display: block;
  margin-bottom: 6px;
}

.score-bar {
  height: 4px;
  background: #e7e5e4;
  border-radius: 2px;
  overflow: hidden;
}

.score-bar-fill {
  height: 100%;
  border-radius: 2px;
  transition: width 0.5s ease;
}

.ipa-row {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
}

.ipa-row.compact { margin-bottom: 12px; margin-top: 12px; }

.ipa-cell {
  flex: 1;
  background: #fafaf9;
  border: 1px solid #e7e5e4;
  border-radius: 6px;
  padding: 8px 10px;
}

.ipa-label {
  display: block;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #a8a29e;
  margin-bottom: 3px;
}

.ipa-cell code {
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 14px;
  color: #1c1917;
  word-break: break-all;
}

.phoneme-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 16px;
}

.ph {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 3px 6px;
  min-width: 28px;
  border-radius: 4px;
  border: 1px solid #e7e5e4;
  background: #fafaf9;
}

.ph.ok { border-color: #86efac; background: #f0fdf4; }
.ph.err { border-color: #fca5a5; background: #fef2f2; }

.ph .exp {
  font-size: 9px;
  color: #a8a29e;
  line-height: 1;
}

.ph .got {
  font-family: monospace;
  font-size: 13px;
  line-height: 1.3;
}

.ph.ok .got { color: #16a34a; }
.ph.err .got { color: #dc2626; }

.detail-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.detail-table td {
  padding: 6px 0;
  border-bottom: 1px solid #f5f5f4;
}

.detail-table tr:last-child td { border-bottom: none; }
.detail-table td:first-child { color: #78716c; width: 100px; }
.detail-table td:last-child { font-weight: 500; color: #1c1917; }

/* ---- activity (aba 2) ---- */
#tab-activity {
  flex-direction: column;
  overflow-y: auto;
}

.activity-setup {
  display: flex;
  justify-content: center;
  padding-top: 20px;
}

.setup-card {
  background: #fff;
  border: 1px solid #e7e5e4;
  border-radius: 8px;
  padding: 20px 24px;
  width: 560px;
  max-width: 100%;
}

.setup-card h3 {
  font-size: 15px;
  font-weight: 600;
  color: #1c1917;
  margin-bottom: 12px;
}

.board-header {
  text-align: center;
  margin-bottom: 16px;
}

.board-header h2 {
  font-size: 18px;
  font-weight: 700;
  color: #1c1917;
  margin-bottom: 4px;
}

.board-header p {
  font-size: 13px;
  color: #78716c;
}

.word-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.word-card {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #fff;
  border: 1px solid #e7e5e4;
  border-radius: 6px;
  padding: 6px 12px;
  transition: border-color 0.15s;
}

.word-card.score-high { border-color: #86efac; background: #f0fdf4; }
.word-card.score-mid { border-color: #fde68a; background: #fefce8; }
.word-card.score-low { border-color: #fca5a5; background: #fef2f2; }

.word-card .word-score {
  font-size: 11px;
  font-weight: 700;
}

.word-card.score-high .word-score { color: #16a34a; }
.word-card.score-mid .word-score { color: #ca8a04; }
.word-card.score-low .word-score { color: #dc2626; }

.btn-speak {
  width: 26px; height: 26px;
  border-radius: 4px;
  border: none;
  background: #f5f5f4;
  color: #78716c;
  font-size: 13px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  flex-shrink: 0;
}

.btn-speak:hover { background: #e7e5e4; color: #44403c; }

.word-text {
  font-size: 13px;
  font-weight: 600;
  color: #1c1917;
  letter-spacing: 0.08em;
  cursor: pointer;
  white-space: nowrap;
}

.word-text:hover { color: #3b82f6; }

.btn-word-mic {
  width: 24px; height: 24px;
  border-radius: 50%;
  border: 1.5px solid #3b82f6;
  background: none;
  color: #3b82f6;
  font-size: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s;
}

.btn-word-mic:hover { background: rgba(59,130,246,0.06); }

/* ---- modal ---- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal-panel {
  background: #fff;
  border: 1px solid #e7e5e4;
  border-radius: 10px;
  width: 380px;
  max-width: 92vw;
  max-height: 88vh;
  overflow-y: auto;
  box-shadow: 0 4px 24px rgba(0,0,0,0.08);
}

.modal-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid #e7e5e4;
}

.modal-top h3 {
  font-size: 16px;
  font-weight: 700;
  color: #1c1917;
  letter-spacing: 0.1em;
}

.close-btn {
  background: none;
  border: none;
  font-size: 20px;
  color: #a8a29e;
  cursor: pointer;
  line-height: 1;
}

.close-btn:hover { color: #44403c; }

.modal-content {
  padding: 18px 20px;
}

.modal-content .rec-controls {
  margin-bottom: 6px;
  padding: 8px 0;
}

.modal-content .rec-btn { width: 44px; height: 44px; }
.modal-content .play-btn { width: 34px; height: 34px; }
.modal-content .rec-status { margin-bottom: 8px; }
.modal-content .btn-primary { margin-top: 2px; }

#modalResult {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid #e7e5e4;
}

.modal-score-row {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 14px;
}

.modal-score-row > div:last-child { flex: 1; }

.modal-content .ipa-row { margin-bottom: 12px; }
.modal-content .phoneme-strip { margin-bottom: 0; }

/* ---- waveform ---- */
.waveform {
  width: 100%;
  display: block;
  border-radius: 4px;
  background: transparent;
  border: none;
  margin-bottom: 0;
  cursor: pointer;
}

.audio-player .waveform {
  height: 36px;
}

/* Live waveform durante gravação */
.live-wave {
  width: 100%;
  height: 40px;
  display: block;
  border-radius: 4px;
  background: #fafaf9;
  border: 1px solid #e7e5e4;
  margin-bottom: 8px;
  cursor: default;
}

/* ---- utilities ---- */
.hidden { display: none !important; }
