/* Recording screen. Sized for a phone held one-handed: the mic button sits in
   thumb reach and the prompt stays readable above it without scrolling. */

.page {
  padding-block: 18px 40px;
  padding-bottom: max(40px, calc(env(safe-area-inset-bottom) + 24px));
  animation: slideIn 0.3s cubic-bezier(0.22, 1, 0.36, 1);
}

.topbar-actions { display: flex; align-items: center; gap: 8px; }
.icon-btn {
  /* Grid rather than relying on a button's default centring: with a glyph
     child the baseline decides where it lands, and every platform draws emoji
     with different metrics — which is why this looked centred on desktop and
     sat high on a phone. */
  display: grid;
  place-items: center;
  width: 42px; height: 42px;
  padding: 0;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
  line-height: 1;
}
/* An SVG has exact geometry, so it centres identically everywhere. */
.icon-btn svg {
  display: block;
  width: 21px; height: 21px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}
#open-board { color: var(--amber); }
#open-board:active { transform: scale(0.94); }

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



/* -------------------------------------------------------------- progress -- */

.progress-strip { margin-bottom: 16px; }
.progress-meta {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; margin-top: 8px;
  font-size: 14px; font-weight: 700; color: var(--muted);
}

/* ---------------------------------------------------------------- prompt -- */

