/* 紙と黒線。影とグラデーションは使わない。色は選択肢のカード（透けるフィルム）と、問題文の色ペンの画だけ。
   カードは mix-blend-mode: multiply で紙に重なる（重ねると色が混ざって見える）。
   画が消えるかは stages.js の vanishes で決め、消える画は .gone で消す（淡い色なので、掛け合わせだけでは消えない）。
   色はカードとペンで同じ系統にそろえる（赤いカードの下で赤ペンの画が消えて見えるように）。 */
:root {
  --ink: #1c1c1e;
  --dim: #85827a;
  --paper: #f4f3ef;
  --sheet: #fbfaf7;
  --card: #fff;
  --soft: #d9d6cd;
  --grid: #e7e3d9;
  --red: #e03131;
  /* 色ペン：それを消す枠（重ね方）を紙に重ねたときと同じ色（紙 × 枠の掛け合わせ。枠の色を変えたら計算し直す）
     赤＝D、緑＝A×B、青＝B×C、黄＝A、水色＝B、ピンク＝C */
  --i-r: #fb8483;
  --i-g: #729d38;
  --i-b: #6e61a5;
  --i-y: #fbd039;
  --i-c: #72bcf4;
  --i-m: #f380a7;
  /* 選択肢のカード（A 黄・B 水色・C ピンク・D 赤） */
  --t-y: #ffd43b;
  --t-c: #74c0fc;
  --t-m: #f783ac;
  --t-r: #ff8787;
  --cell: 46px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; padding: 0; height: 100%; background: var(--paper); touch-action: manipulation; }

body {
  color: var(--ink);
  font-family: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Noto Sans CJK JP", "Yu Gothic", system-ui, sans-serif;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
}

p, h1, h2 { word-break: auto-phrase; text-wrap: pretty; }
button { font-family: inherit; color: inherit; touch-action: manipulation; -webkit-touch-callout: none; }

