:root {
  --accent: #ffd23f;
  --accent-dark: #c98a00;
  --primary: #ff7a3d;
  --primary-dark: #e05a1f;
  --panel-bg: #1e2540;
  --panel-bg2: #2a3358;
  --text-light: #ffffff;
  --text-dim: #c7cde0;
  --danger: #ff5c5c;
  --success: #5fd068;
  --radius: 16px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: #10142a;
  font-family: "Hiragino Maru Gothic ProN", "Hiragino Sans", "Yu Gothic", "Segoe UI", sans-serif;
  touch-action: none;
  overscroll-behavior: none;
}

#app {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #10142a;
  padding: var(--safe-top) env(safe-area-inset-right, 0px) var(--safe-bottom) env(safe-area-inset-left, 0px);
}

#game-wrap {
  position: relative;
  width: 100%;
  height: 100%;
  max-width: 480px;
  max-height: 900px;
  aspect-ratio: 360 / 640;
  background: #000;
  border-radius: 0;
  overflow: hidden;
  box-shadow: 0 0 60px rgba(0,0,0,0.6);
  touch-action: none;
  user-select: none;
}

@media (min-width: 560px) {
  #game-wrap {
    border-radius: var(--radius);
    max-height: min(92vh, 900px);
  }
}

canvas#gameCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.hidden { display: none !important; }

/* ---------------- HUD ---------------- */
#hud {
  position: absolute;
  top: 0; left: 0; right: 0;
  display: flex;
  justify-content: center;
  padding-top: calc(18px);
  pointer-events: none;
}

#hud-score {
  font-size: 52px;
  font-weight: 900;
  color: #fff;
  text-shadow: 0 3px 0 rgba(0,0,0,0.35), 0 0 12px rgba(0,0,0,0.25);
  font-variant-numeric: tabular-nums;
}

#btn-pause {
  position: absolute;
  top: 14px;
  right: 14px;
  pointer-events: auto;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: rgba(0,0,0,0.35);
  color: #fff;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  backdrop-filter: blur(4px);
}
.icon-btn:active { transform: scale(0.92); }

/* ---------------- Screens ---------------- */
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 24px 22px;
  text-align: center;
  color: #fff;
  background: linear-gradient(180deg, rgba(15,20,45,0.55), rgba(10,14,32,0.85));
  overflow-y: auto;
}

.title {
  font-size: 34px;
  font-weight: 900;
  margin: 0;
  letter-spacing: 1px;
  background: linear-gradient(90deg, #ffd23f, #ff7a3d, #ffe066, #ffd23f);
  background-size: 300% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 3px 0 rgba(0,0,0,0.4));
  animation: title-sheen 7s ease-in-out infinite alternate;
}
@keyframes title-sheen {
  0% { background-position: 0% 50%; }
  100% { background-position: 100% 50%; }
}
.subtitle {
  margin: 0 0 6px;
  color: var(--text-dim);
  font-size: 14px;
  font-weight: 600;
}

.start-stats {
  display: flex;
  gap: 10px;
  margin-bottom: 4px;
}
.stat-chip {
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.2);
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
}

.daily-card {
  width: 100%;
  max-width: 300px;
  background: var(--panel-bg);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin: 6px 0;
}
.daily-title { font-weight: 800; font-size: 13px; color: var(--accent); margin-bottom: 4px; }
.daily-desc { font-size: 13px; color: var(--text-light); margin-bottom: 8px; }
.daily-progress-track {
  width: 100%;
  height: 8px;
  border-radius: 5px;
  background: rgba(255,255,255,0.12);
  overflow: hidden;
}
.daily-progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--primary));
  transition: width 0.3s ease;
}
.daily-status { margin-top: 6px; font-size: 12px; color: var(--text-dim); }

.btn-primary, .btn-secondary {
  border: none;
  border-radius: 999px;
  padding: 14px 38px;
  font-size: 17px;
  font-weight: 800;
  cursor: pointer;
  touch-action: manipulation;
}
.btn-primary {
  background: linear-gradient(180deg, var(--accent), var(--primary));
  color: #2a1500;
  box-shadow: 0 5px 0 var(--primary-dark), 0 8px 16px rgba(0,0,0,0.35), 0 0 0 rgba(255,210,63,0.6);
  animation: btn-glow 2.6s ease-in-out infinite;
}
@keyframes btn-glow {
  0%, 100% { box-shadow: 0 5px 0 var(--primary-dark), 0 8px 16px rgba(0,0,0,0.35), 0 0 0px rgba(255,210,63,0.5); }
  50% { box-shadow: 0 5px 0 var(--primary-dark), 0 8px 22px rgba(0,0,0,0.35), 0 0 22px rgba(255,210,63,0.65); }
}
.btn-primary:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--primary-dark); }
.btn-secondary {
  background: rgba(255,255,255,0.12);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.25);
}
.btn-secondary:active { transform: translateY(2px); }

