/* 紙と黒線。影とグラデーションは使わない。色は赤ペン（○×・減点・点数・判子）と鉛筆の灰だけ。 */
:root {
  --ink: #18181a;
  --dim: #85827a;
  --desk: #e9e7e0;
  --sheet: #fbfaf7;
  --card: #fff;
  --soft: #d9d6cd;
  --red: #c8352a;
  --pencil: #5d5b57;
}

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

html, body { margin: 0; padding: 0; height: 100%; background: var(--desk); }

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;
  touch-action: manipulation;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
}

button { font-family: inherit; color: inherit; touch-action: manipulation; -webkit-touch-callout: none; }
input { font-family: inherit; -webkit-user-select: text; user-select: text; }

#app {
  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-x: clip;
  position: relative;
}

/* --- 紙の外（右上の角） --- */
.tools { position: absolute; top: calc(env(safe-area-inset-top) + 4px); right: 8px; display: flex; gap: 5px; z-index: 5; }
.tool {
  font-size: 11px; height: 22px; padding: 0 7px; border: 1.5px solid var(--ink); border-radius: 3px;
  background: var(--card); cursor: pointer; position: relative;
}
.tool:active { transform: translateY(1px); }
.tool.snd { width: 24px; 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); }

#main { flex: 1 1 auto; overflow-y: auto; overflow-x: hidden; padding: 30px 8px 16px; -webkit-overflow-scrolling: touch; }

/* --- 答案用紙（頭＝帯も紙の一部） --- */
.paper { background: var(--sheet); border: 1.5px solid var(--ink); padding: 0 12px 12px; position: relative; }
.head { position: relative; padding: 6px 0 7px; border-bottom: 1.5px solid var(--ink); }
.r { display: flex; align-items: center; gap: 10px; }
.title { margin: 0; font-size: 23px; font-weight: 700; letter-spacing: .12em; line-height: 1.35; }
.dots { display: flex; gap: 6px; }
.dots i { width: 10px; height: 10px; border-radius: 50%; border: 1.5px solid var(--ink); }
.dots i.on { background: var(--ink); }
.rule { margin: 1px 0 6px; font-size: 14px; letter-spacing: .02em; }
.who { display: flex; align-items: flex-end; gap: 10px; }
.nm { display: flex; align-items: flex-end; gap: 6px; flex: 1 1 auto; min-width: 0; }
.lbl { font-size: 12px; line-height: 1; padding-bottom: 6px; white-space: nowrap; }
.nline { position: relative; flex: 1 1 auto; min-width: 0; max-width: 170px; }
.name {
  width: 100%; height: 34px; border: 1.5px solid var(--ink); background: var(--card); border-radius: 0;
  font-size: 18px; color: var(--pencil); padding: 0 6px; outline: none; caret-color: var(--pencil);
}
.name:focus { border-width: 2.5px; }
.nline.red::after { content: ""; position: absolute; left: -2px; right: -2px; bottom: -3px; border-top: 3px solid var(--red); }
.minus { position: absolute; right: 6px; bottom: 5px; color: var(--red); font-size: 18px; font-weight: 700; letter-spacing: .02em; pointer-events: auto; }
.sc { display: flex; align-items: flex-end; gap: 6px; }
.score {
  width: 64px; height: 36px; border: 1.5px solid var(--ink); background: var(--card); color: var(--red);
  display: inline-flex; align-items: center; justify-content: center; font-size: 22px; font-weight: 700; letter-spacing: -.02em;
}
.score { position: relative; }
.score .old { position: absolute; left: 3px; top: -1px; font-size: 13px; line-height: 1.2; text-decoration: line-through; text-decoration-thickness: 1.5px; }
.score .now { display: inline-block; }
.stamp {
  position: absolute; right: 2px; top: calc(100% + 6px); z-index: 2; color: var(--red); border: 3px solid var(--red); border-radius: 8px;
  font-size: 17px; padding: 3px 9px; letter-spacing: .08em; transform: rotate(-9deg); background: transparent; opacity: .9;
}
.stamp.press { animation: press .32s cubic-bezier(.3, 1.6, .5, 1); }

/* --- 問題 --- */
.test { padding-top: 6px; }
.test.out { transform: translateX(-110%); transition: transform .3s ease-in; }
.test.in { animation: slidein .35s ease-out; }
.sub { margin: 0 0 3px; font-size: 14px; font-weight: 700; letter-spacing: .1em; }
.qs { list-style: none; margin: 0; padding: 0; }
.q { position: relative; padding: 4px 0 6px; border-bottom: 1px solid var(--soft); }
.qh { display: flex; align-items: baseline; gap: 8px; min-height: 22px; }
.qn { position: relative; font-size: 14px; font-weight: 700; white-space: nowrap; }
.qn small { font-size: 10px; font-weight: 400; margin-left: 1px; }
.qt { font-size: 15px; }
.ded { margin-left: auto; color: var(--red); font-size: 14px; font-weight: 700; }
.opts { display: flex; gap: 5px; margin-top: 3px; }
.op {
  flex: 1 1 0; min-width: 0; height: 32px; border: 1.5px solid var(--ink); border-radius: 3px; background: var(--card);
  font-size: 15px; display: flex; align-items: center; justify-content: center; gap: 4px; cursor: pointer; position: relative; padding: 0 2px;
  white-space: nowrap;
}
.op b { font-size: 12px; font-weight: 700; }
.op:active { transform: translateY(1px); }
.op b { position: relative; }
.op.on b::before {
  content: ""; position: absolute; left: 50%; top: 50%; width: 18px; height: 18px; margin: -9px 0 0 -9px; border: 2px solid var(--pencil); border-radius: 50%;
  transform: rotate(-12deg) scale(1.05, .95);
}
.op:disabled { cursor: default; }

