* {
  box-sizing: border-box;
}

/* display:flex 等を持つクラスと hidden 属性を併用している要素があるため、
   hidden が常に確実に効くようにしておく(author CSSがUAのdisplay:noneより優先されてしまうのを防ぐ)。
   これは暫定対応ではなく、このサイトでの正式な表示/非表示の切り替え方法。
   新しく要素を出し分けする時もdisplayを個別に上書きせず、hidden属性の付け外しで統一すること。 */
[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh; /* svh未対応ブラウザ向けのフォールバック */
  min-height: 100svh; /* ソフトキーボード表示時に画面が動的に伸縮して中央寄せがガタつくのを防ぐ(dvhだと毎回再計算されて画面がズレる) */
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 16px 16px 28px;
  background: #fffbea;
  font-family: "Poppins", "Hiragino Maru Gothic ProN", "Hiragino Sans", "Yu Gothic", sans-serif;
  color: #4a3f35;
}

h1 {
  margin: 4px 0 0;
  font-size: 22px;
}

/* ネイティブ画像は 1324 x 1904 (Figmaから4倍解像度で書き出し)。
   表示サイズは JS でビューポート幅に合わせて縮小する(スマホ対応)。
   絵の上部には機体が始まるまでの余白があるため、その分だけ高さを詰めて
   タイトルと機体の間が空きすぎないようにしている(トリミング量はgame.jsのSTAGE_TRIM_TOPと合わせる)。 */
.stage-wrap {
  width: min(380px, calc(100vw - 32px));
  aspect-ratio: 1324 / 1724;
  position: relative;
  overflow: hidden;
}

.stage {
  width: 1324px;
  height: 1904px;
  position: relative;
  transform-origin: top left;
  user-select: none;
}

.layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 1324px;
  height: 1904px;
  pointer-events: none;
}

/* 重ね順は z-index ではなく game.html に書いたタグの並び順そのまま:
   back(body) -> toys -> claw -> hole(bin) -> heldToy -> front(frame) -> trayToys(取り出し口は最前面) */
.toys-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

/* 各画像は白背景部分を実際に透明化(アルファ)処理済みなので、
   mix-blend-modeは使わず普通に重ねるだけでよい */

.toy {
  position: absolute;
  height: 290px;
  width: auto;
  transform: translate(-50%, -50%);
  transition: opacity 0.25s ease, top 0.25s ease-in, left 0.25s ease-in;
  pointer-events: none;
}

/* 爪(clow.png)は1枚の絵をそのまま上下左右にスライドさせる。
   窓の外にはみ出た部分は claw-viewport の overflow:hidden で隠す。 */
.claw-viewport {
  position: absolute;
  left: 126px;
  top: 380px;
  width: 1099px;
  height: 819px;
  overflow: hidden;
  pointer-events: none;
}

.claw-img {
  position: absolute;
  left: -126px;
  top: -380px;
  width: 1324px;
  height: 1904px;
  pointer-events: none;
}

.held-toy {
  position: absolute;
  height: 290px;
  width: auto;
  transform: translate(-50%, -50%);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.held-toy.visible {
  opacity: 1;
}

.tray-toys {
  position: absolute;
  left: 608px;
  top: 1513px;
  width: 646px;
  height: 297px;
  display: flex;
  flex-wrap: wrap;
  align-content: center;
  justify-content: center;
  gap: 4px;
  overflow: visible;
  pointer-events: none;
}

.tray-toys > img {
  height: 290px;
  width: auto;
  pointer-events: none;
}

.hotspot {
  position: absolute;
  top: 1264px;
  height: 160px;
  background: transparent;
  border: none;
  padding: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.hotspot:active:not(:disabled) {
  background: rgba(0, 0, 0, 0.1);
  border-radius: 50%;
}

.start-btn {
  left: 264px;
  width: 360px;
  border-radius: 50%;
}

.stop-btn {
  left: 672px;
  width: 352px;
  border-radius: 50%;
}

.hint {
  max-width: 420px;
  text-align: center;
  font-size: 14px;
  color: #55606b;
  margin: 0;
}

/* ガチャ風メッセージのポップアップ */
.message-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 100;
}

.message-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

.message-card {
  background: #fffdf6;
  border-radius: 20px;
  padding: 28px 24px 24px;
  max-width: 320px;
  width: 100%;
  text-align: center;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  transform: scale(0.9);
  transition: transform 0.2s ease;
}

.message-overlay.visible .message-card {
  transform: scale(1);
}

.message-card img {
  height: 110px;
  width: auto;
  margin: 0 auto 20px;
  display: block;
}

.message-card .you-got-it-label {
  margin: 0 0 10px;
  color: #f5a623;
  font-size: 16px;
  font-weight: 900;
  letter-spacing: 0.02em;
}

.message-card p {
  font-size: 14px;
  line-height: 1.7;
  color: #4a3f35;
  margin: 0 0 18px;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  word-break: break-word;
}

.message-card button {
  border: none;
  background: #f5a623;
  color: #fff;
  font-size: 14px;
  font-weight: bold;
  padding: 10px 28px;
  border-radius: 999px;
  cursor: pointer;
}

.creator-credit {
  margin: 28px 0 0;
  text-align: center;
  font-size: 12px;
  color: #8a7a63;
}

.creator-credit a {
  color: #8a7a63;
  text-decoration: underline;
}

.edit-card {
  background: #fffdf6;
  border-radius: 20px;
  padding: 28px 24px 24px;
  max-width: 420px;
  width: 100%;
  text-align: left;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.12);
}

