@import url('https://fonts.googleapis.com/css2?family=Space+Mono:wght@400;700&display=swap');

:root {
  --bg: #0a0015;
  --bg-field: #051205;
  --accent: #7c3aed;
  --accent-soft: rgba(124, 58, 237, 0.18);
  --accent-strong: #c084fc;
  --text: #f7f5ff;
  --text-muted: #a6a0c0;
  --radius-lg: 20px;
  --radius-md: 14px;
  --shadow-soft: 0 18px 45px rgba(0, 0, 0, 0.5);

  --grass-a: #166534;
  --grass-b: #15803d;
  --grass-dark: #052e16;

  --bull-body: #a855f7;
  --bull-body-dark: #7c3aed;
  --bull-shadow: #4c1d95;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100dvh;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: radial-gradient(circle at top, #1a0a2e 0, var(--bg) 55%, #000 100%);
  color: var(--text);
  overflow: hidden;
  position: fixed;
  top: 0; left: 0;
  overscroll-behavior: none;
  /* iOS は -webkit-user-select: none だけでは長押しの虫眼鏡（選択ルーペ）が出る。
     -webkit-touch-callout: none まで指定して初めて止まる */
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

body {
  display: flex;
  justify-content: center;
  align-items: stretch;
}

#app {
  width: 100%;
  max-width: 90vw;
  min-height: 100vh;
  padding: 12px 12px 18px;
  display: flex;
  flex-direction: column;
}

#error-banner {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 100;
  padding: 6px 10px;
  font-size: 0.8rem;
  background: rgba(239, 68, 68, 0.9);
  color: #fef2f2;
  text-align: center;
  display: none;
}

.screen { display: none; flex: 1; }
.screen--active { display: flex; flex-direction: column; }

/* ========== ホーム画面 ========== */

.header {
  position: relative;
  text-align: center;
  padding-top: 8px;
}

.home-logo-link {
  position: absolute;
  top: 0; left: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  text-decoration: none;
}

.home-logo-image {
  display: block;
  width: clamp(56px, 14vw, 78px);
  height: auto;
}

.title {
  margin: 0;
  font-family: "Orbitron", sans-serif;
  font-size: clamp(1.4rem, 4vw, 2rem);
  font-weight: 900;
  letter-spacing: 0.08em;
  color: var(--accent-strong);
  text-shadow: 0 0 18px rgba(157, 93, 255, 0.8);
  animation: title-float 3.6s ease-in-out infinite;
}

@keyframes title-float {
  0%, 100% { transform: translateY(0); }
  50%       { transform: translateY(-6px); }
}

.trash-button {
  position: absolute;
  right: 18px;
  top: 12px;
  background: none;
  border: none;
  font-size: 1.6rem;
  cursor: pointer;
  padding: 8px 12px;
  line-height: 1;
  opacity: 0.7;
  transition: all 0.2s ease;
}

.trash-button:hover {
  opacity: 1;
  transform: scale(1.15);
}

.trash-button:active {
  transform: scale(0.95);
}

.hero {
  margin-top: 14px;
  display: flex;
  justify-content: center;
  position: relative;
  height: 200px;
  align-items: center;
}

.hero-canvas {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  cursor: pointer;
  z-index: 10;
}

.hero-image {
  display: block;
  width: clamp(90px, 25vw, 140px);
  height: auto;
  filter: drop-shadow(0 8px 24px rgba(168, 85, 247, 0.6)) contrast(1.2) saturate(1.3) brightness(1.05);
  animation: title-float 3.6s ease-in-out infinite;
  position: relative;
  z-index: 1;
}

.form-section {
  margin-top: 12px;
  padding: 14px 14px 16px;
  border-radius: var(--radius-lg);
  background: radial-gradient(circle at top left, rgba(124, 58, 237, 0.25), rgba(16, 6, 46, 0.9));
  box-shadow: var(--shadow-soft);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.input {
  padding: 10px 12px;
  border-radius: 999px;
  border: 1px solid rgba(192, 132, 252, 0.4);
  background: rgba(5, 0, 24, 0.9);
  color: var(--text);
  font-size: 0.95rem;
  outline: none;
  /* 入力欄だけは選択・コピー・ペーストできるように戻す */
  -webkit-touch-callout: default;
  -webkit-user-select: text;
  user-select: text;
}

.input::placeholder { color: rgba(166, 160, 192, 0.8); }
.input:focus {
  border-color: var(--accent-strong);
  box-shadow: 0 0 0 1px rgba(124, 58, 237, 0.7);
}

.input.invalid {
  border-color: #ff6b8a;
  box-shadow: 0 0 0 3px rgba(255, 107, 138, 0.3);
  animation: nickShake 0.4s;
}

.nickname-error {
  min-height: 1.1em;
  margin-top: 2px;
  color: #ff6b8a;
  font-size: 0.8rem;
  font-weight: 700;
  text-align: center;
}

@keyframes nickShake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-6px); }
  40%, 80% { transform: translateX(6px); }
}

