:root {
  --sun: #ffb347;
  --hot: #ff6a2b;
  --ink: #fff4e6;
  --dim: #e0c2a4;
  --gold: #ffd27a;
}
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body {
  width: 100%; height: 100%; overflow: hidden; background: #000;
  font-family: "Segoe UI", "Hiragino Sans", "Noto Sans JP", system-ui, sans-serif;
  color: var(--ink); user-select: none; -webkit-user-select: none; touch-action: none;
}
#stage { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); overflow: hidden; background: #1a0f0a; }
#c { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.hidden { display: none !important; }

/* ---------------- HUD */
#hud { position: absolute; inset: 0; pointer-events: none; text-shadow: 0 1px 6px rgba(0, 0, 0, .7); }
#hud-top {
  position: absolute; left: 0; right: 0; top: 0; padding: max(10px, env(safe-area-inset-top)) 14px 0;
  display: flex; justify-content: space-between; align-items: flex-start;
}
.lbl { font-size: 10px; letter-spacing: .25em; color: var(--dim); }
#time { font-size: 26px; font-weight: 800; letter-spacing: .04em; font-variant-numeric: tabular-nums; }
.hud-r { text-align: right; }
#speed { font-size: 30px; font-weight: 900; font-style: italic; font-variant-numeric: tabular-nums; color: var(--gold); }
#progbar { position: absolute; left: 14px; right: 58px; top: calc(max(10px, env(safe-area-inset-top)) + 56px); }
#progbar .name { display: flex; justify-content: space-between; font-size: 10px; letter-spacing: .12em; color: var(--dim); margin-bottom: 3px; }
#progbar .name span:last-child { color: #ff8a70; font-weight: 800; }
#progbar .bar { position: relative; height: 5px; background: rgba(0, 0, 0, .35); border: 1px solid rgba(255, 255, 255, .35); }
#progbar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #ffd27a, #ff6a2b); }
#progbar b { position: absolute; top: -2px; width: 1px; height: 7px; background: rgba(255, 255, 255, .6); }
#skim {
  position: absolute; left: 0; right: 0; bottom: calc(max(22px, env(safe-area-inset-bottom)) + 34px); text-align: center;
  font-size: 22px; font-weight: 900; font-style: italic; letter-spacing: .3em; color: #fff; opacity: 0; transition: opacity .08s;
  text-shadow: 0 0 12px var(--hot), 0 0 26px var(--sun);
}
#skim.on { opacity: 1; }
#boostbar {
  position: absolute; left: 50%; transform: translateX(-50%); width: min(260px, 70%); bottom: max(22px, env(safe-area-inset-bottom));
  display: flex; align-items: center; gap: 8px; font-size: 10px; letter-spacing: .25em; color: var(--dim);
}
#boostbar .bar { flex: 1; height: 8px; background: rgba(0, 0, 0, .4); border: 1px solid rgba(255, 255, 255, .4); transform: skewX(-18deg); }
#boostbar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #ffd27a, #ff6a2b, #fff); box-shadow: 0 0 10px var(--hot); }
#pause-btn {
  position: absolute; right: 14px; top: calc(max(10px, env(safe-area-inset-top)) + 50px); width: 34px; height: 34px;
  border-radius: 50%; border: 1px solid rgba(255, 255, 255, .4); background: rgba(0, 0, 0, .35); color: var(--ink);
  font-weight: 800; font-size: 11px; pointer-events: auto;
}

