/* Tennis Analyzer — app styles (responsive, RTL-aware) */
:root {
  --bg: #0f172a;
  --bg-soft: #1e293b;
  --card: #1e293b;
  --card-hover: #27364d;
  --border: #334155;
  --text: #e2e8f0;
  --text-dim: #94a3b8;
  --accent: #a3e635;
  /* tennis-ball green */
  --accent-dark: #65a30d;
  --accent-text: #0f172a;
  --danger: #f87171;
  --ok: #4ade80;
  --radius: 14px;
  --nav-h: 64px;
  --shadow: 0 4px 16px rgba(0, 0, 0, .35);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', Vazirmatn, Tahoma, system-ui, sans-serif;
  min-height: 100vh;
}

[dir="rtl"] body {
  font-family: Vazirmatn, Tahoma, 'Segoe UI', system-ui, sans-serif;
}

/* ---------- layout ---------- */
.app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ---------- install banner ---------- */
.install-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: linear-gradient(90deg, #1e3a1e 0%, #1e2e1e 100%);
  border-bottom: 2px solid var(--accent);
  position: sticky;
  top: 0;
  z-index: 30;
  flex-shrink: 0;
  animation: bannerSlide .35s cubic-bezier(.25,.8,.25,1);
}

@keyframes bannerSlide {
  from { transform: translateY(-100%); opacity: 0; }
  to   { transform: translateY(0);     opacity: 1; }
}

.install-banner.hidden {
  display: none;
}

.install-banner-ico {
  font-size: 1.4rem;
  flex-shrink: 0;
}

.install-banner-text {
  flex: 1;
  font-size: .88rem;
  color: var(--text);
  min-width: 0;
}

.install-banner #installBannerBtn {
  flex-shrink: 0;
  padding: 7px 16px;
  font-size: .85rem;
  border-radius: 8px;
}

.install-banner-close {
  flex-shrink: 0;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  transition: color .15s, background .15s;
  line-height: 1;
}

.install-banner-close:hover {
  color: var(--text);
  background: rgba(255,255,255,.08);
}

/* iOS-only: no Install button, just a hint */
.install-banner.ios-mode #installBannerBtn {
  display: none;
}

.install-banner.ios-mode .install-banner-text {
  font-size: .82rem;
  color: #d1fae5;
}



.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: rgba(15, 23, 42, .92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}

.topbar .logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 1.05rem;
}

.topbar .logo .ball {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, #d9f99d, var(--accent) 60%, var(--accent-dark));
  box-shadow: 0 0 8px rgba(163, 230, 53, .6);
}

.spacer {
  flex: 1;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 999px;
  background: var(--bg-soft);
  border: 1px solid #475569;
  color: var(--text);
  font-family: inherit;
  font-size: .88rem;
  font-weight: 600;
  cursor: pointer;
}

.chip:hover {
  background: var(--card-hover);
  border-color: var(--accent);
}

.chip.credit b {
  color: var(--accent);
}

.chip.credit.low b {
  color: var(--danger);
}

main {
  flex: 1;
  width: 100%;
  max-width: 960px;
  margin: 0 auto;
  padding: 20px 16px calc(var(--nav-h) + 24px);
}

/* ---------- navigation ---------- */
.nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 20;
  display: flex;
  justify-content: space-around;
  height: var(--nav-h);
  background: rgba(15, 23, 42, .95);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--border);
}

.nav button {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: .68rem;
  font-family: inherit;
  cursor: pointer;
  padding: 6px 2px;
}

.nav button .ico {
  font-size: 1.25rem;
  line-height: 1;
}

.nav button.active {
  color: var(--accent);
}

@media (min-width: 900px) {
  .app {
    flex-direction: row;
  }

  .nav {
    position: sticky;
    top: 0;
    flex-direction: column;
    justify-content: flex-start;
    gap: 4px;
    width: 200px;
    height: 100vh;
    padding-top: 70px;
    border-top: none;
    border-inline-end: 1px solid var(--border);
  }

  .nav button {
    flex: 0 0 auto;
    flex-direction: row;
    justify-content: flex-start;
    gap: 12px;
    padding: 12px 20px;
    font-size: .9rem;
  }

  .topbar {
    position: fixed;
    left: 0;
    right: 0;
  }

  main {
    padding-top: 80px;
  }
}

