/* ==========================================================================
   Design tokens (Apple HIG semantics). Components use var(--token) only;
   component-specific styling lives in each component's .razor.css.
   ========================================================================== */

/* Fonts are bundled with the app (wwwroot/fonts) — never loaded from a third-party service.
   Vazirmatn (SIL OFL, see fonts/Vazirmatn-OFL.txt) ships today. The project font PeydaWeb is commercial:
   once its woff2 files are added to wwwroot/fonts, declare @font-face blocks for it like the ones below;
   it is already first in --font-fa, so it takes over without other changes. */
@font-face { font-family: "Vazirmatn"; src: url("../fonts/Vazirmatn-Regular.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Vazirmatn"; src: url("../fonts/Vazirmatn-Medium.woff2") format("woff2"); font-weight: 500; font-display: swap; }
@font-face { font-family: "Vazirmatn"; src: url("../fonts/Vazirmatn-SemiBold.woff2") format("woff2"); font-weight: 600; font-display: swap; }
@font-face { font-family: "Vazirmatn"; src: url("../fonts/Vazirmatn-Bold.woff2") format("woff2"); font-weight: 700; font-display: swap; }

:root {
  --font-latin: -apple-system, BlinkMacSystemFont, "PeydaWeb", "Segoe UI", system-ui, sans-serif;
  --font-fa: "PeydaWeb", "Vazirmatn", "SF Pro Text", Tahoma, var(--font-latin);

  --text-large-title: 2.125rem; /* 34 */
  --text-title1: 1.75rem;       /* 28 */
  --text-title2: 1.375rem;      /* 22 */
  --text-title3: 1.25rem;       /* 20 */
  --text-headline: 1.0625rem;   /* 17 */
  --text-body: 1.0625rem;       /* 17 */
  --text-callout: 1rem;         /* 16 */
  --text-subhead: 0.9375rem;    /* 15 */
  --text-footnote: 0.8125rem;   /* 13 */
  --text-caption1: 0.75rem;     /* 12 */
  --text-caption2: 0.6875rem;   /* 11 */

  --color-blue: #007AFF;
  --color-green: #34C759;
  --color-red: #FF3B30;
  --color-orange: #FF9500;
  --color-yellow: #FFCC00;
  --color-purple: #AF52DE;
  --color-pink: #FF2D55;
  --color-teal: #5AC8FA;
  --color-indigo: #5856D6;

  --accent: var(--color-pink);
  --on-accent: #FFFFFF;
  --danger: var(--color-red);
  --success: var(--color-green);

  --label: #000000;
  --label-secondary: rgba(60, 60, 67, 0.6);
  --label-tertiary: rgba(60, 60, 67, 0.3);
  --background: #FFFFFF;
  --background-grouped: #F2F2F7;
  --background-secondary: #FFFFFF;
  --separator: rgba(60, 60, 67, 0.29);
  --fill: rgba(120, 120, 128, 0.2);
  --fill-strong: rgba(120, 120, 128, 0.32);
  --shadow-soft: 0 1px 2px rgba(0, 0, 0, 0.06), 0 8px 24px rgba(0, 0, 0, 0.06);
  --scrim: rgba(0, 0, 0, 0.35);

  --glass-bg: rgba(255, 255, 255, 0.62);
  --glass-border: rgba(255, 255, 255, 0.35);
  --glass-shadow: 0 8px 32px rgba(0, 0, 0, 0.1), inset 0 1px 0 rgba(255, 255, 255, 0.45);

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;

  --radius-xs: 6px;
  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-xl: 28px;
  --radius-full: 999px;

  --tap-min: 44px;

  /* ---- Layout (size classes) ----
     compact  < 768px   : phone   — bottom tab bar + mini player + full-screen player sheet
     regular  768–1099  : tablet  — icon rail sidebar + floating player bar + overlay player panel
     wide     ≥ 1100px  : desktop — full sidebar + floating player bar + player panel
     x-wide   ≥ 1440px  : desktop — player panel docks beside the content instead of covering it
     Media queries cannot read custom properties, so these numbers are repeated in the media queries;
     components react to their own width with container queries instead. */
  --page-pad: var(--space-4);
  --sidebar-w: 0px;
  --panel-w: 0px;
  --content-max: 1680px;
  --tabbar-height: 64px;
  --miniplayer-height: 64px;
  --playerbar-height: 84px;
  --ease-spring: cubic-bezier(0.2, 0.9, 0.25, 1.15);
  --ease-out: cubic-bezier(0.2, 0.8, 0.2, 1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --label: #FFFFFF;
    --label-secondary: rgba(235, 235, 245, 0.6);
    --label-tertiary: rgba(235, 235, 245, 0.3);
    --background: #000000;
    --background-grouped: #1C1C1E;
    --background-secondary: #2C2C2E;
    --separator: rgba(84, 84, 88, 0.6);
    --fill: rgba(120, 120, 128, 0.36);
    --fill-strong: rgba(120, 120, 128, 0.5);
    --shadow-soft: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.35);
    --scrim: rgba(0, 0, 0, 0.55);
    --glass-bg: rgba(30, 30, 32, 0.62);
    --glass-border: rgba(255, 255, 255, 0.08);
    --glass-shadow: 0 8px 32px rgba(0, 0, 0, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.06);
  }
}

