/* ─── View別 layout / List / Radar / Heatmap 共通 ─────────────────────── */

/* ── view 別 container 表示制御 ─────────────────────────────────────── */
#list_view, #radar_view, #plot_2d, #compare_view { display: none; }

body[data-view="3d"]      #plot       { display: block; }
body[data-view="3d"]      #list_view,
body[data-view="3d"]      #radar_view,
body[data-view="3d"]      #plot_2d,
body[data-view="3d"]      #compare_view { display: none; }

body[data-view="list"]    #plot       { display: none; }
body[data-view="list"]    #list_view  { display: block; }
body[data-view="list"]    .timebar,
body[data-view="list"]    .legend     { display: none !important; }

body[data-view="radar"]   #plot       { display: none; }
body[data-view="radar"]   #radar_view { display: block; }
body[data-view="radar"]   .timebar,
body[data-view="radar"]   .legend     { display: none !important; }

body[data-view="heatmap"] #plot       { display: none; }
body[data-view="heatmap"] #plot_2d    { display: block; }
body[data-view="heatmap"] .timebar,
body[data-view="heatmap"] .legend     { display: none !important; }

body[data-view="compare"] #plot          { display: none; }
body[data-view="compare"] #compare_view  { display: block; }
body[data-view="compare"] .timebar,
body[data-view="compare"] .legend,
body[data-view="compare"] .sb            { display: none !important; }

/* canvas-wrap が full をたもち、 各 view container が中で fill */
#list_view, #radar_view, #plot_2d, #compare_view {
  width: 100%;
  height: 100%;
  overflow: auto;
  background: var(--bg);
}

/* ── 共通ユーティリティ ──────────────────────────────────────────────── */
.lv-empty {
  padding: 2rem;
  text-align: center;
  color: var(--dim);
  font-size: 0.85rem;
}
.lv-meta {
  position: sticky; top: 0; z-index: 2;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding: 0.4rem 0.8rem;
  font-size: 0.72rem;
  color: var(--dim);
  font-family: 'JetBrains Mono', monospace;
}
.lv-count { font-weight: 700; color: var(--mid); }

/* ──────────────────────────────────────────────────────────────────────
 *  List view
 * ──────────────────────────────────────────────────────────────────── */
.lv-scroll {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.lv-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.78rem;
}
.lv-th {
  position: sticky; top: 0; z-index: 1;
  background: var(--surface);
  color: var(--mid);
  text-align: left;
  font-weight: 700;
  padding: 0.5rem 0.55rem;
  border-bottom: 1px solid var(--border-strong);
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
  transition: background 0.12s;
}
.lv-th:hover { background: var(--surface2); }
.lv-th.is-axis { background: var(--active-bg); }
/* === Sticky 左固定: 作品名列のみ left: 0 === */
/* # 列は left 固定なし (table-layout:auto で実幅が不定のためオフセット計算が不正確になる) */
.lv-th-num { width: 2.5em; text-align: right; color: var(--dim); cursor: default; }
.lv-th-num:hover { background: var(--surface); }

.lv-th-name,
.lv-td-name {
  position: sticky;
  left: 0;
  z-index: 2;
  /* --t-surface は solid 色 (dark:#14141f / light:#fff) — 透過なし */
  background: var(--t-surface);
  box-shadow: 3px 0 8px color-mix(in srgb, var(--t-fg) 10%, transparent);
}
.lv-th-name { z-index: 3; min-width: 14em; }

/* ゼブラ縞・hover も solid 背景でオーバーライド */
.lv-row:nth-child(even) .lv-td-name {
  background: color-mix(in srgb, var(--t-fg) 3%, var(--t-surface));
}
.lv-row:hover .lv-td-name {
  background: var(--t-surface-hover, var(--t-surface));
}
.lv-th-metric { text-align: center; min-width: 5em; }
.lv-th-total { text-align: right; min-width: 4em; }
.lv-th-year  { text-align: center; min-width: 4em; }
.lv-th-status { width: 6em; text-align: center; }
.lv-th-compass { width: 2.4em; text-align: center; }
.lv-td-compass { text-align: center; vertical-align: middle; }
.lv-compass { display: inline-block; vertical-align: middle; }
.lv-arrow {
  display: inline-block;
  margin-left: 0.2em;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.7rem;
  color: var(--accent);
}
.lv-arrow.muted { color: var(--dim); opacity: 0.5; }

