/* =========================================================================
   REZONA JIGSAW — ネオン系スタイル（既存ゲーム群とトーンを合わせる）
   iframe 内・任意アスペクト比で崩れないレスポンシブ設計。
   ========================================================================= */
:root {
  --bg0: #06040f;
  --bg1: #0d0724;
  --cyan: #33ffe7;
  --magenta: #ff2fe5;
  --purple: #8a5cff;
  --text: #eae6ff;
  --muted: #9b93c7;
  --panel: rgba(20, 12, 46, 0.82);
  --line: rgba(138, 92, 255, 0.35);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: radial-gradient(120% 120% at 50% 0%, var(--bg1) 0%, var(--bg0) 70%);
  color: var(--text);
  font-family: "Segoe UI", "Hiragino Kaku Gothic ProN", "Noto Sans JP", sans-serif;
  /* iframe / タッチでの意図しないスクロール・選択・callout を抑止 */
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  overscroll-behavior: none;
}

.screen, .overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
}
[hidden] { display: none !important; }

/* ---------- スタート画面 ---------- */
#start-screen { align-items: center; justify-content: center; padding: 16px; }

.panel {
  width: min(560px, 94vw);
  max-height: 96vh;
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: clamp(18px, 4vw, 34px);
  box-shadow: 0 0 40px rgba(138, 92, 255, 0.25), inset 0 0 30px rgba(51, 255, 231, 0.05);
  backdrop-filter: blur(6px);
}

.title {
  font-size: clamp(30px, 8vw, 52px);
  font-weight: 800;
  letter-spacing: 2px;
  text-align: center;
  color: #fff;
  text-shadow: 0 0 12px var(--cyan), 0 0 26px rgba(51, 255, 231, 0.6);
}
.title span { color: var(--magenta); text-shadow: 0 0 12px var(--magenta), 0 0 26px rgba(255, 47, 229, 0.6); }
.subtitle { text-align: center; color: var(--muted); margin: 8px 0 22px; font-size: clamp(12px, 3vw, 15px); letter-spacing: 1px; }

.field { margin-bottom: 20px; }
.field-label { display: block; font-size: 12px; letter-spacing: 2px; color: var(--muted); margin-bottom: 10px; text-transform: uppercase; }

