/* كابتن ماجد — app shell styles.
   Dark, high-contrast, thumb-reachable. Everything is RTL-first. */

/* Cairo, self-hosted. One variable file covers every weight, and no request
   ever leaves this origin — which the app's CSP requires and the gym's phone
   signal appreciates. */
@font-face {
  font-family: 'Cairo';
  font-style: normal;
  font-weight: 200 1000;
  font-display: swap;
  src: url('../fonts/cairo-arabic.woff2') format('woff2');
  unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+0890-0891, U+0897-08E1,
                 U+08E3-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41,
                 U+FB50-FDFF, U+FE70-FE74, U+FE76-FEFC;
}
@font-face {
  font-family: 'Cairo';
  font-style: normal;
  font-weight: 200 1000;
  font-display: swap;
  src: url('../fonts/cairo-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
                 U+02DC, U+2000-206F, U+2122, U+2212, U+FEFF, U+FFFD;
}

:root {
  --bg: #08090c;
  --surface: #12151b;
  --surface-2: #1a1f27;
  --surface-3: #232a34;
  --line: #2a323d;
  --text: #eef2f7;
  --muted: #8d9aad;
  --dim: #5f6b7c;

  --gold: #e8b64c;
  --gold-2: #f5d489;
  --gold-dim: rgba(232, 182, 76, .14);
  --ok: #3ecf8e;
  --warn: #f0a04b;
  --danger: #f0554b;

  --r-sm: 10px;
  --r: 16px;
  --r-lg: 22px;

  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --tabbar: 64px;

  --ff: 'Cairo', "Segoe UI", Tahoma, system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--ff);
  font-size: 16px;
  line-height: 1.6;
  overscroll-behavior-y: none;
}

body {
  /* Lock the app to a phone-like column even on desktop. */
  max-width: 560px;
  margin-inline: auto;
  min-height: 100dvh;
  position: relative;
  background:
    radial-gradient(120% 60% at 50% 0%, rgba(232,182,76,.07), transparent 60%),
    var(--bg);
}

img { max-width: 100%; display: block; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--gold); text-decoration: none; }

/* ------------------------------------------------------------ layout -- */

.app { padding: calc(var(--safe-t) + 8px) 16px calc(var(--tabbar) + var(--safe-b) + 24px); }
.view { display: none; animation: fade .22s ease; }
.view.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 0 18px;
}
.topbar h1 { font-size: 22px; margin: 0; font-weight: 800; letter-spacing: -.3px; }
.topbar .sub { font-size: 13px; color: var(--muted); margin-top: 2px; }
.topbar .spacer { margin-inline-start: auto; }

.brand-mark {
  width: 42px; height: 42px; border-radius: 13px; flex: none;
  object-fit: cover;
  border: 1px solid var(--line);
  box-shadow: 0 4px 14px rgba(0, 0, 0, .5);
}

/* ----------------------------------------------------------- wordmark -- */

/* The brand name. Heavy Cairo with a brushed-gold gradient — this is the one
   piece of type on the screen that is allowed to shout. */
.wordmark {
  font-weight: 900;
  letter-spacing: -.02em;
  line-height: 1.15;
  background: linear-gradient(168deg, #fff3d0 0%, var(--gold-2) 30%, var(--gold) 58%, #a8761f 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 2px 10px rgba(232, 182, 76, .28));
  margin: 0;
}
.wordmark.xl { font-size: clamp(38px, 12vw, 54px); }
.wordmark.lg { font-size: 27px; }
.wordmark.sm { font-size: 19px; }

.wordmark-rule {
  display: flex; align-items: center; gap: 10px;
  margin: 10px 0 6px; color: var(--gold);
  font-size: 12px; font-weight: 700; letter-spacing: .18em;
}
.wordmark-rule::before, .wordmark-rule::after {
  content: ""; height: 1px; flex: 1;
  background: linear-gradient(90deg, transparent, var(--line), transparent);
}

/* --------------------------------------------------------- hero image -- */

.captain {
  display: block; width: 100%; max-width: 320px; height: auto;
  margin: 0 auto -10px;
  filter: drop-shadow(0 24px 40px rgba(0, 0, 0, .6));
}
.captain-stage {
  position: relative;
  padding-top: 8px;
  isolation: isolate;
}
/* Gold pool of light behind the figure. */
.captain-stage::before {
  content: ""; position: absolute; z-index: -1;
  inset-inline: 6%; top: 12%; bottom: 6%;
  background: radial-gradient(ellipse at 50% 62%, rgba(232,182,76,.30), rgba(232,182,76,.07) 45%, transparent 72%);
  filter: blur(6px);
}
/* Fade the figure into the page instead of ending on a hard crop. */
.captain-stage::after {
  content: ""; position: absolute; inset-inline: 0; bottom: 0; height: 90px;
  background: linear-gradient(to top, var(--bg) 12%, transparent);
  pointer-events: none;
}

.auth-hero { text-align: center; padding-bottom: 4px; }
.auth-hero .tagline { color: var(--muted); font-size: 14px; margin: 2px 0 0; }
/* Cap the figure against viewport height so the sign-in button stays in reach
   on a short phone screen instead of being pushed below the fold. */
.auth-hero .captain { max-height: 36vh; width: auto; max-width: 100%; }
.auth-hero .captain-stage::after { height: 60px; }

/* -------------------------------------------------------------- cards -- */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 16px;
  margin-bottom: 14px;
}
.card.tight { padding: 12px; }
.card h2 { font-size: 17px; margin: 0 0 10px; font-weight: 700; }
.card h3 { font-size: 15px; margin: 0 0 8px; font-weight: 700; color: var(--muted); }

