/* ============================================================
   名画ジグソー — 夜の美術館（Masterpiece Jigsaw）
   識別色：墨(charcoal) × 金(frame gold) × 緑青(patina teal)
   ============================================================ */
:root {
  --bg: #0b0a08;
  --bg2: #14110e;
  --wall: #171410;         /* 壁面 */
  --panel: #1c1813;
  --panel2: #241f19;
  --ink: #efe7d8;
  --ink-dim: #a99e8b;
  --ink-faint: #6f6656;
  --gold: #c8a24a;         /* 額のフチ */
  --gold-2: #e6cf8c;
  --patina: #5fae9d;       /* 緑青アクセント（本作固有） */
  --patina-2: #86d3c1;
  --line: rgba(232, 210, 150, 0.14);
  --hair: rgba(255, 255, 255, 0.07);
  --shadow: 0 18px 55px rgba(0, 0, 0, 0.6);
  --shadow-soft: 0 10px 30px rgba(0, 0, 0, 0.45);
  --serif: "Hiragino Mincho ProN", "Yu Mincho", "YuMincho", "Noto Serif JP",
           "Times New Roman", "Songti SC", serif;
  --sans: "Hiragino Kaku Gothic ProN", "Yu Gothic", "Meiryo", system-ui, sans-serif;
  --board-max: 560px;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0;
  color: var(--ink);
  font-family: var(--sans);
  overscroll-behavior: none;
}
body {
  /* 夜の展示室：中央のほのかなスポット＋周縁ビネット */
  background:
    radial-gradient(130% 90% at 50% 22%, #26201a 0%, var(--bg2) 42%, var(--bg) 78%),
    var(--bg);
  min-height: 100vh;
}
body::after { /* 周縁ビネット */
  content: ""; position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background: radial-gradient(120% 90% at 50% 30%, transparent 55%, rgba(0,0,0,0.55) 100%);
}
.app {
  position: relative; z-index: 1;
  max-width: 720px; margin: 0 auto; padding: 0 14px 48px;
}
@media (min-width: 720px) {
  :root { --board-max: 620px; }
  .app { max-width: 860px; }
}

/* ---- トップバー ---- */
.topbar { display: flex; align-items: center; gap: 10px; padding: 14px 2px 6px; }
.back {
  color: var(--ink-dim); text-decoration: none; font-size: 13px;
  padding: 6px 8px; border-radius: 8px; white-space: nowrap;
}
.back:hover { color: var(--gold-2); background: rgba(255,255,255,0.04); }
.brand { flex: 1; display: flex; align-items: center; gap: 9px; justify-content: center; }
.crest { width: 26px; height: 26px; color: var(--gold); opacity: 0.9; }
.title {
  font-family: var(--serif); font-weight: 600; margin: 0;
  font-size: 21px; letter-spacing: 0.16em; color: var(--ink);
}
.title .accent { color: var(--gold-2); }
@media (min-width: 720px) { .title { font-size: 25px; } }
.icon-btn {
  border: 1px solid var(--hair); background: rgba(255,255,255,0.03);
  color: var(--ink-dim); width: 38px; height: 34px; border-radius: 9px;
  font-size: 13px; cursor: pointer; transition: 0.2s var(--ease);
}
.icon-btn:hover { color: var(--gold-2); border-color: var(--line); }

.wa-divider { display: block; width: 100%; height: 12px; margin: 2px 0 14px; opacity: 0.5; }

/* ============================================================
   ボタン共通
   ============================================================ */
.btn {
  font-family: var(--sans); font-size: 15px; letter-spacing: 0.05em;
  color: var(--ink); background: var(--panel2);
  border: 1px solid var(--line); border-radius: 11px;
  padding: 12px 18px; cursor: pointer; transition: 0.2s var(--ease);
}
.btn:hover { border-color: var(--gold); color: var(--gold-2); }
.btn:active { transform: translateY(1px); }
.btn-primary {
  background: linear-gradient(180deg, #2c2419, #1e1811);
  border-color: var(--gold); color: var(--gold-2);
  box-shadow: 0 0 0 1px rgba(200,162,74,0.15), var(--shadow-soft);
}
.btn-primary:hover { box-shadow: 0 0 24px rgba(200,162,74,0.28), var(--shadow-soft); }
.btn-ghost { background: transparent; border-color: var(--hair); color: var(--ink-dim); }
.btn-ghost:hover { color: var(--patina-2); border-color: rgba(95,174,157,0.4); }
.btn-mini { padding: 8px 12px; font-size: 13px; border-radius: 9px; }
.hidden { display: none !important; }

/* ============================================================
   ホーム（作品選択）
   ============================================================ */
.home-kicker {
  text-align: center; color: var(--patina); font-size: 12px;
  letter-spacing: 0.34em; margin: 4px 0 2px; text-transform: uppercase;
}
.home-lead {
  text-align: center; color: var(--ink-dim); font-size: 13.5px;
  margin: 0 auto 18px; max-width: 30em; line-height: 1.7;
}
.section-label {
  font-family: var(--serif); font-size: 13px; letter-spacing: 0.2em;
  color: var(--ink-dim); margin: 22px 4px 10px; display: flex;
  align-items: center; gap: 10px;
}
.section-label::after { content: ""; flex: 1; height: 1px; background: var(--hair); }

/* 難易度セグメント */
.diff-seg { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.diff-seg .seg {
  text-align: center; padding: 11px 4px; border-radius: 11px;
  border: 1px solid var(--hair); background: rgba(255,255,255,0.02);
  cursor: pointer; transition: 0.2s var(--ease);
}
.diff-seg .seg .seg-grid { font-family: var(--serif); font-size: 17px; color: var(--ink); }
.diff-seg .seg .seg-name { display: block; font-size: 10.5px; color: var(--ink-faint); margin-top: 3px; letter-spacing: 0.08em; }
.diff-seg .seg.on {
  border-color: var(--patina); background: rgba(95,174,157,0.1);
  box-shadow: 0 0 0 1px rgba(95,174,157,0.25) inset;
}
.diff-seg .seg.on .seg-grid { color: var(--patina-2); }
.diff-seg .seg.on .seg-name { color: var(--patina); }

/* 作品グリッド */
.art-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
@media (min-width: 560px) { .art-grid { grid-template-columns: repeat(4, 1fr); } }
.art-card {
  position: relative; border-radius: 10px; overflow: hidden; cursor: pointer;
  aspect-ratio: 1 / 1; background: #0e0c0a;
  border: 1px solid var(--hair); transition: 0.2s var(--ease);
}
.art-card img {
  width: 100%; height: 100%; object-fit: cover; display: block;
  filter: brightness(0.82) saturate(0.95); transition: 0.25s var(--ease);
}
.art-card:hover img { filter: brightness(1) saturate(1); }
.art-card.on {
  border-color: var(--gold);
  box-shadow: 0 0 0 1px var(--gold), 0 0 22px rgba(200,162,74,0.35);
}
.art-card.on img { filter: brightness(1.02) saturate(1.02); }
.art-card .clear-mark {
  position: absolute; top: 6px; right: 6px; width: 20px; height: 20px;
  border-radius: 50%; background: rgba(11,10,8,0.7); color: var(--gold-2);
  font-size: 12px; display: grid; place-items: center;
  border: 1px solid var(--gold); backdrop-filter: blur(2px);
}
.art-card .cap {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 14px 8px 6px;
  font-family: var(--serif); font-size: 11px; letter-spacing: 0.04em; color: var(--ink);
  background: linear-gradient(transparent, rgba(0,0,0,0.72));
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.home-actions { display: flex; gap: 10px; margin-top: 22px; }
.home-actions .btn { flex: 1; }

/* ============================================================
   プレイ画面
   ============================================================ */
.play-head { display: flex; align-items: center; gap: 12px; margin: 2px 4px 12px; }
.play-head .p-title {
  flex: 1; font-family: var(--serif); font-size: 15px; letter-spacing: 0.06em;
  color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.p-stats { display: flex; gap: 16px; }
.p-stat { text-align: right; }
.p-stat .val {
  font-variant-numeric: tabular-nums; font-family: var(--serif);
  font-size: 20px; color: var(--gold-2); line-height: 1;
}
.p-stat .lab { display: block; font-size: 10px; color: var(--ink-faint); letter-spacing: 0.16em; margin-top: 3px; }

/* 額装ステージ */
.stage-wrap { display: flex; justify-content: center; }
.frame {
  position: relative; max-width: var(--board-max); width: 100%;
  padding: 10px; border-radius: 4px;
  background: linear-gradient(145deg, #2a2118, #17120d);
  border: 1px solid rgba(200,162,74,0.55);
  box-shadow:
    0 0 0 1px rgba(0,0,0,0.6),
    0 0 34px rgba(200,162,74,0.12),
    var(--shadow);
}
.frame::before { /* 内マット */
  content: ""; position: absolute; inset: 6px; border-radius: 2px;
  border: 1px solid rgba(255,255,255,0.06); pointer-events: none; z-index: 3;
}
.board {
  position: relative; width: 100%; border-radius: 1px; overflow: hidden;
  background: #050403; touch-action: manipulation; user-select: none;
}
.tile {
  position: absolute; top: 0; left: 0;
  background-repeat: no-repeat;
  transition: transform 0.24s var(--ease), box-shadow 0.2s var(--ease), filter 0.2s var(--ease);
  cursor: pointer; will-change: transform;
  box-shadow: inset 0 0 0 0.5px rgba(0,0,0,0.35);
}
.tile.sel {
  z-index: 5; filter: brightness(1.12);
  box-shadow: inset 0 0 0 2px var(--patina-2), 0 6px 18px rgba(0,0,0,0.5);
}
.tile.home-ok::after { /* 正位置のうっすら金グロー（ヒント時） */
  content: ""; position: absolute; inset: 0;
  box-shadow: inset 0 0 0 1px rgba(200,162,74,0.55);
  pointer-events: none;
}
.board.peek .tile { transform: translate(var(--hx), var(--hy)) !important; }
.board.solved .tile { box-shadow: none; }

/* 完成時のスポット点灯演出 */
.spotlight {
  position: absolute; inset: 0; pointer-events: none; z-index: 4; opacity: 0;
  background: radial-gradient(60% 60% at 50% 42%, rgba(255,246,224,0.16), transparent 70%);
  transition: opacity 0.9s ease;
}
.board.solved .spotlight { opacity: 1; }

/* プレイ操作 */
.play-controls {
  display: flex; gap: 8px; justify-content: center; flex-wrap: wrap;
  margin: 16px auto 0; max-width: var(--board-max);
}
.play-controls .btn { flex: 1; min-width: 78px; }
.peek-hint { text-align: center; color: var(--ink-faint); font-size: 11.5px; margin: 10px 0 0; }

/* ============================================================
   完成オーバーレイ
   ============================================================ */
.overlay {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center;
  padding: 20px; background: rgba(6,5,4,0.72); backdrop-filter: blur(6px);
  animation: fade 0.4s ease;
}
@keyframes fade { from { opacity: 0; } }
.dialog {
  width: 100%; max-width: 460px; border-radius: 16px;
  background: linear-gradient(180deg, var(--panel), var(--bg2));
  border: 1px solid var(--line); box-shadow: var(--shadow);
  padding: 22px; text-align: center; animation: rise 0.45s var(--ease);
}
@keyframes rise { from { transform: translateY(14px); opacity: 0; } }
.result-kicker { color: var(--patina); font-size: 11px; letter-spacing: 0.3em; text-transform: uppercase; margin: 0 0 8px; }
.result-figure {
  position: relative; border-radius: 6px; overflow: hidden; margin: 0 auto 16px;
  border: 1px solid rgba(200,162,74,0.5); box-shadow: 0 0 30px rgba(200,162,74,0.14), var(--shadow-soft);
  animation: light 1s ease;
}
@keyframes light { from { filter: brightness(0.3); } to { filter: brightness(1); } }
.result-figure img { width: 100%; display: block; }
.result-title { font-family: var(--serif); font-size: 22px; margin: 4px 0 2px; letter-spacing: 0.05em; }
.result-meta { color: var(--ink-dim); font-size: 13px; margin: 0 0 4px; }
.result-blurb { color: var(--ink-dim); font-size: 12.5px; line-height: 1.75; margin: 10px 4px 14px; }
.result-stats { display: flex; justify-content: center; gap: 26px; margin: 12px 0 6px; }
.result-stats .val { font-family: var(--serif); font-size: 24px; color: var(--gold-2); font-variant-numeric: tabular-nums; }
.result-stats .lab { display: block; font-size: 10.5px; color: var(--ink-faint); letter-spacing: 0.14em; margin-top: 3px; }
.stars { font-size: 18px; letter-spacing: 4px; color: var(--gold); margin: 4px 0 2px; }
.stars .off { color: var(--ink-faint); opacity: 0.5; }
.best-tag { color: var(--patina-2); font-size: 12px; margin: 6px 0 0; letter-spacing: 0.08em; }
.dialog-actions { display: flex; gap: 10px; margin-top: 18px; }
.dialog-actions .btn { flex: 1; }
.credit-line { color: var(--ink-faint); font-size: 10.5px; margin: 14px 0 0; letter-spacing: 0.04em; }

/* ============================================================
   図鑑（ギャラリー）
   ============================================================ */
.gallery-head { display: flex; align-items: baseline; gap: 12px; margin: 4px 4px 4px; }
.gallery-head h2 { font-family: var(--serif); font-size: 20px; margin: 0; letter-spacing: 0.1em; }
.gallery-head .count { color: var(--patina-2); font-size: 13px; font-variant-numeric: tabular-nums; }
.gallery-sub { color: var(--ink-dim); font-size: 12.5px; margin: 0 4px 16px; line-height: 1.6; }
.gal-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
@media (min-width: 520px) { .gal-grid { grid-template-columns: repeat(3, 1fr); } }
.gal-card {
  border-radius: 8px; overflow: hidden; background: var(--panel);
  border: 1px solid var(--hair); cursor: pointer; transition: 0.2s var(--ease);
}
.gal-card:hover { border-color: var(--line); transform: translateY(-2px); }
.gal-frame {
  position: relative; aspect-ratio: 1 / 1; overflow: hidden;
  background: #0d0b09; display: grid; place-items: center;
}
.gal-frame img { width: 100%; height: 100%; object-fit: cover; }
.gal-frame.locked img { filter: brightness(0) saturate(0); opacity: 0.22; }
.gal-frame.locked::after {
  content: "？"; position: absolute; font-family: var(--serif);
  font-size: 30px; color: var(--ink-faint);
}
.gal-info { padding: 9px 10px 11px; }
.gal-info .t { font-family: var(--serif); font-size: 12.5px; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gal-info .a { font-size: 10.5px; color: var(--ink-faint); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gal-info .a.locked-a { color: var(--ink-faint); }
.gal-stars { font-size: 11px; letter-spacing: 2px; color: var(--gold); margin-top: 4px; min-height: 14px; }
.gal-stars .off { color: var(--ink-faint); opacity: 0.4; }

/* 図鑑 詳細モーダル */
.detail-figure { border-radius: 6px; overflow: hidden; margin: 0 0 14px; border: 1px solid rgba(200,162,74,0.4); box-shadow: var(--shadow-soft); }
.detail-figure img { width: 100%; display: block; }
.detail-title { font-family: var(--serif); font-size: 20px; margin: 2px 0; }
.detail-meta { color: var(--ink-dim); font-size: 13px; }
.detail-blurb { color: var(--ink-dim); font-size: 12.5px; line-height: 1.75; margin: 12px 0; text-align: left; }
.detail-times { display: flex; justify-content: center; gap: 14px; flex-wrap: wrap; margin: 10px 0; }
.detail-times .dt { text-align: center; }
.detail-times .dt .g { font-family: var(--serif); font-size: 13px; color: var(--ink-dim); }
.detail-times .dt .v { font-variant-numeric: tabular-nums; font-size: 14px; color: var(--gold-2); }
.detail-times .dt .v.none { color: var(--ink-faint); }
.detail-license { color: var(--ink-faint); font-size: 11px; margin-top: 6px; letter-spacing: 0.04em; }

/* ============================================================
   下部：遊び方 / SEO本文
   ============================================================ */
.hint { color: var(--ink-dim); font-size: 12.5px; line-height: 1.8; margin: 26px 4px 0; text-align: center; }
.about {
  margin: 34px 4px 0; padding-top: 22px; border-top: 1px solid var(--hair);
  color: var(--ink-dim); line-height: 1.85; font-size: 13.5px;
}
.about h2 { font-family: var(--serif); color: var(--ink); font-size: 18px; letter-spacing: 0.08em; margin: 0 0 10px; }
.about h3 { font-family: var(--serif); color: var(--ink); font-size: 15px; letter-spacing: 0.06em; margin: 20px 0 8px; }
.about p { margin: 0 0 8px; }
.credits { text-align: center; color: var(--ink-faint); font-size: 11px; margin: 22px 0 0; }
.credits a { color: var(--ink-dim); }

.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%) translateY(10px);
  background: var(--panel2); color: var(--gold-2); border: 1px solid var(--gold);
  padding: 11px 20px; border-radius: 30px; font-size: 13px; letter-spacing: 0.06em;
  box-shadow: var(--shadow); opacity: 0; transition: 0.3s var(--ease); z-index: 60; pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
