/* ============================================================
   Part 1 — 基盤：トークン・リセット・レイアウト・ヘッダー
   ============================================================ */

/* ── CSS トークン ── */
:root {
  --bg:          #f1f5f9;
  --surface:     #ffffff;
  --surface-2:   #f8fafc;
  --border:      #e2e8f0;
  --border-2:    #cbd5e1;
  --ink:         #0f172a;
  --ink-2:       #475569;
  --ink-3:       #94a3b8;
  --accent:      #3b82f6;
  --accent-bg:   #eff6ff;
  --accent-dark: #1d4ed8;
  --green:       #059669;
  --green-bg:    #ecfdf5;
  --gold:        #d97706;
  --gold-bg:     #fffbeb;
  --red:         #dc2626;
  --shadow-xs:   0 1px 2px rgba(0,0,0,.05);
  --shadow-sm:   0 1px 3px rgba(0,0,0,.07), 0 1px 2px rgba(0,0,0,.04);
  --shadow:      0 4px 6px -1px rgba(0,0,0,.07), 0 2px 4px -2px rgba(0,0,0,.05);
  --shadow-lg:   0 10px 15px -3px rgba(0,0,0,.08), 0 4px 6px -4px rgba(0,0,0,.05);
  --radius-sm:   6px;
  --radius:      10px;
  --radius-lg:   14px;
  --radius-pill: 999px;
  --sidebar-w:   56px;
  --topbar-h:    104px;
}
body.sidebar-open { --sidebar-w: 220px; }

/* ── リセット ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans JP", sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
img { display: block; max-width: 100%; }
button { font: inherit; cursor: pointer; }
select, input { font: inherit; }
a { color: inherit; text-decoration: none; }

/* ── カード共通 ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
  padding: 14px;
}
h2 {
  font-size: 14px;
  font-weight: 700;
  color: var(--ink-2);
  letter-spacing: .02em;
  margin-bottom: 10px;
}
.meta { color: var(--ink-3); font-size: 12px; }

/* ── モードピル ── */
.mode-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 12px;
  border: 1px solid var(--border-2);
  border-radius: var(--radius-pill);
  background: var(--surface);
  color: var(--ink-2);
  font-size: 12px;
  font-weight: 500;
  transition: background .12s, border-color .12s, color .12s, box-shadow .12s;
  white-space: nowrap;
}
.mode-pill:hover { background: var(--surface-2); border-color: var(--accent); color: var(--accent); }
.mode-pill.is-active { background: var(--ink); border-color: var(--ink); color: #fff; }
.mode-pill[disabled] { opacity: .45; cursor: not-allowed; }

/* ── バッジ ── */
.agg-badge {
  display: inline-block;
  padding: 3px 10px;
  font-size: 11px;
  font-weight: 600;
  border: 1px solid var(--border-2);
  border-radius: var(--radius-pill);
  color: var(--ink-2);
  background: var(--surface-2);
  white-space: nowrap;
}
.agg-badge.is-dc {
  background: var(--accent-bg);
  border-color: #93c5fd;
  color: var(--accent-dark);
}
.scan-status { font-size: 11px; color: var(--ink-3); }

/* ── トップバー ── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}
.beta-banner {
  background: var(--gold-bg);
  border-bottom: 1px solid #fcd34d;
  color: var(--gold);
  text-align: center;
  font-size: 11px;
  font-weight: 600;
  padding: 4px 12px;
  letter-spacing: .02em;
}

/* 上段 */
.topbar-main {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 20px;
  max-width: 1400px;
  margin: 0 auto;
}

/* ブランド */
.topbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  text-decoration: none;
}
.brand-logo {
  height: 36px;
  width: auto;
}
.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}
.brand-name {
  font-size: 16px;
  font-weight: 800;
  color: var(--ink);
  letter-spacing: -.01em;
}
.brand-sub {
  font-size: 10px;
  color: var(--ink-3);
  letter-spacing: .04em;
}

/* 検索 */
.topbar-search {
  flex: 1 1 0;
  max-width: 380px;
  position: relative;
}
.search-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  padding: 6px 14px;
  transition: border-color .15s, box-shadow .15s;
}
.search-wrap:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(59,130,246,.12);
  background: var(--surface);
}
.search-svg {
  width: 16px;
  height: 16px;
  color: var(--ink-3);
  flex-shrink: 0;
}
#global-search {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--ink);
  font-size: 13px;
  outline: none;
}
#global-search::placeholder { color: var(--ink-3); }
#global-search::-webkit-search-cancel-button { cursor: pointer; }