.hero {
  background:
    linear-gradient(160deg, rgba(232,182,76,.10), transparent 42%),
    linear-gradient(160deg, #23252c, var(--surface) 55%);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 20px 18px;
  margin-bottom: 16px;
  position: relative;
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .35);
}
/* A thin gold seam along the top edge. */
.hero::before {
  content: ""; position: absolute; inset-inline: 18px; top: 0; height: 2px;
  background: linear-gradient(90deg, transparent, var(--gold), transparent);
  opacity: .85;
}
.hero::after {
  content: ""; position: absolute; inset-inline-end: -40px; top: -40px;
  width: 160px; height: 160px; border-radius: 50%;
  background: radial-gradient(circle, rgba(232,182,76,.16), transparent 70%);
}
.hero .eyebrow { color: var(--gold); font-size: 12px; font-weight: 700; letter-spacing: .4px; }
.hero .title { font-size: 24px; font-weight: 800; margin: 4px 0 6px; letter-spacing: -.4px; }
.hero .meta { color: var(--muted); font-size: 14px; }

/* -------------------------------------------------------------- stats -- */

.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 14px; }
.stat {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r); padding: 12px 10px; text-align: center;
}
.stat .n { font-size: 21px; font-weight: 800; line-height: 1.2; }
.stat .l { font-size: 11px; color: var(--muted); margin-top: 2px; }
.stat.gold .n { color: var(--gold); }

/* ------------------------------------------------------------ buttons -- */

.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; padding: 15px 18px; min-height: 52px;
  border: 0; border-radius: var(--r);
  background: linear-gradient(150deg, var(--gold-2), var(--gold));
  color: #1a1204; font-weight: 800; font-size: 16px;
  cursor: pointer; transition: transform .12s, filter .12s;
}
.btn:active { transform: scale(.98); filter: brightness(.95); }
.btn[disabled] { opacity: .5; pointer-events: none; }
.btn.ghost { background: var(--surface-2); color: var(--text); border: 1px solid var(--line); }
.btn.outline { background: transparent; color: var(--gold); border: 1.5px solid var(--gold); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.sm { min-height: 42px; padding: 10px 14px; font-size: 14px; width: auto; }
.btn-row { display: flex; gap: 10px; }
.btn-row .btn { width: auto; flex: 1; }

.chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 6px 12px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--line);
  font-size: 13px; color: var(--muted); cursor: pointer;
  white-space: nowrap;
}
.chip.on { background: var(--gold-dim); border-color: var(--gold); color: var(--gold-2); }
.chip-scroll {
  display: flex; gap: 8px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 12px;
  scrollbar-width: none;
}
.chip-scroll::-webkit-scrollbar { display: none; }

