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

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

body {
  margin: 0;
  height: 100vh;
  font-family: "M PLUS Rounded 1c", "Noto Sans JP", "Hiragino Maru Gothic Pro", sans-serif;
  background: #eef3f7;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
}

.container {
  margin: 0 auto;
  background: #f8fafc;
  border: 1px solid #cbd5e1;
  width: 100%;
  max-width: 1196px;
  height: 540px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 18px 46px rgba(15, 23, 42, .16);
}

.is-hidden {
  display: none !important;
}

.start-screen {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 28px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, .42) 25%, transparent 25% 50%, rgba(255, 255, 255, .42) 50% 75%, transparent 75%) 0 0 / 46px 46px,
    linear-gradient(180deg, #fff3a8 0%, #bfe9ff 56%, #d8f6ce 100%);
  overflow: hidden;
}

.start-screen::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    url("assets/coin_1.png") 9% 18% / 54px 54px no-repeat,
    url("assets/coin_5.png") 89% 22% / 62px 62px no-repeat,
    url("assets/coin_10.png") 15% 76% / 72px 72px no-repeat,
    url("assets/coin_50.png") 79% 70% / 66px 66px no-repeat,
    url("assets/coin_100.png") 31% 13% / 58px 58px no-repeat,
    url("assets/coin_500.png") 67% 16% / 70px 70px no-repeat;
  opacity: .92;
  pointer-events: none;
}

.start-screen::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 84px;
  background:
    linear-gradient(90deg, #df372f 0 12.5%, #fff7db 12.5% 25%, #df372f 25% 37.5%, #fff7db 37.5% 50%, #df372f 50% 62.5%, #fff7db 62.5% 75%, #df372f 75% 87.5%, #fff7db 87.5% 100%) 0 0 / 240px 44px repeat-x,
    linear-gradient(180deg, #61b36b 44px, #3f8f50 100%);
  border-top: 3px solid rgba(130, 60, 20, .22);
  pointer-events: none;
}

.start-content {
  position: relative;
  z-index: 1;
  width: min(100%, 520px);
  text-align: center;
}

.start-content::before,
.start-content::after {
  position: absolute;
  top: -58px;
  color: #df372f;
  font-size: 42px;
  font-weight: 900;
  line-height: 1;
  text-shadow: 0 3px 0 rgba(255, 255, 255, .75);
}

.start-content::before {
  content: "¥";
  left: 12%;
  transform: rotate(-12deg);
}

.start-content::after {
  content: "100";
  right: 5%;
  color: #24536b;
  transform: rotate(10deg);
}

.start-content h1 {
  margin: 0 0 18px;
  color: #243447;
  font-size: 42px;
  font-weight: 900;
  line-height: 1.18;
}

.start-content p {
  margin: 0 0 28px;
  color: #365064;
  font-size: 18px;
  font-weight: 700;
  line-height: 1.6;
}

.start-btn {
  min-width: 180px;
  border: 2px solid #1f7a49;
  border-radius: 8px;
  background: #2f9e62;
  color: #fff;
  cursor: pointer;
  font-family: inherit;
  font-size: 22px;
  font-weight: 900;
  letter-spacing: 0;
  padding: 14px 34px;
  box-shadow: 0 8px 18px rgba(47, 158, 98, .24);
  transition: transform .1s, background .15s;
}

.start-btn:hover {
  background: #278653;
}

.start-btn:active {
  transform: scale(.96);
}

.game-header {
  height: 56px;
  flex: 0 0 56px;
  padding: 0 28px;
  background: #243447;
  border-bottom: 1px solid #182334;
  display: flex;
  align-items: center;
}

.info {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  width: 100%;
  min-width: 0;
}

#game-title {
  color: #fff;
  font-size: 22px;
  font-weight: 900;
  letter-spacing: 0;
  white-space: nowrap;
}

.score-group {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-shrink: 0;
}

.score-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.28);
  color: #fff;
  border-radius: 8px;
  padding: 4px 14px;
  font-size: 15px;
  font-weight: 700;
  white-space: nowrap;
}

.score-chip .num {
  color: #ffe066;
  font-size: 20px;
  font-weight: 900;
}

