/* ===== Engine Cadet Master — Design System V3 (LOCKED) =====
   Navy #0a1628 + Gold #d4a857 · Cormorant Garamond + JetBrains Mono + Cairo · RTL
   Animations: transform only — opacity is NEVER animated. Fallback: always visible. */

:root {
  --navy: #0a1628;
  --navy-2: #0f2038;
  --navy-3: #15294a;
  --gold: #d4a857;
  --gold-soft: #e6c789;
  --ink: #eaf0fb;
  --ink-dim: #aebbd4;
  --line: rgba(212, 168, 87, 0.22);
  --ask: #1a3a5c;   /* asker bubble (right) */
  --cadet: #143049; /* cadet bubble (left) */
  --ok: #4cc38a;
  --bad: #e5616a;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  --serif: 'Cormorant Garamond', Georgia, serif;
  --mono: 'JetBrains Mono', ui-monospace, monospace;
  --arab: 'Cairo', 'Segoe UI', Tahoma, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
.hidden { display: none !important; }
/* number-only labels read left-to-right even inside the RTL layout */
.ltr-num { direction: ltr; unicode-bidi: isolate; }

html, body {
  background: var(--navy);
  color: var(--ink);
  font-family: var(--arab);
  direction: rtl;
  min-height: 100%;
  overflow-x: hidden;
}
body {
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(212,168,87,0.10), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, rgba(21,41,74,0.8), transparent 60%),
    var(--navy);
  padding-bottom: 40px;
}

/* ---- App gate (license) ---- */
#gate {
  position: fixed; inset: 0; z-index: 50;
  background: var(--navy);
  display: flex; align-items: center; justify-content: center; padding: 22px;
}
#gate.hidden { display: none; }
.gate-card {
  width: 100%; max-width: 440px;
  background: linear-gradient(180deg, var(--navy-2), var(--navy));
  border: 1px solid var(--line); border-radius: 20px;
  padding: 26px 22px; box-shadow: var(--shadow); text-align: center;
}
.gate-card h1 { font-family: var(--serif); color: var(--gold); font-size: 30px; letter-spacing: .5px; }
.gate-card .sub { color: var(--ink-dim); font-size: 14px; margin: 6px 0 18px; }
.device-box {
  font-family: var(--mono); background: #06101e; border: 1px dashed var(--line);
  color: var(--gold-soft); border-radius: 12px; padding: 12px; font-size: 18px;
  letter-spacing: 2px; margin: 8px 0 4px; user-select: all; word-break: break-all;
}
.device-label { font-size: 12px; color: var(--ink-dim); }
#licenseInput {
  width: 100%; margin-top: 16px; text-align: center; letter-spacing: 3px;
  font-family: var(--mono); font-size: 18px; text-transform: uppercase;
  background: #06101e; color: var(--ink); border: 1px solid var(--line);
  border-radius: 12px; padding: 14px; outline: none;
}
#licenseInput:focus { border-color: var(--gold); }
.btn {
  font-family: var(--arab); font-weight: 700; cursor: pointer; border: none;
  border-radius: 12px; padding: 13px 18px; font-size: 16px;
  background: linear-gradient(180deg, var(--gold-soft), var(--gold));
  color: #1a1205; transition: transform .15s ease; will-change: transform;
}
.btn:active { transform: scale(.97); }
.btn.ghost { background: transparent; color: var(--gold); border: 1px solid var(--line); }
.btn.block { width: 100%; margin-top: 14px; }
.gate-msg { min-height: 20px; font-size: 13px; margin-top: 12px; }
.gate-msg.ok { color: var(--ok); }
.gate-msg.bad { color: var(--bad); }
.copy-mini { font-size: 12px; color: var(--gold); background: transparent; border: 1px solid var(--line); border-radius: 8px; padding: 4px 10px; cursor: pointer; margin-top: 6px; }

/* ---- Header ---- */
header.app {
  text-align: center; padding: 22px 16px 8px;
}
header.app .brand { font-family: var(--serif); color: var(--gold); font-size: 34px; line-height: 1; }
header.app .count { font-family: var(--arab); color: var(--ink); font-size: 18px; font-weight: 700; margin-top: 4px; }
header.app .tag { color: var(--ink-dim); font-size: 13px; margin-top: 2px; }

