/* durusi a3 — a2 visual language: #0b6fb0, Baloo Bhaijaan 2 + IBM Plex Sans Arabic, big rounded cards, RTL, mobile-first */
:root {
  --brand: #0b6fb0;
  --brand-d: #085689;
  --brand-l: #e7f2fa;
  --accent: #ffb020;
  --ok: #1f9d55;
  --no: #d64545;
  --ink: #17324a;
  --muted: #5d7385;
  --bg: #f4f8fb;
  --card: #fff;
  --r: 20px;
  --shadow: 0 6px 22px rgba(11, 111, 176, .12);
  --tap: 52px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: 'IBM Plex Sans Arabic', system-ui, sans-serif;
  color: var(--ink); background: var(--bg);
  min-height: 100vh; -webkit-tap-highlight-color: transparent;
  padding-bottom: env(safe-area-inset-bottom);
}
h1, h2, h3, .brand, .btn, .seg-b, .word-now, .code, .mode-card b {
  font-family: 'Baloo Bhaijaan 2', 'IBM Plex Sans Arabic', system-ui, sans-serif;
}
h1 { font-size: clamp(1.6rem, 5vw, 2.4rem); margin: .3em 0; }
h2 { font-size: 1.5rem; margin: 0 0 .4em; }
h3 { font-size: 1.15rem; margin: 0 0 .5em; }
.muted { color: var(--muted); }
[hidden] { display: none !important; }