/* 列ドラッグ並び替え */
.lv-grip {
  display: inline-block;
  margin-right: 0.2em;
  color: var(--dim);
  opacity: 0.4;
  font-size: 0.8em;
  cursor: grab;
  vertical-align: middle;
}
.lv-th-metric:hover .lv-grip { opacity: 0.7; }
.lv-th-metric { cursor: pointer; }
.lv-th.lv-dragging { opacity: 0.4; }
.lv-th.lv-dragover { background: var(--active-bg); box-shadow: inset 2px 0 0 var(--accent); }
/* composite クラスタ (demand / craft / emo / aux) の境界 */
.lv-group-start { border-left: 2px solid color-mix(in srgb, var(--t-fg) 13%, transparent); }
.lv-reset {
  margin-left: 0.8rem;
  font-family: inherit;
  font-size: 0.7rem;
  color: var(--accent);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.1rem 0.55rem;
  cursor: pointer;
}
.lv-reset:hover { background: var(--surface2); }

.lv-row {
  cursor: pointer;
  transition: background 0.1s;
}
.lv-row:hover { background: var(--active-bg); }
.lv-row:nth-child(even) { background: color-mix(in srgb, var(--t-fg) 3%, transparent); }
.lv-row:nth-child(even):hover { background: var(--active-bg); }
/* サイドバー or ヒートマップ側のホバーによる行ハイライト (setHover 経由、DOM 直操作) */
.lv-row.lv-row--hover { background: color-mix(in srgb, var(--t-accent) 12%, var(--t-surface)); }
.lv-row.lv-row--hover .lv-td-name {
  background: color-mix(in srgb, var(--t-accent) 12%, var(--t-surface));
}
.lv-row:nth-child(even).lv-row--hover,
.lv-row:nth-child(even).lv-row--hover .lv-td-name {
  background: color-mix(in srgb, var(--t-accent) 12%, var(--t-surface));
}

.lv-td {
  padding: 0.45rem 0.55rem;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  vertical-align: middle;
}
.lv-td-num { text-align: right; color: var(--dim); font-family: 'JetBrains Mono', monospace; font-size: 0.7rem; }
/* display:flex を td から外すことで position:sticky が Safari でも正常動作 */
.lv-td-name { max-width: 18em; overflow: hidden; }
.lv-name-inner { display: flex; align-items: center; gap: 0.5rem; overflow: hidden; }
.lv-name-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.lv-dot {
  display: inline-block;
  width: 0.55em; height: 0.55em;
  border-radius: 50%;
  flex-shrink: 0;
  border: 1px solid var(--dot-border);
}
.lv-td-metric {
  position: relative;
  text-align: center;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.74rem;
  min-width: 4em;
}
.lv-td-metric.is-axis { background: color-mix(in srgb, var(--t-accent) 6%, transparent); }
.lv-bar {
  position: absolute;
  left: 0; bottom: 0;
  height: 3px;
  width: var(--lv-bar-w);
  opacity: 0.55;
  pointer-events: none;
}
.lv-val { position: relative; }
.lv-td-total { text-align: right; font-family: 'JetBrains Mono', monospace; font-weight: 700; color: var(--mid); }
.lv-td-year { text-align: center; font-family: 'JetBrains Mono', monospace; font-size: 0.72rem; }
.lv-td-status { text-align: center; }
.lv-badge {
  display: inline-block;
  margin: 0 0.1em;
  font-size: 0.85rem;
  line-height: 1;
}
.lv-td .muted { color: var(--dim); opacity: 0.6; }

@media (max-width: 768px) {
  .lv-table { font-size: 0.72rem; }
  .lv-th, .lv-td { padding: 0.35rem 0.4rem; }
  .lv-th-name, .lv-td-name { min-width: 10em; }
}

/* ──────────────────────────────────────────────────────────────────────
 *  Radar grid view
 * ──────────────────────────────────────────────────────────────────── */
.rv-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 0.6rem;
  padding: 0.8rem;
}
.rv-card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.15s, box-shadow 0.15s;
  display: flex; flex-direction: column; align-items: center;
}
.rv-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(0,0,0,0.15);
}
.rv-head {
  display: flex; align-items: center; gap: 0.35rem;
  width: 100%;
  margin-bottom: 0.3rem;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text);
  min-height: 1.6em;
}
.rv-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}
.rv-dot {
  display: inline-block;
  width: 0.55em; height: 0.55em;
  border-radius: 50%;
  flex-shrink: 0;
  border: 1px solid var(--dot-border);
}
.rv-radar {
  width: 100%;
  display: flex;
  justify-content: center;
}
.rv-radar svg { max-width: 100%; height: auto; }
.rv-badges {
  position: absolute;
  top: 0.3rem; right: 0.3rem;
  display: flex;
  gap: 0.1rem;
}
.rv-badge { font-size: 0.75rem; line-height: 1; }

/* ──────────────────────────────────────────────────────────────────────
 *  Comparison view (5th view)
 * ──────────────────────────────────────────────────────────────────── */