.quit-btn {
  order: 2;
  border: 1px solid rgba(255, 255, 255, 0.38);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
  font-weight: 900;
  letter-spacing: 0;
  padding: 8px 14px;
  white-space: nowrap;
  transition: background .15s, transform .1s;
}

.quit-btn:hover {
  background: rgba(255, 255, 255, 0.22);
}

.quit-btn:active {
  transform: scale(.94);
}

.game-main {
  position: relative;
  flex: 1;
  min-height: 0;
  background: #f8fafc;
  overflow: hidden;
  display: grid;
  grid-template-columns: minmax(330px, .95fr) minmax(520px, 1.05fr);
  grid-template-rows: minmax(0, 1fr) 174px;
  gap: 18px;
  padding: 20px;
}

#row-product {
  grid-column: 1;
  grid-row: 1 / 3;
  display: flex;
  flex-direction: column;
  border: 1px solid #e0c46c;
  border-radius: 8px;
  min-height: 0;
  overflow: hidden;
  background: #fff9d9;
}

#product-row {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 30px 26px;
  background:
    radial-gradient(circle at 50% 30%, rgba(255, 255, 255, .88) 0 30%, rgba(255, 255, 255, 0) 58%),
    linear-gradient(180deg, #fff8cf 0%, #fffef0 100%);
}

#product-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 18px;
  min-width: 0;
  height: 100%;
  text-align: center;
}

#product-frame {
  width: min(76%, 260px);
  aspect-ratio: 1;
  height: auto;
  background: #fff;
  border: 2px solid #dfb93b;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 18px 34px rgba(96, 60, 0, 0.12);
  flex-shrink: 0;
  margin-top: 4px;
}

#product-emoji {
  color: #5a3a00;
  font-size: clamp(82px, 14vw, 148px);
  font-weight: 900;
  line-height: 1;
  text-align: center;
  filter: drop-shadow(0 3px 6px rgba(0, 0, 0, 0.14));
  user-select: none;
}

#product-text {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  min-width: 0;
  width: 100%;
}

#product-name {
  color: #1f1708;
  font-size: 34px;
  font-weight: 900;
  line-height: 1.2;
  text-shadow: 0 2px 0 rgba(255, 255, 255, .85);
}

#price-tag {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 198px;
  background: #df372f;
  color: #fff;
  font-size: 44px;
  font-weight: 900;
  border: 2px solid #9f2420;
  border-radius: 8px;
  padding: 12px 28px 17px;
  box-shadow: 0 12px 22px rgba(159, 36, 32, 0.22);
  letter-spacing: 0;
  line-height: 1.14;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-7px); }
  75% { transform: translateX(7px); }
}

#row-tray {
  grid-column: 2;
  grid-row: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
  padding: 16px;
  overflow: hidden;
  border: 1px solid #b7c4d2;
  border-radius: 8px;
  background: #ffffff;
}

#tray-header {
  display: grid;
  grid-template-columns: auto minmax(120px, 1fr) auto;
  grid-template-areas:
    "paid message actions";
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.status-chip {
  display: flex;
  align-items: center;
  gap: 4px;
  background: #f7fbff;
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
  flex-shrink: 0;
}

#paid-chip {
  grid-area: paid;
  border: 1px solid #3b82a6;
  color: #24536b;
}

#paid-chip .val {
  color: #12384c;
  font-size: 22px;
}

#message-box {
  grid-area: message;
  min-width: 0;
  min-height: 38px;
  border-radius: 8px;
  padding: 7px 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 900;
  text-align: center;
  letter-spacing: .5px;
  overflow: hidden;
  white-space: nowrap;
}

.msg-empty {
  background: transparent;
  border: 2px solid transparent;
  color: transparent;
}

.msg-ok {
  background: #e8f5e9;
  border: 2px solid #66bb6a;
  color: #1b5e20;
}

.msg-over {
  background: #fce4ec;
  border: 2px solid #f06292;
  color: #880e4f;
  animation: shake .3s;
}

.msg-hint {
  background: #fff9c4;
  border: 2px solid #ffd54f;
  color: #f57f17;
}

#btn-area {
  grid-area: actions;
  display: flex;
  gap: 10px;
  flex-shrink: 0;
  justify-content: flex-end;
}

