/* ===================================
   基本設定
   =================================== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Bitter', serif, 'Hiragino Kaku Gothic ProN', 'ヒラギノ角ゴ ProN W3', Meiryo, メイリオ, sans-serif;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  min-height: 100vh;
  color: #333;
  line-height: 1.6;
}

.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 15px;
}

/* ===================================
   ヘッダー
   =================================== */
header {
  background: white;
  padding: 20px;
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  margin-bottom: 20px;
  text-align: center;
}

header h1 {
  font-size: clamp(1.2rem, 4vw, 2rem);
  color: #667eea;
  margin-bottom: 10px;
  word-wrap: break-word;
}

header h2 {
  font-size: clamp(0.9rem, 2.5vw, 1.3rem);
  color: #764ba2;
  margin-bottom: 10px;
}

header p {
  font-size: clamp(0.85rem, 2vw, 1rem);
  color: #666;
}

/* ===================================
   メインコンテンツエリア
   =================================== */
.main-content {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* ===================================
   サイドバー
   =================================== */
.sidebar {
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.card {
  background: white;
  padding: 20px;
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.card h2,
.card h3 {
  color: #667eea;
  margin-bottom: 15px;
  font-size: clamp(1rem, 2.5vw, 1.3rem);
}

.card h4 {
  font-size: clamp(0.9rem, 2vw, 1.1rem);
  margin-bottom: 10px;
}

/* データ選択 */
.data-selector {
  margin-bottom: 20px;
}

.data-selector label {
  display: block;
  margin-bottom: 8px;
  font-weight: bold;
  font-size: clamp(0.9rem, 2vw, 1rem);
}

.data-select {
  width: 100%;
  padding: 12px;
  border: 2px solid #e0e0e0;
  border-radius: 8px;
  font-size: clamp(0.85rem, 2vw, 1rem);
  background: white;
  cursor: pointer;
  transition: border-color 0.3s;
}

.data-select:hover,
.data-select:focus {
  border-color: #667eea;
  outline: none;
}

/* ファイルアップロード */
.file-upload-section {
  margin: 20px 0;
  padding: 15px;
  background: #f8f9fa;
  border-radius: 8px;
}

.file-upload-section h3 {
  font-size: clamp(0.9rem, 2vw, 1.1rem);
  margin-bottom: 12px;
  color: #555;
}

.file-input {
  display: none;
}

.file-label {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 20px;
  background: #667eea;
  color: white;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.3s;
  font-size: clamp(0.85rem, 2vw, 1rem);
  justify-content: center;
}

.file-label:hover {
  background: #5568d3;
}

.file-icon {
  font-size: 1.5em;
}

/* 閾値コントロール */
.threshold-control {
  margin: 20px 0;
}

.threshold-control label {
  display: block;
  margin-bottom: 10px;
  font-weight: bold;
  font-size: clamp(0.9rem, 2vw, 1rem);
}

.slider-container {
  display: flex;
  align-items: center;
  gap: 15px;
  margin-bottom: 8px;
}

#threshold {
  flex: 1;
  height: 8px;
  border-radius: 4px;
  background: #e0e0e0;
  outline: none;
  -webkit-appearance: none;
}

#threshold::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #667eea;
  cursor: pointer;
}

#threshold::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #667eea;
  cursor: pointer;
  border: none;
}

#thresholdValue {
  font-weight: bold;
  color: #667eea;
  font-size: clamp(0.9rem, 2vw, 1.1rem);
  min-width: 50px;
  text-align: center;
}

.threshold-control small {
  display: block;
  color: #666;
  font-size: clamp(0.75rem, 1.8vw, 0.85rem);
}

/* ボタン */
.btn-primary,
.btn-secondary {
  width: 100%;
  padding: 14px 24px;
  border: none;
  border-radius: 8px;
  font-size: clamp(0.9rem, 2vw, 1.1rem);
  font-weight: bold;
  cursor: pointer;
  transition: all 0.3s;
  margin: 10px 0;
  touch-action: manipulation;
}

