/* ==========================================================================
   ピザ配達戦争 — style.css（UI / HUD / ロード画面 / ポップアップ / レスポンシブ）
   ========================================================================== */
:root {
  --red: #e8453c; --red-d: #b71c1c; --orange: #ffb347; --cream: #fff8ec; --brown: #5a3a20;
  --cyan: #3ff0ff; --yellow: #ffd84a; --panel: rgba(255, 248, 236, 0.96); --shadow: 0 6px 0 rgba(90, 40, 10, 0.35);
  --safe-l: env(safe-area-inset-left, 0px); --safe-r: env(safe-area-inset-right, 0px); --safe-b: env(safe-area-inset-bottom, 0px);
  font-family: "M PLUS Rounded 1c", "Hiragino Maru Gothic ProN", "Yu Gothic", sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #1a1210; color: var(--brown); overscroll-behavior: none; touch-action: none; user-select: none; -webkit-user-select: none; }
canvas#gl, canvas#fx { position: fixed; inset: 0; width: 100vw; height: 100vh; display: block; }
canvas#fx { pointer-events: none; z-index: 2; }
[hidden] { display: none !important; }
button { font: inherit; cursor: pointer; border: 0; color: inherit; }
input, select { font: inherit; }

/* ---------- 共通ボタン ---------- */
.screen button, #skip { background: #fff; color: var(--brown); font-weight: 700; padding: 0.7em 1.3em; border-radius: 999px; box-shadow: var(--shadow); transition: transform .08s, box-shadow .08s; font-size: clamp(14px, 2.2vw, 18px); }
.screen button:active, #skip:active { transform: translateY(4px); box-shadow: 0 2px 0 rgba(90, 40, 10, .35); }
.screen button.big { background: var(--red); color: #fff; font-size: clamp(18px, 3vw, 26px); padding: .7em 2.2em; }
.icon-btn { width: 46px; height: 46px; border-radius: 50%; background: rgba(255, 255, 255, .9); color: var(--brown); font-weight: 900; box-shadow: var(--shadow); }
.small { font-size: 12px; opacity: .8; }
.row { display: flex; gap: 12px; justify-content: center; align-items: center; margin-top: 14px; }
.row.wrap { flex-wrap: wrap; }

/* ---------- 画面 ---------- */
.screen { position: fixed; inset: 0; z-index: 10; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 16px calc(16px + var(--safe-r)) calc(16px + var(--safe-b)) calc(16px + var(--safe-l)); overflow-y: auto; touch-action: pan-y; background: radial-gradient(circle at 30% 20%, rgba(255, 179, 71, .55), rgba(232, 69, 60, .75)); }
.screen.dim { background: rgba(30, 15, 5, .55); backdrop-filter: blur(3px); }
.screen h2 { margin: 0 0 14px; color: #fff; text-shadow: 0 3px 0 rgba(90, 30, 0, .5); font-size: clamp(20px, 4vw, 34px); font-weight: 900; text-align: center; }
.screen h2 small { font-size: .55em; display: block; }
#scr-loading { background: linear-gradient(160deg, #ffcf7a, #e8453c); }

/* タイトル */
#scr-title { background: radial-gradient(circle at 50% 40%, rgba(255, 210, 120, .35), rgba(120, 30, 10, .65)); }
.title-box { text-align: center; }
.logo h1 { margin: 0; font-size: clamp(40px, 9vw, 92px); font-weight: 900; color: #fff; letter-spacing: .04em; text-shadow: 0 6px 0 var(--red-d), 0 10px 18px rgba(0, 0, 0, .4); line-height: 1.05; }
.logo h1 em { font-style: normal; color: var(--yellow); }
.logo p { margin: 4px 0 18px; color: #fff; letter-spacing: .4em; font-weight: 700; opacity: .9; }
.logo-pizza { font-size: clamp(36px, 7vw, 64px); display: inline-block; animation: spin 4s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.menu { display: flex; flex-direction: column; gap: 12px; align-items: center; }
#scr-title .small { color: #fff; max-width: 640px; margin: 16px auto 0; }
.fs-btn { position: fixed; top: 12px; right: calc(12px + var(--safe-r)); }

/* カード選択 */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; width: min(920px, 100%); }
.cards button { display: flex; flex-direction: column; gap: 6px; text-align: left; border-radius: 18px; padding: 16px 18px; }
.cards b { font-size: clamp(16px, 2.4vw, 22px); color: var(--red-d); }
.cards span { font-size: 13px; font-weight: 500; opacity: .85; }
.cards .d-hard b { color: #e65100; } .cards .d-ultimate b { color: #6a1b9a; }
#seed-row label { color: #fff; font-weight: 700; }
#seed-input { margin-left: 8px; width: 9em; padding: .4em .7em; border-radius: 10px; border: 0; }

/* ロード画面 */
.loading { display: grid; grid-template-columns: minmax(160px, 1fr) minmax(220px, 1.3fr); grid-template-areas: "pizza bars" "tip tip" "dough dough"; gap: 10px 24px; width: min(860px, 100%); align-items: center; }
#load-pizza { grid-area: pizza; width: 100%; aspect-ratio: 1; max-height: 38vh; }
.bars { grid-area: bars; display: flex; flex-direction: column; gap: 10px; color: #fff; font-weight: 700; }
.bar { height: 14px; background: rgba(255, 255, 255, .35); border-radius: 99px; overflow: hidden; margin-top: 4px; }
.bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #fff6c8, var(--yellow)); border-radius: 99px; transition: width .2s; }
.tip { grid-area: tip; color: #fff; background: rgba(90, 30, 0, .3); padding: 10px 16px; border-radius: 12px; margin: 0; font-weight: 700; }
.dough-box { grid-area: dough; display: flex; align-items: center; gap: 16px; justify-content: center; color: #fff; font-weight: 700; }
.dough-box p { margin: 0; }
#dough { width: 84px; height: 84px; border-radius: 50%; background: radial-gradient(circle at 40% 35%, #fff3d6, #f0d29a 60%, #d9a05b); box-shadow: inset -6px -8px 0 rgba(160, 100, 40, .35), 0 6px 0 rgba(90, 40, 10, .35); cursor: pointer; touch-action: manipulation; position: relative; }
#dough::after { content: ''; position: absolute; left: 18px; top: 24px; width: 18px; height: 10px; border-radius: 50%; background: rgba(200, 140, 70, .5); box-shadow: 30px 14px 0 rgba(200, 140, 70, .4), 10px 30px 0 rgba(200, 140, 70, .35); }

/* リザルト */
.result { background: var(--panel); border-radius: 26px; padding: 18px 24px; width: min(720px, 100%); box-shadow: 0 10px 30px rgba(0, 0, 0, .35); }
.result h2 { color: var(--red); text-shadow: none; margin-bottom: 6px; }
.res-head { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 8px; font-weight: 700; }
.res-head b { font-size: 1.4em; color: var(--red-d); }
#res-judges span { margin-left: 10px; font-weight: 900; font-size: 13px; }
.j-P { color: #e0a800; } .j-G { color: #1aa6c9; } .j-O { color: #4caf50; } .j-M { color: #888; }
#res-breakdown { list-style: none; padding: 0; margin: 10px 0; }
#res-breakdown li { display: flex; justify-content: space-between; padding: 6px 4px; border-bottom: 1px dashed rgba(90, 58, 32, .25); opacity: 0; transform: translateX(-12px); transition: .3s; }
#res-breakdown li.in { opacity: 1; transform: none; }
.res-score-row { display: flex; align-items: baseline; gap: 14px; justify-content: center; }
#res-score { font-size: clamp(40px, 8vw, 68px); color: #e65100; font-weight: 900; }
#res-score.pop { animation: pop .5s; }
@keyframes pop { 40% { transform: scale(1.25); } }
#res-new { color: #fff; background: var(--red); border-radius: 99px; padding: 2px 12px; font-style: normal; font-weight: 900; animation: pop 1s infinite; }
#res-rank { text-align: center; font-weight: 700; min-height: 1.2em; margin: 4px 0; }
.share.x { background: #111; color: #fff; } .share.line { background: #06c755; color: #fff; }

/* ランキング */
.tabs { display: flex; gap: 6px; margin-bottom: 8px; flex-wrap: wrap; justify-content: center; }
.tabs button { padding: .4em 1em; font-size: 14px; }
.tabs button.on { background: var(--red-d); color: #fff; }
#rk-me { color: #fff; font-weight: 700; margin: 4px; } #rk-status { color: #fff; margin: 0; }
#rk-list { list-style: none; padding: 0; margin: 6px 0; width: min(720px, 100%); background: var(--panel); border-radius: 18px; max-height: 50vh; overflow-y: auto; }
#rk-list li { display: flex; gap: 10px; align-items: center; padding: 8px 14px; border-bottom: 1px solid rgba(90, 58, 32, .12); }
#rk-list li.me { background: #fff1b8; font-weight: 900; }
#rk-list li.empty { justify-content: center; opacity: .7; }
.rk-no { width: 2.2em; font-weight: 900; color: var(--red-d); } .rk-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rk-diff { font-size: 11px; padding: 1px 8px; border-radius: 99px; background: #4caf50; color: #fff; }
.rk-diff.d-hard { background: #f57c00; } .rk-diff.d-ultimate { background: #7b1fa2; }
.rk-time { width: 5.5em; text-align: right; opacity: .8; } .rk-score { width: 6em; text-align: right; font-weight: 900; }

/* 設定 */
#settings-form { background: var(--panel); border-radius: 18px; padding: 12px 18px; width: min(640px, 100%); display: grid; gap: 6px; }
#settings-form label { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-weight: 700; padding: 4px 0; border-bottom: 1px dashed rgba(90, 58, 32, .15); }
#settings-form input[type=range] { flex: 1; max-width: 260px; accent-color: var(--red); }
#settings-form output { width: 4.5em; text-align: right; font-variant-numeric: tabular-nums; }
#settings-form input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--red); }
#settings-form input[type=text], #name-input { padding: .45em .8em; border-radius: 10px; border: 2px solid rgba(90, 58, 32, .25); }
#name-input { font-size: 20px; width: min(320px, 80vw); }

/* 実績 */
#ach-list { list-style: none; padding: 0; margin: 0; width: min(640px, 100%); display: grid; gap: 8px; }
#ach-list li { background: var(--panel); border-radius: 14px; padding: 10px 16px; display: flex; flex-direction: column; opacity: .55; }
#ach-list li.got { opacity: 1; }

/* タイミング調整 */
#calib-canvas { width: min(760px, 100%); height: 140px; background: rgba(20, 12, 6, .45); border-radius: 70px; }
#calib-pad { margin-top: 12px; width: min(760px, 100%); padding: 28px; text-align: center; font-weight: 900; background: rgba(255, 255, 255, .9); border-radius: 18px; box-shadow: var(--shadow); touch-action: manipulation; }
#calib-pad:active { transform: translateY(3px); }
#calib-result { color: #fff; font-weight: 700; text-align: center; min-height: 2.4em; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; z-index: 3; pointer-events: none; color: #fff; text-shadow: 0 2px 0 rgba(0, 0, 0, .55); }
#hud button { pointer-events: auto; }
.hud-top { position: absolute; top: 10px; left: calc(12px + var(--safe-l)); right: calc(12px + var(--safe-r)); display: flex; justify-content: space-between; align-items: flex-start; }
#hud-time { font-size: clamp(26px, 4.5vw, 42px); font-weight: 900; font-variant-numeric: tabular-nums; }
#hud-mode, #hud-ghost { font-size: 12px; font-weight: 700; opacity: .9; }
#hud-ghost { color: #bfe8ff; }
.hud-acro { position: absolute; top: 84px; left: calc(12px + var(--safe-l)); }
#hud-mult { font-size: clamp(24px, 4vw, 38px); font-weight: 900; color: var(--yellow); transition: transform .1s; }
#hud-mult.hot { color: #ff8a3d; animation: pop .6s infinite; }
#hud-combo { font-weight: 900; font-size: 18px; }
#hud-fever { display: flex; gap: 5px; align-items: center; margin-top: 4px; font-size: 12px; font-weight: 900; }
#hud-fever i { width: 14px; height: 14px; border-radius: 50%; border: 2px solid #fff; background: rgba(0, 0, 0, .3); }
#hud-fever i.on { background: linear-gradient(135deg, #ff5f6d, #ffc371, #7cff7a, #5fd3ff, #c77dff); box-shadow: 0 0 8px #fff; }
#hud-fever.active span { animation: rainbow 1s linear infinite; }
@keyframes rainbow { 0% { color: #ff5f6d; } 25% { color: #ffd84a; } 50% { color: #7cff7a; } 75% { color: #5fd3ff; } 100% { color: #ff5f6d; } } #hud-acro { font-size: 12px; font-weight: 700; }
#minimap { position: absolute; top: 64px; right: calc(12px + var(--safe-r)); width: clamp(150px, 24vw, 240px); height: auto; aspect-ratio: 1; filter: drop-shadow(0 3px 6px rgba(0, 0, 0, .5)); }
#hud-speed { position: absolute; bottom: calc(14px + var(--safe-b)); left: 50%; transform: translateX(-50%); font-size: 30px; font-weight: 900; font-variant-numeric: tabular-nums; }
#hud-speed small { font-size: 13px; margin-left: 4px; }
#hint { position: absolute; bottom: calc(70px + var(--safe-b)); left: 50%; transform: translateX(-50%) translateY(10px); max-width: min(680px, 90vw); text-align: center; background: rgba(30, 15, 5, .7); padding: 10px 18px; border-radius: 14px; font-weight: 700; opacity: 0; transition: .3s; }
#hint.on { opacity: 1; transform: translateX(-50%); }
#countdown { position: absolute; top: 40%; left: 50%; transform: translate(-50%, -50%) scale(.4); font-size: clamp(80px, 16vw, 160px); font-weight: 900; color: #fff; opacity: 0; text-shadow: 0 8px 0 var(--red-d); }
#countdown.show { animation: cd .75s ease-out forwards; }
#countdown.go { color: var(--yellow); }
@keyframes cd { 0% { opacity: 0; transform: translate(-50%, -50%) scale(2); } 25% { opacity: 1; transform: translate(-50%, -50%) scale(1); } 85% { opacity: 1; } 100% { opacity: 0; transform: translate(-50%, -50%) scale(.9); } }
#intro-banner { position: absolute; left: 50%; top: 14%; transform: translate(-50%, -20px); text-align: center; opacity: 0; transition: .5s; pointer-events: none; }
#intro-banner.on { opacity: 1; transform: translate(-50%, 0); }
#intro-banner b { display: block; font-size: clamp(30px, 6vw, 60px); font-weight: 900; color: #fff; text-shadow: 0 5px 0 var(--red-d), 0 8px 18px rgba(0, 0, 0, .4); }
#intro-banner span { display: inline-block; margin-top: 6px; background: rgba(30, 15, 5, .6); padding: 6px 14px; border-radius: 99px; font-weight: 700; }
#skip { position: absolute; right: calc(16px + var(--safe-r)); bottom: calc(16px + var(--safe-b)); z-index: 5; }

/* ---------- タッチ操作 ---------- */
#touch { position: fixed; inset: 0; z-index: 4; pointer-events: none; }
#touch > * { pointer-events: auto; touch-action: none; }
#stick { position: absolute; left: calc(20px + var(--safe-l)); bottom: calc(20px + var(--safe-b)); width: clamp(120px, 22vh, 170px); aspect-ratio: 1; border-radius: 50%; background: rgba(255, 255, 255, .18); border: 3px solid rgba(255, 255, 255, .5); display: grid; place-items: center; }
#stick span { position: absolute; bottom: -20px; font-size: 11px; color: #fff; font-weight: 700; }
#stick-knob { width: 42%; aspect-ratio: 1; border-radius: 50%; background: rgba(255, 255, 255, .85); box-shadow: 0 3px 8px rgba(0, 0, 0, .4); transition: transform .05s; }
.tbtn { position: absolute; border-radius: 50%; color: #fff; font-weight: 900; text-shadow: 0 1px 0 rgba(0, 0, 0, .4); box-shadow: 0 4px 0 rgba(0, 0, 0, .35); border: 3px solid rgba(255, 255, 255, .6); }
.tbtn.on { transform: translateY(3px); filter: brightness(1.2); }
#btn-accel { right: calc(20px + var(--safe-r)); bottom: calc(20px + var(--safe-b)); width: clamp(84px, 17vh, 120px); aspect-ratio: 1; background: rgba(46, 160, 67, .8); }
#btn-brake { right: calc(clamp(84px, 17vh, 120px) + 34px + var(--safe-r)); bottom: calc(14px + var(--safe-b)); width: clamp(62px, 12vh, 88px); aspect-ratio: 1; background: rgba(200, 60, 50, .8); font-size: 12px; }
#btn-acro { right: calc(28px + var(--safe-r)); bottom: calc(clamp(84px, 17vh, 120px) + 40px + var(--safe-b)); width: clamp(96px, 20vh, 140px); aspect-ratio: 1; background: radial-gradient(circle at 40% 35%, #ffe680, #f5a400); color: #6a3a00; font-size: 20px; text-shadow: none; }
#btn-acro.cue { animation: cue .25s infinite alternate; }
@keyframes cue { to { box-shadow: 0 0 0 10px rgba(255, 230, 100, .55), 0 4px 0 rgba(0, 0, 0, .35); } }
#btn-acro.hitP { animation: hit .35s; background: radial-gradient(circle, #fff7b0, #ffcc00); }
#btn-acro.hitG, #btn-acro.hitO { animation: hit .35s; } #btn-acro.hitM { filter: grayscale(1); }
@keyframes hit { 50% { transform: scale(1.15); } }

/* ---------- ポップアップ ---------- */
#wait { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; background: rgba(20, 10, 5, .35); }
.wait-box { background: var(--panel); border-radius: 22px; padding: 18px 28px; text-align: center; box-shadow: 0 8px 0 rgba(90, 40, 10, .35); min-width: 240px; }
.wait-anim { position: relative; height: 70px; overflow: hidden; }
.wait-scooter { width: 110px; position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%); animation: bounce .35s infinite alternate; }
@keyframes bounce { to { transform: translateX(-50%) translateY(-3px) rotate(-2deg); } }
.wait-road { position: absolute; left: 0; right: 0; bottom: 4px; height: 6px; background: repeating-linear-gradient(90deg, #666 0 24px, transparent 24px 40px); animation: road .4s linear infinite; }
@keyframes road { to { background-position: -40px 0; } }
#wait-msg { margin: 8px 0 0; font-weight: 900; font-size: 18px; }
#toast { position: fixed; z-index: 40; top: 16px; left: 50%; transform: translate(-50%, -80px); background: rgba(30, 15, 5, .85); color: #fff; padding: 10px 18px; border-radius: 12px; font-weight: 700; transition: transform .3s; pointer-events: none; max-width: 90vw; text-align: center; }
#toast.on { transform: translate(-50%, 0); }
#ach-stack { position: fixed; z-index: 41; right: 16px; top: 80px; display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
.ach-pop { background: linear-gradient(90deg, #ffd84a, #ffb347); color: var(--brown); padding: 10px 16px; border-radius: 14px; box-shadow: var(--shadow); display: flex; flex-direction: column; animation: slidein .4s; }
@keyframes slidein { from { transform: translateX(120%); } }
#boot-error { position: fixed; inset: 0; z-index: 99; display: grid; place-items: center; background: #300; color: #fff; padding: 24px; text-align: center; }

/* 縦向きのスマホ：横向きにしてね */
#rotate { display: none; }
@media (orientation: portrait) and (pointer: coarse) and (max-width: 900px) {
  #rotate { display: grid; place-items: center; position: fixed; inset: 0; z-index: 100; background: linear-gradient(160deg, #ffb347, #e8453c); color: #fff; font-size: 64px; text-align: center; font-weight: 900; }
  #rotate div { animation: rot 2s ease-in-out infinite; } #rotate p { font-size: 22px; margin: 8px 0 0; }
  @keyframes rot { 50% { transform: rotate(90deg); } }
}
/* 横向きの低い画面（スマホ） */
@media (max-height: 480px) {
  .screen h2 { margin-bottom: 8px; }
  .cards { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 8px; }
  .cards button { padding: 10px 12px; }
  .loading { grid-template-columns: 30vh 1fr; }
  #load-pizza { max-height: 30vh; }
  .result { padding: 10px 16px; }
  #res-breakdown li { padding: 2px 4px; font-size: 13px; }
  .hud-acro { top: 70px; }
  #minimap { width: clamp(130px, 30vh, 200px); }
}
