/* 出庫パズル — モバイルファースト・縦画面。PCでは中央に縦長のゲーム領域（最大幅480px） */
:root {
  --bg: #f2efe6;
  --outer: #2f3440;
  --panel: #fffdf8;
  --text: #2b2f38;
  --sub: #6b7080;
  --line: #d8d2c2;
  --primary: #e5484d;
  --primary-dark: #c43a3f;
  --accent: #3e7bfa;
  --gold: #e0a800;
  --radius: 14px;
  --bar-h: 52px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--outer);
  color: var(--text);
  font-family: system-ui, -apple-system, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic UI", Meiryo, sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

body { overflow: hidden; }

button { font: inherit; color: inherit; }

.app {
  position: relative;
  width: 100%;
  max-width: 480px;
  height: 100vh;
  height: 100dvh;
  margin: 0 auto;
  background: var(--bg);
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}

.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
}
.screen.active { display: flex; }

/* ---- ボタン ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 48px;
  padding: 0 20px;
  border: 2px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  font-size: 17px;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform .08s, background .15s;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .4; cursor: default; transform: none; }
.btn:focus-visible, .icon-btn:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.btn-primary { background: var(--primary); border-color: var(--primary-dark); color: #fff; }
.btn-danger { border-color: #e9b4b5; color: #b4282d; }
.btn-small { min-height: 44px; padding: 0 12px; font-size: 14px; flex: 1; }
.btn-link { border: 0; background: none; min-height: 36px; padding: 0 6px; color: var(--accent); font-size: 15px; text-decoration: underline; }

.icon-btn {
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  font-size: 30px;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
}
.icon-btn:active { background: rgba(0, 0, 0, .07); }

/* ---- バー ---- */
.bar {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: var(--bar-h);
  padding: 4px 8px;
  flex: none;
}
.bar h2 { margin: 0; font-size: 18px; flex: 1; text-align: center; white-space: nowrap; }
.bar .bar-space { width: 44px; }
.bar .remain { font-size: 14px; font-weight: 700; color: var(--sub); white-space: nowrap; }
.bar-foot { gap: 8px; padding: 6px 10px 10px; }

/* ---- タイトル ---- */
.screen-title { align-items: center; justify-content: center; gap: 28px; padding: 24px; }
.logo { text-align: center; }
.logo-mark { width: 150px; height: 100px; }
.logo h1 { margin: 6px 0 2px; font-size: 40px; letter-spacing: .06em; }
.tagline { margin: 0; color: var(--sub); }
.menu { display: flex; flex-direction: column; gap: 12px; width: min(280px, 100%); }
.copy { position: absolute; bottom: calc(10px + var(--safe-bottom)); margin: 0; font-size: 12px; color: var(--sub); }

