.ipa-exercise-welcome {
  position: relative;
  padding: 1.5rem;
}

@media (prefers-reduced-motion: no-preference) {
  .btn-ipa-toggle,
  .btn-ipa-outline {
    transition: color 0.2s ease, background-color 0.2s ease,
      border-color 0.2s ease, box-shadow 0.2s ease;
  }
}

.btn-ipa-toggle,
.btn-ipa-outline {
  font-weight: 600;
}

.btn-ipa-toggle {
  --bs-btn-color: var(--bs-body-color);
  --bs-btn-bg: transparent;
  --bs-btn-border-width: 2px;
  --bs-btn-border-color: rgba(113, 178, 255, 0.45);
  --bs-btn-hover-color: var(--bs-body-color);
  --bs-btn-hover-bg: rgba(113, 178, 255, 0.12);
  --bs-btn-hover-border-color: rgba(113, 178, 255, 0.6);
  --bs-btn-active-color: var(--bs-body-color);
  --bs-btn-active-bg: rgba(113, 178, 255, 0.22);
  --bs-btn-active-border-color: rgba(113, 178, 255, 0.65);
  --bs-btn-disabled-color: var(--bs-secondary-color);
  --bs-btn-disabled-border-color: rgba(113, 178, 255, 0.25);
  border-radius: 999px;
}

.btn-ipa-outline {
  --bs-btn-color: var(--bs-body-color);
  --bs-btn-bg: transparent;
  --bs-btn-border-color: rgba(113, 178, 255, 0.4);
  --bs-btn-hover-color: var(--bs-body-color);
  --bs-btn-hover-bg: rgba(113, 178, 255, 0.16);
  --bs-btn-hover-border-color: rgba(113, 178, 255, 0.55);
  --bs-btn-active-color: var(--bs-body-color);
  --bs-btn-active-bg: rgba(113, 178, 255, 0.25);
  --bs-btn-active-border-color: rgba(113, 178, 255, 0.6);
  --bs-btn-disabled-color: var(--bs-secondary-color);
  --bs-btn-disabled-border-color: rgba(113, 178, 255, 0.25);
}

[data-bs-theme="light"] .btn-ipa-toggle {
  --bs-btn-border-color: rgba(13, 46, 112, 0.25);
  --bs-btn-hover-bg: rgba(13, 46, 112, 0.1);
  --bs-btn-hover-border-color: rgba(13, 46, 112, 0.4);
  --bs-btn-active-bg: rgba(13, 46, 112, 0.18);
  --bs-btn-active-border-color: rgba(13, 46, 112, 0.45);
}

[data-bs-theme="light"] .btn-ipa-outline {
  --bs-btn-border-color: rgba(13, 46, 112, 0.25);
  --bs-btn-hover-bg: rgba(13, 46, 112, 0.08);
  --bs-btn-hover-border-color: rgba(13, 46, 112, 0.4);
  --bs-btn-active-bg: rgba(13, 46, 112, 0.12);
  --bs-btn-active-border-color: rgba(13, 46, 112, 0.45);
}

.btn-ipa-toggle:focus-visible,
.btn-ipa-outline:focus-visible {
  box-shadow: 0 0 0 0.25rem rgba(113, 178, 255, 0.35);
}

[data-bs-theme="light"] .btn-ipa-toggle:focus-visible,
[data-bs-theme="light"] .btn-ipa-outline:focus-visible {
  box-shadow: 0 0 0 0.25rem rgba(13, 46, 112, 0.25);
}

.ipa-link {
  color: var(--bs-primary) !important;
  text-decoration: underline;
  text-decoration-thickness: 1.5px;
}

[data-bs-theme="dark"] .ipa-link {
  color: #8ec2ff !important;
}

.ipa-exercise-callout {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 0.75rem;
  padding: 1rem 1.25rem;
}

[data-bs-theme="light"] .ipa-exercise-callout {
  background: rgba(12, 30, 67, 0.06);
  border-color: rgba(12, 30, 67, 0.12);
}

.ipa-exercise-summary {
  height: 100%;
  padding: 1.5rem;
}

.ipa-exercise-summary dl dt {
  font-size: 0.75rem;
  letter-spacing: 0.02em;
}

.ipa-exercise-summary dl dd {
  font-size: 0.85rem;
}

.ipa-exercise-controls,
.ipa-exercise-stage,
.ipa-exercise-keyboard-wrap {
  padding: 1.5rem;
}

