@import url('https://fonts.googleapis.com/css2?family=Cairo:wght@400;500;600;700;800&display=swap');

:root {
  color-scheme: dark;
  --bg: #080b14;
  --bg-elevated: #0d1222;
  --surface: rgba(17, 23, 42, 0.86);
  --surface-solid: #11172a;
  --surface-soft: #151d35;
  --border: rgba(155, 171, 218, 0.14);
  --border-strong: rgba(139, 158, 219, 0.28);
  --text: #f6f7ff;
  --muted: #9ca8c7;
  --faint: #6e7897;
  --primary: #5b8cff;
  --primary-strong: #3673ff;
  --purple: #9b66ff;
  --danger: #ff6685;
  --success: #4fd6a1;
  --warning: #ffbf69;
  --shadow: 0 22px 70px rgba(0, 0, 0, 0.28);
  --radius-xl: 26px;
  --radius-lg: 18px;
  --radius-md: 12px;
  --focus: 0 0 0 3px rgba(91, 140, 255, 0.2);
}

html[data-theme="light"] {
  color-scheme: light;
  --bg: #f5f7ff;
  --bg-elevated: #edf1ff;
  --surface: rgba(255, 255, 255, 0.9);
  --surface-solid: #ffffff;
  --surface-soft: #f1f4ff;
  --border: rgba(42, 60, 116, 0.12);
  --border-strong: rgba(49, 77, 163, 0.23);
  --text: #151b31;
  --muted: #5e6a89;
  --faint: #8991aa;
  --primary: #3f74f5;
  --primary-strong: #255bdc;
  --purple: #7d4ee3;
  --danger: #d83f62;
  --success: #16855d;
  --warning: #aa6610;
  --shadow: 0 22px 60px rgba(53, 72, 130, 0.12);
}

*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 85% 0%, rgba(69, 102, 255, 0.12), transparent 30rem),
    radial-gradient(circle at 5% 38%, rgba(139, 80, 255, 0.09), transparent 26rem),
    var(--bg);
  color: var(--text);
  font-family: "Cairo", system-ui, -apple-system, "Segoe UI", sans-serif;
  line-height: 1.6;
  transition: background-color 220ms ease, color 220ms ease;
}