.button {
  margin-top: 6px;
  padding: 10px 16px;
  border-radius: 999px;
  border: none;
  font-family: "Orbitron", sans-serif;
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  cursor: pointer;
  transition: transform 0.08s ease-out, box-shadow 0.08s ease-out;
}

.button--primary {
  background: linear-gradient(135deg, #c084fc, #7c3aed);
  color: #fff;
  box-shadow: 0 4px 0 #4c1d95, 0 8px 24px rgba(124, 58, 237, 0.5);
}

.button--primary:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 #4c1d95, 0 4px 12px rgba(0, 0, 0, 0.5);
}

.button:disabled { opacity: 0.55; cursor: default; box-shadow: none; }

.ranking-section {
  margin-top: 14px;
  padding: 14px 12px 6px;
  border-radius: var(--radius-lg);
  background: rgba(6, 2, 28, 0.92);
  box-shadow: var(--shadow-soft);
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: 1;
  min-height: 0;
}

.tabs {
  display: flex;
  gap: 6px;
  padding: 3px;
  border-radius: 999px;
  background: rgba(19, 8, 55, 0.95);
}

.tab {
  flex: 1;
  border-radius: 999px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  padding: 6px;
  font-size: 0.82rem;
  cursor: pointer;
}

.tab--active {
  background: radial-gradient(circle at top, #c084fc, #7c3aed);
  color: #fff;
  font-weight: 600;
}

.ranking-lists { flex: 1; min-height: 0; }

.ranking-list { display: none; height: 100%; }
.ranking-list--active { display: block; }

.ranking-items {
  list-style: none;
  margin: 0;
  padding: 3px 0 6px;
  max-height: 200px;
  overflow-y: auto;
}

.ranking-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 10px;
  border-radius: var(--radius-md);
  background: linear-gradient(90deg, rgba(19, 8, 55, 0.95), rgba(33, 12, 85, 0.9));
  color: var(--text);
  font-size: 0.9rem;
}

.ranking-item + .ranking-item { margin-top: 6px; }

.ranking-item--placeholder {
  justify-content: center;
  color: var(--text-muted);
  font-size: 0.82rem;
}