#app {
  position: relative;
  height: var(--app-h, 100dvh);
  transform: translateY(var(--app-top, 0px));
  max-width: 440px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding-top: env(safe-area-inset-top);
  overflow: hidden;
}
@media (min-width: 520px) { #app { border-left: 1px solid var(--soft); border-right: 1px solid var(--soft); } }

.stamp { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; animation: stampIn .18s ease-out; }
.stamp circle, .stamp path { fill: none; stroke: var(--red); stroke-width: 3; stroke-linecap: round; opacity: .9; }
@keyframes stampIn { from { transform: scale(1.5); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* --- 帯 --- */
.band { flex: 0 0 auto; padding: 6px 14px 8px; border-bottom: 1.5px solid var(--ink); }
.r { display: flex; align-items: center; gap: 10px; }
.title { margin: 0; font-size: 19px; font-weight: 700; letter-spacing: 1px; white-space: nowrap; }
.dots { display: flex; gap: 5px; margin-right: auto; }
.dots i { width: 10px; height: 10px; border-radius: 50%; border: 1.5px solid var(--ink); }
.dots i.on { background: var(--ink); }
.tools { display: flex; gap: 6px; }
.tool {
  font-size: 12px; height: 26px; padding: 0 8px; border: 1.5px solid var(--ink); border-radius: 3px;
  background: var(--card); cursor: pointer; position: relative; white-space: nowrap;
}
.tool:active { transform: translateY(1px); }
/* 当たりを見た目より 6px ずつ広げる（36px 以上。preflight） */
.tool::before { content: ""; position: absolute; inset: -6px; }
.tool.snd { width: 28px; padding: 0; line-height: 1; }
.tool.snd.off::after { content: ""; position: absolute; left: 4px; right: 4px; top: 50%; border-top: 1.5px solid var(--ink); transform: rotate(-40deg); }
.rule { margin: 4px 0 0; font-size: 14px; }

/* --- 本編 --- */
#main { flex: 1 1 auto; overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch; }
/* 付箋はこの箱の中に絶対配置する。この箱と .films に z-index・transform・opacity を付けない
   （重ね合わせの文脈ができると、付箋が問題カードと混ざらなくなる） */
.play { position: relative; padding: 10px 14px 8px; display: flex; flex-direction: column; gap: 10px; }
.card {
  position: relative; background: var(--sheet); border: 1.5px solid var(--ink); padding: 6px 10px 10px;
  transition: transform .35s ease, opacity .35s ease;
}
.card.out { transform: translateX(-115%) rotate(-5deg); opacity: 0; }
.card.in0 { transform: translateX(30%); opacity: 0; transition: none; }
.chead { display: flex; align-items: center; gap: 10px; min-height: 34px; border-bottom: 1px solid var(--soft); }
.cnum { font-size: 15px; font-weight: 700; letter-spacing: 1px; }
.mark { position: relative; margin-left: auto; width: 34px; height: 34px; }
.qrows { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 14px 0 10px; }
.qrow { display: flex; }
.cell {
  position: relative; width: var(--cell); height: var(--cell); background: var(--sheet);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: calc(var(--cell) * .62); font-weight: 700; line-height: 1;
  outline: 1px solid var(--grid); outline-offset: -1px;
}
.cell .gl { width: 82%; height: 82%; overflow: visible; }
/* インクどうしは掛け合わせで重なる（svg の中だけで混ぜ、紙とは混ぜない） */
.gl { isolation: isolate; }
.gl path { fill: none; stroke-width: 10; stroke-linecap: round; stroke-linejoin: round; mix-blend-mode: multiply; transition: opacity .16s; }
.gl path.gone { opacity: 0; }
.ink-k { stroke: var(--ink); }
.ink-r { stroke: var(--i-r); }
.ink-g { stroke: var(--i-g); }
.ink-b { stroke: var(--i-b); }
.ink-y { stroke: var(--i-y); }
.ink-c { stroke: var(--i-c); }
.ink-m { stroke: var(--i-m); }
.cell.wob { animation: wob .45s; }
.cell.pop { animation: pop .45s; }
@keyframes pop { 40% { transform: scale(1.18); } }
.cell.hov { outline: 2px solid var(--dim); outline-offset: -2px; }

/* 選択肢 A〜D（2×2）。カードの定位置（.spot）と記号 */
.chs { display: grid; grid-template-columns: repeat(2, auto); justify-content: space-around; gap: 12px 18px; padding: 12px 4px 4px; border-top: 1px dashed var(--soft); }
.ch { display: flex; align-items: center; }
/* 選択肢の字は紙に印刷してある（枠を動かしても残る） */
.spot { width: var(--cell); height: var(--cell); border-radius: 8px; outline: 1.5px dashed var(--soft); outline-offset: -1px;
  display: flex; align-items: center; justify-content: center; font-size: calc(var(--cell) * .5); font-weight: 700; line-height: 1; }

/* こたえ（ドロップダウン） */
.arow { display: flex; justify-content: flex-end; align-items: center; gap: 10px; padding-top: 12px; }
.alab { font-size: 15px; font-weight: 700; }
.sel { position: relative; display: inline-block; }
.sel select {
  appearance: none; -webkit-appearance: none; font: inherit; font-size: 17px; font-weight: 700; color: var(--ink);
  height: 42px; min-width: 112px; padding: 0 36px 0 14px; border: 1.5px solid var(--ink); border-radius: 8px; background: var(--card);
}
.sel select.none { color: var(--dim); font-weight: 400; }
.sel::after { content: ""; position: absolute; right: 14px; top: 16px; width: 7px; height: 7px; border-right: 2px solid var(--ink); border-bottom: 2px solid var(--ink); transform: rotate(45deg); pointer-events: none; }
.sel.wob { animation: wob .5s; }

/* 選択肢の枠（色つきの透けるフィルム）。記号 A〜D は枠の隅に書く（隅は色ごとに違うので、重ねても読める） */
.films { position: absolute; left: 0; top: 0; width: 0; height: 0; }
.tile {
  position: absolute; left: 0; top: 0; width: var(--cell); height: var(--cell); border-radius: 8px;
  background: var(--tint); mix-blend-mode: multiply; touch-action: none; cursor: grab;
  transition: left .18s ease, top .18s ease, border-radius .18s;
}
.tile .key { position: absolute; font-style: normal; font-size: 11px; font-weight: 700; line-height: 1; padding: 2px 3px; background: #fff; border-radius: 3px; }
.tile.out { border-radius: 3px; }
.tile[data-t="y"] { --tint: var(--t-y); }
.tile[data-t="c"] { --tint: var(--t-c); }
.tile[data-t="m"] { --tint: var(--t-m); }
.tile[data-t="r"] { --tint: var(--t-r); }
.tile[data-t="y"] .key { left: 2px; top: 2px; }
.tile[data-t="c"] .key { right: 2px; top: 2px; }
.tile[data-t="m"] .key { left: 2px; bottom: 2px; }
.tile[data-t="r"] .key { right: 2px; bottom: 2px; }
.tile.on { outline: 2px solid var(--ink); outline-offset: -2px; }
.tile.held { transition: none; z-index: 20; cursor: grabbing; }
.tile.wob { animation: wob .45s; }
.tile.jig { animation: jig .52s; }

.acts { display: flex; gap: 10px; }
.clr { height: 48px; padding: 0 16px; font-size: 14px; border: 1.5px solid var(--ink); border-radius: 4px; background: var(--card); cursor: pointer; }
.clr:active { transform: translateY(1px); }
.check { flex: 1 1 auto; height: 48px; font-size: 16px; font-weight: 700; border: 2px solid var(--ink); border-radius: 4px; background: var(--card); cursor: pointer; }
.check.wait { opacity: .45; }
.check:active { transform: translateY(2px); }

@keyframes wob { 0%, 100% { transform: translateX(0); } 20% { transform: translateX(-4px); } 40% { transform: translateX(4px); } 60% { transform: translateX(-3px); } 80% { transform: translateX(3px); } }

/* --- 結果 --- */
.result { padding: 18px 14px 18px; display: flex; flex-direction: column; align-items: stretch; gap: 12px; }
.rhead { display: flex; align-items: center; gap: 14px; }
.rbig { position: relative; width: 64px; height: 64px; flex: 0 0 auto; }
.rbig .stamp { animation: none; }
.rtitle { margin: 0; font-size: 26px; font-weight: 700; letter-spacing: 2px; }
.rsub { margin: 2px 0 0; font-size: 14px; color: var(--dim); }
.rfilm { position: relative; height: 92px; }
.rfilm i { position: absolute; top: 14px; width: 74px; height: 74px; mix-blend-mode: multiply; border-radius: 8px; }
.btn {
  display: flex; align-items: center; justify-content: center; gap: 4px; height: 48px; font-size: 16px; font-weight: 700;
  border: 2px solid var(--ink); border-radius: 4px; background: var(--card); color: var(--ink); text-decoration: none; cursor: pointer;
}
.btn.x { background: var(--ink); color: #fff; }
.xlogo { width: 18px; height: 18px; }
.btn:active { transform: translateY(2px); }

#foot { padding: 6px 14px 16px; font-size: 12px; text-align: center; color: var(--dim); }

.toast { pointer-events: none; /* お知らせは指を素通りさせる（出ている 1.6 秒のあいだ下の枠がつまめなくなっていた） */
  position: fixed; left: 50%; top: 40%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 16px;
  border-radius: 4px; font-size: 14px; z-index: 50; transition: opacity .5s;
}
.toast.out { opacity: 0; }
.said { font-size: 15px; font-weight: 700; opacity: 0; transition: opacity .15s; }
.said.on { opacity: 1; }
/* 外れたときの枠の震え。持ち上がって左右に傾く（つまめる物に見せる） */
@keyframes jig { 0%, 100% { transform: none; } 15% { transform: translateY(-3px) rotate(-7deg); } 35% { transform: translateY(-3px) rotate(6deg); } 55% { transform: translateY(-2px) rotate(-4deg); } 75% { transform: translateY(-1px) rotate(2deg); } }
