/* =====================================================================
   Tactics — the 📖 book behind each table in Target Practice (js/tactics.js).
   Ported from the prototype tools/tactics-patterns.html. Everything for the book is scoped to
   #screen-tactics, and every @keyframes name starts with "tx" so none of them can override one of the
   app's own (a duplicate @keyframes name silently wins everywhere — see CLAUDE.md).
   Colours come from the app's theme tokens, so the book follows light and dark.
   ===================================================================== */
#screen-tactics {
  --d0: #d8452f; --d1: #12938a; --d2: #e07b16; --d3: #12938a; --d4: #3f9a3f;
  --d5: #2f7fd0; --d6: #2f7fd0; --d7: #c0457f; --d8: #9b4fc4; --d9: #c0457f;
  --tens: #2f7fd0; --ones: #d8452f;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) #screen-tactics { --tens: #6fa8ff; --ones: #ff7a66; --d5: #6fa8ff; --d6: #6fa8ff; --d0: #ff7a66; }
}
:root[data-theme="dark"] #screen-tactics { --tens: #6fa8ff; --ones: #ff7a66; --d5: #6fa8ff; --d6: #6fa8ff; --d0: #ff7a66; }

#screen-tactics .tx-book {
  width: min(100%, 480px); margin: 6px auto 4px; background: var(--card); border: 4px solid var(--gold); border-radius: 26px;
  box-shadow: 0 8px 0 var(--gold-dark), 0 16px 28px var(--shadow); padding: 12px 10px 14px;
  display: flex; flex-direction: column; gap: 12px;
}

/* the buddy with a speech bubble at the top of the book */
#screen-tactics .tbuddy { display: flex; align-items: center; gap: 12px; min-height: 76px; }
#screen-tactics .tmascot { width: 72px; height: 72px; flex: none; }
#screen-tactics .tmascot svg { width: 100%; height: 100%; display: block; overflow: visible; }
#screen-tactics .tmascot.idle svg { animation: txFloat 3s ease-in-out infinite; }
#screen-tactics .tmascot.cheer { animation: txBounce .6s ease; }
#screen-tactics .tbubble {
  position: relative; flex: 1; min-width: 0; padding: 10px 14px; border-radius: 18px;
  background: var(--bubble); border: 3px solid var(--line); font-size: clamp(16px, 4.4vw, 19px); font-weight: 600;
  box-shadow: 0 4px 12px var(--shadow); text-wrap: balance;
}
#screen-tactics .tbubble::before {
  content: ''; position: absolute; left: -14px; top: 50%; transform: translateY(-50%);
  border: 10px solid transparent; border-right: 12px solid var(--line); border-left: 0;
}
#screen-tactics .tbubble.pop { animation: txBubble .35s ease; }

/* mode tiles: icon on top, a short word below, one row on a phone; a mode a table lacks isn't shown */
#screen-tactics .modes { display: flex; gap: 6px; justify-content: center; flex-wrap: nowrap; }
#screen-tactics .mode {
  display: inline-flex; flex-direction: column; align-items: center; gap: 2px; flex: 1 1 0; max-width: 92px; min-width: 0;
  padding: 6px 4px 5px; font-family: inherit; font-weight: 600; font-size: 13px; line-height: 1.1; border-radius: 12px;
  cursor: pointer; border: 2px solid var(--line); background: var(--card2); color: var(--ink); box-shadow: 0 3px 0 var(--line);
}
#screen-tactics .mode.on { background: var(--gold-hi); color: #3a2614; border-color: var(--gold-dark); box-shadow: 0 3px 0 var(--gold-dark); }
#screen-tactics .mode[hidden] { display: none; }
#screen-tactics .mode .mi { display: inline-flex; font-size: 22px; line-height: 1; color: var(--gold-dark); }
#screen-tactics .mode.on .mi { color: #9a6d0e; }

