* {
  box-sizing: border-box;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation; /*タブレット連打時の拡大防止 */
}

html {
  margin: 0;
  height: 100%;
}

body {
  margin: 0;
  height: 100vh;
  font-family: "Hiragino Sans", "Meiryo", sans-serif;
  background: #f2f2f2;
  display: flex;
  justify-content: center;
  align-items: center;
}

.container {
  margin: 0 auto;
  background: #ffffff;
  border: 2px solid #333;
  width: 100%;
  max-width: 1196px;
  height: 540px;
  display: flex;
  flex-direction: column;
}

.game-header {
  height: 50px;
  padding: 8px 12px;
  background: #ffd978;
  border-bottom: 2px solid #d9a72a;
  flex: 0 0 50px;
  display: flex;
  align-items: center;
}

.info {
  position: relative;
  display: grid;
  grid-template-columns: minmax(88px, 1fr) auto minmax(120px, 1fr) auto;
  align-items: center;
  gap: 10px;
  width: 100%;
  font-weight: bold;
}

.header-message {
  grid-column: 2;
  color: #7a2800;
  font-size: 22px;
  font-weight: 800;
  text-align: center;
  white-space: nowrap;
}

.header-record {
  grid-column: 3;
  justify-self: end;
  color: #7a2800;
  font-size: 15px;
  min-height: 1em;
  text-align: right;
  white-space: nowrap;
}

.quit-btn {
  grid-column: 4;
  justify-self: end;
  display: none;
  border: 2px solid #9f5a00;
  border-radius: 8px;
  padding: 5px 12px;
  background: #ffffff;
  color: #7a2800;
  cursor: pointer;
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  line-height: 1;
}

.quit-btn:hover {
  background: #fff0d0;
}

.game-main {
  position: relative;
  background: linear-gradient(160deg, #fff8e7 0%, #fff0f8 100%);
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  touch-action: none;
}

.timer-bar-wrap {
  position: relative;
  flex: 0 0 24px;
  margin: 0;
  background: #fffaf0;
  border-bottom: 2px solid #e8c65d;
  overflow: hidden;
  z-index: 1;
}

.timer-bar {
  width: 100%;
  height: 100%;
  background: #61c879;
  transition: width 0.12s linear, background 0.25s ease;
}

.tray-bar {
  position: absolute;
  top: 10px;
  left: 14px;
  right: 14px;
  height: 62px;
  background: transparent;
  border: 0;
  display: flex;
  align-items: center;
  padding: 0;
  gap: 10px;
  overflow: visible;
  pointer-events: none;
  z-index: 5;
}

.tray-gems-row {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  overflow-x: auto;
  overflow-y: visible;
  scrollbar-width: none;
}

.tray-gems-row::-webkit-scrollbar {
  display: none;
}

.tray-gem-item {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  filter: drop-shadow(0 5px 5px rgba(75, 48, 18, 0.25));
}

.tray-gem-item img {
  width: 36px;
  height: 36px;
  object-fit: contain;
  filter: drop-shadow(0 0 6px rgba(160, 80, 255, 0.6));
}

.tray-gem-item span {
  color: #5500aa;
  font-size: 9px;
  font-weight: 700;
  white-space: nowrap;
}

.sand-area {
  position: relative;
  flex: 1 1 0;
  min-height: 0;
  overflow: hidden;
  background: #e8c97a;
  cursor: none;
}

.sand-bg {
  position: absolute;
  inset: 0;
  z-index: 0;
  background: url("assets/bg.png") center / cover no-repeat;
}

#scratchCanvas {
  position: absolute;
  top: 0;
  left: 0;
  display: block;
  z-index: 4;
  cursor: none;
}

.gem-img {
  position: absolute;
  z-index: 2;
  width: 160px;
  height: 160px;
  object-fit: contain;
  transform: translate(-50%, -50%) scale(1);
  transition: transform 0.5s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.2s ease;
  pointer-events: none;
  filter: drop-shadow(0 0 28px rgba(255, 220, 80, 0.95));
}

.cursor-hand {
  position: absolute;
  z-index: 6;
  width: 68px;
  height: 86px;
  pointer-events: none;
  transform: translate(-45%, -82%) rotate(-28deg);
  opacity: 0;
  filter: drop-shadow(0 4px 4px rgba(90, 54, 10, 0.28));
  transition: opacity 0.12s ease;
}

