:root {
  --bg: #e7d6b0; --bg2: #d9c296; --ink: #2e2b4f; --ink-soft: #5d5775;
  --btn: #f7eedb; --btn-edge: #2e2b4f; --btn-drop: #a9885a; --btn-down: #eadfc6;
  --accent: #d63d72; --accent-drop: #8f2450; --accent-ink: #fff7f0;
  --panel: #f3e8cf; --scrim: rgba(46, 43, 79, 0.55);
  --tb: max(0px, calc(100% - 100svh));
  --font: "DotGothic16", "Hiragino Maru Gothic ProN", "Hiragino Sans", "Yu Gothic", "Noto Sans JP", sans-serif;
  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1d1e2c; --bg2: #272939; --ink: #efe6d2; --ink-soft: #aaa3bf;
    --btn: #34374c; --btn-edge: #0e0f17; --btn-drop: #0e0f17; --btn-down: #2b2e40;
    --panel: #272939; --scrim: rgba(8, 8, 14, 0.6);
  }
}
:root[data-theme="dark"] {
  --bg: #1d1e2c; --bg2: #272939; --ink: #efe6d2; --ink-soft: #aaa3bf;
  --btn: #34374c; --btn-edge: #0e0f17; --btn-drop: #0e0f17; --btn-down: #2b2e40;
  --panel: #272939; --scrim: rgba(8, 8, 14, 0.6);
}
*, *::before, *::after { box-sizing: inherit; }
[hidden] { display: none !important; }
html { font-synthesis: none; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
html { height: 100%; scroll-padding-top: env(safe-area-inset-top, 0px); }
body {
  height: 100%; margin: 0; background: var(--bg); color: var(--ink);
  font-family: var(--font); overflow: hidden;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
}
button { font-family: inherit; color: inherit; cursor: pointer; }
button:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
svg { display: block; shape-rendering: crispEdges; }

#app {
  height: calc(100% - var(--tb)); max-width: 760px; margin: 0 auto;
  display: flex; flex-direction: column;
  padding: 0 max(10px, env(safe-area-inset-right, 0px)) 0 max(10px, env(safe-area-inset-left, 0px));
}

/* top bar */
.bar { display: flex; align-items: center; gap: 8px; padding: 10px 0 8px; }
.stage-title { flex: 1; min-width: 0; display: flex; align-items: baseline; gap: 10px; white-space: nowrap; overflow: hidden; }
#stId { font-size: 15px; color: var(--ink-soft); letter-spacing: 0.05em; }
#stName { font-size: 19px; overflow: hidden; text-overflow: ellipsis; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  height: 36px; padding: 0 11px; font-size: 14px;
  background: var(--btn); border: 2px solid var(--btn-edge);
  box-shadow: 0 3px 0 var(--btn-drop);
  clip-path: polygon(2px 0, calc(100% - 2px) 0, 100% 2px, 100% calc(100% - 2px), calc(100% - 2px) 100%, 2px 100%, 0 calc(100% - 2px), 0 2px);
}
.chip:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--btn-drop); }
.chip:disabled { opacity: 0.4; cursor: default; }
.chip.icon { width: 40px; padding: 0; justify-content: center; }
@media (max-width: 420px) {
  #btnReset .txt { display: none; }
  #btnReset { width: 40px; padding: 0; justify-content: center; }
  #stName { font-size: 17px; }
}
.chip svg { width: 16px; height: 16px; fill: currentColor; }

/* screen */
.stage { flex: 1; min-height: 0; display: flex; flex-direction: column; }
#screen { flex: 1; min-height: 0; position: relative; display: flex; align-items: center; justify-content: center; }
.frame { position: relative; line-height: 0; border: 3px solid var(--btn-edge); box-shadow: 0 5px 0 var(--btn-drop); }
#cv { display: block; image-rendering: pixelated; image-rendering: crisp-edges; width: 192px; height: 160px; touch-action: none; cursor: grab; }
#cv:active { cursor: grabbing; }
#hint {
  margin: 12px auto 4px; max-width: 34em; min-height: 2.8em;
  font-size: 14px; line-height: 1.4; color: var(--ink-soft); text-align: center; text-wrap: balance;
}

