:root {
  --bg-deep: #2d1810;
  --bg-main: #4a2c1a;
  --bg-panel: rgba(60, 30, 15, 0.9);
  --brown-light: #d4a574;
  --brown-mid: #8b6914;
  --gold: #fbbf24;
  --gold-light: #fde68a;
  --cream: #fff8e7;
  --white: #fff8f0;
  --text-dim: #c0a080;
  --poop-brown: #8B4513;
  --pink: #ff69b4;
  --pink-light: #ffb6c1;
}

html { font-size: 16px; }

body {
  font-family: 'M PLUS Rounded 1c', 'Zen Maru Gothic', sans-serif;
  background: linear-gradient(135deg, var(--bg-deep) 0%, var(--bg-main) 40%, #5a3420 100%);
  color: var(--white);
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  position: relative;
}

/* ===== Back link ===== */
.back-to-top-link {
  position: fixed;
  top: 10px;
  left: 10px;
  color: var(--brown-light);
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 700;
  z-index: 1000;
  background: var(--bg-panel);
  padding: 6px 12px;
  border-radius: 20px;
  border: 1px solid rgba(212, 165, 116, 0.3);
  transition: all 0.3s;
}

.back-to-top-link:hover {
  background: rgba(212, 165, 116, 0.2);
  color: var(--gold);
}

/* ===== Floating poop background ===== */
.bg-poops {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
}

.float-poop {
  position: absolute;
  left: var(--x);
  top: var(--y);
  font-size: 1.5rem;
  animation: floatPoop var(--dur) var(--delay) infinite ease-in-out;
  opacity: 0.2;
}

@keyframes floatPoop {
  0%, 100% { opacity: 0.15; transform: translateY(0) rotate(0deg); }
  50% { opacity: 0.3; transform: translateY(-15px) rotate(20deg); }
}

/* ===== Screens ===== */
.screen {
  display: none;
  justify-content: center;
  align-items: center;
  height: 100dvh;
  position: relative;
  z-index: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.screen.active {
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* ===== Title Screen ===== */
.title-container {
  text-align: center;
  padding: 20px 20px;
  max-width: 500px;
}

.title-icon {
  font-size: 3rem;
  margin-bottom: 6px;
  animation: iconBounce 2s infinite ease-in-out;
}

@keyframes iconBounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-12px); }
}

.game-title {
  font-family: 'Dela Gothic One', sans-serif;
  font-size: 2.4rem;
  background: linear-gradient(135deg, var(--gold), var(--brown-light), #fff);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  filter: drop-shadow(0 0 20px rgba(139, 69, 19, 0.5));
  margin-bottom: 6px;
  line-height: 1.2;
}

.game-subtitle {
  font-size: 1.1rem;
  color: var(--gold);
  font-weight: 700;
  margin-bottom: 20px;
  text-shadow: 0 0 10px rgba(251, 191, 36, 0.5);
}

/* ===== Character Preview (Title) ===== */
.character-preview {
  display: flex;
  justify-content: center;
  margin-bottom: 12px;
}

.character-preview-frame {
  width: 280px;
  height: 280px;
  border-radius: 50%;
  border: 4px solid var(--gold);
  box-shadow: 0 0 20px rgba(251, 191, 36, 0.3);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fff;
}

.character-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* ===== Buttons ===== */
.btn-primary {
  display: inline-block;
  background: linear-gradient(135deg, var(--poop-brown), #a0522d);
  color: white;
  border: none;
  padding: 16px 48px;
  font-size: 1.3rem;
  font-family: 'Zen Maru Gothic', sans-serif;
  font-weight: 700;
  border-radius: 50px;
  cursor: pointer;
  transition: all 0.3s;
  box-shadow: 0 0 20px rgba(139, 69, 19, 0.4), 0 4px 15px rgba(0,0,0,0.3);
  margin-bottom: 24px;
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 0 30px rgba(139, 69, 19, 0.6), 0 6px 20px rgba(0,0,0,0.4);
}

.btn-primary:active { transform: translateY(1px); }

.btn-secondary {
  display: inline-block;
  background: transparent;
  color: var(--brown-light);
  border: 2px solid var(--brown-light);
  padding: 12px 36px;
  font-size: 1rem;
  font-family: 'Zen Maru Gothic', sans-serif;
  font-weight: 700;
  border-radius: 50px;
  cursor: pointer;
  transition: all 0.3s;
  margin-bottom: 20px;
}

.btn-secondary:hover {
  background: rgba(212, 165, 116, 0.15);
}

.controls-help {
  background: var(--bg-panel);
  border: 1px solid rgba(212, 165, 116, 0.2);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 20px;
  font-size: 0.85rem;
  color: var(--text-dim);
  line-height: 1.8;
}

.help-title {
  color: var(--gold);
  font-weight: 700;
  margin-bottom: 4px;
}

.disclaimer {
  font-size: 0.75rem;
  color: var(--text-dim);
  line-height: 1.6;
  opacity: 0.7;
}

/* ===== Story Screen ===== */
.story-container {
  text-align: center;
  padding: 20px 20px;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.story-poop-icon {
  animation: storyBounce 1.5s infinite ease-in-out;
}

.story-poop-img {
  width: 1500px;
  height: 1500px;
  max-width: 90vw;
  max-height: 60vh;
  object-fit: contain;
}

@keyframes storyBounce {
  0%, 100% { transform: translateY(0) rotate(-5deg); }
  50% { transform: translateY(-10px) rotate(5deg); }
}

.story-bubble {
  background: rgba(255, 255, 255, 0.95);
  color: #333;
  border-radius: 20px;
  padding: 20px 24px;
  position: relative;
  font-size: 1.05rem;
  line-height: 1.8;
  font-weight: 700;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
  min-height: 60px;
  opacity: 0;
  transform: scale(0.8);
  transition: opacity 0.4s, transform 0.4s;
}

#story-text {
  white-space: pre-wrap;
}

.story-bubble.visible {
  opacity: 1;
  transform: scale(1);
}

.story-bubble::after {
  content: '';
  position: absolute;
  top: -14px;
  left: 50%;
  transform: translateX(-50%);
  border: 8px solid transparent;
  border-bottom-color: rgba(255, 255, 255, 0.95);
}

.story-tap-hint {
  font-size: 0.85rem;
  color: var(--text-dim);
  opacity: 0;
  animation: hintBlink 1.5s 0.8s infinite;
}

@keyframes hintBlink {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 1; }
}

/* ===== Game Screen ===== */
#game-screen {
  padding-top: 56px;
  min-height: 100vh;
  min-height: 100dvh;
  justify-content: flex-start;
}