/* top bar */
.top {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px 16px; background: var(--brand); color: #fff;
  box-shadow: 0 2px 10px rgba(0, 0, 0, .12);
}
.top .muted { color: #d5e8f5; font-size: .9rem; }
.brand { color: #fff; text-decoration: none; font-size: 1.6rem; font-weight: 800; line-height: 1; }
.brand small { font-size: .8rem; opacity: .8; }
.tag { opacity: .85; }
.conn {
  margin-inline-start: auto; font-size: .85rem; padding: 6px 12px; border-radius: 999px;
  background: rgba(255, 255, 255, .15); max-width: 70vw;
}
.conn.on, .conn[data-connected="1"] { background: #e8f7ee; color: var(--ok); font-weight: 700; }
.conn.off[data-reason]:not([data-reason="idle"]):not([data-reason="connecting"]) { background: #fde8e8; color: var(--no); }

/* buttons & fields */
.btn {
  min-height: var(--tap); padding: 8px 18px; border-radius: 16px; border: 2px solid var(--brand-l);
  background: #fff; color: var(--brand-d); font-size: 1.05rem; font-weight: 700; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  transition: transform .08s, box-shadow .15s, background .15s;
}
.btn:hover { box-shadow: var(--shadow); }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--brand); color: #fff; border-color: var(--brand); }
.btn.accent { background: var(--accent); color: #3b2600; border-color: var(--accent); }
.btn.big { min-height: 58px; font-size: 1.15rem; padding: 10px 22px; }
.btn.round { width: var(--tap); padding: 0; border-radius: 50%; font-size: 1.3rem; }
.btn[aria-pressed="true"] { background: var(--brand-l); border-color: var(--brand); }
.btn.rec, .btn.mic.rec { background: var(--no); color: #fff; border-color: var(--no); animation: pulse 1s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 10px rgba(214, 69, 69, .18); } }
.field {
  min-height: var(--tap); padding: 8px 14px; border-radius: 14px; border: 2px solid #d4e3ee;
  font: inherit; font-size: 1.05rem; background: #fff; color: var(--ink); min-width: 0;
}
.field:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-l); }
.field.big { min-height: 60px; font-size: 1.2rem; }
.code-in { letter-spacing: .35em; text-transform: uppercase; text-align: center; font-weight: 700; }
.grow { flex: 1; }
.lbl { display: flex; flex-direction: column; gap: 6px; font-weight: 700; }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.chip {
  display: inline-flex; align-items: center; gap: 4px; padding: 6px 12px; border-radius: 999px;
  background: var(--brand-l); color: var(--brand-d); font-weight: 700; border: 0; cursor: pointer; font: inherit;
}
.pill { padding: 8px 12px; border-radius: 999px; background: #eef3f7; font-weight: 700; font-size: .9rem; }
.pill[data-on="1"] { background: #e8f7ee; color: var(--ok); }

/* layout */
.layout { display: grid; gap: 14px; padding: 14px; max-width: 1280px; margin: 0 auto; }
.panel { background: var(--card); border-radius: var(--r); padding: 14px; box-shadow: var(--shadow); }
.stage-col, .side-col { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
@media (min-width: 960px) {
  .layout.teacher { grid-template-columns: 1fr 360px; }
  .layout.teacher .start { grid-column: 1 / -1; }
  .layout.student.joined, body.joined .layout.student { grid-template-columns: 1fr 320px; }
  .layout.ai { grid-template-columns: 1fr 360px; }
}
body.joined .layout.student .banner { grid-column: 1 / -1; }

/* landing */
.landing { max-width: 980px; margin: 0 auto; padding: 18px; }
.hero { text-align: center; position: relative; }
.hero-art { width: 100%; max-height: 260px; object-fit: cover; border-radius: var(--r); box-shadow: var(--shadow); }
.modes { display: grid; gap: 14px; margin-top: 16px; }
@media (min-width: 760px) { .modes { grid-template-columns: repeat(3, 1fr); } }
.mode-card {
  display: flex; flex-direction: column; gap: 8px; padding: 20px; border-radius: 24px; text-decoration: none;
  background: #fff; color: var(--ink); box-shadow: var(--shadow); border: 3px solid transparent; min-height: 180px;
  transition: transform .1s, border-color .15s;
}
.mode-card:hover { border-color: var(--brand); transform: translateY(-2px); }
.mode-card b { font-size: 1.5rem; color: var(--brand-d); }
.mode-card.ai { background: linear-gradient(160deg, #fff, #eaf4fb); }
.mode-card.alt { background: #fffaf0; }
.mode-ic { font-size: 2.4rem; }
.foot { text-align: center; padding: 20px; }

/* code box */
.code-box { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 12px; }
.code { font-size: 2.4rem; letter-spacing: .25em; color: var(--brand); background: var(--brand-l); padding: 2px 16px; border-radius: 14px; }
.join-link { font-size: .85rem; color: var(--muted); word-break: break-all; }

/* scene */
.scene {
  position: relative; border-radius: 24px; overflow: hidden; min-height: 320px; aspect-ratio: 16 / 10;
  background: linear-gradient(160deg, #cfe6f5, #fdf3e1); box-shadow: var(--shadow);
}
@media (max-width: 600px) { .scene { aspect-ratio: auto; min-height: 430px; } }
.scene .scene-bg { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.scene-layer {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 12px; padding: 14px; background: linear-gradient(180deg, rgba(255,255,255,.0) 0, rgba(255,255,255,.12) 60%, rgba(10,40,60,.25));
}
.scene-badges { position: absolute; top: 10px; inset-inline-start: 10px; display: flex; gap: 6px; flex-wrap: wrap; }
.badge { background: rgba(255,255,255,.92); border-radius: 999px; padding: 4px 12px; font-weight: 700; font-size: .9rem; }
.badge.stage-live { background: var(--brand); color: #fff; }
.badge.stage-review { background: var(--accent); color: #3b2600; }
.badge.stage-mastery { background: var(--ok); color: #fff; }
.word-card {
  background: rgba(255,255,255,.95); border-radius: 26px; padding: 16px 26px; text-align: center;
  box-shadow: 0 10px 30px rgba(0,0,0,.18); display: flex; flex-direction: column; align-items: center; gap: 6px;
  min-width: 220px; animation: pop .35s ease;
}
@keyframes pop { from { transform: scale(.9); opacity: 0; } }
.word-card.fb-ok { outline: 5px solid var(--ok); }
.word-card.fb-no { outline: 5px solid var(--no); animation: shake .35s; }
@keyframes shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
.word-emoji { font-size: clamp(3rem, 12vw, 5.5rem); line-height: 1.1; }
.big-ear { font-size: 3.5rem; border: 0; background: var(--brand-l); border-radius: 50%; width: 110px; height: 110px; cursor: pointer; }
.word-now { font-size: clamp(2rem, 7vw, 3.2rem); font-weight: 800; color: var(--brand-d); line-height: 1.1; }
.frame { font-size: 1.3rem; font-weight: 700; color: var(--ink); }
.prompt { font-size: 1.05rem; color: var(--muted); }
.answers { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; width: min(560px, 100%); }
.answers-hint { grid-column: 1 / -1; text-align: center; background: rgba(255,255,255,.9); padding: 8px 14px; border-radius: 14px; font-weight: 700; }
.choice {
  min-height: 60px; border-radius: 18px; border: 3px solid #fff; background: rgba(255,255,255,.96);
  font-family: 'Baloo Bhaijaan 2', system-ui, sans-serif; font-size: 1.4rem; font-weight: 800; color: var(--brand-d);
  cursor: pointer; box-shadow: 0 4px 14px rgba(0,0,0,.12);
}
.choice:hover:not(:disabled) { border-color: var(--brand); }
.choice.picked { border-color: var(--brand); background: var(--brand-l); }
.choice.right { border-color: var(--ok); background: #e8f7ee; }
.choice:disabled { cursor: default; opacity: .85; }
.scene.no-art .scene-layer { background: none; }

/* tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.tile {
  position: relative; border-radius: 18px; overflow: hidden; background: #dbe9f3; aspect-ratio: 4 / 3;
  display: flex; align-items: center; justify-content: center; border: 4px solid transparent; transition: border-color .2s, transform .2s;
}
.tile video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.tile video.mirror { transform: scaleX(-1); }
.tile.has-video .avatar { display: none; }
.avatar { font-size: 2.4rem; font-weight: 800; color: var(--brand-d); font-family: 'Baloo Bhaijaan 2', sans-serif; }
.tile-bar {
  position: absolute; inset-inline: 0; bottom: 0; display: flex; justify-content: space-between; gap: 6px;
  padding: 4px 8px; background: linear-gradient(transparent, rgba(0,0,0,.55)); color: #fff; font-weight: 700; font-size: .9rem;
}
.tile.speaking { border-color: #7cc4f5; }
.tile.spot { border-color: var(--accent); transform: scale(1.04); box-shadow: 0 0 0 6px rgba(255,176,32,.35); z-index: 1; }
.tile.spot::after { content: '🔦'; position: absolute; top: 6px; inset-inline-end: 8px; font-size: 1.4rem; }
.tile.self .tile-name::after { content: ' (أنت)'; }
.btn-call {
  position: absolute; top: 6px; inset-inline-start: 6px; min-height: 40px; padding: 4px 10px; border-radius: 12px; border: 0;
  background: rgba(255,255,255,.92); color: var(--brand-d); font-weight: 800; cursor: pointer; font-family: inherit;
}
.tile.spot .btn-call { background: var(--accent); color: #3b2600; }
.teacher-cam { aspect-ratio: 16 / 9; }
.stage-col > .teacher-cam { max-height: 260px; }
.teacher-cam[data-present="0"] .tile-name::after { content: ' — لسه ما دخل'; }
.me-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* actor (a2 teacher video) */
.actor-box, .actor { position: relative; border-radius: 18px; overflow: hidden; background: #eaf4fb; aspect-ratio: 4 / 5; min-height: 140px; }
.actor-box.big { aspect-ratio: auto; height: 100%; min-height: 260px; }
.actor-v, .actor-still { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: 0; transition: opacity .18s; }
.actor-v.show, .actor-still:not([hidden]) { opacity: 1; }
.actor-mood {
  position: absolute; bottom: 8px; inset-inline-start: 8px; background: rgba(255,255,255,.92); border-radius: 999px;
  padding: 4px 10px; font-weight: 700; font-size: .85rem;
}
.actor[data-talking="1"] { box-shadow: 0 0 0 4px #7cc4f5; }

/* spotlight banner */
.banner {
  padding: 14px 18px; border-radius: var(--r); background: #fff4dc; color: #6a4500; font-weight: 800; font-size: 1.1rem;
  text-align: center; box-shadow: var(--shadow); border: 3px solid var(--accent);
}
.banner.mine { background: var(--accent); color: #2b1b00; font-size: 1.3rem; animation: pulse 1.2s infinite; }

/* answers board + scoreboard */
.board-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.board ul, .scoreboard ol { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; max-height: 320px; overflow: auto; }
.board li, .scoreboard li { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 12px; background: #f3f7fa; }
.board li.ok { background: #e8f7ee; }
.board li.no { background: #fdeeee; }
.board .nm, .scoreboard .nm { font-weight: 700; flex: 1; }
.board .val { font-family: 'Baloo Bhaijaan 2', sans-serif; font-weight: 700; }
.scoreboard li.me { outline: 2px solid var(--brand); }
.pts { font-size: 1.2rem; color: var(--brand-d); }

/* quick-fire */
.quickfire { border: 3px solid var(--accent); text-align: center; animation: pop .3s; }
.qf-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 1.1rem; }
.qf-emoji { font-size: 4rem; }
.qf-choices { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.quickfire .choice { border-color: #f1f4f7; }

/* controls */
.controls { display: flex; flex-direction: column; gap: 12px; }
.seg { display: flex; flex-wrap: wrap; gap: 6px; background: #eef3f7; padding: 5px; border-radius: 18px; }
.seg-b {
  flex: 1 1 auto; min-height: 48px; border: 0; border-radius: 14px; background: transparent; font-size: 1.05rem;
  font-weight: 700; color: var(--muted); cursor: pointer; padding: 6px 12px;
}
.seg-b[aria-pressed="true"] { background: var(--brand); color: #fff; box-shadow: var(--shadow); }
.word-nav { justify-content: space-between; }
.answer-bar, .talk-bar, .media-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.join { display: flex; flex-direction: column; gap: 14px; max-width: 520px; width: 100%; margin: 0 auto; }
body[data-page="student"]:not(.joined) .stage-col,
body[data-page="student"]:not(.joined) .side-col { opacity: .55; pointer-events: none; }
body[data-page="ai"]:not(.joined) .talk-bar,
body[data-page="ai"]:not(.joined) .answer-bar { opacity: .5; }

/* AI */
.ai-stage { display: grid; grid-template-columns: minmax(130px, 34%) 1fr; gap: 12px; }
@media (max-width: 600px) { .ai-stage { grid-template-columns: 1fr; } .actor-box.big { min-height: 240px; aspect-ratio: 4 / 3; } }
.scene-layer.ai { justify-content: flex-end; align-items: stretch; }
.ticket { background: rgba(255,255,255,.95); border-radius: 16px; padding: 10px 14px; align-self: flex-end; min-width: 150px; box-shadow: var(--shadow); }
.ticket ul { margin: 6px 0 0; padding: 0 18px 0 0; font-weight: 700; }
.ticket .total { font-weight: 800; color: var(--brand-d); margin-top: 4px; }
.target-card { background: rgba(255,255,255,.96); border-radius: 18px; padding: 10px 14px; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; box-shadow: var(--shadow); }
.target { font-family: 'Baloo Bhaijaan 2', sans-serif; font-size: 1.5rem; font-weight: 800; color: var(--brand-d); flex: 1; }
.done-badge { background: var(--ok); color: #fff; padding: 10px; border-radius: 14px; text-align: center; font-weight: 800; }
.btn.mic { background: var(--brand); color: #fff; border-color: var(--brand); flex: 1; font-size: 1.3rem; min-height: 64px; }
.interim { min-height: 1.6em; text-align: center; color: var(--muted); font-size: 1.1rem; }
.transcript { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; max-height: 60vh; overflow: auto; }
.transcript .line { display: flex; gap: 8px; padding: 8px 12px; border-radius: 14px; background: #f3f7fa; align-items: baseline; }
.transcript .line b { white-space: nowrap; color: var(--muted); font-size: .85rem; }
.transcript .line span { flex: 1; }
.transcript .her { background: var(--brand-l); }
.transcript .her span[lang="en"] { font-weight: 700; font-size: 1.05rem; }
.transcript .hint { background: #fff4dc; }
.transcript .target span { font-family: 'Baloo Bhaijaan 2', sans-serif; font-size: 1.2rem; color: var(--brand-d); }
.transcript .correct { background: #eef9f1; }
.transcript .me { background: #fff; border: 2px solid #e2ecf3; }
.transcript .sys { background: transparent; color: var(--muted); }

/* toast */
#toast {
  position: fixed; bottom: calc(18px + env(safe-area-inset-bottom)); left: 50%; transform: translate(-50%, 30px);
  background: var(--ink); color: #fff; padding: 12px 20px; border-radius: 16px; font-weight: 700; z-index: 50;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; max-width: 90vw; text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