.menu-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  width: 100%;
  max-width: 320px;
  margin-top: 6px;
}
.menu-btn {
  background: var(--panel-bg);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 12px;
  color: #fff;
  padding: 10px 4px;
  font-size: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  cursor: pointer;
}
.menu-btn span { font-size: 11px; font-weight: 700; color: var(--text-dim); }
.menu-btn:active { transform: scale(0.95); }

.hint {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 4px;
}

/* ---------------- Game over ---------------- */
.go-score-row {
  display: flex;
  gap: 14px;
  margin: 8px 0;
}
.go-score-box {
  background: var(--panel-bg);
  border-radius: 14px;
  padding: 10px 24px;
  border: 1px solid rgba(255,255,255,0.1);
}
.go-label { font-size: 11px; color: var(--text-dim); font-weight: 700; }
.go-value { font-size: 28px; font-weight: 900; color: var(--accent); }
.go-newbest {
  color: #ffe066;
  font-weight: 800;
  font-size: 14px;
  animation: pop 0.6s ease, newbest-glow 2.2s ease-in-out 0.6s infinite;
}
@keyframes newbest-glow {
  0%, 100% { text-shadow: 0 0 6px rgba(255,224,102,0.4); }
  50% { text-shadow: 0 0 16px rgba(255,224,102,0.9); }
}
.go-coins { font-size: 14px; font-weight: 700; color: var(--text-light); }
.go-daily {
  font-size: 12px;
  color: var(--success);
  font-weight: 700;
  background: rgba(95,208,104,0.15);
  padding: 6px 12px;
  border-radius: 10px;
}
.go-world {
  font-size: 12px;
  color: #7fd6ff;
  font-weight: 700;
  background: rgba(77,166,255,0.15);
  padding: 6px 12px;
  border-radius: 10px;
}
.go-achievements {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 150px;
  overflow-y: auto;
  width: 100%;
  max-width: 300px;
}
.go-ach-item {
  background: rgba(255,210,63,0.14);
  border: 1px solid rgba(255,210,63,0.4);
  border-radius: 10px;
  padding: 6px 10px;
  font-size: 12px;
  text-align: left;
  display: flex;
  gap: 8px;
  align-items: center;
}
.go-buttons { display: flex; gap: 10px; margin-top: 6px; }

@keyframes pop {
  0% { transform: scale(0.5); opacity: 0; }
  60% { transform: scale(1.15); opacity: 1; }
  100% { transform: scale(1); }
}

/* ---------------- Panels ---------------- */
.panel-overlay {
  position: absolute;
  inset: 0;
  background: rgba(5,8,20,0.72);
  display: flex;
  align-items: flex-end;
  z-index: 20;
  animation: overlay-in 0.22s ease;
}
@keyframes overlay-in {
  from { opacity: 0; }
  to { opacity: 1; }
}
.panel-overlay .panel { animation: panel-in 0.28s cubic-bezier(.2,.8,.3,1); }
@keyframes panel-in {
  from { transform: translateY(24px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
@media (min-width: 560px) {
  .panel-overlay { align-items: center; justify-content: center; }
}
.panel {
  background: var(--panel-bg);
  width: 100%;
  max-height: 82%;
  border-radius: 20px 20px 0 0;
  display: flex;
  flex-direction: column;
  color: #fff;
  overflow: hidden;
  padding-bottom: var(--safe-bottom);
}
@media (min-width: 560px) {
  .panel { border-radius: 20px; max-width: 380px; max-height: 80%; }
}
.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  font-weight: 800;
  font-size: 16px;
}
.panel-body {
  padding: 12px 16px 20px;
  overflow-y: auto;
}

.coin-balance {
  display: flex;
  justify-content: center;
  gap: 6px;
  font-weight: 800;
  color: var(--accent);
  background: rgba(255,210,63,0.1);
  border-radius: 10px;
  padding: 8px;
  margin-bottom: 12px;
  font-size: 15px;
}

/* achievements list */
.ach-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 8px;
  border-radius: 12px;
  margin-bottom: 6px;
  background: var(--panel-bg2);
}
.ach-row.locked { opacity: 0.45; filter: grayscale(0.6); }
.ach-icon { font-size: 24px; width: 32px; text-align: center; }
.ach-info { flex: 1; text-align: left; }
.ach-name { font-weight: 800; font-size: 13px; }
.ach-desc { font-size: 11px; color: var(--text-dim); }
.ach-reward { font-size: 11px; color: var(--accent); font-weight: 700; white-space: nowrap; }
.ach-summary { text-align: center; font-size: 12px; color: var(--text-dim); margin-bottom: 10px; }
.ach-cat-title {
  font-size: 11px;
  font-weight: 800;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin: 14px 0 6px;
  padding-bottom: 4px;
  border-bottom: 1px solid rgba(255,210,63,0.25);
}
.ach-cat-title:first-of-type { margin-top: 0; }

/* shop */
.shop-section-title {
  font-size: 12px;
  font-weight: 800;
  color: var(--text-dim);
  margin: 10px 0 6px;
  text-transform: uppercase;
  letter-spacing: 1px;
}
.shop-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.shop-item {
  background: var(--panel-bg2);
  border-radius: 12px;
  padding: 8px 4px 10px;
  text-align: center;
  border: 2px solid transparent;
  cursor: pointer;
}
.shop-item.selected { border-color: var(--accent); }
.shop-swatch {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  margin: 0 auto 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
}
.shop-name { font-size: 11px; font-weight: 700; }
.shop-cost { font-size: 11px; color: var(--accent); font-weight: 700; margin-top: 2px; }
.shop-owned { font-size: 10px; color: var(--success); font-weight: 700; margin-top: 2px; }
.shop-locked { font-size: 10px; color: var(--danger); font-weight: 700; margin-top: 2px; }

/* stats */
.stat-row {
  display: flex;
  justify-content: space-between;
  padding: 9px 4px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  font-size: 13px;
}
.stat-row span:last-child { font-weight: 800; color: var(--accent); }

/* leaderboard */
.lb-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 4px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  font-size: 13px;
}
.lb-rank { width: 22px; font-weight: 800; color: var(--accent); }
.lb-score { flex: 1; font-weight: 700; }
.lb-date { font-size: 11px; color: var(--text-dim); }
.lb-empty { text-align: center; color: var(--text-dim); font-size: 13px; padding: 20px 0; }

