@import url('./tokens.css');
@import url('./buttons.css');
@import url('./sliders.css');

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

/* ════ iOS Safari ズーム・選択・ドラッグ抑止（共通基盤） ════
   touch-action: manipulation でダブルタップズームを CSS レベルで抑止。
   canvas は touch-action:none に上書きされる場合があるが、
   manipulation をベースラインとして置いておくことで Safari の
   300ms click delay も除去できる。
   JS レベルの gesture / touchend 抑止は MobileGuard.inline.js が担う。
*/
html,
body,
#app,
canvas {
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  overscroll-behavior: none;
}
img,
canvas {
  -webkit-user-drag: none;
  user-drag: none;
}
:root {
  --char-h: 120px;

  /* ゲームごとのテーマカラー。GameTheme.inline.js が manifest.themeColor で上書きする。
     未適用時はブランド色にフォールバックする。 */
  --game-theme: var(--ui-color-brand);
}
html, body { height: 100%; overflow: hidden; }
body {
  font-family: 'Hiragino Maru Gothic ProN','Rounded Mplus 1c','Noto Sans JP',sans-serif;
  background: var(--ui-color-background);
  min-height: 100vh;
}

/* Issue #497: ゲーム選択では年齢・想定時間を制限のように見せない。
   metadata 自体は保護者向け情報など将来用途のため manifest に残す。 */
#screen-gameselect .gc-detail-meta {
  display: none;
}

/* Issue #1609: 派生ゲームを開いた後は「親ゲーム」より「遊び方の選択」を主役にする。
   GameVariation のruntime/gesture契約は変えず、既存DOMをCSSだけで再配分する。
   base.css は platform.css より先に読み込まれるため、#screen-gameselect を含む
   scoped selectorでこの画面だけのoverrideを明示する。 */
#screen-gameselect .gs-lane-variation-open .gc-card-variation-parent {
  --gc-variation-shift: clamp(-220px, -29vw, -90px);
  --gc-variation-scale: .68;
}
#screen-gameselect .gs-variation-panel {
  width: calc(60% - 10px);
  margin: 18px 10px 18px 40%;
  gap: 12px;
}
#screen-gameselect .gs-variation-panel::before {
  content: 'どれで あそぶ？';
  display: block;
  padding: 0 4px 2px;
  color: #765b42;
  font-size: clamp(.82rem, 3.4vw, 1rem);
  font-weight: 900;
  letter-spacing: .04em;
  line-height: 1.25;
}
#screen-gameselect .gs-variation-card {
  min-height: 96px;
  padding: 10px;
  gap: 9px;
  border-radius: 18px;
  position: relative;
  box-shadow: 0 4px 12px rgba(224,123,57,.22);
}
#screen-gameselect .gs-variation-thumb {
  flex-basis: clamp(64px, 18vw, 82px);
  border-radius: 13px;
}
#screen-gameselect .gs-variation-title {
  font-size: clamp(.9rem, 3.8vw, 1.1rem);
}
#screen-gameselect .gs-variation-card::after {
  content: '▶';
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--orange);
  color: #fff;
  font-size: .78rem;
  line-height: 1;
  padding-left: 2px;
  box-shadow: 0 3px 8px rgba(224,123,57,.3);
}
#screen-gameselect .gs-variation-card[data-variation-id='standard'] {
  border-width: 3px;
  background: linear-gradient(135deg, #fffaf1, #fff0d8);
  box-shadow: 0 7px 20px rgba(224,123,57,.3);
}
#screen-gameselect .gs-variation-card[data-variation-id='standard'] .gs-variation-title {
  font-size: clamp(.98rem, 4vw, 1.16rem);
}
#screen-gameselect .gs-variation-card:focus-visible {
  outline: 3px solid rgba(224,123,57,.55);
  outline-offset: 3px;
}
#screen-gameselect .gs-variation-card-locked::after {
  opacity: .22;
  filter: grayscale(1);
}

/* variationを持つ親カードは、一覧open後に「開始」ではなく「選択」の導線だと示す。
   既存のpointer handlerには触れず、表示だけを実際の挙動へ合わせる。 */