.cursor-hand.active {
  opacity: 1;
}

.cursor-hand::before,
.cursor-hand::after {
  position: absolute;
  content: "";
}

.cursor-hand::before {
  left: 30px;
  top: 4px;
  width: 8px;
  height: 76px;
  border-radius: 999px;
  background: linear-gradient(90deg, #8f5525, #d89a4d 50%, #7b431b);
}

.cursor-hand::after {
  left: 8px;
  bottom: 2px;
  width: 52px;
  height: 26px;
  border-radius: 4px 4px 8px 8px;
  background:
    linear-gradient(#6f421e, #a9662d) center top / 52px 7px no-repeat,
    repeating-linear-gradient(90deg, #6f421e 0 5px, transparent 5px 11px) center 6px / 52px 20px no-repeat;
}

.sparkle {
  position: absolute;
  z-index: 5;
  font-size: 20px;
  pointer-events: none;
  animation: sparklePop 0.8s ease-out forwards;
}

@keyframes sparklePop {
  0% {
    opacity: 1;
    transform: translate(0, 0) scale(1);
  }

  100% {
    opacity: 0;
    transform: translate(var(--dx), var(--dy)) scale(0);
  }
}

.choices-panel {
  flex: 0 0 108px;
  background: linear-gradient(180deg, #fff3c0 0%, #ffe8f4 100%);
  border-top: 3px dashed #ffd966;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 18px 8px;
  z-index: 1;
}

.choice-question {
  color: #7a3800;
  font-size: 15px;
  font-weight: 800;
  line-height: 1;
  text-align: center;
}

.choices-strip {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.choice-btn {
  flex: 1;
  max-width: 220px;
  min-width: 0;
  min-height: 68px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  border: 2px solid #d9ab26;
  border-radius: 8px;
  padding: 7px 10px;
  background: linear-gradient(135deg, #fff8e0, #ffe8f8);
  box-shadow: 0 3px 10px rgba(255, 180, 0, 0.12);
  color: #7a3800;
  cursor: pointer;
  font: inherit;
  font-size: 17px;
  font-weight: 700;
  text-align: center;
  transition: background-color 0.18s ease, border-color 0.18s ease, transform 0.18s ease, box-shadow 0.18s ease;
  white-space: nowrap;
}

.choice-name {
  line-height: 1.05;
}

.choice-kana {
  color: #8b5a00;
  font-size: 13px;
  font-weight: 800;
  line-height: 1;
}

.choice-btn:hover:not(:disabled) {
  border-color: #ff9900;
  background: linear-gradient(135deg, #ffe066, #ffb0d8);
  transform: translateY(-3px) scale(1.04);
}

.choice-btn:disabled:not(.correct):not(.wrong) {
  cursor: not-allowed;
  opacity: 0.5;
  transform: none;
  animation: none;
}

.choice-btn.correct {
  border-color: #319e31;
  background: linear-gradient(135deg, #a8ff80, #80ffcc);
  animation: correctPop 0.4s ease;
}

.choice-btn.wrong {
  border-color: #bb1e1e;
  background: linear-gradient(135deg, #ffb0b0, #ff8888);
  animation: wrongShake 0.35s ease;
}

@keyframes correctPop {
  0% {
    transform: scale(1);
  }

  50% {
    transform: scale(1.12);
  }

  100% {
    transform: scale(1);
  }
}

@keyframes wrongShake {
  0%,
  100% {
    transform: translateX(0);
  }

  25% {
    transform: translateX(-7px);
  }

  75% {
    transform: translateX(7px);
  }
}

.choice-btn.ready {
  animation: buttonBounce 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

.choice-btn.ready:nth-child(2) {
  animation-delay: 0.08s;
}

.choice-btn.ready:nth-child(3) {
  animation-delay: 0.16s;
}

.choice-btn.ready:nth-child(4) {
  animation-delay: 0.24s;
}

@keyframes buttonBounce {
  0% {
    opacity: 0;
    transform: translateY(36px) scale(0.7);
  }

  60% {
    opacity: 1;
    transform: translateY(-8px) scale(1.06);
  }

  80% {
    transform: translateY(3px) scale(0.98);
  }

  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.choice-btn.waiting {
  animation: buttonWaiting 1.2s ease-in-out infinite alternate;
}

.choice-btn.waiting:nth-child(2) {
  animation-delay: 0.15s;
}

.choice-btn.waiting:nth-child(3) {
  animation-delay: 0.3s;
}

.choice-btn.waiting:nth-child(4) {
  animation-delay: 0.45s;
}

@keyframes buttonWaiting {
  0% {
    box-shadow: 0 3px 10px rgba(255, 180, 0, 0.12);
    transform: translateY(0) scale(1);
  }

  100% {
    box-shadow: 0 10px 24px rgba(255, 150, 0, 0.35);
    transform: translateY(-5px) scale(1.04);
  }
}

.fly-gem {
  position: fixed;
  z-index: 300;
  object-fit: contain;
  pointer-events: none;
  filter: drop-shadow(0 0 16px rgba(255, 220, 80, 0.9));
}

.celebrate {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.celebrate-text {
  font-size: 72px;
  font-weight: 700;
  color: #ffbf00;
  text-shadow: 4px 4px 0 #fff, -2px -2px 0 #fff;
  animation: celebrateBig 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

.celebrate-text.miss {
  color: #ff6b7a;
  animation: missBig 0.7s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

@keyframes celebrateBig {
  0% {
    opacity: 0;
    transform: scale(0.2) rotate(-20deg);
  }

  100% {
    opacity: 1;
    transform: scale(1) rotate(0);
  }
}

@keyframes missBig {
  0% {
    opacity: 0;
    transform: scale(0.35) rotate(8deg);
  }

  40% {
    opacity: 1;
    transform: scale(1.08) rotate(-4deg);
  }

  100% {
    opacity: 1;
    transform: scale(1) rotate(0);
  }
}

.overlay-screen {
  position: absolute;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  text-align: center;
}

.intro-screen {
  background: linear-gradient(135deg, #ffe066 0%, #ff9500 50%, #ff6090 100%);
}

.end-screen {
  display: none;
  position: absolute;
  overflow: hidden;
  background:
    radial-gradient(circle at 18% 24%, rgba(255, 255, 255, 0.95) 0 3px, transparent 4px),
    radial-gradient(circle at 78% 28%, rgba(255, 255, 255, 0.85) 0 4px, transparent 5px),
    radial-gradient(circle at 34% 76%, rgba(255, 255, 255, 0.75) 0 5px, transparent 6px),
    linear-gradient(135deg, #58d8ff 0%, #8af28e 36%, #ffe266 66%, #ff8ed4 100%);
  background-size: 120px 120px, 150px 150px, 180px 180px, 100% 100%;
  animation: endSkyDrift 8s linear infinite;
}

.end-screen::before,
.end-screen::after {
  position: absolute;
  content: "";
  pointer-events: none;
}

.end-screen::before {
  inset: -24%;
  background:
    radial-gradient(circle, rgba(255, 255, 255, 0.9) 0 7px, transparent 8px),
    radial-gradient(circle, rgba(255, 240, 120, 0.85) 0 10px, transparent 11px),
    radial-gradient(circle, rgba(255, 142, 212, 0.72) 0 9px, transparent 10px),
    radial-gradient(circle, rgba(96, 222, 255, 0.78) 0 8px, transparent 9px);
  background-position: 8% 18%, 84% 16%, 22% 82%, 76% 78%;
  background-size: 210px 210px, 250px 250px, 230px 230px, 270px 270px;
  animation: endBubbleFloat 7s ease-in-out infinite alternate;
}

.end-screen::after {
  inset: 0;
  background:
    linear-gradient(70deg, transparent 0 34%, rgba(255, 255, 255, 0.55) 36%, transparent 40%),
    linear-gradient(110deg, transparent 0 56%, rgba(255, 255, 255, 0.35) 58%, transparent 62%);
  animation: endLightSweep 3.8s ease-in-out infinite;
}

.end-screen > * {
  position: relative;
  z-index: 1;
}

@keyframes endSkyDrift {
  to {
    background-position: 120px 70px, -150px 95px, 90px -180px, 0 0;
  }
}

@keyframes endBubbleFloat {
  from {
    transform: translateY(10px) scale(1);
  }

  to {
    transform: translateY(-18px) scale(1.04);
  }
}

@keyframes endLightSweep {
  0%,
  100% {
    transform: translateX(-18%);
    opacity: 0.25;
  }

  50% {
    transform: translateX(18%);
    opacity: 0.75;
  }
}

.intro-title {
  color: #ffffff;
  font-size: 48px;
  font-weight: 700;
  text-shadow: 3px 3px 0 #c04000;
  animation: titleBounce 1s ease infinite alternate;
}

@keyframes titleBounce {
  from {
    transform: translateY(0);
  }

  to {
    transform: translateY(-7px);
  }
}

.intro-sub {
  color: #fff8d0;
  font-size: 19px;
  font-weight: 700;
}

.gem-row {
  display: flex;
  gap: 12px;
}

.gem-row img {
  width: 56px;
  height: 56px;
  object-fit: contain;
  filter: drop-shadow(0 0 10px rgba(255, 255, 255, 0.9));
  animation: gemFloat 2s ease-in-out infinite;
}

.gem-row img:nth-child(2) {
  animation-delay: 0.3s;
}

.gem-row img:nth-child(3) {
  animation-delay: 0.6s;
}

.gem-row img:nth-child(4) {
  animation-delay: 0.9s;
}

.gem-row img:nth-child(5) {
  animation-delay: 1.2s;
}

@keyframes gemFloat {
  0%,
  100% {
    transform: translateY(0);
  }

  50% {
    transform: translateY(-7px);
  }
}

.big-btn {
  border: 0;
  border-radius: 8px;
  padding: 11px 40px;
  background: #ffffff;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
  cursor: pointer;
  font: inherit;
  font-size: 25px;
  font-weight: 700;
  transition: transform 0.2s ease;
}

.big-btn:hover {
  transform: scale(1.07);
}

.start-btn {
  color: #e05000;
}

.restart-btn {
  color: #6000a0;
}

.end-title {
  color: #ffffff;
  font-size: 42px;
  font-weight: 700;
  text-shadow: 0 4px 0 #5b48c8, 0 8px 18px rgba(60, 35, 120, 0.28);
  animation: endTitlePop 1.4s ease-in-out infinite alternate;
}

.end-message {
  min-width: 180px;
  border: 3px solid rgba(255, 255, 255, 0.9);
  border-radius: 8px;
  padding: 7px 22px;
  background: rgba(255, 255, 255, 0.88);
  color: #e05086;
  font-size: 28px;
  font-weight: 900;
  box-shadow: 0 8px 0 rgba(94, 92, 200, 0.28);
  animation: endMessageBounce 0.9s ease-in-out infinite alternate;
}

.end-score {
  color: #ffffff;
  font-size: 24px;
  font-weight: 700;
  text-shadow: 0 3px 0 rgba(75, 60, 150, 0.55);
}

@keyframes endTitlePop {
  to {
    transform: rotate(-1deg) translateY(-4px);
  }
}

@keyframes endMessageBounce {
  to {
    transform: translateY(-5px) rotate(1deg);
  }
}

.end-gems {
  max-width: min(92%, 600px);
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.end-gem {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.end-gem img {
  width: 44px;
  height: 44px;
  object-fit: contain;
  filter: drop-shadow(0 0 8px rgba(255, 255, 255, 0.55));
}

.end-gem span {
  color: #ffffff;
  font-size: 11px;
  font-weight: 700;
}

@media (max-width: 640px) {
  .info {
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 6px;
  }

  .header-message {
    grid-column: 2;
    font-size: 17px;
    white-space: nowrap;
    line-height: 1.2;
  }

  .header-record {
    display: none;
  }

  .quit-btn {
    grid-column: 3;
    padding: 5px 8px;
    font-size: 12px;
  }

  .tray-bar {
    top: 8px;
    left: 8px;
    right: 8px;
    height: 56px;
  }

  .choices-panel {
    flex-basis: 112px;
    padding: 6px 8px 7px;
  }

  .choice-question {
    font-size: 13px;
  }

  .choices-strip {
    gap: 6px;
  }

  .choice-btn {
    min-height: 62px;
    padding: 6px 4px;
    font-size: 13px;
  }

  .choice-kana {
    font-size: 11px;
  }

  .gem-img {
    width: 124px;
    height: 124px;
  }

  .intro-title {
    font-size: 34px;
  }

  .intro-sub {
    font-size: 15px;
    padding: 0 18px;
  }

  .gem-row {
    gap: 7px;
  }

  .gem-row img {
    width: 42px;
    height: 42px;
  }

  .celebrate-text {
    font-size: 44px;
  }
}
