/* ==========================================================
   スライム無限合体工場 - style.css
   ========================================================== */

:root {
  --color-bg-top: #eafff3;
  --color-bg-bottom: #cdf3de;
  --color-box: #ffffff;
  --color-box-border: #7bd9a5;
  --color-primary: #22a35f;
  --color-primary-2: #7be8a8;
  --color-text: #234a35;
  --color-text-muted: #6a9a7d;
  --color-border: #bdeccd;
  --header-h: 56px;
  --ad-h: 64px;
}

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

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overscroll-behavior: none;
}

body {
  font-family: "Hiragino Maru Gothic ProN", "Hiragino Kaku Gothic ProN", "Yu Gothic", "Segoe UI", Roboto, Arial, sans-serif;
  background: linear-gradient(180deg, var(--color-bg-top), var(--color-bg-bottom));
  color: var(--color-text);
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  user-select: none;
}

/* ---------- ヘッダー ---------- */
.game-header {
  height: var(--header-h);
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 0.8rem;
  background: rgba(255, 255, 255, 0.6);
  border-bottom: 2px solid var(--color-border);
  z-index: 20;
}

.back-link {
  color: var(--color-text);
  text-decoration: none;
  font-size: 1.3rem;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.7);
  flex: 0 0 auto;
}

.back-link:active {
  background: rgba(255, 255, 255, 0.95);
}

.game-title {
  font-size: 0.95rem;
  font-weight: 800;
  letter-spacing: 0.01em;
  margin: 0;
  color: var(--color-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex: 0 0 auto;
}

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.7);
  color: var(--color-text);
  font-size: 1.15rem;
  font-weight: bold;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-btn:active {
  background: rgba(255, 255, 255, 0.95);
}

.icon-btn.is-muted {
  color: var(--color-text-muted);
}

/* ---------- 盤面ステージ ---------- */
.board-stage {
  position: relative;
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0.5rem 0.7rem 0.4rem;
  z-index: 10;
  min-height: 0;
}

.stat-row {
  flex: 0 0 auto;
  display: flex;
  gap: 0.5rem;
  width: 100%;
  max-width: 420px;
  justify-content: center;
  margin-bottom: 0.45rem;
}

.stat-box {
  background: rgba(255, 255, 255, 0.8);
  border: 2px solid var(--color-border);
  border-radius: 999px;
  padding: 0.3rem 0.9rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  min-width: 0;
  flex: 1 1 auto;
  justify-content: center;
}

.stat-box__label {
  font-size: 0.66rem;
  font-weight: bold;
  color: var(--color-text-muted);
  white-space: nowrap;
}

