/* masugami — the core game's sheet (CORE_SWAP_WORK_ORDER §3–§5; built as Kagami,
   docs/handoff/KAGAMI_WORK_ORDER.md §7, and `kagami` stays its internal name)
   The core game is drawn by masugami-kagami-screen.js with the player's own classes: the paper,
   creases and ink (masugami-player.css, masugami-marks.css), the pip strip, the level strip, the
   quiet and primary words and the result presentation; its Home is Home's (masugami-navigation.css).
   This file adds only what the core game has and Clean does not: the pale marks (pale ink in every
   material) and the solved join, the outlined and dashed previews, the lifting side's tone, the
   crease ticks and the result's arrival; the flap is Clean's. Every colour is a theme token; relief is shadow,
   never fill. */

/* ---------- the frame ----------
   A sheet stands where the tab panel stands, in the game view's column (the back chevron, the
   title and its second line, the three glyphs). The play view takes the column's height as
   Clean's level does, so the sheet gets every pixel the chrome leaves. */
.kagami[hidden],.kagami-play[hidden]{display:none}
html[data-view="game"] .kagami{display:flex;flex-direction:column;flex:1 0 auto}
.kagami-play{display:flex;flex-direction:column;flex:1 0 auto}

/* ---------- five paper tiles ----------
   The day's strip keeps the pitch of Clean's ten, so five stand in the middle half of the column. */
.level-strip.kagami-strip{grid-template-columns:repeat(5,minmax(0,1fr));width:50%;margin:var(--ms-space-2) auto 0}
.level-strip.home-strip.kagami-strip{margin:0 auto var(--ms-space-3)}
.level-strip.result-strip.kagami-strip{margin:0 auto var(--ms-space-5)}
.kagami-strip[hidden]{display:none}

/* ---------- the sheet ---------- */
.kagami-board{
  position:relative;display:grid;padding:var(--ms-space-3);
  transform-style:preserve-3d;user-select:none;-webkit-user-select:none;cursor:grab;
  touch-action:none;-webkit-tap-highlight-color:transparent;
}
/* The core game's paper (CORE_SWAP_WORK_ORDER §4): every sheet the core game draws (the board,
   its flap, the still sheets) is its own paper, with its own tokens (--ms-core-*, one set per
   palette in masugami-theme.css). Inside it they stand for the paper and ink names the player's
   rules read, so the paper, the flap, the ink, the creases, the previews and the refused mark all
   follow them with no second code path. On washi and kasure they repeat the material's own
   values; on ai they are the core game's pale indigo paper with deep indigo ink (S-D12), and the
   original's deep indigo ai is untouched outside this scope (S-A14). The strip of five is the
   same paper, so its tiles are too, and so are the core Home's last seven days. */
.kagami-paper,.kagami-strip,.home-core .home-days{
  --ms-paper:var(--ms-core-sheet);--ms-paper-flap:var(--ms-core-flap);--ms-paper-edge:var(--ms-core-edge);
  --ms-tile-1:var(--ms-core-ink);--ms-tile-2:var(--ms-core-ink-mid);--ms-tile-3:var(--ms-core-ink-edge);
  --ms-ink-soak:var(--ms-core-soak);--ms-shadow:var(--ms-core-shadow);
}
/* The armed crease on the core sheet: the material's one accent, as the sheet's own token. On ai's
   pale paper it is yamabuki deepened until the crease reads (at least 3.0:1 against the sheet,
   kagami-player-unit.mjs §11e); on washi and kasure it is their own accent. Only the sheet takes
   it: the room, the header and the controls keep --ms-accent, and nothing else on the sheet spends
   it but the armed crease and its keyboard tick. */
.kagami-paper{--ms-accent:var(--ms-core-accent)}
/* The armed crease is the line the paper bends on: it stays drawn over the lifted flap's hinge,
   so it reads against the sheet and against the flap at every angle. */
.kagami-board > .seam.armed{z-index:21}
/* The sheet's cast shadow is derived from --ms-shadow where the html scope defines it, so the core
   sheet derives it again from its own: on a pale sheet in ai's pale day room, the shadow is what
   sets the paper apart. washi's values are its own, repeated; kasure keeps its own lift. */