button, input { font: inherit; }
button { color: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button:focus-visible, a:focus-visible, input:focus-visible {
  outline: none;
  box-shadow: var(--focus);
}

.ambient {
  position: fixed;
  z-index: -1;
  width: 420px;
  height: 420px;
  border-radius: 50%;
  filter: blur(90px);
  opacity: 0.08;
  pointer-events: none;
}
.ambient-one { top: -170px; right: -120px; background: #366cff; }
.ambient-two { top: 48%; left: -250px; background: #8e4fff; }
.app-shell { width: min(1180px, calc(100% - 40px)); margin: 0 auto; }

.topbar {
  min-height: 96px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 12px; color: var(--text); text-decoration: none; }
.brand-mark {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: linear-gradient(145deg, var(--primary), var(--purple));
  box-shadow: 0 10px 25px rgba(71, 112, 255, 0.22);
  font-size: 23px;
}
.brand strong, .brand small { display: block; }
.brand strong { font-size: 16px; line-height: 1.35; }
.brand small { color: var(--muted); font-size: 11px; }

.theme-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  transition: border-color 180ms ease, transform 180ms ease;
}
.theme-toggle:hover { border-color: var(--border-strong); transform: translateY(-1px); }
.theme-toggle-track { position: relative; width: 52px; height: 26px; display: flex; align-items: center; justify-content: space-around; border-radius: 999px; background: var(--surface-soft); }
.theme-icon { z-index: 1; font-size: 12px; line-height: 1; }
.theme-toggle-thumb { position: absolute; top: 3px; right: 3px; width: 20px; height: 20px; border-radius: 50%; background: linear-gradient(145deg, var(--primary), var(--purple)); transition: transform 220ms ease; box-shadow: 0 4px 12px rgba(33, 51, 104, 0.3); }
html[data-theme="light"] .theme-toggle-thumb { transform: translateX(-26px); }

.hero { padding: 78px 0 58px; text-align: center; }
.eyebrow, .card-kicker, .section-kicker { color: var(--primary); font-size: 12px; font-weight: 700; letter-spacing: 0.04em; }
.eyebrow { display: inline-flex; align-items: center; gap: 9px; padding: 6px 12px; border: 1px solid rgba(91, 140, 255, 0.2); border-radius: 999px; background: rgba(91, 140, 255, 0.06); }
.eyebrow span { width: 6px; height: 6px; border-radius: 50%; background: var(--primary); box-shadow: 0 0 12px var(--primary); }
.hero h1 { margin: 18px 0 16px; font-size: clamp(42px, 7vw, 76px); line-height: 1.16; letter-spacing: -0.055em; }
.hero h1 span { background: linear-gradient(90deg, var(--primary), var(--purple)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.hero > p { width: min(620px, 100%); margin: 0 auto; color: var(--muted); font-size: 16px; }
.feature-pills { margin-top: 25px; display: flex; justify-content: center; flex-wrap: wrap; gap: 10px; }
.feature-pills span { padding: 7px 12px; border: 1px solid var(--border); border-radius: 999px; background: var(--surface); color: var(--muted); font-size: 11px; }

.calculators-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: start; }
.calculator-card, .result-card, .history-section {
  border: 1px solid var(--border);
  background: var(--surface);
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow);
}
.calculator-card { min-height: 535px; padding: 28px; border-radius: var(--radius-xl); }
.calculator-card:hover { border-color: var(--border-strong); }
.card-heading { display: flex; gap: 15px; margin-bottom: 26px; }
.card-icon { flex: 0 0 48px; height: 48px; display: grid; place-items: center; border: 1px solid rgba(91, 140, 255, 0.22); border-radius: 14px; background: rgba(91, 140, 255, 0.08); color: var(--primary); font-size: 20px; }
.video-card .card-icon { border-color: rgba(155, 102, 255, 0.22); background: rgba(155, 102, 255, 0.08); color: var(--purple); }
.card-heading h2, .section-heading h2 { margin: 2px 0 3px; font-size: 22px; }
.card-heading p, .section-heading p { margin: 0; color: var(--muted); font-size: 12px; }

.field-labels, .time-row { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)) 38px; gap: 8px; }
.field-labels { margin-bottom: 8px; padding: 0 3px; color: var(--muted); font-size: 10px; }
.rows-list { display: grid; gap: 9px; max-height: 240px; overflow: auto; padding: 2px; }
.time-row { animation: rowIn 260ms ease both; }
.time-row.removing, .video-link-item.removing { animation: rowOut 220ms ease both; pointer-events: none; }
.time-row label > span { display: none; }
input {
  width: 100%;
  height: 45px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-elevated);
  color: var(--text);
  caret-color: var(--primary);
  transition: border-color 180ms ease, box-shadow 180ms ease, background 180ms ease;
}
input::placeholder { color: var(--faint); }
input:hover { border-color: var(--border-strong); }
input:focus { border-color: var(--primary); box-shadow: var(--focus); outline: none; }
input.invalid { border-color: var(--danger); box-shadow: 0 0 0 3px rgba(255, 102, 133, 0.12); }
.time-input {
  direction: ltr;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.icon-button { width: 38px; height: 45px; display: grid; place-items: center; border: 1px solid transparent; border-radius: 11px; background: transparent; color: var(--faint); cursor: pointer; font-size: 20px; transition: 180ms ease; }
.icon-button:hover { border-color: rgba(255, 102, 133, 0.18); background: rgba(255, 102, 133, 0.08); color: var(--danger); }
.icon-button:disabled { opacity: 0.3; cursor: not-allowed; }
.icon-button:disabled:hover { border-color: transparent; background: transparent; color: var(--faint); }

.card-actions { display: flex; gap: 10px; margin-top: 22px; }
.button { min-height: 45px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 0 17px; border-radius: var(--radius-md); border: 1px solid transparent; cursor: pointer; font-weight: 700; font-size: 12px; transition: transform 180ms ease, filter 180ms ease, border-color 180ms ease, background 180ms ease; }
.button:hover { transform: translateY(-1px); }
.button:active { transform: translateY(0); }
.button:disabled { opacity: 0.55; cursor: wait; transform: none; }
.button-primary { flex: 1; background: linear-gradient(110deg, var(--primary-strong), var(--purple)); color: #fff; box-shadow: 0 10px 24px rgba(78, 103, 235, 0.2); }
.button-primary:hover { filter: brightness(1.08); }
.button-secondary { border-color: var(--border); background: var(--surface-soft); }
.button-secondary:hover { border-color: var(--border-strong); }

.auto-fetch-note {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 13px;
  padding: 10px 12px;
  border: 1px solid rgba(79, 214, 161, 0.18);
  border-radius: 13px;
  background: rgba(79, 214, 161, 0.05);
}
.auto-fetch-icon { width: 31px; height: 31px; display: grid; place-items: center; border-radius: 9px; background: rgba(79, 214, 161, 0.1); font-size: 13px; }
.auto-fetch-note strong { display: block; color: var(--success); font-size: 10px; }
.auto-fetch-note p { margin: 0; color: var(--muted); font-size: 9px; }
.link-composer { position: relative; display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.link-composer input { padding-right: 38px; direction: ltr; text-align: left; font-size: 11px; }
.input-leading { position: absolute; z-index: 1; right: 13px; top: 12px; font-size: 14px; }
.form-message { min-height: 20px; margin: 4px 3px 0; color: var(--danger); font-size: 10px; }
.video-links { min-height: 117px; max-height: 160px; overflow: auto; display: grid; align-content: start; gap: 8px; }
.empty-list { min-height: 110px; display: grid; place-items: center; align-content: center; gap: 4px; border: 1px dashed var(--border); border-radius: 13px; color: var(--faint); }
.empty-list span { font-size: 25px; }
.empty-list p { margin: 0; font-size: 11px; }
.video-link-item { display: grid; grid-template-columns: 31px 1fr auto 34px; gap: 9px; align-items: center; padding: 9px; border: 1px solid var(--border); border-radius: 12px; background: var(--bg-elevated); animation: rowIn 260ms ease both; }
.platform-badge { width: 31px; height: 31px; display: grid; place-items: center; border-radius: 9px; background: rgba(91, 140, 255, 0.1); font-size: 13px; }
.video-link-text { min-width: 0; direction: ltr; text-align: left; }
.video-link-text strong { display: block; overflow: hidden; color: var(--text); font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
.video-link-text small { display: block; color: var(--faint); font-size: 9px; }
.link-duration { color: var(--primary); font-size: 10px; white-space: nowrap; }
.link-duration.error { color: var(--danger); }
.link-duration.loading { color: var(--warning); }
.video-link-item .icon-button { width: 34px; height: 34px; }
.video-actions { align-items: center; justify-content: space-between; }
.links-count { color: var(--muted); font-size: 10px; }
.video-actions .button { flex: 0 1 210px; }

.results-section, .history-section { margin-top: 72px; }
.section-heading { display: flex; align-items: end; justify-content: space-between; margin-bottom: 20px; }
.section-heading h2 { font-size: 27px; }
.results-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.result-card { position: relative; overflow: hidden; min-height: 180px; padding: 24px; border-radius: var(--radius-lg); }
.result-card::after { content: ""; position: absolute; left: -35px; bottom: -60px; width: 160px; height: 160px; border-radius: 50%; background: var(--primary); filter: blur(65px); opacity: 0.08; }
.result-card:nth-child(2)::after { background: var(--purple); }
.result-meta { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 11px; }
.result-dot { width: 7px; height: 7px; border-radius: 50%; }
.result-dot-blue { background: var(--primary); box-shadow: 0 0 10px var(--primary); }
.result-dot-purple { background: var(--purple); box-shadow: 0 0 10px var(--purple); }
.result-placeholder { margin: 18px 0 2px; font-size: 34px; font-weight: 800; line-height: 1.2; font-variant-numeric: tabular-nums; }
.result-card > p { margin: 8px 0 0; color: var(--muted); font-size: 11px; }
.duration-parts { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 18px; direction: rtl; }
.duration-part { min-width: 70px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface-soft); text-align: center; }
.duration-part strong { display: block; direction: ltr; font-size: 22px; line-height: 1.25; font-variant-numeric: tabular-nums; }
.duration-part span { color: var(--muted); font-size: 9px; }
.result-note { color: var(--muted); }
.result-warning { color: var(--warning) !important; }
.result-error { color: var(--danger) !important; }
.result-card.result-updated { animation: resultPulse 500ms ease; }

.history-section { padding: 27px; border-radius: var(--radius-xl); }
.history-heading { align-items: center; }
.text-button { border: 0; background: transparent; color: var(--muted); cursor: pointer; font-size: 11px; }
.text-button:hover { color: var(--danger); }
.text-button:disabled { opacity: 0.4; cursor: not-allowed; }
.history-list { display: grid; gap: 8px; }
.history-empty { padding: 30px; border: 1px dashed var(--border); border-radius: 14px; text-align: center; color: var(--faint); font-size: 12px; }
.history-item { display: grid; grid-template-columns: 38px 1fr auto 34px; align-items: center; gap: 12px; padding: 11px 13px; border: 1px solid var(--border); border-radius: 13px; background: var(--bg-elevated); animation: rowIn 260ms ease both; }
.history-type { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 10px; background: rgba(91, 140, 255, 0.1); }
.history-item[data-type="فيديوهات"] .history-type { background: rgba(155, 102, 255, 0.1); }
.history-copy strong { display: block; font-size: 11px; }
.history-copy small { color: var(--faint); font-size: 9px; }
.history-result { color: var(--muted); font-size: 11px; text-align: left; font-variant-numeric: tabular-nums; }
.duration-probe { position: fixed; top: 0; left: -10000px; width: 200px; height: 200px; overflow: hidden; pointer-events: none; }
.history-delete { width: 34px; height: 34px; }


/* FAQ */
.faq-section {
  margin-top: 72px;
  padding: 27px;
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  background: var(--surface);
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow);
}
.faq-heading { align-items: end; }
.faq-list { display: grid; gap: 10px; }
.faq-item {
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--bg-elevated);
  transition: border-color 180ms ease, background 180ms ease, transform 180ms ease;
}
.faq-item:hover { border-color: var(--border-strong); }
.faq-item[open] {
  border-color: rgba(91, 140, 255, 0.3);
  background: linear-gradient(135deg, rgba(91, 140, 255, 0.055), rgba(155, 102, 255, 0.04)), var(--bg-elevated);
}
.faq-item summary {
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 16px;
  cursor: pointer;
  list-style: none;
  font-size: 12px;
  font-weight: 700;
  user-select: none;
}
.faq-item summary::-webkit-details-marker { display: none; }
.faq-item summary::marker { content: ""; }
.faq-item summary:focus-visible { outline: none; box-shadow: inset var(--focus); }
.faq-icon {
  flex: 0 0 30px;
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface-soft);
  color: var(--primary);
  font-size: 17px;
  line-height: 1;
  transition: transform 180ms ease, background 180ms ease, color 180ms ease, border-color 180ms ease;
}
.faq-item[open] .faq-icon {
  transform: rotate(45deg);
  border-color: rgba(91, 140, 255, 0.28);
  background: rgba(91, 140, 255, 0.1);
}
.faq-answer { padding: 0 16px 16px; }
.faq-answer::before {
  content: "";
  display: block;
  height: 1px;
  margin: 0 0 13px;
  background: var(--border);
}
.faq-answer p {
  width: min(850px, 100%);
  margin: 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.9;
}
.faq-answer [lang="en"], .faq-item summary [lang="en"] { direction: ltr; unicode-bidi: isolate; }

