:root {
  --bg: #f5f5f7;
  --card: rgba(255, 255, 255, 0.78);
  --text: #1d1d1f;
  --muted: #6e6e73;
  --line: rgba(0, 0, 0, 0.08);
  --accent: #0071e3;
  --accent-dark: #005bb5;
  --record: #ff3b30;
  --ok: #34c759;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background:
    radial-gradient(circle at 50% 0%, rgba(255, 255, 255, 0.96), transparent 42%),
    linear-gradient(180deg, #fbfbfd 0%, var(--bg) 100%);
}

button, select, textarea { font: inherit; }

.app-shell {
  width: min(1120px, calc(100vw - 40px));
  margin: 0 auto;
  padding: 72px 0 56px;
  display: grid;
  gap: 34px;
}

.hero { text-align: center; }

.eyebrow {
  margin: 0 0 14px;
  color: var(--accent);
  font-size: 14px;
  font-weight: 750;
}

h1 {
  max-width: 860px;
  margin: 0 auto;
  font-size: clamp(42px, 7vw, 76px);
  line-height: 1.04;
  letter-spacing: -0.035em;
}

.intro {
  max-width: 760px;
  margin: 22px auto 0;
  color: var(--muted);
  font-size: 19px;
  line-height: 1.7;
}

.practice-card {
  padding: clamp(22px, 4vw, 42px);
  border: 1px solid var(--line);
  border-radius: 30px;
  background: var(--card);
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.08);
  backdrop-filter: blur(24px);
}

.toolbar {
  display: flex;
  align-items: end;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.field {
  display: grid;
  gap: 8px;
  min-width: 220px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

select, textarea {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255,255,255,.82);
  color: var(--text);
  outline: none;
}

select {
  min-height: 48px;
  padding: 0 16px;
}

textarea {
  width: 100%;
  margin-top: 16px;
  padding: 16px;
  resize: vertical;
  line-height: 1.6;
}

.dialog-panel, .answer-panel {
  padding: clamp(22px, 3vw, 34px);
  border: 1px solid var(--line);
  border-radius: 24px;
  background: rgba(255,255,255,.72);
}

.dialog-panel {
  min-height: 210px;
}

.answer-panel {
  margin-top: 14px;
  background: rgba(248,248,250,.78);
}

.panel-label, .feedback-card span {
  display: block;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.panel-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.panel-title-row .panel-label,
.panel-title-row span {
  margin-bottom: 0;
}

#promptText {
  margin: 0;
  font-size: clamp(24px, 3vw, 34px);
  line-height: 1.35;
  letter-spacing: -0.02em;
}

.translation, #transcriptText {
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 16px;
  line-height: 1.7;
}

.controls {
  margin-top: 24px;
  display: flex;
  align-items: center;
  gap: 18px;
}

.control-copy {
  flex: 1;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}

.manual-label {
  display: block;
  margin: 18px 0 -8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.primary-button, .secondary-button {
  min-height: 48px;
  padding: 0 22px;
  border: 0;
  border-radius: 999px;
  color: #fff;
  background: var(--accent);
  font-weight: 760;
  cursor: pointer;
  box-shadow: 0 14px 30px rgba(0, 113, 227, 0.2);
}

.primary-button:hover, .secondary-button:hover { background: var(--accent-dark); }
.secondary-button { margin-top: 14px; }
.button-row .secondary-button { margin-top: 0; }
.secondary-button.ghost {
  color: var(--accent);
  background: #fff;
  border: 1px solid var(--line);
  box-shadow: none;
}

.secondary-button:disabled,
.primary-button:disabled {
  opacity: .45;
  cursor: not-allowed;
  box-shadow: none;
}

.submit-wide {
  width: 100%;
}

.text-button {
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--accent);
  cursor: pointer;
}

.mic-button {
  width: 76px;
  height: 76px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: #fff;
  cursor: pointer;
  display: grid;
  place-items: center;
  box-shadow: 0 16px 38px rgba(0, 0, 0, 0.11);
  transition: transform .22s ease, background .22s ease, box-shadow .22s ease;
}

.mic-button:hover { transform: translateY(-2px); }

.mic-button.is-recording {
  background: var(--record);
  box-shadow: 0 0 0 10px rgba(255, 59, 48, 0.12), 0 18px 44px rgba(255, 59, 48, 0.25);
  animation: pulse 1.25s ease-in-out infinite;
}

.mic-icon {
  position: relative;
  width: 18px;
  height: 30px;
  border: 3px solid var(--text);
  border-radius: 12px;
}

.mic-icon::before {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -12px;
  width: 28px;
  height: 17px;
  border: 3px solid var(--text);
  border-top: 0;
  border-radius: 0 0 16px 16px;
  transform: translateX(-50%);
}

.mic-icon::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -22px;
  width: 3px;
  height: 12px;
  border-radius: 99px;
  background: var(--text);
  transform: translateX(-50%);
}

.mic-button.is-recording .mic-icon,
.mic-button.is-recording .mic-icon::before { border-color: #fff; }
.mic-button.is-recording .mic-icon::after { background: #fff; }

.status-text {
  margin: 0;
  color: var(--text);
  font-size: 16px;
  font-weight: 700;
}

.hint-text {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.feedback-grid {
  margin-top: 24px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.feedback-card {
  min-height: 150px;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: rgba(255,255,255,.74);
}

.feedback-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.75;
}

.feedback-card.wide { grid-column: 1 / -1; }

.metric-list {
  display: grid;
  gap: 8px;
}

.metric-list p {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
}

.metric-list b {
  color: var(--ok);
  font-size: 22px;
}

.small-note {
  margin-top: 14px !important;
  font-size: 13px;
}

.score-card strong {
  display: block;
  margin-bottom: 8px;
  color: var(--ok);
  font-size: 52px;
  line-height: 1;
}

.coach-panel {
  margin-top: 24px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: rgba(248,248,250,.78);
}

.coach-panel h2 {
  margin: 0;
  font-size: 24px;
  letter-spacing: 0;
}

.coach-messages {
  min-height: 118px;
  max-height: 280px;
  overflow: auto;
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255,255,255,.7);
}

.empty-message {
  margin: 0;
  color: var(--muted);
  line-height: 1.7;
}

.coach-message {
  width: fit-content;
  max-width: min(720px, 100%);
  padding: 12px 14px;
  border-radius: 16px;
  line-height: 1.65;
}

.coach-message.user {
  justify-self: end;
  color: #fff;
  background: var(--accent);
}

.coach-message.assistant {
  justify-self: start;
  color: var(--text);
  background: #fff;
  border: 1px solid var(--line);
}

.coach-input-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: end;
  gap: 12px;
  margin-top: 12px;
}

.coach-input-row textarea {
  margin-top: 0;
}

@keyframes pulse { 50% { transform: scale(1.04); } }

@media (max-width: 760px) {
  .app-shell {
    width: min(100% - 24px, 1120px);
    padding: 38px 0;
  }

  .toolbar, .controls { align-items: stretch; }
  .field, .primary-button { width: 100%; }
  .feedback-grid { grid-template-columns: 1fr; }
  .panel-title-row { align-items: flex-start; }
  .coach-input-row { grid-template-columns: 1fr; }
}

/* ---- word-level score chips ---- */
.word-detail {
  margin: 8px 0 0;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}
.word-label {
  font-size: 12px;
  color: var(--muted);
  margin-right: 4px;
}
.word-chip {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  cursor: default;
}