#toast {
  position: absolute; left: 50%; top: 44px; transform: translate(-50%, -6px);
  background: var(--ink); color: var(--bg); font-size: 13px; line-height: 1.2; padding: 6px 10px;
  opacity: 0; transition: opacity .15s, transform .15s; pointer-events: none; white-space: nowrap;
}
#toast.on { opacity: 1; transform: translate(-50%, 0); }

/* overlays on the screen */
.over {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px; text-align: center; line-height: 1.3; padding: 12px;
}
.over[hidden] { display: none; }
#overlay { background: var(--scrim); color: #fff7ea; }
#overlay[data-kind="clear"] { background: transparent; justify-content: flex-start; padding-top: 16%; }
#overlay[data-kind="clear"] p { text-shadow: 1px 1px 0 var(--btn-edge); }
#overlay h2 { margin: 0; font-size: 26px; font-weight: 400; text-shadow: 2px 2px 0 var(--btn-edge); }
#overlay p { margin: 0 0 6px; font-size: 14px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.big {
  min-width: 132px; height: 46px; padding: 0 16px; font-size: 17px;
  background: var(--btn); color: var(--ink); border: 2px solid var(--btn-edge); box-shadow: 0 4px 0 var(--btn-drop);
  clip-path: polygon(3px 0, calc(100% - 3px) 0, 100% 3px, 100% calc(100% - 3px), calc(100% - 3px) 100%, 3px 100%, 0 calc(100% - 3px), 0 3px);
}
.big.primary { background: var(--accent); color: var(--accent-ink); box-shadow: 0 4px 0 var(--accent-drop); }
.big:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--btn-drop); }

#title { background: linear-gradient(to bottom, rgba(46,43,79,0.0) 30%, rgba(46,43,79,0.42)); color: #fffaf0; gap: 6px; justify-content: center; }
#title .t-kids { display: block; line-height: 0; margin-bottom: 2px; }
#title .t-kids img { width: min(200px, 56%); height: auto; }
#title .logo { margin: 0; line-height: 0; }
#logoCv { display: block; image-rendering: pixelated; image-rendering: crisp-edges; cursor: pointer; touch-action: manipulation; }
#title .sub { margin: 2px 0 10px; font-size: 14px; text-shadow: 1px 1px 0 var(--btn-edge), 0 0 6px rgba(46,43,79,.5); word-break: keep-all; }
#title .t-btns { display: flex; flex-direction: column; align-items: center; gap: 10px; }
#title .t-btns > .big.primary { min-width: 200px; }
#title .row .big { min-width: 0; padding: 0 14px; }
#title .t-foot { position: absolute; left: 0; right: 0; bottom: 8px; margin: 0; padding: 0 10px; display: flex; flex-wrap: wrap; justify-content: center; gap: 0 12px;
  font-size: 11px; line-height: 1.8; color: #fffaf0; text-shadow: 1px 1px 0 var(--btn-edge), 0 0 4px rgba(46,43,79,.6); }