.edit-card button {
  border: none;
  background: #f5a623;
  color: #fff;
  font-size: 14px;
  font-weight: bold;
  padding: 10px 28px;
  border-radius: 999px;
  cursor: pointer;
}

.edit-card button.secondary {
  background: #e7e0d4;
  color: #4a3f35;
}

.edit-card h2 {
  margin: 0 0 6px;
  font-size: 18px;
  text-align: center;
}

.edit-hint {
  font-size: 13px;
  color: #8a7a63;
  text-align: center;
  margin: 0 0 16px;
}

.edit-list {
  max-height: 45vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 18px;
  padding-right: 4px;
}

.edit-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.edit-row img {
  height: 44px;
  width: 44px;
  object-fit: contain;
  flex-shrink: 0;
}

.edit-field {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.edit-field textarea {
  width: 100%;
  resize: none;
  font-family: inherit;
  font-size: 13px;
  line-height: 1.4;
  padding: 8px 10px;
  border: 1px solid #e7e0d4;
  border-radius: 10px;
  background: #fffdf6;
  color: #4a3f35;
}

.edit-counter {
  align-self: flex-end;
  font-size: 11px;
  color: #8a7a63;
}

/* 丸い小さなアイコンボタン(トイ削除・トースト閉じるで共有) */
.edit-row .edit-row-remove,
.toast-close {
  width: 26px;
  height: 26px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: #f1ece2;
  color: #8a7a63;
  font-size: 12px;
  font-weight: normal;
  line-height: 1;
  cursor: pointer;
}

.edit-row .edit-row-remove:hover:not(:disabled),
.toast-close:hover {
  background: #f3d9d9;
  color: #b3413d;
}

.edit-row-remove {
  flex-shrink: 0;
}

.edit-row .edit-row-remove:disabled {
  opacity: 0.35;
}

/* --- ゲームから外したトイを後から戻せる小さなチップ一覧 ------------ */
.edit-removed {
  margin: 0 0 18px;
}

.edit-removed-label {
  margin: 0 0 8px;
  font-size: 12px;
  color: #8a7a63;
}

.edit-removed-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.edit-removed-chips .edit-removed-chip {
  width: 40px;
  height: 40px;
  padding: 4px;
  border: 1px dashed #e7e0d4;
  border-radius: 12px;
  background: #fffdf6;
  cursor: pointer;
  opacity: 0.6;
  transition: opacity 0.15s ease, border-style 0.15s ease;
}

.edit-removed-chips .edit-removed-chip:hover {
  opacity: 1;
  border-style: solid;
  border-color: #f5a623;
}

.edit-removed-chip img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.edit-actions {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
}

.edit-actions button {
  font-size: 13px;
  padding: 10px 18px;
}

/* --- リンクをコピーした時のトースト通知 ------------------------- */
.toast-backdrop {
  position: fixed;
  inset: 0;
  z-index: 99;
}

.copy-toast {
  position: fixed;
  top: 50%;
  left: 50%;
  z-index: 100;
  width: min(300px, calc(100vw - 48px));
  background: #fffdf6;
  border-radius: 20px;
  padding: 28px 24px;
  text-align: center;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
  animation: toastIn 200ms ease-out both;
}

.toast-close {
  position: absolute;
  top: 10px;
  right: 10px;
}

.toast-title {
  margin: 0 0 6px;
  font-size: 16px;
  font-weight: bold;
  color: #f5a623;
}

.toast-sub {
  margin: 0;
  font-size: 13px;
  color: #8a7a63;
}

.coffee-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin-top: 16px;
}

