html {
  height: auto;
  min-height: 100%;
  overflow: auto;
}

body {
  height: auto;
  min-height: 100%;
  overflow: auto;
}

.speaking-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
  background: var(--bg);
}

.speaking-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 20px 28px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(12px);
}

.speaking-topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.back-link {
  display: inline-grid;
  place-items: center;
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-weight: 800;
  text-decoration: none;
  white-space: nowrap;
}

.back-link:hover {
  border-color: #b8c5cf;
  background: #f9fbfc;
}

.compact-setting {
  display: grid;
  grid-template-columns: auto minmax(180px, 260px);
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.user-setting {
  grid-template-columns: auto minmax(120px, 160px);
}

.speaking-main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(640px, 760px);
  min-height: 0;
  overflow: hidden;
}

.conversation-panel {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.conversation-messages {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  padding: 28px;
  scrollbar-gutter: stable;
}

.conversation-empty,
.conversation-message {
  max-width: min(760px, 94%);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px 16px;
  background: var(--surface);
  line-height: 1.58;
}

.conversation-empty {
  display: grid;
  gap: 6px;
  color: var(--muted);
}

.conversation-empty strong {
  color: var(--text);
}

.conversation-empty span {
  font-size: 13px;
}

.conversation-message {
  display: grid;
  gap: 8px;
}

.conversation-message.user {
  align-self: flex-end;
  border-color: #cde2dd;
  background: #eef5f3;
}

.conversation-message.assistant {
  align-self: flex-start;
}

.message-role {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.message-text {
  margin: 0;
  color: var(--text);
  font-size: 16px;
  line-height: 1.55;
  white-space: pre-wrap;
}

.coach-tip,
.correction-list,
.speech-status {
  padding: 10px 12px;
  border: 1px solid #d8d2ba;
  border-radius: 8px;
  background: #fffdf6;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.coach-tip strong,
.correction-list strong {
  color: var(--accent-2);
}

.speech-status {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  border-color: #cde2dd;
  background: #f6fbf9;
}

.speech-status span {
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  overflow-wrap: anywhere;
}

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

.correction-list ul {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.correction-list li {
  display: grid;
  gap: 3px;
}

.correction-list b {
  color: var(--text);
}

.speaking-recorder {
  display: grid;
  gap: 12px;
  padding: 18px 28px 24px;
  border-top: 1px solid var(--line);
  background: var(--surface);
}

.recorder-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.record-button {
  min-width: 136px;
  border-color: var(--accent);
  background: var(--accent);
  color: white;
  font-weight: 800;
}

.record-button.is-recording {
  border-color: var(--danger);
  background: var(--danger);
}

#stopButton,
#cancelRecordingButton,
#replayButton,
#summaryButton,
#clearSessionButton,
#refreshHistoryButton {
  min-width: 86px;
  font-weight: 700;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

.recording-meter {
  display: flex;
  gap: 5px;
  align-items: end;
  height: 28px;
}

.recording-meter span {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: #c5d1dc;
}

.turn-progress {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.turn-progress li {
  min-height: 32px;
  display: grid;
  place-items: center;
  border: 1px solid #d9e1e7;
  border-radius: 8px;
  background: #f9fbfc;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.turn-progress li.is-active {
  border-color: var(--accent);
  background: #eef5f3;
  color: var(--accent);
}

.turn-progress li.is-complete {
  border-color: #cde2dd;
  background: var(--accent);
  color: white;
}

.is-recording-page .recording-meter span {
  animation: speakingPulse 0.82s ease-in-out infinite;
  background: var(--danger);
}

.is-recording-page .recording-meter span:nth-child(2) {
  animation-delay: 0.12s;
}

.is-recording-page .recording-meter span:nth-child(3) {
  animation-delay: 0.24s;
}

@keyframes speakingPulse {
  0%,
  100% {
    height: 8px;
  }
  50% {
    height: 28px;
  }
}

#recorderHint {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.speaking-side {
  display: grid;
  align-content: start;
  gap: 16px;
  height: 100%;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  padding: 16px;
  border-left: 1px solid var(--line);
  background: #eef2f5;
  scrollbar-gutter: stable;
}

.speaking-side .panel {
  min-height: 168px;
}

.speaking-side .scenario-panel {
  min-height: 540px;
}

.speaking-side .panel-title {
  min-height: 56px;
  padding: 14px 16px;
}

.scenario-controls {
  display: grid;
  gap: 16px;
  padding: 22px;
}

.scenario-controls label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.scenario-controls select {
  min-height: 48px;
  font-size: 15px;
}

.guided-practice-card {
  display: grid;
  gap: 16px;
  margin-top: 10px;
  padding: 20px;
  border: 1px solid #cde2dd;
  border-radius: 8px;
  background: #f6fbf9;
}

.guided-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.guided-card-header span {
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.guided-card-header button {
  min-height: 38px;
  padding: 0 14px;
  font-size: 14px;
  font-weight: 800;
}

.guided-task,
.guided-support {
  margin: 0;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.55;
}

.guided-practice-card strong {
  color: var(--text);
  font-size: 24px;
  line-height: 1.45;
}

.guided-feedback {
  display: grid;
  gap: 5px;
  padding: 10px 12px;
  border: 1px solid #cde2dd;
  border-radius: 8px;
  background: #f6fbf9;
}

.guided-feedback span {
  color: var(--accent);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.guided-feedback strong {
  color: var(--text);
}

.guided-feedback p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.guided-library-action {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid #d8d2ba;
  border-radius: 8px;
  background: #fffdf6;
}

.guided-library-action button {
  min-height: 34px;
  padding: 0 12px;
  font-size: 13px;
  font-weight: 800;
}

.guided-library-action span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.transcript-box {
  min-height: 150px;
  padding: 18px;
}

.transcript-box p {
  color: var(--muted);
  line-height: 1.55;
  white-space: pre-wrap;
}

#turnData {
  min-height: 280px;
  padding: 16px;
}

.summary-content {
  display: grid;
  gap: 14px;
  min-height: 220px;
  padding: 18px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.summary-content p {
  margin: 0;
}

.summary-scores {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.summary-score {
  display: grid;
  gap: 4px;
  padding: 8px 10px;
  border: 1px solid #d9e1e7;
  border-radius: 8px;
  background: #f9fbfc;
}

.summary-score span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.summary-score strong {
  color: var(--accent);
  font-size: 20px;
  line-height: 1;
}

.summary-section {
  display: grid;
  gap: 6px;
}

.summary-section strong {
  color: var(--text);
}

.summary-section ul {
  display: grid;
  gap: 6px;
  margin: 0;
  padding-left: 18px;
}

.summary-section li {
  padding-left: 2px;
}

.summary-empty {
  color: var(--muted);
}

.history-content {
  display: grid;
  gap: 14px;
  min-height: 240px;
  padding: 18px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.history-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.history-stat {
  display: grid;
  gap: 4px;
  padding: 8px 10px;
  border: 1px solid #d9e1e7;
  border-radius: 8px;
  background: #f9fbfc;
}

.history-stat span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.history-stat strong {
  color: var(--accent);
  font-size: 18px;
  line-height: 1;
}

.history-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.history-item {
  display: grid;
  gap: 5px;
  padding: 10px 12px;
  border: 1px solid #d9e1e7;
  border-radius: 8px;
  background: var(--surface);
}

.history-item-header {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  color: var(--text);
  font-size: 12px;
  font-weight: 800;
}

.history-item p {
  margin: 0;
}

.history-item small {
  color: var(--muted);
}

.history-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.history-actions button {
  min-height: 30px;
  padding: 0 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 800;
}

.history-actions button[data-history-action="continue"] {
  border-color: var(--accent);
  background: var(--accent);
  color: white;
}

@media (max-width: 1180px) {
  .speaking-topbar,
  .speaking-topbar-actions {
    display: grid;
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .compact-setting,
  .user-setting {
    grid-template-columns: 1fr;
  }

  .speaking-main {
    grid-template-columns: 1fr;
    overflow: visible;
  }

  .speaking-shell {
    height: auto;
    min-height: 100vh;
    min-height: 100dvh;
    overflow: visible;
  }

  .conversation-panel {
    min-height: 70vh;
    overflow: visible;
  }

  .conversation-messages {
    max-height: none;
    overflow: visible;
  }

  .speaking-side {
    height: auto;
    overflow: visible;
    border-left: none;
    border-top: 1px solid var(--line);
  }
}

@media (max-width: 640px) {
  .conversation-messages,
  .speaking-recorder {
    padding-left: 16px;
    padding-right: 16px;
  }

  .conversation-empty,
  .conversation-message {
    max-width: 100%;
  }

  .recorder-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .record-button {
    grid-column: 1 / -1;
  }

  #summaryButton {
    grid-column: 1 / -1;
  }

  .turn-progress {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