.prompt-card { box-shadow: 0 5px 0 #101a2c; }
.prompt-card.swap { animation: pop 0.3s cubic-bezier(0.22, 1, 0.36, 1); }

.script-label {
  margin: 0 0 4px;
  font-size: 12px; font-weight: 700; letter-spacing: 0.06em;
  color: var(--muted); text-transform: uppercase;
}
.prompt-arabizi {
  margin: 0;
  font-size: 19px; font-weight: 600; color: var(--blue);
  font-family: ui-rounded, -apple-system, system-ui, sans-serif;
  overflow-wrap: anywhere;
}
.prompt-arabic {
  margin: 0;
  font-size: 22px; font-weight: 700; line-height: 1.7;
  overflow-wrap: anywhere;
}
/* Separator and level meter in one. Idle it is a hairline; while recording it
   fills from the centre, right where the reader is already looking. */
.divider {
  position: relative;
  height: 4px;
  margin: 16px 0;
  border-radius: 999px;
  background: var(--line);
  overflow: hidden;
  transition: height 0.2s ease;
}
.divider.live { height: 8px; }
.divider > span {
  position: absolute;
  left: 50%;
  top: 0;
  height: 100%;
  width: 0;
  transform: translateX(-50%);
  border-radius: 999px;
  background: linear-gradient(90deg, var(--blue), var(--green), var(--blue));
  transition: width 70ms linear;
}
.divider.live > span { box-shadow: 0 0 12px color-mix(in srgb, var(--green) 60%, transparent); }

/* ---------------------------------------------------------------- record -- */

.record-zone { display: grid; justify-items: center; gap: 14px; margin-top: 20px; }

.timer {
  font-variant-numeric: tabular-nums;
  font-weight: 800; font-size: 15px; color: var(--amber);
}
.timer small { color: var(--muted); font-weight: 700; }
.timer.warn { color: var(--red); animation: pulse 0.8s ease-in-out infinite; }

.controls { display: flex; align-items: center; justify-content: center; gap: 14px; width: 100%; }

.mic {
  position: relative;
  width: 96px; height: 96px;
  flex: none;
  border: 0; border-radius: 50%;
  background: var(--green);
  box-shadow: 0 6px 0 var(--green-dark);
  cursor: pointer;
  display: grid; place-items: center;
  transition: transform 0.07s ease, box-shadow 0.07s ease, background 0.2s ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.mic:active { transform: translateY(5px); box-shadow: 0 1px 0 var(--green-dark); }
.mic:disabled { opacity: 0.4; cursor: not-allowed; }
.mic:focus-visible { outline: 3px solid var(--blue); outline-offset: 4px; }

.mic svg { width: 42px; height: 42px; fill: none; stroke: #08300a; stroke-width: 2.1; stroke-linecap: round; stroke-linejoin: round; }
.mic svg path:first-child { fill: #08300a; stroke: none; }

.mic[data-live="true"] { background: var(--red); box-shadow: 0 6px 0 var(--red-dark); }
.mic[data-live="true"] svg { stroke: #3d0808; }
.mic[data-live="true"] svg path:first-child { fill: #3d0808; }
.mic[data-live="true"]::before,
.mic[data-live="true"]::after {
  content: "";
  position: absolute; inset: -8px;
  border-radius: 50%;
  border: 3px solid var(--red);
  animation: ring 1.6s ease-out infinite;
}
.mic[data-live="true"]::after { animation-delay: 0.8s; }

.hint { margin: 0; text-align: center; color: var(--muted); font-weight: 700; font-size: 15px; }

.review { display: flex; gap: 12px; width: 100%; }
.review .btn { flex: 1; }

.link {
  display: block; margin: 32px auto 0;
  background: none; border: 0; color: var(--muted);
  font: inherit; font-size: 14px; text-decoration: underline; cursor: pointer;
}

/* Side by side once there is room; stacked on a phone. */
@media (min-width: 700px) {
  .prompt-arabizi { font-size: 21px; }
  .prompt-arabic { font-size: 27px; }
  .mic { width: 104px; height: 104px; }
}

/* ------------------------------------------------------------------ stage --
   One fixed-height area that the record button, the calculating spinner and the
   score all take turns in. Swapping in place is what keeps the controls under
   the thumb — previously the mic scrolled off once a result appeared. */

.stage {
  min-height: 232px;
  display: grid;
  place-items: center;
  margin-top: 18px;
}
.stage-panel {
  grid-area: 1 / 1;
  display: grid;
  justify-items: center;
  gap: 12px;
  width: 100%;
  animation: slideIn 0.28s cubic-bezier(0.22, 1, 0.36, 1);
}
.stage-panel[hidden] { display: none; }

/* --------------------------------------------------------------- scoring -- */

.calc-ring { position: relative; width: 84px; height: 84px; }
.calc-ring span {
  position: absolute; inset: 0;
  border: 4px solid transparent;
  border-top-color: var(--green);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}
.calc-ring span:nth-child(2) { inset: 10px; border-top-color: var(--blue); animation-duration: 1.4s; animation-direction: reverse; }
.calc-ring span:nth-child(3) { inset: 20px; border-top-color: var(--amber); animation-duration: 1.8s; }
@keyframes spin { to { transform: rotate(360deg); } }
.calc-text { margin: 0; font-weight: 800; color: var(--muted); }

/* ---------------------------------------------------------------- result -- */

.score-burst { position: relative; display: grid; justify-items: center; gap: 4px; }
.score-burst.pop { animation: scorePop 0.5s cubic-bezier(0.22, 1, 0.36, 1); }
@keyframes scorePop {
  0% { transform: scale(0.6); opacity: 0; }
  60% { transform: scale(1.08); opacity: 1; }
  100% { transform: scale(1); }
}
/* Rays only for a strong score, so the reward means something. */
.score-burst.great::before {
  content: "";
  position: absolute; inset: -26px;
  border-radius: 50%;
  background: radial-gradient(circle, color-mix(in srgb, var(--green) 30%, transparent) 0%, transparent 68%);
  animation: ring 1.1s ease-out 2;
  pointer-events: none;
}

.score-number {
  display: flex; align-items: baseline; gap: 4px;
  /* Forced LTR: in RTL the "/100" landed left of the number and read as
     "100/ 100". A score is a number, so it reads left to right. */
  direction: ltr;
  font-size: 64px; font-weight: 800; line-height: 1;
  font-variant-numeric: tabular-nums;
  color: var(--green);
}
.score-number small { font-size: 20px; color: var(--muted); font-weight: 700; }
.score-burst[data-tier="ok"] .score-number { color: var(--amber); }
.score-burst[data-tier="low"] .score-number { color: var(--red); }

.score-reaction { margin: 0; font-size: 17px; font-weight: 800; }
.score-parts { justify-content: center; }

/* Two joined buttons, one control. */
.linked {
  display: grid;
  grid-template-columns: 1fr 1fr;
  width: min(340px, 100%);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 4px 0 #0f1727;
}
.linked-btn {
  min-height: 54px;
  border: 2px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  font: inherit; font-weight: 800; font-size: 17px;
  cursor: pointer;
  transition: filter 0.15s ease, transform 0.06s ease;
  -webkit-tap-highlight-color: transparent;
}
.linked-btn:first-child { border-inline-end: 0; }
.linked-btn:active { transform: translateY(2px); }
.linked-btn.primary { background: var(--green); color: #06210f; border-color: var(--green); }
.linked-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.linked-btn:focus-visible { outline: 3px solid var(--blue); outline-offset: -3px; }

/* --------------------------------------------------------- side actions --- */

.side-actions {
  display: flex; justify-content: center; gap: 10px;
  margin-top: 16px;
}

.prompt-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.kind {
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  background: var(--bg-2);
  border: 1px solid var(--line);
  white-space: nowrap;
}
.kind[data-kind="r"] { color: var(--purple); border-color: #4a2d63; }
.kind[data-kind="f"] { color: var(--amber); border-color: #5c4a12; }
.kind[data-kind="q"] { color: var(--blue); border-color: #14506e; }
.kind[data-kind="x"] { color: var(--green); border-color: #2c5c1c; }

/* ------------------------------------------------------ leaderboard sheet -- */

/* A sheet rather than a centred box: on a phone this is the whole screen, and
   sliding up from the bottom keeps the trophy that opened it in view. */
.sheet {
  width: min(560px, 100%);
  /* The UA stylesheet caps a dialog at calc(100% - 6px - 2em), which left a
     gap down both sides of what is meant to be a full-width sheet. */
  max-width: 100%;
  max-height: 88dvh;
  margin: auto auto 0;
  padding: 0 var(--pad) calc(var(--pad) + env(safe-area-inset-bottom, 0px));
  border: 0;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  background: var(--surface);
  color: var(--text);
  overflow: hidden auto;
  overscroll-behavior: contain;
  animation: sheet-up 0.26s cubic-bezier(0.2, 0.9, 0.3, 1);
}
@media (min-width: 640px) {
  .sheet { margin: auto; border-radius: var(--radius-lg); max-height: 80dvh; }
}
.sheet::backdrop { background: rgba(6, 10, 18, 0.72); backdrop-filter: blur(3px); }
@keyframes sheet-up { from { transform: translateY(18px); opacity: 0; } }

/* Sticky so the title and the close button stay reachable while scrolling. */
.sheet-head {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 0 12px;
  background: var(--surface);
}
.sheet-head h2 { font-size: 21px; }
#board-sub { margin-bottom: 12px; }

.board-list { display: grid; gap: 8px; }

.board-row {
  display: grid;
  grid-template-columns: 42px 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 11px 12px;
  border-radius: var(--radius);
  background: var(--bg-2);
  border: 2px solid transparent;
}
/* The viewer's own row, so you find yourself without reading every name. */
.board-row.me {
  border-color: var(--green);
  background: color-mix(in srgb, var(--green) 12%, var(--bg-2));
}
.board-rank { font-size: 19px; font-weight: 800; text-align: center; color: var(--muted); }
.board-row.top .board-rank { font-size: 24px; }

.board-name { font-weight: 800; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board-sub { font-size: 12.5px; color: var(--muted); font-weight: 700; margin-top: 2px; }

/* Score sits right-aligned in its own column so the numbers form a clean
   edge; a badge rather than plain text because it is the quality signal. */
.board-score {
  display: grid;
  place-items: center;
  min-width: 46px;
  padding: 5px 9px;
  border-radius: 999px;
  font-weight: 800;
  font-size: 15px;
  background: var(--surface-2);
  color: var(--muted);
}
.board-score.good { background: color-mix(in srgb, var(--green) 20%, transparent); color: var(--green); }
.board-score.mid { background: color-mix(in srgb, var(--amber) 20%, transparent); color: var(--amber); }

.board-skeleton {
  height: 62px;
  border-radius: var(--radius);
  background: linear-gradient(90deg, var(--bg-2) 25%, var(--surface-2) 50%, var(--bg-2) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.2s infinite;
}
@keyframes shimmer { to { background-position: -200% 0; } }

.board-more { height: 28px; display: grid; place-items: center; color: var(--muted); font-size: 13px; }

/* Pinned copy of your own row, for when your rank is far past what is loaded. */
.board-you {
  position: sticky;
  bottom: 0;
  padding-top: 10px;
  background: linear-gradient(to top, var(--surface) 72%, transparent);
}

/* ------------------------------------------------------ tournament prize -- */

/* The gif is 924x540 and the point of the whole modal, so it leads and it
   bleeds to the edges — padding around a prize makes it look like a banner ad. */
.sheet.prize { padding: 0 0 calc(var(--pad) + env(safe-area-inset-bottom, 0px)); }
/* The source frame is 75% empty cream, so it is cropped to the note and given
   its own band — recoloured to a pale tint of the site blue. A white block on a
   dark sheet reads as a broken image or an advert; a note has to sit on
   something light to stay legible, so the answer is a lighter version of a
   colour already in the palette rather than no colour at all. */
/* `display: block` beats `[hidden] { display: none }`, so an announcement with
   no image kept a pale blue band above it that looked like a failed load. */
.prize-gif[hidden] { display: none; }
.prize-gif {
  display: block;
  width: 100%;
  /* Raised with the crop. The source is now tight to the note rather than 75%
     empty, and its aspect changed from 1.7 to 1.3 — at the old cap the note
     rendered *smaller* than before, letterboxed inside a band sized for a
     wider picture. The band grows by about fifty pixels; the note grows by
     half again. */
  max-height: 186px;
  object-fit: contain;
  padding: 10px 0;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  background: #D6EAF7;
}
@media (min-width: 640px) { .prize-gif { border-radius: var(--radius-lg) var(--radius-lg) 0 0; } }

.sheet.prize { width: min(400px, 100%); }
.prize-body {
  display: flex;
  flex-direction: column;
  gap: 9px;
  padding: 14px var(--pad) 0;
  text-align: center;
}
.prize-body h2 { font-size: 20px; line-height: 1.3; }
.prize-body h2 span { color: var(--green); }
.prize-theme { font-size: 14.5px; color: var(--muted); }
.prize-theme b { color: var(--text); }
/* The rule of the contest, stated plainly. A prize with no stated way to win
   it is decoration; new contributors need one sentence telling them what to do. */
.prize-rule {
  margin: 0;
  padding: 8px 11px;
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--amber) 14%, transparent);
  color: var(--amber);
  font-size: 13.5px;
  font-weight: 700;
}
/* An announcement with nothing conditional to say: ordinary prose, in the
   ordinary secondary colour. */
.prize-plain {
  margin: 0;
  padding: 0 2px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  line-height: 1.55;
}
.prize-body .btn { margin-top: 4px; }

/* ------------------------------------------------------------- winner -- */

/* Shown to one person: whoever is actually first. Gold rather than the app's
   green, because green already means "your recording was fine" here and this
   has to read as something else entirely. */
.winner {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 14px;
  padding: 14px 16px;
  border-radius: var(--radius);
  border: 2px solid var(--amber);
  background: linear-gradient(135deg,
    color-mix(in srgb, var(--amber) 22%, transparent),
    color-mix(in srgb, var(--amber) 8%, transparent));
  position: relative;
  overflow: hidden;
}
.winner b { color: var(--amber); font-size: 17px; }
.winner p { margin: 2px 0 0; font-size: 14px; color: var(--text); }
.winner-cup { font-size: 30px; line-height: 1; }

.winner.celebrate .winner-cup { animation: cupHop 0.9s cubic-bezier(0.22, 1, 0.36, 1) 2; }
@keyframes cupHop {
  0%, 100% { transform: translateY(0) rotate(0); }
  30% { transform: translateY(-8px) rotate(-9deg); }
  60% { transform: translateY(-3px) rotate(7deg); }
}

/* A single sweep of light across the banner. One pass, not a loop — a banner
   that shimmers forever stops being a moment and becomes an advert. */
.winner.celebrate::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(100deg, transparent 35%,
    color-mix(in srgb, var(--amber) 45%, transparent) 50%, transparent 65%);
  transform: translateX(-120%);
  animation: sweep 1.4s ease-out 0.2s 1;
  pointer-events: none;
}
@keyframes sweep { to { transform: translateX(120%); } }

/* When the browser will not give us live levels, the bar sweeps instead.

   The alternative is a bar that sits at zero while recording works perfectly
   well, which reads as "it is broken" and makes people stop and retry a take
   that was fine. This says "listening" without claiming to measure anything. */
.divider.blind > span {
  width: 38%;
  animation: sweep 1.5s ease-in-out infinite;
  background: linear-gradient(90deg, transparent, var(--blue), transparent);
}
@keyframes sweep {
  0%   { transform: translateX(-160%); }
  100% { transform: translateX(160%); }
}
@media (prefers-reduced-motion: reduce) {
  .divider.blind > span { animation: none; width: 100%; opacity: 0.45; }
}

/* ------------------------------------------------------ prize at the end -- */

/* The bar and its destination share a row, so the thing being filled is
   visibly heading somewhere. The bar keeps all the flexible width; the badge
   is a fixed size and cannot push the layout around at any viewport. */
.bar-row { display: flex; align-items: center; gap: 10px; }
.bar-row .bar { flex: 1 1 auto; min-width: 0; }

.prize-badge {
  flex: 0 0 auto;
  /* Fixed box, always. Growing it with `width` moved everything below by a few
     pixels the moment the goal was reached — the one frame where the page must
     not twitch. Size lives entirely in a transform, which costs no layout. */
  width: 54px;
  height: auto;
  display: block;
  /* A banknote is a rectangle, so it stays opaque with a rounded corner.
     Keying the background out left a pink halo along every edge. */
  border-radius: 3px;
  --grow: 1;
  filter: drop-shadow(0 2px 4px rgb(0 0 0 / 0.45));
  transform-origin: center;
  animation: prize-float 3.2s ease-in-out infinite;
  transition: filter 0.3s ease;
}

/* Close to the goal: bigger and lit. */
.prize-badge.close {
  --grow: 1.16;
  filter: drop-shadow(0 0 10px color-mix(in srgb, var(--green) 55%, transparent));
}
.prize-badge.reached {
  --grow: 1.3;
  filter: drop-shadow(0 0 14px color-mix(in srgb, var(--green) 80%, transparent));
  animation: none;
  transform: scale(var(--grow));
}
.prize-badge.won { animation: prize-win 0.9s cubic-bezier(0.22, 1, 0.36, 1); }

@keyframes prize-float {
  0%, 100% { transform: translateY(0) rotate(-1.5deg) scale(var(--grow)); }
  50%      { transform: translateY(-4px) rotate(1.5deg) scale(var(--grow)); }
}
@keyframes prize-win {
  0%   { transform: scale(var(--grow)) rotate(0deg); }
  35%  { transform: scale(calc(var(--grow) * 1.35)) rotate(-8deg); }
  60%  { transform: scale(calc(var(--grow) * 1.1)) rotate(6deg); }
  100% { transform: scale(var(--grow)) rotate(0deg); }
}

@media (prefers-reduced-motion: reduce) {
  .prize-badge, .prize-badge.won { animation: none; transform: scale(var(--grow)); }
}

/* On a narrow phone the bar still needs most of the row. */
@media (max-width: 380px) {
  .prize-badge { width: 44px; }
}

/* ------------------------------------------------------------ share sheet -- */

/* A count on the share icon, so the reward for inviting is visible without
   opening anything. Hidden at zero: a badge showing 0 is an accusation. */
.icon-btn { position: relative; }
/* `display: grid` beats the browser's own `[hidden] { display: none }`, so a
   badge told to hide stayed on screen as a green dot claiming a referral that
   did not exist. */
.icon-badge[hidden] { display: none; }
.icon-badge {
  position: absolute; top: -2px; inset-inline-end: -2px;
  min-width: 18px; height: 18px; padding: 0 5px;
  display: grid; place-items: center;
  border-radius: 999px; background: var(--green); color: #06280a;
  font-size: 11px; font-weight: 800; line-height: 1;
}

.share-body { display: grid; gap: 14px; padding-top: 4px; }
.share-link { display: flex; gap: 8px; }
.share-link input {
  flex: 1 1 auto; min-width: 0;
  padding: 12px 14px; border-radius: 12px;
  background: var(--bg-2); border: 2px solid var(--line); color: var(--text);
  font-size: 14px; direction: ltr; text-align: left;
}
.share-link .btn { flex: 0 0 auto; }
.share-stats { display: grid; gap: 6px; }
.share-figure { display: flex; align-items: baseline; gap: 8px; }
.share-figure b { font-size: 30px; font-weight: 800; line-height: 1; }
.share-figure span { color: var(--muted); font-weight: 700; font-size: 14px; }

/* Announcements that carry no image get a drawn one, so the sheet is not a
   wall of text where the prize gif used to be. */
.announce-art { display: grid; place-items: center; padding: 22px 0 6px; }
.announce-icon {
  width: 64px; height: 64px;
  fill: none; stroke: var(--green); stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round;
}

/* The handover between weeks. A board that resets to zero with no explanation
   reads as lost work, so the trophy lands with the same weight as a win. */
.past-winner { display: grid; justify-items: center; gap: 2px; margin-top: 10px; }
.past-winner b { font-size: 22px; font-weight: 800; }
.past-winner span { color: var(--muted); font-weight: 700; font-size: 13px; }

.sheet.prize.celebrate .announce-art { animation: trophy-land 0.75s cubic-bezier(0.22, 1, 0.36, 1); }
.sheet.prize.celebrate .announce-icon { animation: trophy-shine 2.4s ease-in-out 0.6s infinite; }

@keyframes trophy-land {
  0%   { transform: translateY(-26px) scale(0.7); opacity: 0; }
  60%  { transform: translateY(4px) scale(1.06); opacity: 1; }
  100% { transform: translateY(0) scale(1); opacity: 1; }
}
@keyframes trophy-shine {
  0%, 70%, 100% { transform: rotate(0deg); }
  78%           { transform: rotate(-9deg); }
  86%           { transform: rotate(7deg); }
}
@media (prefers-reduced-motion: reduce) {
  .sheet.prize.celebrate .announce-art,
  .sheet.prize.celebrate .announce-icon { animation: none; }
}

/* The daily allowance, spent. Amber rather than red: nothing went wrong, the
   day is simply done — and it comes back on its own. */
.hint-capped {
  color: var(--amber);
  font-weight: 800;
}