/* the column of fact cards, and the space beside it */
#screen-tactics .split { position: relative; display: flex; gap: 8px; }
#screen-tactics .col { display: flex; flex-direction: column; align-items: flex-start; gap: 5px; flex: none; }
#screen-tactics .fact {
  display: grid; grid-template-columns: 1.2em .8em 1.2em .8em auto; align-items: center; justify-items: center;
  font-weight: 700; font-size: clamp(15px, 5.4vw, 22px); padding: 3px 6px 3px 2px; border-radius: 11px;
  background: var(--card2); border: 2px solid var(--line); box-shadow: 0 2px 0 var(--line);
  transition: background .3s, border-color .3s, box-shadow .3s;
}
#screen-tactics .fact .s { color: var(--muted); }
#screen-tactics .fact .ans { justify-self: end; }
#screen-tactics .area { flex: 1; min-width: 0; position: relative; }
#screen-tactics .ans, #screen-tactics .gt {
  display: inline-flex; min-width: 2.1em; justify-content: flex-end; padding: 0 .22em; border-radius: 8px;
  font-weight: 700; line-height: 1.35; background: var(--gold-soft); border: 2px solid var(--gold);
}
#screen-tactics .gt { position: absolute; left: 0; top: 0; z-index: 5; font-size: clamp(15px, 5.4vw, 22px); color: var(--gold-dark); }
#screen-tactics .dg { display: inline-block; border-radius: 6px; transition: color .35s, background .35s; }
#screen-tactics .dg.hl { color: var(--c); background: color-mix(in srgb, var(--c) 22%, transparent); animation: txPop .45s ease; }
#screen-tactics .dg.lead { color: var(--muted); animation: txPop .45s ease; }
#screen-tactics .col.grid2 { display: grid; grid-auto-flow: column; grid-template-rows: repeat(5, auto); column-gap: 8px; row-gap: 5px; align-content: start; }
#screen-tactics .fact.slim { grid-template-columns: 0 0 0 0 auto; padding: 3px; }
#screen-tactics .fact.slim > span:not(.ans) { opacity: 0; overflow: hidden; }
#screen-tactics .tapping .fact { cursor: pointer; }
#screen-tactics .fact.cur { background: var(--gold-soft); border-color: var(--gold); box-shadow: 0 2px 0 var(--gold); }
#screen-tactics .fact.flipped { background: var(--card); border-style: dashed; box-shadow: none; }
#screen-tactics .tapping:not(.landing) .fact.flipped { cursor: default; }
#screen-tactics .fact.flipped .ans { background: transparent; border-color: var(--line); color: var(--muted); justify-content: center; }

/* patterns: the tens arrow and the ▶ step button */
#screen-tactics .arrow { position: absolute; height: 40px; z-index: 6; pointer-events: none; opacity: 0; transition: opacity .5s; }
#screen-tactics .arrow.in { opacity: 1; }
#screen-tactics .arrow svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
#screen-tactics .arrow path { fill: none; stroke: var(--tens); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
#screen-tactics .arrow .plus {
  position: absolute; left: 50%; top: -6px; transform: translateX(-50%); font-weight: 700; font-size: 17px;
  color: var(--tens); background: var(--card); padding: 0 5px; border-radius: 8px; line-height: 1.1;
}
#screen-tactics .step {
  align-self: center; width: 60px; height: 60px; border-radius: 50%; border: 3px solid var(--gold-dark);
  background: linear-gradient(180deg, var(--gold-hi), var(--gold)); color: #4a3200; font-size: 24px; cursor: pointer;
  box-shadow: 0 5px 0 var(--gold-dark); animation: txBreathe 1.6s ease-in-out infinite;
}
#screen-tactics .step[hidden] { display: none; }
#screen-tactics .replay {
  align-self: center; width: 48px; height: 48px; border-radius: 50%; border: 3px solid var(--line); background: var(--card);
  box-shadow: 0 4px 0 var(--line); font-size: 20px; cursor: pointer; color: var(--ink); opacity: .75;
}

