:root {
  --red: #e0362d;
  --red-d: #a8201a;
  --yellow: #ffd21f;
  --ink: #1d1420;
  --paper: #fff8ec;
  --glass: rgba(20, 12, 22, 0.72);
  --font-title: 'Dela Gothic One', 'M PLUS Rounded 1c', sans-serif;
  --font: 'M PLUS Rounded 1c', 'Hiragino Maru Gothic ProN', 'Meiryo', sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #0b0a10; color: var(--paper); font-family: var(--font); -webkit-user-select: none; user-select: none; }
#c { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; outline: none; }
.hidden { display: none !important; }
button { font-family: inherit; }

/* ---------- 共通パーツ ---------- */
.screen { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; z-index: 20; }
.panel { background: var(--glass); border: 2px solid rgba(255, 255, 255, 0.14); border-radius: 18px; padding: 22px 26px; backdrop-filter: blur(6px); box-shadow: 0 10px 40px rgba(0, 0, 0, 0.45); }
.btn { appearance: none; border: 0; cursor: pointer; color: #fff; background: linear-gradient(#5b4a66, #3a2d44); border-radius: 14px; padding: 12px 22px; font-size: 18px; font-weight: 800; box-shadow: 0 4px 0 #24192b, 0 8px 18px rgba(0, 0, 0, .35); transition: transform .06s, filter .15s; display: inline-flex; flex-direction: column; align-items: center; gap: 2px; line-height: 1.15; }
.btn small { font-size: 12px; font-weight: 400; opacity: .8; }
.btn:hover { filter: brightness(1.12); }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #24192b; }
.btn.primary { background: linear-gradient(#ff5a3c, #d9261b); box-shadow: 0 4px 0 #8e130d, 0 8px 18px rgba(0, 0, 0, .35); }
.btn.small { font-size: 15px; padding: 8px 14px; }
.btn:disabled { opacity: .45; cursor: default; }
.linklike { background: none; border: 0; color: #ffd9a8; text-decoration: underline; cursor: pointer; font-size: 14px; padding: 0; }
kbd { background: #fff; color: #222; border-radius: 5px; padding: 1px 6px; font-family: inherit; font-weight: 800; font-size: .9em; }

/* ---------- タイトル ---------- */
#title { background: radial-gradient(ellipse at 50% 30%, rgba(10, 8, 20, .35), rgba(10, 6, 16, .82)); overflow-y: auto; }
.title-inner { width: min(980px, 94vw); margin: auto; padding: 24px 0 30px; text-align: center; }
.logo { margin: 0; font-family: var(--font-title); font-weight: 400; line-height: 1; letter-spacing: .02em; text-shadow: 0 4px 0 rgba(0, 0, 0, .45), 0 0 30px rgba(255, 90, 40, .35); display: flex; flex-wrap: wrap; justify-content: center; align-items: baseline; gap: .15em .3em; }
.logo span { font-size: clamp(30px, 5.2vw, 56px); color: #fff; }
.logo em { font-style: normal; font-size: clamp(50px, 10vw, 112px); color: var(--red); -webkit-text-stroke: 3px #fff; paint-order: stroke fill; transform: rotate(-3deg); display: inline-block; text-shadow: 0 6px 0 #7d0f0a, 0 0 40px rgba(255, 60, 30, .55); }
.tagline { margin: 10px 0 18px; font-size: clamp(14px, 2vw, 18px); opacity: .9; }

.stages { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 0 auto 14px; }
.stage-card { position: relative; text-align: left; cursor: pointer; border: 3px solid rgba(255, 255, 255, .18); border-radius: 16px; padding: 14px 16px 12px; color: #fff; background: var(--glass); transition: transform .12s, border-color .12s; overflow: hidden; }
.stage-card:hover { transform: translateY(-3px); }
.stage-card.sel { border-color: var(--yellow); box-shadow: 0 0 0 3px rgba(255, 210, 31, .35), 0 10px 28px rgba(0, 0, 0, .5); }
.stage-card .lv { font-family: var(--font-title); font-size: 13px; letter-spacing: .1em; color: var(--yellow); }
.stage-card .nm { font-size: clamp(17px, 2.3vw, 22px); font-weight: 800; margin: 2px 0 4px; }
.stage-card .sb { font-size: 12px; opacity: .85; min-height: 2.4em; }
.stage-card .best { margin-top: 6px; font-size: 12px; color: #ffd9a8; }
.stage-card .stars { color: var(--yellow); letter-spacing: 2px; }
.stage-card::before { content: ''; position: absolute; inset: 0; z-index: -1; opacity: .55; }
.stage-card[data-lv="1"]::before { background: linear-gradient(160deg, #3f8fe0, #4f9f3a); }
.stage-card[data-lv="2"]::before { background: linear-gradient(160deg, #e98a4a, #a4553a); }
.stage-card[data-lv="3"]::before { background: linear-gradient(160deg, #0a1030, #3a3f78); }
.online-ranking { margin: 0 auto 14px; padding: 14px 18px; text-align: left; }
.online-ranking h2 { margin: 0 0 8px; font-family: var(--font-title); font-size: clamp(17px, 2.4vw, 22px); font-weight: 400; color: var(--yellow); }
.ranking-levels { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 6px; }
.ranking-level { min-width: 92px; font-size: 13px; }
.ranking-level[aria-pressed="true"] { background: linear-gradient(#ff5a3c, #d9261b); box-shadow: 0 3px 0 #8e130d; }
.ranking-status { min-height: 1.4em; margin: 4px 0; font-size: 12px; opacity: .85; }
.ranking-scroll { max-height: min(32vh, 280px); overflow: auto; border-radius: 8px; }
.online-ranking .result-table { min-width: 560px; }
.online-ranking .result-table td:last-child { color: #ff9a7a; font-weight: 800; }
.ranking-note { margin: 7px 0 0; font-size: 11px; opacity: .7; }

.menu-row { margin: 6px 0 12px; }
.name-field { font-weight: 700; font-size: 14px; }
.name-field input, .friend-panel input { font-family: inherit; font-size: 16px; padding: 8px 12px; border-radius: 10px; border: 2px solid rgba(255, 255, 255, .25); background: rgba(0, 0, 0, .4); color: #fff; width: 10em; text-align: center; outline: none; }
.name-field input:focus, .friend-panel input:focus { border-color: var(--yellow); }
.menu { display: flex; flex-wrap: wrap; gap: 14px; justify-content: center; }
.menu .btn { min-width: 220px; }
.friend-panel { margin-top: 14px; display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: center; }
.friend-panel input { width: 8em; text-transform: uppercase; letter-spacing: .3em; }
.friend-panel .or { opacity: .7; font-size: 14px; }
.title-msg { min-height: 1.5em; margin: 10px 0 0; color: #ffb3a8; font-weight: 700; }
.links { margin-top: 18px; display: flex; gap: 18px; justify-content: center; flex-wrap: wrap; font-size: 14px; }
.links a { color: #ffd9a8; }

/* ---------- ロビー ---------- */
.lobby-panel { width: min(520px, 92vw); text-align: center; }
.lobby-panel h2, .pause-panel h2 { margin: 0 0 6px; font-family: var(--font-title); font-weight: 400; font-size: 28px; }
.lobby-status { min-height: 1.4em; opacity: .9; margin: 4px 0 10px; }
.lobby-code { display: flex; align-items: baseline; justify-content: center; gap: 12px; margin-bottom: 12px; }
.lobby-code span { font-size: 13px; opacity: .8; }
.lobby-code b { font-family: var(--font-title); font-weight: 400; font-size: 44px; letter-spacing: .18em; color: var(--yellow); }
.lobby-list { list-style: none; padding: 0; margin: 0 0 8px; display: grid; gap: 8px; }
.lobby-list li { display: flex; align-items: center; gap: 12px; background: rgba(255, 255, 255, .08); border-radius: 12px; padding: 10px 14px; font-weight: 700; text-align: left; }
.lobby-list li.empty { opacity: .45; font-weight: 400; }
.lobby-list li .dot { width: 14px; height: 14px; border-radius: 50%; flex: none; }
.lobby-list li .tag { margin-left: auto; font-size: 12px; opacity: .8; }
.lobby-note { font-size: 12px; opacity: .7; margin: 6px 0 14px; }
.lobby-buttons { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.pause-panel { text-align: center; }
#pause { background: rgba(0, 0, 0, .45); }

/* ---------- 読み込み ---------- */
#loading { background: rgba(8, 6, 14, .82); z-index: 40; }
.loading-box { text-align: center; }
.spinner { width: 54px; height: 54px; margin: 0 auto 14px; border-radius: 50%; border: 6px solid rgba(255, 255, 255, .2); border-top-color: var(--red); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
#hud > * { position: absolute; }
#vignette { inset: 0; background: radial-gradient(ellipse at center, rgba(255, 0, 0, 0) 45%, rgba(210, 10, 10, .85) 110%); opacity: 0; transition: opacity .15s; }
#vignette.rampage { animation: pulse .5s ease-in-out infinite alternate; }
@keyframes pulse { from { opacity: .55; } to { opacity: 1; } }
#hud-tl { left: 18px; top: 14px; }
#rank { font-family: var(--font-title); line-height: 1; text-shadow: 0 3px 0 rgba(0, 0, 0, .5); }
#rank b { font-size: clamp(54px, 9vw, 96px); font-weight: 400; color: var(--yellow); -webkit-text-stroke: 2px #6b4a00; paint-order: stroke fill; }
#rank small { font-size: clamp(20px, 3vw, 32px); margin-left: 4px; }
#hud-time { font-weight: 800; font-size: 22px; text-shadow: 0 2px 0 rgba(0, 0, 0, .6); font-variant-numeric: tabular-nums; }
#hud-tr { right: 14px; top: 12px; text-align: right; }
#minimap { width: clamp(120px, 15vw, 180px); height: clamp(120px, 15vw, 180px); background: rgba(10, 8, 18, .55); border: 2px solid rgba(255, 255, 255, .25); border-radius: 14px; }
#gold-hud { margin-top: 4px; color: #ffd21f; text-shadow: 0 0 10px rgba(255, 210, 31, .9), 0 2px 0 rgba(0, 0, 0, .6); animation: chilipulse .35s ease-in-out infinite alternate; }
#chili-hud { margin-top: 4px; color: #ff6a4a; animation: chilipulse .5s ease-in-out infinite alternate; }
@keyframes chilipulse { from { transform: scale(1); } to { transform: scale(1.12); } }
#hud-items { margin-top: 6px; font-size: 20px; font-weight: 800; text-shadow: 0 2px 0 rgba(0, 0, 0, .6); }
#hud-progress { left: 50%; top: 14px; transform: translateX(-50%); width: min(46vw, 560px); height: 22px; }
#progress-line { position: absolute; left: 0; right: 0; top: 9px; height: 5px; border-radius: 3px; background: rgba(255, 255, 255, .3); }
#progress-line::after { content: '🏁'; position: absolute; right: -8px; top: -13px; font-size: 18px; }
#progress-dots { position: absolute; inset: 0; }
#progress-dots i { position: absolute; top: 5px; width: 13px; height: 13px; margin-left: -6px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0, 0, 0, .6); }
#progress-dots i.me { width: 19px; height: 19px; margin-left: -9px; top: 2px; border-color: var(--yellow); z-index: 2; box-shadow: 0 0 10px var(--yellow); }
#hud-bl { left: 18px; bottom: 18px; }
#speed { font-family: var(--font-title); text-shadow: 0 3px 0 rgba(0, 0, 0, .55); }
#speed b { font-size: clamp(38px, 6vw, 60px); font-weight: 400; }
#speed small { font-size: 16px; margin-left: 4px; }
#hud-bc { left: 50%; bottom: 16px; transform: translateX(-50%); width: min(560px, 62vw); text-align: center; }
.anger-label { display: flex; justify-content: space-between; align-items: baseline; font-weight: 800; text-shadow: 0 2px 0 rgba(0, 0, 0, .6); margin-bottom: 3px; }
.anger-label b { color: #ff8a5c; }
.anger-bar { position: relative; height: 24px; border-radius: 13px; background: rgba(0, 0, 0, .55); border: 3px solid #fff; overflow: hidden; box-shadow: 0 3px 10px rgba(0, 0, 0, .5); }
.anger-bar i { position: absolute; left: 0; top: 0; bottom: 0; width: 0; background: linear-gradient(90deg, #ffd21f, #ff8a1f 55%, #e0362d); transition: width .06s linear; }
.anger-bar.max i { animation: flash .25s steps(2) infinite; }
@keyframes flash { 50% { filter: brightness(1.7); } }
#hint { margin-top: 7px; font-size: 13px; opacity: .85; text-shadow: 0 2px 0 rgba(0, 0, 0, .7); }
#hud-br { right: 16px; bottom: 16px; }
#butt { text-align: center; background: rgba(20, 12, 22, .55); border-radius: 16px; padding: 8px 14px 10px; border: 2px solid rgba(255, 255, 255, .18); }
.butt-title { font-size: 12px; font-weight: 800; opacity: .9; }
.butt-cheeks { display: flex; justify-content: center; margin: 2px 0; }
.butt-cheeks span, .result-cheeks span { display: block; width: 44px; height: 46px; border-radius: 50% 50% 46% 46%; background: var(--coat, #d9a98a); box-shadow: inset -4px -6px 10px rgba(0, 0, 0, .18); transition: background .1s; }
.butt-cheeks span:first-child { margin-right: -5px; }
.butt-num { font-family: var(--font-title); font-size: 26px; line-height: 1.1; }
.butt-num small, .butt-num b { font-weight: 400; }
.butt-hits { font-size: 12px; opacity: .9; }
.butt-hits b { font-size: 15px; }
#countdown { left: 50%; top: 32%; transform: translate(-50%, -50%); font-family: var(--font-title); font-size: clamp(90px, 20vw, 220px); color: #fff; -webkit-text-stroke: 4px var(--red); paint-order: stroke fill; text-shadow: 0 8px 0 rgba(0, 0, 0, .4); }
#countdown.pop { animation: cdpop .8s ease-out both; }
@keyframes cdpop { 0% { transform: translate(-50%, -50%) scale(2.2); opacity: 0; } 25% { opacity: 1; } 100% { transform: translate(-50%, -50%) scale(.9); opacity: 0; } }
#banner { left: 50%; top: 24%; transform: translateX(-50%); font-family: var(--font-title); font-size: clamp(34px, 7vw, 76px); text-align: center; color: #fff; -webkit-text-stroke: 3px var(--red); paint-order: stroke fill; white-space: nowrap; text-shadow: 0 6px 0 rgba(0, 0, 0, .4); opacity: 0; }
#banner.show { animation: banner 2.2s ease-out both; }
@keyframes banner { 0% { transform: translateX(-50%) scale(.4); opacity: 0; } 12% { transform: translateX(-50%) scale(1.15); opacity: 1; } 22% { transform: translateX(-50%) scale(1); } 80% { opacity: 1; } 100% { opacity: 0; } }
#toasts { left: 50%; top: 44%; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 6px; }
.toast { font-weight: 800; font-size: clamp(18px, 2.6vw, 26px); padding: 4px 16px; border-radius: 20px; background: rgba(20, 12, 22, .7); border: 2px solid rgba(255, 255, 255, .3); animation: toast 2.2s ease-out both; white-space: nowrap; }
.toast.good { border-color: #7dff9a; color: #c8ffd4; }
.toast.bad { border-color: #ff7a6a; color: #ffd0c8; }
@keyframes toast { 0% { transform: translateY(12px) scale(.8); opacity: 0; } 10% { transform: none; opacity: 1; } 80% { opacity: 1; } 100% { transform: translateY(-14px); opacity: 0; } }
#popups .pop { position: absolute; font-family: var(--font-title); color: #fff; -webkit-text-stroke: 3px #d81f26; paint-order: stroke fill; white-space: nowrap; transform: translate(-50%, -50%); animation: slapfx .7s ease-out both; text-shadow: 0 3px 0 rgba(0, 0, 0, .35); }
@keyframes slapfx { 0% { transform: translate(-50%, -30%) scale(.3) rotate(var(--rot)); opacity: 0; } 15% { transform: translate(-50%, -50%) scale(1.25) rotate(var(--rot)); opacity: 1; } 100% { transform: translate(-50%, -140%) scale(1) rotate(var(--rot)); opacity: 0; } }
#touch { left: 0; right: 0; bottom: 130px; display: flex; justify-content: flex-end; padding-right: 16px; pointer-events: none; }
#touch button { pointer-events: auto; font-size: 18px; font-weight: 800; padding: 16px 22px; border-radius: 50%; border: 3px solid #fff; background: rgba(60, 40, 90, .7); color: #fff; }
#btn-pause { right: calc(clamp(120px, 15vw, 180px) + 26px); top: 14px; pointer-events: auto; width: 38px; height: 38px; border-radius: 10px; border: 2px solid rgba(255, 255, 255, .35); background: rgba(20, 12, 22, .6); color: #fff; font-weight: 800; cursor: pointer; }

/* ---------- 結果 ---------- */
#result { background: linear-gradient(90deg, rgba(8, 4, 12, .82) 0%, rgba(8, 4, 12, .6) 55%, rgba(8, 4, 12, .3) 100%); overflow-y: auto; align-items: flex-start; }
.result-inner { width: min(1080px, 96vw); margin: auto; padding: 18px 0; display: grid; grid-template-columns: minmax(300px, 380px) 1fr; gap: 16px; align-items: start; }
.result-me { text-align: center; }
.result-rank { font-family: var(--font-title); line-height: 1; }
.result-rank span { font-size: 92px; color: var(--yellow); -webkit-text-stroke: 3px #6b4a00; paint-order: stroke fill; text-shadow: 0 6px 0 rgba(0, 0, 0, .4); }
.result-rank small { font-size: 30px; margin-left: 4px; }
.result-stage { font-size: 13px; opacity: .8; margin-bottom: 8px; }
.result-butt { background: rgba(0, 0, 0, .35); border-radius: 16px; padding: 10px 10px 12px; margin-bottom: 10px; }
.result-butt-title { font-weight: 800; font-size: 14px; }
.result-cheeks { display: flex; justify-content: center; margin: 6px 0; }
.result-cheeks span { width: 84px; height: 88px; }
.result-cheeks span:first-child { margin-right: -8px; }
.result-butt-pct { font-family: var(--font-title); font-size: 46px; line-height: 1; }
.result-butt-pct b { font-weight: 400; color: #ff6a55; }
.result-butt-label { font-weight: 800; font-size: 18px; margin-top: 2px; color: #ffd9a8; }
.stats { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; margin: 8px 0; text-align: left; font-size: 15px; }
.stats dt { opacity: .85; }
.stats dd { margin: 0; font-weight: 800; text-align: right; font-variant-numeric: tabular-nums; }
.score-line { display: flex; justify-content: space-between; align-items: baseline; border-top: 2px dashed rgba(255, 255, 255, .3); padding-top: 8px; margin-top: 6px; font-weight: 800; }
.score-line b { font-family: var(--font-title); font-weight: 400; font-size: 38px; color: var(--yellow); }
.res-best { min-height: 1.4em; font-size: 13px; color: #ffd9a8; margin: 4px 0 10px; }
.res-wait, .res-provisional { font-size: 13px; opacity: .85; margin: 8px 0 0; }
.result-table-wrap h3 { margin: 0 0 8px; font-size: 18px; }
.result-table { width: 100%; border-collapse: collapse; font-size: 15px; }
.result-table th { text-align: left; font-size: 12px; opacity: .7; font-weight: 700; padding: 4px 6px; }
.result-table td { padding: 7px 6px; border-top: 1px solid rgba(255, 255, 255, .12); font-variant-numeric: tabular-nums; }
.result-table tr.me td { background: rgba(255, 210, 31, .16); font-weight: 800; }
.result-table td .sw { display: inline-block; width: 11px; height: 11px; border-radius: 50%; margin-right: 6px; vertical-align: -1px; }
.result-table .redbar { display: inline-block; width: 58px; height: 9px; background: rgba(255, 255, 255, .15); border-radius: 5px; overflow: hidden; vertical-align: middle; }
.result-table .redbar i { display: block; height: 100%; background: linear-gradient(90deg, #ff9a7a, #d81f26); }

@media (max-width: 860px) {
  .stages { grid-template-columns: 1fr; }
  .stage-card .sb { min-height: 0; }
  .menu .btn { min-width: 0; flex: 1 1 100%; }
  .result-inner { grid-template-columns: 1fr; }
  #hint { display: none; }
  #hud-br { bottom: 64px; }
  #hud-bl { bottom: 62px; }
  #hud-bc { width: 92vw; }
  #hud-progress { width: 40vw; }
  .logo em { -webkit-text-stroke-width: 2px; }
}
