/* nakama（仲間はずれ探し）- 4枚のカードから仲間はずれを1枚見つけるミニゲーム */

:root {
  --bg: #20212b;
  --panel: #2a2c3a;
  --card: #343650;
  --text: #e8e6f0;
  --text-dim: #9a97ab;
  --accent: #d9b26f;
  --correct: #84a59d;
  --wrong: #c98d94;
}

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

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", sans-serif;
  touch-action: manipulation;
  overscroll-behavior: none;
  overflow: hidden;
}

#app {
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100dvh;
  padding: calc(env(safe-area-inset-top, 0px) + 12px) 16px calc(env(safe-area-inset-bottom, 0px) + 12px);
}

/* ========================================
   ヘッダー・タイトル
   ======================================== */

#header {
  position: relative;
  width: 100%;
  display: flex;
  justify-content: center;
  flex: 0 0 auto;
}

#game-title {
  font-family: Georgia, "Times New Roman", "Hiragino Mincho ProN", serif;
  font-size: 20px;
  font-weight: 400;
  letter-spacing: 0.4em;
  text-indent: 0.4em; /* letter-spacing 分の中央ずれ補正 */
  color: var(--text-dim);
  margin: 8px 0 0;
}

#giveup-button {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 12px);
  right: 16px;
  padding: 6px 12px;
  font-size: 11px;
  letter-spacing: 0.1em;
  border: none;
  border-radius: 6px;
  background: none;
  color: var(--text-dim);
  opacity: 0.6;
  cursor: pointer;
  z-index: 50;
}

/* ========================================
   スコア表示（score / best）
   ======================================== */

#score-display {
  flex: 0 0 auto;
  display: flex;
  gap: 32px;
  margin: 10px 0 4px;
}

.score-block {
  text-align: center;
}

.score-label {
  font-size: 12px;
  letter-spacing: 0.1em;
  color: var(--text-dim);
  text-transform: uppercase;
}

#score-value,
#best-value {
  font-size: 24px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

#best-value {
  color: var(--accent);
}

/* ========================================
   盤面（2×2のカード）
   ======================================== */

#board-wrap {
  flex: 1 1 auto;
  width: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
}

/* 改訂2: カードを5:7の縦長にしたため、#board全体も同じ比率になるよう
   width基準で組み立てる（2×2は個々のカードと同じ5:7比率になる）。
   高さ側の予算（dvh基準）から先に幅の上限を出し、それとvw上限・px上限の
   min()で幅を決め、aspect-ratioで高さを追従させる。 */
#board {
  --board-width: min(90vw, 65dvh, 420px);
  width: var(--board-width);
  aspect-ratio: 5 / 7;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  grid-template-rows: repeat(2, 1fr);
  gap: 12px;
}

.card {
  position: relative;
  border-radius: 18px;
  background: linear-gradient(160deg, #3c3e5c 0%, var(--card) 60%);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.05);
  cursor: pointer;
  /* 正解カードの光り（タップ直後）、誤答時の正解カード表示（タイマー無し、押しっぱなしで残る） */
  transition: box-shadow 0.25s ease, transform 0.25s ease;
}

/* 改訂4: カード地の繊細なペーパーテクスチャ。feTurbulence(fractalNoise)を
   グレースケール化したノイズをdata URIのSVGとして::beforeの背景に敷く。
   ::beforeはカード自身の背景として自動的にborder-radiusでクリップされる
   （overflow: hiddenは付けない。図形の影filterがカード端でクリップされるのを避けるため）。
   図形（.figure）はDOM順でこの後に来るため、常にテクスチャの上に描画される。
   soft-lightは暗いカード地の上でoverlayより控えめに粒立つため採用。 */
.card::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background-image: url("data:image/svg+xml;utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  background-size: 220px 220px;
  opacity: 0.06;
  mix-blend-mode: soft-light;
  pointer-events: none;
}

.board.locked .card {
  cursor: default;
}

/* 改訂1: OK!ポップ表示中に盤面をぼかす（kokonotと同じ方針） */
#board.blurred {
  filter: blur(6px);
  transition: filter 0.15s ease;
}

.card.correct {
  box-shadow: 0 0 0 3px var(--correct), 0 0 18px rgba(132, 165, 157, 0.85);
  transform: translateY(-6px);
}

.card.revealed {
  box-shadow: 0 0 0 3px var(--correct), 0 0 14px rgba(132, 165, 157, 0.6);
}

.card.wrong-pick {
  animation: card-shake 0.4s ease;
}