#ipaExerciseKeyboard {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(2.35rem, 1fr));
  gap: 0.4rem;
}

#ipaExerciseMobileKeyboard[aria-hidden="true"] {
  display: none;
}

@media (max-width: 991.98px) {
  .ipa-exercise-keyboard-wrap {
    padding: 1.25rem 1rem;
  }
  .ipa-exercise-keyboard-wrap > header {
    display: none;
  }
  #ipaExerciseKeyboard {
    display: none !important;
  }
}

.ipa-mobile-keyboard--exercise {
  display: flex;
}

@media (min-width: 992px) {
  .ipa-mobile-keyboard--exercise {
    display: none !important;
  }
}

.ipa-exercise-workspace {
  min-height: 200px;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.ipa-exercise-highlight {
  display: inline-block;
  padding: 0.25rem 0.5rem;
  border-radius: 0.5rem;
  background: rgba(255, 255, 255, 0.12);
  color: var(--bs-body-color);
  font-weight: 600;
}

[data-bs-theme="light"] .ipa-exercise-highlight {
  background: rgba(13, 46, 112, 0.12);
}

.ipa-line-text {
  font-size: 1rem;
  line-height: 1.6;
}

.ipa-line-word {
  display: inline-block;
  padding: 0.15rem 0.35rem;
  border-radius: 0.4rem;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.ipa-line-word.is-active {
  background: rgba(255, 255, 255, 0.12);
  color: var(--bs-body-color);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.2);
}

.ipa-exercise-card__header {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.ipa-exercise-card__meta {
  flex: 1 1 auto;
}

[data-bs-theme="light"] .ipa-line-word.is-active {
  background: rgba(13, 46, 112, 0.14);
  box-shadow: 0 0 0 1px rgba(13, 46, 112, 0.22);
}

.ipa-line-audio {
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 0.75rem;
  padding: 0.75rem 1rem;
  background: rgba(255, 255, 255, 0.04);
  margin-bottom: 1rem;
}

[data-bs-theme="light"] .ipa-line-audio {
  border-color: rgba(15, 25, 54, 0.12);
  background: rgba(255, 255, 255, 0.9);
}

.ipa-line-audio__voice {
  min-width: 160px;
}

.ipa-line-audio__speed input[type="range"] {
  min-width: 140px;
}

@media (min-width: 992px) {
  .ipa-exercise-card__header {
    flex-direction: row;
    align-items: flex-start;
    gap: 1rem;
  }

  .ipa-line-audio {
    margin-bottom: 0;
    min-width: 320px;
  }
}

#ipaExerciseFlash {
  align-self: flex-start;
}

.ipa-exercise-card {
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 0.75rem;
  padding: 1.25rem;
  background: rgba(8, 12, 25, 0.65);
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.18);
}

[data-bs-theme="light"] .ipa-exercise-card {
  background: rgba(255, 255, 255, 0.92);
  border-color: rgba(15, 25, 54, 0.12);
  box-shadow: 0 18px 36px rgba(15, 25, 54, 0.12);
}

#ipaExerciseWordContainer .form-label {
  margin-bottom: 0.5rem;
}

