/* =========================================================
   Elimu Live — game-specific components
   Loaded only on game pages (after style.css)
   ========================================================= */

.tag { font-size: .72rem; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
.label { font-size: .74rem; text-transform: uppercase; letter-spacing: .1em; color: var(--text-faint); font-weight: 800; }

.tips { margin: .6rem 0 0; padding-left: 1.1rem; color: var(--text-dim); font-size: .88rem; }
.tips li { margin-bottom: .45rem; }
.tips li::marker { color: var(--accent, var(--brand)); }

/* ================= CHEMISTRY ================= */
.equation {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: center;
  gap: .35rem .55rem;
  padding: 1.4rem .8rem; margin: .4rem 0 1.2rem;
  border-radius: var(--r);
  background: radial-gradient(700px 200px at 50% 0%, rgba(239,68,68,.12), transparent 70%), rgba(255,255,255,.03);
  border: 1px dashed var(--border);
  min-height: 130px;
}

.term { display: flex; align-items: center; gap: .35rem; }

.term-label {
  font-family: var(--mono); font-size: clamp(1.05rem, 3.2vw, 1.45rem); font-weight: 700;
  padding: 0 .15rem; letter-spacing: .01em;
}

.plus, .arrow {
  font-size: clamp(1.1rem, 3.2vw, 1.4rem); font-weight: 800; color: var(--text-faint); padding: 0 .15rem;
}
.arrow { color: var(--chemistry); margin: 0 .35rem; }

.stepper {
  display: inline-flex; align-items: center; gap: 2px;
  background: rgba(255,255,255,.07); border: 1px solid var(--border);
  border-radius: 999px; padding: 2px;
}
.stepper .step {
  width: 30px; height: 30px; border-radius: 50%; border: none; cursor: pointer;
  background: transparent; color: var(--text); font-weight: 800; font-size: 1rem;
  display: grid; place-items: center; transition: .15s; line-height: 1;
}
.stepper .step:hover { background: var(--chemistry); color: #fff; }
.stepper .coef {
  width: 42px; height: 30px; text-align: center; border: none; background: transparent;
  font-weight: 800; font-size: 1.05rem; outline: none; font-variant-numeric: tabular-nums;
}
.stepper .coef:focus { background: rgba(255,255,255,.10); border-radius: 8px; }

.balance-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
@media (max-width: 720px) { .balance-grid { grid-template-columns: 1fr; } }

.atom-table { margin-top: .5rem; display: grid; gap: .35rem; }
.atom-row {
  display: grid; grid-template-columns: 1fr 46px 26px 46px 24px;
  align-items: center; gap: .2rem;
  padding: .45rem .65rem; border-radius: 10px; font-family: var(--mono); font-size: .92rem;
  background: rgba(255,255,255,.04); border: 1px solid var(--border);
  transition: .2s;
}
.atom-row .sym { font-weight: 800; font-family: var(--font); }
.atom-row .num { text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; }
.atom-row .eq { text-align: center; color: var(--text-faint); }
.atom-row .tick { text-align: center; font-weight: 800; }
.atom-row.ok { border-color: rgba(34,197,94,.5); background: rgba(34,197,94,.10); }
.atom-row.ok .tick { color: var(--ok); }
.atom-row.bad { border-color: rgba(239,68,68,.5); background: rgba(239,68,68,.10); }
.atom-row.bad .tick { color: var(--bad); }

.target { font-weight: 800; font-size: .82rem; padding: .35rem .75rem; border-radius: 999px; white-space: nowrap; }
.target.good { background: rgba(34,197,94,.16); color: #86efac; border: 1px solid rgba(34,197,94,.45); }
.target.wait { background: rgba(255,255,255,.06); color: var(--text-dim); border: 1px solid var(--border); }

.feedback { margin-top: .5rem; min-height: 56px; padding: .7rem .9rem; border-radius: var(--r-sm); font-size: .92rem; background: rgba(255,255,255,.04); border: 1px solid var(--border); }
.feedback.good { border-color: rgba(34,197,94,.5); background: rgba(34,197,94,.10); }
.feedback.bad { border-color: rgba(239,68,68,.5); background: rgba(239,68,68,.10); }

/* ================= PHYSICS ================= */
.range-row { display: grid; gap: .3rem; margin-bottom: .85rem; }
.range-row .top { display: flex; justify-content: space-between; align-items: baseline; }
.range-row .val { font-weight: 800; font-variant-numeric: tabular-nums; color: var(--physics); }

input[type="range"] {
  -webkit-appearance: none; appearance: none; width: 100%; height: 26px; background: transparent; cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 7px; border-radius: 999px; background: linear-gradient(90deg, var(--physics), rgba(255,255,255,.12));
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none; width: 21px; height: 21px; margin-top: -7px;
  border-radius: 50%; background: #fff; border: 3px solid var(--physics); box-shadow: 0 3px 10px rgba(0,0,0,.4);
}
input[type="range"]::-moz-range-track { height: 7px; border-radius: 999px; background: rgba(255,255,255,.15); }
input[type="range"]::-moz-range-thumb { width: 18px; height: 18px; border-radius: 50%; background: #fff; border: 3px solid var(--physics); }

.canvas-wrap {
  position: relative; border-radius: var(--r); overflow: hidden;
  border: 1px solid var(--border);
  background: linear-gradient(180deg, #0a1226, #050914 70%);
}
#stage { width: 100%; height: auto; display: block; touch-action: none; }

.mission { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.chip {
  display: inline-flex; align-items: center; gap: .4rem; font-weight: 700; font-size: .84rem;
  padding: .35rem .7rem; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border);
}
.chip.target-chip { border-color: rgba(245,158,11,.5); color: #fcd34d; background: rgba(245,158,11,.12); }

.readout { display: grid; grid-template-columns: repeat(3, 1fr); gap: .6rem; }
.readout div { padding: .55rem .7rem; border-radius: var(--r-sm); background: rgba(255,255,255,.04); border: 1px solid var(--border); }
.readout b { display: block; font-variant-numeric: tabular-nums; font-size: 1.05rem; }
.readout small { color: var(--text-faint); font-size: .74rem; text-transform: uppercase; letter-spacing: .08em; }

/* ================= CS / LOGIC GATES ================= */
.circuit-diagram { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: .5rem; padding: .5rem 0 .2rem; }

.truth-table { width: 100%; border-collapse: collapse; font-family: var(--mono); font-size: .88rem; }
.truth-table th, .truth-table td { padding: .5rem .6rem; text-align: center; border-bottom: 1px solid var(--border); }
.truth-table th { color: var(--text-faint); font-family: var(--font); font-size: .74rem; text-transform: uppercase; letter-spacing: .08em; }
.truth-table tr.row-active { background: rgba(59,130,246,.16); }
.truth-table tr.row-active td { font-weight: 800; }

.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .7rem .9rem; border-radius: var(--r-sm); background: rgba(255,255,255,.04); border: 1px solid var(--border); margin-bottom: .6rem; }
.switch-btn {
  width: 66px; height: 34px; border-radius: 999px; border: 1px solid var(--border-strong);
  background: rgba(255,255,255,.08); position: relative; cursor: pointer; transition: .22s; flex: none;
}
.switch-btn::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%;
  background: var(--text-dim); transition: .22s;
}
.switch-btn.on { background: linear-gradient(135deg, var(--cs), #6366f1); border-color: transparent; }
.switch-btn.on::after { left: 35px; background: #fff; box-shadow: 0 0 12px rgba(255,255,255,.7); }

.bit-display { font-family: var(--mono); font-size: 1.5rem; font-weight: 800; letter-spacing: .12em; }
.bit-display .zero { color: var(--text-faint); }
.bit-display .one { color: var(--cs); text-shadow: 0 0 14px rgba(59,130,246,.7); }

.decimal-hint { font-size: .86rem; color: var(--text-dim); }
.decimal-hint b { color: #60a5fa; }

/* ================= SHARED RESULT SCREEN ================= */
.result-stats { display: flex; gap: .8rem; flex-wrap: wrap; justify-content: center; margin: 1rem 0; }
.result-stats .item { padding: .6rem 1rem; border-radius: var(--r-sm); background: rgba(255,255,255,.05); border: 1px solid var(--border); min-width: 92px; }
.result-stats .item b { display: block; font-size: 1.3rem; font-variant-numeric: tabular-nums; }
.result-stats .item small { color: var(--text-faint); font-size: .74rem; text-transform: uppercase; letter-spacing: .08em; }

/* Compact HUD on small screens */
@media (max-width: 980px) {
  .hud { grid-template-columns: 1fr; }
  .readout { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 420px) {
  .stepper .step { width: 26px; height: 26px; font-size: .9rem; }
  .stepper .coef { width: 34px; font-size: .95rem; }
  .readout { grid-template-columns: 1fr 1fr; }
}
/* Circuit cards: readable, wrapping signal flow on narrow screens */
.logic-layout { display:grid; grid-template-columns:minmax(180px,240px) minmax(0,1fr); gap:1.2rem; }
.logic-layout > * { min-width:0; }
.circuit-flow { display:flex; align-items:center; justify-content:center; flex-wrap:wrap; gap:.35rem; width:100%; }
.logic-node { display:inline-flex; align-items:center; gap:.4rem; padding:.55rem .7rem; border:1px solid var(--border-strong); border-radius:10px; font:700 .85rem var(--mono); background:rgba(59,130,246,.08); }
.logic-node b { color:var(--text-faint); }
.logic-node b.lit { color:#60a5fa; text-shadow:0 0 12px rgba(59,130,246,.6); }
.logic-node.gate { border-color:rgba(59,130,246,.45); }
.logic-node.output-node { border-color:var(--cs); }
.logic-wire { color:var(--cs); font-weight:800; }
.logic-output { text-align:center; padding:.7rem; border:1px solid var(--border); border-radius:var(--r-sm); }
@media (max-width:680px) { .logic-layout { grid-template-columns:1fr; } }

/* Keep physics launch controls immediately before its canvas on mobile. */
@media (max-width: 980px) {
  body:has(#stage) .game-shell .board-wrap { order: 0; }
  body:has(#stage) .hud .card:nth-child(3) { order: -1; }
}

/* Play area: controls stay directly below the projectile field at every width. */
.projectile-shell .board-wrap { min-width: 0; }
.projectile-shell .board { min-width: 0; }
.projectile-shell #stage { width: 100%; height: 400px; }
.launch-panel {
  display: grid; grid-template-columns: minmax(0,1fr) minmax(0,1fr) auto;
  align-items: end; gap: 1rem; padding: 1rem; margin-top: .75rem;
  background: rgba(245,158,11,.08); border: 1px solid rgba(245,158,11,.25);
  border-radius: var(--r);
}
.launch-control { min-width: 0; }
.launch-control .top { display: flex; justify-content: space-between; gap: .4rem; font-weight: 700; }
.launch-control .val { color: #fcd34d; white-space: nowrap; font-variant-numeric: tabular-nums; }
.launch-control input { margin: .4rem 0 0; height: 38px; }
.launch-panel #fire { min-height: 48px; padding-inline: 1.6rem; }
@media (max-width: 980px) {
  .projectile-shell .board-wrap { order: -1; }
  .projectile-shell .hud .card:nth-child(3) { order: 1; }
  .projectile-shell .readout { grid-template-columns: repeat(3,minmax(0,1fr)); }
  .projectile-shell .readout div { min-width: 0; padding: .55rem .45rem; }
  .projectile-shell .readout small { display: block; font-size: .66rem; line-height: 1.3; min-height: 2.5em; }
  .projectile-shell #stage { height: clamp(245px, 56vw, 360px); }
}
@media (max-width: 640px) {
  .game-shell .board { padding: .85rem;n  .game-shell .card { padding: 1rem; }
  .game-shell .overlay { padding: 1rem; }
  .game-shell .overlay .btn { min-height: 48px; }
  .projectile-shell .board-head { gap: .35rem; margin-bottom: .65rem; }
  .projectile-shell .board-head .chip { font-size: .75rem; }
  .launch-panel { grid-template-columns: repeat(2,minmax(0,1fr)); gap: .5rem .8rem; padding: .7rem; }
  .launch-panel #fire { grid-column: 1/-1; width: 100%; }
  .projectile-shell .readout { gap: .35rem; }
  .projectile-shell .readout b { font-size: .95rem; }
  .equation { padding: .8rem .35rem; gap: .4rem; }
  .equation .term { display: flex; flex-direction: column; position: relative; padding: .3rem .15rem 1.1rem; }
  .equation .term-label { order: -1; }
  .equation .term .plus { position: absolute; right: -.65rem; top: .55rem; }
  .equation .arrow { margin: 0; }
  .stepper .step { min-width: 34px; min-height: 34px; }
  .stepper .coef { height: 34px; }
  .game-shell .board .row .btn { min-height: 46px; }
  .circuit-flow { gap: .3rem; }
  .logic-node { padding: .45rem .5rem; font-size: .8rem; }
  .switch-btn { min-height: 44px; }
  .switch-btn::after { top: 8px; }
  .switch-btn.on::after { left: 35px; }
}

/* Mobile game HUD: compact live stats above the playfield. Override the old
   page-specific ordering rule without hiding anything off-screen. */
@media (max-width: 980px) {
  .game-shell .board-wrap { order: -1 !important; }
  .game-shell .hud .card:nth-child(3) { order: 1 !important; }
  .game-shell .hud .card:nth-child(2) { order: -2; }
}
@media (max-width: 640px) {
  .game-shell .hud .card:nth-child(2) { padding: .7rem .9rem; }
  .projectile-shell .hud .card:nth-child(2) {
    display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: .3rem;
  }
  .projectile-shell .hud .card:nth-child(2) .hud-row {
    display: grid; gap: 0; margin: 0; text-align: center;
  }
  .projectile-shell .hud .card:nth-child(2) .hud-row:nth-child(n+4) { display: none; }
  .projectile-shell .board-wrap { order: -1 !important; }
}

@media (max-width: 640px) {
  .game-shell:not(.projectile-shell) .hud .card:nth-child(2) {
    display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: .4rem;
  }
  .game-shell:not(.projectile-shell) .hud .card:nth-child(2) .hud-row {
    display: grid; gap: 0; margin: 0; text-align: center;
  }
  .game-shell:not(.projectile-shell) .hud .card:nth-child(2) > .hud-row:nth-child(4) { display: none; }
  .game-shell:not(.projectile-shell) .hud .card:nth-child(2) > .mt-2 { grid-column: 1/-1; margin-top: .15rem; }
  .game-shell:not(.projectile-shell) .hud .card:nth-child(2) > .mt-2 .hud-row { display: flex; }
  .game-shell .hud .card:nth-child(2) .label { font-size: .67rem; }
}

.equation-side { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: .4rem .8rem; min-width: 0; }
@media (max-width: 640px) {
  .equation { flex-direction: column; padding: .7rem .35rem; gap: .15rem; }
  .equation-side { width: 100%; }
  .equation .term { padding: .1rem .15rem .6rem; }
  .equation .arrow { line-height: 1; transform: rotate(90deg); padding: .2rem; }
  .balance-grid { gap: .55rem; }
  .balance-grid .feedback { min-height: 0; margin-top: .3rem; }
  .game-shell .board .row.mt-3 { margin-top: .65rem; }
  .game-shell .board .row.mt-2 { margin-top: .6rem; }
  .logic-layout { gap: .5rem; }
  .logic-layout .mt-2 { margin-top: .4rem; }
  .switch-row { padding: .35rem .65rem; margin-bottom: .35rem; }
  .circuit-diagram { padding: .2rem 0; }
}

.chemistry-actions { margin: .7rem 0 1rem; }
.logic-actions { margin: .35rem 0 .65rem; }
@media (max-width: 640px) {
  .chemistry-actions, .logic-actions { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: .45rem; }
  .chemistry-actions .btn:first-child { grid-column: 1/-1; }
  .chemistry-actions .btn, .logic-actions .btn { min-width: 0; padding: .7rem .4rem; }
  .game-shell:not(.projectile-shell) .hud .card:nth-child(2) > .hud-row:nth-child(5) { display: none; }
  .game-shell:not(.projectile-shell) .hud .card:nth-child(2) > .hud-row:nth-child(4) { display: grid; }
  .game-shell:not(.projectile-shell) .hud .card:nth-child(2) > .mt-2 { grid-column: 1/-1; }
}

@media (max-width: 640px) {
  .chemistry-shell .hud .card:nth-child(2),
  .logic-shell .hud .card:nth-child(2) { grid-template-columns: repeat(3,minmax(0,1fr)); }
  .chemistry-shell .hud .card:nth-child(2) > .hud-row:nth-child(4),
  .logic-shell .hud .card:nth-child(2) > .hud-row:nth-child(n+4) { display: none; }
  .chemistry-shell .hud .card:nth-child(2) > .hud-row:nth-child(5) { display: none; }
  .chemistry-shell .hud .card:nth-child(2) > .mt-2 { grid-column: 1/-1; }
  .chemistry-shell .board-head { gap: .35rem; margin-bottom: .45rem; }
  .chemistry-shell .board-head h3 { font-size: .9rem; }
  .chemistry-shell .board-head .target { font-size: .73rem; padding: .25rem .5rem; }
  .chemistry-shell .equation { margin: .25rem 0 .45rem; }
}

/* Keep the reaction compact and the live HUD to one row on narrow phones. */
@media (max-width: 640px) {
  .chemistry-shell .equation {
    flex-wrap: nowrap;
    justify-content: center;
    min-height: 0;
    gap: 0;
  }
  .chemistry-shell .equation-side { flex: none; gap: .3rem .6rem; }
  .chemistry-shell .equation .term { padding: 0 .15rem .25rem; }
  .chemistry-shell .equation .arrow { padding: 0; line-height: 1; }
  .game-shell.logic-shell .hud .card:nth-child(2) > .hud-row:nth-child(n+4) { display: none; }
}

@media (max-width: 640px) {
  .chemistry-shell .stepper .step { width: 44px; height: 44px; min-width: 44px; min-height: 44px; }
  .chemistry-shell .stepper .coef { width: 32px; height: 44px; }
}

}
/* Explicit mobile touch sizing for launch sliders. */
@media (max-width: 640px) {
  .launch-control input[type="range"] { height: 44px; }
}

@media (max-width: 640px) {
  .chemistry-shell .chemistry-actions {
    position: sticky;
    bottom: .5rem;
    z-index: 3;
    padding: .55rem;
    margin: .4rem -.3rem .6rem;
    border: 1px solid var(--border-strong);
    border-radius: var(--r);
    background: #161b31;
    box-shadow: 0 8px 28px rgba(0,0,0,.5);
  }
}