.coffee-link {
  display: inline-block;
  padding: 10px 24px;
  border-radius: 999px;
  border: none;
  background: #f5a623;
  color: #fff;
  font-size: 14px;
  font-weight: bold;
  text-decoration: none;
}

.coffee-link:hover {
  background: #e2941a;
}

.coffee-subtext {
  margin: 0;
  font-size: 11px;
  color: #8a7a63;
  letter-spacing: 0.02em;
}

@keyframes toastIn {
  from { opacity: 0; transform: translate(-50%, calc(-50% + 12px)); }
  to   { opacity: 1; transform: translate(-50%, -50%); }
}

/* --- ランディング画面(サイト説明 → 作成へのCTA) ------------------- */
.landing-card {
  max-width: 420px;
  width: 100%;
  text-align: center;
  background: #fffdf6;
  border-radius: 20px;
  padding: 32px 28px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.12);
}

.eyebrow {
  margin: 0 0 18px;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: bold;
  color: #f5a623;
}

.landing-title {
  margin: 0 0 14px;
  font-size: 19px;
  line-height: 1.3;
}

.landing-lede {
  margin: 0 0 28px;
  font-size: 14px;
  line-height: 1.7;
  color: #55606b;
}

/* game.htmlの実機(.stage-wrap/.stage)をそのまま縮小しただけの、遊べない
   静止プレビュー。構造・トリミングを完全に共有しているので見た目がズレない。
   スケール計算とトイの配置はedit.jsのupdateLandingStageScale/renderLandingToysが行う。 */
.landing-demo {
  margin: 0 auto 28px;
}

.landing-stage-wrap {
  width: min(160px, 45%);
  margin: 0 auto;
  pointer-events: none;
}

.landing-steps {
  display: grid;
  gap: 14px;
  margin: 0 0 32px;
  padding: 0;
  list-style: none;
  text-align: left;
  counter-reset: step;
}

.landing-steps li {
  counter-increment: step;
  position: relative;
  padding-left: 32px;
  font-size: 13px;
  line-height: 1.5;
  color: #4a3f35;
}

.landing-steps li::before {
  content: counter(step);
  position: absolute;
  left: 0;
  top: -1px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #f5a623;
  color: #fff;
  font-weight: bold;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.button-row {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 0;
}

.primary {
  border: none;
  background: #f5a623;
  color: #fff;
  font-weight: bold;
  font-size: 14px;
  padding: 12px 26px;
  border-radius: 999px;
  cursor: pointer;
}

/* --- game.html 上部の「戻る / リンクコピー」ツールバー ------------ */
.game-toolbar {
  display: flex;
  gap: 16px;
  align-items: center;
  justify-content: center;
}

/* --- タイトル入力欄(ユーザーが自分のクレーンゲームの名前を設定できる) --- */
.field-label {
  display: block;
  margin: 0 0 6px;
  font-size: 12px;
  font-weight: bold;
  color: #8a7a63;
}

.title-input {
  width: 100%;
  font-family: inherit;
  font-size: 14px;
  padding: 10px 12px;
  border: 1px solid #e7e0d4;
  border-radius: 10px;
  background: #fffdf6;
  color: #4a3f35;
  margin-bottom: 16px;
}

/* --- クレーンゲームの中身が空になった時の「再挑戦 / 新規作成」導線 --- */
.restock-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 10px;
}

.restock-btn {
  border: none;
  background: #f5a623;
  color: #fff;
  font-weight: bold;
  font-size: 13px;
  padding: 10px 22px;
  border-radius: 999px;
  cursor: pointer;
}

.cta-link {
  display: inline-block;
  padding: 10px 22px;
  border-radius: 999px;
  border: 1px solid #e7e0d4;
  background: #fffdf6;
  color: #4a3f35;
  font-size: 13px;
  font-weight: bold;
  text-decoration: none;
}

/* --- パソコンなど広い画面向けのサイズ調整 -------------------------- */
@media (min-width: 700px) {
  body {
    padding: 40px 16px 56px;
    gap: 18px;
  }

  h1 {
    font-size: 28px;
  }

  .stage-wrap {
    width: min(440px, calc(100vw - 64px));
  }

  .hint {
    font-size: 16px;
  }

  .landing-card,
  .edit-card {
    max-width: 560px;
    padding: 44px 56px;
  }

  .landing-stage-wrap {
    width: min(220px, 45%);
  }

  .landing-title {
    font-size: 24px;
  }

  .landing-lede {
    font-size: 15px;
  }

  .landing-steps li {
    font-size: 14px;
  }
}
