:root {
  --bg: #080c1a;
  --panel: rgba(15, 23, 46, 0.85);
  --border: rgba(125, 211, 252, 0.24);
  --accent: #ff4d6d;
  --cyan: #4cc9f0;
  --gold: #ffd166;
  --text: #f1f5f9;
  --muted: #94a3b8;
}

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

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: radial-gradient(circle at top, #172347 0%, var(--bg) 75%);
  color: var(--text);
  font-family: 'Segoe UI', 'Hiragino Kaku Gothic ProN', 'Yu Gothic', sans-serif;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

input,
select,
button {
  font-family: inherit;
}

.app-shell {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* HUDバー */
.hud-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  paddind: 6px 12px;
  background: rgba(9, 13, 28, 0.85);
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  flex-shrink: 0;
  z-index: 10;
}

.hud-stats {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.hud-pill {
  background: rgba(30, 41, 74, 0.85);
  border: 1px solid rgba(148, 163, 184, 0.25);
  border-radius: 999px;
  padding: 3px 10px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.hud-stage {
  color: var(--cyan);
  border-color: rgba(76, 201, 240, 0.4);
}

.hud-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.icon-btn {
  background: rgba(30, 41, 74, 0.9);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 5px 9px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.icon-btn:active {
  transform: scale(0.95);
}

/* ゲームメイン領域 */
.stage-area {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 6px;
}

.canvas-frame {
  position: relative;
  width: 100%;
  max-width: 960px;
  max-height: 100%;
  aspect-ratio: 480 / 272;
  border-radius: 12px;
  overflow: hidden;
  border: 2px solid rgba(125, 211, 252, 0.35);
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.65);
  background: #0b1021;
}

#game-canvas {
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.hint-bar {
  margin-top: 6px;
  font-size: 12px;
  color: #cbd5e1;
  text-align: center;
  background: rgba(15, 23, 42, 0.65);
  padding: 4px 12px;
  border-radius: 999px;
  max-width: 95%;
}

/* モバイルコントローラーデッキ（縦画面では下部に専用領域、PCでは非表示/控えめ） */
.touch-deck {
  display: flex;
  align-items: stretch;
  justify-content: space-between;
  flex: 0 0 215px;
  width: 100%;
  background: linear-gradient(180deg, rgba(11, 17, 36, 0.6) 0%, rgba(7, 10, 22, 0.96) 100%);
  border-top: 1px solid var(--border);
  position: relative;
  z-index: 8;
}

@media (hover: hover) and (pointer: fine) {
  body:not(.touch-active) .touch-deck {
    flex: 0 0 42px;
    justify-content: center;
    align-items: center;
  }
  body:not(.touch-active) .touch-left,
  body:not(.touch-active) .touch-right {
    display: none;
  }
  .pc-controls-tip {
    display: block;
    font-size: 12px;
    color: var(--muted);
  }
}

@media (hover: none), (pointer: coarse) {
  .pc-controls-tip {
    display: none;
  }
}

.touch-active .pc-controls-tip {
  display: none !important;
}

/* 横画面（モバイルランドスケープ）ではオーバーレイ化 */
@media (max-height: 520px) and (orientation: landscape) {
  .stage-area {
    padding: 0;
  }
  .canvas-frame {
    height: 100%;
    width: auto;
    border-radius: 0;
    border: none;
  }
  .hint-bar {
    display: none;
  }
  .touch-deck {
    position: fixed;
    inset: auto 0 0 0;
    height: 185px;
    background: transparent;
    border-top: none;
    pointer-events: none;
  }
  .touch-left,
  .touch-right {
    pointer-events: auto;
    width: 44% !important;
  }
}

.touch-left,
.touch-right {
  position: relative;
  width: 50%;
  height: 100%;
  touch-action: none;
}

.zone-label {
  position: absolute;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 11px;
  color: rgba(148, 163, 184, 0.65);
  pointer-events: none;
  white-space: nowrap;
}

/* フローティングスティック */
.stick-ghost {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 96px;
  height: 96px;
  border-radius: 50%;
  border: 2px dashed rgba(125, 211, 252, 0.25);
  pointer-events: none;
}

.stick-base {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 98px;
  height: 98px;
  border-radius: 50%;
  background: rgba(30, 41, 74, 0.42);
  border: 2px solid rgba(125, 211, 252, 0.45);
  box-shadow: inset 0 0 18px rgba(76, 201, 240, 0.15);
  pointer-events: none;
  opacity: 0.7;
  transition: opacity 0.12s;
}

.stick-base.is-active {
  opacity: 1;
  border-color: var(--cyan);
}

.stick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #a5f3fc, #38bdf8);
  box-shadow: 0 4px 16px rgba(56, 189, 248, 0.5);
}

/* 右側ボタン配置 */
.pad-cluster {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 20px;
  gap: 16px;
}

.pad-btn {
  width: 78px;
  height: 78px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.35);
  color: #ffffff;
  font-weight: 800;
  font-size: 13px;
  letter-spacing: 0.04em;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  touch-action: none;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.45);
  transition: transform 0.06s, filter 0.06s;
}

