* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  min-height: 100%;
}

body {
  overflow-y: auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: #F5F7FA;
  color: #0F1D2F;
  font-family: Montserrat, sans-serif;
  font-size: clamp(12px, 1.8vw, 16px);
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

#app {
  width: 100%;
  min-height: max(560px, 100dvh);
  padding: clamp(10px, 1.5vw, 20px);
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 5px;
}

#main {
  min-height: 0;
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  gap: 5px;
  overflow: hidden auto;
}

#settings {
  flex: 0 0 auto;
  min-height: 0;
  z-index: 10;
}

#mobile-overlay {
  display: none;
}

@media (max-width: 1023px) {
  #mobile-overlay {
    display: flex;
    position: fixed;
    inset: 0;
    z-index: 9999;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    color: #fff;
    font-family: Montserrat, sans-serif;
    font-size: clamp(16px, 4vw, 24px);
    line-height: 1.45;
    text-align: center;
  }

  #mobile-overlay::before {
    content: attr(data-message);
    max-width: 420px;
  }
}

.app-header {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: clamp(12px, 2vw, 20px);
  font-family: Montserrat, system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

.app-header__brand {
  display: inline-flex;
  align-items: center;
  min-width: 0;
}

.app-header__logo {
  height: 32px;
  width: auto;
  margin-right: 8px;
  flex: 0 0 auto;
}

.app-header__title {
  color: #1E3A5F;
  font-size: clamp(16px, 2.5vw, 24px);
  font-weight: 700;
  white-space: nowrap;
}

.app-header__nav {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-left: auto;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.app-header__mode {
  padding: 8px 16px;
  border: 1px solid #536276;
  border-radius: 6px;
  background: transparent;
  color: #536276;
  font-family: Montserrat, system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: clamp(12px, 1.8vw, 16px);
  line-height: 1.2;
}

.app-header__mode.is-active {
  border-color: #1E3A5F;
  background: #1E3A5F;
  color: #fff;
  cursor: default;
}

.app-header__mode:disabled {
  opacity: 1;
}

.app-header__divider {
  width: 1px;
  height: 20px;
  background: #C8D0D9;
  margin-left: 16px;
  flex-shrink: 0;
}

.app-header__feedback {
  padding: 8px 16px;
  border: 1px solid #C8D0D9;
  border-radius: 6px;
  background: transparent;
  color: #8A97A6;
  font-size: clamp(11px, 1.6vw, 14px);
  font-weight: 500;
  line-height: 1.2;
  white-space: nowrap;
  flex-shrink: 0;
  transition: border-color 0.15s, color 0.15s;
}

.app-header__feedback:hover {
  border-color: #8A97A6;
  color: #536276;
}

.route-field {
  width: 100%;
  min-height: 0;
  flex: 1 1 auto;
  padding: clamp(14px, 2vw, 24px);
  overflow-x: auto;
  overflow-y: hidden;
  background: #F5F7FA;
  border-radius: 18px;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

.route-field__track {
  min-height: 100%;
  display: flex;
  align-items: center;
  gap: 16px;
}

.route-field__empty {
  width: 100%;
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(16px, 2vw, 28px);
  color: #7A90AE;
  font-size: clamp(18px, 2.2vw, 30px);
  font-style: italic;
  line-height: 1.25;
  text-align: center;
  white-space: pre-line;
  padding: clamp(20px, 4vw, 56px);
}

.route-field__empty-logo {
  width: min(140px, 30%);
  height: auto;
  opacity: 0.9;
}

.card {
  --card-row-height: clamp(72px, 8vh, 100px);
  --card-accessories-height: clamp(48px, 5.5vh, 66px);
  --card-beats-height: clamp(100px, 11vh, 135px);
  position: relative;
  min-width: 0;
  max-width: none;
  flex: 0 0 min(560px, calc((100% - 32px) / 3 * 0.95));
  padding: clamp(20px, 2vw, 28px) 24px;
  border: 3px solid transparent;
  border-radius: 18px;
  background: #fff;
  color: #0F1D2F;
  font-family: 'Montserrat Alternates', Montserrat, sans-serif;
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

.card__info-button {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 2;
  width: 24px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid #1E3A5F;
  border-radius: 50%;
  background: #fff;
  color: #1E3A5F;
  font-family: Georgia, serif;
  font-size: 15px;
  font-style: italic;
  line-height: 1;
}

.card__info-button:hover {
  background: #E8F0FE;
  box-shadow: 0 4px 12px rgba(30, 58, 95, 0.18);
}

.card--start,
.card--rest {
  opacity: 0.6;
}

.card--active {
  border-color: #1E3A5F;
  box-shadow: 0 10px 26px rgba(30, 58, 95, 0.18);
  opacity: 1;
}

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

.card__half {
  min-width: 0;
  padding-right: 14px;
  border-right: 1px solid #D5E4F5;
}

.card__half:last-child {
  padding-right: 0;
  padding-left: 2px;
  border-right: 0;
}

.card__line {
  height: var(--card-row-height);
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-bottom: 1px solid #D5E4F5;
}

.card__line--accessories {
  height: var(--card-accessories-height);
}

.card__line--beats {
  height: var(--card-beats-height);
  border-bottom: none;
}

.card__line-content {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  text-align: center;
}

.card__line-content--direction {
  color: #7A90AE;
  font-size: clamp(18px, 1.5vw, 24px);
  font-weight: 700;
  text-transform: uppercase;
}
.card__line-content--split {
  gap: 0;
}

.card__line-half {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 8px;
  height: 100%;
}

.card__line-half:not(:last-child) {
  border-right: 1px solid #D5E4F5;
}

.card__icon-text {
  min-width: 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  justify-content: center;
  font-size: clamp(16px, 1.25vw, 22px);
  font-weight: 700;
}

.card__icon {
  width: 40px;
  height: 40px;
  object-fit: contain;
  flex: 0 0 auto;
}

.card__dash {
  color: #9BB5D4;
  font-size: clamp(16px, 2.5vw, 20px);
  line-height: 1;
}

.card__accessory-grid,
.card__beats {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 4px;
}

.card__accessory-grid .card__dash {
  grid-column: 1 / -1;
  align-self: center;
  justify-self: center;
}

.card__accessories,
.card__beats {
  padding: 0;
  align-items: center;
}

.card__accessory-grid--half,
.card__beats--half {
  grid-template-columns: repeat(4, 1fr);
}

.card__accessory-cell {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: #F5F7FA;
}

.card__accessory-cell .card__icon {
  width: clamp(34px, 3.2vw, 50px);
  height: clamp(34px, 3.2vw, 50px);
}

.card__beat-cell {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

.card__beat-bar {
  width: 100%;
  max-width: 16px;
  border-radius: 999px 999px 4px 4px;
}

.card__beat-bar--high {
  height: clamp(38px, 4vh, 54px);
  background: #1E3A5F;
}

.card__beat-bar--medium {
  height: clamp(28px, 3vh, 40px);
  margin-top: 10px;
  background: #3B7DD8;
}

.card__beat-bar--low {
  height: clamp(18px, 2vh, 28px);
  margin-top: 20px;
  background: #C8DAF2;
}

.card__beat-number {
  color: #9BB5D4;
  font-size: clamp(10px, 1.2vw, 12px);
}

.card__beat-dot {
  width: 30px;
  height: 30px;
  border: 6px solid #9BB5D4;
  border-radius: 50%;
  background: transparent;
}

.card--active .card__beat-dot--active {
  border-color: #1E3A5F;
  background: #1E3A5F;
}

.audio-controls {
  width: 100%;
  min-height: 56px;
  padding: 8px 12px;
  display: flex;
  align-items: center;
  gap: 12px;
  overflow-x: auto;
  border: 1px solid #D5E4F5;
  border-radius: 12px;
  background: #fff;
  font-family: Montserrat, system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

.audio-controls__row {
  margin: 0;
  display: flex;
  align-items: center;
  flex: 0 0 auto;
  flex-wrap: nowrap;
  gap: 8px;
}

.audio-controls__label {
  min-width: auto;
  color: #1E3A5F;
  font-weight: 700;
}

.audio-controls input[type='range'] {
  width: clamp(110px, 12vw, 180px);
  min-width: 110px;
}

.audio-controls button {
  padding: 6px 10px;
  border: 1px solid #ccc;
  border-radius: 8px;
  background: #fff;
}

.audio-controls__value-button,
.audio-controls__value-input {
  width: 64px;
  text-align: center;
}

.audio-controls__value-input {
  padding: 8px 12px;
  border: 1px solid #ccc;
  border-radius: 8px;
  font: inherit;
}

.audio-controls button.is-active {
  border-color: #3B7DD8;
  background: #3B7DD8;
  color: #fff;
}

/* Кнопка "Настучать ритм" — flash и tooltip */
.tap-tooltip {
  position: fixed;
  background: #1E3A5F;
  color: #fff;
  font-size: clamp(12px, 1.8vw, 16px);
  white-space: normal;
  max-width: 140px;
  text-align: center;
  padding: 6px 14px;
  border-radius: 6px;
  pointer-events: none;
  z-index: 9999;
  transition: opacity 150ms;
}

@keyframes tap-flash {
  0%   { background: #3B7DD8; color: #fff; transform: scale(0.94); }
  50%  { background: #3B7DD8; color: #fff; transform: scale(1.00); }
  100% { background: #fff;    color: inherit; transform: scale(1.00); }
}

.audio-controls__tap {
  min-width: 9em;
  text-align: center;
}

.audio-controls__tap.is-tapping {
  animation: tap-flash 250ms ease-out forwards;
}

button.audio-controls__start {
  min-width: 110px;
  margin-top: 0;
  font-weight: 700;
  background: #1E3A5F;
  color: #fff;
  border-color: transparent;
  box-shadow: 0 4px 14px rgba(30, 58, 95, 0.35);
}

.game-settings {
  width: 100%;
  height: 100%;
  max-height: none;
  padding: clamp(8px, 0.8vw, 14px) clamp(14px, 1.4vw, 24px);
  display: grid;
  grid-template-columns: 1fr 1fr 1fr auto;
  grid-template-rows: auto minmax(0, 1fr);
  align-items: start;
  gap: clamp(6px, 0.65vw, 10px);
  overflow: hidden;
  border-top: 1px solid #D5E4F5;
  border-radius: 18px 18px 0 0;
  background: #fff;
  box-shadow: 0 -8px 26px rgba(30, 58, 95, 0.08);
  font-family: Montserrat, system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

.game-settings__section,
.game-settings__deck {
  min-width: 0;
  min-height: 0;
  padding: clamp(6px, 0.65vw, 10px);
  display: flex;
  flex-direction: column;
  border-radius: 12px;
  background: #fff;
  border: 1px solid #DDE7F4;
  box-shadow: 0 3px 10px rgba(30, 58, 95, 0.06);
}

.game-settings__section--eights {
  grid-column: 1 / -1;
  padding: 0 2px clamp(5px, 0.55vw, 8px);
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: clamp(14px, 1.5vw, 28px);
  border: 0;
  border-bottom: 1px solid #DDE7F4;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

.game-settings__decks {
  grid-column: 1 / 4;
  grid-row: 2;
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  align-items: stretch;
  gap: clamp(6px, 0.8vw, 10px);
}

.game-settings__deck {
  width: auto;
}

.game-settings__duration-group {
  display: flex;
  gap: 4px;
}

.game-settings__duration-btn {
  padding: 2px 8px;
  border: 1px solid #9BB5D4;
  border-radius: 6px;
  background: #fff;
  color: #1E3A5F;
  font-size: clamp(11px, 0.85vw, 13px);
  font-weight: 600;
  cursor: pointer;
  line-height: 1.4;
}

.game-settings__duration-btn.is-active {
  border-color: #3B7DD8;
  background: #3B7DD8;
  color: #fff;
}

.game-settings__label {
  margin-bottom: 0;
  color: #1E3A5F;
  font-size: clamp(13px, 1vw, 18px);
  font-weight: 400;
}

.game-settings__dots {
  display: inline-flex;
  gap: clamp(2px, 0.3vw, 4px);
  vertical-align: middle;
}

.game-settings__dot {
  width: clamp(13px, 1vw, 20px);
  height: clamp(13px, 1vw, 20px);
  border: 0;
  border-radius: 50%;
  background: #D5E4F5;
}

.game-settings__dot.is-active {
  background: #1E3A5F;
}

.game-settings__eight-value {
  min-width: 24px;
  margin-left: clamp(6px, 0.8vw, 12px);
  display: inline-flex;
  color: #1E3A5F;
  font-size: clamp(15px, 1.1vw, 20px);
  font-weight: 700;
  vertical-align: middle;
}

.game-settings__deck-header {
  margin-bottom: clamp(4px, 0.6vw, 8px);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px 6px;
}

.game-settings__deck-title {
  flex: 1;
  color: #1E3A5F;
  font-family: 'Montserrat Alternates', Montserrat, system-ui, sans-serif;
  font-size: clamp(14px, 1.1vw, 20px);
  font-weight: 700;
}

.game-settings__deck-links {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
}

.game-settings__link-button {
  border: 0;
  background: transparent;
  color: #3B7DD8;
  font: inherit;
  font-size: clamp(9px, 0.72vw, 13px);
  text-decoration: underline;
}

.game-settings__motion-list {
  align-content: flex-start;
  display: flex;
  flex-wrap: wrap;
  gap: clamp(4px, 0.4vw, 7px);
}

.game-settings__motion {
  padding: clamp(4px, 0.4vw, 6px) clamp(8px, 0.7vw, 12px);
  display: inline-flex;
  align-items: center;
  gap: clamp(3px, 0.4vw, 6px);
  border: 1px solid #C8DAF2;
  border-radius: 999px;
  background: #F2F6FC;
  color: #536276;
  font-size: clamp(11px, 0.82vw, 14px);
}

.game-settings__motion.is-active {
  background: #1E3A5F;
  color: #fff;
}

.game-settings__motion-icon {
  width: clamp(18px, 1.45vw, 26px);
  height: clamp(18px, 1.45vw, 26px);
  object-fit: contain;
}

.game-settings__section--actions {
  grid-column: 4;
  grid-row: 2;
  display: flex;
  flex-direction: column;
  justify-content: end;
  gap: clamp(8px, 0.8vw, 12px);
  min-height: 0;
  height: 100%;
}

.game-settings__rest {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #1E3A5F;
  font-weight: 700;
  line-height: 1.35;
  font-size: clamp(9px, 0.72vw, 13px);
}

.game-settings__generate {
  padding: clamp(8px, 0.7vw, 11px) clamp(14px, 1.2vw, 22px);
  border: 0;
  border-radius: 8px;
  background: linear-gradient(135deg, #1E3A5F, #2E5DA0);
  color: #fff;
  font-weight: 700;
  width: max-content;
  font-size: clamp(11px, 0.88vw, 15px);
}

.video-popup {
  position: fixed;
  inset: 0;
  z-index: 9000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(0, 0, 0, 0.5);
}

.video-popup--open {
  display: flex;
}

.video-popup__dialog {
  width: min(90vw, 600px);
  max-height: 80vh;
  overflow-y: auto;
  padding: 24px;
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 20px 60px rgba(15, 29, 47, 0.25);
}

.video-popup__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.video-popup__title {
  color: #1E3A5F;
  font-family: 'Montserrat Alternates', Montserrat, sans-serif;
  font-size: clamp(18px, 2vw, 24px);
}

.video-popup__close {
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 50%;
  background: #F2F6FC;
  color: #1E3A5F;
  font-size: 24px;
  line-height: 1;
}

.video-popup__chapter {
  padding: 18px 0;
  border-top: 1px solid #DDE7F4;
}

.video-popup__chapter:first-child {
  border-top: 0;
  padding-top: 0;
}

.video-popup__chapter-title {
  margin-bottom: 8px;
  color: #0F1D2F;
  font-family: 'Montserrat Alternates', Montserrat, sans-serif;
  font-size: clamp(16px, 1.5vw, 20px);
  font-weight: 700;
}

.video-popup__description {
  margin-bottom: 12px;
  color: #536276;
  font-size: clamp(13px, 1.1vw, 16px);
  line-height: 1.55;
}

.video-popup__iframe,
.video-popup__video-placeholder {
  width: 100%;
  min-height: 200px;
  border-radius: 10px;
}

.video-popup__iframe {
  border: 0;
  background: #0F1D2F;
}

.video-popup__video-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  background: #F2F6FC;
  color: #7A90AE;
  font-style: italic;
}

.video-popup__course-link {
  display: inline-flex;
  margin-top: 12px;
  color: #3B7DD8;
  font-weight: 700;
}
.card__start-word {
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.6s ease, transform 0.6s ease;
  font-size: clamp(18px, 1.5vw, 24px);
  font-weight: 700;
  color: #7A90AE;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.card__start-word--visible {
  opacity: 1;
  transform: translateY(0);
}