/* tricks / constructions: the working copy of a fact slides out beside its row */
#screen-tactics .stage { position: absolute; inset: 0; }
#screen-tactics .eq {
  position: absolute; left: 6px; display: flex; align-items: center; gap: .22em; z-index: 10;
  font-weight: 700; white-space: nowrap; padding: 3px 8px; border-radius: 11px;
  background: var(--card2); border: 2px solid var(--line); box-shadow: 0 2px 0 var(--line);
}
#screen-tactics .tk { display: inline-block; flex: none; }
#screen-tactics .tk.op { color: var(--muted); }
#screen-tactics .tk.q {
  min-width: 2.1em; text-align: center; padding: 0 .22em; border-radius: 8px; line-height: 1.35;
  background: var(--card); border: 2px solid var(--line); color: var(--muted); transition: background .3s, border-color .3s, color .3s;
}
#screen-tactics .tk.q.ansq { background: var(--gold-soft); border-color: var(--gold); color: var(--ink); }
#screen-tactics .tk.q.filled { color: var(--good); background: var(--good-soft); border-color: var(--good); }
#screen-tactics .tk.grp { color: var(--gold-dark); }
#screen-tactics .tile {
  position: absolute; z-index: 20; pointer-events: none; display: flex; align-items: center; justify-content: center;
  font-weight: 700; color: var(--gold-dark); border-radius: 10px; background: var(--gold-soft); border: 2px solid var(--gold);
}
#screen-tactics .tile.bare { background: none; border-color: transparent; color: var(--ink); }
#screen-tactics .minus {
  position: absolute; z-index: 21; font-weight: 700; color: var(--ones); pointer-events: none;
  opacity: 0; transition: opacity .25s, transform .25s;
}
#screen-tactics .minus.in { opacity: 1; transform: translateY(-3px); }
#screen-tactics .tk.pop, #screen-tactics .tile.pop { animation: txPop2 .4s ease; }
#screen-tactics .tk.shrink { animation: txShrink .45s ease; }
#screen-tactics .tx-spark { position: absolute; pointer-events: none; font-size: 20px; z-index: 25; animation: txSpark 700ms ease-out forwards; }

/* Grid mode: where this table's answers live in the 10 × 10 times grid */
#screen-tactics .gridwrap { position: absolute; left: 0; top: 0; z-index: 4; opacity: 0; transition: opacity .6s; pointer-events: none; }
#screen-tactics .gridwrap.in { opacity: 1; }
#screen-tactics .ghead {
  position: absolute; transform: translate(-50%, -50%); font-weight: 700; color: var(--muted); line-height: 1.2;
  padding: 0 .25em; border-radius: 6px; transition: color .4s, background .4s, box-shadow .4s;
}
#screen-tactics .ghead.t { color: var(--gold-dark); background: var(--gold-soft); box-shadow: 0 0 0 2px var(--gold); animation: txGpop .45s ease; }
#screen-tactics .glines { position: absolute; left: 0; top: 0; overflow: visible; }
#screen-tactics .glines line { stroke: var(--line); stroke-width: 1; opacity: .7; }
#screen-tactics .gband { position: absolute; background: var(--gold-soft); border-radius: 8px; opacity: 0; transition: opacity .6s; }
#screen-tactics .gband.in { opacity: 1; }
#screen-tactics .gdiag { position: absolute; left: 0; top: 0; opacity: 0; transition: opacity .8s; overflow: visible; }
#screen-tactics .gdiag.in { opacity: 1; }
#screen-tactics .gdiag line { stroke: var(--line); stroke-width: 2; stroke-linecap: round; }
#screen-tactics .gnum {
  position: absolute; z-index: 6; font-weight: 700; color: var(--gold-dark); transform: translate(-50%, -50%);
  white-space: nowrap; line-height: 1.15; padding: 1px 3px; border-radius: 6px; transition: background .3s, color .3s;
}
#screen-tactics .gnum.lit { background: var(--gold); color: #fff; }
#screen-tactics .gnum.gpop { animation: txGpop .45s ease; }
#screen-tactics .gridready .gnum { cursor: pointer; }

@keyframes txFloat { 50% { transform: translateY(-5px); } }
@keyframes txBounce { 30% { transform: translateY(-14px) scale(1.05); } 60% { transform: translateY(0) scale(.97); } }
@keyframes txBubble { from { transform: scale(.85); opacity: .4; } to { transform: none; opacity: 1; } }
@keyframes txPop { 0% { transform: scale(1); } 45% { transform: scale(1.4); } 100% { transform: scale(1); } }
@keyframes txPop2 { 0% { transform: scale(1); } 45% { transform: scale(1.3) rotate(-3deg); } 100% { transform: scale(1); } }
@keyframes txShrink { 0% { transform: scale(1); } 40% { transform: scale(.7); } 100% { transform: scale(1); } }
@keyframes txSpark { to { transform: translate(var(--dx), var(--dy)) scale(0); opacity: 0; } }
@keyframes txGpop { 0% { transform: translate(-50%, -50%) scale(1); } 45% { transform: translate(-50%, -50%) scale(1.5); } 100% { transform: translate(-50%, -50%) scale(1); } }
@keyframes txBreathe { 50% { transform: scale(1.08); } }

