/* ============================================================
   SF6 ランク分布チェッカー / 共通スタイル
   ============================================================ */
:root {
  --bg-page:       #0f1419;
  --bg-card:       #1a2332;
  --bg-card-2:     #243447;
  --bg-input:      #2c3e50;
  --border:        #3a4a5e;
  --border-strong: #5a6c80;

  --text-main:     #e8eef5;
  --text-sub:      #9aa8b8;
  --text-muted:    #6b7785;

  --accent:        #ff6b35;
  --accent-2:      #ffb700;
  --accent-3:      #c41e3a;
  --legend:        #ff3860;
  --master:        #b266ff;
  --diamond:       #4dd0e1;
  --platinum:      #66bb6a;
  --gold:          #fdd835;
  --silver:        #bdbdbd;
  --bronze:        #a1887f;
  --iron:          #78909c;
  --rookie:        #90a4ae;

  --highlight:     #ffeb3b;
  --error:         #ef5350;
  --success:       #66bb6a;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  background: var(--bg-page);
  color: var(--text-main);
  font-family: "Yu Gothic UI", "Hiragino Sans", "Meiryo", sans-serif;
  font-size: 16px;
  line-height: 1.5;
}
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-2); }

/* ヘッダ */
.header {
  background: linear-gradient(180deg, #0a0f14 0%, var(--bg-card) 100%);
  border-bottom: 2px solid var(--accent);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}
.header-main {
  display: flex;
  align-items: center;
  padding: 12px 24px;
  gap: 24px;
}
.logo {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: 1px;
  color: var(--accent);
  text-shadow: 0 0 8px rgba(255, 107, 53, 0.3);
}
.logo .sub {
  font-size: 13px;
  color: var(--text-sub);
  font-weight: 400;
  letter-spacing: 0;
  margin-left: 6px;
}
.nav { display: flex; gap: 4px; flex: 1; }
.nav-link {
  padding: 10px 18px;
  color: var(--text-sub);
  font-weight: 600;
  border-radius: 4px 4px 0 0;
  transition: all 0.15s;
}
.nav-link:hover { color: var(--text-main); background: rgba(255,255,255,0.04); }
.nav-link.active {
  color: var(--accent);
  background: var(--bg-card);
  box-shadow: inset 0 -3px 0 var(--accent);
}
.search-box { position: relative; }
.search-box input {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-main);
  padding: 8px 12px 8px 32px;
  width: 220px;
  border-radius: 4px;
  font-size: 15px;
}
.search-box::before {
  content: "🔍";
  position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
  opacity: 0.6;
}
.header-info {
  display: flex;
  align-items: center;
  padding: 8px 24px;
  background: rgba(0,0,0,0.3);
  border-top: 1px solid var(--border);
  font-size: 14px;
  gap: 24px;
  flex-wrap: wrap;
}
.info-item { display: flex; align-items: center; gap: 8px; }
.info-label {
  color: var(--text-sub);
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.info-value { color: var(--text-main); font-weight: 700; }
.info-value.legend {
  color: var(--legend);
  text-shadow: 0 0 4px rgba(255, 56, 96, 0.4);
}
.info-value.accent { color: var(--accent); }
.spacer { flex: 1; }
.updated-at { color: var(--text-muted); font-size: 13px; }

/* コンテナ */
.container { max-width: 1400px; margin: 0 auto; padding: 24px; }
.page-title {
  font-size: 22px;
  font-weight: 700;
  margin: 0 0 16px;
  display: flex; align-items: center; gap: 12px;
}
.page-title::before {
  content: "";
  width: 4px; height: 24px;
  background: var(--accent);
  border-radius: 2px;
}

/* タイトル + 更新日付バッジ (ボディのページタイトル横) */
.title-bar {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 8px 12px;
  margin: 0 0 16px;
}
.update-chip {
  font-size: 12px;
  color: var(--text-sub);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 3px 9px;
  white-space: nowrap;
}

/* カード */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 20px;
  margin-bottom: 20px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}
.card-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--accent);
  margin: 0 0 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
  text-transform: uppercase;
  letter-spacing: 1px;
}

