/* ============================================================
   تمرین سالسا — تم تیره مینیمال
   ============================================================ */

@font-face {
  font-family: "Vazirmatn";
  src: url("../fonts/Vazirmatn.woff2") format("woff2-variations");
  font-weight: 100 900;
  font-display: swap;
}

:root {
  --bg: #0F1115;
  --card: #181B20;
  --border: rgba(255, 255, 255, .06);
  --accent: #5EEAD4;
  --text: #F8FAFC;
  --text-2: #94A3B8;
  --text-3: #475569;
  --danger: #EF4444;
  --success: #22C55E;
  --radius: 16px;
  --gap: clamp(8px, 1.6vh, 14px);
  --transition: 180ms ease;
}

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

html, body {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Vazirmatn", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
  touch-action: manipulation;
}

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

/* ---------- چیدمان کلی: یک ستون تمام‌صفحه بدون اسکرول ---------- */

.app {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  padding: calc(env(safe-area-inset-top, 0px) + var(--gap))
           max(var(--gap), env(safe-area-inset-right, 0px))
           calc(env(safe-area-inset-bottom, 0px) + var(--gap))
           max(var(--gap), env(safe-area-inset-left, 0px));
  max-width: 560px;
  margin-inline: auto;
}

.middle {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  justify-content: space-evenly;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(0, 0, 0, .25);
  padding: clamp(10px, 1.8vh, 16px) 16px;
}

.section-title {
  color: var(--text-2);
  font-size: clamp(.8rem, 1.8vh, .95rem);
  font-weight: 500;
}

/* ---------- تمپو ---------- */

.tempo {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.tempo-controls {
  display: flex;
  align-items: center;
  gap: clamp(10px, 3vw, 20px);
}

.tempo-btn {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  background: rgba(255, 255, 255, .05);
  border: 1px solid var(--border);
  font-size: 1.5rem;
  font-weight: 600;
  line-height: 1;
  transition: background var(--transition), transform var(--transition);
}

.tempo-btn:active { background: rgba(255, 255, 255, .12); transform: scale(.96); }

.tempo-value {
  min-width: 92px;
  text-align: center;
  display: flex;
  flex-direction: column;
  line-height: 1.1;
}

#tempo-number {
  font-size: clamp(1.7rem, 4.2vh, 2.3rem);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.tempo-unit {
  color: var(--text-2);
  font-size: .75rem;
  letter-spacing: .12em;
}

/* ---------- گام ---------- */

.key-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.key-select-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
}

#key-select {
  appearance: none;
  background: rgba(255, 255, 255, .05);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  font: inherit;
  font-size: 1.05rem;
  font-weight: 600;
  padding: 10px 18px;
  min-width: 72px;
  min-height: 48px;
  text-align: center;
  transition: border-color var(--transition);
}

/* ---------- سوییچ (تغییر خودکار گام / مترونوم) ---------- */

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  min-height: 48px;
  text-align: right;
}

.switch-label {
  font-size: clamp(.9rem, 2vh, 1.05rem);
  font-weight: 500;
}

.switch {
  flex: none;
  width: 48px;
  height: 28px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .1);
  border: 1px solid var(--border);
  position: relative;
  transition: background var(--transition);
}

.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  inset-inline-start: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--text-2);
  transition: transform var(--transition), background var(--transition);
}

.switch-row[aria-pressed="true"] .switch { background: var(--accent); }

.switch-row[aria-pressed="true"] .switch::after {
  background: var(--bg);
  transform: translateX(-20px); /* RTL: knob moves left */
}

/* ---------- سازها ---------- */

.instruments {
  display: flex;
  gap: var(--gap);
}

.instrument {
  flex: 1;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: clamp(8px, 1.6vh, 14px) 6px;
  min-height: 48px;
  cursor: pointer;
  transition: opacity var(--transition), border-color var(--transition), transform var(--transition);
}

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

/* دکمه تنظیمات سبک؛ نباید کارت را روشن/خاموش کند */
.inst-gear {
  position: absolute;
  top: 2px;
  inset-inline-start: 2px; /* در RTL یعنی سمت راست کارت */
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  transition: background var(--transition);
}

.inst-gear svg {
  width: 17px;
  height: 17px;
  fill: var(--text-2);
  transition: fill var(--transition), transform var(--transition);
}

.inst-gear:hover svg,
.inst-gear:active svg { fill: var(--text); transform: rotate(30deg); }

