@font-face {
  font-family: 'Vazirmatn';
  src: url('../fonts/vazir.ttf') format('truetype');
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

:root {
  --bg: #f3f4f6;
  --panel: #ffffff;
  --line: #c5cad2;
  --text: #171a20;
  --muted: #5d6673;
  --accent: #397dcc;
  --gold: #d79516;
  --grey: #747d89;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: 'Vazirmatn', Tahoma, Arial, sans-serif;
  font-weight: 400;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
  font-weight: 400;
}

.shell {
  position: relative;
  width: 100%;
  height: 100%;
}

.toolbar {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 10;
  display: flex;
  gap: 8px;
}

.controls {
  display: flex;
  gap: 8px;
}

button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  line-height: 1;
  text-decoration: none;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.06);
}

button {
  cursor: pointer;
}

button:hover:not(:disabled) {
  background: #ffffff;
}

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

button:disabled {
  cursor: default;
  opacity: 0.45;
}

.token-strip {
  position: absolute;
  top: 16px;
  left: 16px;
  z-index: 9;
  max-width: calc(100% - 220px);
  min-height: 42px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 2px 10px rgba(25, 35, 50, 0.06);
  font-size: 14px;
  line-height: 1.9;
  white-space: pre-wrap;
}

.verse-break {
  display: block;
}

.token-chip {
  background: transparent;
  color: var(--muted);
  font-weight: 500;
  white-space: pre-wrap;
  transition:
    color 0.25s ease,
    background-color 0.25s ease;
}

.token-chip.visible {
  background: color-mix(in srgb, var(--token-color) 18%, white);
  color: var(--token-color);
}

.token-strip::after {
  content: '';
  display: inline-block;
  width: 2px;
  height: 1.35em;
  margin-inline-start: 3px;
  border-radius: 1px;
  background: var(--accent);
  vertical-align: -0.25em;
  animation: token-caret-blink 0.9s steps(1, end) infinite;
}

@keyframes token-caret-blink {
  0%,
  48% {
    opacity: 1;
  }
  49%,
  100% {
    opacity: 0;
  }
}

.stage {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 68px 16px 62px;
}

svg {
  display: block;
  width: 100%;
  max-width: 1100px;
  max-height: 100%;
}

.stage-bg {
  fill: rgba(255, 255, 255, 0.7);
  stroke: var(--line);
}

.vocab-group {
  opacity: 0.7;
  transition: opacity 0.24s linear;
}

.vocab-group.hidden {
  opacity: 0;
}

.vocab-dot {
  fill: var(--grey);
  transition:
    fill 0.35s ease,
    r 0.35s ease,
    opacity 0.35s ease;
}

.vocab-label {
  fill: var(--grey);
  font-size: 11.5px;
  font-weight: 400;
  paint-order: stroke;
  stroke: var(--panel);
  stroke-width: 4px;
  stroke-linejoin: round;
  transition:
    fill 0.35s ease,
    opacity 0.35s ease;
}

.vocab-group.highlight .vocab-dot,
.vocab-group.highlight .vocab-label {
  fill: var(--accent);
}

.vocab-group.target .vocab-dot,
.vocab-group.target .vocab-label {
  fill: var(--gold);
}

.active-token {
  opacity: 0;
  transition: opacity 0.2s linear;
  will-change: transform;
}

.active-token.visible {
  opacity: 1;
}

.active-dot {
  fill: var(--token-color, var(--accent));
  stroke: var(--panel);
  stroke-width: 2.5;
}

.active-label {
  fill: var(--token-color, var(--text));
  font-size: 12px;
  font-weight: 500;
  paint-order: stroke;
  stroke: var(--panel);
  stroke-width: 4px;
  stroke-linejoin: round;
}

.position-line {
  stroke: var(--muted);
  stroke-width: 1.4;
  marker-end: url(#arrow);
  opacity: 0;
  transition: opacity 0.3s ease;
}

.position-line.show {
  opacity: 0.7;
}

.status {
  position: absolute;
  left: 16px;
  bottom: 14px;
  z-index: 10;
  width: 230px;
  pointer-events: none;
}
.status p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.progress-track {
  overflow: hidden;
  height: 2px;
  background: transparent;
}

.progress-fill {
  width: 0;
  height: 100%;
  background: var(--accent);
  transition: width 0.3s ease;
}

body[data-language='fa'] .token-chip,
body[data-language='fa'] .vocab-label,
body[data-language='fa'] .active-label {
  font-family: 'Vazirmatn', Tahoma, Arial, sans-serif;
}

body[data-language='fa'] .vocab-label,
body[data-language='fa'] .active-label {
  direction: rtl;
  unicode-bidi: plaintext;
}

@media (max-width: 900px) {
  .toolbar {
    left: 12px;
    right: 12px;
  }

  .token-strip {
    top: 64px;
    left: 12px;
    right: 12px;
    max-width: none;
  }

  .stage {
    padding: 116px 10px 62px;
  }
}

@media (max-width: 560px) {
  .toolbar {
    display: grid;
    grid-template-columns: 1fr;
  }

  .toolbar {
    gap: 6px;
  }

  .controls {
    display: grid;
    width: 100%;
    gap: 6px;
  }

  .controls {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  button {
    flex: 1;
    min-width: 0;
    padding-inline: 6px;
    font-size: 12px;
  }

  .token-strip {
    top: 64px;
  }
  .stage {
    padding-top: 116px;
  }
  .status {
    right: 12px;
    left: 12px;
    width: auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  .token-strip::after {
    animation: none;
  }

  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}
