:root {
  --ink: #1b2747; --ink2: #3c4d78; --coral: #ff6a55; --gold: #ffc53d; --ice: #8fd3ff; --paper: rgba(255, 255, 255, .78);
  --font: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #cfdcef; font-family: var(--font); color: var(--ink); user-select: none; -webkit-user-select: none; touch-action: none; }
#app canvas { display: block; position: fixed; inset: 0; width: 100vw; height: 100vh; }
button { font-family: inherit; border: 0; cursor: pointer; color: inherit; background: none; padding: 0; }
.layer { position: fixed; inset: 0; pointer-events: none; opacity: 0; visibility: hidden; transition: opacity .35s, visibility 0s .35s; }
.layer.on { opacity: 1; visibility: visible; transition: opacity .35s; }
.layer.on > * { pointer-events: auto; }

/* ---------- タイトル ---------- */
#title { display: flex; flex-direction: column; align-items: center; justify-content: space-between; padding: max(4vh, env(safe-area-inset-top)) 16px max(4vh, env(safe-area-inset-bottom)); }
#title::before { content: ""; position: absolute; inset: 0; background: linear-gradient(180deg, rgba(20, 35, 75, .18), transparent 30%, transparent 55%, rgba(20, 35, 75, .35)); pointer-events: none; }
.logo { position: relative; display: flex; align-items: center; gap: 14px; margin-top: 2vh; animation: logoIn .9s cubic-bezier(.2, 1.4, .4, 1) both; pointer-events: none !important; }
.logoBall { width: clamp(64px, 11vw, 120px); filter: drop-shadow(0 6px 0 #29407a) drop-shadow(0 14px 18px rgba(20, 30, 70, .35)); animation: roll 6s linear infinite; }
.lt { display: flex; flex-direction: column; line-height: .9; }
.l1 { font-size: clamp(56px, 11vw, 132px); font-weight: 900; letter-spacing: -.02em; color: #fff;
  text-shadow: 0 3px 0 #cfe0f7, 0 6px 0 #29407a, 0 7px 0 #29407a, 0 14px 22px rgba(15, 25, 60, .45); -webkit-text-stroke: 1.5px #29407a; paint-order: stroke fill; }
.l2 { font-size: clamp(18px, 3.3vw, 38px); font-weight: 900; letter-spacing: .55em; color: #29407a; margin-top: 6px; padding-left: 4px; text-shadow: 0 2px 0 rgba(255, 255, 255, .7); }
@keyframes logoIn { from { transform: translateY(-40px) scale(.9); opacity: 0; } }
@keyframes roll { to { transform: rotate(360deg); } }

#cards { position: relative; display: flex; gap: clamp(10px, 1.6vw, 20px); margin-top: auto; flex-wrap: nowrap; }
.card { position: relative; width: clamp(150px, 21vw, 230px); height: clamp(170px, 25vh, 230px); border-radius: 18px; overflow: hidden; text-align: left;
  background: linear-gradient(170deg, var(--c1), var(--c2) 55%, var(--c3)); box-shadow: 0 0 0 3px rgba(255, 255, 255, .55), 0 10px 0 #22345f, 0 18px 30px rgba(15, 25, 60, .35);
  transform: translateY(0); transition: transform .25s cubic-bezier(.2, 1.4, .4, 1), box-shadow .25s; animation: cardIn .6s cubic-bezier(.2, 1.3, .4, 1) both; }
.card:nth-child(2) { animation-delay: .07s; } .card:nth-child(3) { animation-delay: .14s; }
@keyframes cardIn { from { transform: translateY(60px); opacity: 0; } }
.card.sel { transform: translateY(-12px); box-shadow: 0 0 0 4px #fff, 0 0 0 8px var(--coral), 0 18px 0 #22345f, 0 26px 40px rgba(15, 25, 60, .45); }
.card:hover:not(.sel):not(.locked) { transform: translateY(-5px); }
.card .mt { position: absolute; left: 0; right: 0; bottom: 0; width: 100%; height: 58%; }
.card .mt polygon { fill: rgba(255, 255, 255, .92); }
.card .no { position: absolute; top: 10px; right: 14px; font-size: 40px; font-weight: 900; color: rgba(255, 255, 255, .45); font-family: Georgia, serif; font-style: italic; }
.card .nm { position: absolute; top: 14px; left: 14px; font-size: clamp(17px, 2vw, 23px); font-weight: 900; color: #fff; text-shadow: 0 2px 0 rgba(20, 35, 80, .5); }
.card .len { position: absolute; top: 44px; left: 15px; font-size: 12px; font-weight: 800; color: rgba(255, 255, 255, .85); }
.card .len b { font-size: 16px; margin-right: 1px; }
.card .st { position: absolute; left: 12px; bottom: 40px; display: flex; gap: 3px; }
.card .best { position: absolute; left: 14px; bottom: 12px; font-size: 13px; font-weight: 800; color: var(--ink2); }
.card .best span { font-size: 10px; letter-spacing: .15em; margin-right: 6px; color: #7d8bb0; }
.card .best b { font-size: 19px; color: var(--ink); margin-right: 1px; }
.card.locked { filter: saturate(.35) brightness(.8); cursor: not-allowed; }
.card .lk { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; background: rgba(20, 30, 60, .45); z-index: 2; }
.card .lk .lock { width: 44px; fill: #fff; filter: drop-shadow(0 3px 0 rgba(0, 0, 0, .3)); }
.card .lk span { display: flex; align-items: center; gap: 4px; padding: 4px 10px; border-radius: 14px; background: rgba(20, 30, 60, .55); }
.card.shake { animation: shake .4s; }
@keyframes shake { 20%, 60% { transform: translateX(-7px); } 40%, 80% { transform: translateX(7px); } }

.star { width: 24px; height: 24px; fill: rgba(30, 45, 90, .22); stroke: rgba(255, 255, 255, .7); stroke-width: 1.2; }
.star.on { fill: var(--gold); stroke: #b9781a; filter: drop-shadow(0 2px 0 #b9781a); }
.star.mini { width: 18px; height: 18px; }

.big { width: 86px; height: 86px; border-radius: 50%; background: var(--coral); box-shadow: 0 0 0 5px #fff, 0 9px 0 5px #22345f, 0 16px 30px rgba(15, 25, 60, .4); display: grid; place-items: center; transition: transform .15s; margin-top: 30px; }
.big svg { width: 42px; fill: #fff; margin-left: 5px; }
.big:hover { transform: scale(1.06); } .big:active { transform: translateY(5px); box-shadow: 0 0 0 5px #fff, 0 4px 0 5px #22345f; }
#goBtn { animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.06); } }
.keys { position: absolute; left: 20px; bottom: 18px; display: flex; gap: 6px; opacity: .85; pointer-events: none !important; }
.kc { min-width: 34px; height: 32px; padding: 0 8px; border-radius: 8px; background: rgba(255, 255, 255, .85); box-shadow: 0 3px 0 #22345f; font-size: 14px; font-weight: 900; display: grid; place-items: center; color: var(--ink); }
.kc.wide { font-size: 11px; letter-spacing: .1em; }
body.touch .keys { display: none; }
@media (hover: none) and (pointer: coarse) { .keys { display: none; } body[data-state="run"] #jumpBtn, body[data-state="intro"] #jumpBtn, body[data-state="goal"] #jumpBtn { display: grid; } }
.mute { width: 46px; height: 46px; border-radius: 50%; background: rgba(255, 255, 255, .85); box-shadow: 0 4px 0 #22345f; display: grid; place-items: center; }
.mute svg { width: 24px; fill: var(--ink); stroke: var(--ink); }
.mute .spk { stroke: none; } .mute .x { display: none; }
.mute.off .wv { display: none; } .mute.off .x { display: block; }
.mute.corner { position: absolute; right: 18px; bottom: 18px; }

/* ---------- HUD ---------- */
#hud { padding: max(14px, env(safe-area-inset-top)) 18px 0; }
#hud > * { pointer-events: none; }
#prog { position: absolute; left: 50%; top: max(16px, env(safe-area-inset-top)); width: min(52vw, 520px); height: 8px; transform: translateX(-50%); border-radius: 8px; background: rgba(27, 39, 71, .25); box-shadow: inset 0 1px 2px rgba(0, 0, 0, .2); }
#progFill { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 8px; background: linear-gradient(90deg, #fff, #dfeaff); }
#progBall { position: absolute; top: 50%; width: 20px; height: 20px; margin: -10px 0 0 -10px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #fff, #dde7f7 60%, #a9bde0); box-shadow: 0 2px 0 #22345f, 0 0 0 2px #fff; }
#prog .flagEnd { position: absolute; right: -8px; top: -12px; width: 14px; height: 24px; background: repeating-conic-gradient(#22283a 0 25%, #fff 0 50%) 0 0 / 7px 7px; border-radius: 2px; box-shadow: 0 0 0 2px #fff; }
#sizeBox { position: absolute; left: max(18px, env(safe-area-inset-left)); top: max(14px, env(safe-area-inset-top)); }
#size { font-weight: 900; color: #fff; font-size: clamp(42px, 6.5vw, 72px); line-height: 1; letter-spacing: -.02em; text-shadow: 0 3px 0 #29407a, 0 4px 0 #29407a, 0 8px 18px rgba(15, 25, 60, .45); -webkit-text-stroke: 1px #29407a; paint-order: stroke fill; transform-origin: 10% 80%; font-variant-numeric: tabular-nums; }
#size .u { font-size: .42em; margin-left: 4px; }
#size.bump { animation: bump .28s cubic-bezier(.2, 2, .4, 1); }
@keyframes bump { 40% { transform: scale(1.12); } }
#gauge { position: relative; width: clamp(180px, 24vw, 280px); height: 10px; margin-top: 12px; border-radius: 10px; background: rgba(27, 39, 71, .3); box-shadow: 0 0 0 2px rgba(255, 255, 255, .7); }
#gFill { position: absolute; left: 0; top: 0; bottom: 0; width: 0; border-radius: 10px; background: linear-gradient(90deg, #cfe3ff, #fff); transition: width .15s; }
#gTicks i { position: absolute; top: 50%; transform: translate(-50%, -50%); display: flex; flex-direction: column; align-items: center; }
#gTicks .star { width: 26px; height: 26px; }
#gTicks em { position: absolute; top: 24px; font-style: normal; font-size: 11px; font-weight: 900; color: #fff; text-shadow: 0 1px 0 #29407a, 0 0 4px rgba(20, 30, 70, .6); }
#gTicks i.pop .star { animation: starPop .6s cubic-bezier(.2, 2, .4, 1); }
@keyframes starPop { 0% { transform: scale(.4) rotate(-40deg); } 50% { transform: scale(1.7) rotate(10deg); } }
#pauseBtn { position: absolute; right: max(16px, env(safe-area-inset-right)); top: max(12px, env(safe-area-inset-top)); width: 48px; height: 48px; border-radius: 50%; background: rgba(255, 255, 255, .8); box-shadow: 0 4px 0 #22345f; display: grid; place-items: center; pointer-events: auto !important; }
#pauseBtn svg { width: 22px; fill: var(--ink); }
#jumpBtn { display: none; position: fixed; right: max(26px, env(safe-area-inset-right)); bottom: max(30px, env(safe-area-inset-bottom)); width: 112px; height: 112px; border-radius: 50%; background: rgba(255, 255, 255, .55); box-shadow: 0 0 0 4px rgba(255, 255, 255, .8), 0 7px 0 4px rgba(34, 52, 95, .7); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); place-items: center; touch-action: none; }
#jumpBtn svg { width: 50px; fill: var(--ink); }
#jumpBtn.down { transform: translateY(5px) scale(.96); box-shadow: 0 0 0 4px #fff, 0 2px 0 4px rgba(34, 52, 95, .7); background: rgba(255, 255, 255, .85); }
body.touch[data-state="run"] #jumpBtn, body.touch[data-state="intro"] #jumpBtn, body.touch[data-state="goal"] #jumpBtn { display: grid; }

/* ---------- パネル ---------- */
.panel { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); min-width: min(440px, 90vw); padding: 34px 34px 30px; border-radius: 28px; background: var(--paper);
  backdrop-filter: blur(14px) saturate(1.3); -webkit-backdrop-filter: blur(14px) saturate(1.3); box-shadow: 0 0 0 3px rgba(255, 255, 255, .8), 0 12px 0 #22345f, 0 24px 60px rgba(15, 25, 60, .45); display: flex; flex-direction: column; align-items: center; gap: 18px; }
#pause { background: rgba(20, 30, 60, .35); }
#pause .big { margin-top: 0; }
.row { display: flex; gap: 12px; }
.pill { height: 54px; padding: 0 26px; border-radius: 30px; background: #fff; font-size: 17px; font-weight: 900; color: var(--ink); box-shadow: 0 0 0 3px #22345f inset, 0 5px 0 #22345f; transition: transform .12s; }
.pill.main { background: var(--coral); color: #fff; box-shadow: 0 0 0 3px #22345f inset, 0 5px 0 #22345f; }
.pill:hover { transform: translateY(-2px); } .pill:active { transform: translateY(4px); box-shadow: 0 0 0 3px #22345f inset, 0 1px 0 #22345f; }
#result { background: radial-gradient(circle at 50% 55%, transparent 20%, rgba(20, 30, 60, .35)); }
#result .panel { animation: panelIn .55s cubic-bezier(.2, 1.4, .4, 1) both; }
@keyframes panelIn { from { transform: translate(-50%, -40%) scale(.85); opacity: 0; } }
#rName { font-size: 16px; font-weight: 900; color: var(--ink2); letter-spacing: .1em; }
.rsize { font-size: clamp(72px, 14vw, 120px); font-weight: 900; line-height: .9; color: #fff; letter-spacing: -.03em; font-variant-numeric: tabular-nums;
  text-shadow: 0 4px 0 #29407a, 0 6px 0 #29407a, 0 12px 26px rgba(15, 25, 60, .4); -webkit-text-stroke: 2px #29407a; paint-order: stroke fill; }
.rsize .u { font-size: .4em; margin-left: 6px; }
#rStars { display: flex; gap: 10px; }
#rStars .star { width: 56px; height: 56px; }
#rStars .star.pop { animation: starPop .6s cubic-bezier(.2, 2, .4, 1); }
.rbest { min-height: 30px; font-weight: 900; opacity: 0; transform: scale(.8); transition: .3s cubic-bezier(.2, 1.8, .4, 1); display: flex; flex-direction: column; align-items: center; gap: 8px; }
.rbest.show { opacity: 1; transform: none; }
.rbest.new b { display: inline-block; padding: 6px 16px; border-radius: 20px; background: var(--gold); color: #5a3a00; letter-spacing: .2em; box-shadow: 0 3px 0 #b9781a; animation: pulse 1.2s infinite; }
.rbest.old { color: var(--ink2); font-size: 18px; } .rbest.old span { font-size: 11px; letter-spacing: .2em; color: #7d8bb0; margin-right: 6px; }
.unlock { display: flex; align-items: center; gap: 6px; padding: 6px 14px; border-radius: 20px; background: #22345f; color: #fff; font-size: 14px; animation: panelIn .5s .2s both; }
.unlock .lock { width: 18px; fill: #fff; }

/* ---------- 画面効果 ---------- */
body::after { content: ""; position: fixed; inset: 0; pointer-events: none; opacity: 0; }
body.flash::after { background: #fff; animation: flash .5s ease-out; }
body.perfect::after { background: radial-gradient(circle at 50% 55%, transparent 40%, rgba(120, 190, 255, .45)); animation: flash .6s ease-out; }
@keyframes flash { 0% { opacity: 1; } 100% { opacity: 0; } }

@media (max-width: 720px) {
  #cards { flex-direction: row; gap: 8px; }
  .card { width: 30vw; height: 170px; border-radius: 14px; }
  .card .nm { font-size: 15px; } .card .no { display: none; }
  .card .st .star { width: 18px; height: 18px; }
  .card .best b { font-size: 15px; }
  .big { width: 76px; height: 76px; }
}
@media (max-height: 500px) {
  .l1 { font-size: 56px; } .logo { margin-top: 0; }
  .card { height: 140px; }
  .big { width: 64px; height: 64px; margin-top: 12px; } .big svg { width: 30px; }
  #title { padding-top: 10px; padding-bottom: 10px; }
}

@media (min-width: 901px) {
  #result .panel { left: auto; right: 7vw; transform: translate(0, -50%); }
  @keyframes panelIn { from { transform: translate(0, -40%) scale(.85); opacity: 0; } }
  #result { background: linear-gradient(90deg, transparent 40%, rgba(20, 30, 60, .3)); }
}
@media (max-width: 600px) {
  #prog { top: auto; bottom: max(28px, env(safe-area-inset-bottom)); left: 24px; transform: none; width: calc(100vw - 190px); }
}
