/* =========================================================================
   Mills Maths Tools — FLIP CARDS (shared engine styles, 2026-11-18)
   Every flip-card deck loads this file and shared/flipcards.js; the page itself
   only defines window.FLIP_DECK. Same shell as the interactive tools: navy
   topbar, white board card, side panel, menus, icon buttons.
   ========================================================================= */
:root{
  --bg:#f8fafc; --card:#ffffff; --ink:#0f172a; --muted:#64748b; --border:#e2e8f0;
  --shadow:0 18px 45px rgba(15,23,42,.13);
  --blue:#2563eb; --blue-dark:#1d4ed8; --green:#16a34a; --green-dark:#15803d;
  --purple:#7c3aed; --orange:#f97316; --red:#dc2626; --line:#334155;
  --front:#2563eb; --back:#16a34a;
  --uiFont:system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Helvetica,Arial,sans-serif;
  --mathFont:"Cambria Math","STIX Two Math","Latin Modern Math","Times New Roman",Georgia,serif;
}
*{ box-sizing:border-box; }
html,body{ height:100%; }
body{ margin:0; font-family:var(--uiFont); color:var(--ink); overflow-x:hidden;
  background:radial-gradient(circle at top left,rgba(37,99,235,.14),transparent 32rem),radial-gradient(circle at top right,rgba(124,58,237,.12),transparent 34rem),var(--bg); }
button,input,select{ font:inherit; }
[hidden]{ display:none !important; }
.app{ height:100dvh; display:flex; flex-direction:column; min-width:0; }