/* 右側コントロール */
.topbar-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  margin-left: auto;
}
.ctrl-group {
  display: flex;
  align-items: center;
  gap: 4px;
}
.ctrl-label {
  font-size: 11px;
  color: var(--ink-3);
  white-space: nowrap;
}
.topbar-controls select {
  padding: 5px 8px;
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  font-size: 12px;
}
.topbar-controls select:focus { outline: none; border-color: var(--accent); }
.dev-controls { display: none; }

/* DC モードトグルボタン */
.dc-mode-btn {
  padding: 4px 10px;
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink-3);
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, color .15s, border-color .15s;
}
.dc-mode-btn:hover { border-color: var(--accent); color: var(--ink); }
.dc-mode-btn.is-active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
#worldId:disabled { opacity: .45; pointer-events: none; }

/* 下段：モード切替 */
.topbar-modes {
  border-top: 1px solid var(--border);
  background: var(--surface-2);
}
#mode-switch {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  max-width: 1400px;
  margin: 0 auto;
  padding: 6px 20px;
  box-sizing: border-box;
  width: 100%;
}
.modes-sep {
  width: 1px;
  height: 18px;
  background: var(--border-2);
  margin: 0 4px;
}

/* ── ワークスペース ── */
.workspace {
  max-width: 1400px;
  margin: 0 auto;
  padding: 16px 20px;
}

/* 3カラムグリッド: ミニレール | 市場規模 | 利益 | 採取 */
.threecol {
  display: grid;
  grid-template-columns: var(--sidebar-w) repeat(3, 1fr);
  gap: 14px;
  align-items: start;
  transition: grid-template-columns .2s ease;
}

/* ── カード列配置 ── */
.sidebar-card   { grid-column: 1; grid-row: 1; }
#market-card    { grid-column: 2; }
#profit-card    { grid-column: 3; }
#gathering-card { grid-column: 4; }

/* カテゴリ・原価計算・Top100 はコンテンツ幅いっぱい */
#category-results { grid-column: 2 / span 3; }
#calc-view        { grid-column: 2 / span 3; display: none; }
#fav-view         { grid-column: 2 / span 3; display: none; }
#player-view      { grid-column: 2 / span 3; display: none; }
#gmv-top-card     { grid-column: 2 / span 3; display: none; }
#profit-top-card  { grid-column: 2 / span 3; display: none; }

/* ── 表示モード切替 ── */
.show-category #market-card,
.show-category #profit-card,
.show-category #gathering-card  { display: none !important; }
.show-category #category-results { display: block !important; }

.show-estimator #market-card,
.show-estimator #profit-card,
.show-estimator #gathering-card { display: none !important; }
.show-estimator #calc-view       { display: block !important; }

.show-favorites #market-card,
.show-favorites #profit-card,
.show-favorites #gathering-card { display: none !important; }
.show-favorites #fav-view        { display: block !important; }

.show-player #market-card,
.show-player #profit-card,
.show-player #gathering-card { display: none !important; }
.show-player #player-view     { display: block !important; }

.show-gmv-top #market-card,
.show-gmv-top #profit-card,
.show-gmv-top #gathering-card   { display: none !important; }
.show-gmv-top #gmv-top-card     { display: block !important; }

.show-profit-top #market-card,
.show-profit-top #profit-card,
.show-profit-top #gathering-card { display: none !important; }
.show-profit-top #profit-top-card { display: block !important; }

.show-gathering-top #market-card,
.show-gathering-top #profit-card,
.show-gathering-top #gathering-card { display: none !important; }
.show-gathering-top #gathering-top-card { display: block !important; }

#gathering-top-card { grid-column: 2 / span 3; display: none; }

/* Top100 ヘッダー行 */
.top-card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}
.top-card-head h2 { margin-bottom: 0; }

/* sheet-open 時スクロール禁止 */
body.sheet-open { overflow: hidden; }

/* ============================================================
   Part 2 — サイドバー
   ============================================================ */

/* ── サイドバーカード ── */
.sidebar-card {
  padding: 0;
  overflow: hidden;
  min-height: 300px;
}

/* ── left-menu グリッド ── */
#left-menu {
  display: grid;
  grid-template-columns: 56px 1fr;
  grid-template-rows: auto auto auto 1fr;
  column-gap: 0;
  align-items: start;
  min-height: 400px;
}