#title .t-foot a { color: inherit; }
#title.t-in .t-foot { animation-delay: 3.1s; }
body.ogp #title .t-foot { display: none; }
.big.daily { display: inline-flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.1; }
.big.daily small { font-size: 11px; color: var(--ink-soft); }
.big.daily small:empty { display: none; }
#title.t-in > * { animation: tIn .5s steps(5, end) both; }
#title.t-in .t-kids { animation-delay: .05s; } #title.t-in .logo { animation: none; }
#title.t-in .sub { animation-delay: 2.6s; } #title.t-in .t-btns { animation-delay: 2.9s; }
@keyframes tIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { #title.t-in > * { animation: none; } }

/* entry gate */
#gate { position: fixed; inset: 0; bottom: var(--tb); z-index: 20; display: flex; align-items: center; justify-content: center; background: #2e2b4f; color: #fffaf0; cursor: default; }
#gate.ready { cursor: pointer; }
#gate .g-in { display: flex; flex-direction: column; align-items: center; gap: 18px; padding: 16px; }
#gate .g-kids { width: min(220px, 60vw); height: auto; margin-bottom: 8px; }
#gCv { display: block; image-rendering: pixelated; image-rendering: crisp-edges; }
.g-msg { margin: 0; min-height: 1.4em; font-size: 15px; letter-spacing: .12em; color: #aaa3bf; }
.g-msg::after { content: ''; display: inline-block; width: 1.5em; text-align: left; animation: gDots 1.2s steps(4, end) infinite; }
@keyframes gDots { 0% { content: ''; } 25% { content: '.'; } 50% { content: '..'; } 75% { content: '...'; } }
.g-start { min-width: 220px; height: 52px; padding: 0 18px; font-size: 18px; letter-spacing: .08em;
  background: var(--accent); color: var(--accent-ink); border: 3px solid #fffaf0; box-shadow: 0 5px 0 var(--accent-drop);
  clip-path: polygon(3px 0, calc(100% - 3px) 0, 100% 3px, 100% calc(100% - 3px), calc(100% - 3px) 100%, 3px 100%, 0 calc(100% - 3px), 0 3px);
  animation: gBlink 1.1s steps(2, jump-none) infinite; }
.g-start:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--accent-drop); }
@keyframes gBlink { 50% { filter: brightness(1.18); } }
#gate .chip { color: var(--ink); }
@media (prefers-reduced-motion: reduce) { .g-start, .g-msg::after { animation: none; } }

#overlay .stars { font-size: 26px; letter-spacing: .12em; color: #ffd23f; text-shadow: 2px 2px 0 var(--btn-edge); }
#overlay .perfect { display: inline-block; margin-bottom: 4px; padding: 2px 10px; background: #ffd23f; color: var(--ink); font-size: 14px; text-shadow: none; }
.is-daily #stId { color: var(--accent); }

#wcard { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; line-height: 1.3; pointer-events: none;
  background: rgba(46,43,79,.72); color: #fffaf0; animation: wcard 2.1s steps(12, end) both; }