#msg {
  position: absolute; left: 0; right: 0; top: 30%; text-align: center; pointer-events: none;
  font-size: 30px; font-weight: 900; letter-spacing: .2em; opacity: 0; text-shadow: 0 0 18px rgba(255, 140, 40, .9), 0 2px 8px #000;
}
#msg.show { animation: msg 1.6s ease-out forwards; }
#msg.count { font-size: 64px; font-style: italic; }
#msg.count.show { animation: count .95s ease-out forwards; }
#msg small { display: block; font-size: 13px; letter-spacing: .18em; margin-top: 8px; font-style: normal; }
@keyframes msg { 0% { opacity: 0; transform: scale(1.4); } 12% { opacity: 1; transform: none; } 80% { opacity: 1; } 100% { opacity: 0; } }
@keyframes count { 0% { opacity: 0; transform: scale(2.2); } 18% { opacity: 1; transform: none; } 75% { opacity: 1; } 100% { opacity: 0; transform: scale(.8); } }
.pop {
  position: absolute; left: 50%; top: 42%; transform: translate(-50%, -50%); pointer-events: none; white-space: nowrap;
  font-weight: 900; font-style: italic; letter-spacing: .14em; font-size: 20px; color: #fff; text-shadow: 0 0 10px var(--hot), 0 2px 6px #000;
  animation: popup .9s ease-out forwards;
}
.pop.good { color: #fff3c0; font-size: 24px; }
.pop.bad { color: #ff8a70; font-size: 30px; }
.pop.gate { top: 24%; font-size: 16px; font-style: normal; color: #bff2ff; text-shadow: 0 0 10px #4cf, 0 2px 6px #000; }
@keyframes popup { 0% { opacity: 0; transform: translate(-50%, -20%) scale(.6); } 15% { opacity: 1; transform: translate(-50%, -50%) scale(1.1); } 70% { opacity: 1; } 100% { opacity: 0; transform: translate(-50%, -130%); } }
#flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; }

/* ---------------- 画面 */
.screen {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px; text-align: center; padding: 20px;
}
/* タイトル：ロゴは上、説明とボタンは下に寄せる（間は機体を見せる）。ボタンは必ず画面の中に入れる */
#title {
  justify-content: flex-start; padding-top: max(7vh, env(safe-area-inset-top)); padding-bottom: max(14px, env(safe-area-inset-bottom));
  background: linear-gradient(180deg, rgba(0, 0, 0, .45), rgba(0, 0, 0, 0) 28%, rgba(0, 0, 0, 0) 52%, rgba(0, 0, 0, .72)); overflow: hidden;
}
#title .start { margin-top: auto; }
#pause, #result { background: rgba(14, 7, 4, .78); backdrop-filter: blur(4px); }
#loading { background: #1a0f0a; }
.logo {
  font-size: min(40px, 10.2vw); font-weight: 900; font-style: italic; letter-spacing: .12em;
  background: linear-gradient(180deg, #fff 20%, #ffd27a 55%, #ff6a2b); -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 2px 10px rgba(0, 0, 0, .6));
}
.logo.small { font-size: 30px; }
.sub { font-size: 12px; letter-spacing: .35em; color: var(--dim); text-shadow: 0 1px 6px #000; }
.start { font-size: 16px; font-weight: 800; letter-spacing: .4em; color: #fff; text-shadow: 0 0 10px var(--hot), 0 1px 6px #000; }
.blink { animation: blink 1.4s infinite; }
@keyframes blink { 50% { opacity: .25; } }
.howto { font-size: 12px; line-height: 1.6; color: var(--dim); text-shadow: 0 1px 6px #000; }
.howto b { color: var(--ink); }
.hi { font-size: 12px; letter-spacing: .2em; color: var(--gold); text-shadow: 0 1px 6px #000; }
@media (max-height: 640px) { #title .howto { display: none; } }
.row { display: flex; gap: 8px; pointer-events: auto; flex-wrap: wrap; justify-content: center; }
button.big, button.small, a.home {
  pointer-events: auto; border: 1px solid rgba(255, 190, 110, .7); background: rgba(50, 22, 8, .7); color: #fff;
  font-weight: 700; letter-spacing: .15em; border-radius: 4px; font-family: inherit; text-decoration: none; display: inline-block;
}
button.big { font-size: 16px; padding: 12px 30px; box-shadow: 0 0 16px rgba(255, 150, 60, .35); }
button.small, a.home { font-size: 11px; padding: 7px 16px; opacity: .9; }
#result { gap: 8px; }
#result-table { border-collapse: collapse; font-size: 12px; min-width: 250px; }
#result-table td { padding: 3px 8px; border-bottom: 1px solid rgba(255, 255, 255, .1); }
#result-table td:first-child { text-align: left; color: var(--dim); }
#result-table td:last-child { text-align: right; font-variant-numeric: tabular-nums; }
.total { font-size: 46px; font-weight: 900; font-style: italic; color: var(--gold); font-variant-numeric: tabular-nums; }
#result-new { color: #ff8a70; font-weight: 900; letter-spacing: .3em; animation: blink .8s infinite; }

/* ---------------- ランキング */
.rk-entry { display: flex; gap: 6px; align-items: center; pointer-events: auto; }
.rk-entry input {
  width: 130px; padding: 7px 8px; font-size: 14px; font-family: inherit; color: #fff; text-align: center;
  background: rgba(0, 0, 0, .5); border: 1px solid rgba(255, 190, 110, .6); border-radius: 4px; user-select: text; -webkit-user-select: text;
}
#rank-panel { background: rgba(14, 7, 4, .94); z-index: 5; }
#rank-list { width: 100%; max-width: 340px; pointer-events: auto; }
table.rk { width: 100%; border-collapse: collapse; font-size: 13px; }
table.rk td { padding: 5px 4px; border-bottom: 1px solid rgba(255, 255, 255, .1); text-align: left; }
table.rk td:first-child { width: 22px; color: var(--gold); font-weight: 800; }
table.rk td:nth-child(3) { text-align: right; font-variant-numeric: tabular-nums; font-weight: 700; }
table.rk td:nth-child(4) { text-align: right; font-size: 10px; color: var(--dim); }
table.rk tr.me td { color: #fff; background: rgba(255, 170, 80, .2); }
.rk-empty { color: var(--dim); font-size: 13px; padding: 20px; }

#skim.dbl { color: #fff3c0; font-size: 26px; text-shadow: 0 0 14px #ffb347, 0 0 30px #ff6a2b; }
#msg.warn { color: #bff2ff; text-shadow: 0 0 16px #4cf, 0 2px 8px #000; }