/* 問4 のマス */
.boxes { display: flex; align-items: center; gap: 4px; margin-top: 4px; }
.bx {
  width: 38px; height: 42px; border: 1.5px solid var(--ink); background: var(--card); text-align: center;
  font-size: 24px; display: inline-flex; align-items: center; justify-content: center; padding: 0; border-radius: 0;
}
input.bx { color: var(--pencil); outline: none; caret-color: var(--pencil); }
input.bx:focus { border-width: 2.5px; }
.bx.pr { color: var(--ink); font-weight: 700; }
span.bx.d { color: var(--pencil); }
.ten { font-size: 15px; margin-left: 2px; }

/* --- 赤ペン --- */
.mkw { position: absolute; left: -6px; top: -12px; width: 40px; height: 40px; pointer-events: none; }
.mk { position: absolute; inset: 0; display: block; pointer-events: auto; }
.mk svg { width: 100%; height: 100%; fill: none; stroke: var(--red); stroke-width: 3.2; stroke-linecap: round; stroke-linejoin: round; overflow: visible; }
.mk.draw svg path { stroke-dasharray: 160; stroke-dashoffset: 160; animation: draw .24s ease-out forwards; }
.mk.draw svg path + path { animation-delay: .08s; }
.hanaw { position: absolute; right: 4px; top: 26px; width: 60px; height: 60px; pointer-events: none; }
.mk.m-hana svg { stroke-width: 3; }
.mk.m-hana.draw svg path { stroke-dasharray: 420; stroke-dashoffset: 420; animation: draw .5s ease-out forwards; }
.q4 .qt { line-height: 1.5; }
.cond { text-decoration: underline wavy transparent; text-decoration-thickness: 2px; text-underline-offset: 4px; text-decoration-skip-ink: none; transition: text-decoration-color .25s; }
.cond.near { text-decoration-color: var(--red); }

/* --- 出す --- */
.submit {
  display: block; width: 100%; height: 44px; margin-top: 8px; border: 2px solid var(--ink); border-radius: 4px; background: var(--card);
  font-size: 17px; font-weight: 700; letter-spacing: .3em; cursor: pointer;
}
.submit:active { transform: translateY(2px); }
.busy .submit { opacity: .55; }

/* 押す物ではない */
.wob { animation: wob .36s; }
.ink { animation: ink .3s; }

@keyframes draw { to { stroke-dashoffset: 0; } }
@keyframes wob { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-3px); } 75% { transform: translateX(3px); } }
@keyframes ink { from { transform: scale(1.18); } to { transform: scale(1); } }
@keyframes press { from { transform: rotate(-9deg) scale(1.8); opacity: 0; } to { transform: rotate(-9deg) scale(1); opacity: .9; } }
@keyframes slidein { from { transform: translateX(110%); } to { transform: translateX(0); } }

/* --- タイトル画面（遊びの土台だけ） --- */
.top { display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 36px 6px 10px; text-align: center; }
.big { margin: 0; font-size: 40px; font-weight: 700; letter-spacing: .16em; }
.base { margin: 0; font-size: 15px; line-height: 1.8; }
.sample { width: 100%; max-width: 330px; background: var(--sheet); border: 1.5px solid var(--ink); padding: 8px 12px 10px; text-align: left; }
.sample .sh { display: flex; align-items: baseline; gap: 8px; font-size: 15px; }
.sample .sh b { font-size: 14px; }
.sample .sh small { font-size: 10px; font-weight: 400; }
.sample .opts { pointer-events: none; }
.begin { width: 100%; max-width: 330px; margin-top: 6px; }
.tfoot { font-size: 12px; color: var(--dim); }

/* --- 結果 --- */
.result { display: flex; flex-direction: column; gap: 10px; }
.rpaper .op, .rpaper .name { pointer-events: none; }
.minis { display: flex; gap: 8px; }
.mini { flex: 1 1 0; position: relative; background: var(--sheet); border: 1.5px solid var(--ink); padding: 6px 8px; height: 58px; display: flex; flex-direction: column; justify-content: space-between; }
.mt { font-size: 12px; font-weight: 700; }
.ms { font-size: 20px; color: var(--red); font-weight: 700; }
.mh { position: absolute; right: 6px; top: 6px; width: 44px; height: 44px; }
.mh .mk svg { stroke-width: 4; }
.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px; height: 46px; border: 2px solid var(--ink); border-radius: 4px;
  background: var(--card); font-size: 16px; font-weight: 700; text-decoration: none; color: var(--ink); cursor: pointer;
}
.btn.x { background: var(--ink); color: #fff; }
.xlogo { width: 18px; height: 18px; }
#foot { margin-top: 14px; font-size: 12px; color: var(--dim); text-align: center; }

.toast {
  position: fixed; left: 50%; bottom: 40px; transform: translateX(-50%); background: var(--ink); color: #fff; font-size: 13px;
  padding: 8px 14px; border-radius: 4px; z-index: 20; transition: opacity .5s;
}
.toast.out { opacity: 0; }

@media (max-width: 370px) {
  .op { font-size: 14px; }
  .qt { font-size: 14px; }
}
@media (prefers-reduced-motion: reduce) {
  .mk.draw svg path, .mk.m-hana.draw svg path { animation-duration: .01s; }
}