.image-picker { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 10px; }
.thumb {
  position: relative;
  aspect-ratio: 4 / 3;
  border-radius: 10px;
  overflow: hidden;
  border: 2px solid transparent;
  cursor: pointer;
  background: #000;
  transition: border-color .15s, transform .1s;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .thumb-title {
  position: absolute; left: 0; right: 0; bottom: 0;
  font-size: 10px; padding: 3px 5px; color: #fff;
  background: linear-gradient(transparent, rgba(0,0,0,.8));
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.thumb.is-active { border-color: var(--cyan); box-shadow: 0 0 14px rgba(51,255,231,.6); }
.thumb:active { transform: scale(.97); }

.chip-row { display: flex; gap: 10px; flex-wrap: wrap; }
.chip {
  flex: 1 1 0; min-width: 92px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 12px 8px; border-radius: 12px; cursor: pointer;
  background: rgba(51, 255, 231, 0.06);
  border: 1px solid var(--line); color: var(--text);
  font-size: 15px; font-weight: 600; letter-spacing: 1px;
  transition: all .15s;
}
.chip small { font-size: 11px; color: var(--muted); font-weight: 400; }
.chip.is-active { background: rgba(51, 255, 231, 0.16); border-color: var(--cyan); box-shadow: 0 0 14px rgba(51,255,231,.4); color: #fff; }
.chip.is-active small { color: var(--cyan); }
.chip:active { transform: scale(.97); }

.primary-btn {
  width: 100%; padding: 15px; margin-top: 8px;
  border: none; border-radius: 12px; cursor: pointer;
  font-size: 18px; font-weight: 800; letter-spacing: 2px; color: #06040f;
  background: linear-gradient(90deg, var(--cyan), var(--purple), var(--magenta));
  box-shadow: 0 0 22px rgba(138, 92, 255, 0.5);
  transition: filter .15s, transform .1s;
}
.primary-btn:hover { filter: brightness(1.1); }
.primary-btn:active { transform: scale(.98); }

.error-text { color: #ff7a9c; text-align: center; margin-top: 12px; font-size: 13px; }

/* ---------- ゲーム画面 ---------- */
.hud {
  flex: 0 0 auto;
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 8px clamp(8px, 2vw, 16px);
  background: rgba(10, 6, 26, 0.7);
  border-bottom: 1px solid var(--line);
  z-index: 3;
}
.hud-stats { display: flex; gap: clamp(8px, 3vw, 22px); margin: 0 auto; }
.hud-actions { flex-wrap: wrap; justify-content: flex-end; }
.stat { display: flex; flex-direction: column; align-items: center; line-height: 1.1; }
.stat-label { font-size: 9px; letter-spacing: 2px; color: var(--muted); }
.stat span:last-child, #stat-time, #stat-moves, #stat-pieces {
  font-size: clamp(14px, 3.6vw, 20px); font-weight: 700; font-variant-numeric: tabular-nums;
  color: #fff; text-shadow: 0 0 8px rgba(51,255,231,.5);
}
.hud-actions { display: flex; gap: 6px; }

.ghost-btn {
  padding: 8px 12px; border-radius: 10px; cursor: pointer;
  background: rgba(138, 92, 255, 0.12); border: 1px solid var(--line);
  color: var(--text); font-size: 14px; font-weight: 600; white-space: nowrap;
  transition: background .15s, transform .1s;
}
.ghost-btn:hover { background: rgba(138, 92, 255, 0.24); }
.ghost-btn:active { transform: scale(.96); }

.puzzle-wrap {
  position: relative; flex: 1 1 auto; min-height: 0;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
/* headbreaker(Konva) が生成する canvas コンテナ。タッチのスクロール抑止が必須。 */
#puzzle { position: relative; z-index: 1; touch-action: none; }
#puzzle canvas { touch-action: none !important; }

/* 正解位置を示す薄い下絵（ゴースト）。盤面アスペクト＝画像アスペクトなので object-fit:fill でも歪まない。 */
.ghost-img {
  position: absolute; z-index: 0; object-fit: fill;
  opacity: .16; filter: saturate(.85);
  border: 1px dashed rgba(51, 255, 231, .45); border-radius: 6px;
  pointer-events: none;
}

.preview-img {
  position: absolute; right: 12px; bottom: 12px;
  width: clamp(120px, 26vw, 240px); object-fit: contain;
  border: 2px solid var(--cyan); border-radius: 10px;
  box-shadow: 0 0 20px rgba(51,255,231,.5); z-index: 2; pointer-events: none;
}

/* 分解操作のヒント（控えめに左下） */
.detach-hint {
  position: absolute; left: 12px; bottom: 10px; z-index: 2;
  margin: 0; padding: 4px 9px; border-radius: 8px;
  font-size: 11px; letter-spacing: .5px; color: var(--muted);
  background: rgba(10, 6, 26, .5); border: 1px solid var(--line);
  pointer-events: none; user-select: none;
}

/* ---------- クリア演出 ---------- */
.overlay { align-items: center; justify-content: center; z-index: 10; background: rgba(4, 2, 12, 0.72); backdrop-filter: blur(3px); }
#confetti { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.clear-card {
  position: relative; z-index: 2; text-align: center;
  width: min(460px, 92vw);
  background: var(--panel); border: 1px solid var(--cyan); border-radius: 18px;
  padding: clamp(20px, 5vw, 34px);
  box-shadow: 0 0 50px rgba(51,255,231,.4);
  animation: pop .45s cubic-bezier(.2,1.3,.4,1) both;
}
@keyframes pop { from { transform: scale(.7); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.clear-title {
  font-size: clamp(28px, 8vw, 46px); font-weight: 800; letter-spacing: 3px; color: #fff;
  text-shadow: 0 0 14px var(--cyan), 0 0 30px var(--magenta);
  margin-bottom: 16px;
}
.clear-img { width: 100%; max-height: 42vh; object-fit: contain; border-radius: 12px; border: 1px solid var(--line); }
.clear-stats { display: flex; justify-content: center; gap: 34px; margin: 18px 0 22px; }
.clear-stats span { display: block; font-size: 11px; letter-spacing: 2px; color: var(--muted); }
.clear-stats b { font-size: 24px; color: #fff; font-variant-numeric: tabular-nums; text-shadow: 0 0 10px rgba(51,255,231,.5); }
.clear-actions { display: flex; gap: 10px; }
.clear-actions .primary-btn { margin-top: 0; }
.clear-actions .ghost-btn { flex: 0 0 auto; padding: 15px 18px; }

/* 横長・狭高（iframe が低い）の場合はクリアカードの画像を隠して収める */
@media (max-height: 460px) {
  .clear-img { display: none; }
  .clear-stats { margin: 12px 0 16px; }
}