@keyframes card-shake {
  0%, 100% { transform: translateX(0); }
  20%      { transform: translateX(-6px); }
  40%      { transform: translateX(5px); }
  60%      { transform: translateX(-3px); }
  80%      { transform: translateX(2px); }
}

/* ========================================
   図形（inline SVG）
   ======================================== */

/* 改訂2: カード内の格子（個数ごとの固定位置）を基準に少しジッターさせて置く
   （position/rotationはgame.jsのplaceFiguresが決める。ランダム散布はしない）。
   left/topの%指定はカード自身（絶対配置の containing block）基準なので、カードが縮んでも
   game.jsのCONFIG.layout.grids（正規化座標0〜1）とそのまま対応する */
.figure {
  position: absolute;
  display: block;
}

/* 改訂2: 図形を全体的に大きく。大は小の約1.67倍（小 = 大の0.6倍、結城さん指定）。
   CONFIG.layout の largeRadius/smallRadius（直径換算36%/21.6%）と対応。
   widthのみ指定しaspect-ratio: 1で正方形にする。カードが5:7の縦長になったため、
   width/heightを同じ%にすると（%はそれぞれ親のwidth/heightが基準のため）縦につぶれてしまう。
   width基準で高さを追従させることで、カードの縦横比に関係なく真円・正方形を保つ */
.figure-small {
  width: 21.6%;
  aspect-ratio: 1;
}

.figure-large {
  width: 36%;
  aspect-ratio: 1;
}

.figure svg {
  width: 100%;
  height: 100%;
  display: block;
  overflow: visible; /* feDropShadowの影がviewBoxの0〜100をわずかにはみ出すため */
}

.figure-shape {
  /* 改訂3: 小さい図形でも縁がはっきり見えるよう太く（6→10）。3種の模様すべてで同じ太さ・同じ色相 */
  /* 改訂5: stroke-width は game.js の inline style が常に上書きする（★だけ8、他は10）。
     ここでの10はinline styleが万一無いときのフォールバックとして残す */
  stroke-width: 10;
  filter: url(#nakama-shadow);
  /* fill/fill-opacity/stroke/stroke-width/color は figure ごとに game.js が inline style で設定する
     （形の色相ではなくカード単位の色、模様、★のみ縁の太さが異なるため） */
}

/* ========================================
   結果パネル（Game Over + Restart）
   ======================================== */

#result-panel {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 20px;
  min-height: 56px;
  margin-top: 16px;
  visibility: hidden;
}

#result-panel.show {
  visibility: visible;
}

#result-text {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: var(--wrong);
}

#restart-button {
  padding: 10px 28px;
  font-size: 16px;
  border: none;
  border-radius: 999px;
  background: var(--accent);
  color: #2a2410;
  font-weight: 600;
  cursor: pointer;
}

#restart-button:active {
  transform: scale(0.97);
}

/* ========================================
   OK! / Oops... ポップオーバーレイ（kokonotのClear!/Oops...ポップを踏襲）
   ======================================== */

#pop-overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  /* 改訂4: 1.25倍に拡大（32/11/56 → 40/14/70） */
  font-size: clamp(40px, 14vw, 70px);
  font-weight: 800;
  letter-spacing: 0.02em;
  opacity: 0;
  transform: scale(0.3);
}

#pop-overlay.pop-active {
  pointer-events: auto;
  cursor: pointer;
}

/* 改訂4: 白をはっきり（純白に近づけ、色味は縁取り的なtext-shadowでOK/Oopsを区別） */
#pop-overlay.pop-ok {
  color: #ffffff;
  text-shadow: 0 2px 14px rgba(132, 165, 157, 0.65);
}

/* 改訂3: 誤答時の Oops... ポップ（kokonot の pop-oops を踏襲） */
#pop-overlay.pop-oops {
  color: #ffffff;
  text-shadow: 0 2px 14px rgba(201, 141, 148, 0.65);
}

/* ポップイン（CONFIG.popMs=450 と同期） */
@keyframes pop-in {
  0%   { transform: scale(0.3); opacity: 0; }
  60%  { transform: scale(1.15); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

#pop-overlay.pop-show {
  animation: pop-in 0.45s ease forwards;
}

/* ポップアウト（CONFIG.popFadeMs=150 と同期） */
#pop-overlay.pop-fade {
  transition: opacity 0.15s ease;
  /* opacity 自体は game.js の dismissPop が inline で 0 にする（クラスの opacity は inline に負けるため） */
}
