:root {
  --bg: #050811;
  --surface: #0c1222;
  --surface-elevated: #10182d;
  --text: #f2f6ff;
  --text-secondary: #a8b6d6;
  --border: #1e2942;
  --border-subtle: rgba(148, 179, 245, 0.14);
  --accent: #4df5c5;
  --accent-hover: #72f8d1;
  --accent-ink: #041511;
  --blue-pill: #9ec2ff;
  font-family: 'Atkinson Hyperlegible', system-ui, -apple-system,
    BlinkMacSystemFont, 'Segoe UI', sans-serif;
  color-scheme: dark;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

::selection {
  background: rgba(77, 245, 197, 0.25);
  color: var(--text);
}

html {
  scrollbar-width: thin;
  scrollbar-color: #243252 var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  caret-color: var(--accent);
  -webkit-font-smoothing: antialiased;
}

#home-splash {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  display: block;
  pointer-events: none;
  z-index: -1;
  opacity: 0.55;
  filter: saturate(140%);
  background: radial-gradient(
    circle at top right,
    rgba(40, 180, 255, 0.14),
    rgba(2, 4, 10, 0.9)
  );
}

@media (prefers-reduced-motion: reduce) {
  #home-splash {
    opacity: 0.2;
  }
}

.page {
  min-height: 100vh;
  max-width: 720px;
  margin: 0 auto;
  padding: 56px 20px 72px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  align-items: center;
  text-align: center;
}

.hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin-bottom: 4px;
}

h1 {
  margin: 0;
  font-size: clamp(2rem, 4.5vw, 2.75rem);
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.1;
  color: var(--text);
}

.subtitle {
  margin: 0;
  max-width: 52ch;
  font-size: 0.98rem;
  line-height: 1.5;
  color: var(--text-secondary);
}

.wiki-link {
  color: var(--text);
  text-decoration: underline;
  text-decoration-color: rgba(77, 245, 197, 0.45);
  text-underline-offset: 0.22em;
  transition: color 0.18s ease, text-decoration-color 0.18s ease;
}

.wiki-link:hover,
.wiki-link:focus-visible {
  color: var(--accent);
  text-decoration-color: var(--accent);
}

.input-panel {
  width: 100%;
  display: flex;
  align-items: stretch;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: 0 18px 44px rgba(2, 4, 12, 0.55);
}

.input-panel input {
  flex: 1;
  min-width: 0;
  padding: 14px 16px;
  border-radius: 11px;
  border: 1px solid rgba(148, 179, 245, 0.12);
  background: #070b15;
  color: var(--text);
  font-family: inherit;
  font-size: 1.1rem;
  font-weight: 500;
  transition: border-color 0.18s ease;
}

.input-panel input::placeholder {
  color: var(--text-secondary);
  opacity: 0.65;
}

.input-panel input:focus {
  outline: none;
  border-color: var(--accent);
}

.input-actions {
  display: flex;
  align-items: stretch;
  gap: 8px;
}

button {
  font-family: inherit;
  border-radius: 11px;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  white-space: nowrap;
  transition: transform 0.15s ease, background-color 0.18s ease,
    border-color 0.18s ease, color 0.18s ease;
}

button:focus-visible,
a:focus-visible,
input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn-primary {
  padding: 0 22px;
  border: 1px solid transparent;
  background: var(--accent);
  color: var(--accent-ink);
  box-shadow: 0 8px 20px rgba(4, 12, 24, 0.45);
}

.btn-primary:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
}

.btn-secondary {
  width: 48px;
  padding: 0;
  border: 1px solid var(--border);
  background: var(--surface-elevated);
  color: var(--text-secondary);
}

.btn-secondary:hover {
  border-color: rgba(77, 245, 197, 0.45);
  color: var(--text);
  background: #15203b;
  transform: translateY(-1px);
}

.icon-refresh {
  flex-shrink: 0;
  transition: transform 0.45s cubic-bezier(0.22, 1, 0.36, 1);
}

.btn-secondary:hover .icon-refresh,
.btn-secondary.is-spinning .icon-refresh {
  transform: rotate(180deg);
}

.controls-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 14px;
}

.controls-divider {
  color: rgba(168, 182, 214, 0.35);
  user-select: none;
}

.notation-switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font-size: 0.86rem;
  color: var(--text-secondary);
  cursor: pointer;
  user-select: none;
}

.notation-switch input {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.notation-side {
  font-weight: 600;
  transition: color 0.18s ease;
}

.notation-switch input:not(:checked) ~ .notation-arpabet,
.notation-switch input:checked ~ .notation-ipa {
  color: var(--accent);
}

.switch-track {
  position: relative;
  display: inline-flex;
  align-items: center;
  width: 38px;
  height: 20px;
  padding: 2px;
  border-radius: 999px;
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  transition: border-color 0.2s ease, background-color 0.2s ease;
}

.notation-switch:hover .switch-track {
  border-color: rgba(77, 245, 197, 0.45);
}

.notation-switch input:focus-visible ~ .switch-track {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.switch-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  transition: transform 0.22s cubic-bezier(0.22, 1, 0.36, 1);
}

.notation-switch input:checked ~ .switch-track .switch-thumb {
  transform: translateX(18px);
}

.debug-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 0.86rem;
  color: var(--text-secondary);
  cursor: pointer;
  user-select: none;
}