/* ---------- Target Practice: the 📖 hanging from each reached table's shield ---------- */
.table-grid.with-books { row-gap: 30px; padding-bottom: 12px; }
.table-btn .tbook {
  position: absolute; left: 50%; bottom: -19px; transform: translateX(-50%); width: 38px; height: 38px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; font-size: 20px; cursor: pointer; z-index: 2;
  background: radial-gradient(circle at 35% 30%, var(--card), var(--card2)); border: 3px solid var(--gold);
  box-shadow: 0 3px 0 var(--gold-dark); animation: txBookGlow 2.6s ease-in-out infinite;
}
.table-btn .tbook:active { transform: translateX(-50%) translateY(2px); box-shadow: 0 1px 0 var(--gold-dark); }
@keyframes txBookGlow { 50% { box-shadow: 0 3px 0 var(--gold-dark), 0 0 12px 3px color-mix(in srgb, var(--gold-hi) 85%, transparent); } }

/* ---------- Target Practice: "All your answers" (the progress map) ---------- */
.tx-map {
  position: relative; display: flex; align-items: center; gap: 14px; width: 100%; max-width: 480px; margin: 18px auto 6px;
  padding: 12px; border-radius: 18px; cursor: pointer; text-align: left; font: inherit; color: var(--ink);
  background: var(--card); border: 3px solid var(--gold); box-shadow: 0 5px 0 var(--gold-dark);
}
.tx-map:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--gold-dark); }
.tx-mini { flex: none; display: grid; grid-template-columns: repeat(10, 1fr); gap: 1.5px; width: 96px; height: 96px; }
.tx-mini i { border-radius: 2px; background: color-mix(in srgb, var(--line) 55%, transparent); }
.tx-mini i.f { background: var(--gold); }
.tx-maptxt { font-weight: 600; font-size: 18px; }
.tx-mapcount { display: block; font-size: 14px; color: var(--muted); margin-top: 2px; }
.tx-mapnew { position: absolute; top: -12px; right: -8px; font-size: 26px; animation: txBreathe 1.4s ease-in-out infinite; }
.tx-overlay {
  position: fixed; inset: 0; z-index: 80; display: flex; align-items: center; justify-content: center;
  padding: 16px max(16px, env(safe-area-inset-right, 0px)) 16px max(16px, env(safe-area-inset-left, 0px));
  background: rgba(30, 18, 8, .5);
}
.tx-sheet {
  position: relative; width: min(100%, 520px); background: var(--card); border: 4px solid var(--gold); border-radius: 24px;
  box-shadow: 0 8px 0 var(--gold-dark); padding: 14px 12px 12px;
}
.tx-close {
  position: absolute; top: -14px; right: -10px; width: 42px; height: 42px; border-radius: 50%; font-size: 18px; cursor: pointer;
  border: 3px solid var(--line); background: var(--card); box-shadow: 0 3px 0 var(--line); color: var(--ink);
}
.tx-bigmap { position: relative; width: 100%; }
.tx-bigmap svg { position: absolute; left: 0; top: 0; overflow: visible; }
.tx-bigmap line { stroke: var(--line); stroke-width: 1; opacity: .7; }
.tx-mh, .tx-mc { position: absolute; transform: translate(-50%, -50%); font-weight: 700; line-height: 1.15; white-space: nowrap; }
.tx-mh { color: var(--muted); }
.tx-mc { color: var(--gold-dark); padding: 1px 3px; border-radius: 6px; transition: background .4s, color .4s; }
.tx-mbg { position: absolute; background: var(--gold-soft); border-radius: 4px; transition: opacity .3s; }
.tx-mc.wait, .tx-mbg.wait { opacity: 0; }
.tx-mc.new { background: var(--gold); color: #fff; animation: txMapPop .45s ease; }
@keyframes txMapPop { 0% { transform: translate(-50%, -50%) scale(.2); } 60% { transform: translate(-50%, -50%) scale(1.35); } 100% { transform: translate(-50%, -50%) scale(1); } }