.progress-wrap { max-width: 760px; margin: 14px auto 0; padding: 0 16px; }
.progress-track { height: 10px; background: #06101e; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.progress-fill { height: 100%; width: 0%; background: linear-gradient(90deg, var(--gold), var(--gold-soft)); border-radius: 999px; transition: width .4s ease; }
.progress-text { text-align: center; font-size: 12px; color: var(--ink-dim); margin-top: 6px; font-family: var(--mono); direction: ltr; }

/* ---- Sections grid (home) ---- */
.sections {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px;
  max-width: 760px; margin: 18px auto; padding: 0 16px;
}
.section-card {
  position: relative; background: linear-gradient(180deg, var(--navy-2), var(--navy));
  border: 1px solid var(--line); border-radius: 18px; padding: 18px 16px;
  cursor: pointer; transition: transform .18s ease; will-change: transform;
  box-shadow: var(--shadow); min-height: 132px; display: flex; flex-direction: column; justify-content: space-between;
}
.section-card:active { transform: translateY(2px) scale(.99); }
.section-card .s-no { font-family: var(--mono); color: var(--gold); font-size: 13px; }
.section-card .s-title { font-family: var(--arab); font-weight: 700; font-size: 17px; margin-top: 6px; line-height: 1.35; }
.section-card .s-meta { font-size: 12px; color: var(--ink-dim); margin-top: 10px; font-family: var(--mono); direction: ltr; text-align: right; }
.section-card .s-bar { height: 6px; background: #06101e; border-radius: 999px; margin-top: 8px; overflow: hidden; }
.section-card .s-bar > i { display: block; height: 100%; width: 0; background: var(--gold); border-radius: 999px; transition: width .4s ease; }
.section-card.star { border-color: rgba(212,168,87,0.55); }
.section-card .star-badge { position: absolute; top: 12px; left: 12px; color: var(--gold); font-size: 18px; }

/* ---- Section view ---- */
.view { max-width: 760px; margin: 0 auto; padding: 0 16px; }
.view.hidden { display: none; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 16px 16px 6px; max-width: 760px; margin: 0 auto; }
.topbar .title { font-family: var(--serif); color: var(--gold); font-size: 22px; }
.mode-switch { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.mode-switch button { background: transparent; color: var(--ink-dim); border: none; padding: 8px 14px; font-family: var(--arab); font-weight: 700; cursor: pointer; font-size: 13px; }
.mode-switch button.active { background: var(--gold); color: #1a1205; }

.card-nav { display: flex; align-items: center; justify-content: space-between; margin: 10px 0; }
.card-nav .counter { font-family: var(--mono); color: var(--ink-dim); font-size: 13px; direction: ltr; }
.nav-btn { background: var(--navy-3); color: var(--gold); border: 1px solid var(--line); border-radius: 10px; padding: 10px 16px; font-size: 18px; cursor: pointer; transition: transform .15s ease; }
.nav-btn:active { transform: scale(.94); }

/* ---- Dialogue card ---- */
.qa-card {
  background: linear-gradient(180deg, var(--navy-2), var(--navy));
  border: 1px solid var(--line); border-radius: 20px; padding: 18px 16px 20px;
  box-shadow: var(--shadow); margin-bottom: 18px;
}
.bubble-row { display: flex; margin: 12px 0; align-items: flex-end; gap: 10px; }
.bubble-row.asker { justify-content: flex-start; flex-direction: row; }      /* asker on the RIGHT in RTL */
.bubble-row.cadet { justify-content: flex-end; flex-direction: row-reverse; } /* cadet on the LEFT in RTL */
.avatar { width: 40px; height: 40px; border-radius: 50%; flex: 0 0 40px; display: grid; place-items: center; font-size: 20px; border: 1px solid var(--line); }
.avatar.asker { background: var(--ask); }
.avatar.cadet { background: var(--cadet); }
.bubble {
  max-width: 78%; border-radius: 16px; padding: 12px 14px; position: relative;
  transform: translateY(8px); animation: rise .32s ease forwards; /* transform only */
}
@keyframes rise { to { transform: translateY(0); } }
.bubble.asker { background: var(--ask); border: 1px solid var(--line); border-bottom-right-radius: 4px; }
.bubble.cadet { background: var(--cadet); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.bubble .role { font-family: var(--mono); font-size: 11px; color: var(--gold); margin-bottom: 4px; }
.bubble .en { font-family: var(--serif); font-size: 19px; line-height: 1.35; color: var(--ink); }
.bubble .ar { font-family: var(--arab); font-size: 14px; color: var(--ink-dim); margin-top: 6px; line-height: 1.6; }
.bubble .play { margin-top: 8px; background: var(--navy); border: 1px solid var(--line); color: var(--gold); border-radius: 10px; padding: 7px 12px; font-size: 14px; cursor: pointer; display: inline-flex; gap: 6px; align-items: center; transition: transform .15s ease; }
.bubble .play:active { transform: scale(.94); }
.bubble .play.playing { background: var(--gold); color: #1a1205; }

.note {
  margin-top: 6px; background: rgba(212,168,87,0.08); border: 1px solid var(--line);
  border-radius: 14px; padding: 12px 14px; font-family: var(--arab); font-size: 14.5px;
  color: var(--gold-soft); line-height: 1.7;
}

/* Practice mode reveal */
.reveal-btn { width: 100%; margin: 6px 0 4px; }
.hidden-answer { display: none; }
.hidden-answer.show { display: block; }

.back-row { padding: 12px 16px; max-width: 760px; margin: 0 auto; }
.kbd-hint { text-align:center; color: var(--ink-dim); font-size: 12px; font-family: var(--mono); margin: 4px 0 24px; }

@media (max-width: 480px) {
  header.app .brand { font-size: 28px; }
  .bubble .en { font-size: 17px; }
  .sections { gap: 11px; }
  .section-card { min-height: 120px; padding: 14px 12px; }
}

/* Install button (PWA) */
#installBtn { position: fixed; bottom: 16px; inset-inline-start: 16px; z-index: 30; display: none; }
#installBtn.show { display: inline-flex; }
