/* ==========================================================
   ぴったり積み込み便 - style.css
   ========================================================== */

:root {
  --color-bg: #16202b;
  --color-panel: #1f2c3a;
  --color-panel-2: #27384a;
  --color-accent: #ffb340;
  --color-accent-2: #4fd6ff;
  --color-good: #4ade80;
  --color-bad: #ff6b6b;
  --color-text: #f2f6fa;
  --color-text-muted: #9db0c4;
  --color-border: #35506b;
  --header-h: 56px;
  --ad-h: 64px;
  --pad-h: 132px;
}

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

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

body {
  font-family: "Segoe UI", "Hiragino Kaku Gothic ProN", "Yu Gothic", Roboto, Arial, sans-serif;
  background: var(--color-bg);
  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;
  gap: 0.4rem;
  padding: 0 0.7rem;
  background: linear-gradient(180deg, #22334a, var(--color-bg));
  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: 10px;
  flex: 0 0 auto;
}
.back-link:hover { background: rgba(255, 255, 255, 0.1); }

.game-title {
  margin: 0;
  font-size: 1.02rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: 1px solid var(--color-border);
  background: var(--color-panel);
  color: var(--color-text);
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:hover { background: var(--color-panel-2); }
.icon-btn.is-muted { opacity: 0.65; }

/* ---------- ステージ ---------- */
.game-stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  background: radial-gradient(circle at 50% 35%, #2c4258 0%, #16202b 70%);
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

/* ---------- HUD ---------- */
.hud {
  position: absolute;
  top: 8px;
  left: 8px;
  display: flex;
  gap: 6px;
  z-index: 6;
  pointer-events: none;
}

.hud-box {
  background: rgba(15, 24, 34, 0.72);
  border: 1px solid var(--color-border);
  border-radius: 9px;
  padding: 4px 9px;
  min-width: 62px;
  text-align: center;
  backdrop-filter: blur(3px);
}

.hud-box__label {
  display: block;
  font-size: 0.6rem;
  color: var(--color-text-muted);
  letter-spacing: 0.04em;
}

.hud-box__value {
  display: block;
  font-size: 1.02rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--color-accent);
}

/* ---------- 荷降ろし場（届いた段ボールの一覧） ---------- */
.pool-bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: var(--pad-h);
  padding: 5px 10px 7px;
  background: linear-gradient(180deg, rgba(22, 32, 43, 0) 0%, rgba(22, 32, 43, 0.9) 45%);
  z-index: 7;
}

.pool-bar__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 3px;
}

.pool-bar__label {
  font-size: 0.62rem;
  letter-spacing: 0.06em;
  color: var(--color-accent-2);
  font-weight: 700;
}

.pool-bar__count {
  font-size: 0.62rem;
  color: var(--color-text-muted);
  font-variant-numeric: tabular-nums;
}
.pool-bar__count.is-danger { color: var(--color-bad); font-weight: 700; }

.pool-bar__list {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 2px;
  scrollbar-width: thin;
}

/* 広い画面ではプールが横に散らばらないよう中央にまとめる */
@media (min-width: 720px) {
  .pool-bar__head,
  .pool-bar__list {
    max-width: 560px;
    margin-left: auto;
    margin-right: auto;
  }
  .pool-bar__list { justify-content: center; }
}

.pool-item {
  flex: 0 0 auto;
  width: 46px;
  height: 42px;
  padding: 0;
  border: 2px solid var(--color-border);
  border-radius: 8px;
  background: rgba(15, 24, 34, 0.85);
  cursor: pointer;
  display: block;
  position: relative;
}
.pool-item canvas { display: block; width: 100%; height: 100%; }
.pool-item.is-selected {
  border-color: var(--color-accent);
  background: rgba(255, 179, 64, 0.18);
}
/* 今のトラックにはもう入らない段ボール */
.pool-item.is-blocked { opacity: 0.34; cursor: default; }
.pool-item.is-blocked::after {
  content: "";
  position: absolute;
  inset: 6px;
  border-top: 2px solid var(--color-bad);
  transform: rotate(-35deg);
  transform-origin: center;
}

/* ---------- 得点トースト ---------- */
.score-toast {
  position: absolute;
  top: 20%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.85);
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--color-accent);
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.7);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 7;
  white-space: nowrap;
  text-align: center;
}
.score-toast.is-visible {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}
.score-toast.is-bad { color: var(--color-bad); }
.score-toast.is-great { color: var(--color-good); }