/* ---------- base ---------- */

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--background);
  color: var(--label);
  font-family: var(--font-fa);
  font-size: 100%;
  line-height: 1.75; /* a bit taller than Latin, for Persian script */
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  /* iOS: keep our type scale on rotation, no grey flash on tap. */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-size: var(--text-body);
  /* Safety net against sideways scrolling; clip (unlike hidden) keeps position: sticky working. */
  overflow-x: clip;
}

h1, h2, h3, h4 { margin: 0; line-height: 1.35; font-weight: 700; }

a { color: inherit; text-decoration: none; }

img { display: block; max-width: 100%; }

button { font: inherit; color: inherit; }

/* Native feel: controls do not start text selection or the iOS long-press callout, and respond to taps
   immediately (no double-tap-zoom delay). Text inputs keep the default behaviour. */
button, a, [role="button"], .icon-btn, img {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
}

/* iOS zooms the page when a focused field's text is under 16px. */
input, select, textarea { font-size: max(16px, 1em); }

/* Opened from the home screen (iOS/Android standalone): there is no browser chrome, so the rubber-band
   overscroll of the whole page would show the empty canvas behind the app. */
@media (display-mode: standalone) {
  html { overscroll-behavior-y: none; }
}

[dir="ltr"], .ltr { direction: ltr; unicode-bidi: isolate; }

/* Keyboard focus stays visible on every surface, glass included. */
:focus { outline: none; }
:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-xs);
}

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------- control layer (Liquid Glass): bars, sheets, floating buttons only ---------- */

.liquid-glass {
  background: var(--glass-bg);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border: 1px solid var(--glass-border);
  box-shadow: var(--glass-shadow);
}

/* ---------- shared primitives (the design system's buttons and fields) ---------- */

.btn-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--tap-min);
  padding-inline: var(--space-5);
  border: 0;
  border-radius: var(--radius-full);
  background: var(--accent);
  color: var(--on-accent);
  font-size: var(--text-headline);
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s var(--ease-out), opacity 0.15s;
}
.btn-pill:active { transform: scale(0.97); }
.btn-pill:disabled { opacity: 0.45; cursor: default; transform: none; }
.btn-pill.secondary { background: var(--fill); color: var(--accent); }
.btn-pill.block { width: 100%; }

.btn-text {
  display: inline-flex;
  align-items: center;
  min-height: var(--tap-min);
  padding-inline: var(--space-2);
  border: 0;
  background: none;
  color: var(--accent);
  font-size: var(--text-callout);
  cursor: pointer;
}
.btn-text:disabled { color: var(--label-tertiary); cursor: default; }

.form { display: grid; gap: var(--space-4); }

.field { display: grid; gap: var(--space-1); }
.field label { font-size: var(--text-footnote); color: var(--label-secondary); padding-inline-start: var(--space-3); }
.field input {
  min-height: var(--tap-min);
  padding: var(--space-3) var(--space-4);
  border: 0;
  border-radius: var(--radius-sm);
  background: var(--fill);
  color: var(--label);
  font: inherit;
  font-size: var(--text-body);
}
.field input::placeholder { color: var(--label-tertiary); }
/* One-time code: Latin and LTR, the only place letter-spacing is allowed. */
.field input.code-input {
  text-align: center;
  font-size: var(--text-title2);
  letter-spacing: 0.4em;
  font-variant-numeric: tabular-nums;
}
.field .hint { font-size: var(--text-footnote); color: var(--label-secondary); padding-inline-start: var(--space-3); line-height: 1.6; }
.field .error { font-size: var(--text-footnote); color: var(--danger); padding-inline-start: var(--space-3); }

