/*
 * ManaScope Lens — lens.html 専用スタイル
 * 既存 style.css の変数を参照するが、上書きは行わない
 * スマホ縦持ち前提 / PC は副次的
 */

/* ── ヘッダー（軽量・固定・48px） ── */
.lh-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: #F7F7F9;
  border-bottom: 1px solid var(--line);
  height: 48px;
  display: flex;
  align-items: center;
}
.lh-header::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: var(--green);
}
.lh-header-inner {
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: 0 14px;
  display: flex;
  align-items: center;
  gap: 0;
}
.lh-brand {
  font-family: Georgia, "Palatino Linotype", "Book Antiqua", serif;
  font-size: 17px;
  font-weight: 900;
  color: var(--green);
  text-decoration: none;
  letter-spacing: .02em;
  flex: 0 0 auto;
}
.lh-brand-page {
  font-family: inherit;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  margin-left: 6px;
  flex: 1 1 auto;
  white-space: nowrap;
}
.lh-nav {
  display: flex;
  align-items: center;
  gap: 0;
  flex: 0 0 auto;
}
.lh-nav-link {
  padding: 0 10px;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  text-decoration: none;
  line-height: 48px;
  border-bottom: 2px solid transparent;
  transition: color .15s;
  white-space: nowrap;
}
.lh-nav-link:hover {
  color: var(--green);
}
.lh-nav-link[aria-current="page"] {
  color: var(--green);
  font-weight: 600;
  border-bottom-color: var(--green);
}

/* ── メインコンテンツ ── */
.lh-main {
  max-width: 480px;
  margin: 0 auto;
  padding: 12px 14px 40px;
}

/* ── 説明文（コンパクト） ── */
.lh-desc {
  font-size: 14px;
  color: var(--muted);
  line-height: 1.6;
  margin-bottom: 10px;
}

/* ── カメラステージ ── */
.lh-stage {
  position: relative;
  background: #111;
  border-radius: 14px;
  overflow: hidden;
  /* Phase 15.11: idle / live で 4:3 統一（カメラ起動時のリサイズで「何かの
     意味」と誤認される問題を解消、番号帯の横長フォームとも親和） */
  aspect-ratio: 4 / 3;
  width: 100%;
}

/* lh-stage--live は将来の差別化用に残置、現状は default と同じ 4:3 */
.lh-video,
.lh-still {
  width: 100%;
  height: 100%;
  display: block;
}
.lh-video { object-fit: cover; }
/* Phase 15.2: 撮影画像は横長の番号帯。contain で全体を見せる */
.lh-still { object-fit: contain; background: #000; display: none; }
.lh-stage.captured .lh-video { display: none; }
.lh-stage.captured .lh-still { display: block; }
/* 撮影後はガイド枠 / マナ枠 / ヒントを隠して、撮影画像を見やすくする */
.lh-stage.captured .lh-guide { display: none; }
.lh-stage.captured .lh-mana-frame { display: none; }
.lh-stage.captured .lh-hint { display: none; }

/* P-2: カメラ起動前プレースホルダー */
.lh-stage--idle .lh-idle-overlay {
  display: flex;
}
.lh-idle-overlay {
  display: none;
  position: absolute;
  inset: 0;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: rgba(0, 0, 0, .72);
  padding: 20px;
  text-align: center;
  pointer-events: none;
  border-radius: inherit;
}
.lh-idle-icon {
  color: rgba(255,255,255,.7);
  flex-shrink: 0;
}
.lh-idle-text {
  color: rgba(255,255,255,.85);
  font-size: 13px;
  line-height: 1.6;
  max-width: 260px;
}
/* CSS のみで描く「カード左下に番号帯」の図解 */
.lh-idle-card {
  width: 56px;
  height: 78px;         /* 5:7 比 */
  border: 2px solid rgba(255,255,255,.45);
  border-radius: 6px;
  position: relative;
  flex-shrink: 0;
}
.lh-idle-card::after {
  content: "";
  position: absolute;
  bottom: 10px;
  left: 4px;
  right: 4px;
  height: 11px;
  border: 1.5px solid rgba(255,255,255,.65);
  border-radius: 3px;
  background: rgba(255,255,255,.15);
}

/* P-3: 処理中スピナー */
/* stage に .matching クラスが付いているときに ::after でオーバーレイ */
.lh-stage.matching::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,.45);
  pointer-events: none;
  z-index: 20;
  border-radius: inherit;
}
/* ドット 3 つのアニメーション — 疑似要素で実装できないため .lh-spinner を使う */
.lh-spinner {
  display: none;
  position: absolute;
  inset: 0;
  align-items: center;
  justify-content: center;
  z-index: 21;
  pointer-events: none;
}
.lh-stage.matching .lh-spinner {
  display: flex;
}
.lh-spinner-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #fff;
  margin: 0 5px;
  animation: lh-dot-pulse 1.2s ease-in-out infinite;
}
.lh-spinner-dot:nth-child(2) { animation-delay: .2s; }
.lh-spinner-dot:nth-child(3) { animation-delay: .4s; }
@keyframes lh-dot-pulse {
  0%, 80%, 100% { opacity: .25; transform: scale(.85); }
  40%           { opacity: 1;   transform: scale(1.15); }
}

