:root {
  --bg: #061331;
  --bg-deep: #040b22;
  --surface: rgba(16, 34, 76, 0.55);
  --surface-2: rgba(28, 52, 104, 0.42);
  --line: rgba(120, 160, 255, 0.16);
  --line-2: rgba(120, 160, 255, 0.28);
  --ink: #eaf0fc;
  --muted: #93a3c6;
  --gold: #e2b84a;
  --gold-2: #f7da86;
  --gold-ink: #191204;
  --ok: #3ddc97;
  --warn: #ffd100;
  --bad: #ff7a7a;
  --hot: #ff7a45;
  --cool: #4cb8ff;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html { background: var(--bg-deep); }
body {
  margin: 0;
  min-height: 100dvh;
  color: var(--ink);
  font: 16px/1.55 Heebo, system-ui, sans-serif;
  background: radial-gradient(1200px 600px at 80% -10%, rgba(42, 100, 214, 0.35), transparent 60%),
    linear-gradient(165deg, #0a1e4a 0%, var(--bg) 40%, var(--bg-deep) 100%) fixed;
  -webkit-font-smoothing: antialiased;
}
h1, .brand { font-family: Rubik, Heebo, sans-serif; }
[hidden] { display: none !important; }

/* ── כותרת ── */
.top {
  display: flex; align-items: center; gap: 18px;
  padding: max(12px, env(safe-area-inset-top)) 20px 12px;
  border-bottom: 1px solid var(--line);
  background: rgba(4, 11, 34, 0.6);
  backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 5;
}
.brand { font-weight: 700; font-size: 19px; color: var(--gold-2); white-space: nowrap; }
.brand small { color: var(--muted); font-weight: 500; font-size: 13px; margin-inline-start: 6px; }
.gear { display: inline-block; animation: spin 12s linear infinite; }
.top-mid { flex: 1; display: flex; align-items: center; gap: 14px; min-width: 0; }
#lesson-title { font-weight: 700; white-space: nowrap; }
.progress { flex: 1; height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
#progress-bar { height: 100%; width: 0; background: linear-gradient(90deg, var(--gold), var(--gold-2)); transition: width 0.6s; }

/* ── כללי ── */
.view { padding: 20px; max-width: 1240px; margin: 0 auto; }
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: 0 20px 50px -20px rgba(0, 0, 0, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.04);
}
.btn {
  font: inherit; font-weight: 600;
  border: 1px solid var(--line-2); border-radius: 12px;
  background: var(--surface-2); color: var(--ink);
  padding: 10px 16px; cursor: pointer;
  transition: transform 0.12s, filter 0.2s, opacity 0.2s;
}
.btn:active { transform: scale(0.97); }
.btn.primary {
  background: linear-gradient(180deg, var(--gold-2), var(--gold));
  color: var(--gold-ink); border-color: transparent;
  box-shadow: 0 10px 30px -10px rgba(226, 184, 74, 0.7);
}
.btn.ghost { background: transparent; }
.btn.big { padding: 15px 22px; font-size: 18px; width: 100%; }
.btn:disabled { opacity: 0.38; cursor: default; box-shadow: none; }

/* ── כניסה ── */
.entry { max-width: 520px; margin: 24px auto; padding: 28px; text-align: center; }
.entry h1 { margin: 6px 0 6px; font-size: 30px; }
.lead { color: var(--muted); margin: 0 0 20px; }
.lead b { color: var(--gold-2); }
.entry-avatar { width: 150px; height: 165px; margin: 0 auto; }
form { display: grid; gap: 14px; text-align: start; }
form label { display: grid; gap: 6px; font-weight: 500; }
input {
  font: inherit; color: var(--ink);
  background: rgba(4, 11, 34, 0.55);
  border: 1px solid var(--line-2); border-radius: 12px;
  padding: 12px 14px;
}
input:focus, select:focus { outline: 2px solid var(--gold); outline-offset: 1px; }
.seg { border: 0; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.seg legend { font-weight: 500; margin-bottom: 6px; }
.seg label { display: block; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span {
  display: block; text-align: center; padding: 10px; border-radius: 12px;
  border: 1px solid var(--line-2); background: var(--surface-2); cursor: pointer;
}
.seg input:checked + span { background: rgba(226, 184, 74, 0.16); border-color: var(--gold); color: var(--gold-2); font-weight: 700; }
.tips { list-style: none; padding: 12px 14px; margin: 0; border-radius: 12px; background: rgba(4, 11, 34, 0.4); color: var(--muted); font-size: 14px; display: grid; gap: 4px; }
.err { color: var(--bad); margin: 0; text-align: center; }

/* ── שיעור ── */
.lesson {
  display: grid;
  grid-template-columns: 340px 1fr;
  grid-template-areas: 'inst diag' 'ctrl diag';
  grid-template-rows: 1fr auto;
  gap: 18px;
  min-height: calc(100dvh - 70px);
}
.instructor { grid-area: inst; padding: 18px; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.avatar { width: 100%; max-width: 280px; aspect-ratio: 300 / 330; }
.av-svg { width: 100%; height: 100%; display: block; overflow: visible; }
.status { display: flex; align-items: center; gap: 8px; font-weight: 600; color: var(--muted); }
.status .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); }
.avatar[data-state='speaking'] ~ .status .dot { background: var(--gold); box-shadow: 0 0 12px var(--gold); }
.avatar[data-state='listening'] ~ .status { color: var(--ok); }
.avatar[data-state='listening'] ~ .status .dot { background: var(--ok); box-shadow: 0 0 12px var(--ok); animation: pulse 1.2s infinite; }
.avatar[data-state='thinking'] ~ .status .dot { background: var(--cool); animation: pulse 0.7s infinite; }
.caption {
  margin: 0; width: 100%; min-height: 4.6em;
  font-size: 18px; line-height: 1.5; text-align: center;
  padding: 12px 14px; border-radius: 14px; background: rgba(4, 11, 34, 0.45);
}
.heard {
  margin: 0; width: 100%; font-size: 15px; color: var(--ok);
  padding: 8px 12px; border-radius: 12px; border: 1px dashed rgba(61, 220, 151, 0.4);
}
.heard::before { content: 'אתה: '; font-weight: 700; }

.diagram { grid-area: diag; min-width: 0; padding: 14px; position: relative; display: flex; flex-direction: column; justify-content: center; }
#diagram { width: 100%; }
.hint-line { margin: 4px 0 0; text-align: center; color: var(--muted); font-size: 14px; }
.toast {
  position: absolute; top: 14px; inset-inline: 0; margin: 0 auto; width: max-content;
  padding: 10px 18px; border-radius: 99px; font-weight: 700; font-size: 17px;
  background: rgba(4, 11, 34, 0.9); border: 1px solid var(--line-2);
  animation: pop 0.35s cubic-bezier(0.2, 0.8, 0.2, 1.4);
}
.toast.ok { color: var(--ok); border-color: var(--ok); }
.toast.mid { color: var(--warn); border-color: var(--warn); }
.toast.bad { color: var(--bad); border-color: var(--bad); }

.controls { grid-area: ctrl; display: grid; gap: 10px; align-content: end; }
.ctrl-row { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
select { font: inherit; color: var(--ink); background: var(--surface-2); border: 1px solid var(--line-2); border-radius: 12px; padding: 10px; }
#btn-done { display: flex; align-items: center; justify-content: center; gap: 10px; }
#btn-done:not(:disabled) { animation: glow 1.6s infinite; }
.mic-level { width: 8px; height: 22px; border-radius: 4px; background: rgba(0, 0, 0, 0.25); display: flex; align-items: flex-end; overflow: hidden; }
.mic-level i { display: block; width: 100%; height: 0; background: var(--gold-ink); transition: height 0.08s; }

/* ── שרטוט ── */
.dg-svg { width: 100%; height: auto; display: block; }
.dg-label { fill: var(--ink); font: 600 15px Heebo, sans-serif; paint-order: stroke; stroke: #061331; stroke-width: 4px; }
.dg-note { fill: var(--muted); font: 500 13px Heebo, sans-serif; }
.part { cursor: pointer; transition: opacity 0.35s; }
.part.dim { opacity: 0.28; }
.part.hl { filter: url(#dgGlow); }
.part.hl .dg-label { fill: var(--gold-2); font-weight: 700; }
.part:hover { opacity: 1; }
.part.picked { animation: blink 0.7s; }
.flow { fill: none; stroke-width: 4; stroke-linecap: round; stroke-dasharray: 9 13; opacity: 0; transition: opacity 0.5s; }
.dg-svg[data-mode='flow'] .f-main,
.dg-svg[data-mode='flow'] .f-engine,
.dg-svg[data-mode='cold'] .f-engine,
.dg-svg[data-mode='cold'] .f-bypass { opacity: 1; animation: dash 1.1s linear infinite; }
.dg-svg[data-mode='flow'] .fan-blades { animation: spin 0.9s linear infinite; }
.dg-svg[data-mode='flow'] .impeller,
.dg-svg[data-mode='cold'] .impeller { animation: spin 0.8s linear infinite; }
.valve-disk { transition: transform 0.6s; transform-box: fill-box; transform-origin: center; }
.dg-svg[data-mode='flow'] .valve-disk { transform: rotate(90deg) scaleX(0.4); }
.dg-svg[data-mode='cold'] .valve-disk { fill: var(--bad); }

@keyframes dash { to { stroke-dashoffset: -44; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 50% { opacity: 0.35; } }
@keyframes pop { from { transform: scale(0.6); opacity: 0; } }
@keyframes blink { 30% { opacity: 0.3; } }
@keyframes glow { 50% { box-shadow: 0 0 0 6px rgba(226, 184, 74, 0.18), 0 10px 30px -10px rgba(226, 184, 74, 0.7); } }

/* ── סיום ── */
.done .score { font: 700 54px Rubik, sans-serif; color: var(--gold-2); margin: 10px 0; }
.done p { color: var(--muted); }

/* ── טלפון ── */
@media (max-width: 860px) {
  .view { padding: 12px; }
  .lesson {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: 'inst' 'diag' 'ctrl';
    grid-template-rows: auto auto auto;
    min-height: 0;
    gap: 12px;
    padding-bottom: 150px;
  }
  .instructor { flex-direction: row; flex-wrap: wrap; align-items: center; padding: 12px; gap: 10px; }
  .avatar { width: 92px; flex: none; }
  .status { flex: 1; }
  .caption { min-height: 0; font-size: 16px; text-align: start; }
  .controls {
    position: fixed; bottom: 0; inset-inline: 0; z-index: 6;
    padding: 10px 12px max(10px, env(safe-area-inset-bottom));
    background: rgba(4, 11, 34, 0.92); border-top: 1px solid var(--line); backdrop-filter: blur(8px);
  }
  .top { padding-inline: 12px; gap: 10px; }
  .brand small { display: none; }
  #lesson-title { display: none; }
  /* בטלפון השרטוט רחב יותר מהמסך: אפשר לגלול הצידה, והחלק המודגש נגלל למרכז */
  #diagram { overflow-x: auto; scrollbar-width: none; }
  #diagram::-webkit-scrollbar { display: none; }
  .dg-svg { width: 640px; max-width: none; }
  .dg-label { font-size: 17px; }
}