/* ------------------------------------------------------------- forms -- */

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; font-weight: 600; }
.input, select.input, textarea.input {
  width: 100%; padding: 14px 14px; min-height: 50px;
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: var(--r-sm); color: var(--text);
  outline: none; transition: border-color .15s;
  -webkit-appearance: none; appearance: none;
}
.input:focus { border-color: var(--gold); }
textarea.input { min-height: 90px; resize: vertical; }
select.input {
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
                    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: left 18px center, left 13px center;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.hint { font-size: 12px; color: var(--dim); margin-top: 5px; }

.seg { display: grid; grid-auto-flow: column; gap: 6px; background: var(--surface-2);
       border: 1px solid var(--line); border-radius: var(--r-sm); padding: 4px; }
.seg button {
  border: 0; background: transparent; color: var(--muted);
  padding: 11px 6px; border-radius: 8px; font-size: 14px; font-weight: 600; cursor: pointer;
}
.seg button.on { background: var(--gold); color: #1a1204; }

/* ------------------------------------------------------ exercise list -- */

.ex-item {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r); padding: 10px; margin-bottom: 10px;
  cursor: pointer; transition: border-color .15s;
}
.ex-item:active { border-color: var(--gold); }
.ex-thumb {
  width: 62px; height: 62px; border-radius: 12px; flex: none;
  object-fit: cover; background: var(--surface-3);
}
.ex-body { min-width: 0; flex: 1; }
.ex-name { font-weight: 700; font-size: 15px; margin-bottom: 3px;
           overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ex-meta { font-size: 12px; color: var(--muted); display: flex; gap: 8px; flex-wrap: wrap; }
.ex-sets { font-size: 13px; color: var(--gold); font-weight: 700; white-space: nowrap; }
.ex-item.done { opacity: .55; }
.ex-item.done .ex-name { text-decoration: line-through; }

.badge {
  font-size: 11px; padding: 2px 8px; border-radius: 999px;
  background: var(--surface-3); color: var(--muted);
}
.badge.gold { background: var(--gold-dim); color: var(--gold-2); }
.badge.ok { background: rgba(62,207,142,.14); color: var(--ok); }

/* ------------------------------------------------------ day / program -- */

.day-card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r); padding: 14px; margin-bottom: 12px;
}
.day-card.rest { opacity: .7; border-style: dashed; }
.day-card .d-title { font-weight: 800; font-size: 16px; }
.day-card .d-focus { color: var(--muted); font-size: 13px; margin-top: 2px; }
.day-card .d-cardio { color: var(--gold); font-size: 12px; margin-top: 8px; }

/* --------------------------------------------------- workout player -- */

.set-grid {
  display: grid; grid-template-columns: 34px 1fr 1fr 44px;
  gap: 8px; align-items: center; margin-bottom: 8px;
}
.set-grid .idx { text-align: center; color: var(--muted); font-size: 13px; font-weight: 700; }
.set-grid .input { min-height: 46px; padding: 10px; text-align: center; font-weight: 700; }
.set-grid .tick {
  width: 44px; height: 46px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface-2); color: var(--dim); font-size: 18px; cursor: pointer;
}
.set-grid .tick.on { background: var(--ok); border-color: var(--ok); color: #04240f; }
.set-head { display: grid; grid-template-columns: 34px 1fr 1fr 44px; gap: 8px;
            font-size: 11px; color: var(--dim); text-align: center; margin-bottom: 6px; }

.rest-timer {
  position: fixed; inset-inline: 0; bottom: calc(var(--tabbar) + var(--safe-b));
  max-width: 560px; margin-inline: auto;
  background: linear-gradient(150deg, var(--gold-2), var(--gold));
  color: #1a1204; padding: 12px 16px;
  display: flex; align-items: center; gap: 12px;
  font-weight: 800; z-index: 40;
  transform: translateY(120%); transition: transform .25s;
}
.rest-timer.on { transform: none; }
.rest-timer .t { font-size: 24px; font-variant-numeric: tabular-nums; }
.rest-timer button {
  margin-inline-start: auto; border: 0; background: rgba(0,0,0,.18);
  color: #1a1204; padding: 8px 14px; border-radius: 10px; font-weight: 800; cursor: pointer;
}

.timer-big {
  font-size: 34px; font-weight: 800; font-variant-numeric: tabular-nums;
  letter-spacing: -1px;
}

/* ----------------------------------------------------------- gallery -- */

.gallery { display: grid; grid-auto-flow: column; gap: 10px; overflow-x: auto;
           scroll-snap-type: x mandatory; margin-bottom: 14px; scrollbar-width: none; }
.gallery::-webkit-scrollbar { display: none; }
.gallery img {
  width: 82vw; max-width: 460px; aspect-ratio: 4/3; object-fit: cover;
  border-radius: var(--r); scroll-snap-align: center; background: var(--surface-2);
}

.steps { counter-reset: s; list-style: none; padding: 0; margin: 0; }
.steps li {
  counter-increment: s; position: relative;
  padding-inline-start: 38px; padding-block: 9px;
  border-bottom: 1px solid var(--line); font-size: 15px;
}
.steps li:last-child { border-bottom: 0; }
.steps li::before {
  content: counter(s); position: absolute; inset-inline-start: 0; top: 10px;
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--gold-dim); color: var(--gold-2);
  display: grid; place-items: center; font-size: 12px; font-weight: 800;
}