.game-hud {
  display: flex;
  justify-content: center;
  gap: 24px;
  padding: 8px 16px;
  margin-bottom: 4px;
}

.hud-item {
  background: var(--bg-panel);
  border: 1px solid rgba(212, 165, 116, 0.3);
  border-radius: 10px;
  padding: 6px 20px;
  text-align: center;
}

.hud-label {
  font-size: 0.7rem;
  color: var(--text-dim);
  letter-spacing: 2px;
  display: block;
}

.hud-value {
  font-family: 'Dela Gothic One', sans-serif;
  font-size: 1.4rem;
  color: var(--gold);
  text-shadow: 0 0 8px rgba(251, 191, 36, 0.4);
}

#game-canvas {
  display: block;
  border: 2px solid rgba(212, 165, 116, 0.3);
  border-radius: 4px;
  box-shadow: 0 0 30px rgba(139, 69, 19, 0.2), inset 0 0 30px rgba(0,0,0,0.3);
  touch-action: none;
}

/* Combo text */
.combo-text {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0);
  font-family: 'Dela Gothic One', sans-serif;
  font-size: 1.6rem;
  color: var(--gold);
  text-shadow: 0 0 20px rgba(251, 191, 36, 0.8), 0 0 40px rgba(251, 191, 36, 0.4);
  width: 92vw;
  max-width: 92vw;
  text-align: center;
  line-height: 1.3;
  white-space: pre-line;
  overflow-wrap: anywhere;
  pointer-events: none;
  opacity: 0;
  z-index: 10;
}

.combo-text.active {
  animation: comboFlash 1s ease-out forwards;
}

@keyframes comboFlash {
  0% { opacity: 1; transform: translate(-50%, -50%) scale(0.5); }
  20% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  40% { transform: translate(-50%, -50%) scale(0.95); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(1) translateY(-30px); }
}

/* Nishida comment bubble */
.nishida-comment {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(255, 255, 255, 0.95);
  color: #333;
  padding: 8px 20px;
  border-radius: 20px;
  font-size: 0.9rem;
  font-weight: 700;
  text-align: center;
  max-width: 92vw;
  white-space: normal;
  word-break: keep-all;
  overflow-wrap: anywhere;
  line-height: 1.4;
  opacity: 0;
  pointer-events: none;
  z-index: 10;
  box-shadow: 0 2px 10px rgba(0,0,0,0.3);
}

.nishida-comment.active {
  animation: commentPop 1.5s ease-out forwards;
}

@keyframes commentPop {
  0% { opacity: 0; transform: translateX(-50%) translateY(10px); }
  15% { opacity: 1; transform: translateX(-50%) translateY(0); }
  75% { opacity: 1; }
  100% { opacity: 0; transform: translateX(-50%) translateY(-10px); }
}

/* ===== Result Screen ===== */
#result-screen {
  justify-content: flex-start;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 10px 0;
}

.result-container {
  text-align: center;
  padding: 20px 20px;
  max-width: 420px;
  width: 100%;
}

.result-icon {
  font-size: 2.5rem;
  margin-bottom: 4px;
  animation: iconBounce 2s infinite ease-in-out;
}

.result-title {
  font-family: 'Dela Gothic One', sans-serif;
  font-size: 1.8rem;
  color: var(--brown-light);
  margin-bottom: 12px;
}

.result-stats {
  background: var(--bg-panel);
  border: 1px solid rgba(212, 165, 116, 0.2);
  border-radius: 16px;
  padding: 20px;
  margin-bottom: 16px;
}

.result-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid rgba(212, 165, 116, 0.1);
}