.btn-primary {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
}

.btn-primary:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(102, 126, 234, 0.4);
}

.btn-primary:disabled {
  background: #ccc;
  cursor: not-allowed;
}

.btn-secondary {
  background: #f0f0f0;
  color: #333;
}

.btn-secondary:hover {
  background: #e0e0e0;
  transform: translateY(-2px);
}

/* ステータスメッセージ */
.status-message {
  margin-top: 15px;
  padding: 12px;
  border-radius: 8px;
  font-size: clamp(0.85rem, 2vw, 0.95rem);
  text-align: center;
  display: none;
}

.status-message.success {
  background: #d4edda;
  color: #155724;
  border: 1px solid #c3e6cb;
  display: block;
}

.status-message.error {
  background: #f8d7da;
  color: #721c24;
  border: 1px solid #f5c6cb;
  display: block;
}

/* 統計ボックス */
.stats-box {
  margin-top: 20px;
  padding: 15px;
  background: #f8f9fa;
  border-radius: 8px;
}

.stat-item {
  display: flex;
  justify-content: space-between;
  margin: 8px 0;
  font-size: clamp(0.85rem, 2vw, 0.95rem);
}

.stat-label {
  font-weight: bold;
  color: #555;
}

.stat-value {
  color: #667eea;
  font-weight: bold;
}

/* 使い方 */
.controls-how2 {
  list-style: decimal inside;
  padding-left: 20px;
}

/* 操作方法 */
.controls-list {
  list-style: none;
  padding: 0;
}

.controls-list li {
  padding: 8px 0;
  border-bottom: 1px solid #f0f0f0;
  font-size: clamp(0.85rem, 2vw, 0.95rem);
}

.controls-list li:last-child {
  border-bottom: none;
}

.controls-list strong {
  color: #667eea;
}

/* ===================================
   ネットワーク表示エリア
   =================================== */
.network-area {
  flex: 1;
}

.network-container {
  background: white;
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  overflow: hidden;
  height: 500px;
  position: relative;
}

.placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: #999;
}

.placeholder-icon {
  font-size: clamp(3rem, 8vw, 5rem);
  margin-bottom: 20px;
}

.placeholder p {
  font-size: clamp(0.9rem, 2.5vw, 1.2rem);
}

#network svg {
  width: 100%;
  height: 100%;
  display: block;
}

/* ===================================
   詳細パネル
   =================================== */