.ranking-item--gold   { background: linear-gradient(90deg, #facc15, #b45309); color: #1f2933; }
.ranking-item--silver { background: linear-gradient(90deg, #e5e7eb, #9ca3af); color: #111827; }
.ranking-item--bronze { background: linear-gradient(90deg, #f97316, #7c2d12); color: #111827; }

.ranking-rank { min-width: 32px; font-weight: 700; }
.ranking-name { flex: 1; padding: 0 8px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ranking-score { font-weight: 600; }

.footer { margin-top: 10px; text-align: center; }

/* ========== ゲーム画面 ========== */

.game-header {
  position: relative;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  justify-items: center;
  gap: 12px;
  padding: 12px 12px;
  background: rgba(0, 0, 0, 0.4);
  border-bottom: 1px solid rgba(124, 58, 237, 0.2);
  border-radius: var(--radius-md) var(--radius-md) 0 0;
}

.pause-button {
  /* レイアウト */
  padding: 12px 24px;
  margin: 8px auto;
  display: block;

  /* 基本スタイル */
  background: linear-gradient(135deg, #a78bfa 0%, #8b5cf6 100%);
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 1.2rem;
  font-weight: bold;

  /* 立体効果 */
  box-shadow:
    0 4px 15px rgba(139, 92, 246, 0.4),
    inset 0 -2px 4px rgba(0, 0, 0, 0.2),
    inset 0 2px 4px rgba(255, 255, 255, 0.2);

  /* トランジション */
  transition: all 0.2s ease;
}

.pause-button:hover {
  box-shadow:
    0 6px 20px rgba(139, 92, 246, 0.6),
    inset 0 -2px 4px rgba(0, 0, 0, 0.2),
    inset 0 2px 4px rgba(255, 255, 255, 0.2);
}

.pause-button:active {
  transform: translateY(2px);
  box-shadow:
    0 2px 8px rgba(139, 92, 246, 0.4),
    inset 0 -1px 2px rgba(0, 0, 0, 0.2),
    inset 0 1px 2px rgba(255, 255, 255, 0.2);
}

.pause-button.paused {
  background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
  box-shadow:
    0 4px 15px rgba(217, 119, 6, 0.4),
    inset 0 -2px 4px rgba(0, 0, 0, 0.2),
    inset 0 2px 4px rgba(255, 255, 255, 0.2);
}

.game-score-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.9rem;
  color: #f59e0b;
}

.game-score-value {
  font-family: "Space Mono", monospace;
  font-size: 1.8rem;
  font-weight: 700;
  color: #fff;
  line-height: 1;
  text-shadow: 0 0 12px rgba(245, 158, 11, 0.6);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.05em;
  text-align: center;
  min-width: 65px;
}

.game-best-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: "Space Mono", monospace;
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--accent-strong);
}

.quit-button {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: #6b7280;
  font-size: 1.1rem;
  cursor: pointer;
  padding: 4px 8px;
  line-height: 1;
}

.game-section {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, #0a0015, #051205);
  border-radius: 0 0 var(--radius-md) var(--radius-md);
  overflow: hidden;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
  user-select: none;
  -webkit-user-select: none;
}

/* ========== 2D フィールド ========== */

.game-field-wrapper {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
}

.game-field {
  display: block;
  width: 100%;
  max-width: 500px;
  aspect-ratio: 3 / 5;
  height: auto;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
  transform: translateZ(0);
  will-change: auto;
}


.swipe-hint {
  margin: 6px 0 0;
  font-size: 0.7rem;
  color: #374151;
  letter-spacing: 2px;
  text-align: center;
  font-family: "Share Tech Mono", monospace;
  transition: opacity 0.5s;
}

/* ========== ゲームオーバー ========== */

.gameover-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at top, rgba(76, 29, 149, 0.85), rgba(15, 6, 45, 0.96));
  backdrop-filter: blur(10px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease-out;
  z-index: 50;
}

.gameover-overlay--visible {
  opacity: 1;
  pointer-events: auto;
}

.gameover-dialog {
  width: 100%;
  max-width: 420px;
  margin: 0 16px;
  padding: 24px 20px 26px;
  border-radius: 20px;
  background: radial-gradient(circle at top, #a855f7, #4c1d95);
  box-shadow: 0 22px 50px rgba(0, 0, 0, 0.75);
  text-align: center;
  color: #fdf4ff;
}

.gameover-title {
  margin: 0 0 16px;
  font-family: "Orbitron", sans-serif;
  font-size: 2.2rem;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-shadow: 0 0 10px rgba(250, 250, 255, 0.9), 0 0 24px rgba(192, 132, 252, 0.8);
}

.gameover-score {
  margin: 6px 0;
  font-size: 1.3rem;
  font-weight: 700;
}

.gameover-score-label { color: #fdfdfd; }
.gameover-score-value { color: #fde68a; margin-left: 4px; }
.gameover-score-unit  { margin-left: 2px; }

.gameover-badge {
  margin: 8px 0 12px;
  font-size: 1.4rem;
  font-weight: 800;
  color: #fef9c3;
  text-shadow: 0 0 10px rgba(251, 191, 36, 0.9), 0 0 22px rgba(245, 158, 11, 0.9);
  animation: badge-bounce 0.9s ease-out infinite, badge-rainbow 2.2s linear infinite;
}

.gameover-badge--hidden { display: none; }

@keyframes badge-bounce {
  0%, 100% { transform: translateY(0) scale(1); }
  30%       { transform: translateY(-6px) scale(1.08); }
  60%       { transform: translateY(2px) scale(0.98); }
}

@keyframes badge-rainbow {
  0%   { color: #fef9c3; }
  25%  { color: #bfdbfe; }
  50%  { color: #f9a8d4; }
  75%  { color: #a7f3d0; }
  100% { color: #fef9c3; }
}

.gameover-actions {
  margin-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.gameover-button {
  padding: 14px 20px;
  border-radius: 999px;
  border: none;
  font-family: "Orbitron", sans-serif;
  font-weight: 700;
  font-size: 1.1rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  min-width: 100%;
}

.gameover-button--primary {
  background: linear-gradient(135deg, #f9a8ff, #c084fc);
  color: #0b0014;
  box-shadow: 0 12px 28px rgba(192, 132, 252, 0.6);
}

.gameover-button--secondary {
  background: rgba(15, 23, 42, 0.9);
  color: #e5e7eb;
  border: 1px solid rgba(226, 232, 240, 0.45);
}

@media (min-width: 768px) {
  #app { padding: 20px 18px 24px; }
  .form-section { margin-top: 20px; }
}
