:root {
  --bg: #05070d;
  --bg-2: #080c18;
  --surface: rgba(255, 255, 255, 0.03);
  --surface-2: rgba(255, 255, 255, 0.06);
  --line: rgba(255, 255, 255, 0.08);
  --cyan: #38e1ff;
  --cyan-deep: #0e86a6;
  --gold: #f7c14a;
  --rose: #ff6d7a;
  --text: #e6f4ff;
  --muted: #6b7f94;
  --shadow-cyan: 0 0 20px rgba(56, 225, 255, 0.45), 0 0 40px rgba(56, 225, 255, 0.18);
  --display: "Orbitron", ui-sans-serif, system-ui, sans-serif;
  --body: "Space Grotesk", ui-sans-serif, system-ui, sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bot: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: radial-gradient(ellipse at 50% -10%, #0c1a2e 0%, var(--bg) 55%) fixed;
  color: var(--text);
  font-family: var(--body);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  display: flex;
  flex-direction: column;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bot);
}

/* ——— Decorative backdrops ——— */

.scanlines {
  position: fixed; inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(
    to bottom,
    rgba(56, 225, 255, 0.018) 0px,
    rgba(56, 225, 255, 0.018) 1px,
    transparent 1px,
    transparent 3px
  );
  mix-blend-mode: screen;
  z-index: 1;
}

.grid-bg {
  position: fixed; inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(to right, rgba(56, 225, 255, 0.04) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(56, 225, 255, 0.04) 1px, transparent 1px);
  background-size: 40px 40px;
  mask-image: radial-gradient(ellipse at 50% 30%, black 20%, transparent 75%);
  z-index: 0;
}

/* ——— Topbar ——— */

.topbar {
  position: relative;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px 10px;
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(8px);
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand h1 {
  font-family: var(--display);
  font-weight: 700;
  font-size: 18px;
  letter-spacing: 0.35em;
  margin: 0;
  color: var(--cyan);
  text-shadow: 0 0 14px rgba(56, 225, 255, 0.5);
}
.brand .sub {
  display: none;
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.18em;
  text-transform: uppercase;
}
@media (min-width: 520px) {
  .brand .sub { display: inline; }
}

.reactor {
  width: 22px; height: 22px;
  border-radius: 50%;
  background: radial-gradient(circle, var(--cyan) 0%, #0b2a38 60%, transparent 100%);
  box-shadow: 0 0 14px var(--cyan), inset 0 0 10px rgba(255,255,255,0.4);
  animation: pulse 2.4s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.12); opacity: 0.75; }
}

.stats { display: flex; gap: 14px; }
.stat {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  line-height: 1;
}
.stat label {
  font-size: 9px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--muted);
}
.stat b {
  font-family: var(--display);
  font-weight: 500;
  font-size: 16px;
  color: var(--cyan);
  margin-top: 4px;
}

/* ——— Stage ——— */

.stage {
  position: relative;
  z-index: 2;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 14px 16px 0;
  overflow: hidden;
}

/* ——— Phrase card ——— */

.phrase-card {
  position: relative;
  background:
    linear-gradient(180deg, rgba(56, 225, 255, 0.06), rgba(56, 225, 255, 0.015)),
    var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 16px 18px;
  box-shadow: 0 0 0 1px rgba(56, 225, 255, 0.06), 0 20px 60px rgba(0,0,0,0.45);
  backdrop-filter: blur(10px);
  animation: rise 0.6s cubic-bezier(.2,.9,.3,1) both;
}
.phrase-card::before {
  content: "";
  position: absolute; inset: 0;
  border-radius: 18px;
  background: linear-gradient(135deg, transparent 45%, rgba(56,225,255,0.2) 50%, transparent 55%);
  opacity: 0.25;
  pointer-events: none;
}
@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.phrase-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
.pill {
  font-family: var(--display);
  font-size: 10px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--cyan);
  background: rgba(56,225,255,0.08);
  border: 1px solid rgba(56,225,255,0.3);
  padding: 4px 10px;
  border-radius: 999px;
}
.phrase-context {
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  max-width: 60%;
  text-align: right;
  line-height: 1.3;
}

.phrase-arabic {
  font-size: 38px;
  font-weight: 500;
  line-height: 1.2;
  color: #fff;
  text-align: right;
  margin: 6px 0 4px;
  font-family: "Amiri", "Noto Naskh Arabic", "Geeza Pro", serif;
  letter-spacing: 0;
}
.phrase-translit {
  font-family: var(--display);
  font-weight: 500;
  font-size: 16px;
  color: var(--gold);
  letter-spacing: 0.08em;
  margin-bottom: 4px;
}
.phrase-english {
  font-size: 14px;
  color: var(--text);
  opacity: 0.85;
  margin-bottom: 14px;
}

.phrase-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.btn {
  flex: 1;
  font-family: var(--body);
  font-weight: 500;
  font-size: 13px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(0.97); }
.btn-ghost:hover { border-color: rgba(56,225,255,0.4); }
.btn-accent {
  background: linear-gradient(135deg, var(--cyan), var(--cyan-deep));
  color: #02121b;
  border-color: rgba(56,225,255,0.6);
  font-weight: 600;
  box-shadow: 0 0 0 1px rgba(56,225,255,0.25), 0 8px 30px rgba(56,225,255,0.25);
}
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.practice-result {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px dashed var(--line);
  animation: rise 0.4s ease both;
}
.score-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 6px;
}
.score-label {
  font-family: var(--display);
  font-size: 11px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--muted);
}
.score-dots {
  display: flex;
  gap: 6px;
}
.score-dots span {
  width: 14px; height: 14px;
  border-radius: 50%;
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--line);
}
.score-dots span.on {
  background: var(--cyan);
  border-color: var(--cyan);
  box-shadow: 0 0 10px rgba(56,225,255,0.7);
}
.feedback {
  margin: 0;
  font-size: 14px;
  color: var(--text);
  line-height: 1.5;
}