.abtn {
  border: none;
  border-radius: 8px;
  padding: 10px 18px;
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
  font-weight: 900;
  letter-spacing: 1px;
  white-space: nowrap;
  transition: transform .1s;
}

.abtn:active {
  transform: scale(.94);
}

#btn-clear {
  background: #7f8794;
  border: 1px solid #5f6875;
  color: #fff;
}

#btn-pay {
  background: #2f9e62;
  border: 1px solid #1f7a49;
  color: #fff;
  box-shadow: 0 5px 14px rgba(47, 158, 98, .24);
  font-size: 15px;
  padding: 10px 24px;
}

#btn-pay.btn-pay-ready:not(:disabled) {
  animation: payReady .55s ease;
}

#btn-pay:disabled {
  background: #ccc;
  border-color: #aaa;
  box-shadow: none;
  cursor: not-allowed;
  opacity: .55;
}

@keyframes payReady {
  0%, 100% { transform: translateY(0); }
  35% { transform: translateY(-6px); }
  65% { transform: translateY(2px); }
}

#coin-tray {
  position: relative;
  flex: 1;
  min-height: 0;
  background: #f5f7fa;
  border: 2px dashed #9aa8b8;
  border-radius: 8px;
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 10px;
  padding: 14px 14px 44px;
  overflow-y: auto;
}

#coin-tray::after {
  content: attr(data-guide);
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: 12px;
  color: #c9a34a;
  display: block;
  font-size: 15px;
  font-weight: 700;
  opacity: .7;
  text-align: center;
  pointer-events: none;
}

.tray-coin {
  position: relative;
  flex-shrink: 0;
  cursor: pointer;
  user-select: none;
  transition: transform .12s;
}

.tray-coin:hover {
  transform: scale(1.15) rotate(-5deg);
}

.tray-coin:active {
  transform: scale(.92);
}

.tray-coin .rx {
  position: absolute;
  top: -4px;
  right: -4px;
  width: 15px;
  height: 15px;
  background: #ff4444;
  border-radius: 50%;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 900;
  line-height: 1;
  opacity: 0;
  pointer-events: none;
  transition: opacity .15s;
}

.tray-coin:hover .rx {
  opacity: 1;
}

#row-coins {
  grid-column: 2;
  grid-row: 2;
  background: #e8f4f2;
  border: 1px solid #b4ccc8;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 14px;
}

#coin-btn-row {
  display: grid;
  grid-template-columns: repeat(6, minmax(68px, 1fr));
  gap: 10px;
  width: 100%;
}

.coin-btn {
  width: 100%;
  min-height: 118px;
  background: #ffffff;
  border: 1px solid #b4ccc8;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 6px;
  font-family: inherit;
  user-select: none;
  box-shadow: 0 5px 12px rgba(36, 74, 69, .08);
  transition: background .15s, border-color .15s, transform .12s;
}

.coin-btn:hover {
  background: #f7fffd;
  border-color: #4c8f84;
  transform: translateY(-3px);
}

.coin-btn:active {
  transform: scale(.93);
}

.coin-btn:disabled {
  cursor: not-allowed;
  opacity: .4;
  transform: none;
}

.coin-btn .clabel {
  color: #244a45;
  font-size: 13px;
  font-weight: 900;
}

.coin-btn-icon {
  width: 68px;
  height: 68px;
}

.coin-img {
  display: block;
  object-fit: contain;
  pointer-events: none;
}

#overlay {
  position: absolute;
  inset: 0;
  z-index: 100;
  background: rgba(0, 0, 0, .46);
  display: none;
  align-items: center;
  justify-content: center;
}

#overlay.show {
  display: flex;
}

#result-card {
  max-width: 420px;
  background: linear-gradient(160deg, #fffde7, #fff9c4);
  border: 4px solid #ffd54f;
  border-radius: 20px;
  padding: 28px 48px;
  text-align: center;
  box-shadow: 0 12px 40px rgba(0, 0, 0, .3);
  animation: popIn .4s;
}

@keyframes popIn {
  0% { transform: scale(.6) rotate(-6deg); opacity: 0; }
  70% { transform: scale(1.06) rotate(1deg); }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}

#result-emoji {
  margin-bottom: 8px;
  color: #e65100;
  font-size: 32px;
  font-weight: 900;
}