.stat-box__value {
  font-size: 1rem;
  font-weight: 900;
  color: var(--color-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stat-box--rate .stat-box__value {
  color: #d98c2f;
}

/* ---------- 盤面グリッド ---------- */
.board-wrap {
  position: relative;
  width: min(92vw, 420px);
  height: min(50vh, 460px);
  max-height: 46vh;
  margin: 0 auto;
}

.board-grid {
  position: relative;
  width: 100%;
  height: 100%;
  aspect-ratio: 4 / 5;
  margin: 0 auto;
  max-height: 100%;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(5, 1fr);
  gap: 5px;
  padding: 7px;
  border-radius: 18px;
  border: 3px solid var(--color-box-border);
  background-color: #dff7e8;
  background-image: url("assets/grid-bg.png");
  background-size: cover;
  background-position: center;
  box-shadow: 0 10px 26px rgba(34, 163, 95, 0.25);
  touch-action: none;
}

.cell {
  position: relative;
  border-radius: 11px;
  background: rgba(255, 255, 255, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 0;
}

.cell.is-selected {
  box-shadow: 0 0 0 3px #ffd23d, 0 0 14px 3px rgba(255, 210, 61, 0.8);
  animation: cell-pulse 0.8s ease-in-out infinite;
}

@keyframes cell-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

.slime {
  position: relative;
  width: 86%;
  height: 86%;
  cursor: grab;
  touch-action: none;
}

.slime__img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
  -webkit-user-drag: none;
  filter: drop-shadow(0 4px 6px rgba(34, 163, 95, 0.35));
  transition: transform 0.15s ease;
}

.slime.is-dragging .slime__img {
  opacity: 0;
}

.slime.is-radiant .slime__img {
  filter: drop-shadow(0 4px 6px rgba(34, 163, 95, 0.35)) drop-shadow(0 0 8px rgba(255, 210, 61, 0.9));
}

.slime__badge {
  position: absolute;
  right: -4%;
  bottom: -4%;
  min-width: 1.3em;
  padding: 0.05em 0.32em;
  border-radius: 999px;
  background: var(--color-primary);
  color: #fff;
  font-size: 0.66rem;
  font-weight: 900;
  text-align: center;
  line-height: 1.4;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  pointer-events: none;
}

@keyframes slime-pop {
  0% { transform: scale(0.3); }
  60% { transform: scale(1.15); }
  100% { transform: scale(1); }
}

.slime.is-spawned .slime__img {
  animation: slime-pop 0.28s ease;
}

.drag-ghost {
  position: fixed;
  pointer-events: none;
  z-index: 999;
  transform: translate(-50%, -50%);
  filter: drop-shadow(0 8px 14px rgba(34, 163, 95, 0.45)) drop-shadow(0 0 10px rgba(255, 255, 255, 0.6));
}

.drag-ghost img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* ---------- 合体エフェクト ---------- */
.merge-burst {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  font-size: 1.6rem;
  animation: merge-burst-anim 0.5s ease-out forwards;
}

@keyframes merge-burst-anim {
  0% { opacity: 1; transform: scale(0.5) rotate(0deg); }
  100% { opacity: 0; transform: scale(1.8) rotate(20deg); }
}

/* ---------- 生成ボタン ---------- */
.spawn-btn {
  flex: 0 0 auto;
  margin-top: 0.5rem;
  border: none;
  border-radius: 999px;
  padding: 0.6rem 1.6rem;
  background: linear-gradient(135deg, var(--color-primary), var(--color-primary-2));
  color: #fff;
  font-size: 0.95rem;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 8px 18px rgba(34, 163, 95, 0.4);
  display: flex;
  align-items: center;
  gap: 0.4rem;
  transition: transform 0.08s ease;
}

.spawn-btn:active {
  transform: scale(0.95);
}

/* ---------- トースト（満杯・記録達成） ---------- */
.toast-layer {
  position: absolute;
  top: 0.2rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 15;
  width: 100%;
  display: flex;
  justify-content: center;
  pointer-events: none;
}

.toast {
  background: rgba(34, 163, 95, 0.92);
  color: #fff;
  font-size: 0.78rem;
  font-weight: 800;
  padding: 0.4rem 0.9rem;
  border-radius: 999px;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.25);
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity 0.25s ease, transform 0.25s ease;
  white-space: nowrap;
  max-width: 90vw;
  overflow: hidden;
  text-overflow: ellipsis;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.toast.is-record {
  background: rgba(255, 165, 30, 0.95);
}

/* ---------- ショップパネル ---------- */
.shop-panel {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: rgba(255, 255, 255, 0.55);
  border-top: 2px solid var(--color-border);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.shop-panel__title {
  flex: 0 0 auto;
  margin: 0;
  padding: 0.55rem 0.9rem 0.25rem;
  font-size: 0.83rem;
  font-weight: 800;
  color: var(--color-text);
}

.shop-list {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.2rem 0.7rem 0.6rem;
}

.shop-item {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  background: var(--color-box);
  border: 2px solid var(--color-box-border);
  border-radius: 16px;
  padding: 0.5rem 0.7rem;
}

.shop-item__icon {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: rgba(34, 163, 95, 0.1);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
}

.shop-item__info {
  flex: 1 1 auto;
  min-width: 0;
}

.shop-item__name {
  font-size: 0.84rem;
  font-weight: 800;
  color: var(--color-text);
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.shop-item__level {
  font-size: 0.66rem;
  font-weight: 800;
  color: #fff;
  background: var(--color-primary-2);
  border-radius: 999px;
  padding: 0.05rem 0.5rem;
}

.shop-item__desc {
  font-size: 0.68rem;
  color: var(--color-text-muted);
  margin: 0.15rem 0 0;
  line-height: 1.4;
}

.shop-item__effect {
  font-size: 0.66rem;
  color: var(--color-primary);
  font-weight: bold;
  margin: 0.1rem 0 0;
}

.shop-item__buy {
  flex: 0 0 auto;
  border: none;
  border-radius: 12px;
  padding: 0.5rem 0.6rem;
  min-width: 78px;
  background: linear-gradient(135deg, var(--color-primary), var(--color-primary-2));
  color: #fff;
  font-weight: 900;
  font-size: 0.76rem;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.3;
}

.shop-item__buy:active {
  filter: brightness(0.92);
}

.shop-item__buy:disabled {
  background: #d5e6da;
  color: #8fa89a;
  cursor: not-allowed;
}

.shop-item__buy-label {
  font-size: 0.6rem;
  opacity: 0.9;
}

/* ---------- オーバーレイ ---------- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(35, 74, 53, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 30;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  padding: 1rem;
}

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

.overlay__box {
  text-align: center;
  padding: 1.8rem 2rem;
  background: var(--color-box);
  border: 3px solid var(--color-box-border);
  border-radius: 22px;
  max-width: 85%;
  box-shadow: 0 20px 50px rgba(35, 74, 53, 0.35);
}

.overlay__box--wide {
  max-width: min(92%, 460px);
  max-height: 88%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.guide-section {
  text-align: left;
  margin: 1rem 0;
}

.guide-section__title {
  font-size: 0.92rem;
  color: var(--color-primary);
  margin: 0 0 0.4rem;
}

.guide-section__text {
  font-size: 0.82rem;
  color: var(--color-text-muted);
  margin: 0;
  line-height: 1.6;
}

.guide-section__list {
  margin: 0;
  padding-left: 1.1rem;
  font-size: 0.8rem;
  color: var(--color-text-muted);
  line-height: 1.7;
}

.guide-section__list li {
  margin-bottom: 0.3rem;
}

.overlay__title {
  font-size: 1.4rem;
  font-weight: 900;
  margin: 0 0 0.5rem;
  color: var(--color-primary);
}

.overlay__desc {
  color: var(--color-text-muted);
  margin: 0 0 1.3rem;
  font-size: 0.9rem;
  font-weight: bold;
}

.overlay__btn {
  border: none;
  background: linear-gradient(135deg, var(--color-primary), var(--color-primary-2));
  color: #fff;
  font-weight: bold;
  font-size: 0.95rem;
  padding: 0.8rem 1.8rem;
  border-radius: 999px;
  cursor: pointer;
}

.overlay__btn:active {
  filter: brightness(0.92);
}

.overlay__btn-row {
  display: flex;
  gap: 0.6rem;
  justify-content: center;
}

.overlay__btn--ghost {
  background: rgba(34, 163, 95, 0.12);
  color: var(--color-primary);
}

/* ---------- 広告スペース ---------- */
.ad-slot {
  flex: 0 0 var(--ad-h);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0.3rem 0.7rem 0.7rem;
  border: 2px dashed var(--color-border);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.6);
  color: var(--color-text-muted);
  font-size: 0.72rem;
  overflow: hidden;
}

@media (max-height: 640px) {
  .board-wrap {
    height: min(40vh, 400px);
  }
  .spawn-btn {
    padding: 0.5rem 1.3rem;
    font-size: 0.85rem;
  }
}
