/* ── Reset ── */
[hidden] { display: none !important; }
*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  width: 100%; height: 100%;
  overflow: hidden;
  background: #faf6ee;
  color: #1a1208;
  font-family: "Hiragino Maru Gothic ProN", "Hiragino Maru Gothic Pro",
               "M PLUS Rounded 1c", "Rounded Mplus 1c",
               -apple-system, BlinkMacSystemFont, sans-serif;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

/* ── Variables ── */
:root {
  --red:     #e8473f;
  --red-dk:  #b5302a;
  --orange:  #f28b30;
  --ora-dk:  #c06618;
  --yellow:  #f5c842;
  --yel-dk:  #c49a10;
  --green:   #4caf7d;
  --cream:   #faf6ee;
  --cream2:  #f0e9d8;
  --ink:     #1a1208;
  --border:  rgba(0,0,0,0.13);
  --shadow:  rgba(0,0,0,0.14);
  --safe-top:    env(safe-area-inset-top,    0px);
  --safe-right:  env(safe-area-inset-right,  0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left:   env(safe-area-inset-left,   0px);
}

/* ── Dot-grid texture ── */
body::before {
  content: '';
  position: fixed; inset: 0;
  background-image: radial-gradient(circle, rgba(0,0,0,0.09) 1.2px, transparent 1.2px);
  background-size: 18px 18px;
  pointer-events: none;
  z-index: 0;
}

/* ── Floating color circles (アイコンのバッジを模した背景装飾) ── */
body::after {
  content: '';
  position: fixed; inset: 0;
  background:
    radial-gradient(circle 80px at 8%  20%, rgba(232,71,63,0.18)  0%, transparent 70%),
    radial-gradient(circle 60px at 92% 15%, rgba(242,139,48,0.20) 0%, transparent 70%),
    radial-gradient(circle 70px at 85% 80%, rgba(245,200,66,0.22) 0%, transparent 70%),
    radial-gradient(circle 50px at 12% 82%, rgba(76,175,125,0.18) 0%, transparent 70%),
    radial-gradient(circle 40px at 50% 90%, rgba(242,139,48,0.15) 0%, transparent 70%);
  pointer-events: none;
  z-index: 0;
}

/* ── Title screen ── */
#title-screen {
  position: fixed; inset: 0;
  display: flex; flex-direction: column;
  justify-content: center; align-items: center;
  padding: var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left);
  z-index: 10;
  gap: 0;
}

.title-content {
  display: flex; flex-direction: column;
  align-items: center; gap: 16px;
}

/* staggered pop-in */
.title-content > * { animation: popIn 0.45s cubic-bezier(0.34,1.56,0.64,1) both; }
.title-content > *:nth-child(1) { animation-delay: 0s; }
.title-content > *:nth-child(2) { animation-delay: 0.1s; }
.title-content > *:nth-child(3) { animation-delay: 0.18s; }

@keyframes popIn {
  from { opacity: 0; transform: scale(0.7) translateY(8px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

/* ── タイトルバッジ ── */
.title-text {
  margin: 0;
  font-size: clamp(1.7rem, 7vw, 2.8rem);
  font-weight: 900;
  letter-spacing: 0.12em;
  color: #fff;
  /* アイコンの赤バッジを模した丸型 */
  background: var(--red);
  padding: 12px 36px 14px;
  border-radius: 999px;
  /* 立体スタンプ感 */
  box-shadow:
    0 5px 0 var(--red-dk),
    0 8px 20px rgba(232,71,63,0.40),
    inset 0 1px 0 rgba(255,255,255,0.25);
  /* 文字のアウトライン */
  -webkit-text-stroke: 1px rgba(0,0,0,0.12);
  text-shadow: 0 2px 4px rgba(0,0,0,0.2);
  position: relative;
}

/* タイトル横の小丸デコ */
.title-text::before,
.title-text::after {
  content: '●';
  position: absolute;
  top: 50%; transform: translateY(-50%);
  font-size: 0.6em;
  opacity: 0.55;
}
.title-text::before { left: -1.4em; color: var(--orange); }
.title-text::after  { right: -1.4em; color: var(--yellow); }

/* ── Tap hint ── */
.tap-hint {
  margin: 0;
  font-size: 0.88rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  color: rgba(26,18,8,0.5);
  animation: blink 2.2s ease-in-out infinite;
}
@keyframes blink {
  0%,100% { opacity: 0.45; } 50% { opacity: 1; }
}

/* ── Howto button ── */
#howto-btn {
  background: #fff;
  border: 2.5px solid var(--border);
  color: var(--ink);
  padding: 9px 26px 10px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  font-family: inherit;
  cursor: pointer;
  box-shadow: 0 3px 0 var(--border), 0 4px 10px var(--shadow);
  transition: transform 0.1s, box-shadow 0.1s;
}
#howto-btn:active {
  transform: translateY(3px);
  box-shadow: none;
}

/* ── Howto modal ── */
#howto-modal {
  position: fixed; inset: 0;
  background: rgba(20,12,4,0.55);
  display: flex; justify-content: center; align-items: center;
  z-index: 20;
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
}

