/* 爆弾脱出 — 木の倉庫×時限爆弾 */

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

:root {
  --wood-dark: #4a2f16;
  --wood-frame1: #8a5a2b;
  --wood-frame2: #6f4118;
  --wood-board1: #edd29b;
  --wood-board2: #e2bf7f;
  --block1: #f7e3b6;
  --block2: #eccf92;
  --ink: #3b2a17;
  --coral: #e8503a;
  --led: #7dff9a;
  --led-danger: #ff5b45;
  --gap: 4px;
}

html, body { height: 100%; }
body {
  font-family: "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Yu Gothic", system-ui, sans-serif;
  background:
    radial-gradient(120% 90% at 50% 0%, #6b4423 0%, #4a2f16 55%, #33200e 100%);
  color: #f4e8d2;
  display: flex;
  justify-content: center;
  overscroll-behavior: none;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

#app {
  width: min(100vw, 480px);
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: max(8px, env(safe-area-inset-top)) 12px max(10px, env(safe-area-inset-bottom));
}

/* ---------- HUD ---------- */
.hud {
  display: flex; align-items: center; justify-content: space-between;
  padding: 4px 2px 6px;
}
.hud-cell { display: flex; align-items: center; gap: 5px; font-size: 12px; opacity: .95; min-width: 92px; }
.hud-right { justify-content: flex-end; }
.hud-label { opacity: .65; }
.hud-cell b { font-size: 16px; color: #ffd98a; }
.hud-sep { width: 1px; height: 14px; background: rgba(255,255,255,.25); margin: 0 3px; }
.title {
  font-size: 21px; letter-spacing: .12em; font-weight: 800;
  text-shadow: 0 2px 0 rgba(0,0,0,.4);
}
.title-bomb { font-size: 16px; margin: 0 1px; }
.icon-btn {
  font-size: 17px; background: rgba(0,0,0,.25); border: 1px solid rgba(255,255,255,.18);
  border-radius: 10px; padding: 4px 9px; cursor: pointer; color: inherit;
}

/* ---------- タイマー ---------- */
.statusbar { margin: 2px 0 8px; }
.timebar {
  height: 10px; border-radius: 6px; overflow: hidden;
  background: rgba(0,0,0,.4);
  box-shadow: inset 0 1px 3px rgba(0,0,0,.6);
}
#timefill {
  height: 100%; width: 100%;
  background: linear-gradient(90deg, #7ddf87, #b9e06a);
  border-radius: 6px;
  transition: width .25s linear, background-color .4s;
}
.warn #timefill { background: linear-gradient(90deg, #f0b34c, #f4d35e); }
.danger #timefill { background: linear-gradient(90deg, #f0503a, #ff8a5c); }
.stats {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 12.5px; margin-top: 5px; opacity: .95;
}
.timer {
  font-variant-numeric: tabular-nums;
  font-weight: 800; font-size: 17px; letter-spacing: .06em; color: #cfe8b7;
}
.warn .timer { color: #ffd98a; }
.danger .timer { color: var(--led-danger); animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: .35; } }
.stats-moves b { color: #ffd98a; }

/* ---------- 盤 ---------- */
.board-wrap {
  flex: 1; min-height: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
#board {
  position: relative;
  border-radius: 18px;
  padding: 10px;
  background:
    repeating-linear-gradient(93deg, rgba(0,0,0,.045) 0 2px, transparent 2px 26px),
    linear-gradient(180deg, var(--wood-board1), var(--wood-board2));
  box-shadow:
    0 0 0 10px var(--wood-frame1),
    0 0 0 11px rgba(0,0,0,.35),
    0 14px 30px rgba(0,0,0,.5),
    inset 0 3px 10px rgba(80,45,10,.45);
  touch-action: none;
}
#board.shake { animation: shake .5s; }
@keyframes shake {
  0%,100% { transform: translate(0,0); }
  15% { transform: translate(-7px,3px) rotate(-.7deg); }
  30% { transform: translate(6px,-4px) rotate(.6deg); }
  45% { transform: translate(-5px,-3px); }
  60% { transform: translate(4px,3px) rotate(.4deg); }
  75% { transform: translate(-3px,1px); }
}
.danger #board { animation: dangerpulse 1s ease-in-out infinite; }
@keyframes dangerpulse {
  0%,100% { box-shadow: 0 0 0 10px var(--wood-frame1), 0 0 0 11px rgba(0,0,0,.35), 0 14px 30px rgba(0,0,0,.5), inset 0 3px 10px rgba(80,45,10,.45); }
  50% { box-shadow: 0 0 0 10px #a04a2a, 0 0 0 11px rgba(0,0,0,.35), 0 14px 40px rgba(200,50,20,.55), inset 0 3px 10px rgba(80,45,10,.45); }
}

#fx {
  position: absolute; inset: 0; width: 100%; height: 100%;
  pointer-events: none; z-index: 40;
}

/* ---------- ブロック ---------- */
.piece {
  position: absolute;
  border-radius: 10px;
  cursor: grab;
  background: linear-gradient(180deg, var(--block1), var(--block2));
  box-shadow:
    inset 0 2px 0 rgba(255,255,255,.55),
    inset 2px 0 0 rgba(255,255,255,.25),
    inset 0 -3px 0 rgba(0,0,0,.18),
    inset -2px 0 0 rgba(0,0,0,.08),
    0 3px 6px rgba(0,0,0,.28);
  z-index: 10;
}
.piece.dragging { cursor: grabbing; z-index: 30; box-shadow:
    inset 0 2px 0 rgba(255,255,255,.55), inset 0 -3px 0 rgba(0,0,0,.18),
    0 10px 18px rgba(0,0,0,.4); }
.piece.snap { transition: left .14s cubic-bezier(.2,.8,.3,1.1), top .14s cubic-bezier(.2,.8,.3,1.1); }
.piece.settled { animation: settle .22s ease-out; }
@keyframes settle {
  0% { transform: scale(1.03, .95); }
  55% { transform: scale(.985, 1.015); }
  100% { transform: scale(1,1); }
}
.piece.hint-flash { animation: hintflash 1.1s ease-in-out; }
@keyframes hintflash {
  0%,100% { filter: none; }
  25%,65% { filter: brightness(1.35) drop-shadow(0 0 10px #ffd98a); }
}

/* 種類ごとの木の色味 */
.piece.c-v { background: linear-gradient(180deg, #e9cfa4, #d9b276); }
.piece.c-w { background: linear-gradient(180deg, #ecd6ac, #dcbb84); }
.piece.c-s { background: linear-gradient(180deg, #f6e6bd, #ead29a); }

/* 木目 */
.piece::after {
  content: ""; position: absolute; inset: 0; border-radius: inherit;
  background: repeating-linear-gradient(88deg, rgba(90,55,20,.06) 0 2px, transparent 2px 14px);
  pointer-events: none;
}

/* ---------- 爆弾（主役） ---------- */
.piece.hero {
  background: radial-gradient(90% 90% at 30% 25%, #565064 0%, #322d3a 45%, #1c1922 100%);
  box-shadow:
    inset 0 2px 0 rgba(255,255,255,.22),
    inset 0 -4px 0 rgba(0,0,0,.5),
    0 4px 10px rgba(0,0,0,.45);
  z-index: 20;
  display: flex; align-items: center; justify-content: center;
}
.piece.hero::after { background: none; }
.hero-inner { position: relative; width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; pointer-events: none; }
.hero-bomb { width: 62%; height: auto; display: block; }
.hero-timer {
  position: absolute; left: 50%; top: 56%; transform: translate(-50%, -50%);
  font-weight: 800; font-size: clamp(14px, 5.2vw, 24px);
  font-variant-numeric: tabular-nums; letter-spacing: .04em;
  color: var(--led); text-shadow: 0 0 8px rgba(125,255,154,.7);
  font-family: "Menlo", "Courier New", monospace;
}
.danger .hero-timer { color: var(--led-danger); text-shadow: 0 0 10px rgba(255,91,69,.8); animation: blink 1s steps(2) infinite; }
.hero .spark {
  position: absolute; top: 6%; left: 66%;
  width: 10px; height: 10px; border-radius: 50%;
  background: radial-gradient(circle, #fff7c0 0%, #ffcf4d 45%, rgba(255,120,40,0) 75%);
  animation: sparkle .32s ease-in-out infinite alternate;
}
@keyframes sparkle {
  from { transform: scale(.7); opacity: .8; }
  to   { transform: scale(1.5); opacity: 1; }
}
.piece.hero.exiting { transition: top .55s cubic-bezier(.5,0,.8,.4), opacity .55s; opacity: .1; }
.piece.hero.blasted { transition: opacity .2s; opacity: 0; }

/* ---------- 岩（障害物） ---------- */
.wall {
  position: absolute; border-radius: 9px; z-index: 5;
  background:
    radial-gradient(60% 50% at 32% 28%, rgba(255,255,255,.28), transparent 60%),
    linear-gradient(180deg, #a7abb3, #7d828c 60%, #676c76);
  box-shadow:
    inset 0 2px 0 rgba(255,255,255,.35),
    inset 0 -3px 0 rgba(0,0,0,.35),
    0 2px 4px rgba(0,0,0,.35);
}
.wall::before {
  content: ""; position: absolute; inset: 18%;
  border-radius: 40% 55% 45% 60%;
  background: linear-gradient(160deg, rgba(255,255,255,.16), rgba(0,0,0,.14));
}

/* ---------- 出口 ---------- */
.board-col { position: relative; margin-bottom: 36px; }
.exit {
  position: absolute;
  top: calc(100% + 13px);
  left: 0;
  text-align: center;
  font-size: 13px; letter-spacing: .3em; font-weight: 700;
  color: #ffd98a;
  background: rgba(0,0,0,.3);
  border: 1px dashed rgba(255,217,138,.6);
  border-radius: 8px;
  padding: 3px 0 4px;
}
.exit-arrow { animation: exitpulse 1.6s ease-in-out infinite; display: inline-block; }
@keyframes exitpulse { 50% { transform: translateY(3px); opacity: .5; } }

/* ---------- ツールバー ---------- */
.toolbar { display: flex; gap: 8px; justify-content: center; margin-top: 12px; }
.btn {
  font-family: inherit; font-size: 13.5px; font-weight: 700;
  color: #3b2a17;
  background: linear-gradient(180deg, #f7e3b6, #e5c584);
  border: none; border-radius: 12px;
  padding: 10px 14px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.6), 0 3px 0 #a97e3f, 0 5px 8px rgba(0,0,0,.3);
  cursor: pointer;
  transition: transform .06s, box-shadow .06s;
}
.btn:active { transform: translateY(3px); box-shadow: inset 0 1px 0 rgba(255,255,255,.6), 0 0 0 #a97e3f, 0 1px 3px rgba(0,0,0,.3); }
.btn.primary {
  color: #fff;
  background: linear-gradient(180deg, #ff7a58, #e8503a);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.4), 0 3px 0 #a02c1c, 0 5px 8px rgba(0,0,0,.3);
}
.btn.primary:active { box-shadow: inset 0 1px 0 rgba(255,255,255,.4), 0 0 0 #a02c1c, 0 1px 3px rgba(0,0,0,.3); }
.btn-row { display: flex; gap: 10px; justify-content: center; }
.subtitle { text-align: center; font-size: 11.5px; opacity: .6; margin-top: 9px; min-height: 1.2em; }

/* ---------- オーバーレイ ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(20, 10, 4, .72);
  backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  animation: fadein .25s ease-out;
}
.overlay[hidden] { display: none; }
@keyframes fadein { from { opacity: 0; } }
.panel {
  width: min(88vw, 360px);
  background: linear-gradient(180deg, #fdf3da, #f3dfae);
  color: var(--ink);
  border-radius: 20px;
  padding: 26px 22px 22px;
  text-align: center;
  box-shadow: 0 0 0 8px var(--wood-frame1), 0 0 0 9px rgba(0,0,0,.4), 0 24px 50px rgba(0,0,0,.6);
  animation: pop .3s cubic-bezier(.2,1.4,.4,1);
}
@keyframes pop { from { transform: scale(.85); opacity: 0; } }
.panel h2 { font-size: 21px; margin-bottom: 10px; letter-spacing: .05em; }
.panel p { font-size: 13.5px; line-height: 1.75; }
.panel .note { font-size: 12px; opacity: .75; margin-top: 4px; }
.panel .btn { margin-top: 16px; min-width: 140px; }
.panel-bomb { font-size: 44px; margin-bottom: 6px; }
.boom-icon { animation: boompop .5s cubic-bezier(.2,1.6,.4,1); }
@keyframes boompop { from { transform: scale(.2) rotate(-30deg); } }
.story b { color: var(--coral); }
.rules {
  list-style: none; text-align: left;
  margin: 14px 4px 2px; font-size: 12.5px; line-height: 2;
}
.win-stars { font-size: 34px; letter-spacing: .12em; color: #f2a01f; text-shadow: 0 2px 0 rgba(0,0,0,.12); margin: 2px 0 8px; }
.share-sub { margin-top: 10px; font-size: 12px; padding: 8px 12px; }
.share-preview {
  font-family: inherit; font-size: 12px; line-height: 1.7;
  text-align: left; white-space: pre-wrap; word-break: break-all;
  background: rgba(120, 80, 30, .12);
  border: 1px dashed rgba(120, 80, 30, .35);
  border-radius: 10px; padding: 10px 12px; margin: 8px 0 2px;
}
.share-grid { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-top: 12px; }
.share-grid .btn { min-width: 72px; }
.win-stars .off { color: #cbb389; }
.boom-panel h2 { color: #c0331e; }

/* ---------- トースト ---------- */
.toast {
  position: fixed; left: 50%; bottom: max(24px, env(safe-area-inset-bottom));
  transform: translate(-50%, 20px);
  background: rgba(25,15,6,.92); color: #ffe9bd;
  font-size: 13px; padding: 10px 16px; border-radius: 12px;
  opacity: 0; pointer-events: none; z-index: 200;
  transition: opacity .25s, transform .25s;
  white-space: nowrap;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- ローディング ---------- */
.loading {
  position: absolute; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; color: #6b4a22; font-weight: 700;
  background: rgba(240, 220, 170, .6);
  border-radius: 10px;
}

@media (prefers-reduced-motion: reduce) {
  .piece.snap, .exit-arrow, .hero .spark, .danger #board { animation: none; transition: none; }
}