/* حتی وقتی ساز خاموش است، چرخ‌دنده کاملاً قابل استفاده بماند */
.instrument[aria-pressed="false"] .inst-gear { opacity: 1; }

.instrument:active { transform: scale(.97); }

.instrument[aria-pressed="true"] { border-color: rgba(94, 234, 212, .35); }

.instrument[aria-pressed="false"] { opacity: .5; }

.inst-icon { font-size: clamp(1.3rem, 3vh, 1.7rem); line-height: 1.2; }

.inst-name { font-weight: 600; font-size: clamp(.85rem, 2vh, 1rem); }

.inst-state { font-size: .72rem; color: var(--accent); }

.instrument[aria-pressed="false"] .inst-state { color: var(--text-3); }

/* ---------- شمارنده ---------- */

.counter-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: clamp(8px, 1.5vh, 14px);
  justify-items: center;
}

.count {
  width: clamp(48px, 8.5vh, 60px);
  height: clamp(48px, 8.5vh, 60px);
  border-radius: 50%;
  border: 2px solid var(--text-3);
  color: var(--text-2);
  font-size: clamp(1.05rem, 2.4vh, 1.3rem);
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition), color var(--transition),
              border-color var(--transition), box-shadow var(--transition),
              transform var(--transition);
}

.count[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--bg);
}

.count:active { transform: scale(.94); }

/* هایلایت زندهٔ شمارهٔ در حال پخش */
.count.playing {
  box-shadow: 0 0 0 4px rgba(94, 234, 212, .28);
  transform: scale(1.06);
}

/* ---------- کنترل پخش ---------- */

.transport {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(20px, 6vw, 36px);
  padding-block: clamp(4px, 1vh, 10px);
}

.transport-btn {
  width: clamp(56px, 8vh, 64px);
  height: clamp(56px, 8vh, 64px);
  border-radius: 50%;
  background: var(--card);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition), transform var(--transition),
              box-shadow var(--transition), opacity var(--transition);
}

.transport-btn svg {
  width: 44%;
  height: 44%;
  fill: var(--text);
}

.transport-btn:active { transform: scale(.94); }

.transport-btn.play {
  width: clamp(72px, 11vh, 88px);
  height: clamp(72px, 11vh, 88px);
  background: var(--accent);
  border: none;
  box-shadow: 0 6px 24px rgba(94, 234, 212, .3);
}

.transport-btn.play svg { fill: var(--bg); }

.transport-btn.play.is-playing { box-shadow: 0 6px 32px rgba(94, 234, 212, .45); }

.transport-btn[disabled] { opacity: .4; cursor: default; }

/* ---------- شیت پایین (انتخاب سبک صدا) ---------- */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(0, 0, 0, .55);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  opacity: 0;
  pointer-events: none; /* must not block the page when closed */
  transition: opacity 180ms ease;
}

/* class styles override the native [hidden] rule, so force it back */
.sheet-backdrop[hidden] {
  display: none !important;
}

.sheet-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.sheet {
  width: 100%;
  max-width: 560px;
  background: var(--card);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: 20px 20px 0 0;
  padding: 8px 16px calc(16px + env(safe-area-inset-bottom, 0px));
  box-shadow: 0 -8px 32px rgba(0, 0, 0, .45);
  transform: translateY(100%);
  transition: transform 200ms ease;
}

.sheet-backdrop.open .sheet { transform: translateY(0); }

.sheet-handle {
  width: 36px;
  height: 4px;
  border-radius: 999px;
  background: var(--text-3);
  margin: 4px auto 12px;
}

.sheet-title {
  font-size: 1.05rem;
  font-weight: 700;
  margin-bottom: 10px;
  text-align: center;
  color: var(--text);
}

.sheet-options {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sheet-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  min-height: 52px;
  padding: 0 14px;
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 500;
  color: var(--text);
  text-align: right;
  transition: background var(--transition), color var(--transition);
}

.sheet-option:active { background: rgba(255, 255, 255, .08); }

.sheet-option[aria-checked="true"] {
  color: var(--accent);
  background: rgba(94, 234, 212, .08);
}

.sheet-option .check {
  opacity: 0;
  font-weight: 700;
  transition: opacity var(--transition);
}

.sheet-option[aria-checked="true"] .check { opacity: 1; }

/* ---------- صفحه‌های خیلی کوتاه ---------- */

@media (max-height: 560px) {
  .inst-icon { display: none; }
  .tempo-unit { display: none; }
}