/* ---------- 操作パネル ---------- */
.control-pad {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: var(--pad-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 12px 10px;
  background: linear-gradient(180deg, rgba(22, 32, 43, 0) 0%, rgba(22, 32, 43, 0.86) 26%, rgba(22, 32, 43, 0.96) 100%);
  z-index: 8;
}

.dpad {
  position: relative;
  width: 116px;
  height: 116px;
  flex: 0 0 auto;
}

.pad-btn {
  background: var(--color-panel);
  border: 1px solid var(--color-border);
  color: var(--color-text);
  border-radius: 11px;
  cursor: pointer;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
}
.pad-btn:active { background: var(--color-accent); color: #16202b; }

/* 荷台を斜めから見ているので、4つの軸は画面上の斜め方向に伸びる。
   矢印もひし形（45度ずらし）に並べて、押した向きと荷物が動く向きを一致させる。 */
.dpad__up, .dpad__down, .dpad__left, .dpad__right {
  position: absolute;
  width: 44px;
  height: 44px;
}
.dpad__up    { top: 0;    right: 0; }
.dpad__right { bottom: 0; right: 0; }
.dpad__down  { bottom: 0; left: 0; }
.dpad__left  { top: 0;    left: 0; }

.action-cluster {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 7px;
  max-width: 260px;
}

.action-row {
  display: flex;
  gap: 7px;
}

.pad-btn--wide {
  flex: 1 1 0;
  height: 50px;
  flex-direction: column;
  gap: 1px;
}

.pad-btn__icon { font-size: 1.05rem; line-height: 1; }
.pad-btn__text { font-size: 0.62rem; color: var(--color-text-muted); }
.pad-btn:active .pad-btn__text { color: #16202b; }

.pad-btn--drop {
  background: linear-gradient(180deg, #ffbe55, #f08f1d);
  border-color: #ffd08a;
  color: #2a1a06;
  font-weight: 700;
}
.pad-btn--drop .pad-btn__text { color: #5a3a08; font-weight: 700; }
.pad-btn--drop:active { filter: brightness(1.15); }

.pad-btn--camera { background: var(--color-panel-2); }

/* ---------- オーバーレイ ---------- */
.overlay {
  position: absolute;
  inset: 0;
  background: rgba(9, 15, 22, 0.86);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 12px;
  z-index: 30;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.overlay.is-visible { display: flex; }

.overlay__box {
  background: linear-gradient(180deg, #253749, #1a2634);
  border: 2px solid var(--color-border);
  border-radius: 16px;
  padding: 18px 16px;
  max-width: 420px;
  width: 100%;
  text-align: center;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
  margin: auto;
}
.overlay__box--wide { max-width: 520px; text-align: left; }

.overlay__title {
  margin: 0 0 12px;
  font-size: 1.16rem;
  font-weight: 700;
  text-align: center;
}

.overlay__result-emoji {
  margin: 0 0 4px;
  font-size: 2.6rem;
  text-align: center;
}

.overlay__score {
  margin: 4px 0 10px;
  font-size: 2.3rem;
  font-weight: 800;
  color: var(--color-accent);
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.overlay__desc {
  margin: 4px 0;
  font-size: 0.85rem;
  color: var(--color-text-muted);
  text-align: center;
}

.guide-section { margin-bottom: 12px; }

.guide-section__title {
  margin: 0 0 5px;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--color-accent);
}

.guide-section__text {
  margin: 0;
  font-size: 0.83rem;
  line-height: 1.65;
  color: #d8e2ec;
}

.guide-section__list {
  margin: 0;
  padding-left: 1.15rem;
  font-size: 0.83rem;
  line-height: 1.6;
  color: #d8e2ec;
}
.guide-section__list li { margin-bottom: 3px; }

/* 屋根があるので上からは入れられない、という決まりごとの注記 */
.guide-note {
  margin: 8px 0 0;
  font-size: 0.72rem;
  line-height: 1.55;
  color: var(--color-text-muted);
}

.overlay__btn {
  display: block;
  width: 100%;
  margin-top: 12px;
  padding: 12px;
  font-size: 0.98rem;
  font-weight: 700;
  color: #2a1a06;
  background: linear-gradient(180deg, #ffc86a, #f0951d);
  border: none;
  border-radius: 11px;
  cursor: pointer;
}
.overlay__btn:hover { filter: brightness(1.08); }

.overlay__btn--secondary {
  background: var(--color-panel-2);
  color: var(--color-text);
  border: 1px solid var(--color-border);
}

/* ---------- 広告 ---------- */
.ad-gap { height: 10px; flex: 0 0 auto; }

.ad-slot {
  flex: 0 0 var(--ad-h);
  display: flex;
  align-items: center;
  justify-content: center;
  background: #101923;
  border-top: 2px dashed var(--color-border);
  overflow: hidden;
  z-index: 20;
}
.ad-slot span { color: #63788d; font-size: 0.75rem; }

/* ---------- 広い画面 ---------- */
@media (min-width: 720px) {
  .game-title { font-size: 1.15rem; }
  .hud-box__value { font-size: 1.14rem; }
  .control-pad { justify-content: center; gap: 32px; }
}

@media (max-height: 620px) {
  :root { --pad-h: 116px; }
  .pad-btn--wide { height: 44px; }
  .dpad { width: 100px; height: 100px; }
  .dpad__up, .dpad__down, .dpad__left, .dpad__right { width: 40px; height: 40px; }
}
