* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Arial, sans-serif;
  background: #f4f6f8;
  color: #222;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

.app {
  max-width: 720px;
  margin: 0 auto;
  padding: 24px;
}

.mic-warning {
  margin-bottom: 16px;
  padding: 14px 16px;
  border-radius: 14px;
  background: #b91c1c;
  color: #fff;
  font-weight: 700;
  text-align: center;
  letter-spacing: 0.02em;
  box-shadow: 0 8px 18px rgba(185, 28, 28, 0.24);
}

.mic-warning--ready {
  background: #15803d;
  box-shadow: 0 8px 18px rgba(21, 128, 61, 0.24);
}

.mic-warning--denied {
  background: #b91c1c;
  box-shadow: 0 8px 18px rgba(185, 28, 28, 0.24);
}

.mic-warning--missing {
  background: #c2410c;
  box-shadow: 0 8px 18px rgba(194, 65, 12, 0.24);
}

.mic-warning--unsupported,
.mic-warning--unavailable {
  background: #a16207;
  box-shadow: 0 8px 18px rgba(161, 98, 7, 0.24);
}

.game-actions {
  display: flex;
  gap: 12px;
  margin-top: 16px;
}

.game-actions button {
  margin-top: 0;
  flex: 1;
}

.card {
  background: white;
  border-radius: 16px;
  padding: 24px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
}

.home-summary {
  display: grid;
  gap: 10px;
  margin-top: 18px;
  padding: 16px;
  border-radius: 14px;
  background: #f8fafc;
  border: 1px solid #e5e7eb;
  font-size: 16px;
  line-height: 1.5;
}

.home-actions,
.settings-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 18px;
}

.settings-actions--top {
  margin-top: 14px;
  margin-bottom: 12px;
}

h1,
h2 {
  margin-top: 0;
  text-align: center;
}

label {
  display: block;
  margin-top: 16px;
  font-weight: bold;
}

input {
  width: 100%;
  padding: 12px;
  margin-top: 6px;
  font-size: 16px;
  border: 1px solid #ccc;
  border-radius: 8px;
}

.select-control {
  width: 100%;
  padding: 12px;
  margin-top: 6px;
  font-size: 16px;
  border: 1px solid #ccc;
  border-radius: 8px;
  background: #fff;
}

.operation-row {
  display: flex;
  gap: 12px;
  margin-top: 8px;
  flex-wrap: wrap;
}

.toggle-switch {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  padding: 14px 16px;
  margin-top: 0;
  font-weight: normal;
  border: 1px solid #d1d5db;
  border-radius: 14px;
  background: #fafafa;
  cursor: pointer;
  user-select: none;
}

.toggle-switch input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.toggle-name {
  font-weight: 700;
}

.toggle-track {
  position: relative;
  width: 54px;
  height: 30px;
  border-radius: 999px;
  background: #9ca3af;
  flex: 0 0 auto;
  transition: background-color 180ms ease;
}

.toggle-track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: white;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
  transition: transform 180ms ease;
}

.toggle-status {
  min-width: 34px;
  font-size: 14px;
  font-weight: 700;
  text-align: right;
  color: #6b7280;
}

.toggle-switch input:not(:checked) ~ .toggle-status .toggle-on {
  display: none;
}

.toggle-switch input:checked ~ .toggle-status .toggle-off {
  display: none;
}

.toggle-switch input:checked + .toggle-track {
  background: #16a34a;
}

.toggle-switch input:checked + .toggle-track::after {
  transform: translateX(24px);
}

.toggle-switch input:checked ~ .toggle-status .toggle-on {
  color: #166534;
}

.toggle-switch:focus-within {
  border-color: #86efac;
  box-shadow: 0 0 0 3px rgba(134, 239, 172, 0.25);
}

.stepper {
  display: flex;
  align-items: stretch;
  gap: 8px;
  margin-top: 6px;
}

.stepper input {
  flex: 1;
  text-align: center;
  margin-top: 0;
  font-size: 18px;
}

.stepper-button {
  width: 48px;
  min-width: 48px;
  margin-top: 0;
  padding: 0;
  font-size: 24px;
  line-height: 1;
  background: #111827;
}

.stepper-button:hover {
  background: #0f172a;
}

button {
  margin-top: 24px;
  width: 100%;
  padding: 14px;
  font-size: 18px;
  border: none;
  border-radius: 10px;
  background: #2563eb;
  color: white;
  cursor: pointer;
}

button:hover {
  background: #1d4ed8;
}

button.secondary {
  background: #555;
}

button.secondary:hover {
  background: #444;
}

.hidden {
  display: none;
}

.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 20px;
  margin-bottom: 32px;
}

.timer {
  font-size: 28px;
  font-weight: bold;
  background: #111827;
  color: white;
  padding: 10px 16px;
  border-radius: 12px;
  min-width: 72px;
  text-align: center;
}

.score-row {
  display: flex;
  justify-content: space-between;
  font-size: 18px;
  margin-bottom: 32px;
}

.question {
  text-align: center;
  font-size: clamp(2.5rem, 10vw, 4.5rem);
  font-weight: bold;
  margin: 32px 0;
  padding: 28px 16px;
  border-radius: 20px;
  background: #7f1d1d;
  color: #fef2f2;
  border: 4px solid rgba(255, 255, 255, 0.08);
  transition: background-color 180ms ease, color 180ms ease, border-color 180ms ease, transform 180ms ease;
}

.question.question-listening {
  background: #86efac;
  color: #14532d;
  border-color: rgba(255, 255, 255, 0.14);
  animation: questionPulse var(--question-pulse-duration, 2.4s) ease-in-out infinite;
}

.question.question-idle {
  background: #7f1d1d;
  color: #fef2f2;
  border-color: rgba(255, 255, 255, 0.08);
}