.cv-wrap {
  max-width: 980px;
  margin: 0 auto;
  padding: 0.8rem 1rem 2rem;
}
.cv-top {
  display: grid;
  grid-template-columns: minmax(280px, 380px) 1fr;
  gap: 1rem;
  margin-bottom: 1rem;
  align-items: start;
}
@media (max-width: 720px) {
  .cv-top { grid-template-columns: 1fr; }
}
.cv-radar-wrap {
  display: flex; justify-content: center;
  background: var(--t-bg-elev);
  border: 1px solid var(--t-border);
  border-radius: 14px;
  padding: 0.6rem;
}
.cv-radar-wrap svg { max-width: 100%; height: auto; }
.cv-legend {
  display: flex; flex-direction: column;
  gap: 0.35rem;
}
.cv-legend-item {
  display: flex; align-items: center; gap: 0.5rem;
  background: var(--t-bg-elev);
  border: 1px solid var(--t-border);
  border-radius: 8px;
  padding: 0.4rem 0.5rem;
}
.cv-legend-dot {
  display: inline-block;
  width: 0.85em; height: 0.85em;
  border-radius: 50%;
  border: 1px solid color-mix(in srgb, var(--t-fg) 25%, transparent);
  flex-shrink: 0;
}
.cv-legend-name {
  flex: 1;
  font-size: 0.82rem;
  color: var(--text, #e8e8f5);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cv-legend-rm {
  background: transparent;
  border: none;
  color: var(--dim, #9090b0);
  font-size: 1.1rem;
  font-family: inherit;
  cursor: pointer;
  padding: 0 0.3rem;
  line-height: 1;
  transition: color 0.12s;
}
.cv-legend-rm:hover { color: var(--t-negative); }

.cv-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--t-bg-elev);
  border: 1px solid var(--t-border);
  border-radius: 14px;
}
.cv-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.8rem;
}
.cv-th {
  background: var(--t-surface);
  color: var(--mid);
  font-weight: 700;
  text-align: center;
  padding: 0.55rem 0.5rem;
  border-bottom: 1px solid var(--border-strong);
  white-space: nowrap;
  position: sticky; top: 0;
  font-size: 0.78rem;
}
.cv-th-axis {
  text-align: left;
  position: sticky; left: 0;
  background: var(--t-surface);
  z-index: 1;
  min-width: 4em;
}
.cv-th-range {
  font-style: italic;
  color: var(--dim);
}
.cv-td {
  position: relative;
  padding: 0.45rem 0.6rem;
  border-bottom: 1px solid var(--border);
  text-align: center;
  min-width: 5em;
  font-family: 'JetBrains Mono', monospace;
}
.cv-td-range {
  padding: 0.45rem 0.6rem;
  border-bottom: 1px solid var(--border);
  text-align: center;
  font-family: 'JetBrains Mono', monospace;
  color: var(--dim);
  font-size: 0.78rem;
}
.cv-td.is-max { background: color-mix(in srgb, var(--t-emo) 12%, transparent); }
.cv-td.is-min { background: color-mix(in srgb, var(--t-cog) 10%, transparent); }
.cv-bar {
  position: absolute;
  left: 0; bottom: 0;
  height: 3px;
  width: var(--cv-bar-w);
  opacity: 0.55;
  pointer-events: none;
}
.cv-val { position: relative; }
.cv-td.muted { color: var(--dim); opacity: 0.6; }

.cv-hint { margin-top: 0.6rem; }

/* ── My Taste Overlay (YOU 表示) ──────────────────────────────────── */
.lv-you-row {
  position: sticky; top: 32px;
  background: linear-gradient(90deg, color-mix(in srgb, var(--t-accent-warm) 18%, transparent), color-mix(in srgb, var(--t-accent) 12%, transparent)) !important;
  font-weight: 700;
  z-index: 2;
}
.lv-you-row:hover { background: color-mix(in srgb, var(--t-accent) 16%, transparent) !important; }
.lv-you-dot {
  background: var(--t-accent) !important;
  border-color: var(--t-on-accent) !important;
}
.lv-you-cell { color: var(--text); }

.rv-you-card {
  background: color-mix(in srgb, var(--t-accent) 12%, transparent) !important;
  border-color: var(--t-accent-warm) !important;
  box-shadow: 0 4px 16px rgba(212,160,23,0.18);
  order: -1;  /* grid 内で先頭に */
}
.rv-you-card .rv-name strong { color: var(--t-accent-warm); }
.rv-you-dot {
  background: var(--t-accent) !important;
  border-color: var(--t-on-accent) !important;
}
.rv-you-meta {
  margin-top: 0.2rem;
  font-size: 0.65rem;
  color: var(--dim);
  font-family: 'JetBrains Mono', monospace;
}