html:is([data-theme="washi"],[data-theme="ai"]) .kagami-paper{
  --ms-paper-lift:0 2px 3px var(--ms-shadow), 0 16px 30px var(--ms-shadow), 0 40px 70px var(--ms-shadow);
  --ms-paper-cut-shadow:drop-shadow(0 2px 2px var(--ms-shadow)) drop-shadow(0 16px 24px var(--ms-shadow));
}
/* A locked tile is as faint on ai's pale paper as on washi's, not as on its dyed sheet. */
html[data-theme="ai"][data-appearance="light"] .kagami-strip .level-cell.locked .level-tile{opacity:.42}
html[data-theme="ai"][data-appearance="dark"] .kagami-strip .level-cell.locked .level-tile{opacity:.16}
/* ai's pale paper at night takes the fibre as washi's pale paper does, not sunk into a dyed sheet. */
html[data-theme="ai"][data-appearance="dark"] .kagami-paper :is(.sheetbase,.foldface){background-blend-mode:normal,normal,normal,multiply}

/* The pale marks (S-D17): pale ink in every material. A square still to be inked carries the
   material's own ink mark, in the square's own silhouette variant and jitter, filled flat in the
   sheet's pale tone (--ms-core-pale) at --kagami-pale-alpha, with no relief and no gradient: washi
   the brush dab, ai the same dab in light indigo, kasure the dry brush stroke. Bare paper is bare.
   The opacity is set per material and appearance by a rule both platforms reproduce exactly from
   the theme tokens (site/scripts/kagami-player-unit.mjs §11d computes every contrast): washi at the
   lowest whole percent at which the pale dab reaches 2.3:1 against the sheet (2.0:1 to 2.6:1);
   kasure at 47% by day and 49% at night (2.0:1 to 2.6:1); ai at 40% and 43%, the lowest that reach
   1.6:1 (1.6:1 to 2.0:1, S-A15); full ink at least 3.0:1 against a pale mark, everywhere.
   Ink and its pale mark share one slot, 86% of the pitch (the square and its gap, crease to
   crease, as the study's square is), centred on the square and moved by its jitter. The board,
   the still sheet and the flap carry --kagami-cell and --kagami-pitch. */
:root{--kagami-pale-alpha:50%}
html[data-theme="washi"][data-appearance="light"]{--kagami-pale-alpha:40%}
html[data-theme="washi"][data-appearance="dark"]{--kagami-pale-alpha:41%}
html[data-theme="ai"][data-appearance="light"]{--kagami-pale-alpha:40%}
html[data-theme="ai"][data-appearance="dark"]{--kagami-pale-alpha:43%}
html[data-theme="kasure"][data-appearance="light"]{--kagami-pale-alpha:47%}
html[data-theme="kasure"][data-appearance="dark"]{--kagami-pale-alpha:49%}
.kagami-square{--kagami-pitch-inset:calc((var(--kagami-cell, 42px) - var(--kagami-pitch, 48px)) / 2)}
:is(.kagami-square,.kagami-bleed){--kagami-pale-ink-inset:calc((var(--kagami-cell, 42px) - var(--kagami-pitch, 48px) * .86) / 2)}
.kagami-pale{
  display:none;position:absolute;z-index:0;pointer-events:none;
  background:color-mix(in srgb, var(--ms-core-pale) var(--kagami-pale-alpha), transparent);
  mask-size:100% 100%;mask-repeat:no-repeat;
}
/* A browser without color-mix() would draw no pale mark at all (the declaration above is dropped),
   leaving nothing to ink. There the mark is the pale token at full strength, thinned by its own
   opacity at the same percentage: the same tone on the paper. Where color-mix() works this block
   does not apply, so nothing it draws changes. */
@supports not (background:color-mix(in srgb, currentColor 50%, transparent)){
  .kagami-pale{background:var(--ms-core-pale);opacity:var(--kagami-pale-alpha)}
}
/* Pale ink: the square's own mark, flat, where the ink will lie; printing fills it. */
.kagami-square:not(.on) > .kagami-pale{
  display:block;inset:var(--kagami-pale-ink-inset);mask-image:var(--kagami-dab);
  transform:translate(var(--ink-x),var(--ink-y)) rotate(var(--ink-rotation));
}
.kagami-square[data-material="kasure"] > .kagami-pale{mask-image:var(--kagami-stroke)}
/* Ink once it lands: Clean's mark (masugami-marks.css), the dab or the dry stroke, in the pale
   mark's slot; on ai the brush dab, never the pool. Seen through the flap's back (.kagami-bleed,
   Clean's soft bleed) it is the same mark in the same slot with the same jitter, so the shadow
   sits exactly where the ink is. */