footer { min-height: 140px; display: flex; align-items: center; justify-content: space-between; color: var(--faint); font-size: 11px; }
footer a { color: var(--muted); text-decoration: none; }
footer a:hover { color: var(--primary); }
.toast { position: fixed; z-index: 20; left: 24px; bottom: 24px; max-width: min(360px, calc(100% - 48px)); padding: 12px 16px; border: 1px solid var(--border-strong); border-radius: 12px; background: var(--surface-solid); box-shadow: var(--shadow); color: var(--text); font-size: 11px; transform: translateY(25px); opacity: 0; pointer-events: none; transition: 240ms ease; }
.toast.visible { transform: translateY(0); opacity: 1; }
.noscript { position: fixed; inset: auto 20px 20px; z-index: 30; padding: 14px; border-radius: 12px; background: #7b2036; color: white; text-align: center; }
.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

@keyframes rowIn { from { opacity: 0; transform: translateY(-7px) scale(0.985); } to { opacity: 1; transform: none; } }
@keyframes rowOut { to { opacity: 0; transform: translateX(-15px) scale(0.98); } }
@keyframes resultPulse { 0% { transform: scale(0.99); border-color: var(--primary); } 100% { transform: none; } }

@media (max-width: 900px) {
  .calculators-grid, .results-grid { grid-template-columns: 1fr; }
  .calculator-card { min-height: auto; }
}

@media (max-width: 620px) {
  .app-shell { width: min(100% - 24px, 1180px); }
  .topbar { min-height: 78px; }
  .theme-toggle > span:last-child, .brand small { display: none; }
  .hero { padding: 54px 0 42px; }
  .hero h1 { font-size: clamp(38px, 13vw, 56px); }
  .hero > p { font-size: 13px; }
  .calculator-card { padding: 20px 16px; border-radius: 20px; }
  .field-labels { display: none; }
  .time-row { grid-template-columns: repeat(2, 1fr) 36px; padding: 10px; border: 1px solid var(--border); border-radius: 14px; }
  .time-row label > span { display: block; margin-bottom: 4px; color: var(--muted); font-size: 9px; }
  .time-row .icon-button { grid-column: 3; grid-row: 1 / span 2; align-self: center; }
  .link-composer { grid-template-columns: 1fr; }
  .link-composer .button { width: 100%; }
  .video-link-item { grid-template-columns: 31px 1fr 34px; }
  .link-duration { grid-column: 2; }
  .video-link-item .icon-button { grid-column: 3; grid-row: 1 / span 2; }
  .section-heading { align-items: start; }
  .section-heading > p { display: none; }
  .history-section { margin-top: 50px; padding: 20px 15px; }
  .faq-section { margin-top: 50px; padding: 20px 15px; }
  .faq-item summary { min-height: 54px; padding: 12px 13px; font-size: 11px; }
  .faq-answer { padding: 0 13px 13px; }
  .history-item { grid-template-columns: 38px 1fr 34px; }
  .history-result { grid-column: 2; text-align: right; }
  .history-delete { grid-column: 3; grid-row: 1 / span 2; }
  footer { min-height: 110px; }
}

@media (max-width: 410px) {
  .card-actions { flex-direction: column; }
  .card-actions .button { width: 100%; flex-basis: auto; }
  .video-actions .links-count { text-align: center; }
  .duration-part { flex: 1; min-width: 58px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