.debug-toggle input {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

.status {
  min-height: 20px;
  margin: -6px 0 0;
  font-size: 0.92rem;
  color: #ff9b9b;
}

.status:empty {
  display: none;
}

.results {
  width: 100%;
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.results.is-hidden {
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  text-align: left;
  box-shadow: 0 20px 50px rgba(2, 4, 12, 0.55);
}

.steps {
  display: grid;
  gap: 12px;
  text-align: left;
}

.step {
  border: 1px solid var(--border-subtle);
  border-radius: 14px;
  padding: 16px 18px;
  background: #090e1c;
}

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

.step-title {
  color: var(--text-secondary);
  font-size: 0.76rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.step .content {
  font-weight: 600;
  font-size: 1.35rem;
  letter-spacing: -0.01em;
  line-height: 1.25;
}

.debug-step {
  background: #080c18;
}

.debug-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-family: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.84rem;
  font-variant-numeric: tabular-nums;
  color: var(--text-secondary);
}

.debug-row {
  padding: 6px 0;
  border-bottom: 1px solid rgba(148, 179, 245, 0.08);
}

.debug-row:last-child {
  border-bottom: none;
}

.phoneme-step {
  background: #080d1a;
  border: 1px solid var(--border-subtle);
  overflow: hidden;
  cursor: pointer;
  transition: border-color 0.25s ease;
}

.phoneme-step:hover {
  border-color: rgba(77, 245, 197, 0.35);
}

.phoneme-header-links {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  gap: 12px;
  margin-bottom: 14px;
}

.phoneme-link {
  font-size: 0.76rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-secondary);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: color 0.18s ease;
}

.phoneme-link::after {
  content: '↗';
  font-size: 0.72rem;
  opacity: 0.7;
}

.phoneme-link:hover,
.phoneme-link:focus-visible {
  color: var(--accent);
}

.phoneme-rail {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  min-height: 40px;
}

.phoneme-word {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  font-family: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  font-weight: 600;
}

.chunk-wrap {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
  will-change: transform;
  transition: transform 1.25s cubic-bezier(0.22, 1, 0.36, 1);
}

.phoneme-step.can-swap:hover .chunk-wrap,
.phoneme-step.can-swap.is-swapped .chunk-wrap {
  transform: translateX(var(--swap-shift, 0px));
}

.chunk {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 34px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid transparent;
  font-weight: 600;
  line-height: 1;
  background: rgba(255, 255, 255, 0.04);
}

.chunk-token {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.92rem;
  line-height: 1;
  letter-spacing: 0.06em;
}

.chunk-empty {
  display: inline-flex;
  min-width: 52px;
  height: 34px;
  border-bottom: 1px dashed rgba(255, 255, 255, 0.15);
}

.chunk-a {
  border-color: rgba(105, 255, 210, 0.48);
  background: rgba(105, 255, 210, 0.14);
  color: #89ffd9;
}

.chunk-b {
  border-color: rgba(129, 178, 255, 0.48);
  background: rgba(129, 178, 255, 0.14);
  color: var(--blue-pill);
}

.phoneme-tail {
  display: inline-grid;
  align-items: center;
  height: 34px;
  font-size: 0.92rem;
  line-height: 1;
  letter-spacing: 0.12em;
  color: var(--text);
}

.tail-layer {
  grid-area: 1 / 1;
  display: inline-flex;
  align-items: center;
  height: 34px;
  line-height: 1;
  transition: opacity 0.85s ease;
  white-space: nowrap;
}

.tail-swapped {
  opacity: 0;
}

.phoneme-step.can-swap:hover .tail-swapped,
.phoneme-step.can-swap.is-swapped .tail-swapped {
  opacity: 1;
}

.phoneme-step.can-swap:hover .tail-original,
.phoneme-step.can-swap.is-swapped .tail-original {
  opacity: 0;
}

.divider {
  align-self: center;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 34px;
  min-width: 28px;
  font-weight: 500;
  color: rgba(168, 182, 214, 0.35);
}

.swap {
  color: var(--accent);
}

.animate-in {
  animation: fade 0.35s cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes fade {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 640px) {
  .page {
    padding: 36px 16px 56px;
  }

  .input-panel {
    flex-direction: column;
    padding: 12px;
  }

  .input-actions {
    width: 100%;
  }

  .btn-secondary {
    width: 48px;
    flex: 0 0 48px;
    padding: 13px 0;
  }

  .btn-primary {
    flex: 1;
    padding: 13px 16px;
  }

  .phoneme-rail {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }

  .divider {
    display: none;
  }
}