:is(.kagami-square,.kagami-bleed)[data-material] > .ink-print{inset:var(--kagami-pale-ink-inset)}
:is(.kagami-square,.kagami-bleed)[data-material="ai"] .ink-mark{mask-image:var(--ink-mask-washi)}
.kagami-square[data-material="ai"].on > .ink-print{filter:drop-shadow(0 0 .5px var(--ms-ink-soak))}
/* The solved join (S-D18): on a solved sheet the ink runs together as one picture
   (masugami-kagami-paper.js kagamiJoin) and the single marks give way to it. Never during play. */
.kagami-join{position:absolute;left:0;top:0;z-index:1;pointer-events:none;overflow:visible}
.kagami-join-stop-1{stop-color:var(--ms-core-ink)}
.kagami-join-stop-2{stop-color:var(--ms-core-ink-mid)}
.kagami-joined .kagami-square > .ink-print{opacity:0}

/* Ink that would print: an outline in the ink tone over the pale mark it will fill, told from a
   pale mark (no fill) and from ink (no body). On washi and ai the dab's own outline; on kasure the
   square's brushed outline, since a dry stroke has no single edge to outline. It fades with the
   closing paper (--preview-strength). The accent is spent only on the armed crease. */
.kagami-square.kagami-print::before{
  content:"";position:absolute;z-index:2;pointer-events:none;opacity:var(--preview-strength,1);
  background:var(--ms-tile-2);mask-size:100% 100%;mask-repeat:no-repeat;
}
.kagami-square:is([data-material="washi"],[data-material="ai"]).kagami-print::before{
  inset:var(--kagami-pale-ink-inset);mask-image:var(--ink-outline-washi);
  transform:translate(var(--ink-x),var(--ink-y)) rotate(var(--ink-rotation));
}
.kagami-square[data-material="kasure"].kagami-print::before{inset:var(--kagami-pitch-inset);mask-image:var(--kagami-square-outline)}
/* Ink that would land on a square with no pale mark: a dashed outline struck through once, upper
   left to lower right, in the ink's tone, never the accent, so it cannot be taken for the
   outlined mark of ink that would print. Drawn as a mask (as the ink marks are) so its numbers are
   exact on both platforms: a box 60% of the square, a rounded square inset by half the stroke
   (corner radius 16), stroke 9, dashes 16 on 10, and a strike from 18,18 to 82,82 with round caps,
   all in a 100-unit box: the stroke is 5.4% of the square, 1.6px on a 30px square. The paper
   will not lie down while one shows. */
.kagami-square.kagami-spoil::after{
  content:"";position:absolute;inset:20%;z-index:2;pointer-events:none;
  background:var(--ms-tile-2);opacity:var(--preview-strength,1);
  mask-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'%3E%3Crect x='4.5' y='4.5' width='91' height='91' rx='16' fill='none' stroke='white' stroke-width='9' stroke-dasharray='16 10'/%3E%3Cline x1='18' y1='18' x2='82' y2='82' stroke='white' stroke-width='9' stroke-linecap='round'/%3E%3C/svg%3E");
  mask-size:100% 100%;mask-repeat:no-repeat;
}
/* The side that would lift: the flap's tone over the paper, under the squares. On ai, whose
   flap is its paper, the shadow layer alone carries it. */
.kagami-lift{position:absolute;z-index:0;pointer-events:none;background:var(--ms-paper-flap);opacity:.8}
.kagami-lift::after{content:"";position:absolute;inset:0;background:var(--ms-shadow);opacity:.28}
.kagami-lift[hidden]{display:none}

.kagami-board.dragging{cursor:grabbing}
/* The creases as keyboard and screen-reader controls (the sheet owns the pointer, as Clean's
   does): a tick in the paper's margin, top edge for each upright crease and left edge for each
   level one, drawn only while it has keyboard focus, in the accent when that crease is armed. */
