:root { --bg: #14110e; --ink: #f4efe6; --dim: #b4a995; --acc: #ff9a1f; --acc2: #ffd36b; --line: rgba(255,255,255,.16); --panel: rgba(18,15,12,.72); }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); overflow: hidden; font-family: "Zen Kaku Gothic New", "Hiragino Kaku Gothic ProN", "Yu Gothic", "Meiryo", sans-serif; user-select: none; -webkit-user-select: none; touch-action: none; }
#gl { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
a { color: var(--acc2); }
.screen { position: fixed; inset: 0; display: none; z-index: 10; }
.screen.show { display: flex; }
#loading { align-items: center; justify-content: center; flex-direction: column; background: radial-gradient(ellipse at 50% 40%, #3a2a1a 0%, #14110e 70%); z-index: 50; }
.logo { display: inline-block; font-family: "Russo One", sans-serif; font-size: clamp(40px, 9vw, 84px); line-height: 1; letter-spacing: .04em; transform: skewX(-8deg); position: relative; padding: 0 .1em .08em; }
.logo .mark { background: linear-gradient(180deg, #fff6e0 0%, #ffd36b 36%, #ff8a14 62%, #c44a08 100%); -webkit-background-clip: text; background-clip: text; color: transparent; filter: drop-shadow(0 3px 0 #2a1204) drop-shadow(0 0 22px rgba(255,140,30,.4)); }
.logo::after { content: ""; position: absolute; left: 3%; right: -2%; bottom: -.04em; height: max(3px, .05em); background: linear-gradient(90deg, transparent, #ff9a1f 18%, #ff9a1f 82%, transparent); box-shadow: 0 0 14px #ff9a1f; }
.logo.big { font-size: clamp(54px, 13vw, 150px); }
.bar { width: min(420px, 70vw); height: 6px; background: rgba(255,255,255,.14); margin-top: 38px; overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #ff9a1f, #ffd36b); transition: width .15s; }
#loading p { color: var(--dim); font-size: 14px; letter-spacing: .08em; margin-top: 14px; }
/* タイトル */
#title { align-items: center; justify-content: center; background: linear-gradient(180deg, rgba(10,8,6,.15) 0%, rgba(10,8,6,.55) 100%); }
.title-wrap { text-align: center; padding: 0 16px; }
.tag { font-size: clamp(15px, 2.4vw, 22px); letter-spacing: .24em; margin: 30px 0 28px; text-shadow: 0 2px 10px #000; }
.menu { display: flex; flex-direction: column; align-items: center; gap: 18px; }
.btn { font: 700 16px/1 "Zen Kaku Gothic New", sans-serif; letter-spacing: .12em; color: var(--ink); background: rgba(24,20,16,.7); border: 1px solid rgba(255,255,255,.35); padding: 14px 28px; cursor: pointer; transition: .15s; }
.btn:hover { background: rgba(255,154,31,.22); border-color: var(--acc); }
.btn.primary { font-size: 20px; padding: 16px 56px; background: linear-gradient(180deg, #ffb13b, #e8730c); border: none; color: #1a0e04; box-shadow: 0 6px 24px rgba(255,140,20,.35); }
.btn.primary:hover { filter: brightness(1.1); }
.opts { display: flex; gap: 22px; flex-wrap: wrap; justify-content: center; background: var(--panel); padding: 12px 20px; border: 1px solid var(--line); }
.opt { display: flex; align-items: center; gap: 10px; font-size: 14px; }
.opt input[type=range] { width: 110px; accent-color: var(--acc); }
.seg { display: inline-flex; border: 1px solid var(--line); }
.seg button { background: transparent; border: none; color: var(--dim); padding: 6px 14px; cursor: pointer; font: 700 14px "Zen Kaku Gothic New", sans-serif; }
.seg button.on { background: var(--acc); color: #1a0e04; }
.keys { max-width: 760px; font-size: 12.5px; color: #d8cfbf; line-height: 1.9; margin: 0; text-shadow: 0 1px 6px #000; }
.keys b { color: var(--acc2); font-weight: 700; }
.foot { margin: 0; font-size: 13px; }
/* 見出し */
.head { position: absolute; top: 0; left: 0; right: 0; display: flex; align-items: center; gap: 18px; padding: 16px 22px; background: linear-gradient(180deg, rgba(10,8,6,.85), transparent); z-index: 2; }
.head h2 { margin: 0; font-family: "Russo One", "Zen Kaku Gothic New", sans-serif; font-size: 22px; letter-spacing: .1em; }
.back { background: transparent; border: 1px solid var(--line); color: var(--ink); padding: 8px 16px; cursor: pointer; font: 700 14px "Zen Kaku Gothic New", sans-serif; }
.back:hover { border-color: var(--acc); }
/* 車選び */
#garage { background: linear-gradient(90deg, rgba(10,8,6,.0) 0%, rgba(10,8,6,0) 30%, rgba(10,8,6,.0) 60%, rgba(10,8,6,.5) 100%); }
.garage-grid { position: absolute; inset: 70px 18px 18px; display: grid; grid-template-columns: 210px 1fr 340px; gap: 14px; }
.car-list { overflow-y: auto; display: flex; flex-direction: column; gap: 6px; padding-right: 4px; touch-action: pan-y; }
.car-item { text-align: left; background: var(--panel); border: 1px solid var(--line); color: var(--ink); padding: 9px 12px; cursor: pointer; font: 700 14px "Zen Kaku Gothic New", sans-serif; display: block; }
.car-item small { display: block; color: var(--dim); font: 600 11px "Chakra Petch", sans-serif; letter-spacing: .1em; margin-top: 2px; }
.car-item.on { border-color: var(--acc); background: rgba(255,154,31,.2); }
.car-stage { position: relative; }
.car-title { position: absolute; left: 0; bottom: 6px; text-shadow: 0 2px 12px #000; }
.car-name { font-size: clamp(22px, 3.4vw, 38px); font-weight: 900; }
.car-en { font: 700 15px "Chakra Petch", sans-serif; letter-spacing: .3em; color: var(--acc2); }
.arrow { position: absolute; top: 50%; transform: translateY(-50%); width: 48px; height: 64px; background: var(--panel); border: 1px solid var(--line); color: #fff; font-size: 34px; cursor: pointer; }
.arrow.l { left: 0; } .arrow.r { right: 0; } .arrow:hover { border-color: var(--acc); }
.car-info { background: var(--panel); border: 1px solid var(--line); padding: 16px; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; touch-action: pan-y; }
.car-desc { margin: 0; font-size: 13.5px; line-height: 1.7; color: #e4dccb; min-height: 3.4em; }
.stat { display: grid; grid-template-columns: 92px 1fr 56px; align-items: center; gap: 8px; font-size: 13px; margin-bottom: 7px; }
.stat .bar2 { height: 10px; background: rgba(255,255,255,.12); position: relative; }
.stat .bar2 i { position: absolute; left: 0; top: 0; bottom: 0; background: linear-gradient(90deg, #ff9a1f, #ffd36b); transition: width .3s; }
.stat .v { text-align: right; font: 600 12px "Chakra Petch", sans-serif; color: var(--dim); }
.colors h3 { margin: 0 0 8px; font-size: 13px; color: var(--dim); font-weight: 700; letter-spacing: .1em; }
.swatches { display: flex; flex-wrap: wrap; gap: 7px; }
.sw { width: 30px; height: 30px; border: 2px solid rgba(255,255,255,.3); cursor: pointer; border-radius: 50%; padding: 0; }
.sw.on { border-color: #fff; box-shadow: 0 0 0 2px var(--acc); }
.sw.orig { background: conic-gradient(#d11a1a, #f2c200, #2b8a3e, #1b5fd1, #7a3fc0, #d11a1a); }
.custom { display: flex; align-items: center; gap: 10px; margin-top: 10px; font-size: 13px; color: var(--dim); }
.custom input { width: 46px; height: 30px; padding: 0; border: 1px solid var(--line); background: none; cursor: pointer; }
#btn-garage-next { margin-top: auto; }
/* コース選び */
#courses { background: linear-gradient(180deg, rgba(10,8,6,.35), rgba(10,8,6,.8)); }
.course-list { position: absolute; inset: 80px 22px 22px; display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; align-items: stretch; }
.course { position: relative; overflow: hidden; border: 1px solid var(--line); background: #181410 center/cover no-repeat; cursor: pointer; display: flex; flex-direction: column; justify-content: flex-end; min-height: 240px; transition: .2s; text-align: left; color: var(--ink); padding: 0; }
.course:hover { transform: translateY(-4px); border-color: var(--acc); box-shadow: 0 10px 40px rgba(255,140,20,.25); }
.course .shade { position: absolute; inset: 0; background: linear-gradient(180deg, rgba(0,0,0,0) 30%, rgba(8,6,4,.92) 88%); }
.course .body { position: relative; padding: 16px 18px 18px; }
.course .time { display: inline-block; font: 700 12px "Chakra Petch", sans-serif; letter-spacing: .2em; color: #1a0e04; background: var(--acc); padding: 2px 10px; margin-bottom: 8px; }
.course h3 { margin: 0; font-size: clamp(20px, 2.4vw, 28px); font-weight: 900; }
.course .en { font: 700 13px "Chakra Petch", sans-serif; letter-spacing: .26em; color: var(--acc2); margin: 2px 0 10px; }
.course p { margin: 0 0 10px; font-size: 13px; line-height: 1.7; color: #e4dccb; }
.course .meta { font-size: 12.5px; color: var(--dim); display: flex; gap: 14px; flex-wrap: wrap; }
.course .meta b { color: var(--ink); }
/* HUD */
#hud { position: fixed; inset: 0; display: none; pointer-events: none; z-index: 5; font-family: "Chakra Petch", "Zen Kaku Gothic New", sans-serif; text-shadow: 0 2px 8px rgba(0,0,0,.7); }
#hud.show { display: block; }
.hud-tl { position: absolute; left: 20px; top: calc(16px + env(safe-area-inset-top)); }
.rank { font-size: 64px; font-weight: 700; line-height: 1; font-style: italic; } .rank b { color: var(--acc2); } .rank span { font-size: 28px; color: var(--dim); }
.cpbox { margin-top: 6px; font-size: 16px; letter-spacing: .08em; } .cpbox b { font-size: 24px; color: var(--acc2); }
.hud-tc { position: absolute; left: 50%; top: calc(14px + env(safe-area-inset-top)); transform: translateX(-50%); text-align: center; }
.time { font-size: 40px; font-weight: 700; letter-spacing: .04em; font-variant-numeric: tabular-nums; }
.best { font-size: 13px; color: var(--dim); letter-spacing: .08em; }
#minimap { position: absolute; right: 16px; top: calc(14px + env(safe-area-inset-top)); width: 180px; height: 180px; opacity: .92; }
#navarrow { position: absolute; left: 50%; top: calc(112px + env(safe-area-inset-top)); width: 64px; margin-left: -32px; text-align: center; }
#navarrow i { display: block; width: 0; height: 0; margin: 0 auto 4px; border-left: 20px solid transparent; border-right: 20px solid transparent; border-bottom: 44px solid #ffd36b; filter: drop-shadow(0 2px 6px rgba(0,0,0,.8)); transform-origin: 50% 70%; }
#navarrow span { font-size: 16px; font-weight: 600; }
.hud-br { position: absolute; right: 22px; bottom: calc(18px + env(safe-area-inset-bottom)); text-align: right; }
.speed b { font-size: 84px; font-weight: 700; font-style: italic; line-height: 1; font-variant-numeric: tabular-nums; } .speed span { font-size: 20px; color: var(--dim); margin-left: 6px; }
.rev { width: 260px; height: 8px; background: rgba(255,255,255,.18); margin: 6px 0 4px auto; } .rev i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #ffd36b, #ff6a1a); }
.surf { font-size: 14px; color: var(--acc2); letter-spacing: .12em; min-height: 18px; }
.hud-bl { position: absolute; left: 20px; bottom: calc(20px + env(safe-area-inset-bottom)); font-size: 14px; color: #fff; letter-spacing: .06em; }
#center-msg { position: absolute; left: 0; right: 0; top: 30%; text-align: center; font-size: clamp(40px, 9vw, 110px); font-weight: 700; font-style: italic; letter-spacing: .06em; opacity: 0; }
#center-msg.show { animation: pop .9s ease-out; }
#center-msg.hold { opacity: 1; }
#center-msg small { display: block; font-size: .28em; letter-spacing: .1em; font-style: normal; color: var(--acc2); }
@keyframes pop { 0% { opacity: 0; transform: scale(1.6); } 15% { opacity: 1; transform: scale(1); } 75% { opacity: 1; } 100% { opacity: 0; transform: scale(.96); } }
#flash { position: absolute; inset: 0; background: #fff; opacity: 0; }
/* 結果 */
#result { align-items: center; justify-content: center; background: rgba(8,6,4,.62); }
.res-card { width: min(560px, 92vw); max-height: 94vh; overflow: auto; background: rgba(20,16,12,.92); border: 1px solid rgba(255,255,255,.2); padding: 24px 28px; text-align: center; }
.res-card h2 { margin: 0; font-family: "Russo One", sans-serif; letter-spacing: .2em; color: var(--acc2); font-size: 22px; }
.res-rank { margin: 6px 0 12px; } .res-rank b { font: italic 700 100px/1 "Chakra Petch", sans-serif; color: var(--acc); } .res-rank span { font-size: 30px; font-weight: 900; margin-left: 4px; }
.res-tab { width: 100%; border-collapse: collapse; font-size: 15px; margin-bottom: 12px; } .res-tab th, .res-tab td { padding: 7px 8px; border-top: 1px solid var(--line); text-align: left; } .res-tab th { color: var(--dim); width: 34%; font-weight: 500; } .res-tab td { font-weight: 700; }
.res-list { list-style: none; margin: 0 0 14px; padding: 0; font-size: 13px; color: #d8cfbf; text-align: left; } .res-list li { padding: 3px 8px; border-top: 1px solid rgba(255,255,255,.08); display: flex; justify-content: space-between; } .res-list li.me { color: var(--acc2); font-weight: 700; }
.res-btns { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; } .res-btns .btn { padding: 12px 18px; font-size: 14px; }
/* タッチ操作 */
#touch { position: fixed; inset: 0; z-index: 8; pointer-events: none; display: none; }
body.touch.racing #touch { display: block; }
#touch button { pointer-events: auto; position: absolute; background: rgba(20,16,12,.55); border: 2px solid rgba(255,255,255,.4); color: #fff; font: 700 14px "Zen Kaku Gothic New", sans-serif; touch-action: none; }
#touch .tl button { bottom: calc(26px + env(safe-area-inset-bottom)); width: 86px; height: 86px; font-size: 32px; border-radius: 50%; } #touch .tl button[data-k=left] { left: 22px; } #touch .tl button[data-k=right] { left: 128px; }
#touch .tr button { bottom: calc(26px + env(safe-area-inset-bottom)); width: 104px; height: 104px; border-radius: 50%; } #touch .tr button[data-k=gas] { right: 22px; background: rgba(255,154,31,.5); } #touch .tr button[data-k=brake] { right: 140px; width: 84px; height: 84px; }
#touch .tm button { bottom: calc(150px + env(safe-area-inset-bottom)); width: 64px; height: 50px; font-size: 11px; line-height: 1.2; border-radius: 8px; } #touch .tm button[data-k=hand] { right: 162px; bottom: calc(124px + env(safe-area-inset-bottom)); } #touch .tm button[data-k=reset] { right: 22px; bottom: calc(142px + env(safe-area-inset-bottom)); } #touch .tm button[data-k=view] { right: 90px; bottom: calc(142px + env(safe-area-inset-bottom)); }
#touch button.on { background: rgba(255,154,31,.8); }
@media (max-width: 480px) { #touch .tl button { width: 72px; height: 72px; } #touch .tl button[data-k=left] { left: 12px; } #touch .tl button[data-k=right] { left: 90px; } #touch .tr button { width: 92px; height: 92px; } #touch .tr button[data-k=gas] { right: 12px; } #touch .tr button[data-k=brake] { right: 112px; width: 72px; height: 72px; } }
@media (max-width: 900px) {
  .garage-grid { grid-template-columns: 1fr; grid-template-rows: auto minmax(160px, 1fr) auto; inset: 62px 10px 10px; gap: 8px; }
  .car-list { flex-direction: row; overflow-x: auto; overflow-y: hidden; padding-bottom: 4px; } .car-item { white-space: nowrap; flex: 0 0 auto; }
  .car-info { max-height: 44vh; padding: 12px; } .stat { margin-bottom: 4px; }
  .course-list { grid-template-columns: 1fr; overflow-y: auto; inset: 70px 12px 12px; touch-action: pan-y; } .course { min-height: 170px; }
  #minimap { width: 120px; height: 120px; } .speed b { font-size: 56px; } .rev { width: 180px; } .time { font-size: 28px; } .rank { font-size: 44px; }
  .hud-bl { display: none; }
}
@media (max-height: 520px) { .head { padding: 8px 14px; } .garage-grid { inset: 52px 10px 8px; } .tag { margin: 16px 0; } .keys { display: none; } }
/* 横向きのスマホ（高さが低い画面）は、パソコンと同じ3列に戻す */
@media (max-height: 520px) and (min-width: 700px) {
  .garage-grid { grid-template-columns: 150px 1fr 280px; grid-template-rows: none; inset: 50px 8px 6px; gap: 8px; }
  .car-list { flex-direction: column; overflow-x: hidden; overflow-y: auto; } .car-item { padding: 6px 8px; font-size: 12px; white-space: normal; } .car-item small { font-size: 10px; }
  .car-info { max-height: none; padding: 10px; gap: 8px; } .car-desc { font-size: 12px; min-height: 0; } .stat { font-size: 11.5px; margin-bottom: 3px; grid-template-columns: 78px 1fr 48px; }
  .sw { width: 24px; height: 24px; } #btn-garage-next { padding: 10px; font-size: 15px; } .car-name { font-size: 22px; } .arrow { width: 36px; height: 48px; font-size: 26px; }
  .course-list { grid-template-columns: repeat(3, 1fr); overflow: visible; inset: 54px 10px 8px; gap: 10px; } .course { min-height: 0; } .course p { font-size: 11px; line-height: 1.5; margin-bottom: 6px; } .course h3 { font-size: 18px; } .course .meta { font-size: 11px; gap: 8px; } .course .body { padding: 10px; }
}
/* タッチ操作のときは、速度表示を下の中央へ（ボタンと重ならないように） */
body.touch .hud-br { right: auto; left: 50%; transform: translateX(-50%); text-align: center; bottom: calc(10px + env(safe-area-inset-bottom)); }
body.touch .speed b { font-size: 46px; } body.touch .speed span { font-size: 14px; } body.touch .rev { width: 150px; margin: 4px auto; } body.touch .surf { min-height: 14px; font-size: 12px; }
body.touch .hud-tl .rank { font-size: 40px; } body.touch .time { font-size: 26px; } body.touch .cpbox { font-size: 13px; }

/* タイトル：文字を左に寄せ、車は右に見せる */
#title { justify-content: flex-start; padding-left: clamp(16px, 7vw, 120px); }
.title-wrap { text-align: left; padding: 0; } .menu { align-items: flex-start; } .opts { justify-content: flex-start; } .keys { max-width: 560px; }
@media (max-width: 900px) { #title { justify-content: center; padding-left: 0; } .title-wrap { text-align: center; padding: 0 12px; } .menu { align-items: center; } }

/* 戻る・ポーズのボタン、暗転、ポーズの画面 */
.hud-btns { position: absolute; right: 16px; top: calc(206px + env(safe-area-inset-top)); display: flex; flex-direction: column; gap: 8px; pointer-events: auto; }
.hud-btns button { font: 700 15px "Zen Kaku Gothic New", sans-serif; letter-spacing: .06em; color: #fff; background: rgba(20,16,12,.72); border: 1px solid rgba(255,255,255,.4); padding: 10px 16px; cursor: pointer; text-shadow: none; }
.hud-btns button:hover { background: rgba(255,154,31,.5); border-color: var(--acc); }
#fade { position: fixed; inset: 0; background: #000; opacity: 0; pointer-events: none; z-index: 30; }
#pause { align-items: center; justify-content: center; background: rgba(8,6,4,.7); z-index: 40; }
.pz { width: min(420px, 90vw); } .pz-btns { display: flex; flex-direction: column; gap: 12px; margin-top: 18px; } .pz-btns .btn { padding: 15px; font-size: 17px; }
.speed b { font-size: 132px; } .speed span { font-size: 26px; } .rev { width: 320px; height: 10px; }
body.touch .speed b { font-size: 60px; } body.touch .hud-btns { right: auto; left: 10px; top: 104px; } body.touch .hud-btns button { padding: 6px 10px; font-size: 12px; } body.touch #btn-recover { display: none; }
@media (max-width: 900px) { .hud-btns { top: 142px; right: 10px; } .hud-btns button { padding: 6px 10px; font-size: 12px; } .speed b { font-size: 72px; } }
@media (max-width: 480px) { body.touch .hud-br { bottom: calc(210px + env(safe-area-inset-bottom)); } }
/* 縦長の画面：上の表示を、左の列（時計・自己ベスト・順位・チェックポイント・ポーズ）と右の列（地図・矢印）に分けて並べる */
@media (max-width: 480px) {
  body .hud-tc { left: 12px; transform: none; text-align: left; top: calc(10px + env(safe-area-inset-top)); }
  body .hud-tl { left: 12px; top: calc(70px + env(safe-area-inset-top)); }
  body #navarrow { left: auto; right: 40px; margin-left: 0; top: calc(142px + env(safe-area-inset-top)); }
  body .hud-btns, body.touch .hud-btns { left: 12px; right: auto; top: calc(158px + env(safe-area-inset-top)); }
}
.speed { display: flex; align-items: baseline; justify-content: flex-end; } body.touch .speed { justify-content: center; }
#view-name { position: absolute; left: 0; right: 0; top: 17%; text-align: center; font-size: clamp(18px, 3vw, 30px); font-weight: 700; letter-spacing: .12em; opacity: 0; transition: opacity .18s; pointer-events: none; } #view-name.show { opacity: 1; }
body.touch #btn-view { display: none; }