/* 絞込パネル */
.filter-panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 16px 20px;
  margin-bottom: 20px;
}
.filter-row {
  display: flex; gap: 20px; flex-wrap: wrap; align-items: center;
  margin-bottom: 12px;
}
.filter-row:last-child { margin-bottom: 0; }
.filter-item { display: flex; align-items: center; gap: 8px; }
.filter-label {
  color: var(--text-sub);
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
}
select, input[type="text"], input[type="number"] {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-main);
  padding: 6px 10px;
  border-radius: 4px;
  font-size: 15px;
}
select:focus, input:focus { outline: none; border-color: var(--accent); }
input[type="number"] { width: 90px; }
.radio-group, .checkbox-group { display: inline-flex; gap: 12px; align-items: center; }
.radio-group label, .checkbox-group label {
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 15px;
}
input[type="radio"], input[type="checkbox"] { accent-color: var(--accent); }
button.primary {
  background: linear-gradient(180deg, var(--accent) 0%, #d4541f 100%);
  border: none;
  color: white;
  padding: 8px 20px;
  border-radius: 4px;
  font-weight: 700;
  cursor: pointer;
  font-size: 15px;
  letter-spacing: 0.5px;
}
button.primary:hover { filter: brightness(1.1); }
button.primary:active { transform: scale(0.97); }
button.secondary {
  background: var(--bg-input);
  border: 1px solid var(--border-strong);
  color: var(--text-main);
  padding: 8px 16px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 15px;
}

/* タブ */
.tabs {
  display: flex;
  border-bottom: 2px solid var(--border);
  margin-bottom: 20px;
}
.tab {
  padding: 12px 24px;
  cursor: pointer;
  color: var(--text-sub);
  font-weight: 600;
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
}
.tab:hover { color: var(--text-main); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.subtabs {
  display: flex; gap: 6px; margin-bottom: 16px;
  background: var(--bg-card-2);
  padding: 4px;
  border-radius: 6px;
  width: fit-content;
}
.subtab {
  padding: 6px 14px;
  cursor: pointer;
  color: var(--text-sub);
  border-radius: 4px;
  font-size: 14px;
  font-weight: 600;
}
.subtab:hover { color: var(--text-main); }
.subtab.active { background: var(--accent); color: white; }

/* チップ */
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.chip {
  background: var(--bg-card-2);
  border: 1px solid var(--border);
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 13px;
  color: var(--text-sub);
  display: inline-flex; align-items: center; gap: 6px;
}
.chip .remove { cursor: pointer; color: var(--text-muted); }
.chip .remove:hover { color: var(--error); }

/* グラフ */
.chart-wrap { position: relative; height: 360px; margin: 12px 0; }
.chart-wrap.tall { height: 500px; }
.chart-wrap.xtall { height: 820px; }
.chart-wrap.short { height: 240px; }
.grid-2col { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-3col { display: grid; grid-template-columns: 2fr 1fr; gap: 20px; }
@media (max-width: 900px) {
  .grid-2col, .grid-3col { grid-template-columns: 1fr; }
}

/* テーブル */
table.data { width: 100%; border-collapse: collapse; font-size: 15px; }
table.data th {
  background: var(--bg-card-2);
  color: var(--text-sub);
  font-weight: 600;
  padding: 8px 12px;
  text-align: left;
  border-bottom: 2px solid var(--border-strong);
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
table.data td { padding: 8px 12px; border-bottom: 1px solid var(--border); }
table.data tr:hover td { background: rgba(255,255,255,0.02); }
table.data tr.highlight td { background: rgba(255, 56, 96, 0.08); }
table.data tr.highlight td:first-child { border-left: 3px solid var(--legend); }
/* 複数レジェンド達成者 (複数キャラでレジェンド到達) を金系の色で差別化 */
table.data tr.multi-legend td { background: rgba(255, 202, 40, 0.09); }
table.data tr.multi-legend td:first-child { border-left: 3px solid #ffca28; }
table.data .num { text-align: right; font-variant-numeric: tabular-nums; }
table.data .center { text-align: center; }
table.data .player-link { color: var(--text-main); font-weight: 600; }
table.data .player-link:hover { color: var(--accent); }

/* バッジ */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 700;
}
.badge.legend { background: var(--legend); color: white; }
.badge.master { background: var(--master); color: white; }
.badge.multi { background: linear-gradient(90deg, var(--legend), var(--accent-2)); color: white; }
.badge.classic { background: #4a6fa5; color: white; }
.badge.modern { background: #6b8e23; color: white; }
.badge.dynamic { background: #b8860b; color: white; }
.badge.steam { background: #1b2838; color: #66c0f4; border: 1px solid #66c0f4; }
.badge.ps { background: #003791; color: white; }
.badge.xbox { background: #107c10; color: white; }
.badge.rank-rookie   { background: var(--rookie); color: #000; }
.badge.rank-iron     { background: var(--iron); color: #000; }
.badge.rank-bronze   { background: var(--bronze); color: #000; }
.badge.rank-silver   { background: var(--silver); color: #000; }
.badge.rank-gold     { background: var(--gold); color: #000; }
.badge.rank-platinum { background: var(--platinum); color: #000; }
.badge.rank-diamond  { background: var(--diamond); color: #000; }
.badge.rank-master   { background: var(--master); color: white; }

/* キャラアイコン */
.char-icon {
  display: inline-block;
  width: 24px; height: 24px;
  border-radius: 50%;
  background: var(--bg-input);
  text-align: center;
  line-height: 24px;
  font-size: 13px;
  font-weight: 700;
  vertical-align: middle;
  margin-right: 6px;
  border: 1px solid var(--border);
}
.char-name { vertical-align: middle; display: inline-flex; align-items: center; }

/* キャラ色ドット (レジェンド画面のキャラ表示) */
.char-dot {
  display: inline-block;
  width: 12px; height: 12px;
  border-radius: 50%;
  margin-right: 8px;
  border: 1px solid var(--border);
  flex: 0 0 auto;
}

/* サマリー統計 (トップ・レジェンド画面) */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin: 16px 0 8px;
}
.stat-grid-2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 700px) {
  .stat-grid, .stat-grid-2 { grid-template-columns: 1fr; }
}
.stat-box {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 16px 18px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.stat-num { font-size: 26px; font-weight: 700; }
.stat-cap { font-size: 12px; color: var(--text-sub); }

/* ページャ (レジェンドランキング) */
.pager {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 16px;
  justify-content: center;
}
.pager-link {
  display: inline-block;
  min-width: 34px;
  padding: 6px 10px;
  text-align: center;
  font-size: 13px;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-main);
  text-decoration: none;
}
.pager-link:hover { border-color: var(--accent); color: var(--accent); }
.pager-link.current {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 700;
}
.pager-link.disabled {
  color: var(--text-sub);
  opacity: 0.4;
  pointer-events: none;
}

/* 上位％結果 */
.percentile-result {
  text-align: center;
  padding: 40px 20px;
  background: linear-gradient(135deg, var(--bg-card-2) 0%, var(--bg-card) 100%);
  border-radius: 8px;
  border: 2px solid var(--accent);
}
.percentile-result .label { color: var(--text-sub); font-size: 16px; margin-bottom: 12px; }
.percentile-result .value {
  font-size: 48px;
  font-weight: 800;
  color: var(--accent);
  text-shadow: 0 0 12px rgba(255, 107, 53, 0.4);
}
.percentile-result .value .pct { font-size: 28px; margin-left: 4px; }
.percentile-result .note { margin-top: 12px; color: var(--text-sub); font-size: 15px; }

/* プレイヤーヘッダ */
.player-header {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 20px 24px;
  background: linear-gradient(135deg, var(--bg-card) 0%, var(--bg-card-2) 100%);
  border-radius: 8px;
  border-left: 4px solid var(--accent);
  margin-bottom: 20px;
}
.player-avatar {
  width: 80px; height: 80px;
  border-radius: 50%;
  background: var(--bg-input);
  text-align: center;
  line-height: 80px;
  font-size: 36px;
  font-weight: 700;
  color: var(--accent);
  border: 3px solid var(--accent);
}
.player-info-block .name { font-size: 24px; font-weight: 700; margin: 0; }
.player-info-block .id { color: var(--text-sub); font-size: 15px; font-family: monospace; }
.player-info-block .meta {
  margin-top: 8px;
  display: flex; gap: 16px; flex-wrap: wrap;
  font-size: 14px;
  color: var(--text-sub);
}

/* フッタ */
.footer {
  background: #0a0f14;
  border-top: 1px solid var(--border);
  padding: 24px;
  margin-top: 40px;
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
}
.footer .links { display: flex; justify-content: center; gap: 24px; margin-bottom: 12px; }
.footer .links a { color: var(--text-sub); }
.footer .disclaimer { margin-top: 8px; font-size: 13px; color: var(--text-muted); }

/* ユーティリティ */
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.mt-0 { margin-top: 0 !important; }
.mb-0 { margin-bottom: 0 !important; }
.text-sub { color: var(--text-sub); }
.text-muted { color: var(--text-muted); }
.text-accent { color: var(--accent); }
.text-legend { color: var(--legend); }
.fw-700 { font-weight: 700; }
.fs-11 { font-size: 13px; }
.fs-12 { font-size: 14px; }
.hidden { display: none !important; }

/* ランク分布: 絞込の適用範囲に関する注記 (表の下に配置) */
.filter-note {
  margin: 12px 0;
  padding: 8px 12px;
  background: var(--surface-2, #243447);
  border-left: 3px solid var(--accent, #ff6b35);
  border-radius: 4px;
  line-height: 1.6;
}

/* マスター帯 MR100単位: 棒グラフと数値表を横並び、行の縦位置を揃える */
.mr-table { width: 100%; border-collapse: collapse; font-size: 15px; }
.mr-table thead th {
  height: 36px;
  padding: 0 12px;
  background: var(--bg-card-2);
  color: var(--text-sub);
  font-size: 13px;
  text-align: left;
  border-bottom: 2px solid var(--border-strong);
}
.mr-table thead th.num { text-align: right; }
.mr-table tbody td {
  height: 30px;
  padding: 0 12px;
  border: none;
}
.mr-table tbody tr:nth-child(even) td { background: rgba(255,255,255,0.03); }
.mr-table .num { text-align: right; font-variant-numeric: tabular-nums; }
/* 棒グラフ側: 上部X軸(目盛・補助線 約36px) + 16行ぶん(16×30px)の高さ */
.mr-chart-wrap { position: relative; height: 516px; }

/* ============================================================
   広告枠 (ad_slot.jsp で生成)
   ・slot種別: header / inline / footer / sticky-mobile
   ・開発時は ad-placeholder で枠位置を可視化
   ・本番では <div class="ad-placeholder">…</div> を広告タグに差替
   ============================================================ */
.ad-slot {
  margin: 16px 0;
  text-align: center;
}
.ad-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: repeating-linear-gradient(
    45deg,
    rgba(255,255,255,0.025),
    rgba(255,255,255,0.025) 8px,
    rgba(255,255,255,0.05)  8px,
    rgba(255,255,255,0.05)  16px
  );
  border: 1px dashed var(--border-strong);
  border-radius: 4px;
  color: var(--text-muted);
  font-size: 13px;
  padding: 12px;
  min-height: 90px;
  margin: 0 auto;
}
.ad-placeholder .ad-label    { font-weight: 700; }
.ad-placeholder .ad-slot-name { font-size: 11px; color: var(--text-muted); font-family: monospace; }

/* ヘッダ直下バナー: 728x90 相当 */
.ad-slot-header  .ad-placeholder { min-height: 90px;  max-width: 970px; }
/* インライン矩形: 336x280 相当 */
.ad-slot-inline  .ad-placeholder { min-height: 250px; max-width: 336px; }
/* フッタ直前バナー: 728x90 相当 */
.ad-slot-footer  .ad-placeholder { min-height: 90px;  max-width: 970px; }

/* モバイル下部スティッキー
   ★ 公開時は表示OFF。本番広告投入時に下のmedia query内の `display:none` 行を削除して有効化。
   JSP側 (footer.jsp) の <jsp:include slot="sticky-mobile"> は残置済 */
.ad-slot-sticky-mobile { display: none; }

/* ----- PCサイドバー広告 (左右余白の縦長スカイスクレイパー) -----
   設計方針:
   ・常に <main class="container"> (max-width:1400px) の左右「外側」に固定配置
   ・スクロールバー(~17px) を吸収できる安全マージンを確保 (32px以上)
   ・100vw ではなく 50vw 基準で「中央から外側へ離す」計算式を使用
       left  = 50vw - half_container - sidebar_width - gap
       right = 50vw - half_container - sidebar_width - gap
   ・viewport が狭すぎる時は display:none で完全に隠す (オーバーラップ完全防止)
   ・縦が短いブラウザでは見切れるので max-height:700px 未満も非表示
*/
/* ★ 公開時OFF: 本番広告タグ投入時に下の media query 内の `display: none` を削除
   (または `display: block` のコメントを解除) するとサイドバー表示が有効化される。
   JSP側 (footer.jsp) の <jsp:include slot="sidebar-left/right"> は残置済 */
.ad-slot-sidebar-left,
.ad-slot-sidebar-right {
  display: none; /* デフォルト非表示。下の media query で広い画面のみ表示 */
}

/* ≥ 1820px: 160×600 (Wide Skyscraper)
   必要幅 = container(1400) + sidebar(160×2) + gap(32×2) + scrollbar余裕(16) = 1808px → 1820pxで安全 */
@media (min-width: 1820px) and (min-height: 700px) {
  .ad-slot-sidebar-left,
  .ad-slot-sidebar-right {
    display: none;       /* ←本番有効化時はこの行を削除 */
    /*
    display: block;
    */
    position: fixed;
    top: 100px;          /* sticky headerの下から開始 (header高 ~95px) */
    width: 160px;
    height: 600px;
    margin: 0;
    z-index: 50;         /* header(100)より下・本文より上 */
  }
  /* 50vw - half_container(700) - sidebar(160) - gap(32) = 50vw - 892 */
  .ad-slot-sidebar-left  { left:  calc(50vw - 892px); }
  .ad-slot-sidebar-right { right: calc(50vw - 892px); }
  .ad-slot-sidebar-left  .ad-placeholder,
  .ad-slot-sidebar-right .ad-placeholder {
    width: 160px;
    height: 600px;
    min-height: 600px;
    max-width: none;
    margin: 0;
  }
}

/* ≥ 2160px: 300×600 (Half-Page) — ユーザ要望のメインサイズ
   必要幅 = container(1400) + sidebar(300×2) + gap(40×2) + scrollbar(16) = 2096px → 2160px で安全 */
@media (min-width: 2160px) and (min-height: 700px) {
  .ad-slot-sidebar-left,
  .ad-slot-sidebar-right { width: 300px; }
  /* 50vw - 700 - 300 - 40 = 50vw - 1040 */
  .ad-slot-sidebar-left  { left:  calc(50vw - 1040px); }
  .ad-slot-sidebar-right { right: calc(50vw - 1040px); }
  .ad-slot-sidebar-left  .ad-placeholder,
  .ad-slot-sidebar-right .ad-placeholder { width: 300px; }
}

/* モバイル時の広告サイズ調整 + スティッキー表示 */
@media (max-width: 640px) {
  .ad-slot-header .ad-placeholder { min-height: 50px; max-width: 100%; font-size: 12px; }
  .ad-slot-footer .ad-placeholder { min-height: 50px; max-width: 100%; font-size: 12px; }
  .ad-slot-inline .ad-placeholder { min-height: 250px; }

  /* 画面下部固定の320x50相当
     ★ 公開時OFF: 下の `display: none` を削除 (または `display: block` に戻す)
     と sticky 表示が有効化される。本番広告タグ投入時にコメントアウト解除。 */
  .ad-slot-sticky-mobile {
    display: none;                /* ←本番有効化時はこの行を削除 */
    /*
    display: block;
    */
    position: fixed;
    bottom: 0; left: 0; right: 0;
    background: var(--bg-card);
    border-top: 1px solid var(--border);
    padding: 4px 8px;
    margin: 0;
    z-index: 90;
    box-shadow: 0 -2px 8px rgba(0,0,0,0.4);
  }
  .ad-slot-sticky-mobile .ad-placeholder {
    min-height: 50px;
    margin: 0;
    border-style: dashed;
  }
  /* スティッキー広告の高さぶん本文下に余白を確保 (フッタが見えるように)
     ★ 公開時は不要。本番有効化時に有効化 */
  /*
  body { padding-bottom: 64px; }
  */
}

/* ============================================================
   テーブル横スクロールラッパ (モバイル対応の基盤)
   ・JSP側で `<div class="table-scroll"><table>...</table></div>` のように包む
   ・スマホで画面に収まらないテーブルが横スクロールで全カラム表示可能になる
   ============================================================ */
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0 -4px; /* カード内padding を少しはみ出してスクロール余地を確保 */
}
.table-scroll > table { min-width: 100%; }

/* ============================================================
   ヘッダ用 hamburger ボタン (モバイル時のみ表示)
   ============================================================ */
.hamburger {
  display: none;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--text-main);
  font-size: 20px;
  line-height: 1;
  width: 40px;
  height: 40px;
  border-radius: 4px;
  cursor: pointer;
  padding: 0;
  margin-left: auto;     /* logoから右側へ押出し (検索ボックスより左) */
  flex-shrink: 0;
}
.hamburger-icon { display: inline-block; line-height: 1; pointer-events: none; }
.hamburger:hover { background: rgba(255,255,255,0.05); }
.hamburger:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ============================================================
   モバイル: タブレット (≤ 900px) は既存ルールで対応済 (.grid-3col → 1col)
   以下は追加分: ≤ 640px (大型スマホ) / ≤ 420px (一般スマホ)
   ============================================================ */

/* ========== ≤ 640px: 大型スマホ (横向きスマホ含む) ========== */
@media (max-width: 640px) {
  html, body { font-size: 15px; }

  /* ----- ヘッダ (高さはデスクトップとほぼ同じに保つ) ----- */
  /* .nav をドロップダウンとして絶対配置するため position: relative */
  .header-main {
    position: relative;
    padding: 10px 12px;
    gap: 8px;
    flex-wrap: nowrap; /* 折返しさせない (1行のまま、高さ不変) */
  }
  .logo { font-size: 18px; flex-shrink: 0; }
  .logo .sub { display: none; } /* サブタイトル省略でスペース確保 */

  /* hamburger ボタン表示 + 配置順: logo → search → hamburger (右端) */
  .hamburger { display: inline-flex; flex-shrink: 0; order: 99; margin-left: 0; }
  .search-box { margin-left: auto; order: 50; }

  /* ナビをドロップダウン化: hamburger 押下時に絶対配置で表示 */
  .nav {
    position: absolute;
    top: 100%;          /* ヘッダ直下から下に展開 */
    right: 10px;
    margin-top: 4px;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    min-width: 200px;
    max-width: calc(100vw - 24px);
    background: var(--bg-card);
    border: 1px solid var(--border-strong);
    border-radius: 6px;
    padding: 6px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.6);
    z-index: 200;
    display: none;      /* 通常は非表示 */
  }
  .nav.open { display: flex; }
  .nav-link {
    width: 100%;
    text-align: left;
    padding: 10px 14px;
    border-radius: 4px;
    background: transparent;
    white-space: nowrap;
  }
  .nav-link:hover { background: rgba(255,255,255,0.05); }
  .nav-link.active {
    background: var(--bg-card-2);
    box-shadow: inset 3px 0 0 var(--accent);
  }

  /* 検索ボックス: 小さくして残す (非表示にしない) */
  .search-box { flex-shrink: 1; min-width: 0; }
  .search-box input {
    width: 100px;
    padding: 6px 8px 6px 26px;
    font-size: 13px;
  }
  .search-box::before { left: 6px; font-size: 12px; }

  /* ヘッダ下部情報 (レジェンド/アクト) */
  .header-info {
    padding: 8px 16px;
    gap: 6px 12px;
    font-size: 13px;
  }
  .info-label { font-size: 11px; }
  .info-value { font-size: 13px; }

  /* ----- コンテナ ----- */
  .container { padding: 16px; }

  /* ----- ページタイトル ----- */
  .page-title { font-size: 18px; }
  .page-title::before { height: 20px; }

  /* ----- タイトルバー (タイトル + 更新日付チップ) ----- */
  .title-bar { gap: 6px 8px; }
  .update-chip { font-size: 11px; padding: 2px 7px; }

  /* ----- 絞込パネル (フィルタフォーム) ----- */
  .filter-panel { padding: 12px 14px; }
  .filter-row {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }
  .filter-item {
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
    width: 100%;
  }
  .filter-label { white-space: normal; }
  .filter-panel select,
  .filter-panel input[type="text"],
  .filter-panel input[type="number"] {
    width: 100%;
    font-size: 16px; /* iOSでautoズーム回避は16px以上 */
  }
  /* spacer (横並び時の押出し) は縦積みでは不要 */
  .filter-row .spacer { display: none; }
  .filter-panel button.primary,
  .filter-panel a.secondary,
  .filter-panel button.secondary {
    width: 100%;
    padding: 12px 16px;
    text-align: center;
  }

  /* ----- サブタブ (横スクロール化) ----- */
  .subtabs {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
    flex-wrap: nowrap;
  }
  .subtab { flex-shrink: 0; font-size: 13px; padding: 6px 12px; }

  /* ----- カード ----- */
  .card { padding: 14px; margin-bottom: 14px; }
  .card-title { font-size: 14px; }

  /* ----- グラフ (高さ縮小) ----- */
  .chart-wrap { height: 280px; }
  .chart-wrap.tall { height: 380px; }
  .chart-wrap.xtall { height: 520px; }
  .chart-wrap.short { height: 200px; }
  /* MR100単位の棒グラフ: 数値表と縦に並ぶのでそのまま */
  .mr-chart-wrap { height: 460px; }

  /* ----- テーブル ----- */
  table.data { font-size: 14px; }
  table.data th, table.data td { padding: 6px 8px; }
  .mr-table { font-size: 13px; }
  .mr-table thead th { height: 32px; padding: 0 8px; font-size: 12px; }
  .mr-table tbody td { height: 28px; padding: 0 8px; }

  /* ----- チップ ----- */
  .chip { font-size: 12px; padding: 3px 8px; }

  /* ----- ページャ (レジェンド) ----- */
  .pager-link { min-width: 30px; padding: 5px 8px; font-size: 12px; }

  /* ----- 上位%結果カード ----- */
  .percentile-result { padding: 24px 16px; }
  .percentile-result .label { font-size: 14px; }
  .percentile-result .value { font-size: 36px; }
  .percentile-result .value .pct { font-size: 22px; }
  .percentile-result .note { font-size: 13px; }

  /* ----- プレイヤーヘッダ (S004) ----- */
  .player-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
    padding: 16px;
  }
  .player-avatar {
    width: 60px; height: 60px;
    line-height: 60px;
    font-size: 28px;
  }
  .player-info-block .name { font-size: 20px; }
  .player-info-block .id { font-size: 13px; }
  .player-info-block .meta { font-size: 13px; gap: 8px 14px; }

  /* ----- フッタ ----- */
  .footer { padding: 16px; font-size: 13px; }
  .footer .links { gap: 16px; flex-wrap: wrap; }
}

/* ========== ≤ 420px: 一般的なスマホ (縦持ち) ========== */
@media (max-width: 420px) {
  html, body { font-size: 14px; }

  .header-main { padding: 8px 10px; gap: 6px; }
  .logo { font-size: 16px; letter-spacing: 0.5px; }
  /* ≤ 420px: 検索欄をさらに小さく (アイコン+わずかなplaceholder幅のみ) */
  .search-box input { width: 80px; font-size: 12px; }
  .hamburger { width: 36px; height: 36px; font-size: 18px; }
  .header-info { padding: 6px 10px; gap: 4px 10px; }
  .info-label { font-size: 10px; }

  .container { padding: 12px; }
  .page-title { font-size: 16px; }
  .title-bar { gap: 4px 6px; }
  .update-chip { font-size: 10px; padding: 2px 6px; }

  .filter-panel { padding: 10px 12px; }
  .card { padding: 12px; margin-bottom: 12px; }
  .card-title { font-size: 13px; padding-bottom: 8px; margin-bottom: 12px; }

  .chart-wrap { height: 240px; }
  .chart-wrap.tall { height: 320px; }
  .chart-wrap.xtall { height: 440px; }
  .mr-chart-wrap { height: 420px; }

  table.data { font-size: 13px; }
  table.data th, table.data td { padding: 5px 6px; }
  table.data th { font-size: 11px; letter-spacing: 0.3px; }
  .mr-table { font-size: 12px; }
  .mr-table thead th { padding: 0 6px; font-size: 11px; }
  .mr-table tbody td { padding: 0 6px; }

  .percentile-result { padding: 20px 12px; }
  .percentile-result .value { font-size: 30px; }
  .percentile-result .value .pct { font-size: 18px; }
  .percentile-result .label { font-size: 13px; }

  .player-avatar { width: 50px; height: 50px; line-height: 50px; font-size: 24px; }
  .player-info-block .name { font-size: 18px; }
}
