:root {
  color-scheme: dark;
  --ink: #211b45;
  --cream: #fff8df;
  --mint: #8ff0ce;
  --mint-dark: #247a70;
  --pink: #ff7aa8;
  --gold: #ffd86b;
  --violet: #6859c7;
  --panel: rgba(24, 20, 61, .93);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html,
body,
#app {
  width: 100%;
  height: 100%;
}

body {
  overflow: hidden;
  background:
    radial-gradient(circle at 18% 14%, rgba(123, 113, 220, .34), transparent 34%),
    radial-gradient(circle at 78% 82%, rgba(50, 195, 178, .18), transparent 30%),
    #0f0d2d;
  color: var(--cream);
  font-family: "Yu Gothic UI", "Hiragino Kaku Gothic ProN", "Meiryo", sans-serif;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

button,
input {
  font: inherit;
  touch-action: manipulation;
}

button:focus-visible,
input:focus-visible,
canvas:focus-visible {
  outline: 4px solid #fff;
  outline-offset: 4px;
}

#gameWrap {
  position: fixed;
  left: 50%;
  top: 50%;
  width: min(100vw, calc(100vh * 16 / 9));
  aspect-ratio: 16 / 9;
  transform: translate(-50%, -50%);
  overflow: hidden;
  border-radius: clamp(0px, 1.7vw, 22px);
  box-shadow: 0 28px 80px rgba(0, 0, 0, .42);
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  background: #29235f;
}

#ui {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: none;
  align-items: center;
  justify-content: center;
  padding: max(18px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
  background: rgba(8, 7, 29, .34);
  overflow-y: auto;
}

#ui.show {
  display: flex;
}

.panel {
  width: min(760px, 94vw);
  max-height: min(94vh, 760px);
  overflow-y: auto;
  padding: clamp(22px, 4.3vw, 42px);
  text-align: center;
  background:
    linear-gradient(155deg, rgba(255, 255, 255, .07), transparent 34%),
    var(--panel);
  border: 3px solid rgba(255, 248, 223, .88);
  border-radius: 28px;
  box-shadow:
    0 0 0 7px rgba(104, 89, 199, .58),
    0 22px 70px rgba(0, 0, 0, .5);
}

.eyebrow {
  margin-bottom: 8px;
  color: var(--mint);
  font-size: clamp(12px, 2vw, 15px);
  font-weight: 800;
  letter-spacing: .2em;
}

.panel h1 {
  color: var(--cream);
  font-size: clamp(34px, 7vw, 66px);
  line-height: 1.05;
  letter-spacing: .03em;
  text-shadow: 0 5px 0 #5a4398, 0 10px 28px rgba(0, 0, 0, .45);
}

.panel h1 .accent,
.panel h2 .accent {
  color: var(--gold);
}

.panel h2 {
  font-size: clamp(25px, 5vw, 42px);
  line-height: 1.2;
}

.lead {
  max-width: 590px;
  margin: 18px auto 0;
  color: #e9e4ff;
  font-size: clamp(14px, 2.4vw, 18px);
  line-height: 1.8;
}

.small {
  color: #b9b2df;
  font-size: 12px;
  line-height: 1.65;
}

.menu {
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  justify-content: center;
  gap: 12px;
  margin-top: 24px;
}

.menu.vertical {
  flex-direction: column;
  align-items: center;
}

.btn {
  position: relative;
  min-width: 220px;
  padding: 13px 24px 12px;
  border: 3px solid #fff;
  border-radius: 999px;
  background: linear-gradient(#ff92b8, var(--pink));
  color: #2d1737;
  font-weight: 900;
  letter-spacing: .04em;
  cursor: pointer;
  box-shadow: 0 6px 0 #a93867, 0 12px 24px rgba(0, 0, 0, .25);
}

.btn:hover {
  filter: brightness(1.07);
}

.btn:active {
  transform: translateY(5px);
  box-shadow: 0 1px 0 #a93867;
}

.btn.secondary {
  background: linear-gradient(#aaf7dc, var(--mint));
  color: #173d3a;
  box-shadow: 0 6px 0 var(--mint-dark), 0 12px 24px rgba(0, 0, 0, .25);
}

.btn.ghost {
  background: rgba(255, 255, 255, .08);
  color: var(--cream);
  border-color: rgba(255, 255, 255, .7);
  box-shadow: 0 5px 0 rgba(0, 0, 0, .34);
}

.btn small {
  display: block;
  margin-top: 3px;
  font-size: 11px;
  font-weight: 600;
  opacity: .78;
}

.courseGrid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 22px;
  text-align: left;
}

.courseCard {
  min-height: 112px;
  padding: 16px;
  border: 2px solid rgba(255, 255, 255, .35);
  border-radius: 18px;
  background: rgba(255, 255, 255, .07);
  color: var(--cream);
  cursor: pointer;
}

.courseCard:hover,
.courseCard:focus-visible {
  border-color: var(--gold);
  background: rgba(255, 216, 107, .1);
}

.courseCard strong {
  display: block;
  margin-bottom: 5px;
  color: var(--gold);
  font-size: 18px;
}

.courseCard span {
  color: #d9d4f2;
  font-size: 13px;
  line-height: 1.5;
}

.howto {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 22px 0;
}

.howStep {
  padding: 15px 10px;
  border-radius: 17px;
  background: rgba(255, 255, 255, .07);
}

.howStep b {
  display: block;
  margin-bottom: 7px;
  color: var(--gold);
  font-size: 21px;
}

.howStep span {
  font-size: 13px;
  line-height: 1.5;
}

.settingsRow {
  display: grid;
  grid-template-columns: minmax(130px, 1fr) minmax(220px, 2fr) 80px;
  gap: 14px;
  align-items: center;
  margin: 26px 0 12px;
  text-align: left;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--pink);
}