/* changelog */
.cl-entry { margin-bottom: 14px; }
.cl-version { font-weight: 900; color: var(--accent); font-size: 14px; }
.cl-date { font-size: 11px; color: var(--text-dim); margin-bottom: 6px; }
.cl-notes { margin: 0; padding-left: 18px; font-size: 12px; line-height: 1.6; color: var(--text-light); }

/* settings */
.setting-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 4px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  font-size: 14px;
  font-weight: 700;
}
.switch {
  width: 46px;
  height: 26px;
  border-radius: 999px;
  background: rgba(255,255,255,0.2);
  position: relative;
  cursor: pointer;
  border: none;
}
.switch.on { background: var(--success); }
.switch::after {
  content: "";
  position: absolute;
  top: 3px; left: 3px;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.2s ease;
}
.switch.on::after { transform: translateX(20px); }
.danger-btn {
  width: 100%;
  margin-top: 16px;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid rgba(255,92,92,0.5);
  background: rgba(255,92,92,0.12);
  color: var(--danger);
  font-weight: 800;
  cursor: pointer;
}

/* toast */
#toast-container {
  position: absolute;
  top: calc(70px);
  left: 0; right: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  pointer-events: none;
  z-index: 30;
}
.toast {
  position: relative;
  background: rgba(20,24,45,0.92);
  border: 1px solid rgba(255,210,63,0.5);
  color: #fff;
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
  overflow: hidden;
  animation: toast-in 0.35s ease, toast-out 0.4s ease 2.6s forwards;
  box-shadow: 0 6px 16px rgba(0,0,0,0.35), 0 0 16px rgba(255,210,63,0.35);
}
.toast::after {
  content: "";
  position: absolute;
  top: 0; left: -60%;
  width: 40%;
  height: 100%;
  background: linear-gradient(120deg, transparent, rgba(255,255,255,0.35), transparent);
  animation: toast-shine 1s ease-out 0.15s 1;
}
@keyframes toast-shine {
  to { left: 130%; }
}
@keyframes toast-in {
  from { transform: translateY(-16px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
@keyframes toast-out {
  to { transform: translateY(-16px); opacity: 0; }
}

/* shake */
#shake-layer { position: absolute; inset: 0; pointer-events: none; }
.shaking { animation: shake 0.35s ease; }
@keyframes shake {
  0%, 100% { transform: translate(0,0); }
  20% { transform: translate(-6px, 3px); }
  40% { transform: translate(5px, -4px); }
  60% { transform: translate(-4px, 4px); }
  80% { transform: translate(4px, -2px); }
}

/* impact flash — 単発フェードのみ。連続点滅は行わない */
#flash-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 25;
}
.impact-flash {
  position: absolute;
  inset: 0;
  opacity: 0;
  animation: flash-fade 0.5s ease-out forwards;
}
@keyframes flash-fade {
  0% { opacity: 0; }
  15% { opacity: 1; }
  100% { opacity: 0; }
}

/* confetti — ゆっくり落下してフェードするのみ。明滅なし */
#confetti-layer {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 26;
}
.confetti-piece {
  position: absolute;
  top: -20px;
  width: 8px;
  height: 14px;
  border-radius: 2px;
  opacity: 0.95;
  animation-name: confetti-fall;
  animation-timing-function: ease-in;
  animation-fill-mode: forwards;
}
@keyframes confetti-fall {
  0% { transform: translate(0, 0) rotate(0deg); opacity: 0.95; }
  85% { opacity: 0.9; }
  100% { transform: translate(var(--drift), 780px) rotate(var(--rot)); opacity: 0; }
}

/* footer */
#version-footer {
  position: absolute;
  bottom: calc(4px + var(--safe-bottom));
  left: 0; right: 0;
  text-align: center;
  font-size: 10px;
  color: rgba(255,255,255,0.55);
  pointer-events: none;
  z-index: 5;
  letter-spacing: 0.5px;
}