.kagami-tick{
  position:absolute;z-index:6;appearance:none;border:0;padding:0;margin:0;background:transparent;
  pointer-events:none;
}
.kagami-tick::before{
  content:"";position:absolute;background:var(--ms-tile-2);opacity:.45;
  transition:opacity var(--ms-dur-crease),background-color var(--ms-dur-crease);
}
.kagami-tick.v::before{left:50%;width:2px;margin-left:-1px;top:calc(50% - 4px);height:8px}
.kagami-tick.h::before{top:50%;height:2px;margin-top:-1px;left:calc(50% - 4px);width:8px}
.kagami-tick:not(:focus-visible)::before{opacity:0}
.kagami-tick.armed:focus-visible::before{background:var(--ms-accent);opacity:1}
.kagami-tick.hidden{visibility:hidden}
/* A tick's box lies partly on the sheet and partly on the room: its ring is drawn in the sheet's
   ink, which reads on the paper in every palette (at least 3.0:1, kagami-player-unit.mjs §11e),
   and edged outside in the page's text tone, which reads on the room. */
.kagami-tick:focus-visible{
  outline:var(--ms-focus-width) solid var(--ms-core-ink);outline-offset:calc(var(--ms-focus-offset) * -1);
  box-shadow:0 0 0 var(--ms-focus-width) var(--ms-text);
}

/* ---------- the fold ----------
   The lifting half is Clean's flap (masugami-player.css .foldclone, .foldband, .foldface,
   .foldshadow, .exposed), drawn by the shared renderer: it follows the pointer, lands, lies
   pressed, and opens again. Its squares are the sheet's own; nothing here restyles the paper. */
.kagami-flap .fc.kagami-square{z-index:1}

/* ---------- under the sheet ----------
   Undo and Start over at the column's edges as Clean's are; Press, the one primary, between them. */
.kagami-controls{align-items:center}
/* While a viewing shows (My folds, the optimal solution), the stage gives up height to the
   original's section under it, as the original's board does: no floor but the sheet at the
   viewing's least square (masugami-kagami-screen.js KAGAMI_VIEW_CELL_MIN), so the title, the
   position, the transport and Back to result are on a small phone's first screen. Never in play. */
.kagami-play.is-viewing .kagami-stage{min-height:var(--stage-floor,0px)}
/* Room for a two-line status, so a longer sentence does not move the sheet. */
.kagami-status{min-height:3.2em}

/* ---------- the result ----------
   The player's result presentation (masugami-player.css), in Kagami's own dialog: one room, the
   page's ground, the head, the paper with the award on it, the words, the actions. */
.kagami-result{
  position:fixed;inset:0;width:100%;height:100%;max-width:none;max-height:none;margin:0;
  border:0;padding:0;color:var(--ms-text);
  background-color:var(--ms-bg);background-image:var(--ms-bg-glow);background-repeat:no-repeat;
  overflow-y:auto;overscroll-behavior:contain;
}
.kagami-result::backdrop{background:transparent}
html:has(.kagami-result[open]){overflow:hidden}
.kagami-result-main{margin:0;font:400 var(--ms-size-title)/1.25 var(--ms-font-display);color:var(--ms-text-bright);text-wrap:balance}
.kagami-result-sub{margin:0;font:400 var(--ms-size-small)/1.4 var(--ms-font-display);color:var(--ms-text-2);text-wrap:pretty}
.kagami-result-back{display:flex;align-items:center;justify-content:center;flex:none;width:var(--ms-hit-min);height:var(--ms-hit-min);margin:0 0 0 calc(var(--ms-space-4) * -1);padding:0}
.kagami-result-back .back-chevron{flex:none;width:9px;height:15px}
.kagami-result .btn:focus-visible{outline:var(--ms-focus-width) solid var(--ms-text);outline-offset:var(--ms-focus-offset)}
.kagami-result .kagami-result-back:focus-visible{outline-offset:calc(var(--ms-focus-offset) * -1)}
.kagami-day-note[hidden]{display:none}
.kagami-result .result-sheet{margin-block:var(--result-gap)}
/* The arrival, as Clean's one sequence (masugami-player.css): the sheet settles from where it lay
   on the board (--settle-*), the award lands, then the words. A solved sheet's ink runs together
   over the award's landing. A still under Reduce Motion or with Paper bend off. */