/* ── ミニレール ── */
#left-menu .sidebar-mini {
  grid-column: 1;
  grid-row: 1 / -1;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 56px;
  flex: 0 0 56px;
  padding: 10px 6px;
  gap: 6px;
  border-right: 1px solid var(--border);
  background: var(--surface-2);
  min-height: 100%;
}
#left-menu .sidebar-mini .mini-btn {
  width: 36px;
  height: 36px;
  flex: 0 0 36px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink-2);
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .12s, border-color .12s, box-shadow .12s;
}
#left-menu .sidebar-mini .mini-btn:hover {
  background: var(--accent-bg);
  border-color: var(--accent);
  color: var(--accent);
}
#left-menu .sidebar-mini .mini-sep {
  width: 24px;
  height: 1px;
  background: var(--border);
  margin: 2px 0;
}
#left-menu .sidebar-mini .mini-grow { flex: 1; }

/* ── カテゴリメニューは右列 ── */
#left-menu .cat-root-menu {
  grid-column: 2;
  grid-row: 1;
  overflow-y: auto;
  max-height: calc(100vh - 120px);
}

/* 閉じているとき右列を隠す */
body:not(.sidebar-open) #left-menu .cat-root-menu { display: none; }

/* 開いているとき左カラムを広げる */
body.sidebar-open #left-menu {
  grid-template-columns: 56px 1fr;
}

/* ── サイドバー固定時 ── */
body.sidebar-open #left-menu { align-items: flex-start; }

/* ── カテゴリルートメニュー ── */
.cat-root-menu {
  grid-column: 2;
  grid-row: 1;
  padding: 10px 12px 6px;
}
.cat-root-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}
.cat-root-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--ink-3);
}
.cat-root-all {
  font-size: 11px;
  padding: 2px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--surface);
  color: var(--ink-2);
}
.cat-root-all:hover { background: var(--accent-bg); color: var(--accent); border-color: var(--accent); }
.cat-root-body { }

/* ── ナビペイン（中分類・アイテム） ── */
.nav-pane {
  grid-column: 2;
  padding: 6px 12px;
  border-top: 1px solid var(--border);
}
.nav-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}
.nav-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--ink-3);
}
.nav-search {
  flex: 1;
  margin-left: 8px;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  font-size: 12px;
  color: var(--ink);
  outline: none;
}
.nav-search:focus { border-color: var(--accent); background: var(--surface); }
.nav-body { }

/* ── メニューリスト ── */
.menu-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.menu-list li a {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  color: var(--ink-2);
  font-size: 13px;
  transition: background .1s, color .1s;
}
.menu-list li a:hover   { background: var(--surface-2); color: var(--ink); }
.menu-list li a.active  { background: var(--accent-bg); color: var(--accent-dark); font-weight: 600; }
.cat-icon { width: 24px; height: 24px; border-radius: 4px; object-fit: contain; flex-shrink: 0; }

/* ── サイドバー変数同期 ── */
.threecol { grid-template-columns: var(--sidebar-w) repeat(3, 1fr); }

/* ============================================================
   Part 3 — ランキングカード・アイテムチップ
   ============================================================ */

/* ── リスト共通リセット ── */
#gmv-list, #profit-list, #gathering-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

/* ── 行レイアウト ── */
/* GMV・利益: rank | chip | meta（単価/利益率） | val（GMV/利益額） の4列 */
#gmv-list .row,
#profit-list .row {
  display: grid;
  grid-template-columns: 24px 1fr auto auto;
  align-items: center;
  gap: 6px;
  padding: 5px 4px;
  border-radius: var(--radius-sm);
  transition: background .1s;
}
/* 採取: rank | chip | val の3列 */
#gathering-list .row {
  display: grid;
  grid-template-columns: 24px 1fr auto;
  align-items: center;
  gap: 6px;
  padding: 5px 4px;
  border-radius: var(--radius-sm);
  transition: background .1s;
}
#gmv-list .row:hover,
#profit-list .row:hover,
#gathering-list .row:hover { background: var(--surface-2); }

/* 「もっと見る」行は中央揃えに上書き */
#gmv-list .row:last-child,
#profit-list .row:last-child,
#gathering-list .row:last-child {
  display: flex;
  justify-content: center;
  padding: 8px 0 4px;
  background: none !important;
}