#result-title {
  margin-bottom: 6px;
  color: #e65100;
  font-size: 30px;
  font-weight: 900;
  letter-spacing: 2px;
}

#result-sub {
  margin-bottom: 22px;
  color: #5a3a00;
  font-size: 17px;
  font-weight: 700;
  line-height: 1.7;
  white-space: pre-line;
}

#btn-next-result {
  background: linear-gradient(135deg, #ff9a3c, #f57f00);
  border: 3px solid #c05000;
  border-radius: 16px;
  color: #fff;
  cursor: pointer;
  font-family: inherit;
  font-size: 18px;
  font-weight: 900;
  letter-spacing: 1px;
  padding: 13px 36px;
  box-shadow: 0 4px 16px rgba(200, 100, 0, .3);
  transition: transform .1s;
}

#btn-next-result:hover {
  transform: scale(1.05);
}

#btn-next-result:active {
  transform: scale(.96);
}

@media (max-width: 920px) {
  .game-header {
    padding: 0 12px;
  }

  body {
    align-items: stretch;
    overflow: auto;
  }

  .container {
    min-height: 100vh;
    height: auto;
    border: 0;
  }

  .game-main {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(220px, 1fr) auto;
    gap: 12px;
    padding: 12px;
    overflow: visible;
  }

  #row-product {
    grid-column: 1;
    grid-row: 1;
  }

  #row-tray {
    grid-column: 1;
    grid-row: 2;
  }

  #row-coins {
    grid-column: 1;
    grid-row: 3;
  }

  #game-title {
    font-size: 16px;
  }

  .start-screen {
    padding: 22px;
  }

  .start-screen::before {
    background:
      url("assets/coin_1.png") 8% 16% / 38px 38px no-repeat,
      url("assets/coin_5.png") 88% 18% / 44px 44px no-repeat,
      url("assets/coin_10.png") 12% 78% / 50px 50px no-repeat,
      url("assets/coin_50.png") 84% 74% / 48px 48px no-repeat,
      url("assets/coin_100.png") 28% 10% / 42px 42px no-repeat,
      url("assets/coin_500.png") 70% 12% / 48px 48px no-repeat;
  }

  .start-screen::after {
    height: 62px;
    background:
      linear-gradient(90deg, #df372f 0 12.5%, #fff7db 12.5% 25%, #df372f 25% 37.5%, #fff7db 37.5% 50%, #df372f 50% 62.5%, #fff7db 62.5% 75%, #df372f 75% 87.5%, #fff7db 87.5% 100%) 0 0 / 180px 34px repeat-x,
      linear-gradient(180deg, #61b36b 34px, #3f8f50 100%);
  }

  .start-content h1 {
    font-size: 30px;
  }

  .start-content::before,
  .start-content::after {
    top: -40px;
    font-size: 28px;
  }

  .start-content p {
    font-size: 15px;
  }

  .start-btn {
    min-width: 150px;
    font-size: 18px;
    padding: 12px 26px;
  }

  .score-group {
    gap: 6px;
  }

  .score-chip {
    padding: 3px 8px;
    font-size: 12px;
  }

  .quit-btn {
    padding: 6px 9px;
    font-size: 12px;
  }

  #product-row {
    padding: 18px 14px;
  }

  #product-info {
    gap: 14px;
  }

  #product-frame {
    width: min(44%, 150px);
    height: auto;
  }

  #product-emoji {
    font-size: 52px;
  }

  #product-name {
    font-size: 20px;
  }

  #price-tag {
    font-size: 24px;
    padding: 7px 16px 11px;
  }

  #row-tray {
    padding: 8px 10px;
  }

  #tray-header {
    grid-template-columns: 1fr auto;
    grid-template-areas:
      "paid actions"
      "message message";
    gap: 8px;
  }

  .status-chip,
  #message-box {
    font-size: 12px;
  }

  .abtn {
    padding: 7px 10px;
    font-size: 12px;
  }

  #coin-btn-row {
    grid-template-columns: repeat(3, minmax(72px, 1fr));
    gap: 8px;
  }

  .coin-btn {
    min-height: 108px;
    padding: 6px 4px;
  }
}