.kagami-result.is-arriving .result-sheet{animation:result-settle var(--ms-dur-sheet) var(--ms-ease) both}
.kagami-result.is-arriving .result-award .rank{animation:award-land var(--ms-dur-award-land) var(--ms-ease) var(--ms-dur-sheet) both}
.kagami-result.is-arriving .result-body{animation:result-words var(--ms-dur-result-words) linear calc(var(--ms-dur-sheet) + var(--ms-dur-award-land)) both}
.kagami-result.is-arriving .kagami-joined > .kagami-join{animation:kagami-join var(--ms-dur-award-land) var(--ms-ease) var(--ms-dur-sheet) both}
.kagami-result.is-arriving .kagami-joined .kagami-square > .ink-print{animation:kagami-join var(--ms-dur-award-land) var(--ms-ease) var(--ms-dur-sheet) reverse both}
@keyframes kagami-join{from{opacity:0}to{opacity:1}}
@media (prefers-reduced-motion: reduce){
  html:not([data-fold-motion="full"]) .kagami-result.is-arriving :is(.result-sheet,.result-award .rank,.result-body,.kagami-joined > .kagami-join,.kagami-joined .kagami-square > .ink-print){animation:none}
}
html[data-fold-motion="reduce"] .kagami-result.is-arriving :is(.result-sheet,.result-award .rank,.result-body,.kagami-joined > .kagami-join,.kagami-joined .kagami-square > .ink-print){animation:none}

/* ---------- the landing's frame ----------
   /play?embed=sheet plays the core game's level 1: the sheet alone, as Clean's frame was
   (masugami-player.css), with the foot under it. No pips, strip, Practice word or status line. */
html[data-embed="sheet"] :is(.kagami .practice-label,.kagami-strip,.kagami-status,.kagami-save-notice){display:none!important}
html[data-embed="sheet"] .kagami-controls{justify-content:center;align-items:center;gap:var(--ms-space-4);margin:var(--ms-space-3) 0 0}

/* ---------- the animated how-to (COMPLETE_GAME_WORK_ORDER §7, lane G6w) ----------
   masugami-kagami-howto.js: the how-to's own small sheet folding itself on the core game's own
   paper and flap. The sheet is the one memorable thing; the caption under it is quiet text and the
   pause control a quiet word. Every box is the frame's (masugami-kagami-howto-frame.js), there from
   the first paint: the live sheet's room and its caption's two lines; under Reduce Motion, which
   this media query decides before any script runs, the four stills instead, each a square box with
   its caption, their sheets drawn into the boxes and scaled to them. So nothing below moves when the
   how-to is drawn. A teaching loop is not a fold: neither Reduce Motion's flat fold nor Paper bend
   Off hides its flap. It takes no touch: a finger on it scrolls the page. */
.kagami-howto{margin:0;--kagami-howto-side:266px}
.kagami-howto-stage{position:relative;perspective:1100px}
.kagami-howto-live{display:flex;flex-direction:column;align-items:flex-start;gap:var(--ms-space-3);min-height:calc(var(--kagami-howto-side) + 4.4em)}
.kagami-howto-board{touch-action:auto;cursor:default}
.kagami-howto-board :is(.foldclone,.foldshadow){display:block!important}
.kagami-howto-board.kagami-joined > .kagami-join{opacity:var(--howto-join,1)}
.kagami-howto-board.kagami-joined .kagami-square > .ink-print{opacity:calc(1 - var(--howto-join,1))}
.kagami-howto-caption,.kagami-howto-still-caption{margin:0;font:400 var(--ms-size-body)/1.5 var(--ms-font-display);color:var(--ms-text-2);text-wrap:pretty}
.kagami-howto-caption{min-height:3em;max-width:var(--kagami-howto-side)}
.kagami-howto-stills{display:none;grid-template-columns:repeat(2,minmax(0,1fr));gap:var(--ms-space-5) var(--ms-space-4);margin:0;padding:0;list-style:none}
.kagami-howto-still{display:flex;flex-direction:column;gap:var(--ms-space-2);min-width:0}
.kagami-howto-still-sheet{position:relative;display:block;width:100%;aspect-ratio:1/1}
.kagami-howto-still-sheet > .kagami-howto-board{position:absolute;left:0;top:0;transform-origin:0 0}
.kagami-howto-still-caption{font-size:var(--ms-size-small)}
@media (prefers-reduced-motion: reduce){
  .kagami-howto-live,.kagami-howto-pause{display:none}
  .kagami-howto-stills{display:grid}
}