/* ---------- generic components ---------- */
.view {
  display: none;
  animation: fade .25s ease;
}

.view.active {
  display: block;
}

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

  to {
    opacity: 1;
  }
}

h1 {
  font-size: 1.45rem;
  margin: 0 0 2px;
}

.subtitle {
  color: var(--text-dim);
  margin: 0 0 20px;
  font-size: .92rem;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.grid {
  display: grid;
  gap: 12px;
}

.grid.cols-2 {
  grid-template-columns: repeat(2, 1fr);
}

.grid.cols-4 {
  grid-template-columns: repeat(2, 1fr);
}

@media (min-width: 640px) {
  .grid.cols-4 {
    grid-template-columns: repeat(4, 1fr);
  }
}

.stat {
  text-align: center;
  padding: 14px 8px;
}

.stat .value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--accent);
}

.stat .label {
  font-size: .78rem;
  color: var(--text-dim);
  margin-top: 2px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 20px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--text);
  font-family: inherit;
  font-size: .95rem;
  cursor: pointer;
  transition: background .15s;
}

.btn:hover {
  background: var(--card-hover);
}

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  font-weight: 700;
}

.btn.primary:hover {
  background: #bef264;
}

.btn.danger {
  color: var(--danger);
  border-color: var(--danger);
  background: transparent;
}

.btn.block {
  width: 100%;
}

.btn:disabled {
  opacity: .45;
  cursor: not-allowed;
}

.btn.recording {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
  animation: pulse 1s infinite;
}

@keyframes pulse {
  50% {
    opacity: .65;
  }
}

label.field {
  display: block;
  margin-bottom: 14px;
}

label.field span {
  display: block;
  font-size: .85rem;
  color: var(--text-dim);
  margin-bottom: 6px;
}

select,
input[type="text"],
input[type="email"],
input[type="password"] {
  width: 100%;
  padding: 11px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: .95rem;
}

.seg {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}

.seg button {
  flex: 1;
  padding: 10px;
  background: var(--bg);
  border: none;
  color: var(--text-dim);
  font-family: inherit;
  font-size: .9rem;
  cursor: pointer;
}

.seg button.active {
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 700;
}

.toast {
  position: fixed;
  bottom: calc(var(--nav-h) + 16px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 50;
  background: var(--card);
  border: 1px solid var(--accent);
  color: var(--text);
  padding: 12px 22px;
  border-radius: 999px;
  box-shadow: var(--shadow);
  font-size: .9rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity .3s;
  max-width: 90vw;
  text-align: center;
}

.toast.show {
  opacity: 1;
}

.toast.error {
  border-color: var(--danger);
}

/* ---------- capture view ---------- */
.camera-wrap {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  background: #000;
  aspect-ratio: 9 / 14;
  max-height: 62vh;
  margin: 0 auto 14px;
}

@media (min-width: 640px) {
  .camera-wrap {
    aspect-ratio: 16 / 10;
  }
}

.camera-wrap video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.guide-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.guide-overlay svg {
  width: 100%;
  height: 100%;
}

.guide-hint {
  position: absolute;
  bottom: 10px;
  left: 0;
  right: 0;
  text-align: center;
  font-size: .8rem;
  color: #fff;
  text-shadow: 0 1px 4px #000;
  padding: 0 12px;
}

.rec-dot {
  position: absolute;
  top: 12px;
  inset-inline-end: 12px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--danger);
  animation: pulse 1s infinite;
  display: none;
}

.rec-dot.on {
  display: block;
}

.controls-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.controls-row .btn {
  flex: 1;
  min-width: 120px;
}

/* ---------- in-camera record bar ---------- */
.cam-record-bar {
  position: absolute;
  bottom: 18px;
  left: 0;
  right: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}

.rec-timer {
  background: rgba(0, 0, 0, .6);
  color: #fff;
  font-size: .85rem;
  font-weight: 700;
  letter-spacing: .08em;
  padding: 3px 12px;
  border-radius: 999px;
  backdrop-filter: blur(4px);
}

/* Solid red circle = ready to record */
.rec-circle-btn {
  pointer-events: auto;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--danger);
  border: 3px solid rgba(255,255,255,.85);
  cursor: pointer;
  transition: transform .15s, box-shadow .15s, background .2s, border-radius .25s;
  box-shadow: 0 0 0 0 rgba(248, 113, 113, .6);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.rec-circle-btn:hover {
  transform: scale(1.08);
  box-shadow: 0 0 0 8px rgba(248, 113, 113, .25);
}