#actionDock {
  position: fixed;
  z-index: 15;
  left: auto;
  right: calc(22px + env(safe-area-inset-right));
  bottom: calc(16px + env(safe-area-inset-bottom));
  display: none;
  transform: none;
}

#actionDock.show {
  display: block;
}

#actionBtn {
  width: clamp(126px, 18vw, 176px);
  height: clamp(76px, 10vw, 98px);
  border: 4px solid white;
  border-radius: 50%;
  background: radial-gradient(circle at 42% 28%, #fff2a8, var(--gold) 43%, #f49b55 100%);
  color: #4f2a37;
  cursor: pointer;
  box-shadow: 0 8px 0 #ad563e, 0 14px 30px rgba(0, 0, 0, .34);
}

#actionBtn.locked {
  background: radial-gradient(circle at 42% 28%, #ffc5cb, #ef7885 48%, #a44358 100%);
  color: #fff;
  cursor: not-allowed;
  box-shadow: 0 8px 0 #6e2b3d, 0 14px 30px rgba(0, 0, 0, .34);
}

#actionBtn.locked:active,
#actionBtn.locked.on {
  transform: none;
  box-shadow: 0 8px 0 #6e2b3d, 0 14px 30px rgba(0, 0, 0, .34);
}

#actionBtn:active,
#actionBtn.on {
  transform: translateY(6px) scale(.98);
  box-shadow: 0 2px 0 #ad563e, 0 7px 16px rgba(0, 0, 0, .3);
}

.actionSpark {
  margin-right: 3px;
  color: #fff;
  font-size: 22px;
}

.actionLabel {
  font-size: clamp(22px, 4vw, 34px);
  font-weight: 1000;
}

.actionKey {
  display: block;
  margin-top: 2px;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .1em;
}

#systemButtons {
  position: fixed;
  z-index: 30;
  top: calc(9px + env(safe-area-inset-top));
  right: calc(9px + env(safe-area-inset-right));
  display: flex;
  gap: 8px;
}

#systemButtons button {
  width: 43px;
  height: 43px;
  border: 2px solid rgba(255, 255, 255, .66);
  border-radius: 13px;
  background: rgba(20, 16, 58, .7);
  color: #fff;
  font-size: 19px;
  font-weight: 900;
  cursor: pointer;
  backdrop-filter: blur(7px);
}

#systemButtons button:disabled {
  opacity: .35;
  cursor: default;
}

.resultRing {
  width: 126px;
  height: 126px;
  margin: 20px auto 14px;
  display: grid;
  place-items: center;
  border: 10px solid var(--mint);
  border-radius: 50%;
  background: rgba(255, 255, 255, .06);
  box-shadow: 0 0 30px rgba(143, 240, 206, .28);
}

.resultRing strong {
  display: block;
  color: var(--gold);
  font-size: 34px;
  line-height: 1;
}

.resultRing span {
  font-size: 11px;
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin: 16px 0;
}

.stat {
  padding: 10px 5px;
  border-radius: 12px;
  background: rgba(255, 255, 255, .07);
}

.stat b {
  display: block;
  color: var(--gold);
  font-size: 21px;
}

.stat span {
  color: #c9c3e7;
  font-size: 10px;
}

.srOnly {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

@media (max-width: 640px) {
  .courseGrid {
    grid-template-columns: 1fr;
  }

  .howto {
    grid-template-columns: 1fr;
  }

  .settingsRow {
    grid-template-columns: 1fr;
    text-align: center;
  }

  .panel {
    border-radius: 20px;
  }
}

@media (orientation: portrait) {
  /*
   * 縦持ちで16:9をそのまま入れると、375px幅の端末で盤面が375x211（画面の26%）にしかならず、
   * HUDの文字が実寸7px程度になって読めなかった。
   * リズムレーダーはキャンバス座標の x240〜720 に収まっているので、その中央480pxだけを
   * 切り出して見せる（= 8:9）。同じ端末で盤面が375x422になり、盤面もHUDも約2倍になる。
   * 切り落とす範囲は js/game.js の PORTRAIT_CROP と対になっている。
   */
  #gameWrap {
    /* 盤面が画面幅いっぱいになるぶん、右上の音量・一時停止ボタン（高さ43px）が
       HUDバーのCOMBO表示に重なる。その下から始める。 */
    top: calc(env(safe-area-inset-top) + 62px);
    width: min(100vw, 68vh * 8 / 9);
    aspect-ratio: 8 / 9;
    transform: translate(-50%, 0);
    border-radius: 0;
  }

  #gameWrap canvas {
    position: absolute;
    top: 0;
    left: -50%;
    width: 200%;
    height: 100%;
  }

  #actionDock {
    left: 50%;
    right: auto;
    bottom: calc(9vh + env(safe-area-inset-bottom));
    transform: translateX(-50%);
  }

  #actionBtn {
    width: clamp(190px, 58vw, 260px);
    height: clamp(100px, 28vw, 132px);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: .001ms !important;
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
  }
}