/* ---- ステージ選択 ---- */
.stage-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  padding: 8px 16px;
  align-content: start;
  flex: 1;
}
.stage-btn {
  position: relative;
  aspect-ratio: 1;
  border: 2px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  font-size: 20px;
  font-weight: 800;
  cursor: pointer;
  touch-action: manipulation;
}
.stage-btn.cleared { border-color: #9bd1b2; background: #eef8f1; }
.stage-btn.locked { color: #b8b3a5; background: #ece8dc; cursor: default; }
.stage-btn .marks { position: absolute; right: 6px; top: 3px; font-size: 13px; }
.stage-btn .lock { font-size: 15px; }
.stage-btn .lv { position: absolute; left: 0; right: 0; bottom: 4px; height: 4px; margin: 0 14px; border-radius: 2px; }
.mark-clear { color: #2f9e5b; }
.mark-star { color: var(--gold); }
.lv-1 { background: #9bd1b2; } .lv-2 { background: #8fb6f7; } .lv-3 { background: #f5c518; } .lv-4 { background: #f7964f; } .lv-5 { background: #e5484d; }
.lv-6 { background: #c13584; } .lv-7 { background: #8e4ec6; } .lv-8 { background: #5b3a9e; } .lv-9 { background: #2b2f38; }
.pager { display: flex; align-items: center; justify-content: center; gap: 16px; font-weight: 700; }
.legend { margin: 0 0 12px; text-align: center; font-size: 13px; color: var(--sub); }

/* ---- プレイ ---- */
.stage-wrap { position: relative; flex: 1; min-height: 0; }
#board { display: block; touch-action: none; }
.toast {
  position: absolute;
  left: 50%;
  top: 40%;
  transform: translate(-50%, -50%);
  padding: 10px 18px;
  border-radius: 999px;
  background: rgba(43, 47, 56, .9);
  color: #fff;
  font-weight: 700;
  font-size: 15px;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity .2s;
}
.toast.show { opacity: 1; }

/* ---- ダイアログ ---- */
.dlg {
  width: min(400px, calc(100% - 32px));
  max-height: calc(100% - 32px);
  padding: 0;
  border: 0;
  border-radius: 20px;
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
  overflow: auto;
}
.dlg-wide { width: min(460px, calc(100% - 24px)); }
.dlg::backdrop { background: rgba(30, 33, 40, .45); }
.dlg[open] { animation: pop .18s ease-out; }
@keyframes pop { from { transform: scale(.94); opacity: 0; } to { transform: none; opacity: 1; } }
.dlg-body { padding: 22px 20px 18px; display: flex; flex-direction: column; gap: 12px; }
.dlg h3 { margin: 0; font-size: 24px; text-align: center; }
.dlg p { margin: 0; line-height: 1.6; }
.dlg-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 6px; }
.result-taps { text-align: center; font-size: 18px; }
.result-taps span { font-size: 40px; font-weight: 800; }
.result-best, .result-note { text-align: center; color: var(--sub); font-size: 14px; }
.result-badge { text-align: center; color: var(--gold); font-weight: 800; }
.result-clear h3 { color: var(--primary); }
.hidden { display: none !important; }

/* 全面クリア */
.title-badge { margin: 10px 0 0; font-weight: 800; color: var(--gold); font-size: 18px; }
.dlg-complete .dlg-body { text-align: center; }
.dlg-complete h3 { color: var(--gold); font-size: 30px; }
.trophy { width: 110px; height: 110px; margin: 0 auto; }
.dlg-complete[open] .trophy { animation: trophy 1.2s ease-out; }
@keyframes trophy { 0% { transform: scale(.3) rotate(-20deg); opacity: 0; } 60% { transform: scale(1.15) rotate(6deg); opacity: 1; } 100% { transform: none; } }
.complete-stats { font-weight: 800; color: var(--gold); }
.complete-hint { font-size: 13px; color: var(--sub); }

.cards { display: flex; flex-direction: column; gap: 12px; }
.card { margin: 0; display: grid; grid-template-columns: 120px 1fr; gap: 10px; align-items: center; }
.card svg { width: 120px; height: auto; border-radius: 10px; background: var(--bg); }
.card figcaption { font-size: 14px; line-height: 1.55; }
.card-intro { grid-template-columns: 1fr; text-align: center; }
.card-intro svg { width: 100%; max-width: 280px; margin: 0 auto; }
.howto-assist { font-size: 14px; color: var(--sub); }
.howto-gimmicks { display: flex; flex-wrap: wrap; align-items: center; font-size: 14px; color: var(--sub); }
.privacy { border-top: 1px solid var(--line); padding-top: 10px; }
.privacy h4 { margin: 0 0 4px; font-size: 14px; }
.privacy p { font-size: 12px; color: var(--sub); }

.switch { display: flex; align-items: center; gap: 10px; min-height: 44px; font-size: 16px; cursor: pointer; }
.switch input { width: 22px; height: 22px; accent-color: var(--primary); }

.noscript { padding: 40px 20px; text-align: center; }

@media (min-width: 481px) {
  .app { box-shadow: 0 0 40px rgba(0, 0, 0, .35); }
}

@media (prefers-reduced-motion: reduce) {
  .dlg[open], .dlg-complete[open] .trophy { animation: none; }
  .btn, .toast { transition: none; }
}