#screen-gameselect .gs-lane-variation-open .gc-card-variation-parent .gc-play-btn:not(.gc-play-btn-loading) .gc-play-icon {
  font-size: 0;
  padding-left: 0;
}
#screen-gameselect .gs-lane-variation-open .gc-card-variation-parent .gc-play-btn:not(.gc-play-btn-loading) .gc-play-icon::after {
  content: '☝';
  font-size: 1rem;
}
#screen-gameselect .gs-lane-variation-open .gc-card-variation-parent .gc-play-btn:not(.gc-play-btn-loading) > span:last-child {
  font-size: 0;
}
#screen-gameselect .gs-lane-variation-open .gc-card-variation-parent .gc-play-btn:not(.gc-play-btn-loading) > span:last-child::after {
  content: 'あそびかたを えらぶ';
  font-size: .82rem;
}

@media (max-width: 360px) {
  #screen-gameselect .gs-lane-variation-open .gc-card-variation-parent {
    --gc-variation-shift: clamp(-108px, -30vw, -82px);
    --gc-variation-scale: .60;
  }
  #screen-gameselect .gs-variation-panel {
    width: calc(62% - 8px);
    margin-left: 38%;
    margin-right: 8px;
  }
  #screen-gameselect .gs-variation-card {
    min-height: 90px;
    padding: 8px;
    gap: 7px;
  }
  #screen-gameselect .gs-variation-thumb {
    flex-basis: clamp(58px, 18vw, 66px);
  }
  #screen-gameselect .gs-variation-card::after {
    width: 28px;
    height: 28px;
    font-size: .7rem;
  }
}

/* 福笑いは固定幅の子要素を持つため、幅未指定だと flex の intrinsic size に
   引っ張られてスマホ時に #js-game-root より広がることがある。
   ルートだけを親幅へ固定し、absolute配置の右上UIも可視領域内に保つ。 */
.fw-app {
  width: 100%;
  min-width: 0;
}

/* ════ デバッグパネル ════ */
#debug-panel {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  height: 30vh;
  display: none;
  flex-direction: column;
  z-index: 9999;
  background: rgba(8,8,12,0.96);
  color: #f5f5f5;
  opacity: 1;
  font-family: 'Courier New', monospace;
  font-size: 11px;
  border-top: 2px solid #444;
  pointer-events: auto;
}
#debug-panel.visible { display: flex; }

/* タブヘッダー：高さ固定、スクロールに巻き込まれない */
#dbg-tabs {
  flex: 0 0 auto;
  height: 34px;
  display: flex;
  align-items: center;
  background: #050508;
  color: #f5f5f5;
  z-index: 2;
  border-bottom: 1px solid #222;
}
.dbg-tab {
  padding: 0 12px;
  height: 100%;
  display: flex;
  align-items: center;
  font-size: 10px;
  cursor: pointer;
  color: #666;
  border: none;
  background: none;
  font-family: inherit;
  border-bottom: 2px solid transparent;
  transition: color .12s;
  white-space: nowrap;
  flex-shrink: 0;
}
.dbg-tab.active { color: #7fffb0; border-bottom-color: #7fffb0; }
.dbg-badge {
  display: inline-block;
  background: #e74c3c; color: #fff;
  border-radius: 8px; font-size: 8px;
  padding: 0 4px; margin-left: 3px;
  min-width: 14px; text-align: center;
  visibility: hidden;
}
.dbg-badge.on { visibility: visible; }
#dbg-export {
  padding: 0 8px; height: 100%;
  display: flex; align-items: center;
  font-size: 10px; cursor: pointer;
  color: #6af; border: none; background: none;
  font-family: inherit; flex-shrink: 0;
}
#dbg-export:hover { color: #9cf; }
#dbg-clear {
  margin-left: auto;
  padding: 0 10px; height: 100%;
  display: flex; align-items: center;
  font-size: 10px; cursor: pointer;
  color: #666; border: none; background: none;
  font-family: inherit; flex-shrink: 0;
}
#dbg-clear:hover { color: #aaa; }

