/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; }

[hidden] { display: none !important; }

:root {
  --indigo-deep:   #0b0d1a;
  --indigo-mid:    #111428;
  --teal-glow:     #2dd4bf;
  --teal-dim:      #0d9488;
  --aurora-1:      #1e3a5f;
  --aurora-2:      #0f4c4c;
  --aurora-3:      #2d1b4e;
  --text-primary:  #e8eaf6;
  --text-muted:    rgba(232,234,246,0.45);
  --glass-bg:      rgba(255,255,255,0.06);
  --glass-border:  rgba(255,255,255,0.12);
  --btn-hover:     rgba(45,212,191,0.15);
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--indigo-deep);
  color: var(--text-primary);
  font-family: 'Jost', sans-serif;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

/* ── Title Screen ── */
#title-screen {
  position: fixed;
  inset: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
}

/* Aurora background layers */
.bg-aurora {
  position: absolute;
  inset: -40%;
  background:
    radial-gradient(ellipse 70% 50% at 20% 60%, var(--aurora-1) 0%, transparent 60%),
    radial-gradient(ellipse 60% 45% at 80% 30%, var(--aurora-2) 0%, transparent 55%),
    radial-gradient(ellipse 80% 60% at 50% 80%, var(--aurora-3) 0%, transparent 50%);
  animation: aurora-drift 12s ease-in-out infinite alternate;
  will-change: transform;
}

@keyframes aurora-drift {
  0%   { transform: translate(0, 0) scale(1); }
  33%  { transform: translate(-2%, 1.5%) scale(1.03); }
  66%  { transform: translate(1.5%, -1%) scale(0.98); }
  100% { transform: translate(-1%, 2%) scale(1.02); }
}

/* Subtle star field */
.bg-stars {
  position: absolute;
  inset: 0;
  background-image:
    radial-gradient(1px 1px at 15% 20%, rgba(255,255,255,0.6) 0%, transparent 100%),
    radial-gradient(1px 1px at 72% 8%, rgba(255,255,255,0.5) 0%, transparent 100%),
    radial-gradient(1.5px 1.5px at 40% 75%, rgba(255,255,255,0.4) 0%, transparent 100%),
    radial-gradient(1px 1px at 88% 55%, rgba(255,255,255,0.5) 0%, transparent 100%),
    radial-gradient(1px 1px at 25% 88%, rgba(255,255,255,0.3) 0%, transparent 100%),
    radial-gradient(1px 1px at 60% 35%, rgba(255,255,255,0.4) 0%, transparent 100%),
    radial-gradient(1px 1px at 5%  50%, rgba(255,255,255,0.35) 0%, transparent 100%),
    radial-gradient(1px 1px at 93% 82%, rgba(255,255,255,0.3) 0%, transparent 100%);
  opacity: 0.8;
  animation: stars-twinkle 8s ease-in-out infinite alternate;
}

@keyframes stars-twinkle {
  0%   { opacity: 0.6; }
  50%  { opacity: 1; }
  100% { opacity: 0.7; }
}

/* Title content */
.title-content {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  animation: fade-in-up 1.2s cubic-bezier(0.16, 1, 0.3, 1) both;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

@keyframes fade-in-up {
  from { opacity: 0; transform: translateY(24px); }
  to   { opacity: 1; transform: translateY(0); }
}

.title-text {
  font-family: 'Cormorant Garamond', serif;
  font-weight: 300;
  font-size: clamp(3rem, 10vw, 6rem);
  letter-spacing: 0.12em;
  margin: 0;
  color: var(--text-primary);
  text-shadow:
    0 0 40px rgba(45,212,191,0.35),
    0 0 80px rgba(45,212,191,0.15);
  animation: title-breathe 5s ease-in-out infinite alternate;
}

@keyframes title-breathe {
  from { text-shadow: 0 0 30px rgba(45,212,191,0.25), 0 0 60px rgba(45,212,191,0.1); }
  to   { text-shadow: 0 0 50px rgba(45,212,191,0.5),  0 0 100px rgba(45,212,191,0.2); }
}

.tap-hint {
  font-family: 'Jost', sans-serif;
  font-weight: 200;
  font-size: clamp(0.75rem, 2.5vw, 1rem);
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin: 0;
  animation: hint-pulse 3s ease-in-out infinite;
}

@keyframes hint-pulse {
  0%, 100% { opacity: 0.4; }
  50%       { opacity: 0.9; }
}

#howto-btn {
  font-family: 'Jost', sans-serif;
  font-weight: 300;
  font-size: 0.85rem;
  letter-spacing: 0.15em;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  color: var(--text-muted);
  padding: 10px 28px;
  border-radius: 999px;
  cursor: pointer;
  transition: color 0.25s, border-color 0.25s, background 0.25s;
}

#howto-btn:hover,
#howto-btn:active {
  color: var(--teal-glow);
  border-color: rgba(45,212,191,0.4);
  background: var(--btn-hover);
}

/* ── Howto Modal ── */
#howto-modal {
  position: fixed;
  inset: 0;
  background: rgba(8, 10, 22, 0.75);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 20;
  animation: fade-in 0.2s ease both;
}

