* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { width: 100%; height: 100%; overflow: hidden; background: #8fd0ff; }
body {
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic", "Meiryo", sans-serif;
  color: #fff; user-select: none; -webkit-user-select: none; touch-action: none;
}
#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
#ui { position: fixed; inset: 0; pointer-events: none; }
#ui button { pointer-events: auto; font-family: inherit; cursor: pointer; }
.hidden { display: none !important; }
b { font-weight: 900; }

.screen { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; }

/* ---- 野菜選択 ---- */
#select { justify-content: space-between; padding: 3vh 12px 4vh; }
.logo {
  font-size: clamp(30px, 7vw, 64px); font-weight: 900; letter-spacing: .04em;
  color: #ffe14a; -webkit-text-stroke: 2px #23130a; paint-order: stroke fill;
  text-shadow: 0 5px 0 #23130a, 0 8px 18px rgba(0,0,0,.35); transform: rotate(-3deg);
}
.logo span { color: #ff8fb3; }
.select-panel { display: flex; align-items: center; gap: 10px; margin-top: auto; width: min(560px, 100%); }
.arrow {
  flex: none; width: 54px; height: 72px; border: 3px solid #23130a; border-radius: 14px;
  background: #fff; font-size: 24px; color: #23130a; box-shadow: 0 4px 0 #23130a;
}
.arrow:active, .big-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #23130a; }
.veg-info {
  flex: 1; min-width: 0; background: rgba(20, 14, 10, .78); border: 3px solid #23130a; border-radius: 16px;
  padding: 10px 16px 12px; text-align: center;
}
.veg-count { font-size: 12px; opacity: .7; }
.veg-name { font-size: clamp(22px, 5vw, 32px); font-weight: 900; color: #ffe14a; }
.veg-desc { font-size: 14px; margin: 2px 0 8px; min-height: 1.4em; }
.stats { display: grid; gap: 5px; }
.stat { display: flex; align-items: center; gap: 8px; font-size: 12px; }
.stat span { width: 5.5em; text-align: right; }
.bar { flex: 1; height: 10px; background: rgba(255,255,255,.18); border-radius: 6px; overflow: hidden; }
.bar i { display: block; height: 100%; width: 50%; background: linear-gradient(90deg, #5fe36a, #ffe14a); border-radius: 6px; transition: width .25s; }
.veg-best { font-size: 12px; margin-top: 8px; opacity: .85; }
.big-btn {
  margin-top: 14px; padding: 14px 34px; font-size: clamp(18px, 4.4vw, 26px); font-weight: 900;
  color: #23130a; background: #ffe14a; border: 3px solid #23130a; border-radius: 999px; box-shadow: 0 5px 0 #23130a;
}
.big-btn.sub { background: #fff; }
.tip { margin-top: 12px; font-size: 13px; text-shadow: 0 1px 4px rgba(0,0,0,.8); text-align: center; max-width: 520px; }

/* ---- HUD ---- */
#hud { position: absolute; inset: 0; }
#runHud { position: absolute; top: 4vh; left: 0; right: 0; text-align: center; text-shadow: 0 2px 0 #23130a, 0 0 10px rgba(0,0,0,.5); }
.run-remain { font-size: clamp(20px, 5vw, 34px); font-weight: 700; }
.run-remain b { font-size: 1.7em; color: #ffe14a; font-variant-numeric: tabular-nums; }
.run-remain.danger b { color: #ff4a3d; }
.run-speed { font-size: 16px; }
#flyHud { position: absolute; top: 3vh; left: 0; right: 0; text-align: center; text-shadow: 0 2px 0 #23130a, 0 0 12px rgba(0,0,0,.55); }
.fly-dist b { font-size: clamp(48px, 12vw, 96px); font-style: italic; color: #ffe14a; font-variant-numeric: tabular-nums; }
.fly-dist small { font-size: 24px; margin-left: 6px; font-weight: 900; }
.fly-place { font-size: clamp(16px, 4vw, 24px); font-weight: 700; }
.fly-sub { font-size: 14px; margin-top: 2px; font-variant-numeric: tabular-nums; }
#cityPop {
  position: absolute; left: 50%; top: 70%; transform: translate(-50%, -50%) scale(.6); opacity: 0;
  font-size: clamp(28px, 8vw, 64px); font-weight: 900; white-space: nowrap; font-style: italic;
  -webkit-text-stroke: 2px #23130a; paint-order: stroke fill; text-shadow: 0 4px 0 #23130a;
  transition: opacity .15s, transform .15s;
}
#cityPop.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }
#cityPop small { display: block; font-size: .4em; font-style: normal; -webkit-text-stroke: 0; text-align: center; }
#message {
  position: absolute; left: 0; right: 0; bottom: 12vh; text-align: center;
  font-size: clamp(18px, 4.6vw, 28px); font-weight: 900; text-shadow: 0 2px 0 #23130a, 0 0 10px rgba(0,0,0,.6);
  animation: blink 1s infinite;
}
@keyframes blink { 50% { opacity: .45; } }
#judge {
  position: absolute; left: 50%; top: 42%; transform: translate(-50%, -50%) rotate(-6deg) scale(.3); opacity: 0;
  font-size: clamp(44px, 12vw, 110px); font-weight: 900; font-style: italic; white-space: nowrap;
  color: #ffe14a; -webkit-text-stroke: 3px #23130a; paint-order: stroke fill; text-shadow: 0 6px 0 #23130a;
}
#judge.show { animation: judge 1.1s ease-out forwards; }
#judge.bad { color: #9fb4c4; }
#judge.foul { color: #ff4a3d; }
@keyframes judge {
  0% { opacity: 0; transform: translate(-50%, -50%) rotate(-6deg) scale(.3); }
  15% { opacity: 1; transform: translate(-50%, -50%) rotate(-6deg) scale(1.15); }
  25% { transform: translate(-50%, -50%) rotate(-6deg) scale(1); }
  80% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -50%) rotate(-6deg) scale(1.05); }
}
#judge.foul.show { animation: judgeStay .4s ease-out forwards; }
@keyframes judgeStay {
  0% { opacity: 0; transform: translate(-50%, -50%) rotate(-6deg) scale(.3); }
  100% { opacity: 1; transform: translate(-50%, -50%) rotate(-6deg) scale(1); }
}

/* ---- 角度ゲージ ---- */
#gauge { position: absolute; left: 50%; bottom: 5vh; width: min(46vw, 250px); transform: translateX(-120%); }
#gauge svg { width: 100%; display: block; filter: drop-shadow(0 3px 0 rgba(0,0,0,.6)); }
.gauge-val { position: absolute; right: 8%; bottom: 14%; font-size: 30px; text-shadow: 0 2px 0 #23130a; }
.gauge-hint { text-align: center; font-weight: 900; font-size: 15px; text-shadow: 0 2px 0 #23130a; }

/* ---- 結果 ---- */
#result { justify-content: center; background: rgba(0,0,0,.25); pointer-events: auto; padding: 12px; }
.result-card {
  width: min(460px, 100%); background: rgba(20, 14, 10, .88); border: 3px solid #23130a; border-radius: 20px;
  padding: 18px 20px 20px; text-align: center; animation: pop .35s cubic-bezier(.2,1.5,.4,1);
}
@keyframes pop { from { transform: scale(.6); opacity: 0; } }
.result-new { color: #ff8fb3; font-weight: 900; font-size: 20px; animation: blink .6s infinite; }
.result-veg { font-size: 14px; opacity: .8; }
.result-dist b { font-size: clamp(56px, 15vw, 96px); font-style: italic; color: #ffe14a; line-height: 1.05; font-variant-numeric: tabular-nums; }
.result-dist small { font-size: 26px; font-weight: 900; margin-left: 6px; }
.result-rank { font-size: 24px; font-weight: 900; color: #5fe36a; }
.result-comment { font-size: 14px; margin: 4px 0 12px; }
.result-detail { width: 100%; border-collapse: collapse; font-size: 14px; text-align: left; }
.result-detail th { width: 4.5em; font-weight: 700; opacity: .7; padding: 4px 0; vertical-align: top; }
.result-detail td { padding: 4px 0; }
.result-detail tr + tr { border-top: 1px solid rgba(255,255,255,.14); }
.result-btns { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.result-btns .big-btn { padding: 12px 24px; font-size: 18px; }

/* ---- その他 ---- */
#muteBtn {
  position: absolute; right: 10px; top: 10px; width: 42px; height: 42px; border-radius: 50%;
  border: 2px solid #23130a; background: rgba(255,255,255,.85); font-size: 18px;
}
#speedfx {
  position: absolute; inset: 0; opacity: 0;
  background: radial-gradient(ellipse at center, rgba(255,255,255,0) 45%, rgba(255,255,255,.55) 100%);
}
#flash { position: absolute; inset: 0; background: #fff; opacity: 0; }
#loading {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  background: #8fd0ff; font-size: 22px; font-weight: 900; color: #23130a;
}

/* タイトルとオンライン記録 */
#title { padding: max(18px, env(safe-area-inset-top)) 12px 20px; background: rgba(0,0,0,.18); }
#title, #result { overflow-y: auto; touch-action: pan-y; pointer-events: auto; justify-content: flex-start; }
.title-card { width: min(540px, 100%); padding: 20px; border: 3px solid #23130a; border-radius: 20px; background: rgba(20,14,10,.88); text-align: center; }
.title-card .logo { font-size: clamp(27px, 6.8vw, 42px); }
.title-catch { margin: 12px 0 0; font-size: 14px; }
.title-card #playBtn { margin-top: 12px; width: 100%; }
.howto { margin-top: 22px; font-size: 13px; text-align: left; line-height: 1.9; }
.ranking { margin-top: 18px; text-align: left; }
.ranking h2 { color: #ffe14a; font-size: 17px; text-align: center; }
.ranking-note { font-size: 11px; opacity: .75; text-align: center; margin: 6px 0; }
.top-list { list-style: none; margin-top: 10px; font-size: 14px; }
.top-list li { display: flex; gap: 8px; align-items: center; padding: 7px 0; border-bottom: 1px solid rgba(255,255,255,.14); }
.top-list .top-name { flex: 1; overflow-wrap: anywhere; }
.top-list .top-score { color: #ffe14a; white-space: nowrap; font-variant-numeric: tabular-nums; }
.small-btn { margin-top: 10px; padding: 10px 14px; font-size: 14px; font-weight: 900; border: 2px solid #23130a; border-radius: 12px; background: #fff; color: #23130a; box-shadow: 0 3px 0 #23130a; }
.small-btn:active { transform: translateY(2px); }
.small-btn:disabled { opacity: .6; cursor: default; }
.footer-links { display: flex; justify-content: center; flex-wrap: wrap; gap: 18px; margin-top: 20px; font-size: 13px; }
.footer-links a { color: #fff; padding: 6px 0; }
.score-form { margin-top: 20px; text-align: left; font-size: 13px; }
.score-entry { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.score-entry input { width: 0; flex: 1; min-width: 0; padding: 12px 10px; border: 2px solid #ffe14a; border-radius: 12px; font: inherit; font-size: 16px; background: #fff; color: #23130a; user-select: text; -webkit-user-select: text; touch-action: manipulation; }
.score-entry button { margin: 0; white-space: nowrap; }
#scoreStatus { min-height: 1.6em; margin-top: 8px; color: #5fe36a; }
#result .result-card { margin: auto; flex-shrink: 0; }
#selectTitleBtn { font-size: 12px; padding: 7px 14px; }
@media (max-height: 540px) {
  #select { overflow-y: auto; touch-action: pan-y; pointer-events: auto; }
  #select .logo { font-size: 30px; }
  .select-panel { margin-top: 10px; }
  #select .big-btn { margin-top: 10px; padding: 10px 24px; }
}