@keyframes questionPulse {
  0% {
    transform: scale(1);
    box-shadow: 0 0 0 0 rgba(134, 239, 172, 0.45);
  }
  70% {
    transform: scale(1.015);
    box-shadow: 0 0 0 16px rgba(134, 239, 172, 0);
  }
  100% {
    transform: scale(1);
    box-shadow: 0 0 0 0 rgba(134, 239, 172, 0);
  }
}

.status {
  text-align: center;
  font-size: 20px;
  min-height: 28px;
  margin-top: 16px;
}

.detected {
  margin-top: 8px;
  text-align: center;
  font-size: 14px;
  color: #4b5563;
  min-height: 20px;
  word-break: break-word;
}

.answer-input {
  margin-top: 24px;
  text-align: center;
}

.answer-input input {
  text-align: center;
  font-size: 24px;
}

.debug-log {
  margin-top: 18px;
  padding: 12px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  background: #111827;
  color: #e5e7eb;
}

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

.debug-log-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.debug-log-button {
  width: auto;
  min-height: 0;
  margin-top: 0;
  padding: 7px 10px;
  font-size: 13px;
}

.debug-log-body {
  max-height: 220px;
  overflow: auto;
  font-family: Consolas, "Courier New", monospace;
  font-size: 12px;
  line-height: 1.45;
  white-space: pre-wrap;
}

.debug-log-line {
  padding: 3px 0;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.debug-log-line:first-child {
  border-top: 0;
}

.small-note {
  font-size: 14px;
  color: #666;
  margin-top: 12px;
  text-align: center;
}

.result {
  display: grid;
  gap: 8px;
  margin-top: 18px;
  padding: 16px;
  border-radius: 14px;
  background: #f8fafc;
  border: 1px solid #e5e7eb;
  text-align: center;
  font-size: 20px;
  line-height: 1.5;
}

.game-over-result {
  gap: 10px;
  padding: 12px;
  font-size: 16px;
  text-align: left;
}

.game-over-result p {
  margin: 0;
}

.game-over-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  text-align: center;
}

.game-over-stats p {
  padding: 8px;
  border-radius: 10px;
  background: #fff;
  border: 1px solid #e5e7eb;
}

.mistakes-panel {
  display: grid;
  gap: 8px;
}

.mistakes-panel h2 {
  margin: 0;
  font-size: 18px;
  text-align: left;
}

.mistakes-list {
  display: grid;
  gap: 6px;
  max-height: 220px;
  overflow: auto;
  padding: 0;
  margin: 0;
  list-style: none;
}

.mistake-item {
  padding: 8px 10px;
  border-radius: 10px;
  background: #fff7ed;
  border: 1px solid #fed7aa;
  color: #7c2d12;
  font-size: 14px;
  line-height: 1.35;
}

.mistake-item--empty {
  background: #f0fdf4;
  border-color: #bbf7d0;
  color: #166534;
}

#gameOverScreen h1 {
  margin-bottom: 8px;
}

#gameOverScreen .result {
  margin-top: 10px;
}

#gameOverScreen #continueButton {
  margin-top: 14px;
}

.error {
  color: #b91c1c;
  text-align: center;
  margin-top: 12px;
}

#settingsScreen h1 {
  margin-bottom: 8px;
}

#settingsScreen label {
  margin-top: 12px;
}

#settingsScreen input {
  padding: 10px 12px;
}

#settingsScreen .select-control {
  padding: 10px 12px;
}

#settingsScreen .stepper {
  margin-top: 4px;
}

#settingsScreen .settings-actions {
  margin-top: 14px;
}

@media (max-width: 640px) {
  .app {
    padding: 12px;
  }

  .card {
    padding: 18px;
    border-radius: 14px;
  }

  h1 {
    font-size: 1.8rem;
  }

  .operation-row {
    flex-direction: column;
    gap: 10px;
  }

  .toggle-switch {
    padding: 12px 14px;
  }

  #settingsScreen h1 {
    margin-bottom: 4px;
  }

  #settingsScreen label {
    margin-top: 10px;
  }

  #settingsScreen input {
    padding: 10px;
  }

  .top-bar,
  .score-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
    margin-bottom: 18px;
  }

  .top-bar {
    font-size: 16px;
  }

  .timer {
    font-size: 24px;
    min-width: 64px;
    width: 100%;
  }

  .score-row {
    font-size: 16px;
    margin-bottom: 22px;
  }

  .question {
    margin: 20px 0;
    padding: 22px 14px;
    border-radius: 18px;
  }

  .game-actions {
    flex-direction: column;
  }

  .home-summary {
    font-size: 15px;
    padding: 14px;
  }

  .settings-actions--top {
    margin-top: 10px;
    margin-bottom: 10px;
  }

  .status {
    font-size: 18px;
    min-height: 24px;
  }

  .detected {
    font-size: 13px;
  }

  .debug-log-body {
    max-height: 180px;
    font-size: 11px;
  }

  .mistakes-list {
    max-height: 180px;
  }

  #resetListeningButton,
  #startGameButton,
  #continueButton {
    min-height: 52px;
    font-size: 18px;
  }

  .answer-input {
    margin-top: 18px;
  }

  .answer-input input {
    font-size: 22px;
    padding: 14px;
  }

  .stepper-button {
    width: 46px;
    min-width: 46px;
  }
}

@media (max-width: 420px) {
  .app {
    padding: 8px;
  }

  .card {
    padding: 16px;
    border-radius: 12px;
  }

  .question {
    font-size: clamp(2rem, 14vw, 3.2rem);
  }

  button {
    font-size: 17px;
  }

  .toggle-switch {
    padding: 12px;
  }
}