@keyframes fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.howto-content {
  background: rgba(17,20,40,0.92);
  border: 1px solid var(--glass-border);
  width: min(90vw, 480px);
  height: min(80vh, 560px);
  border-radius: 16px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 24px 64px rgba(0,0,0,0.6), 0 0 0 1px rgba(45,212,191,0.08);
  animation: modal-in 0.3s cubic-bezier(0.16, 1, 0.3, 1) both;
}

@keyframes modal-in {
  from { opacity: 0; transform: scale(0.94) translateY(12px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.howto-content iframe {
  flex: 1;
  border: 0;
  background: #fff;
}

#howto-close {
  font-family: 'Jost', sans-serif;
  font-weight: 300;
  letter-spacing: 0.1em;
  font-size: 0.9rem;
  background: transparent;
  border: none;
  border-top: 1px solid var(--glass-border);
  color: var(--text-muted);
  padding: 14px;
  cursor: pointer;
  transition: color 0.2s, background 0.2s;
}

#howto-close:hover {
  color: var(--teal-glow);
  background: var(--btn-hover);
}

/* ── Loading ── */
#loading {
  position: fixed;
  inset: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  background: var(--indigo-deep);
  z-index: 5;
}

.loading-dots {
  display: flex;
  gap: 10px;
}

.loading-dots span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--teal-glow);
  animation: dot-bounce 1.2s ease-in-out infinite;
  opacity: 0.7;
}

.loading-dots span:nth-child(1) { animation-delay: 0s; }
.loading-dots span:nth-child(2) { animation-delay: 0.2s; }
.loading-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes dot-bounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.3; }
  40%            { transform: scale(1.2); opacity: 1; }
}

/* ── Game Frame ── */
#game-frame {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  background: #000;
}

/* ── Game Overlay Buttons（左上：ホーム・リトライ）── */
#game-overlay-btns {
  position: fixed;
  top: calc(env(safe-area-inset-top) + 10px);
  left: calc(env(safe-area-inset-left) + 10px);
  display: flex;
  gap: 8px;
  z-index: 15;
}

#home-btn,
#retry-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(11,13,26,0.55);
  border: 1px solid rgba(255,255,255,0.15);
  color: rgba(255,255,255,0.55);
  font-size: 1rem;
  cursor: pointer;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  transition: color 0.2s, border-color 0.2s, background 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

#home-btn:hover, #home-btn:active,
#retry-btn:hover, #retry-btn:active {
  color: var(--teal-glow);
  border-color: rgba(45,212,191,0.4);
  background: rgba(11,13,26,0.8);
}

/* ── Mute Button（右上）── */
#mute-btn {
  position: fixed;
  top: calc(env(safe-area-inset-top) + 10px);
  right: calc(env(safe-area-inset-right) + 10px);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(11,13,26,0.55);
  border: 1px solid rgba(255,255,255,0.15);
  color: rgba(255,255,255,0.55);
  font-size: 1rem;
  cursor: pointer;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 15;
  transition: color 0.2s, border-color 0.2s, background 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

#mute-btn:hover,
#mute-btn:active {
  color: var(--teal-glow);
  border-color: rgba(45,212,191,0.4);
  background: rgba(11,13,26,0.8);
}

/* ── Touch Controls ── */
#touch-controls {
  position: fixed;
  bottom: calc(env(safe-area-inset-bottom) + 12px);
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  padding: 0 20px;
  pointer-events: none;
  z-index: 10;
}

#ctrl-dpad {
  display: flex;
  flex-direction: column;
  gap: 4px;
  pointer-events: none;
}

.ctrl-dpad-row {
  display: flex;
  gap: 4px;
  justify-content: center;
}

.ctrl-dpad-center {
  width: 52px;
  height: 52px;
}

#ctrl-actions {
  display: grid;
  grid-template-columns: repeat(2, 52px);
  grid-template-rows: repeat(2, 52px);
  gap: 6px;
  pointer-events: none;
}

.ctrl-btn {
  pointer-events: auto;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: rgba(11,13,26,0.5);
  border: 1.5px solid rgba(255,255,255,0.2);
  color: rgba(255,255,255,0.65);
  font-size: 1rem;
  font-weight: 400;
  font-family: 'Jost', sans-serif;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  touch-action: none;
  cursor: pointer;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  transition: background 0.1s, border-color 0.1s, color 0.1s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ctrl-btn:active {
  background: rgba(45,212,191,0.25);
  border-color: rgba(45,212,191,0.5);
  color: #fff;
}

/* ── Rotate Overlay ── */
#rotate-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--indigo-deep);
  color: var(--text-muted);
  font-family: 'Jost', sans-serif;
  font-weight: 200;
  font-size: 1rem;
  letter-spacing: 0.15em;
  justify-content: center;
  align-items: center;
  text-align: center;
  z-index: 100;
  line-height: 2.2;
}

@media (orientation: portrait) {
  #rotate-overlay {
    display: flex;
  }
}