/* Stop state: hollow circle + inner square */
.rec-circle-btn.recording {
  background: transparent;
  border-color: var(--danger);
  animation: rec-pulse 1.2s infinite;
}

.rec-circle-btn.recording::before {
  content: '';
  display: block;
  width: 20px;
  height: 20px;
  border-radius: 4px;
  background: var(--danger);
}

@keyframes rec-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(248, 113, 113, .5); }
  50%       { box-shadow: 0 0 0 10px rgba(248, 113, 113, 0); }
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.trim-fields {
  margin-top: 12px;
}

.trim-fields .field {
  margin-bottom: 8px;
}

.trim-fields b {
  color: var(--accent);
}

[dir="rtl"] .trim-labels {
  flex-direction: row-reverse;
}

/* ---------- dual range slider ---------- */
.dual-range {
  position: relative;
  width: 100%;
  height: 32px;
  direction: ltr;
}

.dual-range input[type="range"] {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 32px;
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  pointer-events: none;
  z-index: 2;
  margin: 0;
  outline: none;
}

.dual-range input[type="range"]::-webkit-slider-thumb {
  pointer-events: auto;
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  position: relative;
  box-shadow: 0 0 4px rgba(0, 0, 0, 0.5);
}

.dual-range input[type="range"]::-moz-range-thumb {
  pointer-events: auto;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: none;
  box-shadow: 0 0 4px rgba(0, 0, 0, 0.5);
}

.dual-range-track {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  left: 0;
  right: 0;
  height: 6px;
  background: var(--bg);
  border-radius: 999px;
  z-index: 1;
}

.dual-range-fill {
  position: absolute;
  top: 0;
  bottom: 0;
  background: var(--accent);
  border-radius: 999px;
  opacity: 0.6;
}

.trim-duration {
  font-size: .9rem;
  font-weight: 700;
  color: var(--accent);
  margin: 0 0 12px;
}

.trim-duration.over {
  color: var(--danger);
}

video.preview {
  width: 100%;
  border-radius: var(--radius);
  background: #000;
  max-height: 50vh;
}

.progress {
  height: 8px;
  background: var(--bg);
  border-radius: 999px;
  overflow: hidden;
  margin: 10px 0;
}

.progress>div {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width .2s;
}

/* ---------- sample result ---------- */
.sample-banner {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  background: rgba(163, 230, 53, .08);
  border: 1px solid var(--accent-dark);
  border-radius: var(--radius);
  padding: 12px 14px;
  font-size: .85rem;
  margin-bottom: 16px;
}

.gauge {
  position: relative;
  width: 150px;
  height: 150px;
  margin: 8px auto 14px;
}

.gauge svg {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.gauge circle {
  fill: none;
  stroke-width: 9;
  stroke-linecap: round;
}

.gauge-bg {
  stroke: var(--bg);
}

.gauge-fg {
  stroke: var(--accent);
  stroke-dasharray: 339.29;
  stroke-dashoffset: 339.29;
  transition: stroke-dashoffset 1.2s cubic-bezier(.4, 0, .2, 1);
}

.gauge-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.gauge-center span {
  font-size: 2.1rem;
  font-weight: 800;
  line-height: 1;
}

.gauge-center small {
  color: var(--text-dim);
  font-size: .72rem;
  margin-top: 2px;
}

.badge-row {
  display: flex;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
}

.badge.big {
  font-size: .8rem;
  padding: 5px 12px;
}

.ph-tabs {
  display: flex;
  gap: 6px;
  background: var(--bg);
  border-radius: 12px;
  padding: 4px;
}

.ph-tabs button {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 4px;
  border: none;
  border-radius: 9px;
  background: transparent;
  color: var(--text-dim);
  font-family: inherit;
  font-size: .78rem;
  cursor: pointer;
  transition: background .15s, color .15s;
}

.ph-tabs button.active {
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 700;
}

.ph-tabs .ph-num {
  width: 17px;
  height: 17px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .12);
  font-size: .68rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.ph-tabs button.active .ph-num {
  background: rgba(0, 0, 0, .18);
}

.keyframe-wrap {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  margin-top: 12px;
  background: #000;
  min-height: 120px;
}

.keyframe-wrap img {
  width: 100%;
  display: block;
  transition: opacity .2s;
}

.phase-score-chip {
  position: absolute;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(0, 0, 0, .72);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 14px;
  font-size: .72rem;
  color: var(--text-dim);
  white-space: nowrap;
}

.phase-score-chip b {
  font-size: .95rem;
  color: var(--accent);
}

.phase-score-chip b.mid {
  color: #facc15;
}

.phase-score-chip b.low {
  color: var(--danger);
}

.angle-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.angle-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
}