.ipa-exercise-word-title {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.ipa-exercise-hint {
  font-size: 0.85rem;
  color: var(--bs-secondary-color);
}

.ipa-exercise-slot {
  background: rgba(12, 16, 32, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 0.65rem;
  padding: 0.35rem 0.6rem;
  color: var(--bs-body-color);
  text-align: center;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
  flex: 0 1 auto;
  width: calc((var(--slot-chars, 3) + 1) * 1ch + 1rem);
  min-width: calc((var(--slot-chars, 3) + 1) * 1ch + 1rem);
  max-width: 100%;
  box-sizing: border-box;
}

[data-bs-theme="light"] .ipa-exercise-slot {
  background: rgba(244, 247, 255, 0.9);
  border-color: rgba(15, 25, 54, 0.15);
}

.ipa-exercise-slot:focus {
  border-color: rgba(113, 178, 255, 0.7);
  box-shadow: 0 0 0 0.2rem rgba(113, 178, 255, 0.15);
  outline: none;
}

.ipa-exercise-slot.is-correct {
  border-color: rgba(68, 214, 155, 0.9);
  box-shadow: 0 0 0 0.2rem rgba(68, 214, 155, 0.2);
}

.ipa-exercise-slot.is-wrong {
  border-color: rgba(211, 106, 203, 0.9);
  box-shadow: 0 0 0 0.2rem rgba(211, 106, 203, 0.2);
}

.ipa-exercise-token {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
  justify-content: flex-start;
}

.ipa-exercise-token + .ipa-exercise-token {
  margin-top: 0.5rem;
}

.ipa-exercise-token.has-error .ipa-exercise-slot {
  border-color: rgba(211, 106, 203, 0.9);
  box-shadow: 0 0 0 0.2rem rgba(211, 106, 203, 0.2);
}

.ipa-exercise-token-label {
  font-size: 0.8rem;
  color: var(--bs-secondary-color);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.ipa-exercise-line-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: stretch;
  justify-content: flex-start;
  width: 100%;
}

.ipa-exercise-line-column {
  --column-base: calc(var(--column-length, 4) * 1ch);
  --column-extra: calc(1.75rem + var(--slot-count, 1) * 1.2rem);
  --column-width: calc(var(--column-base) + var(--column-extra));
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  gap: 0.6rem;
  flex: 1 1 var(--column-width);
  max-width: 100%;
  min-width: 10rem;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 0.85rem;
  padding: 0.75rem 0.9rem;
  background: rgba(12, 16, 32, 0.8);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.04);
  text-align: center;
  position: relative;
}

[data-bs-theme="light"] .ipa-exercise-line-column {
  background: rgba(255, 255, 255, 0.88);
  border-color: rgba(15, 25, 54, 0.12);
  box-shadow: inset 0 0 0 1px rgba(15, 25, 54, 0.05);
}

.ipa-exercise-line-column.is-target {
  border-color: rgba(113, 178, 255, 0.7);
  box-shadow: inset 0 0 0 1px rgba(113, 178, 255, 0.25);
}

.ipa-exercise-line-original-token {
  font-size: 0.9rem;
  font-weight: 600;
  text-align: center;
  color: var(--bs-body-color);
  min-height: 1.4rem;
}

.ipa-exercise-line-slotwrap {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  justify-content: center;
  align-items: center;
  width: 100%;
  min-height: 2.25rem;
  white-space: normal;
  overflow-wrap: anywhere;
}

.ipa-exercise-line-slotwrap.is-compact {
  flex-wrap: nowrap;
  gap: 0.25rem;
  overflow-x: auto;
}

.ipa-exercise-line-slotwrap.is-compact .ipa-exercise-slot,
.ipa-exercise-line-slotwrap.is-compact span {
  flex: 0 0 auto;
}

.ipa-exercise-slot.is-locked,
.ipa-exercise-slot[disabled] {
  background: rgba(255, 255, 255, 0.05);
  border-style: dashed;
  color: var(--bs-secondary-color);
  cursor: default;
}

.ipa-exercise-line-slotwrap span {
  font-size: 1rem;
  color: var(--bs-body-color);
  white-space: pre;
  display: inline-flex;
  align-items: center;
}

.ipa-exercise-line-column.has-error {
  border-color: rgba(211, 106, 203, 0.9);
  box-shadow: inset 0 0 0 1px rgba(211, 106, 203, 0.2);
}

.ipa-exercise-line-column.is-correct {
  border-color: rgba(68, 214, 155, 0.85);
  box-shadow: inset 0 0 0 1px rgba(68, 214, 155, 0.22);
}

.ipa-exercise-column-status {
  position: absolute;
  top: 0.45rem;
  right: 0.5rem;
  width: 1.6rem;
  height: 1.6rem;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.9rem;
  pointer-events: none;
  opacity: 0;
  transform: scale(0.9);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.ipa-exercise-column-status.is-correct {
  background: rgba(68, 214, 155, 0.18);
  color: #2fe0a0;
  opacity: 1;
  transform: scale(1);
}

.ipa-exercise-column-status.has-error {
  background: rgba(211, 106, 203, 0.2);
  color: #ff62ef;
  opacity: 1;
  transform: scale(1);
}

.ipa-exercise-feedback {
  font-size: 0.9rem;
  margin-top: 0.75rem;
}

.ipa-exercise-feedback-message {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.ipa-exercise-attempts {
  margin-top: 0.5rem;
}

.ipa-exercise-history {
  margin-top: 0.5rem;
  padding-left: 1.25rem;
  font-size: 0.85rem;
  color: var(--bs-secondary-color);
}

.ipa-exercise-history li {
  margin-bottom: 0.25rem;
}

.ipa-exercise-history code {
  background: rgba(255, 255, 255, 0.08);
  border-radius: 0.4rem;
  padding: 0.1rem 0.35rem;
  color: var(--bs-body-color);
}

.ipa-exercise-history .badge {
  margin-right: 0.5rem;
}

.ipa-exercise-feedback .badge {
  font-size: 0.75rem;
  letter-spacing: 0.08em;
}

.ipa-exercise-options {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.ipa-exercise-option-buttons {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.ipa-exercise-option-buttons button {
  text-align: left;
}

.ipa-exercise-placeholder {
  text-align: center;
  margin: auto;
  font-size: 0.95rem;
}

.ipa-exercise-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(5, 9, 18, 0.78);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1060;
  padding: 1rem;
}

.ipa-exercise-modal-backdrop.is-active {
  display: flex;
}

.ipa-exercise-modal {
  background: rgba(10, 14, 28, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 0.9rem;
  padding: 1.5rem;
  max-width: 420px;
  width: 100%;
  box-shadow: 0 20px 45px rgba(0, 0, 0, 0.4);
}

.ipa-exercise-modal-body {
  font-size: 0.95rem;
  color: var(--bs-body-color);
}

.ipa-exercise-modal-body code {
  background: rgba(255, 255, 255, 0.08);
  padding: 0.15rem 0.4rem;
  border-radius: 0.4rem;
  color: var(--bs-body-color);
}

.ipa-exercise-modal-actions {
  margin-top: 1.5rem;
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
}

:root[data-bs-theme="light"] .ipa-exercise-callout {
  background: rgba(15, 25, 54, 0.05);
  border-color: rgba(15, 25, 54, 0.12);
}

:root[data-bs-theme="light"] .ipa-exercise-language.active,
:root[data-bs-theme="light"] .ipa-exercise-unit.active,
:root[data-bs-theme="light"] .ipa-exercise-mode.active {
  background: rgba(15, 25, 54, 0.08);
  border-color: rgba(15, 25, 54, 0.2);
}

:root[data-bs-theme="light"] .ipa-exercise-highlight {
  background: rgba(15, 25, 54, 0.12);
}

:root[data-bs-theme="light"] .ipa-exercise-card {
  background: rgba(255, 255, 255, 0.95);
  border-color: rgba(15, 25, 54, 0.12);
  box-shadow: 0 12px 24px rgba(15, 25, 54, 0.12);
}

:root[data-bs-theme="light"] .ipa-exercise-slot {
  background: rgba(15, 25, 54, 0.05);
  border-color: rgba(15, 25, 54, 0.12);
}

:root[data-bs-theme="light"] .ipa-exercise-slot.is-locked,
:root[data-bs-theme="light"] .ipa-exercise-slot[disabled] {
  background: rgba(15, 25, 54, 0.04);
}

:root[data-bs-theme="light"] .ipa-exercise-line-column {
  background: rgba(15, 25, 54, 0.04);
  border-color: rgba(15, 25, 54, 0.12);
  box-shadow: inset 0 0 0 1px rgba(15, 25, 54, 0.05);
}

:root[data-bs-theme="light"] .ipa-exercise-history code,
:root[data-bs-theme="light"] .ipa-exercise-modal-body code {
  background: rgba(15, 25, 54, 0.08);
}

:root[data-bs-theme="light"] .ipa-exercise-modal {
  background: #ffffff;
  border-color: rgba(15, 25, 54, 0.12);
  box-shadow: 0 20px 45px rgba(15, 25, 54, 0.15);
}

:root[data-bs-theme="light"] .ipa-exercise-modal-backdrop {
  background: rgba(11, 18, 32, 0.55);
}

@media (max-width: 767.98px) {
  .ipa-exercise-workspace {
    min-height: 160px;
  }
  .ipa-exercise-slot {
    width: calc(var(--slot-chars, 3) * 1ch + 1rem);
    min-width: calc(var(--slot-chars, 3) * 1ch + 1rem);
  }
  .ipa-exercise-line-grid {
    gap: 0.75rem;
  }
  .ipa-exercise-line-column {
    min-width: calc((var(--column-length, 4) + 1) * 1.05ch + 1rem);
  }
}