/* ── 順位番号 ── */
.rank {
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
  text-align: right;
  min-width: 20px;
}

/* ── アイテムチップ（全リスト共通） ── */
.item-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--surface);
  color: inherit;
  text-decoration: none;
  box-shadow: var(--shadow-xs);
  transition: background .12s, border-color .12s, transform .06s;
  cursor: pointer;
}
.item-chip:hover {
  background: var(--accent-bg);
  border-color: #93c5fd;
}
.item-chip:active { transform: translateY(1px); }
.item-chip img {
  width: 24px;
  height: 24px;
  border-radius: 5px;
  object-fit: contain;
  flex-shrink: 0;
  background: var(--surface-2);
}
.item-chip .label {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.item-chip .label .name {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.item-chip .label .sub {
  font-size: 11px;
  color: var(--ink-3);
  line-height: 1.2;
  margin-top: 1px;
}

/* クリッカブルでないチップ（採取など） */
.item-text.item-chip {
  cursor: default;
  opacity: .85;
}
.item-text.item-chip .name { color: var(--ink-2); }

/* ── 数値列 ── */
.val {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  text-align: right;
  white-space: nowrap;
}
.val.profit { color: var(--green); }
.val.loss   { color: var(--red); }

/* ── GMV Top100 グリッド ── */
.profit-top-grid {
  display: grid;
  grid-template-columns: 28px 1.6fr 64px 110px 110px 72px 130px;
  gap: 8px;
  align-items: center;
}
.profit-top-grid .h {
  font-size: 11px;
  font-weight: 700;
  color: var(--ink-3);
  text-align: center;
}
.profit-top-grid .cell.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-size: 12px;
}
.profit-top-grid .icon {
  width: 24px;
  height: 24px;
  border-radius: 4px;
  object-fit: cover;
}
.profit-top-grid .row { display: contents; }
.profit-top-grid .item-chip {
  padding: 4px 8px;
  font-size: 12px;
}

/* ── scope バー（ワールド/DC 切替） ── */
.scope-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
}
.scope-label { font-size: 12px; color: var(--ink-3); min-width: 48px; }
.scope-pills { display: flex; gap: 6px; }
.scope-pill {
  border: 1px solid var(--border);
  background: var(--surface);
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  font-size: 12px;
  cursor: pointer;
}
.scope-pill.is-active {
  border-color: #93c5fd;
  background: var(--accent-bg);
  color: var(--accent-dark);
  font-weight: 600;
}
.scope-meta { margin-left: auto; font-size: 12px; color: var(--ink-3); }
.scope-now  { color: var(--ink); font-weight: 600; }
.world-note { font-size: 11px; color: var(--ink-3); margin-top: 2px; line-height: 1.2; }
.rank-number { width: 28px; text-align: center; color: var(--accent); font-weight: 700; flex-shrink: 0; }

/* ============================================================
   Part 4 — アイテム詳細シート・検索ドロップダウン
   ============================================================ */

/* ── シートオーバーレイ ── */
.sheet-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 500;
  background: rgba(15,23,42,.45);
  backdrop-filter: blur(3px);
  justify-content: center;
  align-items: center;
}
.sheet-overlay.is-open { display: flex; }

/* ── シートパネル ── */
.sheet-panel {
  width: 540px;
  max-width: 94vw;
  max-height: 86vh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 20px 60px rgba(0,0,0,.18), 0 4px 16px rgba(0,0,0,.10);
  display: flex;
  flex-direction: column;
  scrollbar-width: thin;
  scrollbar-color: var(--border-2) transparent;
}

/* ── ヘッダー ── */
.sheet-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 14px 16px 12px;
}
.sheet-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 28px;
  height: 28px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--ink-3);
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .12s, color .12s;
}
.sheet-close:hover { background: #fee2e2; border-color: #fca5a5; color: var(--red); }
.sheet-title-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-right: 80px; /* 閉じる(28px) + お気に入り(28px) + 余白 */
}
.sheet-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface-2);
  object-fit: contain;
  flex-shrink: 0;
}
.sheet-title-text { flex: 1; min-width: 0; }
.sheet-name {
  font-size: 15px;
  font-weight: 700;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sheet-meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 5px;
}
.sheet-il, .sheet-cat {
  font-size: 11px;
  padding: 2px 7px;
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--ink-3);
}
.sheet-badge {
  font-size: 11px;
  padding: 2px 7px;
  border-radius: var(--radius-pill);
  white-space: nowrap;
}
.sheet-badge.craft    { background: #f0fdf4; border: 1px solid #bbf7d0; color: #15803d; }
.sheet-badge.craft.sm { font-size: 10px; padding: 1px 5px; }

/* ── セクション ── */
.sheet-section {
  padding: 14px 16px 12px;
  border-bottom: 1px solid var(--border);
}
.sheet-section:last-of-type { border-bottom: none; }
.sheet-section-title {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--ink-3);
  margin-bottom: 10px;
}