.detail-panel {
  position: fixed;
  top: 0;
  right: -100%;
  width: 90%;
  max-width: 400px;
  height: 100%;
  background: white;
  box-shadow: -4px 0 16px rgba(0, 0, 0, 0.2);
  transition: right 0.3s ease;
  z-index: 1000;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.detail-panel.active {
  right: 0;
}

.close-btn {
  position: absolute;
  top: 15px;
  right: 15px;
  background: #f0f0f0;
  border: none;
  border-radius: 50%;
  width: 36px;
  height: 36px;
  font-size: 20px;
  cursor: pointer;
  transition: background 0.3s;
  z-index: 1;
  touch-action: manipulation;
}

.close-btn:hover {
  background: #e0e0e0;
}

.detail-header {
  padding: 20px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
}

.detail-header h3 {
  font-size: clamp(1.1rem, 3vw, 1.5rem);
  margin-bottom: 8px;
}

.detail-id {
  font-size: clamp(0.85rem, 2vw, 0.95rem);
  opacity: 0.9;
}

.detail-image {
  padding: 20px;
  text-align: center;
  background: #f8f9fa;
}

.detail-image img {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.detail-content {
  padding: 20px;
}

.detail-content p {
  margin: 10px 0;
  font-size: clamp(0.85rem, 2vw, 0.95rem);
  line-height: 1.6;
}

.detail-content strong {
  color: #667eea;
  display: inline-block;
  min-width: 100px;
}

/* 詳細コンテンツのプロパティボックス */
.detail-content .property {
  margin-bottom: 18px;
  padding: 15px;
  background: #f8f9ff;
  border-radius: 8px;
  border-left: 4px solid var(--primary-color);
  transition: all 0.2s ease;
}

.detail-content .property:hover {
  background: #eef1ff;
  transform: translateX(5px);
}

.detail-content .property strong {
  color: var(--primary-color);
  display: block;
  margin-bottom: 6px;
  font-size: 0.95em;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.detail-content .property div {
  color: #555;
  word-wrap: break-word;
  font-size: clamp(0.85rem, 2vw, 0.95rem);
}

/* ===================================
   フッター
   =================================== */
footer {
  background: rgba(255, 255, 255, 0.95);
  padding: 20px;
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  margin-top: 20px;
  text-align: center;
}

footer p {
  font-size: clamp(0.75rem, 2vw, 0.9rem);
  color: #666;
  line-height: 1.6;
}

footer a {
  color: #667eea;
  text-decoration: none;
  transition: color 0.3s;
}

footer a:hover {
  color: #764ba2;
  text-decoration: underline;
}

/* ===================================
   レスポンシブ対応
   =================================== */

/* タブレット（768px以上） */
@media (min-width: 768px) {
  .container {
    padding: 20px;
  }

  header {
    padding: 30px;
  }

  .main-content {
    flex-direction: row;
    align-items: flex-start;
  }

  .sidebar {
    width: 350px;
    flex-shrink: 0;
  }

  .network-container {
    height: 600px;
  }

  .detail-panel {
    width: 450px;
  }
}

/* デスクトップ（1024px以上） */
@media (min-width: 1024px) {
  .container {
    padding: 30px;
  }

  .main-content {
    gap: 30px;
  }

  .sidebar {
    width: 380px;
  }

  .network-container {
    height: 700px;
  }

  .card {
    padding: 25px;
  }
}

/* 大画面（1400px以上） */
@media (min-width: 1400px) {
  .network-container {
    height: 800px;
  }
}

/* 小画面（480px以下） */
@media (max-width: 480px) {
  .container {
    padding: 10px;
  }

  header {
    padding: 15px;
  }

  .card {
    padding: 15px;
  }

  .network-container {
    height: 400px;
  }

  .detail-panel {
    width: 100%;
    max-width: 100%;
  }
}

/* タッチデバイス向けの調整 */
@media (hover: none) and (pointer: coarse) {
  .btn-primary,
  .btn-secondary,
  .close-btn,
  .file-label {
    min-height: 44px; /* タップしやすいサイズ */
  }

  .data-select {
    min-height: 44px;
  }
}

/* 横向きモバイル */
@media (max-width: 900px) and (orientation: landscape) {
  .network-container {
    height: 400px;
  }
  
  .detail-panel {
    width: 50%;
  }
}

/* ダークモード対応（オプション） */
@media (prefers-color-scheme: dark) {
  body {
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
  }
  
  .card,
  .network-container,
  footer {
    background: #2d2d44;
    color: #e0e0e0;
  }
  
  .data-select {
    background: #1a1a2e;
    color: #e0e0e0;
    border-color: #444;
  }
  
  .file-upload-section,
  .stats-box {
    background: #1a1a2e;
  }
}

/* ===================================
   SVG ネットワークスタイル
   =================================== */

/* ノードのスタイル */
.node circle {
  stroke: #fff;
  stroke-width: 3px;
  cursor: pointer;
  transition: all 0.2s ease;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2));
}

.node:hover circle {
  stroke-width: 4px;
  stroke: var(--primary-color);
  filter: drop-shadow(0 4px 8px rgba(102, 126, 234, 0.4));
}

.node.selected circle {
  stroke: var(--secondary-color);
  stroke-width: 5px;
  filter: drop-shadow(0 4px 8px rgba(118, 75, 162, 0.5));
}

.node text {
  font-size: 13px;
  font-weight: 600;
  pointer-events: none;
  text-anchor: middle;
  fill: #333;
  text-shadow: 0 1px 2px rgba(255, 255, 255, 0.8);
}

/* モバイルではノードのテキストを少し小さく */
@media (max-width: 768px) {
  .node text {
    font-size: 11px;
  }
}

/* リンクのスタイル */
.link {
  stroke: #999;
  stroke-opacity: 0.5;
  transition: all 0.2s ease;
}

.link:hover {
  stroke: var(--primary-color);
  stroke-opacity: 0.9;
  stroke-width: 3px;
}

.link.highlighted {
  stroke: var(--secondary-color);
  stroke-opacity: 1;
  stroke-width: 3px;
}

/* ===================================
   アニメーション
   =================================== */

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes fadeInDown {
  from {
    opacity: 0;
    transform: translateY(-20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes pulse {
  0%, 100% {
    transform: scale(1);
    opacity: 0.3;
  }
  50% {
    transform: scale(1.05);
    opacity: 0.5;
  }
}

/* カードにフェードインアニメーションを適用 */
.card {
  animation: fadeIn 0.6s ease;
}

/* ヘッダーにアニメーションを適用 */
header h1 {
  animation: fadeInDown 0.6s ease;
}

header h2 {
  animation: fadeInUp 0.6s ease 0.2s both;
}

header p {
  animation: fadeInUp 0.6s ease 0.3s both;
}

/* ネットワークコンテナにアニメーション */
.network-container {
  animation: fadeIn 0.6s ease 0.3s both;
}

/* プレースホルダーアイコンにパルスアニメーション */
.placeholder-icon {
  animation: pulse 2s ease-in-out infinite;
}

/* ステータスメッセージにスライドインアニメーション */
.status-message {
  animation: slideIn 0.3s ease;
}

/* ===================================
   スクロールバースタイル
   =================================== */

/* 詳細パネルのスクロールバー */
.detail-panel::-webkit-scrollbar {
  width: 8px;
}

.detail-panel::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: 4px;
}

.detail-panel::-webkit-scrollbar-thumb {
  background: #667eea;
  border-radius: 4px;
  transition: background 0.3s;
}

.detail-panel::-webkit-scrollbar-thumb:hover {
  background: #764ba2;
}

/* メインコンテンツのスクロールバー（必要に応じて） */
body::-webkit-scrollbar {
  width: 10px;
}

body::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.1);
}

body::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.3);
  border-radius: 5px;
}