.result-row:last-child { border-bottom: none; }

.result-label {
  color: var(--text-dim);
  font-size: 0.95rem;
}

.result-value {
  font-family: 'Dela Gothic One', sans-serif;
  font-size: 1.5rem;
  color: var(--gold);
  text-shadow: 0 0 8px rgba(251, 191, 36, 0.4);
}

.result-rank {
  font-family: 'Dela Gothic One', sans-serif;
  font-size: 1.6rem;
  margin-bottom: 16px;
  min-height: 2.2rem;
}

/* ===== 主人公コメント欄 ===== */
@media (min-width: 700px) {
  .title-container {
    max-width: 620px;
    padding: 42px 24px 24px;
  }

  .game-title {
    font-size: 2.8rem;
  }

  .game-subtitle {
    font-size: 1.2rem;
  }

  .character-preview-frame {
    width: 320px;
    height: 320px;
  }

  .controls-help {
    max-width: 420px;
    margin-left: auto;
    margin-right: auto;
    font-size: 0.9rem;
  }

  .story-container {
    max-width: 520px;
    gap: 20px;
  }

  .story-bubble {
    padding: 22px 28px;
    font-size: 1.08rem;
  }

  .result-container {
    max-width: 520px;
  }

  .character-comment-box {
    padding: 18px;
  }
}

.character-comment-box {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  background: linear-gradient(135deg, rgba(251, 191, 36, 0.15), rgba(212, 165, 116, 0.1));
  border: 1px solid rgba(251, 191, 36, 0.3);
  border-radius: 16px;
  padding: 16px;
  margin-bottom: 20px;
  text-align: left;
}

.character-face {
  flex-shrink: 0;
  width: 60px;
  height: 60px;
}

.character-result-img {
  width: 60px;
  height: 60px;
  object-fit: cover;
  object-position: center 20%;
  transform: scale(1.4);
  border-radius: 50%;
  border: 2px solid var(--gold);
}

.character-speech {
  flex: 1;
  min-width: 0;
}

.character-name {
  font-size: 0.75rem;
  color: var(--gold);
  font-weight: 700;
  margin-bottom: 4px;
}

.character-text {
  font-size: 0.9rem;
  color: var(--cream);
  line-height: 1.6;
  white-space: pre-wrap;
}

/* ===== Responsive: スマホ ===== */
@media (max-width: 500px) {
  .back-to-top-link {
    font-size: 0.75rem;
    padding: 4px 10px;
  }

  .title-container {
    padding: 12px 16px;
  }

  .title-icon {
    font-size: 2.2rem;
    margin-bottom: 4px;
  }

  .game-title {
    font-size: 1.8rem;
    margin-bottom: 4px;
  }

  .character-preview-frame {
    width: 200px;
    height: 200px;
  }

  .character-preview {
    margin-bottom: 8px;
  }

  .btn-primary {
    padding: 12px 32px;
    font-size: 1.1rem;
    margin-bottom: 12px;
  }

  .controls-help {
    padding: 10px;
    margin-bottom: 12px;
    font-size: 0.75rem;
    line-height: 1.6;
  }

  .story-poop-img {
    width: 1080px;
    height: 1080px;
  }

  .story-container {
    padding: 16px;
    gap: 12px;
  }

  .story-bubble {
    padding: 14px 18px;
    font-size: 0.9rem;
  }

  .result-container {
    padding: 10px 12px;
  }

  .result-icon {
    font-size: 1.8rem;
    margin-bottom: 2px;
  }

  .result-title {
    font-size: 1.3rem;
    margin-bottom: 8px;
  }

  .result-stats {
    padding: 10px;
    margin-bottom: 8px;
  }

  .result-rank {
    font-size: 1.1rem;
    margin-bottom: 8px;
  }

  .character-comment-box {
    padding: 10px;
    margin-bottom: 10px;
  }

  .character-text {
    font-size: 0.8rem;
  }

  .combo-text {
    font-size: 1.15rem;
  }
}

/* ===== Responsive: 小さなスマホ（iPhone SE等） ===== */
@media (max-height: 600px) {
  .title-icon {
    font-size: 1.8rem;
    margin-bottom: 2px;
  }

  .game-title {
    font-size: 1.5rem;
  }

  .character-preview-frame {
    width: 140px;
    height: 140px;
  }

  .character-preview {
    margin-bottom: 6px;
  }

  .btn-primary {
    padding: 10px 28px;
    font-size: 1rem;
    margin-bottom: 8px;
  }

  .controls-help {
    padding: 8px;
    margin-bottom: 8px;
    font-size: 0.7rem;
  }

  .story-poop-img {
    width: 840px;
    height: 840px;
  }

  .story-bubble {
    padding: 10px 14px;
    font-size: 0.85rem;
  }
}

/* ===== Responsive: iPad縦向き ===== */
@media (min-width: 768px) and (max-width: 1024px) {
  .title-container {
    padding: 30px 20px;
  }

  .character-preview-frame {
    width: 300px;
    height: 300px;
  }

  .story-poop-img {
    width: 1500px;
    height: 1500px;
  }
}