.pad-btn small {
  font-size: 9px;
  opacity: 0.85;
  font-weight: 600;
}

.btn-jump {
  margin-top: 26px;
  background: radial-gradient(circle at 35% 30%, #60a5fa, #2563eb);
}

.btn-dash {
  margin-bottom: 26px;
  background: radial-gradient(circle at 35% 30%, #ff758f, #e11d48);
}

.pad-btn.is-pressed {
  transform: scale(0.91);
  filter: brightness(1.25);
  border-color: #ffffff;
}

.swipe-indicator {
  position: fixed;
  width: 44px;
  height: 8px;
  background: linear-gradient(90deg, transparent, #ffd166);
  border-radius: 99px;
  pointer-events: none;
  opacity: 0;
  z-index: 50;
}

.swipe-indicator.is-firing {
  animation: swipeFlash 0.25s ease-out forwards;
}

@keyframes swipeFlash {
  0% {
    opacity: 1;
    width: 24px;
  }
  100% {
    opacity: 0;
    width: 72px;
  }
}

/* モーダル & オーバーレイ */
.overlay-modal {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(5, 8, 18, 0.82);
  backdrop-filter: blur(8px);
  z-index: 100;
  padding: 16px;
  touch-action: auto;
}

.overlay-modal.is-open {
  display: flex;
}

.modal-card {
  width: 100%;
  max-width: 480px;
  max-height: 90dvh;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.75);
  touch-action: pan-y;
}

.title-logo {
  margin: 0;
  font-size: 26px;
  font-weight: 900;
  letter-spacing: 0.06em;
  background: linear-gradient(90deg, #4cc9f0, #ff4d6d, #ffd166);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.title-sub {
  margin: 4px 0 12px;
  font-size: 13px;
  color: #cbd5e1;
}

.daily-banner {
  background: rgba(76, 201, 240, 0.14);
  border: 1px solid rgba(76, 201, 240, 0.4);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 12px;
  color: #bae6fd;
  margin-bottom: 14px;
}

.primary-btn {
  width: 100%;
  padding: 12px 16px;
  border: none;
  border-radius: 12px;
  background: linear-gradient(90deg, #ff4d6d, #f43f5e);
  color: #fff;
  font-size: 16px;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(255, 77, 109, 0.4);
}

.secondary-btn {
  padding: 9px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(30, 41, 74, 0.9);
  color: var(--text);
  font-weight: 700;
  cursor: pointer;
}

.chapter-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-top: 12px;
}

.chapter-pill {
  padding: 8px 10px;
  border-radius: 9px;
  border: 1px solid rgba(148, 163, 184, 0.28);
  background: rgba(15, 23, 42, 0.7);
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
}

.chapter-pill:hover {
  border-color: var(--cyan);
}

.control-guide {
  margin-top: 14px;
  padding: 10px 12px;
  background: rgba(15, 23, 42, 0.6);
  border-radius: 10px;
  font-size: 12px;
  line-height: 1.55;
  color: #cbd5e1;
}

.assist-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid rgba(148, 163, 184, 0.16);
  font-size: 14px;
}

.assist-row select {
  background: #0f172a;
  color: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 5px 10px;
}

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

.stat-box {
  background: rgba(15, 23, 42, 0.75);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 6px;
  text-align: center;
}

.stat-box span {
  display: block;
  font-size: 11px;
  color: var(--muted);
}

.stat-box strong {
  font-size: 16px;
  color: var(--gold);
}

.score-form {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.score-form input {
  flex: 1;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #0b1224;
  color: #fff;
  font-size: 14px;
  user-select: text;
  -webkit-user-select: text;
  touch-action: auto;
}

.leaderboard-list {
  list-style: none;
  margin: 10px 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.lb-row {
  display: grid;
  grid-template-columns: 32px 1fr auto auto;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  background: rgba(15, 23, 42, 0.7);
  border-radius: 8px;
  font-size: 12px;
}

.lb-rank {
  font-weight: 800;
  color: var(--gold);
}

.lb-time {
  font-weight: 800;
  color: var(--cyan);
  font-variant-numeric: tabular-nums;
}

.lb-meta {
  color: var(--muted);
  font-size: 11px;
}

.tag-pure,
.tag-assist {
  font-size: 9px;
  padding: 1px 5px;
  border-radius: 4px;
  margin-left: 4px;
}

.tag-pure {
  background: rgba(82, 183, 136, 0.25);
  color: #80ed99;
}

.tag-assist {
  background: rgba(251, 191, 36, 0.2);
  color: #fcd34d;
}

.modal-footer {
  display: flex;
  gap: 8px;
  margin-top: 14px;
  justify-content: flex-end;
}

.status-msg {
  font-size: 12px;
  color: var(--cyan);
  min-height: 18px;
  margin-top: 6px;
}
