/* 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. Letting a white rectangle sit on a dark sheet reads as a broken
   image; making it a deliberate light panel reads as a prize. */
.prize-gif {
  display: block;
  width: 100%;
  max-height: 240px;
  object-fit: contain;
  padding: 14px 0;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  background: #F7F2EE;
}
@media (min-width: 640px) { .prize-gif { border-radius: var(--radius-lg) var(--radius-lg) 0 0; } }

.prize-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 20px var(--pad) 0;
  text-align: center;
}
.prize-body h2 { font-size: 24px; line-height: 1.3; }
.prize-body h2 span { color: var(--green); }
.prize-theme { font-size: 16px; 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: 10px 12px;
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--amber) 14%, transparent);
  color: var(--amber);
  font-size: 15px;
  font-weight: 700;
}
.prize-body .btn { margin-top: 4px; }