#wcard .wn { font-size: 15px; letter-spacing: .3em; margin-right: -.3em; color: #aee3ff; }
#wcard .wt { font-size: 30px; letter-spacing: .2em; margin-right: -.2em; text-shadow: 3px 3px 0 var(--btn-edge); }
@keyframes wcard { 0% { opacity: 0; clip-path: inset(48% 0 48% 0); } 18% { opacity: 1; clip-path: inset(0 0 0 0); } 78% { opacity: 1; clip-path: inset(0 0 0 0); } 100% { opacity: 0; clip-path: inset(0 0 0 0); } }
@media (prefers-reduced-motion: reduce) { #wcard { animation-timing-function: linear; } }

#endLines .roll { animation: roll 9.6s linear both; text-align: center; }
#endLines .cr { margin: 0 0 22px; font-size: 16px; line-height: 1.5; text-shadow: 1px 1px 0 var(--btn-edge), 0 0 6px rgba(42,33,64,.6); }
#endLines .cr small { display: block; font-size: 12px; color: #d8e9ff; }
#endLines .cr.big { font-size: 24px; letter-spacing: .12em; }
@keyframes roll { 0% { transform: translateY(120px); opacity: 0; } 8% { opacity: 1; } 88% { opacity: 1; } 100% { transform: translateY(-140px); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { #endLines .roll { animation: none; } }

/* OGP 撮影（?ogp=1） */
body.ogp .bar, body.ogp .pad, body.ogp .hint-row, body.ogp #toast, body.ogp #wcard { display: none !important; }
body.ogp { background: #3f78bf; }
body.ogp #app { max-width: none; padding: 0; height: 100%; }
body.ogp .stage, body.ogp #screen { position: fixed; inset: 0; }
body.ogp .frame { border: 0; box-shadow: none; }
body.ogp #title { background: none; pointer-events: none; padding-bottom: 150px; }
body.ogp #title .sub, body.ogp #title .t-btns, body.ogp #title .t-kids { display: none; }
body.ogp #title > * { animation: none !important; }

/* 外側の装飾（js の drawDeco） */
#deco { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 0; pointer-events: none; image-rendering: pixelated; image-rendering: crisp-edges; }
#app { position: relative; z-index: 1; }

/* しらべる */
#info { position: absolute; left: 8px; right: 8px; bottom: 8px; display: flex; flex-direction: column; gap: 3px; padding: 9px 12px 10px;
  background: rgba(46,43,79,.92); color: #fffaf0; border: 2px solid #fffaf0; line-height: 1.45; text-align: left; cursor: pointer;
  clip-path: polygon(3px 0, calc(100% - 3px) 0, 100% 3px, 100% calc(100% - 3px), calc(100% - 3px) 100%, 3px 100%, 0 calc(100% - 3px), 0 3px);
  animation: infoIn .18s steps(3, end) both; }
#info.top { bottom: auto; top: 44px; }
#info b { font-weight: 400; font-size: 15px; color: #aee3ff; }
#info span { font-size: 13px; word-break: keep-all; overflow-wrap: anywhere; }
#info span:empty { display: none; }
@keyframes infoIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
body.ogp #info { display: none !important; }

/* hint row */
.hint-row { display: flex; align-items: center; justify-content: center; gap: 10px; margin: 10px auto 2px; min-height: 2.8em; max-width: 36em; }
.hint-row #hint { margin: 0; min-height: 0; }
.hint-row #hint:empty { display: none; }
#hintBtn { flex: none; }
.menu-credit { margin: 26px 0 0; font-size: 12px; color: var(--ink-soft); line-height: 1.9; display: flex; flex-wrap: wrap; gap: 0 14px; }
.menu-credit a { color: inherit; }

/* pad */
.pad { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; padding: 6px 0 14px; }
.pad .grp { display: flex; gap: 10px; }
.pad button {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  width: 76px; height: 76px; background: var(--btn); border: 3px solid var(--btn-edge); box-shadow: 0 5px 0 var(--btn-drop);
  clip-path: polygon(3px 0, calc(100% - 3px) 0, 100% 3px, 100% calc(100% - 3px), calc(100% - 3px) 100%, 3px 100%, 0 calc(100% - 3px), 0 3px);
  touch-action: none; font-size: 12px; line-height: 1;
}
.pad button svg { width: 30px; height: 30px; fill: currentColor; }
.pad button.down, .pad button:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--btn-drop); background: var(--btn-down); }
.pad .act button { width: 92px; }
#bA { background: var(--accent); color: var(--accent-ink); box-shadow: 0 5px 0 var(--accent-drop); }
#bA.down, #bA:active { box-shadow: 0 1px 0 var(--accent-drop); background: var(--accent); filter: brightness(0.92); }
#bA .i-side { display: none; }
#bA[data-mode="side"] .i-side { display: block; }
#bA[data-mode="side"] .i-down { display: none; }
#bU[aria-pressed="true"] { background: var(--ink); color: var(--bg); }
#bU[aria-pressed="true"] svg { fill: var(--accent); }
.key { display: none; position: absolute; top: 5px; right: 6px; font-size: 11px; opacity: .6; }
@media (hover: hover) and (pointer: fine) { .key { display: block; } }
.pulse { animation: pulse 1.1s steps(2, jump-none) infinite; }
@keyframes pulse { 50% { outline: 3px solid var(--accent); outline-offset: 3px; } }
#bA.pulse { animation-name: pulseA; }
@keyframes pulseA { 50% { outline: 3px solid var(--ink); outline-offset: 3px; } }
body[data-mode="title"] .pad, body[data-mode="title"] .bar .chip:not(#btnMenu) { opacity: 0.35; pointer-events: none; }
body[data-mode="title"] .stage-title, body[data-mode="title"] .hint-row { visibility: hidden; }
body[data-mode="ending"] .pad, body[data-mode="ending"] .bar .chip:not(#btnMenu) { opacity: 0.35; pointer-events: none; }
body[data-mode="ending"] #btnMenu { pointer-events: none; opacity: .35; }
#ending { justify-content: flex-start; padding-top: 14%; color: #fffaf0; background: linear-gradient(to bottom, rgba(42,33,64,0.35), rgba(42,33,64,0)); pointer-events: none; }
#ending #endFin { pointer-events: auto; display: flex; flex-direction: column; align-items: center; gap: 8px; }
#ending #endFin[hidden] { display: none; }
#endLines { padding: 0 14px; }
#endLines p { margin: 0 0 10px; font-size: 16px; line-height: 1.5; text-wrap: balance; line-break: strict; text-shadow: 1px 1px 0 var(--btn-edge), 0 0 6px rgba(42,33,64,.6); animation: lineIn 1.2s ease-out both; }
@keyframes lineIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
#ending .fin { margin: 0; font-size: 34px; font-weight: 400; letter-spacing: .2em; margin-right: -.2em; text-shadow: 3px 3px 0 var(--btn-edge); }
#endStats, #ending .thanks { margin: 0; font-size: 14px; text-shadow: 1px 1px 0 var(--btn-edge); }
.st.locked { opacity: .45; box-shadow: none; cursor: default; }
.st.locked .t { color: var(--ink-soft); }
@media (prefers-reduced-motion: reduce) { #endLines p { animation: none; } }

/* stage menu */
#menu { position: fixed; inset: 0; z-index: 10; background: var(--bg); overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: calc(env(safe-area-inset-top, 0px) + 14px) max(16px, env(safe-area-inset-right, 0px)) calc(env(safe-area-inset-bottom, 0px) + 24px) max(16px, env(safe-area-inset-left, 0px)); }
#menu[hidden] { display: none; }
.menu-in { max-width: 560px; margin: 0 auto; }
.menu-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.menu-head h2 { margin: 0; font-weight: 400; font-size: 22px; }
#stageList h3 { margin: 22px 0 10px; font-size: 15px; font-weight: 400; color: var(--ink-soft); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.st {
  position: relative; text-align: left; display: grid; grid-template-columns: auto 1fr; column-gap: 10px; row-gap: 2px; align-items: baseline;
  padding: 12px 26px 12px 12px; background: var(--btn); border: 2px solid var(--btn-edge); box-shadow: 0 4px 0 var(--btn-drop);
  clip-path: polygon(3px 0, calc(100% - 3px) 0, 100% 3px, 100% calc(100% - 3px), calc(100% - 3px) 100%, 3px 100%, 0 calc(100% - 3px), 0 3px);
}
.st:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--btn-drop); }
.st .n { font-size: 13px; color: var(--ink-soft); }
.st .t { font-size: 16px; }
.st .b { grid-column: 2; font-size: 12px; color: var(--ink-soft); }
.st .fi { position: absolute; right: 10px; top: 10px; width: 14px; height: 14px; }
.st.cur { border-color: var(--accent); }
.menu-foot { margin-top: 26px; display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; font-size: 13px; color: var(--ink-soft); line-height: 1.6; }
.keys { display: none; }
@media (hover: hover) and (pointer: fine) { .keys { display: block; } }

/* landscape phones: controls beside the screen */
@media (orientation: landscape) and (max-height: 520px) {
  #app { max-width: none; display: grid; grid-template-columns: auto 1fr auto; grid-template-rows: auto 1fr; column-gap: 14px; }
  .bar { grid-column: 1 / -1; padding: 6px 0 4px; }
  .stage { grid-column: 2; grid-row: 2; }
  #hint { min-height: 0; margin: 6px auto 6px; font-size: 12px; }
  .pad { display: contents; }
  .pad .grp { grid-row: 2; align-self: end; padding-bottom: 14px; }
  .pad .move { grid-column: 1; }
  .pad .act { grid-column: 3; flex-direction: column-reverse; }
}
@media (prefers-reduced-motion: reduce) { .pulse, #bA.pulse { animation: none; outline: 3px solid var(--accent); outline-offset: 3px; } }