/* MTG カード比 5:7 ガイド枠 */
.lh-guide {
  position: absolute;
  inset: 0;
  pointer-events: none;
  display: flex;
  align-items: center;
  justify-content: center;
}
.lh-guide-frame {
  position: relative;
  /* Phase 15.2: 番号帯フォーカス UI — ガイド枠 = カード左下の番号印字帯
     （M 0040 / J25・JP 等）を合わせる横長バンド。OCR 専用、pHash は廃止。
     lens.js の GUIDE_WIDTH_RATIO / STRIP_ASPECT と一致させること。 */
  width: 86%;
  aspect-ratio: 4 / 1;
  border: 2px solid rgba(255,255,255,.5);
  border-radius: 8px;
  box-shadow: 0 0 0 9999px rgba(0,0,0,.55);
  transition: border-color .15s, box-shadow .15s;
}
/* 4 隅 L 字マーカー（番号帯の四隅を合わせる目印） */
.lh-corner {
  position: absolute;
  width: 22px;
  height: 22px;
  border: 3px solid #fff;
  transition: border-color .15s;
}
.lh-corner--tl { top: -3px; left: -3px;  border-right: none; border-bottom: none; border-top-left-radius: 6px; }
.lh-corner--tr { top: -3px; right: -3px; border-left: none;  border-bottom: none; border-top-right-radius: 6px; }
.lh-corner--bl { bottom: -3px; left: -3px;  border-right: none; border-top: none; border-bottom-left-radius: 6px; }
.lh-corner--br { bottom: -3px; right: -3px; border-left: none;  border-top: none; border-bottom-right-radius: 6px; }

