:root {
  --paper: #f6f0e2;
  --sheet: #fffaf0;
  --ink: #1f1b16;
  --sub: #6b5f50;
  --rule: #d7a089;
  --guide: #ecd2c4;
  --shu: #d8402c;
  --rest: #cfc6b8;
  --serif: "Hiragino Mincho ProN", "Yu Mincho", YuMincho, "Noto Serif JP", "Noto Serif CJK JP", serif;
  --sans: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic", Meiryo, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--paper); color: var(--ink); font-family: var(--sans); -webkit-text-size-adjust: 100%; }
body { min-height: 100dvh; }
button { font: inherit; color: inherit; }
.hidden { display: none !important; }

.screen { max-width: 520px; margin: 0 auto; padding: max(12px, env(safe-area-inset-top)) 14px calc(28px + env(safe-area-inset-bottom)); }

.btn {
  appearance: none; border: 2px solid var(--ink); background: var(--sheet); border-radius: 12px;
  padding: 12px 20px; font-weight: 700; font-size: 17px; cursor: pointer; touch-action: manipulation;
}
.btn.primary { background: var(--ink); color: var(--sheet); }
.btn:disabled { opacity: .45; cursor: default; }
.btn:active:not(:disabled) { transform: translateY(1px); }

/* glyphs drawn from KanjiVG strokes */
svg.g { width: 1em; height: 1em; fill: none; stroke: currentColor; stroke-width: 8; stroke-linecap: round; stroke-linejoin: round; }

/* --- title --- */
.title { text-align: center; padding-top: max(56px, env(safe-area-inset-top)); }
.logo { margin: 12px 0 18px; font-size: 76px; line-height: 1; display: flex; justify-content: center; gap: 2px; }
.logo svg.g path { stroke-dasharray: 200 400; stroke-dashoffset: 200; animation: draw .22s ease-out forwards; animation-delay: calc(var(--d, 0s) + var(--i) * .2s); }
.logo .k1 { --d: .6s; } .logo .k2 { --d: .9s; } .logo .k3 { --d: 1.3s; }
@keyframes draw { to { stroke-dashoffset: 0; } }
.lead { font-family: var(--serif); font-size: 21px; line-height: 1.7; margin: 0 0 24px; }
.today { margin: 0 0 18px; color: var(--sub); font-size: 15px; }
.today b { font-size: 22px; color: var(--ink); margin-right: 8px; font-family: var(--serif); }
.title .btn.primary { min-width: 220px; font-size: 20px; padding: 15px 28px; }
.sub { color: var(--sub); font-size: 13px; margin: 14px 0 24px; }
.credit { margin-top: 28px; font-size: 11px; color: #9a8d7c; text-align: center; }
.credit a { color: inherit; }

/* --- header --- */
.top { display: flex; align-items: center; gap: 10px; margin: 0 0 10px; }
.logo-s { font-size: 22px; display: inline-flex; }
.logo-s svg.g { stroke-width: 10; }
.top .no { font-family: var(--serif); font-weight: 700; font-size: 18px; }
.top .date { margin-left: auto; color: var(--sub); font-size: 13px; }

/* --- the manuscript sheet --- */
.sheet {
  display: grid; grid-template-columns: repeat(var(--cols), 1fr);
  background: var(--sheet); padding: 6px; border: 1px solid var(--rule); border-radius: 4px;
  box-shadow: 0 1px 0 rgba(0,0,0,.04), 0 6px 18px -12px rgba(60,40,20,.35);
}
.cell {
  position: relative; aspect-ratio: 1; border: .5px solid var(--rule); margin: -.25px;
  background:
    linear-gradient(to right, transparent calc(50% - .5px), var(--guide) calc(50% - .5px), var(--guide) calc(50% + .5px), transparent calc(50% + .5px)),
    linear-gradient(to bottom, transparent calc(50% - .5px), var(--guide) calc(50% - .5px), var(--guide) calc(50% + .5px), transparent calc(50% + .5px));
}
.cell svg { position: absolute; inset: 6%; width: 88%; height: 88%; overflow: visible; }
.cell path { fill: none; stroke: var(--ink); stroke-width: 6.5; stroke-linecap: round; stroke-linejoin: round; visibility: hidden; stroke-dasharray: 1 2; stroke-dashoffset: 1; transition: stroke .5s; }
.cell path.on { visibility: visible; animation: draw .28s ease-out forwards; }
.cell path.on.now { animation: none; stroke-dashoffset: 0; }
.cell path.new { stroke: var(--shu); transition: none; }
.cell path.rest { visibility: visible; stroke: var(--rest); animation: draw .2s linear both; }
.cell path.rest.now { animation: none; stroke-dashoffset: 0; }
@keyframes stampin { from { opacity: 0; transform: scale(1.5) rotate(-20deg); } to { opacity: 1; transform: none; } }

/* --- play --- */
.ctrl { display: flex; align-items: center; gap: 12px; margin: 14px 0 6px; }
.count { font-family: var(--serif); font-size: 18px; min-width: 92px; text-align: right; }
.count b { font-size: 40px; font-variant-numeric: tabular-nums; }
.btn.write {
  flex: 1; height: 64px; font-size: 22px; font-family: var(--serif); letter-spacing: .3em; text-indent: .3em;
  background: var(--sheet); user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; touch-action: none;
  box-shadow: 0 4px 0 var(--ink); transition: transform .05s, box-shadow .05s;
}
.btn.write.held { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); background: #fff3ea; }
.btn.write:disabled { box-shadow: none; letter-spacing: 0; text-indent: 0; font-size: 17px; }
.hint { text-align: center; color: var(--shu); font-size: 13px; margin: 6px 0 0; transition: opacity .4s; }
.hint.gone { opacity: 0; }
.ans { display: flex; gap: 8px; margin: 14px 0 8px; }
.ans input {
  flex: 1; min-width: 0; font-size: 18px; padding: 12px 12px; border: 2px solid var(--ink); border-radius: 12px; background: #fff; color: var(--ink);
}
.ans input:focus { outline: 3px solid rgba(216,64,44,.25); }
.ans.shake { animation: shake .35s; }
@keyframes shake { 20%, 60% { transform: translateX(-7px); } 40%, 80% { transform: translateX(7px); } }
.status { display: flex; align-items: center; gap: 10px; min-height: 28px; flex-wrap: wrap; }
.lives { display: inline-flex; gap: 5px; }
.lives i { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--ink); background: var(--ink); display: inline-block; position: relative; }
.lives i.x { background: transparent; border-color: var(--shu); }
.lives i.x::before, .lives i.x::after { content: ""; position: absolute; left: 50%; top: -3px; width: 2px; height: 18px; background: var(--shu); transform: translateX(-50%) rotate(45deg); }
.lives i.x::after { transform: translateX(-50%) rotate(-45deg); }
.guesses { display: flex; gap: 8px; flex-wrap: wrap; color: var(--sub); font-size: 14px; }
.guesses s { text-decoration-color: var(--shu); text-decoration-thickness: 2px; }
.giveup { display: block; margin: 12px auto 0; background: none; border: none; color: var(--sub); text-decoration: underline; font-size: 14px; cursor: pointer; }
.toast { position: fixed; left: 50%; top: max(10px, env(safe-area-inset-top)); z-index: 5; transform: translate(-50%, 8px); background: var(--ink); color: var(--sheet); padding: 10px 18px; border-radius: 999px; font-weight: 700; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* --- result --- */
.verdict { text-align: center; margin: 8px 0 14px; position: relative; }
.verdict .big { font-family: var(--serif); font-size: 26px; font-weight: 700; margin: 0; }
.verdict .big b { font-size: 68px; line-height: 1; margin-right: 2px; }
.verdict .big b.ng { font-size: 48px; }
.verdict .stamp {
  display: inline-block; margin: 8px 0 4px; padding: 4px 16px; border: 3px solid var(--shu); border-radius: 8px; color: var(--shu);
  font-family: var(--serif); font-weight: 700; font-size: 22px; transform: rotate(-4deg); animation: stampin .4s .3s ease-out both;
}
.verdict .meta { margin: 6px 0 0; color: var(--sub); font-size: 14px; }
.answer { text-align: center; font-size: 15px; color: var(--sub); margin: 12px 0 14px; }
.answer b { font-family: var(--serif); font-size: 26px; color: var(--ink); margin-left: 8px; }
.actions { display: flex; gap: 10px; justify-content: center; }
.actions .btn.primary { min-width: 180px; font-size: 18px; }
.btn.x { display: inline-flex; align-items: center; justify-content: center; gap: 4px; }
.btn.x svg { width: 20px; height: 20px; }
.card { display: block; width: 100%; height: auto; margin: 14px 0 6px; border-radius: 6px; border: 1px solid var(--rule); }
.box { background: var(--sheet); border: 1px solid var(--rule); border-radius: 6px; padding: 12px 14px; margin: 14px 0; }
.box h2 { font-family: var(--serif); font-size: 16px; margin: 0 0 8px; }
.dist-top { margin: 0 0 8px; font-size: 14px; color: var(--sub); }
.dist-top b { color: var(--shu); font-size: 18px; }
.dist-empty { margin: 0; color: var(--sub); font-size: 14px; }
.dist { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.dist li { display: grid; grid-template-columns: 76px 1fr 32px; align-items: center; gap: 8px; font-size: 12px; color: var(--sub); }
.dist li i { display: block; height: 14px; width: var(--w); background: #bfb4a4; border-radius: 2px; }
.dist li em { font-style: normal; text-align: right; font-variant-numeric: tabular-nums; }
.dist li.me { color: var(--shu); font-weight: 700; }
.dist li.me i { background: var(--shu); }
.mine { display: grid; grid-template-columns: repeat(4, 1fr); margin: 0; text-align: center; }
.mine dt { font-size: 11px; color: var(--sub); }
.mine dd { margin: 2px 0 0; font-family: var(--serif); font-size: 24px; font-weight: 700; }
.next { text-align: center; color: var(--sub); font-size: 14px; }
.next b { font-family: var(--serif); font-size: 20px; color: var(--ink); font-variant-numeric: tabular-nums; margin-left: 6px; }
.sn-after { margin-top: 18px; }