/* ——— Transcript ——— */

.transcript {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 6px 2px 18px;
  scrollbar-width: thin;
  scrollbar-color: var(--cyan-deep) transparent;
}
.transcript::-webkit-scrollbar { width: 6px; }
.transcript::-webkit-scrollbar-thumb { background: var(--cyan-deep); border-radius: 4px; }

.bubble {
  max-width: 88%;
  padding: 11px 14px 12px;
  border-radius: 16px;
  font-size: 15px;
  line-height: 1.45;
  position: relative;
  animation: rise 0.4s cubic-bezier(.2,.9,.3,1) both;
}
.bubble .who {
  font-family: var(--display);
  font-size: 9px;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  display: block;
  margin-bottom: 4px;
  opacity: 0.7;
}
.bubble.user {
  align-self: flex-end;
  background: linear-gradient(135deg, rgba(247,193,74,0.12), rgba(247,193,74,0.03));
  border: 1px solid rgba(247,193,74,0.25);
  color: #fff5d9;
  border-bottom-right-radius: 4px;
}
.bubble.user .who { color: var(--gold); }
.bubble.jarvis {
  align-self: flex-start;
  background: linear-gradient(135deg, rgba(56,225,255,0.09), rgba(56,225,255,0.02));
  border: 1px solid rgba(56,225,255,0.25);
  border-bottom-left-radius: 4px;
}
.bubble.jarvis .who { color: var(--cyan); }
.bubble.sys {
  align-self: center;
  background: transparent;
  border: 1px dashed var(--line);
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

/* ——— Dock with mic orb ——— */

.dock {
  position: relative;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 14px 16px calc(18px + var(--safe-bot));
  border-top: 1px solid var(--line);
  background: linear-gradient(180deg, transparent 0%, rgba(5,7,13,0.9) 40%, var(--bg));
  backdrop-filter: blur(10px);
}
.status {
  font-size: 13px;
  color: var(--muted);
  text-align: center;
  letter-spacing: 0.02em;
  min-height: 18px;
}
.hint {
  font-size: 10px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--muted);
  opacity: 0.7;
}

.mic-orb {
  position: relative;
  width: 92px; height: 92px;
  border-radius: 50%;
  border: 0;
  background: transparent;
  color: var(--cyan);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  display: grid;
  place-items: center;
}
.orb-core {
  position: absolute; inset: 12px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, #1bd0ff 0%, #0c6a88 55%, #062d3d 100%);
  box-shadow:
    0 0 30px rgba(56, 225, 255, 0.55),
    inset 0 0 20px rgba(255,255,255,0.2),
    inset 0 -10px 20px rgba(0,0,0,0.35);
  transition: transform 0.25s, box-shadow 0.25s;
}
.orb-ring {
  position: absolute;
  border-radius: 50%;
  border: 1px solid rgba(56, 225, 255, 0.45);
}
.orb-ring.r1 { inset: 0; }
.orb-ring.r2 { inset: -10px; border-color: rgba(56, 225, 255, 0.2); }
.orb-ring.r3 { inset: -22px; border-color: rgba(56, 225, 255, 0.08); }

.orb-glyph {
  position: relative;
  z-index: 2;
  color: #02121b;
  filter: drop-shadow(0 0 4px rgba(255,255,255,0.6));
}

.mic-orb.listening .orb-core {
  background: radial-gradient(circle at 30% 30%, #ff9da6 0%, #c8344a 55%, #2d0610 100%);
  box-shadow:
    0 0 40px rgba(255, 100, 120, 0.8),
    inset 0 0 25px rgba(255,255,255,0.3),
    inset 0 -10px 20px rgba(0,0,0,0.35);
}
.mic-orb.listening .orb-ring {
  animation: ripple 1.6s ease-out infinite;
  border-color: rgba(255, 109, 122, 0.55);
}
.mic-orb.listening .orb-ring.r2 { animation-delay: 0.4s; }
.mic-orb.listening .orb-ring.r3 { animation-delay: 0.8s; }
.mic-orb.listening .orb-glyph { color: #fff; }

@keyframes ripple {
  0% { transform: scale(1); opacity: 0.9; }
  100% { transform: scale(1.7); opacity: 0; }
}

.mic-orb.thinking .orb-core {
  background: conic-gradient(from 0deg, var(--cyan), transparent 60%, var(--cyan));
  animation: spin 1.2s linear infinite;
}
.mic-orb.thinking .orb-ring { animation: breathe 1.8s ease-in-out infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes breathe {
  0%, 100% { opacity: 0.2; }
  50% { opacity: 0.6; }
}

.mic-orb.speaking .orb-core {
  background: radial-gradient(circle at 30% 30%, #fbe592 0%, #b88213 55%, #3d2806 100%);
  box-shadow:
    0 0 45px rgba(247, 193, 74, 0.75),
    inset 0 0 25px rgba(255,255,255,0.35);
}
.mic-orb.speaking .orb-ring {
  animation: ripple 2.2s ease-out infinite;
  border-color: rgba(247, 193, 74, 0.5);
}
.mic-orb.speaking .orb-glyph { color: #2a1a00; }

/* ——— Phrase card: responsive tuning ——— */
@media (max-width: 420px) {
  .phrase-arabic { font-size: 30px; }
  .stats .stat label { font-size: 8px; }
  .mic-orb { width: 84px; height: 84px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0s !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0s !important;
  }
}
