* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #222; }
body {
  font-family: "Hiragino Maru Gothic ProN", "Hiragino Sans", "Yu Gothic", "Meiryo", sans-serif;
  color: #2a2a33; -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent;
}
#c { position: fixed; inset: 0; display: block; touch-action: none; cursor: none; }
button { font: inherit; cursor: pointer; }

/* 上の数字 */
#hud {
  position: fixed; left: 0; right: 0; top: 0; z-index: 5;
  display: grid; grid-template-columns: 1fr auto; grid-template-areas: 'mass btns' 'stage stage'; gap: 4px 12px; align-items: center;
  padding: 8px 10px calc(8px); padding-top: max(8px, env(safe-area-inset-top));
  background: rgba(255, 253, 246, 0.94); border-bottom: 3px solid #2a2a33;
}
.label { font-size: 11px; color: #6a6a74; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.label b { color: #2a2a33; font-size: 13px; }
#kasu { font-size: 24px; font-weight: 800; letter-spacing: -0.5px; white-space: nowrap; transform-origin: left center; }
#kasu.bump { animation: bump 0.18s ease-out; }
@keyframes bump { 0% { transform: scale(1.12); color: #e0302e; } 100% { transform: scale(1); } }
#rate { font-size: 11px; color: #4b4bd0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.massbox { grid-area: mass; min-width: 0; }
.stagebox { grid-area: stage; min-width: 0; display: grid; grid-template-columns: auto 1fr; gap: 0 10px; align-items: center; }
.stagebox .label { grid-column: 1 / 3; }
.stagebox #effects { grid-column: 1 / 3; }
.btns { grid-area: btns; }
.stname { font-size: 15px; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar { height: 10px; background: #e4e0d4; border: 2px solid #2a2a33; border-radius: 6px; overflow: hidden; margin: 3px 0; }
.bar i { display: block; height: 100%; width: 0; background: repeating-linear-gradient(-45deg, #f39a2b 0 8px, #ffb14e 8px 16px); transition: width 0.15s; }
#effects { display: flex; flex-wrap: wrap; gap: 4px; }
#effects span { white-space: nowrap; font-size: 10px; background: #2a2a33; color: #fff; border-radius: 8px; padding: 1px 7px; }
.btns { display: flex; gap: 6px; align-self: start; }
.btns button { font-size: 11px; padding: 3px 8px; border: 2px solid #2a2a33; border-radius: 8px; background: #fff; }

/* 店(スマホは下、PC は右) */
#shop {
  position: fixed; left: 0; right: 0; bottom: 0; height: 38vh; z-index: 5; overflow-y: auto;
  background: rgba(255, 253, 246, 0.97); border-top: 3px solid #2a2a33;
  padding: 6px 10px calc(10px + env(safe-area-inset-bottom));
  -webkit-overflow-scrolling: touch; touch-action: pan-y;
}
.shophead { display: flex; align-items: center; justify-content: space-between; gap: 6px; position: sticky; top: -6px; background: rgba(255,253,246,0.97); padding: 4px 0; z-index: 1; }
.shophead h2 { margin: 0; font-size: 15px; }
#buymode { display: flex; gap: 4px; }
#buymode button { font-size: 12px; padding: 3px 9px; border: 2px solid #2a2a33; border-radius: 8px; background: #fff; }
#buymode button.on { background: #2a2a33; color: #fff; }
#shop h3 { font-size: 12px; margin: 8px 0 4px; color: #6a6a74; }
.item {
  display: grid; grid-template-columns: 1fr auto; gap: 0 8px; width: 100%; text-align: left;
  border: 2px solid #b8b4a8; border-radius: 10px; background: #f1eee6; padding: 6px 9px; margin-bottom: 5px; color: #8a8a90;
}
.item.can { border-color: #2a2a33; background: #fff; color: #2a2a33; box-shadow: 0 3px 0 #2a2a33; }
.item.can:active { transform: translateY(2px); box-shadow: 0 1px 0 #2a2a33; }
.item.maxed { opacity: 0.6; }
.item .nm { font-weight: 800; font-size: 14px; }
.item .ct { font-size: 12px; text-align: right; }
.item .ds { font-size: 11px; grid-column: 1; line-height: 1.35; min-height: 2.7em; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.pairhead { font-size: 11px; font-weight: 800; color: #b0451a; margin: 8px 0 3px; }
.item.pair { border-left-width: 6px; border-left-color: #f39a2b; }
.item.maxed .cs { color: #8a8a90; }
.item.picked { opacity: 1; background: #fff4e0; color: #2a2a33; border-color: #f39a2b; }
.item.picked .ct { color: #c0601a; font-weight: 800; }
.item .cs { font-size: 12px; font-weight: 700; text-align: right; align-self: end; white-space: nowrap; }
.item.can .cs { color: #c0601a; }
.item.locked { border-style: dashed; }
#erased { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 8px; }
#erased span, #erased button { font-size: 11px; border-radius: 8px; padding: 2px 7px; border: 1.5px solid #b8b4a8; color: #8a8a90; background: transparent; }
#erased button.done { cursor: pointer; background: #fff; }
#erased .done { text-decoration: line-through; text-decoration-thickness: 2px; color: #2a2a33; border-color: #2a2a33; }
#erased .now { background: #f39a2b; color: #fff; border-color: #f39a2b; }

@media (min-width: 820px) {
  #shop { top: 0; left: auto; width: 360px; height: auto; border-top: 0; border-left: 3px solid #2a2a33; padding-top: 10px; }
  #hud { right: 360px; padding: 12px 18px; }
  #kasu { font-size: 34px; }
  #rate { font-size: 13px; }
  .label { font-size: 13px; }
  .label b { font-size: 16px; }
  .item .nm { font-size: 15px; }
}

/* UI を隠す(H) */
body.hideui #hud, body.hideui #shop { display: none; }
#showBtn { position: fixed; top: 0; right: 0; width: 56px; height: 56px; opacity: 0; border: 0; background: transparent; z-index: 6; display: none; }
body.hideui #showBtn { display: block; }

/* 重力を消したあと: UI がふわふわ浮く */
body.nogravity #hud { animation: floaty 3.2s ease-in-out infinite; }
body.nogravity #shop .item:nth-child(odd) { animation: floaty 2.6s ease-in-out infinite; }
body.nogravity #shop .item:nth-child(even) { animation: floaty 3.4s ease-in-out infinite reverse; }
@keyframes floaty { 0%, 100% { transform: translateY(0) rotate(0); } 50% { transform: translateY(-5px) rotate(-0.6deg); } }

/* ひと言 */
#toast { position: fixed; left: 50%; top: 22%; transform: translateX(-50%); z-index: 8; width: min(92vw, 520px); pointer-events: none; display: flex; flex-direction: column; gap: 6px; align-items: center; }
.toastItem { background: #2a2a33; color: #fff; border-radius: 12px; padding: 9px 14px; font-size: 14px; font-weight: 700; text-align: center; animation: tin 0.25s ease-out; transition: opacity 0.4s, transform 0.4s; }
.toastItem.out { opacity: 0; transform: translateY(-10px); }
@keyframes tin { from { opacity: 0; transform: translateY(10px) scale(0.95); } }

#effects span.fz { background: #f6b21e; color: #2a2a33; font-weight: 800; }
#note { position: fixed; inset: 0; z-index: 9; display: flex; align-items: center; justify-content: center; background: rgba(20, 20, 26, 0.45); }
#note[hidden] { display: none; }
#modal { position: fixed; inset: 0; z-index: 9; display: flex; align-items: center; justify-content: center; background: rgba(20, 20, 26, 0.45); }
#modal[hidden] { display: none; }
.card {
  position: relative; width: min(90vw, 460px); background: #fffdf6; border: 4px solid #2a2a33; border-radius: 16px;
  padding: 30px 22px 18px; text-align: center; box-shadow: 0 8px 0 #2a2a33; animation: cardin 0.35s cubic-bezier(.2, 1.6, .4, 1);
}
@keyframes cardin { from { transform: scale(0.6) rotate(-6deg); opacity: 0; } }
.stamp {
  position: absolute; right: 14px; top: -26px; font-size: 30px; font-weight: 900; color: #e0302e; border: 5px solid #e0302e; border-radius: 10px;
  padding: 2px 12px; transform: rotate(12deg); background: #fffdf6; animation: stamp 0.45s 0.15s cubic-bezier(.3, 1.8, .5, 1) both;
}
@keyframes stamp { from { transform: scale(3) rotate(30deg); opacity: 0; } }
.gone { font-size: 30px; font-weight: 900; text-decoration: line-through; text-decoration-color: #e0302e; text-decoration-thickness: 5px; }
.msg { font-size: 18px; font-weight: 700; line-height: 1.6; margin: 14px 0 10px; }
.next { font-size: 13px; color: #6a6a74; }
.tap { font-size: 16px; font-weight: 800; margin-top: 8px; padding: 8px 26px; border: 3px solid #2a2a33; border-radius: 12px; background: #f39a2b; color: #fff; box-shadow: 0 4px 0 #2a2a33; }
.tap:disabled { opacity: 0.4; }
@keyframes blink { 50% { opacity: 0.3; } }

#ending, #title { position: fixed; inset: 0; z-index: 10; display: flex; align-items: center; justify-content: center; background: #fff; }
#ending[hidden], #title[hidden] { display: none; }
#title { background: rgba(255, 253, 246, 0.9); }
.endcard, .titlecard { width: min(90vw, 520px); text-align: center; padding: 20px; }
.endcard h1 { font-size: 34px; margin: 0 0 12px; animation: tin 1.2s ease-out; }
.endcard p { font-size: 17px; line-height: 1.7; margin: 8px 0; }
.endcard dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; text-align: left; font-size: 14px; margin: 18px auto; max-width: 420px; }
.endcard dt { color: #6a6a74; }
.endcard dd { margin: 0; font-weight: 800; word-break: break-all; }
#endArt { display: block; margin: 0 auto 4px; max-width: 100%; }
.endcard h2 { font-size: 18px; margin: 14px 0 0; }
.endcard h3 { font-size: 14px; margin: 10px 0 6px; color: #6a6a74; }
#perks { display: grid; gap: 8px; }
.perk { text-align: left; border: 3px solid #2a2a33; border-radius: 12px; background: #fff; padding: 8px 12px; box-shadow: 0 4px 0 #2a2a33; }
.perk b { display: block; font-size: 16px; color: #c0601a; }
.perk span { font-size: 13px; color: #2a2a33; }
.perk:active { transform: translateY(2px); box-shadow: 0 2px 0 #2a2a33; }
.route { margin-top: 18px; line-height: 1.6; }
#ending { overflow-y: auto; align-items: flex-start; }
.endcard { margin: auto; }
#rebirthBtn, #startBtn { font-size: 18px; font-weight: 800; padding: 12px 22px; border: 3px solid #2a2a33; border-radius: 14px; background: #f39a2b; color: #fff; box-shadow: 0 5px 0 #2a2a33; }
#rebirthBtn:active, #startBtn:active { transform: translateY(3px); box-shadow: 0 2px 0 #2a2a33; }
.small { font-size: 13px; color: #6a6a74; }
.titlecard h1 { font-size: 64px; margin: 0; letter-spacing: 4px; transform: rotate(-3deg); }
.titlecard p { font-size: 16px; }

/* 消し終わりのひと言を、閉じたあとも残す(タップで閉じる) */
.toastItem.memo { pointer-events: auto; background: #fffdf6; color: #2a2a33; border: 3px solid #e0302e; box-shadow: 0 4px 0 #2a2a33; display: flex; flex-direction: column; gap: 2px; max-width: 100%; }
.toastItem.memo b { font-size: 12px; color: #e0302e; text-decoration: line-through; text-decoration-thickness: 2px; }
.toastItem.memo span { font-size: 15px; line-height: 1.5; }
.toastItem.memo small { font-size: 10px; color: #8a8a90; font-weight: 400; }

/* 店: 強化の効き目 */
.item .cs { display: flex; flex-direction: column; align-items: flex-end; }
.item .ef { font-size: 11px; font-weight: 800; color: #2a8a4a; }
.item .ef:empty { display: none; }
.item.maxed .ef { color: #8a8a90; }

/* 2択が買えるときの印 */
#pairBadge { font-size: 11px; font-weight: 800; padding: 3px 8px; border: 2px solid #b0451a; border-radius: 10px; background: #f39a2b; color: #fff; animation: pairpulse 1.1s ease-in-out infinite; white-space: nowrap; }
#pairBadge[hidden] { display: none; }
@keyframes pairpulse { 50% { transform: scale(1.07); background: #e0702a; } }
.item.pair.can { animation: pairglow 1.4s ease-in-out infinite; }
@keyframes pairglow { 50% { box-shadow: 0 3px 0 #2a2a33, 0 0 0 4px rgba(243, 154, 43, 0.55); } }

/* エンディング: 共有 */
#shareBtn { font-size: 16px; font-weight: 800; margin: 6px 0 4px; padding: 10px 22px; border: 3px solid #2a2a33; border-radius: 14px; background: #fff; color: #2a2a33; box-shadow: 0 4px 0 #2a2a33; }
#shareBtn:active { transform: translateY(2px); box-shadow: 0 2px 0 #2a2a33; }
