:root {
  --ink: #171717;
  --paper: #fffdf6;
  --yellow: #ffd332;
  --black: #1d1d1d;
  --red: #ff4b4b;
  --blue: #2377ff;
  --green: #16a05d;
  --orange: #ff9f1c;
  --shadow: 0 18px 45px rgba(16, 18, 24, .18);
  --radius: 8px;
  font-family: "Arial", "Hiragino Kaku Gothic ProN", "Yu Gothic", Meiryo, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(90deg, rgba(255, 211, 50, .14) 0 12px, transparent 12px 24px),
    linear-gradient(135deg, #fff8d7 0%, #f5fbff 42%, #fff 100%);
  overflow: hidden;
}

button,
textarea {
  font: inherit;
}

/*
 * 左上の共通バー（← ゲーム一覧 / Xで共有）はポータル共通のCSSで固定配置される。
 * 常に見えている必要があるので、盤面の上にバー1本分の余白を確保して重ねない。
 */

.phone-shell {
  height: 100svh;
  display: grid;
  place-items: center;
  padding: 8px;
  padding-top: calc(48px + env(safe-area-inset-top));
}

.game-card {
  position: relative;
  width: min(100%, 430px);
  height: 100%;
  max-height: 820px;
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  grid-template-areas:
    "hud"
    "combo"
    "counter"
    "actions";
  overflow: hidden;
  border: 4px solid var(--black);
  border-radius: 18px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.hud {
  grid-area: hud;
  display: grid;
  grid-template-columns: 78px 1fr 88px;
  align-items: center;
  gap: 8px;
  padding: calc(8px + env(safe-area-inset-top)) 12px 7px;
  background: linear-gradient(90deg, var(--black) 0 26%, var(--yellow) 26% 100%);
  color: #fff;
}

.brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-width: 0;
  color: var(--black);
}

.brand h1 {
  margin: 0;
  font-size: clamp(17px, 5.4vw, 24px);
  line-height: 1;
  white-space: nowrap;
}

.store-light {
  width: 12px;
  height: 24px;
  border-radius: 3px;
  background: linear-gradient(#ff4b4b 0 33%, #fff 33% 66%, #2377ff 66%);
  border: 2px solid var(--black);
}

.meter {
  display: grid;
  gap: 1px;
  min-width: 0;
  padding: 4px 5px;
  border: 2px solid currentColor;
  border-radius: var(--radius);
  text-align: center;
  background: rgba(255, 255, 255, .12);
}

.meter:last-child {
  color: var(--black);
  background: rgba(255, 255, 255, .42);
}

.meter-label {
  font-size: 9px;
  font-weight: 900;
  letter-spacing: 0;
}

.meter strong {
  font-size: clamp(18px, 5vw, 22px);
  line-height: 1;
}

.combo-row {
  grid-area: combo;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 12px;
  border-bottom: 3px solid var(--black);
  background: #fff;
  font-weight: 900;
  font-size: 13px;
}

#combo {
  flex: 0 0 auto;
  color: var(--red);
}

#message {
  min-width: 0;
  overflow: hidden;
  font-size: 11px;
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.counter {
  grid-area: counter;
  position: relative;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 6px;
  min-height: 0;
  padding: 10px;
  background:
    linear-gradient(180deg, #f2fbff 0 52%, #d53333 52% 54%, #fbf1d0 54% 100%);
}

.counter::after {
  content: "";
  position: absolute;
  inset: auto 0 0;
  height: 34%;
  background:
    linear-gradient(90deg, transparent 0 18%, rgba(255, 255, 255, .65) 18% 20%, transparent 20% 80%, rgba(255, 255, 255, .65) 80% 82%, transparent 82%),
    linear-gradient(#454545, #222);
  border-top: 4px solid var(--black);
  z-index: 0;
}

.mascot-wrap {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: end;
  justify-content: center;
  min-height: 0;
  overflow: hidden;
}

.mascot {
  /*
   * 高さ基準で拡縮する。幅は 高さ/1.5 で決まるので max-width で潰れることがなく、
   * コマの切り出し（object-fit: cover）がずれない。63vw = 42vw * 1.5。
   */
  height: 100%;
  width: auto;
  max-height: min(26svh, 220px, 63vw);
  /* スプライトは1774x887の3コマ並び。1コマ = 1/1.5 なので隣のコマが見切れない */
  aspect-ratio: 1 / 1.5;
  object-fit: cover;
  object-position: left center;
  filter: drop-shadow(0 10px 12px rgba(0, 0, 0, .2));
}

.mascot-neutral {
  object-position: left center;
}

.mascot-happy {
  object-position: center center;
}

.mascot-miss {
  object-position: right center;
}

.item-card {
  position: relative;
  z-index: 1;
  align-self: end;
  display: grid;
  grid-template-rows: auto auto auto auto;
  gap: 5px;
  min-height: 0;
  padding: 9px 10px;
  border: 4px solid var(--black);
  border-radius: 14px 14px var(--radius) var(--radius);
  background: #fff;
  text-align: center;
  box-shadow: 0 10px 0 #c92525;
}

.item-card.correct {
  animation: pop .28s ease;
}

.item-card.wrong {
  animation: shake .25s linear;
}

.lane-label {
  justify-self: center;
  padding: 4px 10px;
  border: 2px solid var(--black);
  border-radius: 999px;
  background: var(--yellow);
  font-size: 11px;
  font-weight: 900;
}

.item-icon {
  justify-self: center;
  width: min(36vw, 140px, 17svh);
  aspect-ratio: 1;
  background-image: url("assets/item-sprites.png");
  background-size: 400% 300%;
  background-position: 0 0;
  background-repeat: no-repeat;
  filter: drop-shadow(0 8px 10px rgba(0, 0, 0, .2));
}

.item-card h2 {
  margin: 0;
  font-size: clamp(21px, 6.6vw, 32px);
  line-height: 1.05;
}

.item-card p {
  min-height: 2.7em;
  margin: 0;
  color: #4a4a4a;
  font-size: clamp(12px, 3.4vw, 14px);
  font-weight: 800;
  line-height: 1.35;
}

.actions {
  grid-area: actions;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 8px 12px calc(10px + env(safe-area-inset-bottom));
  border-top: 4px solid var(--black);
  background: #fff;
}

.action {
  min-height: clamp(48px, 8.4svh, 70px);
  display: grid;
  grid-template-columns: 22px 40px 1fr;
  align-items: center;
  gap: 6px;
  padding: 4px 6px;
  border: 3px solid var(--black);
  border-radius: var(--radius);
  color: var(--black);
  box-shadow: 0 5px 0 var(--black);
  cursor: pointer;
  touch-action: manipulation;
}

.action:active {
  transform: translateY(4px);
  box-shadow: 0 1px 0 var(--black);
}

.action:focus-visible,
.primary:focus-visible,
.secondary:focus-visible {
  outline: 4px solid #111;
  outline-offset: 3px;
}

.action .num,
.action .icon {
  display: grid;
  place-items: center;
  border: 2px solid currentColor;
  border-radius: 6px;
  background: rgba(255, 255, 255, .7);
  font-weight: 950;
}

.action .num {
  width: 22px;
  height: 22px;
  font-size: 12px;
}

.action .icon {
  min-height: clamp(30px, 5svh, 40px);
  font-size: 12px;
}

.action strong {
  min-width: 0;
  font-size: clamp(13px, 3.8vw, 17px);
  line-height: 1.1;
  text-align: left;
}

.heat {
  background: #ffb536;
}

.bag {
  background: #30c471;
}

.age {
  background: #ff6262;
}

.point {
  background: #5ba8ff;
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: none;
  place-items: center;
  padding: 12px;
  background: rgba(17, 17, 17, .42);
  backdrop-filter: blur(3px);
}

.overlay.visible {
  display: grid;
}

.panel {
  width: min(100%, 340px);
  max-height: 100%;
  overflow: auto;
  padding: 18px;
  border: 4px solid var(--black);
  border-radius: 12px;
  background: #fffdf6;
  text-align: center;
  box-shadow: 0 12px 0 var(--black);
}

.panel h2 {
  margin: 0 0 8px;
  font-size: clamp(24px, 7.5vw, 38px);
  line-height: 1;
}

.panel p {
  margin: 0 0 14px;
  font-size: clamp(13px, 3.6vw, 15px);
  font-weight: 800;
  line-height: 1.5;
}

.primary,
.secondary {
  min-height: clamp(44px, 7svh, 52px);
  border: 3px solid var(--black);
  border-radius: var(--radius);
  font-weight: 950;
  cursor: pointer;
  box-shadow: 0 5px 0 var(--black);
}

.primary {
  width: 100%;
  background: var(--yellow);
}

.secondary {
  background: #fff;
}

.result-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.rank {
  display: inline-block;
  margin-bottom: 8px;
  padding: 5px 10px;
  border: 2px solid var(--black);
  border-radius: 999px;
  background: #ff6262;
  color: #fff;
  font-weight: 950;
}

textarea {
  width: 100%;
  min-height: 84px;
  margin-top: 10px;
  padding: 8px;
  border: 3px solid var(--black);
  border-radius: var(--radius);
  resize: none;
  font-size: 12px;
  line-height: 1.45;
  font-weight: 800;
}

@keyframes pop {
  50% {
    transform: scale(1.04) rotate(-1deg);
  }
}

@keyframes shake {
  20% {
    transform: translateX(-8px);
  }
  40% {
    transform: translateX(7px);
  }
  60% {
    transform: translateX(-5px);
  }
  80% {
    transform: translateX(4px);
  }
}

/* 狭い端末 */
@media (max-width: 374px) {
  .game-card {
    border-width: 3px;
  }

  .hud {
    grid-template-columns: 66px 1fr 74px;
    padding-left: 8px;
    padding-right: 8px;
  }

  .actions {
    gap: 6px;
    padding-left: 8px;
    padding-right: 8px;
  }

  .action {
    grid-template-columns: 20px 34px 1fr;
  }
}

/* 縦に低い画面: さらに詰めて1画面に収める */
@media (max-height: 640px) {
  .phone-shell {
    padding: 4px;
    padding-top: calc(44px + env(safe-area-inset-top));
  }

  .game-card {
    border-radius: 14px;
  }

  .counter {
    padding: 8px;
  }

  .item-card p {
    min-height: 2.5em;
  }

  .actions {
    gap: 6px;
    padding-top: 6px;
  }
}

/* 横向き: 商品エリアとボタンを左右に分けて1画面に収める */
@media (orientation: landscape) and (max-height: 620px) {
  /*
   * 横向きは高さが足りないので、バーのぶんを上に空けるのではなく
   * HUD の左側を空けて、TIME メーターの隣にバーを置く。
   */
  .phone-shell {
    padding-top: 6px;
  }

  .hud {
    padding-left: 128px;
    /* バーとTIMEメーターがまとめて黒帯に載るよう、切り替え位置を実寸で決める */
    background: linear-gradient(90deg, var(--black) 0 220px, var(--yellow) 220px 100%);
  }

  .game-card {
    width: min(100%, 940px);
    max-height: none;
    grid-template-columns: minmax(0, 1.05fr) minmax(0, .95fr);
    grid-template-rows: auto auto minmax(0, 1fr);
    grid-template-areas:
      "hud hud"
      "combo combo"
      "counter actions";
  }

  .counter {
    grid-template-rows: minmax(0, 1fr);
    grid-template-columns: clamp(72px, 13vw, 118px) minmax(0, 1fr);
    align-items: end;
    gap: 8px;
  }

  .mascot {
    /* 横向きは列幅が基準。高さは 幅 x 1.5 で決まる */
    width: 100%;
    height: auto;
    max-height: 100%;
  }

  /* 横向きは商品カードで列を埋めて、余白が間延びしないようにする */
  .item-card {
    align-self: stretch;
    align-content: center;
    gap: 6px;
  }

  .item-card p {
    min-height: 0;
  }

  .item-icon {
    width: min(22vw, 150px, 25svh);
  }

  .item-card h2 {
    font-size: clamp(19px, 3.4vw, 28px);
  }

  .actions {
    grid-template-columns: 1fr;
    align-content: center;
    border-top: none;
    border-left: 4px solid var(--black);
  }

  .action {
    min-height: clamp(42px, 13svh, 64px);
  }
}

/* 大画面（タブレット/PC）: 高さに余裕があるときだけ大きく */
@media (min-width: 760px) and (min-height: 820px) {
  .phone-shell {
    padding: 20px;
    padding-top: calc(52px + env(safe-area-inset-top));
  }

  .game-card {
    max-height: 860px;
  }
}
