:root {
  --bg: #2b1d18;
  --panel: #fff3d7;
  --ink: #2a1712;
  --accent: #e45a2c;
  --accent-dark: #973719;
  --gold: #ffd15c;
  --green: #5fb870;
  --sky: #83c9ef;
  --shadow: rgba(0, 0, 0, .22);
}

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

html,
body {
  min-height: 100%;
  margin: 0;
  overscroll-behavior: none;
  background: radial-gradient(circle at top, #604034 0%, var(--bg) 62%);
  color: var(--ink);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  touch-action: manipulation;
  user-select: none;
}

button {
  font: inherit;
}

.app {
  width: min(100vw, 430px);
  min-height: 100svh;
  margin: 0 auto;
  padding: env(safe-area-inset-top) 16px env(safe-area-inset-bottom);
  display: grid;
  place-items: center;
}

.screen {
  display: none;
  width: 100%;
  min-height: calc(100svh - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  padding: 28px 0;
  text-align: center;
}

.screen.is-active {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  color: #fff7e8;
  font-size: clamp(46px, 15vw, 72px);
  line-height: .9;
  letter-spacing: -0.08em;
  text-shadow: 0 6px 0 var(--accent-dark), 0 10px 20px var(--shadow);
}

h1 span {
  color: var(--gold);
}

h2 {
  color: #fff7e8;
  font-size: clamp(34px, 11vw, 52px);
  line-height: 1;
  text-shadow: 0 5px 0 var(--accent-dark), 0 10px 20px var(--shadow);
}

.lead,
.result-copy,
.ending-line,
.tiny-note,
.flavor-text {
  color: #fff7e8;
  line-height: 1.75;
  font-weight: 700;
}

.lead {
  font-size: 14px;
}

.tiny-note,
.flavor-text {
  font-size: 12px;
  opacity: .88;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  padding: 6px 12px;
  border: 3px solid var(--ink);
  background: var(--gold);
  box-shadow: 0 5px 0 var(--ink);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: .08em;
}

.badge.bad {
  background: #c8c1ba;
}

.badge.good {
  background: #96e879;
}

.pixel-canvas {
  width: min(84vw, 320px);
  height: auto;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  border: 5px solid var(--ink);
  background: var(--sky);
  box-shadow: 0 10px 0 var(--ink), 0 18px 30px var(--shadow);
}

.stage-canvas {
  margin-top: 4px;
}

.status-card {
  width: min(100%, 330px);
  padding: 12px 14px;
  border: 4px solid var(--ink);
  background: var(--panel);
  box-shadow: 0 6px 0 var(--ink);
  font-size: 12px;
  line-height: 1.7;
  font-weight: 900;
}

.primary-button,
.sub-button,
.tap-button {
  width: min(100%, 330px);
  min-height: 54px;
  border: 4px solid var(--ink);
  border-radius: 0;
  color: var(--ink);
  font-weight: 900;
  box-shadow: 0 7px 0 var(--ink);
  cursor: pointer;
}

.primary-button,
.tap-button {
  background: var(--accent);
  color: #fff7e8;
  text-shadow: 0 2px 0 var(--accent-dark);
}

.sub-button {
  min-height: 44px;
  background: var(--panel);
}

.primary-button:active,
.sub-button:active,
.tap-button:active {
  transform: translateY(5px);
  box-shadow: 0 2px 0 var(--ink);
}

.game-screen.screen.is-active {
  justify-content: flex-start;
  padding-top: max(18px, env(safe-area-inset-top));
}

.game-header {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  width: min(100%, 360px);
}

.game-header > div {
  padding: 10px;
  border: 4px solid var(--ink);
  background: var(--panel);
  box-shadow: 0 5px 0 var(--ink);
}

.label {
  display: block;
  font-size: 10px;
  font-weight: 900;
  letter-spacing: .1em;
  opacity: .65;
}

.game-header strong {
  display: block;
  font-size: 30px;
  line-height: 1;
}

.progress-wrap {
  width: min(100%, 360px);
  height: 22px;
  border: 4px solid var(--ink);
  background: #ffe7af;
  box-shadow: 0 5px 0 var(--ink);
  overflow: hidden;
}

.progress-bar {
  width: 0%;
  height: 100%;
  background: repeating-linear-gradient(90deg, var(--green) 0 12px, #84d96e 12px 24px);
  transition: width .12s linear;
}

.meter {
  width: min(100%, 360px);
  padding: 12px 10px;
  border: 4px solid var(--ink);
  background: var(--panel);
  box-shadow: 0 6px 0 var(--ink);
}

.meter-track {
  position: relative;
  height: 58px;
  border: 4px solid var(--ink);
  background: #fffaf0;
  overflow: hidden;
}

.good-zone,
.perfect-zone,
.cheer-line,
.moving-bar {
  position: absolute;
  top: 0;
  bottom: 0;
}

.good-zone {
  left: 50%;
  width: 92px;
  transform: translateX(-50%);
  background: rgba(95, 184, 112, .22);
}

.perfect-zone {
  left: 50%;
  width: 28px;
  transform: translateX(-50%);
  background: rgba(255, 209, 92, .48);
}

.cheer-line {
  left: 50%;
  width: 4px;
  transform: translateX(-50%);
  background: var(--accent);
  box-shadow: 0 0 0 2px #fff7e8;
  z-index: 2;
}

.moving-bar {
  left: 0;
  width: 18px;
  background: #2f6fbd;
  box-shadow: inset 0 0 0 4px #73a9ff, 0 0 0 3px var(--ink);
  z-index: 3;
}

.meter-caption {
  margin-top: 10px;
  font-size: 12px;
  font-weight: 900;
}

.meter-caption span {
  color: var(--accent-dark);
}

.tap-button {
  min-height: 74px;
  font-size: 22px;
}

.judge-text {
  min-height: 30px;
  color: var(--gold);
  font-size: 24px;
  font-weight: 900;
  text-shadow: 0 3px 0 var(--accent-dark);
}

.item-icon {
  width: 122px;
  height: 122px;
  display: grid;
  place-items: center;
  border: 5px solid var(--ink);
  background: var(--panel);
  box-shadow: 0 8px 0 var(--ink);
  font-size: 60px;
}

.hidden {
  display: none !important;
}

@media (max-height: 720px) {
  .screen.is-active {
    gap: 10px;
    padding-top: 16px;
    padding-bottom: 16px;
  }

  .pixel-canvas {
    width: min(70vw, 260px);
  }

  .tap-button {
    min-height: 62px;
  }

  h1 {
    font-size: clamp(40px, 13vw, 58px);
  }
}

/* 追加調整：スタート画面の主役を「ブッ立つ」に寄せる */
h1 {
  white-space: nowrap;
  font-size: clamp(38px, 13vw, 64px);
  letter-spacing: -0.1em;
}

.status-card {
  border: 0;
  box-shadow: none;
  background: rgba(255, 247, 232, .16);
  color: #fff7e8;
  text-align: left;
  padding: 10px 14px;
}

.start-note {
  width: min(100%, 330px);
  color: #fff7e8;
  font-size: 13px;
  line-height: 1.6;
  font-weight: 900;
  opacity: .95;
  padding: 0 4px;
}

#startButton {
  min-height: 86px;
  font-size: clamp(28px, 9vw, 40px);
  letter-spacing: .02em;
  box-shadow: 0 10px 0 var(--ink), 0 18px 30px var(--shadow);
}

#resetButton {
  width: min(100%, 260px);
  min-height: 42px;
  font-size: 12px;
}

button:disabled {
  opacity: .55;
  transform: none !important;
  box-shadow: 0 7px 0 var(--ink) !important;
  cursor: wait;
}

#itemButton:disabled::after {
  content: "  ・・・";
}