.note {
  border-inline-start: 3px solid var(--gold);
  background: var(--gold-dim); border-radius: 0 var(--r-sm) var(--r-sm) 0;
  padding: 11px 13px; font-size: 14px; margin-bottom: 12px;
}
.note.info { border-color: var(--ok); background: rgba(62,207,142,.10); }

/* -------------------------------------------------------------- tabs -- */

.tabbar {
  position: fixed; inset-inline: 0; bottom: 0; z-index: 50;
  max-width: 560px; margin-inline: auto;
  height: calc(var(--tabbar) + var(--safe-b));
  padding-bottom: var(--safe-b);
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: rgba(12,15,20,.94);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
}
.tabbar button {
  border: 0; background: none; color: var(--dim);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  font-size: 10px; cursor: pointer; font-weight: 600;
}
.tabbar button svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 1.9; }
.tabbar button.on { color: var(--gold); }

/* ------------------------------------------------------------- misc -- */

.sync-pill {
  position: fixed; top: calc(var(--safe-t) + 10px); inset-inline-end: 12px; z-index: 60;
  font-size: 12px; padding: 6px 12px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--line); color: var(--muted);
  display: none; align-items: center; gap: 6px;
}
.sync-pill.show { display: flex; }
.sync-pill.off { border-color: var(--warn); color: var(--warn); }
.sync-pill.busy { border-color: var(--gold); color: var(--gold); }
.sync-pill.ok { border-color: var(--ok); color: var(--ok); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

.sheet {
  position: fixed; inset: 0; z-index: 70;
  background: rgba(0,0,0,.6); backdrop-filter: blur(3px);
  display: none; align-items: flex-end; justify-content: center;
}
.sheet.on { display: flex; }
.sheet-inner {
  width: 100%; max-width: 560px; max-height: 88dvh; overflow-y: auto;
  background: var(--surface); border-radius: var(--r-lg) var(--r-lg) 0 0;
  border-top: 1px solid var(--line);
  padding: 8px 16px calc(20px + var(--safe-b));
  animation: up .26s cubic-bezier(.2,.9,.3,1);
}
@keyframes up { from { transform: translateY(100%); } to { transform: none; } }
.grab { width: 40px; height: 4px; border-radius: 2px; background: var(--surface-3);
        margin: 6px auto 14px; }

.toast {
  position: fixed; bottom: calc(var(--tabbar) + var(--safe-b) + 16px);
  inset-inline: 20px; z-index: 90; max-width: 520px; margin-inline: auto;
  background: var(--surface-3); border: 1px solid var(--line);
  border-radius: var(--r-sm); padding: 13px 16px; font-size: 14px;
  opacity: 0; transform: translateY(12px); transition: .22s; pointer-events: none;
}
.toast.on { opacity: 1; transform: none; }
.toast.err { border-color: var(--danger); }
.toast.ok { border-color: var(--ok); }

.credit {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  margin: 26px auto 6px; padding: 12px 18px;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--surface); color: var(--muted);
  font-size: 13px; width: fit-content; text-decoration: none;
  transition: border-color .15s, color .15s;
}
.credit:active { border-color: var(--gold); color: var(--gold-2); }
.credit strong { color: var(--gold-2); font-weight: 800; letter-spacing: .02em; }
.credit svg { width: 14px; height: 14px; stroke: currentColor; fill: none; stroke-width: 2; }

.empty { text-align: center; color: var(--dim); padding: 40px 20px; }
.empty .big { font-size: 40px; margin-bottom: 10px; opacity: .5; }

.list-row {
  display: flex; align-items: center; gap: 12px;
  padding: 13px 0; border-bottom: 1px solid var(--line);
}
.list-row:last-child { border-bottom: 0; }
.list-row .grow { flex: 1; min-width: 0; }
.list-row .val { font-weight: 800; color: var(--gold); font-variant-numeric: tabular-nums; }

.bar-track { height: 8px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.bar-fill { height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--gold), var(--gold-2)); }
.bar-fill.over { background: var(--danger); }

.chart { width: 100%; height: 170px; display: block; }

.split { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.muted { color: var(--muted); }
.dim { color: var(--dim); }
.sm { font-size: 13px; }
.xs { font-size: 12px; }
.center { text-align: center; }
.mb0 { margin-bottom: 0; }
.mt { margin-top: 14px; }
.nowrap { white-space: nowrap; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