/* Slider (seek bar, volume). Media timelines stay LTR even in RTL: markup sets dir="ltr" and --fill. */
.range {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 28px;
  margin: 0;
  background: transparent;
  cursor: pointer;
  --track: var(--fill);
  --done: var(--label-secondary);
}
.range::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: var(--radius-full);
  background: linear-gradient(to right, var(--done) var(--fill-pct, 0%), var(--track) var(--fill-pct, 0%));
}
.range::-moz-range-track {
  height: 4px;
  border-radius: var(--radius-full);
  background: linear-gradient(to right, var(--done) var(--fill-pct, 0%), var(--track) var(--fill-pct, 0%));
}
.range::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px; height: 14px;
  margin-top: -5px;
  border-radius: var(--radius-full);
  background: var(--label);
  opacity: 0;
  transition: opacity 0.15s;
}
.range::-moz-range-thumb { width: 14px; height: 14px; border: 0; border-radius: var(--radius-full); background: var(--label); opacity: 0; }
.range:hover::-webkit-slider-thumb, .range:focus-visible::-webkit-slider-thumb, .range.always::-webkit-slider-thumb { opacity: 1; }
.range:hover::-moz-range-thumb, .range:focus-visible::-moz-range-thumb, .range.always::-moz-range-thumb { opacity: 1; }
.range:hover { --done: var(--accent); }

/* Round icon button used across bars and panels. */
.icon-btn {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: var(--tap-min);
  height: var(--tap-min);
  border: 0;
  border-radius: var(--radius-full);
  background: none;
  color: var(--label);
  cursor: pointer;
  transition: background 0.15s, transform 0.15s var(--ease-out), color 0.15s;
}
.icon-btn:hover { background: var(--fill); }
.icon-btn:active { transform: scale(0.92); }
.icon-btn:disabled { color: var(--label-tertiary); background: none; cursor: default; transform: none; }
.icon-btn.on { color: var(--accent); }

.alert {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-sm);
  font-size: var(--text-subhead);
  line-height: 1.7;
}
.alert.error { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }
.alert.info { background: var(--fill); color: var(--label); }
.alert.success { background: color-mix(in srgb, var(--success) 16%, transparent); color: var(--label); }

/* ---------- Blazor shell ---------- */

#blazor-error-ui {
  display: none;
  position: fixed;
  inset-inline: var(--space-4);
  bottom: var(--space-4);
  z-index: 1000;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  background: var(--danger);
  color: #fff;
}
#blazor-error-ui .reload { color: #fff; text-decoration: underline; margin-inline-start: var(--space-3); }
#blazor-error-ui .dismiss { cursor: pointer; float: inline-end; }

/* Branded boot screen shown until WebAssembly has started. */
.boot {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  align-content: center;
  gap: var(--space-5);
  background: var(--background);
}
.boot-logo {
  width: 88px; height: 88px;
  border-radius: 22px;
  background: linear-gradient(145deg, var(--color-pink), var(--color-red));
  display: grid; place-items: center;
  box-shadow: var(--shadow-soft);
  animation: boot-pulse 1.6s ease-in-out infinite;
}
.boot-logo svg { width: 48px; height: 48px; }
.boot-title { font-size: var(--text-title3); font-weight: 700; }
.boot-skeleton { display: flex; gap: var(--space-3); }
.boot-skeleton span {
  width: 96px; height: 96px;
  border-radius: var(--radius-md);
  background: var(--fill);
  animation: boot-shimmer 1.4s ease-in-out infinite;
}
.boot-skeleton span:nth-child(2) { animation-delay: 0.15s; }
.boot-skeleton span:nth-child(3) { animation-delay: 0.3s; }
.boot-bar { width: 160px; height: 4px; border-radius: var(--radius-full); background: var(--fill); overflow: hidden; }
.boot-bar::after {
  content: "";
  display: block;
  height: 100%;
  width: var(--blazor-load-percentage, 10%);
  background: var(--accent);
  transition: width 0.2s;
}
@keyframes boot-pulse { 50% { transform: scale(0.94); } }
@keyframes boot-shimmer { 50% { opacity: 0.45; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