.result-copy {
  white-space: pre-line;
}

.link-buttons {
  width: min(100%, 330px);
  display: grid;
  gap: 10px;
}

.link-button {
  display: grid;
  place-items: center;
  min-height: 48px;
  padding: 10px 12px;
  border: 4px solid var(--ink);
  background: var(--panel);
  color: var(--ink);
  box-shadow: 0 6px 0 var(--ink);
  text-decoration: none;
  font-size: 12px;
  font-weight: 900;
  line-height: 1.35;
}

.link-button:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 var(--ink);
}

@media (max-height: 720px) {
  #startButton {
    min-height: 72px;
    font-size: clamp(24px, 8vw, 34px);
  }
}

/* 失敗画面の再挑戦ボタンだけ、改行されないよう少し小さくする */
#failScreen .primary-button {
  font-size: 12px;
  letter-spacing: -0.04em;
}

/* ゲーム中：ゲージ・スコアを応援ボタン付近に集約 */
.game-screen.screen.is-active {
  gap: 10px;
}

.game-screen .stage-canvas {
  width: min(72vw, 270px);
}

.game-screen .game-header {
  gap: 8px;
}

.game-screen .game-header > div {
  padding: 7px 10px;
}

.game-screen .game-header strong {
  font-size: 24px;
}