/* ログ本文ペイン：残り高さを全部使ってスクロール */
.dbg-pane {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  display: none;
  flex-direction: column;
  overscroll-behavior: contain;
  opacity: 1;
  color: #f5f5f5;
}
.dbg-pane.active { display: flex; }

/* ログ行・文字色：!important で他CSSに負けない */
#debug-panel * { opacity: 1; }
.dbg-row,
.dbg-row * {
  color: #f5f5f5 !important;
  opacity: 1 !important;
}
.dbg-row {
  padding: 2px 8px;
  border-bottom: 1px solid rgba(255,255,255,.04);
  word-break: break-all;
  line-height: 1.5;
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}
.dbg-row .dt {
  flex-shrink: 0;
  font-size: 9px;
  padding-top: 2px;
  min-width: 90px;
  color: #999 !important;
}
.dbg-row .dm { flex: 1; }

/* 種別ごとの色分け（!important で確実に適用） */
.dbg-row.log   .dm { color: #d0d0d0 !important; }
.dbg-row.info  .dm { color: #7ecfff !important; }
.dbg-row.warn  .dm { color: #ffd080 !important; }
.dbg-row.error .dm { color: #ff8080 !important; }
.dbg-row.error      { background: rgba(255,0,0,.08); }
.dbg-row.gl-event   .dm { color: #7fffb0 !important; }
.dbg-row.gl-input   .dm { color: #87cefa !important; }
.dbg-row.gl-comment .dm { color: #ffdf80 !important; }
.dbg-row.gl-system  .dm { color: #aaa    !important; }
.dbg-row.sc         .dm { color: #c792ea !important; }
#debug-toggle {
  position: fixed;
  bottom: 8px;
  right: 8px;
  z-index: 10000;
  background: rgba(10,10,18,.9);
  color: #7fffb0;
  border: 1.5px solid #444;
  border-radius: 7px;
  padding: 4px 10px;
  font-size: 10px;
  cursor: pointer;
  font-family: 'Courier New',monospace;
}
/* タイトル画面では右下の企業ロゴと競合しないよう、LOGだけ少し上へ逃がす。 */
body.screen-title #debug-toggle {
  bottom: calc(max(8px, env(safe-area-inset-bottom)) + 64px);
}
.err-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #e74c3c;
  margin-right: 3px;
  visibility: hidden;
  animation: errBlink .8s ease-in-out infinite;
}
.err-dot.on { visibility: visible; }
@keyframes errBlink { 0%,100% { opacity:1; } 50% { opacity:.15; } }

/* ══════════════════════════════════════════
   アニメデバッグペイン（#pane-anim）
   CommentatorAnimatorDebug.inline.js が使う
══════════════════════════════════════════ */
#pane-anim {
  padding: 10px 12px;
  overflow-y: auto;
  gap: 10px;
  flex-direction: column;
}
.dbg-anim-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.dbg-anim-label {
  font-size: 10px;
  color: #aaa;
  min-width: 80px;
  flex-shrink: 0;
}
.dbg-anim-btn {
  padding: 4px 9px;
  font-size: 10px;
  border-radius: 5px;
  border: 1px solid #555;
  background: #1a1a28;
  color: #ccc;
  cursor: pointer;
  font-family: inherit;
  transition: background .1s, color .1s, border-color .1s;
  flex-shrink: 0;
}
.dbg-anim-btn:hover { background: #2a2a40; color: #fff; border-color: #888; }
.dbg-anim-btn.active {
  background: #1e3d2a;
  color: #7fffb0;
  border-color: #7fffb0;
}
#dbg-chobo-preview {
  position: relative;
  width: 64px;
  height: 72px;
  background: rgba(255,255,255,.04);
  border: 1px dashed #444;
  border-radius: 6px;
  overflow: visible;
  flex-shrink: 0;
}
#dbg-chobo-preview .char-img-wrap {
  width: 100%;
  height: 100%;
}
.dbg-anim-divider {
  border: none;
  border-top: 1px solid #222;
  margin: 4px 0;
}