/* ---------- topbar ---------- */
.mmtTopbar{ position:relative; z-index:40; flex:0 0 auto; background:linear-gradient(135deg,#0f172a,#123b7a 55%,#2563eb); color:white; padding:14px 24px;
  display:grid; grid-template-columns:minmax(200px,1fr) auto minmax(300px,1fr); align-items:center; gap:18px; box-shadow:0 10px 28px rgba(15,23,42,.22); }
.mmtBrand{ display:flex; align-items:center; gap:12px; justify-self:start; text-decoration:none; color:white; border-radius:14px; padding:8px 12px; margin-left:-12px; font-weight:900; transition:.18s ease; }
.mmtBrand:hover{ background:rgba(255,255,255,.12); transform:translateY(-1px); box-shadow:0 0 10px rgba(124,58,237,.6),0 0 18px rgba(37,99,235,.4); }
.mmtBrandLogo{ width:44px; height:44px; border-radius:9px; background:white; color:#1d4ed8; display:grid; place-items:center; font-weight:1000; letter-spacing:-.08em; flex:0 0 auto; }
.mmtBrandText strong{ display:block; font-size:1.18rem; line-height:1; letter-spacing:-.03em; }
.mmtBrandText span{ display:block; font-size:.78rem; opacity:.82; font-weight:650; }
.mmtTopTitle{ font-weight:850; font-size:clamp(1.05rem,1.8vw,1.45rem); letter-spacing:-.04em; text-align:center; white-space:nowrap; }
.topActions{ justify-self:end; display:flex; align-items:center; gap:10px; flex-wrap:wrap; justify-content:flex-end; }
.btn{ appearance:none; border:1px solid rgba(255,255,255,.28); background:rgba(255,255,255,.14); color:white; padding:11px 15px; border-radius:14px; font-weight:900; font-size:15px; cursor:pointer; transition:.18s ease; user-select:none; }
.btn:hover:not(:disabled){ background:rgba(255,255,255,.22); transform:translateY(-1px); }
.btn:focus-visible{ outline:none; box-shadow:0 0 0 4px rgba(255,255,255,.23); }
.btn-primary{ background:white; color:#1d4ed8; border-color:white; }
.btn-primary:hover:not(:disabled){ background:#eef2ff; color:#1d4ed8; }
.menuWrap{ position:relative; display:inline-flex; }
.dropMenu{ position:absolute; top:calc(100% + 8px); right:0; min-width:270px; background:#fff; color:var(--ink); border:1px solid rgba(226,232,240,.95); border-radius:14px;
  box-shadow:0 18px 45px rgba(15,23,42,.22); padding:7px; display:none; z-index:120; text-align:left; }
.dropMenu.open{ display:grid; gap:4px; }
.toolLink{ display:flex; align-items:center; justify-content:space-between; gap:10px; padding:10px 12px; border-radius:10px; color:var(--ink); text-decoration:none; font-weight:900; font-size:.9rem; }
.toolLink::after{ content:'\203A'; color:var(--blue); font-weight:1000; font-size:1.1rem; line-height:1; }
.toolLink:hover,.toolLink:focus-visible{ background:#eef2ff; color:#1d4ed8; outline:none; }
.toolLink small{ display:block; font-weight:650; font-size:.74rem; color:var(--muted); }
.settingsMenu.open{ gap:11px; padding:15px 18px; min-width:340px; max-height:min(78vh,640px); overflow:auto; }
.settingsHead{ font-size:.68rem; letter-spacing:.14em; text-transform:uppercase; font-weight:950; color:var(--muted); }
.settingsNote{ margin:-4px 0 0; font-size:.76rem; font-weight:650; color:var(--muted); line-height:1.4; }
.settingsRule{ height:1px; background:var(--border); margin:1px 0; }
.selRow{ display:flex; align-items:center; justify-content:space-between; gap:12px; }
.selRow > span{ font-weight:900; font-size:.92rem; white-space:nowrap; }
.selRow select{ appearance:none; border:1.5px solid var(--border); padding:8px 30px 8px 11px; border-radius:11px; font-weight:850; font-size:.88rem; color:var(--line); min-width:170px; cursor:pointer;
  background:#fff url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'><path d='M1 1l5 5 5-5' fill='none' stroke='%232563eb' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/></svg>") no-repeat right 10px center; background-size:11px; }
.sw{ display:inline-flex; align-items:center; gap:11px; cursor:pointer; user-select:none; font-weight:850; color:var(--line); font-size:.93rem; }
.sw input{ position:absolute; opacity:0; width:0; height:0; }
.sw .track{ position:relative; width:50px; height:29px; border-radius:999px; background:#cbd5e1; transition:.18s ease; flex:0 0 auto; }
.sw .track::after{ content:""; position:absolute; top:3px; left:3px; width:23px; height:23px; border-radius:50%; background:#fff; box-shadow:0 2px 6px rgba(15,23,42,.3); transition:.18s ease; }
.sw input:checked + .track{ background:#22c55e; }
.sw input:checked + .track::after{ transform:translateX(21px); }
.sw input:focus-visible + .track{ box-shadow:0 0 0 4px rgba(37,99,235,.28); }

/* ---------- layout ---------- */
.layout{ flex:1 1 auto; min-height:0; width:min(1600px,100%); margin:0 auto; padding:14px 18px 16px; display:grid; grid-template-columns:minmax(0,1fr) 340px; gap:14px; min-width:0; }
.app.noPanel .layout{ grid-template-columns:minmax(0,1fr); }
.app.noPanel .panel{ display:none; }
.card{ background:var(--card); border:1px solid var(--border); border-radius:22px; box-shadow:var(--shadow); min-width:0; }
.boardCard{ display:flex; flex-direction:column; min-height:0; padding:12px 14px 12px; position:relative; overflow:hidden; }
.boardTop{ display:flex; align-items:center; justify-content:space-between; gap:10px; flex-wrap:wrap; }
.topLeft,.topRight{ display:flex; align-items:center; gap:8px; flex-wrap:wrap; min-width:0; }
.chip{ font-size:.74rem; letter-spacing:.06em; font-weight:950; text-transform:uppercase; padding:6px 11px; border-radius:999px; white-space:nowrap; color:var(--blue-dark); background:rgba(37,99,235,.1); border:1px solid rgba(37,99,235,.25); }
.chip.grey{ color:var(--muted); background:#f1f5f9; border-color:var(--border); }
.iconGroup{ display:inline-flex; gap:6px; }
.iconBtn{ appearance:none; width:42px; height:42px; border-radius:13px; border:1.5px solid var(--border); background:#fff; color:var(--line); display:grid; place-items:center; cursor:pointer; transition:.16s ease; padding:0; }
.iconBtn svg{ width:21px; height:21px; display:block; }
.iconBtn:hover:not(:disabled){ border-color:var(--blue); background:#eef2ff; color:var(--blue-dark); transform:translateY(-1px); }
.iconBtn:focus-visible{ outline:none; box-shadow:0 0 0 3px rgba(37,99,235,.3); }
.iconBtn[aria-pressed="true"]{ background:#eef2ff; border-color:#c7d2fe; color:var(--blue-dark); }

.prompt{ text-align:center; margin:10px 0 0; font-weight:900; font-size:clamp(1rem,1.5vw,1.25rem); color:var(--ink); letter-spacing:-.01em; min-height:1.4em; }
.prompt small{ display:block; font-weight:700; font-size:.78em; color:var(--muted); margin-top:2px; }
.stage{ flex:1 1 auto; min-height:0; display:grid; place-items:center; padding:12px 0 6px; }

/* ---------- the card ---------- */
.scene{ perspective:1600px; width:var(--cw,640px); height:var(--ch,360px); position:relative; }
.flip{ position:relative; width:100%; height:100%; transform-style:preserve-3d; transition:transform .62s cubic-bezier(.4,.1,.2,1); }
.flip.revealed{ transform:rotateY(180deg); }
.face{ position:absolute; inset:0; border-radius:28px; background:#fff; backface-visibility:hidden; -webkit-backface-visibility:hidden; display:flex; flex-direction:column; align-items:center; justify-content:center;
  padding:5% 6%; overflow:hidden; border:8px solid var(--front); box-shadow:0 22px 50px rgba(15,23,42,.16); }
.face::before{ content:""; position:absolute; inset:10px; border-radius:20px; border:2px solid rgba(37,99,235,.08); pointer-events:none; }
.face.back{ transform:rotateY(180deg); border-color:var(--bc,var(--back)); }
.face.back::before{ border-color:rgba(22,163,74,.10); }
.faceTag{ position:absolute; top:16px; left:22px; font-size:.72rem; letter-spacing:.14em; text-transform:uppercase; font-weight:950; color:#94a3b8; }
.faceInner{ position:relative; z-index:1; width:100%; max-height:100%; display:flex; flex-direction:column; align-items:center; justify-content:center; gap:.35em; text-align:center; font-size:var(--fs,64px); line-height:1.15; }
.faceMain{ font-family:var(--mathFont); font-weight:600; color:var(--front); white-space:nowrap; }
.face.back .faceMain{ color:var(--bc,var(--back)); }
.faceMain.wrap{ white-space:normal; }
.faceMain.ui{ font-family:var(--uiFont); font-weight:850; letter-spacing:-.02em; }
.faceSub{ font-size:.26em; font-weight:800; color:var(--muted); font-family:var(--uiFont); line-height:1.3; max-width:94%; }
.faceSub.math{ font-family:var(--mathFont); font-weight:600; font-size:.4em; color:#334155; white-space:nowrap; }
.facePic{ display:flex; justify-content:center; align-items:center; }
.facePic{ width:100%; }
.facePic:not(.side) svg{ display:block; width:100%; height:auto; }
.facePic img{ display:block; max-width:100%; height:auto; margin:0 auto; }
.facePic.side{ width:auto; }
.faceRow{ display:flex; align-items:center; justify-content:center; gap:.45em; width:100%; }
.faceText{ display:flex; flex-direction:column; align-items:center; gap:.3em; min-width:0; }
.facePic.side svg{ width:calc(var(--ch) * .66); height:calc(var(--ch) * .66); max-width:calc(var(--cw) * .42); max-height:calc(var(--cw) * .42); flex:0 0 auto; }
.face.back .faceInner.pop{ animation:pop .34s ease-out; }
@keyframes pop{ 0%{ transform:scale(.88); opacity:.6; } 70%{ transform:scale(1.04); opacity:1; } 100%{ transform:scale(1); } }
.flip.deal{ animation:deal .32s ease-out; }
@keyframes deal{ from{ transform:translateX(26px); opacity:.2; } to{ transform:none; opacity:1; } }
.flip.dealBack{ animation:dealBack .32s ease-out; }
@keyframes dealBack{ from{ transform:translateX(-26px); opacity:.2; } to{ transform:none; opacity:1; } }
.think{ position:absolute; right:18px; top:14px; width:46px; height:46px; z-index:3; pointer-events:none; }
.think circle{ fill:none; stroke-width:5; }
.think .bg{ stroke:#e2e8f0; } .think .fg{ stroke:var(--blue); stroke-linecap:round; transform:rotate(-90deg); transform-origin:50% 50%; }
.think text{ font:900 15px var(--uiFont); fill:var(--blue-dark); }

/* maths pieces the decks share */
.mv{ font-family:var(--mathFont); font-style:italic; }
.frac{ display:inline-flex; flex-direction:column; align-items:center; vertical-align:middle; font-size:.72em; line-height:1.04; margin:0 .08em; }
.frac > span:first-child{ border-bottom:.07em solid currentColor; padding:0 .12em .05em; }
.frac > span:last-child{ padding:.05em .12em 0; }
.rad{ display:inline-flex; align-items:stretch; vertical-align:middle; }
.rad svg{ width:.5em; height:auto; display:block; flex:0 0 auto; overflow:visible; }
.rad svg path{ fill:none; stroke:currentColor; stroke-width:1.6px; vector-effect:non-scaling-stroke; stroke-linejoin:round; stroke-linecap:round; }
.rad > span{ border-top:.07em solid currentColor; padding:.04em .06em 0 .03em; line-height:1.05; }
.pos{ color:#15803d; } .neg{ color:#dc2626; } .zero{ color:#64748b; }

/* ---------- controls under the card ---------- */
.controls{ display:flex; align-items:center; justify-content:center; gap:12px; flex-wrap:wrap; padding-top:4px; }
.ctlBtn{ appearance:none; border:1.5px solid var(--border); background:#fff; color:var(--ink); border-radius:16px; padding:13px 20px; font-weight:950; font-size:1.02rem; cursor:pointer; transition:.16s ease; display:inline-flex; align-items:center; gap:8px; }
.ctlBtn:hover:not(:disabled){ border-color:var(--blue); background:#eef2ff; color:var(--blue-dark); transform:translateY(-1px); }
.ctlBtn:disabled{ opacity:.4; cursor:not-allowed; }
.ctlBtn.flipBtn{ background:linear-gradient(135deg,#2563eb,#7c3aed); color:#fff; border-color:transparent; padding:14px 34px; font-size:1.15rem; box-shadow:0 12px 28px rgba(37,99,235,.28); min-width:170px; justify-content:center; }
.ctlBtn.flipBtn:hover:not(:disabled){ color:#fff; background:linear-gradient(135deg,#1d4ed8,#6d28d9); }
.ctlBtn.flipBtn.isBack{ background:linear-gradient(135deg,#16a34a,#0d9488); box-shadow:0 12px 28px rgba(22,163,74,.26); }
.hint{ text-align:center; margin-top:8px; font-size:.82rem; font-weight:700; color:var(--muted); }
.kbd{ display:inline-block; min-width:22px; padding:2px 7px; border-radius:7px; background:#fff; border:1px solid var(--border); box-shadow:0 2px 0 rgba(0,0,0,.04); color:var(--ink); font:800 12px/1.3 var(--uiFont); margin:0 1px; }

/* ---------- side panel ---------- */
.panel{ display:flex; flex-direction:column; min-height:0; overflow:auto; padding:16px; gap:14px; }
.pHead{ font-size:.7rem; letter-spacing:.14em; text-transform:uppercase; font-weight:950; color:var(--muted); margin:0; }
.setList{ display:grid; gap:8px; }
.setBtn{ appearance:none; text-align:left; border:1.5px solid var(--border); background:#fff; border-radius:15px; padding:11px 13px; cursor:pointer; transition:.15s ease; display:grid; gap:3px; }
.setBtn:hover{ border-color:#c7d2fe; background:#f8faff; }
.setBtn[aria-pressed="true"]{ border-color:var(--blue); background:#eef2ff; box-shadow:inset 4px 0 0 var(--blue); }
.setBtn .sn{ font-weight:950; font-size:.95rem; color:var(--ink); display:flex; align-items:center; gap:8px; }
.setBtn .sn .num{ width:22px; height:22px; border-radius:7px; background:#e2e8f0; color:#334155; display:grid; place-items:center; font-size:.75rem; font-weight:1000; flex:0 0 auto; }
.setBtn[aria-pressed="true"] .sn .num{ background:var(--blue); color:#fff; }
.setBtn .ss{ font-size:.8rem; font-weight:700; color:var(--muted); line-height:1.35; }
.setBtn .se{ font-family:var(--mathFont); font-size:.98rem; font-weight:600; color:#334155; }
.notes{ font-size:.85rem; font-weight:650; color:#334155; line-height:1.5; }
.notes p{ margin:0 0 8px; } .notes ul{ margin:0; padding-left:18px; } .notes li{ margin:3px 0; }
.tally{ display:flex; gap:8px; flex-wrap:wrap; }
.tally span{ font-size:.78rem; font-weight:900; color:#334155; background:#f1f5f9; border-radius:999px; padding:5px 10px; }

/* ---------- loading (image decks) ---------- */
.loading{ position:fixed; inset:0; z-index:200; display:grid; place-items:center; background:rgba(248,250,252,.92); backdrop-filter:blur(6px); }
.loading .box{ background:#fff; border:1px solid var(--border); border-radius:22px; box-shadow:var(--shadow); padding:22px 26px; width:min(360px,90vw); text-align:center; }
.loading .bar{ height:10px; border-radius:999px; background:#e2e8f0; overflow:hidden; margin-top:12px; }
.loading .bar span{ display:block; height:100%; width:0; background:linear-gradient(90deg,#2563eb,#7c3aed); transition:width .15s ease; }

/* ---------- full screen ---------- */
.app.fs .mmtTopbar{ display:none; }
.app.fs .layout{ grid-template-columns:minmax(0,1fr); width:100%; padding:10px; }
.app.fs .panel{ display:none; }

@media (max-width:1180px){ .mmtBrandText{ display:none; } .mmtTopbar{ grid-template-columns:auto auto minmax(0,1fr); } }
@media (max-width:980px){
  .layout{ grid-template-columns:1fr; height:auto; }
  .app{ height:auto; min-height:100dvh; }
  .panel{ max-height:none; }
  .stage{ flex:0 0 auto; }
}
@media (max-width:640px){
  .mmtTopbar{ grid-template-columns:auto 1fr; padding:10px 12px; gap:10px; }
  .mmtTopTitle{ grid-column:1 / -1; order:3; white-space:normal; font-size:1.05rem; }
  .topActions{ gap:6px; } .btn{ padding:9px 11px; font-size:14px; }
  .layout{ padding:10px; }
  .ctlBtn{ padding:11px 14px; } .ctlBtn.flipBtn{ min-width:120px; padding:12px 22px; }
  .hint{ display:none; }
  .faceRow{ flex-direction:column; gap:.2em; }
  .facePic.side svg{ width:calc(var(--ch) * .4); height:calc(var(--ch) * .4); }
}
@media (prefers-reduced-motion:reduce){ .flip{ transition:none; } .flip.deal,.flip.dealBack,.face.back .faceInner.pop{ animation:none; } }