.game-screen .progress-wrap {
  height: 18px;
}

.game-screen .tap-button {
  margin-top: 2px;
}


/* 4回目：150ポイント到達後のMOREモード */
.game-screen.is-more-mode .game-header > div {
  background: var(--gold);
  animation: morePulse .45s steps(2, end) infinite;
}

.game-screen.is-more-mode #scoreText {
  color: var(--accent);
  text-shadow: 2px 2px 0 #fff7e8, 4px 4px 0 var(--ink);
}

.game-screen.is-more-mode .progress-wrap {
  background: #fff7e8;
  box-shadow: 0 5px 0 var(--ink), 0 0 18px var(--gold);
}

.game-screen.is-more-mode .progress-bar {
  background: repeating-linear-gradient(
    90deg,
    var(--gold) 0 10px,
    #fff7e8 10px 20px,
    var(--accent) 20px 30px,
    #96e879 30px 40px
  );
  animation: moreStripe .35s linear infinite;
}

.game-screen.is-more-mode .judge-text {
  color: #fff7e8;
  font-size: 30px;
  text-shadow: 0 3px 0 var(--accent-dark), 0 0 14px var(--gold);
  animation: moreBounce .35s steps(2, end) infinite;
}

.game-screen.is-more-mode .tap-button {
  background: var(--gold);
  color: var(--ink);
  text-shadow: none;
  box-shadow: 0 7px 0 var(--ink), 0 0 18px var(--gold);
}

@keyframes morePulse {
  0% {
    transform: rotate(-1deg);
  }
  100% {
    transform: rotate(1deg);
  }
}

@keyframes moreStripe {
  0% {
    background-position: 0 0;
  }
  100% {
    background-position: 40px 0;
  }
}

@keyframes moreBounce {
  0% {
    transform: translateY(0) scale(1);
  }
  100% {
    transform: translateY(-2px) scale(1.06);
  }
}

/* クリア画面：4ゲーム目スコア表示とヒント */
.clear-score {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 6px 12px;
  border: 3px solid var(--ink);
  background: var(--panel);
  color: var(--ink);
  box-shadow: 0 5px 0 var(--ink);
  font-size: 13px;
  font-weight: 900;
  line-height: 1.2;
}

.clear-hint {
  width: min(100%, 330px);
  margin-top: -4px;
  color: rgba(255, 247, 232, .58);
  font-size: 10px;
  line-height: 1.6;
  font-weight: 700;
}


/* クリア画面：非公式注意書きだけ少し小さくする */
#clearScreen .link-buttons + .result-copy {
  font-size: 80%;
}