.howto-content {
  background: var(--cream);
  border: 2.5px solid var(--border);
  width: min(90vw, 400px);
  height: min(75vh, 460px);
  display: flex; flex-direction: column;
  border-radius: 22px;
  overflow: hidden;
  box-shadow: 0 16px 48px rgba(0,0,0,0.22), 0 4px 0 var(--cream2);
  animation: popIn 0.3s cubic-bezier(0.34,1.56,0.64,1) both;
}

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

#howto-close {
  background: var(--cream2);
  border: 0; border-top: 2px solid var(--border);
  color: var(--ink);
  padding: 13px;
  font-size: 0.88rem; font-weight: 800;
  letter-spacing: 0.08em;
  font-family: inherit;
  cursor: pointer;
}
#howto-close:active { background: #e4dccb; }

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

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

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

.loading-dots span {
  width: 14px; height: 14px;
  border-radius: 50%;
  animation: dotBounce 1.2s ease-in-out infinite;
}
.loading-dots span:nth-child(1) { background: var(--red);    animation-delay: 0s; }
.loading-dots span:nth-child(2) { background: var(--orange); animation-delay: 0.18s; }
.loading-dots span:nth-child(3) { background: var(--yellow); animation-delay: 0.36s; }

@keyframes dotBounce {
  0%,80%,100% { opacity: 0.3; transform: scale(0.65) translateY(0); }
  40%         { opacity: 1;   transform: scale(1.15) translateY(-4px); }
}

/* ── Game overlay: home / retry (top-left) ── */
#game-overlay-btns {
  position: fixed;
  top: calc(var(--safe-top) + 10px);
  left: calc(var(--safe-left) + 10px);
  display: flex; gap: 6px;
  z-index: 15;
}

#home-btn, #retry-btn {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: rgba(255,255,255,0.92);
  border: 2px solid var(--border);
  color: var(--ink);
  font-size: 1rem;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; font-family: inherit;
  box-shadow: 0 2px 0 var(--border), 0 3px 8px var(--shadow);
  transition: transform 0.1s, box-shadow 0.1s;
}
#home-btn:active, #retry-btn:active {
  transform: translateY(2px); box-shadow: none;
}

/* ── Mute (top-right) ── */
#mute-btn {
  position: fixed;
  top: calc(var(--safe-top) + 10px);
  right: calc(var(--safe-right) + 10px);
  width: 36px; height: 36px;
  border-radius: 50%;
  background: rgba(255,255,255,0.92);
  border: 2px solid var(--border);
  color: var(--ink);
  font-size: 1rem;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; font-family: inherit;
  box-shadow: 0 2px 0 var(--border), 0 3px 8px var(--shadow);
  z-index: 15;
}

/* ── D-pad (bottom-right) ── */
#touch-controls {
  position: fixed;
  bottom: calc(var(--safe-bottom) + 14px);
  right: calc(var(--safe-right) + 14px);
  display: flex; align-items: flex-end;
  pointer-events: none;
  z-index: 12;
}

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

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

.ctrl-dpad-center {
  width: 48px; height: 48px;
  background: rgba(0,0,0,0.055);
  border-radius: 8px;
  border: 2px solid rgba(0,0,0,0.07);
}

.ctrl-btn {
  pointer-events: auto;
  width: 48px; height: 48px;
  border-radius: 12px;
  background: #fff;
  border: 2px solid rgba(0,0,0,0.15);
  color: var(--ink);
  font-size: 0.9rem; font-weight: 800;
  -webkit-tap-highlight-color: transparent;
  user-select: none; touch-action: none;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-family: inherit;
  /* 立体押し込み感 */
  box-shadow:
    0 4px 0 rgba(0,0,0,0.2),
    0 5px 10px rgba(0,0,0,0.12);
  transition: transform 0.08s, box-shadow 0.08s, background 0.08s;
}
.ctrl-btn:active {
  transform: translateY(4px);
  box-shadow: 0 0 0 rgba(0,0,0,0.2);
  background: var(--cream2);
}

/* 上ボタンだけオレンジのアクセント */
.ctrl-up    { border-top-color:    var(--orange); }
.ctrl-down  { border-bottom-color: var(--red);    }
.ctrl-left  { border-left-color:   var(--yellow); }
.ctrl-right { border-right-color:  var(--green);  }

/* ── Rotate overlay ── */
#rotate-overlay {
  display: none;
  position: fixed; inset: 0;
  background: var(--cream);
  color: var(--ink);
  justify-content: center; align-items: center; text-align: center;
  z-index: 100;
}

.rotate-content {
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  animation: popIn 0.4s ease both;
}

.rotate-icon {
  font-size: 2.6rem;
  animation: tilt 1.8s ease-in-out infinite;
}
@keyframes tilt {
  0%,100% { transform: rotate(-30deg); }
  50%     { transform: rotate(0deg); }
}

.rotate-content p {
  margin: 0; font-size: 1rem; font-weight: 800;
  letter-spacing: 0.1em; color: rgba(26,18,8,0.5);
}

@media (orientation: portrait) {
  #rotate-overlay[data-orientation="landscape"] { display: flex; }
}
@media (orientation: landscape) {
  #rotate-overlay[data-orientation="portrait"]  { display: flex; }
}
