/* Factors, primes & short-division ladder (すだれ算 / 거꾸로 나눗셈 / 短除法).
   Look B Sticker Book by default; clean flat rules under html.calm (Years 5+). All layout sizes in rem. */

.fp-stage { display: grid; justify-items: center; gap: .75rem; width: 100%; max-width: 40rem; min-width: 0; }
.fp-prompt { margin: 0; font: 700 clamp(1.125rem, 4.2vw, 1.375rem)/1.4 var(--f-b), var(--cjk); text-align: center; }
.fp-msg { margin: 0; min-height: 2.5rem; font-size: 1rem; color: var(--ink2); text-align: center; max-width: 34rem; }
.fp-hide-timer .timer { display: none; }

/* ---------- pre-start demo & parent method-guide ---------- */
.fp-demo { display: grid; gap: .625rem; justify-items: start; padding: .875rem 1rem; border: 2px dashed var(--edge); border-radius: 1rem; background: #fff; }
.fp-demo-h { margin: 0; font-weight: 600; color: var(--ink); }
.fp-demo-body { display: grid; gap: .625rem; justify-items: start; width: 100%; }
.fp-demo-vis { width: 100%; max-width: 22rem; }
.fp-demo-chips { display: flex; flex-wrap: wrap; gap: .5rem; }
.fp-demo .fp-prime, .fp-demo .fp-dim { min-width: 3.5rem; min-height: 3.5rem; justify-content: center; font: 700 1.125rem/1 var(--f-m); }

.method-guide { border: 2px solid var(--edge); border-radius: 1rem; background: #fff; padding: .5rem .875rem; }
.method-guide > summary { cursor: pointer; font: 700 .9375rem/1.4 var(--f-d), var(--cjk); min-height: 2.75rem; display: flex; align-items: center; }
.fp-guide-body { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: .875rem 1.125rem; align-items: center; padding: .625rem 0 .25rem; }
.fp-guide-copy p { margin: 0 0 .5rem; font-size: .9375rem; }
.fp-guide-svg { display: block; width: 100%; max-width: 24rem; height: auto; }
.fp-g-bg { fill: #F9FBFF; stroke: var(--edge); stroke-width: 2; }
.fp-g-lcm { fill: #FFF4CC; stroke: var(--sun); stroke-width: 2.5; }
.fp-g-gcf { fill: #D9F4EA; stroke: var(--mint); stroke-width: 2.5; stroke-dasharray: 5 3; }
.fp-g-lines path { fill: none; stroke: var(--ink); stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.fp-g-num { fill: var(--ink); font: 700 17px/1 var(--f-m); }
.fp-g-tag.gcf { fill: #E3F5EE; stroke: var(--mint); stroke-width: 2; }
.fp-g-tag.lcm { fill: #FFF6D6; stroke: var(--sun); stroke-width: 2; }
.fp-g-t1 { fill: var(--ink); font: 700 12.5px/1 var(--f-b), var(--cjk); }
.fp-g-t2 { fill: var(--ink); font: 700 12px/1 var(--f-m); }

/* ---------- Mode 1: Short-division ladder ---------- */
.fp-ladder-wrap { width: 100%; display: grid; justify-items: center; }
.fp-ladder { display: grid; grid-template-columns: 3.5rem minmax(4rem, 5.75rem) minmax(4rem, 5.75rem); align-items: stretch; padding: .875rem 1rem; border: .1875rem solid var(--ink); border-radius: 1.25rem; background: #fff; box-shadow: .25rem .25rem 0 var(--sky); }
.fp-div, .fp-cell { display: grid; place-items: center; min-height: 2.875rem; font: 700 clamp(1.375rem, 5vw, 1.875rem)/1 var(--f-m); position: relative; }
.fp-div { color: var(--ink); padding-right: .375rem; }
.fp-div.fp-qslot { color: var(--ink2); }
.fp-div.fp-qslot::after { content: ""; position: absolute; inset: .375rem .625rem .375rem .25rem; border: 2px dashed var(--sky); border-radius: .625rem; pointer-events: none; }
.fp-cell { padding: .25rem .5rem; }
.fp-cell.fp-l { border-left: .1875rem solid var(--ink); }
.fp-cell.fp-b { border-bottom: .1875rem solid var(--ink); }
.fp-cell.fp-cur { color: var(--ink); background: #FFFDF5; }

/* GCF mint column glow & LCM sun L-shape glow */
.fp-ladder.glow-gcf .fp-div:not(.fp-empty) { background: #D7F3E8; border: .15625rem solid var(--mint); border-radius: .75rem; margin: .125rem .375rem .125rem 0; padding-right: 0; color: var(--ink); box-shadow: 0 0 0 .125rem rgba(47, 169, 135, .25); }
.fp-ladder.glow-lcm .fp-div:not(.fp-empty),
.fp-ladder.glow-lcm .fp-bottom { background: #FFF3C4; border: .15625rem solid var(--sun); border-radius: .75rem; margin: .125rem; padding-right: 0; color: var(--ink); box-shadow: 0 0 0 .125rem rgba(255, 200, 58, .35); }
.fp-ladder.glow-lcm .fp-div:not(.fp-empty) { margin-right: .375rem; }

.fp-ans-row { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: .5rem; font-size: clamp(1.625rem, 6vw, 2.5rem); }
.fp-ans-tag { padding: .25rem .75rem; border-radius: 62.4375rem; border: 2px solid var(--ink); font: 700 1.0625rem/1.2 var(--f-b), var(--cjk); background: #fff; }
.fp-ans-tag.gcf { background: #D7F3E8; border-color: var(--mint); }
.fp-ans-tag.lcm { background: #FFF3C4; border-color: var(--ink); }

/* Prime chips pad in .ho-foot */
.fp-primes { display: grid; grid-template-columns: repeat(3, minmax(4rem, 5.25rem)); gap: .5rem; justify-content: center; width: min(100%, 20rem); }
.fp-prime { min-width: 3.75rem; min-height: 3.75rem; padding: .5rem; font: 800 1.375rem/1 var(--f-m); justify-content: center; }

/* ---------- Mode 2: Prime Tile Splitter ---------- */
.fp-split-box { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: .4375rem; min-height: 4.5rem; padding: .5rem; }
.fp-tile { display: inline-grid; place-items: center; min-width: 3.25rem; min-height: 3.25rem; padding: .375rem .75rem; border: .1875rem solid var(--ink); border-radius: .875rem; font: 800 clamp(1.5rem, 6vw, 2.25rem)/1 var(--f-m); background: #fff; }
.fp-tile.done { background: #E3F5EE; border-color: var(--mint); }
.fp-tile.target { background: var(--sun); box-shadow: .25rem .25rem 0 var(--ink); min-width: 4.5rem; }
.fp-tile.target.unit { background: #E4F1FC; box-shadow: none; border-color: var(--sky); }
.fp-mul { font: 700 1.375rem/1 var(--f-m); color: var(--ink2); }
.fp-power { display: inline-block; position: relative; margin: 0; padding: .375rem .75rem; font: 700 clamp(1.375rem, 5.5vw, 2rem)/1.3 var(--f-m); text-align: center; background: #fff; border: 2px solid var(--edge); border-radius: .875rem; }
.fp-power sup { font-size: .62em; vertical-align: super; line-height: 0; }

/* ---------- Mode 3: Factor Rectangles & Primes ---------- */
.fp-dims { display: flex; flex-wrap: wrap; justify-content: center; gap: .4375rem; max-width: 24rem; }
.ho .fp-dim { min-width: 3.5rem; min-height: 3.5rem; padding: .375rem .625rem; font: 700 1.125rem/1 var(--f-m); justify-content: center; border-radius: .875rem; }
.fp-dim[aria-pressed="true"] { background: var(--sun); border-color: var(--ink); }
.fp-grid-wrap { width: min(100%, 22rem); }
.fp-grid-svg { display: block; width: 100%; height: auto; }
.fp-paper { fill: #fff; stroke: var(--edge); stroke-width: 2; }
.fp-gridline { stroke: #E3ECF7; stroke-width: 1; }
.fp-gridline-strong { stroke: #2FA987; stroke-width: 1; stroke-opacity: .45; }
.fp-sq.ok { fill: #BEEBD9; stroke: #2FA987; stroke-width: 1; }
.fp-sq.part { fill: #D9EBFC; stroke: #4F9BE6; stroke-width: 1; }
.fp-sq.rem { fill: #FDE7E3; stroke: #E8573C; stroke-width: 1.5; stroke-dasharray: 3 2; }
.fp-outline { fill: none; stroke-width: 2; }
.fp-outline.ok { stroke: #1F8A6C; }
.fp-outline.part { stroke: #2F7CC9; }
.fp-bar-lab { fill: var(--ink); font: 800 16px/1 var(--f-m); }
.fp-found { display: flex; flex-wrap: wrap; gap: .375rem; align-items: center; justify-content: center; }
.fp-pair-pill { padding: .25rem .625rem; border-radius: 62.4375rem; border: 1.5px solid var(--mint); background: #E3F5EE; font: 700 .9375rem/1.2 var(--f-m); }
.fp-choices { display: flex; flex-wrap: wrap; gap: .75rem; justify-content: center; width: 100%; }
.fp-choice { display: grid; gap: .125rem; justify-items: center; min-width: 9rem; min-height: 4rem; padding: .5rem 1rem; }
.fp-choice small { font: 500 .8125rem/1.2 var(--f-b), var(--cjk); color: var(--ink2); }
.fp-choice.fp-right { box-shadow: 0 0 0 .25rem var(--mint); }

/* ---------- Look B playful stickers (html:not(.calm)) ---------- */
html:not(.calm) .fp-demo { border: var(--line); border-radius: 1.25rem; background: var(--sb-sun); }
html:not(.calm) .method-guide { border: var(--line); border-radius: 1.25rem; box-shadow: .25rem .25rem 0 var(--mint); }
html:not(.calm) .fp-prime,
html:not(.calm) .fp-dim { border: var(--line); border-radius: 1rem; }
html:not(.calm) .fp-primes .fp-prime:nth-child(3n+1) { background: var(--sb-sun); }
html:not(.calm) .fp-primes .fp-prime:nth-child(3n+2) { background: var(--sb-sky); }
html:not(.calm) .fp-primes .fp-prime:nth-child(3n) { background: var(--sb-mint); }

/* ---------- Calm overrides (Year 5+, html.calm) ---------- */
html.calm .fp-ladder { border-width: 2px; border-color: var(--ink); box-shadow: none; border-radius: .875rem; }
html.calm .fp-tile.target { background: var(--chip); box-shadow: none; }
html.calm .fp-tile.done { background: #EDF7F3; }
html.calm .fp-ladder.glow-gcf .fp-div:not(.fp-empty) { background: #E9F6F0; box-shadow: none; }
html.calm .fp-ladder.glow-lcm .fp-div:not(.fp-empty),
html.calm .fp-ladder.glow-lcm .fp-bottom { background: #FAF1D4; box-shadow: none; }
html.calm .fp-g-bg { fill: #fff; }
html.calm .fp-g-lcm { fill: #FAF1D4; }
html.calm .fp-g-gcf { fill: #E9F6F0; }

@media (max-width: 720px) {
  .fp-guide-body { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  .fp-tile, .fp-prime, .fp-dim { transition: none; }
}

/* ---------- Print sheets & #key view (A4, JIS B5 182x257mm, Letter) ---------- */
.fp-sheet { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 5mm 7mm; align-items: start; }
.fp-sheet li { display: grid; grid-template-columns: auto 1fr; gap: 2mm; align-items: start; break-inside: avoid; border: .3mm solid #B9CBE4; border-radius: 2mm; padding: 2.5mm 3mm; }
.fp-sh-card { display: grid; gap: 1.8mm; min-width: 0; }
.fp-sh-top { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 2mm; font: 700 11pt/1.2 var(--f-m), var(--cjk); }
.fp-sh-num { font: 700 13pt/1.1 var(--f-m); }
.fp-sh-tag { font: 600 8.5pt/1.1 var(--f-b), var(--cjk); padding: .3mm 1.5mm; border: .3mm solid #7F9AC2; border-radius: 1mm; }
.fp-sh-lad { border-collapse: collapse; font: 600 10.5pt/1.2 var(--f-m); margin: .5mm 0; }
.fp-sh-lad td { min-width: 8mm; height: 5.2mm; text-align: center; padding: 0 1.5mm; }
.fp-sh-lad td.d:not(.sh-ans) { width: 7mm; color: #555; }
.fp-sh-lad td.d.sh-ans { width: 7mm; }
.fp-sh-lad td.l { border-left: .45mm solid #263049; }
.fp-sh-lad td.b { border-bottom: .45mm solid #263049; }
.fp-sh-ans { font: 600 9.5pt/1.3 var(--f-m), var(--cjk); }
.fp-sh-blank { display: inline-block; width: 15mm; border-bottom: .35mm solid #263049; height: 3.5mm; vertical-align: baseline; }
.fp-sh-blank.wide { width: 28mm; }
.fp-sh-blank.sm { width: 9mm; }
.fp-sh-work { height: 15mm; border: .3mm dashed #9FB3D1; border-radius: 1.5mm; }
.fp-sh-chain { font: 500 8pt/1.3 var(--f-m); color: #444; word-break: break-word; }
.fp-sh-slots { display: flex; gap: 3mm; padding: 2mm 0; }
.fp-sh-slots i { flex: 1; height: 5mm; border-bottom: .3mm dashed #7F9AC2; }
.fp-sh-pairs { font: 600 9.5pt/1.3 var(--f-m); min-height: 7mm; }
.fp-sh-checks { display: flex; flex-wrap: wrap; gap: 1.5mm 3mm; font: 600 8.5pt/1.3 var(--f-b), var(--cjk); align-items: baseline; }
@media print {
  .fp-sheet { gap: 4mm 5.5mm; }
  .fp-sheet li { padding: 2.2mm 2.8mm; }
  .fp-sh-lad td { height: 5mm; }
  .fp-sh-work { height: 14mm; }
}
@media screen {
  .keyview .fp-sheet { grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr)); gap: .75rem; }
  .keyview .fp-sheet li { border: 1.5px solid var(--edge); border-radius: .75rem; padding: .625rem .75rem; background: #fff; }
}