/* ── 価格行 ── */
.sheet-price-row {
  display: grid;
  grid-template-columns: auto 1fr auto 1fr;
  align-items: center;
  gap: 6px 10px;
}
.sheet-price-label {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--ink-3);
}
.sheet-price-label.hq { background: var(--gold-bg); border-color: #fde68a; color: var(--gold); }
.sheet-price-val { font-size: 15px; font-weight: 700; color: var(--ink); }
.sheet-price-with-trend { display: flex; align-items: center; gap: 6px; }
.trend-note {
  font-size: 10px; font-weight: 500; color: var(--ink-3);
  margin-left: 8px; letter-spacing: 0;
}
.trend-badge {
  display: inline-block; font-size: 11px; font-weight: 700;
  padding: 1px 6px; border-radius: var(--radius-pill);
  white-space: nowrap;
}
.trend-badge.up   { background: #f0fdf4; color: #16a34a; border: 1px solid #bbf7d0; }
.trend-badge.down { background: #fef2f2; color: #dc2626; border: 1px solid #fecaca; }
.trend-badge.flat { background: var(--surface-2); color: var(--ink-3); border: 1px solid var(--border); }

/* ── DCテーブル ── */
.sheet-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.sheet-table th {
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  color: var(--ink-3);
  padding: 4px 8px 4px 0;
  border-bottom: 1px solid var(--border);
}
.sheet-table td {
  padding: 5px 8px 5px 0;
  border-bottom: 1px solid var(--surface-2);
  color: var(--ink-2);
}
.sheet-table td:not(:first-child) { text-align: right; }
.sheet-table tr:hover td { background: var(--surface-2); }
.world-name { font-weight: 600; color: var(--ink); }
.sheet-table td.price-min { background: #f0fdf4; color: #15803d; font-weight: 600; }
.sheet-table td.price-max { background: #fff1f2; color: #be123c; font-weight: 600; }

/* ── お気に入りボタン（シートヘッダー内） ── */
.sheet-fav-btn {
  position: absolute;
  top: 12px;
  right: 46px;
  width: 28px;
  height: 28px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--ink-3);
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .12s, color .12s;
  cursor: pointer;
  line-height: 1;
}
.sheet-fav-btn:hover { background: #fef9c3; border-color: #fde68a; color: #d97706; }
.sheet-fav-btn.is-fav { color: #f59e0b; background: #fef3c7; border-color: #fde68a; }

/* ── お気に入りビュー ── */
.fav-empty {
  padding: 48px 0;
  text-align: center;
  color: var(--ink-3);
  font-size: 14px;
}
.fav-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 8px;
  margin-top: 12px;
}
.fav-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  cursor: pointer;
  transition: background .12s, box-shadow .12s;
  position: relative;
}
.fav-card:hover { background: var(--surface); box-shadow: var(--shadow-sm); }
.fav-card-icon { width: 32px; height: 32px; flex-shrink: 0; object-fit: contain; }
.fav-card-name { flex: 1; font-size: 13px; font-weight: 600; color: var(--ink); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fav-card-remove {
  flex-shrink: 0;
  background: none;
  border: none;
  color: var(--ink-3);
  font-size: 14px;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
  line-height: 1;
}
.fav-card-remove:hover { background: #fee2e2; color: var(--red); }

/* ── 価格推移チャート（折れ線） ── */
.hist-svg {
  width: 100%;
  height: auto;
  display: block;
  overflow: visible;
}
.hist-xlabel {
  font-size: 9px;
  fill: var(--ink-3);
}
.hist-legend {
  display: flex;
  gap: 14px;
  margin-top: 6px;
  font-size: 11px;
}
.hist-leg { display: flex; align-items: center; gap: 4px; color: var(--ink-2); }
.hist-leg::before { content: ''; display: inline-block; width: 18px; height: 2px; border-radius: 1px; }
.hist-leg.nq::before { background: var(--accent); }
.hist-leg.hq::before { background: var(--gold, #f59e0b); }

/* ── 逆引きリスト ── */
.uses-list { display: flex; flex-direction: column; gap: 3px; }
.uses-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background .1s;
}
.uses-row:hover { background: var(--surface-2); }
.uses-name {
  flex: 1;
  font-size: 13px;
  color: var(--ink-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.icon-sm {
  width: 24px;
  height: 24px;
  border-radius: 4px;
  background: var(--surface-2);
  flex-shrink: 0;
  object-fit: contain;
}

/* ── フッター ── */
.sheet-footer {
  padding: 14px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: auto;
  background: var(--surface-2);
}
.sheet-loading { padding: 40px; text-align: center; color: var(--ink-3); font-size: 13px; }

/* ── 検索ドロップダウン ── */
#search-results {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  z-index: 200;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  max-height: 380px;
  overflow-y: auto;
  scrollbar-width: thin;
}
.search-result-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background .1s;
}
.search-result-row:last-child { border-bottom: none; }
.search-result-row:hover { background: var(--accent-bg); }
.sr-icon {
  width: 24px;
  height: 24px;
  border-radius: 4px;
  object-fit: contain;
  flex-shrink: 0;
  background: var(--surface-2);
}
.sr-icon-ph {
  width: 24px;
  height: 24px;
  border-radius: 4px;
  background: var(--surface-2);
  flex-shrink: 0;
}
.sr-name { font-size: 13px; color: var(--ink); flex: 1; min-width: 0; }
.sr-craft { font-size: 11px; margin-left: 4px; }
.search-empty { padding: 14px 12px; color: var(--ink-3); font-size: 13px; }

/* ============================================================
   Part 5 — 原価計算・カテゴリ・ツリー・その他
   ============================================================ */

/* ── 原価計算ビュー ── */
#calc-body {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.calc-section {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  background: var(--surface);
}
.calc-kpis { display: flex; gap: 10px; flex-wrap: wrap; }
.kpi {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
  min-width: 120px;
  background: var(--surface-2);
}
.kpi-btn {
  cursor: pointer;
  user-select: none;
  transition: transform .06s, box-shadow .12s, background .12s;
  text-align: left;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
  min-width: 120px;
  background: var(--surface-2);
}
.kpi-btn:hover  { box-shadow: var(--shadow-sm); }
.kpi-btn:active { transform: translateY(1px); }
.kpi-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.kpi-btn.is-active, .kpi.is-active {
  background: var(--accent-bg);
  border-color: #93c5fd;
  box-shadow: 0 0 0 2px rgba(59,130,246,.15) inset;
}
.kpi-btn.is-active .meta::after,
.kpi.is-active .meta::after {
  content: "・選択中";
  margin-left: .4em;
  color: var(--accent);
  font-weight: 600;
  font-size: .85em;
}
.ph-kpis { display: flex; gap: 10px; flex-wrap: wrap; }
.ph-kpi {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 10px;
  min-width: 120px;
  background: var(--surface-2);
}
.ph-kpi .meta { color: var(--ink-3); font-size: 11px; }
.ph-kpi .val  { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--ink); }

/* 完成品ヘッダー */
.product-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}
.product-head .ph-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius);
  object-fit: contain;
  border: 1px solid var(--border);
  background: var(--surface-2);
}
.product-head .ph-main { flex: 1; min-width: 0; }
.product-head .ph-name {
  font-weight: 700;
  font-size: 16px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.product-head .ph-sub { color: var(--ink-3); font-size: 12px; margin-top: 2px; }

/* ── 素材ツリー ── */
.tree { font-size: 13px; line-height: 1.6; margin-top: 8px; }
.tree .node { margin-left: 16px; margin-top: 8px; }
.tree .node .node-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px;
}
.tree .node .node-head {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}
.tree .node .node-title { font-weight: 600; color: var(--ink); }
.tree .node .indent     { color: var(--ink-3); font-size: 12px; }
.tree .node .node-children { margin-top: 6px; }
.tree .node.is-bought > .node-card + .node-children { display: none; }

.tree .node .mode-pills {
  display: inline-flex;
  gap: 5px;
  margin-left: 6px;
  flex-wrap: wrap;
}
.tree .node .mode-pills .mode-pill { padding: 3px 8px; font-size: 11px; }

.tree .node .badge-root,
.tree .node .badge-yield,
.tree .node .badge-buy {
  display: inline-block;
  margin-left: 6px;
  padding: 2px 6px;
  font-size: 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  color: var(--ink-3);
  background: var(--surface-2);
}
.tree .node .badge-yield { background: #eff6ff; border-color: #bfdbfe; color: var(--accent-dark); }
.tree .node .badge-buy   { background: var(--surface-2); }

.actual-badge {
  display: inline-block;
  font-size: 9px;
  background: #7c3aed;
  color: #fff;
  border-radius: 4px;
  padding: 1px 4px;
  margin-left: 4px;
  vertical-align: middle;
}

/* テーブル */
table.clean { width: 100%; border-collapse: collapse; }
table.clean th,
table.clean td { border-bottom: 1px solid var(--border); padding: 6px 8px; font-size: 13px; }
table.clean th { color: var(--ink-3); font-weight: 600; font-size: 11px; }

/* ── カテゴリ結果グリッド ── */
#category-results.category-grid {
  display: block;
}
.cat-grid-inner {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 6px;
}
.cat-total-label {
  text-align: center;
  font-size: 12px;
  color: var(--ink-3);
  margin-top: 8px;
  padding-bottom: 4px;
}
.card-item {
  display: flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 5px 8px;
  background: var(--surface);
  cursor: pointer;
  transition: background .12s, border-color .12s;
}
.card-item:hover { background: var(--accent-bg); border-color: #93c5fd; }
.card-item img  { width: 26px; height: 26px; border-radius: var(--radius-sm); object-fit: contain; flex-shrink: 0; }
.card-item > div { min-width: 0; flex: 1; overflow: hidden; }
.card-item .name { font-size: 12px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-item .meta { color: var(--ink-3); font-size: 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ============================================================
   Fix — GMV Top100 rank-row / ランキング行補足
   ============================================================ */

/* GMV Top100 の各行（rank | img | name+sub | val） */
.rank-row {
  display: grid;
  grid-template-columns: 28px 28px 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 6px 4px;
  border-bottom: 1px solid var(--border);
  transition: background .1s;
}
.rank-row:last-child { border-bottom: none; }
.rank-row:hover { background: var(--surface-2); }
.rank-row .rank {
  text-align: right;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
}
.rank-row img {
  width: 24px;
  height: 24px;
  border-radius: 4px;
  object-fit: contain;
  background: var(--surface-2);
}
.rank-row .name {
  font-size: 13px;
  font-weight: 500;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.rank-row .name .sub {
  font-size: 11px;
  color: var(--ink-3);
  margin-top: 1px;
}
.rank-row .val {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  text-align: right;
  white-space: nowrap;
}

/* ── 採取ランキング行（コンパクト：rank|chip|単価|売数|合計） ── */
#gathering-list .gather-row {
  grid-template-columns: 24px 1fr auto auto auto;
}

/* ── 採取 Top100 グリッド ── */
.gather-top-grid {
  display: grid;
  grid-template-columns: 28px 1fr 110px 80px 130px;
  gap: 6px 10px;
  align-items: center;
}
.gather-top-grid .h {
  font-size: 11px;
  font-weight: 700;
  color: var(--ink-3);
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}
.gather-top-grid > * {
  padding: 5px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.gather-top-grid .cell.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.gather-top-grid .cell.num.profit {
  font-weight: 700;
  color: var(--green);
}
.gather-name-cell {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.gather-name-cell span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 13px;
}
.gather-src {
  font-size: 10px;
  padding: 1px 5px;
  border-radius: var(--radius-pill);
  background: var(--gold-bg);
  border: 1px solid #fde68a;
  color: var(--gold);
  margin-left: 4px;
}

/* ── プレイヤーダッシュボード ── */
.player-head { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; margin-bottom: 12px; }
.player-head h2 { margin: 0; font-size: 16px; }
.player-tabs { display: flex; gap: 6px; }
.player-cache-clear-btn {
  margin-left: auto;
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid #fca5a5;
  background: #fee2e2;
  color: #dc2626;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, color .15s;
}
.player-cache-clear-btn:hover { background: #fecaca; }
.player-cache-clear-btn.is-cleared { background: #dcfce7; color: #16a34a; border-color: #86efac; }
.player-tab {
  padding: 5px 14px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--bg); color: var(--muted); font-size: 13px; cursor: pointer;
}
.player-tab.is-active { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 600; }
.player-tab-panel.hidden { display: none; }
.player-input-row { display: flex; gap: 8px; flex: 1; min-width: 200px; margin-bottom: 12px; }
.player-char-input {
  flex: 1; padding: 6px 10px; border: 1px solid var(--border); border-radius: var(--radius);
  font-size: 13px; background: var(--bg); color: var(--ink);
}
.player-load-btn {
  padding: 6px 14px; border: none; border-radius: var(--radius); cursor: pointer;
  background: var(--accent); color: #fff; font-size: 13px; font-weight: 600;
}
.player-load-btn:hover { opacity: .85; }
.player-hint { color: var(--muted); font-size: 13px; padding: 16px 0; }
.player-summary {
  font-size: 13px; margin-bottom: 10px; padding: 8px 12px;
  background: var(--surface); border-radius: var(--radius); border: 1px solid var(--border);
}
.player-table-wrap { overflow-x: auto; }
.player-table {
  width: 100%; border-collapse: collapse; font-size: 13px;
}
.player-table th, .player-table td {
  padding: 6px 10px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap;
}
.player-table th { background: var(--surface); font-weight: 600; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .04em; }
.player-table tbody tr:hover { background: var(--surface); }
.player-name-cell { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.player-num { text-align: right !important; font-variant-numeric: tabular-nums; }
.player-date { color: var(--muted); font-size: 12px; }
.player-cheap { color: #16a34a; font-weight: 600; }
.player-pricey { color: var(--red); font-weight: 600; }
.player-icon { width: 24px; height: 24px; object-fit: contain; flex-shrink: 0; }
.hq-badge {
  display: inline-block; font-size: 9px; background: #0284c7; color: #fff;
  border-radius: 3px; padding: 1px 4px; vertical-align: middle; margin-left: 3px;
}
.player-retainer-tags {
  display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px;
}
.player-retainer-tag {
  display: inline-flex; align-items: center; gap: 4px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 2px 8px; font-size: 12px; color: var(--ink);
}
.player-retainer-remove {
  background: none; border: none; color: var(--muted); font-size: 13px;
  cursor: pointer; padding: 0; line-height: 1;
}
.player-retainer-remove:hover { color: var(--red); }
.player-retainer-col { font-size: 11px; color: var(--muted); }
.del-sale-btn { background: none; border: none; color: var(--muted); cursor: pointer; padding: 0 4px; font-size: 14px; }
.del-sale-btn:hover { color: var(--red); }
.player-del-cell { width: 28px; text-align: center; }

/* ===== プレイヤーダッシュボード グラフ ===== */
.player-stat-row {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
}
.player-stat {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
}
.player-stat-label { font-size: 11px; color: var(--muted); margin-bottom: 4px; }
.player-stat-value { font-size: 16px; font-weight: 700; }
.player-stat-rev  { color: #16a34a; }
.player-stat-exp  { color: #ea580c; }
.player-stat-pos  { color: #16a34a; }
.player-stat-neg  { color: #dc2626; }
.player-chart-wrap { border: 1px solid var(--border); border-radius: 8px; padding: 12px; background: var(--surface); }
.pd-section-title { font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin: 16px 0 8px; }
.pd-top3 { border: 1px solid var(--border); border-radius: 8px; overflow: hidden; margin-bottom: 4px; }
.pd-top3-item { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-bottom: 1px solid var(--border); background: var(--surface); }
.pd-top3-item:last-child { border-bottom: none; }
.pd-rank { font-size: 18px; width: 26px; text-align: center; flex-shrink: 0; }
.pd-top3-body { flex: 1; min-width: 0; }
.pd-top3-name { font-size: 14px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pd-top3-sub  { font-size: 12px; color: var(--muted); }
.pd-feed { border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.pd-feed-item { display: flex; align-items: center; gap: 10px; padding: 7px 12px; border-bottom: 1px solid var(--border); background: var(--surface); }
.pd-feed-item:last-child { border-bottom: none; }
.pd-feed-badge { font-size: 10px; font-weight: 700; padding: 2px 6px; border-radius: 4px; flex-shrink: 0; }
.pd-sell { background: #dcfce7; color: #16a34a; }
.pd-buy  { background: #ffedd5; color: #ea580c; }
.pd-feed-name  { flex: 1; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pd-feed-price { font-size: 13px; font-weight: 600; white-space: nowrap; }
.pd-feed-date  { font-size: 12px; color: var(--muted); white-space: nowrap; }