.angle-card .joint {
  font-size: .74rem;
  color: var(--text-dim);
}

.angle-card .val {
  font-size: 1.25rem;
  font-weight: 700;
  margin: 2px 0;
}

.angle-card .ideal {
  font-size: .7rem;
}

.angle-card .ideal.ok {
  color: var(--ok);
}

.angle-card .ideal.mid {
  color: #facc15;
}

.angle-card .ideal.bad {
  color: var(--danger);
}

.tip-card {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 8px;
  font-size: .86rem;
  line-height: 1.6;
}

.tip-card .tip-num {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: rgba(163, 230, 53, .15);
  color: var(--accent);
  font-size: .72rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-top: 2px;
}

.guide-list {
  list-style: none;
  margin: 12px 0 0;
  padding: 0;
}

.guide-list li {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: .86rem;
  line-height: 1.6;
}

.guide-list li:last-child {
  border-bottom: none;
}

/* ---------- history ---------- */
.hist-item {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.hist-head {
  display: flex;
  align-items: center;
  gap: 12px;
}

.score-ring {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1rem;
  flex-shrink: 0;
  border: 4px solid var(--accent);
}

.score-ring.mid {
  border-color: #facc15;
}

.score-ring.low {
  border-color: var(--danger);
}

.hist-meta {
  flex: 1;
  min-width: 0;
}

.hist-meta .stroke-name {
  font-weight: 700;
}

.hist-meta .sub {
  color: var(--text-dim);
  font-size: .8rem;
}

.angles {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.angles .angle {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: .78rem;
}

.angles .angle b {
  color: var(--accent);
}

.hist-actions {
  display: flex;
  gap: 8px;
}

.badge {
  font-size: .68rem;
  background: var(--bg);
  border: 1px solid var(--ok);
  color: var(--ok);
  border-radius: 999px;
  padding: 2px 8px;
}

/* ---------- reports ---------- */
.bar-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.bar-row .bar-label {
  width: 130px;
  font-size: .78rem;
  color: var(--text-dim);
  flex-shrink: 0;
}

.bar-row .bar-track {
  flex: 1;
  height: 14px;
  background: var(--bg);
  border-radius: 999px;
  overflow: hidden;
}

.bar-row .bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent-dark), var(--accent));
  border-radius: 999px;
}

.bar-row .bar-val {
  width: 34px;
  font-size: .8rem;
  text-align: end;
}

.trend {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  height: 120px;
  padding-top: 8px;
}

.trend .t-bar {
  flex: 1;
  background: linear-gradient(180deg, var(--accent), var(--accent-dark));
  border-radius: 4px 4px 0 0;
  min-height: 6px;
}

/* ---------- modal ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .6);
  z-index: 40;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-backdrop.open {
  display: flex;
}

.modal {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow);
}

.modal h2 {
  margin: 0 0 14px;
  font-size: 1.15rem;
}

.pack {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 10px;
  cursor: pointer;
  transition: border-color .15s;
}

.pack:hover {
  border-color: var(--accent);
}

.pack .price {
  color: var(--accent);
  font-weight: 700;
}

/* ---------- login ---------- */
.login-card {
  max-width: 380px;
  margin: 8vh auto 0;
}

.login-logo {
  text-align: center;
  margin-bottom: 18px;
}

.login-logo .ball {
  width: 54px;
  height: 54px;
  margin: 0 auto 10px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, #d9f99d, var(--accent) 60%, var(--accent-dark));
  box-shadow: 0 0 24px rgba(163, 230, 53, .5);
}

.hint {
  font-size: .78rem;
  color: var(--text-dim);
}

.hidden {
  display: none !important;
}