body::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.5);
}

/* ===================================
   CSS変数の定義
   =================================== */

:root {
  --primary-color: #667eea;
  --secondary-color: #764ba2;
  --background-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  --card-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  --card-shadow-hover: 0 8px 15px rgba(0, 0, 0, 0.2);
}

/* ダークモード時の変数上書き */
@media (prefers-color-scheme: dark) {
  :root {
    --primary-color: #8b9eff;
    --secondary-color: #9d7bc5;
  }
}

/* ===================================
   追加のインタラクション効果
   =================================== */

/* カードホバー効果 */
.card:hover {
  box-shadow: var(--card-shadow-hover);
  transform: translateY(-2px);
}

/* 閉じるボタンのホバー効果 */
.close-btn:hover {
  background: var(--primary-color);
  color: white;
  transform: rotate(90deg);
}

/* 詳細コンテンツのプロパティホバー効果 */
.detail-content .property {
  transition: all 0.2s ease;
}

.detail-content .property:hover {
  background: #eef1ff;
  transform: translateX(5px);
}

/* ファイルラベルのホバー効果を強化 */
.file-label:hover {
  background: #eef1ff;
  border-color: var(--secondary-color);
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(102, 126, 234, 0.2);
}

/* 印刷用スタイル */
@media print {
  body {
    background: white;
  }
  
  .sidebar,
  footer,
  .detail-panel {
    display: none;
  }
  
  .network-container {
    height: auto;
    page-break-inside: avoid;
  }
  
  /* ネットワークのノードとリンクを印刷時にも表示 */
  .node,
  .link {
    print-color-adjust: exact;
    -webkit-print-color-adjust: exact;
  }
}