/* 撮影品質 + 枠合致に応じて枠色 / マーカー色を変える */
.lh-guide-frame--ok {
  border-color: #4CAF50;
  box-shadow: 0 0 0 9999px rgba(0,0,0,.45), 0 0 16px rgba(76,175,80,.7);
}
.lh-guide-frame--ok .lh-corner { border-color: #4CAF50; }
.lh-guide-frame--warn { border-color: rgba(255,193,7,.8); }
.lh-guide-frame--warn .lh-corner { border-color: #FFC107; }
.lh-guide-frame--bad { border-color: rgba(244,67,54,.8); }
.lh-guide-frame--bad .lh-corner { border-color: #F44336; }
.lh-hint {
  position: absolute;
  bottom: 14px; left: 0; right: 0;
  text-align: center;
  color: #fff;
  font-size: 16px;
  font-weight: 500;
  line-height: 1.5;
  text-shadow: 0 1px 4px rgba(0,0,0,.9), 0 2px 10px rgba(0,0,0,.7);
  pointer-events: none;
  padding: 0 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Phase 7: 撮影品質メーター（カメラステージ上部に重ねる） */
.lh-quality {
  position: absolute;
  top: 8px; left: 8px; right: 8px;
  display: flex;
  gap: 8px;
  justify-content: center;
  pointer-events: none;
}
/* [hidden] 属性が CSS の display: flex に負けないように明示上書き */
.lh-quality[hidden] { display: none; }
.lh-quality-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 14px;
  border-radius: 16px;
  background: rgba(0,0,0,.55);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: .02em;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  transition: background .15s, color .15s;
}
/* P-6: ピル先頭に意味アイコンを追加 */
/* 個別ピルごとに content を上書きする。ドット表示は廃止 */
.lh-quality-pill::before {
  content: "◎";
  display: inline-block;
  font-size: 14px;
  line-height: 1;
}
#quality-focus::before  { content: "◎"; }
#quality-bright::before { content: "☀"; }
#quality-stable::before { content: "≈"; }
.lh-quality-pill[data-state="ok"] { background: rgba(76,175,80,.85); }
.lh-quality-pill[data-state="ok"]::before { background: #fff; }
.lh-quality-pill[data-state="warn"] { background: rgba(255,193,7,.85); color: #222; }
.lh-quality-pill[data-state="warn"]::before { background: #444; }
.lh-quality-pill[data-state="bad"] { background: rgba(244,67,54,.9); }
.lh-quality-pill[data-state="bad"]::before { background: #fff; }

/* ── コントロール ── */
/*
 * P-1: ボタン配置再設計
 * - .lh-controls を 2 行グリッドにする
 *   行 1: サブアクション群（カメラ起動 / カメラ切替 / 撮り直し）を均等分割
 *   行 2: シャッター専用（幅全体、56px、主役ボタン）
 * - setButtons(state) の 4 ステートで hidden を制御するため
 *   display:none (hidden 属性) で消えた分はグリッドが詰まる
 */
.lh-controls {
  margin-top: 10px;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  grid-template-rows: auto auto;
  gap: 8px;
}

/* サブアクション: カメラ起動 / カメラ切替 / 撮り直し */
.lh-btn {
  min-height: 44px;
  padding: 0 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #fff;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: opacity .15s;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* シャッターは独立行・全幅・大きめ */
.lh-btn--shutter {
  grid-column: 1 / -1;
  grid-row: 2;
  min-height: 56px;
  font-size: 16px;
  border-radius: 14px;
}

.lh-btn-primary {
  background: var(--green);
  color: #fff;
  border-color: var(--green);
}
.lh-btn:disabled {
  opacity: .45;
  cursor: not-allowed;
}
.lh-btn:not(:disabled):active {
  filter: brightness(.92);
}

/* hidden ボタンはグリッドから除去して折れを防ぐ */
.lh-controls .lh-btn[hidden] {
  display: none;
}

/* idle 時に btnStart を全幅表示するユーティリティクラス */
.lh-btn--full-row {
  grid-column: 1 / -1;
}

/* ── ステータス ── */
.lh-status {
  margin-top: 8px;
  font-size: 14px;
  color: #444;
  min-height: 1.4em;
  line-height: 1.6;
}
.lh-status.error { color: #c0392b; }

/* ── 候補リスト ── */
.lh-results {
  margin-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.lh-card {
  display: flex;
  gap: 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  align-items: stretch;
  transition: background .1s;
}
.lh-card-top {
  border-color: var(--green);
  box-shadow: 0 0 0 1px var(--green);
}
.lh-thumb {
  width: 110px;
  height: 154px;
  object-fit: cover;
  border-radius: 6px;
  background: #eee;
  flex-shrink: 0;
  cursor: zoom-in;
}
.lh-meta {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 4px;
}
.lh-name { font-size: 18px; font-weight: 700; line-height: 1.3; word-break: break-word; }
.lh-name-ja { font-size: 14px; color: #666; margin-top: 2px; }
.lh-tags { font-size: 13px; color: var(--muted); margin-top: 3px; line-height: 1.5; }
.lh-distance {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 4px;
  background: #eef;
  color: #335;
  font-size: 10px;
  margin-right: 6px;
  font-variant-numeric: tabular-nums;
  vertical-align: middle;
}
.lh-card-top .lh-distance {
  background: var(--green);
  color: #fff;
}

/* P-4: 距離バッジを意味化した新クラス群 */
/* 版確定（collector method, distance=0） */
.lh-badge-confirmed {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  background: var(--green);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  margin-right: 6px;
  vertical-align: middle;
}
/* 候補（collector method, distance>0） */
.lh-badge-candidate {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  background: #e0e0e0;
  color: #444;
  font-size: 12px;
  font-weight: 600;
  margin-right: 6px;
  vertical-align: middle;
}
/* 参考（phash method）*/
.lh-badge-fallback {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  background: #fff3e0;
  color: #e65100;
  font-size: 12px;
  font-weight: 600;
  margin-right: 6px;
  vertical-align: middle;
  border: 1px solid #ffcc80;
}
.lh-open-btn {
  display: inline-block;
  padding: 11px 14px;
  border-radius: 8px;
  background: var(--green);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  text-align: center;
  min-height: 44px;
  align-self: flex-start;
  margin-top: auto;
  border: none;
  cursor: pointer;
}
.lh-open-btn:hover { filter: brightness(.92); }
.lh-card:not(.lh-card-top) .lh-open-btn {
  background: #fff;
  color: var(--green);
  border: 1px solid var(--green);
}
.lh-empty {
  padding: 24px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

/* ── フッター注記 ── */
.lh-foot {
  margin-top: 16px;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.7;
}
.lh-foot a { color: inherit; text-decoration: underline; }

/* ── Phase 15: OCR 結果バッジ（OCR テキスト / 版確定通知） ── */
.lh-estimate-status {
  margin-top: 6px;
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 14px;
  line-height: 1.5;
  min-height: 1.4em;
  background: transparent;
  color: var(--muted);
  transition: background .2s, color .2s, border-color .2s;
}
.lh-estimate-status:empty {
  padding: 0;
  min-height: 0;
}
.lh-estimate--high {
  background: #e8f5e9;
  color: #2e7d32;
  border: 1px solid #a5d6a7;
}
.lh-estimate--medium {
  background: #fff8e1;
  color: #f57c00;
  border: 1px solid #ffe082;
}

/* ── PC 幅での余裕（副次的） ── */
@media (min-width: 520px) {
  .lh-main { padding: 16px 20px 48px; }
  .lh-stage { border-radius: 16px; }
}

/* タブレット幅（iPad mini 等）ではピル・ヒントをさらに大きく */
@media (min-width: 768px) {
  .lh-quality-pill {
    font-size: 18px;
    padding: 7px 16px;
    border-radius: 18px;
  }
  .lh-quality-pill::before {
    font-size: 16px;
  }
  .lh-hint {
    font-size: 18px;
  }
}
