:root { color-scheme: dark; --yellow: #ffe23a; --pink: #ff5fae; --navy: rgba(16, 26, 96, .78); }
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: #000; color: #fff; overflow: hidden; }
body {
  font-family: "Hiragino Maru Gothic ProN", "Hiragino Sans", "Yu Gothic UI", "Meiryo", sans-serif;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; touch-action: none;
}
#view { position: fixed; inset: 0; width: 100vw; height: 100vh; height: 100dvh; display: block; }
.hidden { display: none !important; }
.screen { position: fixed; inset: 0; }
button { font: inherit; cursor: pointer; }

/* 最初の画面 */
#gate { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 22px; background: radial-gradient(#1b2150, #000 70%); cursor: pointer; }
.gate-title { font-size: clamp(22px, 5vw, 44px); font-weight: bold; color: var(--yellow); text-shadow: 0 0 2px #000, 0 3px 0 #7a4b00; }
.gate-title span { color: var(--pink); font-style: italic; }
#gate-msg { font-size: 20px; font-weight: bold; color: #fff; }
#gate-links a { color: #8fc6ff; font-size: 14px; }

/* 物語の文 */
#story { cursor: pointer; }
.panel {
  position: absolute; left: 50%; top: 5%; transform: translateX(-50%);
  width: min(1060px, 94vw); max-height: 80vh; overflow: hidden;
  padding: clamp(14px, 2.4vw, 26px) clamp(16px, 3vw, 34px);
  background: var(--navy); border: 2px solid rgba(160, 190, 255, .75); border-radius: 14px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, .5), inset 0 0 0 1px rgba(255, 255, 255, .08);
  font-size: clamp(11px, calc((min(1060px, 94vw) - 72px) / 55), 19px); line-height: 1.75; text-shadow: 0 1px 2px #000;
  line-break: strict;
}
.panel.bottom { top: auto; bottom: 9%; }
.panel.center { top: 42%; background: none; border: none; box-shadow: none; text-align: center; font-size: clamp(16px, 2.6vw, 26px); }
.panel.empty { display: none; }
.panel.in { animation: fadein .6s ease-out; }
@keyframes fadein { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }
.panel p, .panel .txt { margin: 0; text-wrap: pretty; }
.panel .gap { height: .8em; }
.panel .say { display: grid; grid-template-columns: 8.5em 1fr; }
.panel .who { color: var(--yellow); font-weight: bold; }
.panel .who::after { content: "："; color: #fff; }
.hint { position: absolute; right: 16px; bottom: 12px; font-size: 12px; color: rgba(255, 255, 255, .7); text-shadow: 0 1px 2px #000; }
.skip { position: absolute; left: 14px; bottom: 8px; padding: 6px 14px; font-size: 13px; color: #fff; background: rgba(0, 0, 0, .45); border: 1px solid rgba(255, 255, 255, .5); border-radius: 16px; }
#gameovermark, #fin { position: fixed; left: 0; right: 0; text-align: center; pointer-events: none; opacity: 0; transition: opacity 1.2s; }
#gameovermark { top: 34%; font-size: clamp(36px, 8vw, 80px); font-weight: bold; color: var(--yellow); text-shadow: 0 0 3px #000, 0 4px 0 #7a4b00, 0 0 24px rgba(0, 0, 0, .8); }
#fin { top: 38%; font-size: clamp(60px, 13vw, 140px); font-family: "Comic Sans MS", "Chalkboard SE", cursive; color: #fff; text-shadow: 0 0 18px rgba(120, 160, 255, .9); }
#gameovermark.on, #fin.on { opacity: 1; }

/* タイトル */
#title { display: flex; flex-direction: column; align-items: center; justify-content: space-between; padding: 7vh 0 9vh; cursor: pointer; }
.logo { display: flex; flex-direction: column; align-items: center; animation: logoin 1.6s ease-out; }
.logo .l1 {
  font-size: clamp(34px, 8vw, 92px); font-weight: bold; color: var(--yellow); letter-spacing: .04em;
  -webkit-text-stroke: 2px #6b3a00; paint-order: stroke fill;
  text-shadow: 0 5px 0 #6b3a00, 0 8px 18px rgba(0, 0, 0, .55);
}
.logo .l2 {
  margin-top: -.1em; font-size: clamp(26px, 5.4vw, 62px); font-weight: bold; font-style: italic; letter-spacing: .08em;
  color: #fff; -webkit-text-stroke: 1.5px #a0105a; paint-order: stroke fill;
  text-shadow: 0 0 14px var(--pink), 0 4px 0 #a0105a;
}
@keyframes logoin { from { opacity: 0; transform: scale(.85) translateY(-20px); } to { opacity: 1; transform: none; } }
.press { font-size: clamp(15px, 2.2vw, 22px); font-weight: bold; color: #fff; text-shadow: 0 2px 4px #000; animation: blink 1.4s infinite; }
@keyframes blink { 50% { opacity: .35; } }

/* おもちゃ選び */
#select { pointer-events: none; }
#select > * { pointer-events: auto; }
.sel-head { position: absolute; top: 4vh; left: 0; right: 0; text-align: center; font-size: clamp(20px, 3.4vw, 34px); font-weight: bold; color: var(--yellow); text-shadow: 0 3px 0 #6b3a00, 0 0 10px #000; }
#toycard {
  position: absolute; right: 4vw; top: 16vh; width: min(360px, 44vw); padding: 16px 20px;
  background: #fffbd0; color: #222; border: 2px solid #333; border-radius: 6px; box-shadow: 6px 6px 0 rgba(0, 0, 0, .35);
  font-size: clamp(12px, 1.7vw, 16px); line-height: 2.1; transform: rotate(1.5deg);
}
#toycard b { font-weight: normal; }
.sel-btns { position: absolute; bottom: 16vh; left: 0; right: 0; display: flex; justify-content: center; gap: 14px; }
.btn { padding: 12px 22px; font-size: clamp(14px, 2vw, 20px); font-weight: bold; color: #fff; background: #1d3f8a; border: 2px solid #8fb0ff; border-radius: 12px; box-shadow: 0 4px 0 #0c1f4d; }
.btn.go { background: #e0357f; border-color: #ffb3d6; box-shadow: 0 4px 0 #7a0c3c; }
.btn.on, .btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #0c1f4d; }
.sel-note { position: absolute; bottom: 4vh; left: 50%; transform: translateX(-50%); width: min(620px, 92vw); padding: 12px 20px; background: linear-gradient(#0c2a8a, #2f63ff); border-radius: 4px; font-size: clamp(12px, 1.6vw, 15px); line-height: 1.7; }

/* ステージ中 */
#hud { position: fixed; left: 14px; top: 12px; pointer-events: none; text-shadow: 0 1px 2px #000; }
.gauge { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.gl { width: 4.6em; font-size: 15px; font-weight: bold; color: var(--yellow); }
.pips { display: flex; gap: 4px; }
.pips i { width: 20px; height: 20px; display: block; border-radius: 50%; border: 2px solid rgba(255, 255, 255, .8); background: rgba(0, 0, 0, .35); box-shadow: 0 1px 3px rgba(0, 0, 0, .6); }
.pips.hp i { border-radius: 4px; }
.pips.hp i.on { background: radial-gradient(circle at 35% 35%, #9fe8ff, #1b8fd6); }
.pips.cap i.on { background: radial-gradient(circle at 35% 35%, #ffd0ec, #e0357f); }
.keys { margin-top: 4px; font-size: 11px; color: rgba(255, 255, 255, .7); }
#banner {
  position: fixed; left: 0; right: 0; top: 38%; text-align: center; pointer-events: none; opacity: 0;
  font-size: clamp(22px, 4.2vw, 44px); font-weight: bold; color: #fff; -webkit-text-stroke: 1.5px #1d3f8a; paint-order: stroke fill;
  text-shadow: 0 4px 0 #1d3f8a, 0 0 18px rgba(0, 0, 0, .6);
}
#banner.go { animation: banner 2.6s ease-out forwards; }
@keyframes banner { 0% { opacity: 0; transform: translateY(20px); } 15%, 75% { opacity: 1; transform: none; } 100% { opacity: 0; transform: translateY(-10px); } }
#flash { position: fixed; inset: 0; pointer-events: none; opacity: 0; }
#flash.hurt { animation: hurt .5s ease-out; background: radial-gradient(transparent 50%, rgba(255, 40, 40, .55)); }
#flash.magic { animation: magic 1.6s ease-out; background: radial-gradient(rgba(255, 200, 240, .8), rgba(255, 120, 200, .2) 60%, transparent); }
@keyframes hurt { from { opacity: 1; } to { opacity: 0; } }
@keyframes magic { from { opacity: 1; } to { opacity: 0; } }

/* スマホの操作 */
#touch { position: fixed; inset: 0; pointer-events: none; }
#touch .tb { position: absolute; pointer-events: auto; touch-action: none; color: #fff; font-weight: bold; font-size: 18px; background: rgba(20, 40, 120, .55); border: 2px solid rgba(160, 190, 255, .8); border-radius: 50%; width: 76px; height: 76px; }
#touch .tb.on { background: rgba(255, 220, 60, .8); color: #000; }
#tb-l { left: 18px; bottom: 26px; }
#tb-r { left: 110px; bottom: 26px; }
#tb-brake { right: 110px; bottom: 26px; font-size: 13px !important; }
#tb-accel { right: 14px; bottom: 60px; width: 90px !important; height: 90px !important; }
#tb-pause { right: 14px; top: 12px; width: 44px !important; height: 44px !important; font-size: 14px !important; }

/* 一時停止 */
#pause { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 22px; background: rgba(0, 0, 0, .55); }
.pmsg { font-size: clamp(15px, 2.4vw, 22px); font-weight: bold; animation: rainbow 1s infinite; }
@keyframes rainbow { 0% { color: #ff8080; } 33% { color: #80ff9a; } 66% { color: #80b8ff; } 100% { color: #ff8080; } }
.pbtns { display: flex; gap: 14px; }

.touch .keys, .touch .sel-note { display: none; }
@media (max-width: 640px) {
  #toycard { left: 50%; right: auto; top: 11vh; width: 88vw; transform: translateX(-50%) rotate(1deg); line-height: 1.8; }
  .panel .say { grid-template-columns: 6.5em 1fr; }
  .keys { display: none; }
}
@media (max-height: 460px) {
  .panel { top: 3%; max-height: 86vh; line-height: 1.55; }
  .panel.bottom { bottom: 4%; }
  .sel-btns { bottom: 5vh; }
  .sel-note { display: none; }
  #toycard { top: 14vh; right: 2vw; width: 36vw; padding: 8px 12px; font-size: 12px; line-height: 1.7; }
}
