* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; user-select: none; }
html, body {
  margin: 0; padding: 0; width: 100%; height: 100%; overflow: hidden;
  background: #060814; color: #e8ecff;
  font-family: 'Segoe UI', 'Hiragino Kaku Gothic ProN', 'Yu Gothic', sans-serif;
}

.screen {
  position: fixed; inset: 0;
  display: flex; flex-direction: column;
  background: #060814;
}
.hidden { display: none !important; }

/* ---------- Title ---------- */
#screenTitle { align-items: center; justify-content: center; }
.bgGlow {
  position: absolute; inset: 0;
  background: radial-gradient(circle at 50% 35%, rgba(77,240,255,0.18), transparent 55%),
              radial-gradient(circle at 70% 70%, rgba(200,107,255,0.14), transparent 55%);
  animation: pulse 5s ease-in-out infinite;
}
@keyframes pulse { 0%,100%{opacity:0.7;} 50%{opacity:1;} }
.titleWrap { position: relative; text-align: center; padding: 20px; }
.logo {
  font-size: clamp(2rem, 8vw, 3.6rem); margin: 0; letter-spacing: 2px;
  color: #4df0ff; text-shadow: 0 0 18px rgba(77,240,255,0.7), 0 0 40px rgba(77,240,255,0.3);
}
.logo span { color: #c86bff; text-shadow: 0 0 18px rgba(200,107,255,0.7), 0 0 40px rgba(200,107,255,0.3); }
.tagline { color: #9aa4d0; margin: 6px 0 30px; font-size: 1rem; }
.titleButtons { display: flex; flex-direction: column; gap: 12px; align-items: center; }

.bigBtn, .smallBtn, .hudBtn {
  font-family: inherit; cursor: pointer; border-radius: 12px; font-weight: 700;
  border: 1px solid rgba(77,240,255,0.4);
  background: linear-gradient(180deg, rgba(77,240,255,0.16), rgba(77,240,255,0.05));
  color: #e8ecff;
}
.bigBtn { padding: 14px 40px; font-size: 1.1rem; box-shadow: 0 0 20px rgba(77,240,255,0.25); }
.bigBtn:active { transform: scale(0.97); }
.smallBtn { padding: 10px 20px; font-size: 0.9rem; opacity: 0.9; }
.smallBtn:active { transform: scale(0.97); }

/* ---------- Header bar (shared) ---------- */
.headerBar {
  display: flex; align-items: center; gap: 12px; padding: 14px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.headerBar h2 { margin: 0; font-size: 1.1rem; color: #cfe9ff; }
.backBtn {
  width: 38px; height: 38px; border-radius: 50%; border: 1px solid rgba(255,255,255,0.2);
  background: rgba(255,255,255,0.05); color: #e8ecff; font-size: 1.1rem; cursor: pointer;
}

/* ---------- How to ---------- */
.howToBody { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.howToCard {
  display: flex; gap: 14px; align-items: flex-start; padding: 14px;
  background: rgba(255,255,255,0.04); border: 1px solid rgba(255,255,255,0.08); border-radius: 12px;
  line-height: 1.5; font-size: 0.92rem; color: #cfd6f5;
}
.howToIcon { font-size: 1.6rem; flex-shrink: 0; }
.howToCard b { color: #4df0ff; }

/* ---------- Level select ---------- */
.levelGrid {
  flex: 1; overflow-y: auto; padding: 18px;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px;
}
.levelCard {
  position: relative; border-radius: 14px; padding: 16px 10px; text-align: center;
  background: rgba(255,255,255,0.05); border: 1px solid rgba(77,240,255,0.25);
  cursor: pointer; color: #e8ecff;
}
.levelCard.locked { opacity: 0.4; cursor: default; }
.levelCard .lvNum { font-size: 1.6rem; font-weight: 800; color: #4df0ff; }
.levelCard .lvName { font-size: 0.72rem; color: #9aa4d0; margin-top: 4px; min-height: 2.4em; }
.levelCard .lvStars { margin-top: 6px; font-size: 0.9rem; letter-spacing: 2px; color: #ffd76b; }
.levelCard .lvLock { font-size: 1.6rem; }

/* ---------- Game screen ---------- */
#screenGame { background: #04050c; }
.gameHud {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px;
  border-bottom: 1px solid rgba(255,255,255,0.08); flex-shrink: 0;
}
.hudBtn {
  width: 40px; height: 40px; border-radius: 10px; font-size: 1.1rem; cursor: pointer; flex-shrink: 0;
}
.hudCenter { flex: 1; min-width: 0; }
.hudLevelName { font-size: 0.78rem; color: #9aa4d0; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tickBarWrap { height: 8px; border-radius: 4px; background: rgba(255,255,255,0.08); margin-top: 4px; overflow: hidden; }
.tickBarFill { height: 100%; width: 100%; background: linear-gradient(90deg,#4df0ff,#c86bff); transition: width 0.15s linear; }
.hudLoop { font-size: 0.85rem; font-weight: 700; color: #ffd76b; white-space: nowrap; flex-shrink: 0; }

.canvasWrap { flex: 1; position: relative; display: flex; align-items: center; justify-content: center; overflow: hidden; min-height: 0; }
#gameCanvas { background: #0a0e1e; image-rendering: pixelated; max-width: 100%; max-height: 100%; }

.hintBox {
  position: absolute; left: 10px; right: 10px; bottom: 10px;
  background: rgba(6,8,20,0.92); border: 1px solid rgba(77,240,255,0.35); border-radius: 12px;
  padding: 12px 14px; font-size: 0.82rem; line-height: 1.5; color: #cfd6f5; cursor: pointer;
}
.hintBox::after { content: '(タップで閉じる)'; display: block; margin-top: 6px; color: #6d78a8; font-size: 0.72rem; }

.victoryModal {
  position: absolute; inset: 0; background: rgba(2,3,10,0.82);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.victoryCard {
  background: #0c1024; border: 1px solid rgba(77,240,255,0.4); border-radius: 18px;
  padding: 26px 22px; text-align: center; max-width: 340px; width: 100%;
  box-shadow: 0 0 40px rgba(77,240,255,0.25);
}
.victoryTitle { font-size: 1.8rem; font-weight: 800; color: #4df0ff; text-shadow: 0 0 16px rgba(77,240,255,0.6); }
.victoryStars { font-size: 2rem; margin: 10px 0; color: #ffd76b; letter-spacing: 4px; }
.victoryLoops { color: #9aa4d0; font-size: 0.85rem; margin-bottom: 18px; }
.victoryButtons { display: flex; flex-direction: column; gap: 10px; }

/* ---------- D-Pad (touch) ---------- */
.dpad {
  position: relative; height: 150px; flex-shrink: 0; margin: 6px auto 14px;
  width: 150px; display: grid;
  grid-template-columns: 46px 46px 46px; grid-template-rows: 46px 46px 46px;
}
.dpadBtn {
  border-radius: 10px; border: 1px solid rgba(77,240,255,0.35);
  background: rgba(77,240,255,0.1); color: #cfe9ff; font-size: 1.1rem; cursor: pointer;
}
.dpadBtn:active { background: rgba(77,240,255,0.3); }
.dpadUp { grid-column: 2; grid-row: 1; }
.dpadLeft { grid-column: 1; grid-row: 2; }
.dpadRight { grid-column: 3; grid-row: 2; }
.dpadDown { grid-column: 2; grid-row: 3; }

@media (min-width: 820px) {
  .dpad { display: none; }
}
