/* =========================================================
   ComfyUI Workflow Share — スタイルシート
   デザインコンセプト: ノードエディタのキャンバスの延長線上にある
   カタログ。ドットグリッド背景、配線を思わせるティール、
   ノードのハイライトを思わせるアンバーの2色を差し色に使用。
   ========================================================= */

:root {
  --bg:        #14161a;
  --panel:     #1c1f26;
  --panel-2:   #22262f;
  --line:      #2a2f3a;
  --text:      #e8eaed;
  --muted:     #8b93a1;
  --teal:      #4fd1c5;
  --amber:     #f2a65a;
  --danger:    #e0666a;
  --radius:    10px;
  --font-head: 'Space Grotesk', 'Hiragino Sans', sans-serif;
  --font-body: 'Inter', 'Hiragino Sans', sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  line-height: 1.7;
  background-image:
    radial-gradient(circle, #262b34 1px, transparent 1px);
  background-size: 22px 22px;
}

a { color: var(--teal); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3, h4 {
  font-family: var(--font-head);
  font-weight: 600;
  line-height: 1.3;
  margin: 0 0 .5em;
}

p { margin: 0 0 1em; color: var(--text); }

.container {
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 20px;
}

/* --- ヘッダー --- */
.site-header {
  border-bottom: 1px solid var(--line);
  background: rgba(20, 22, 26, 0.9);
  backdrop-filter: blur(6px);
  position: sticky;
  top: 0;
  z-index: 50;
}
.site-header .inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
}
.brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
  font-family: var(--font-head);
  font-size: 20px;
  color: var(--text);
}
.brand .dot { color: var(--teal); }
.brand:hover { text-decoration: none; }
.nav-links { display: flex; gap: 18px; align-items: center; }
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
  font-family: var(--font-body);
  font-size: 14px;
  transition: border-color .15s ease, transform .1s ease;
}
.btn:hover { border-color: var(--teal); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn-primary {
  background: var(--teal);
  border-color: var(--teal);
  color: #0c1210;
  font-weight: 600;
}
.btn-primary:hover { border-color: var(--teal); opacity: .92; }
.btn-danger { border-color: var(--danger); color: var(--danger); background: transparent; }
.btn-danger:hover { background: rgba(224,102,106,.1); }
.btn-small { padding: 6px 12px; font-size: 13px; }

/* --- ヒーロー --- */
.hero {
  padding: 64px 0 40px;
  border-bottom: 1px solid var(--line);
}
.hero h1 {
  font-size: 40px;
  max-width: 640px;
  letter-spacing: -.01em;
}
.hero p.lead {
  color: var(--muted);
  max-width: 560px;
  font-size: 17px;
}
.hero-actions { display: flex; gap: 12px; margin-top: 20px; }

/* --- カテゴリーグリッド --- */
.section-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin: 48px 0 20px;
}
.section-title h2 { font-size: 22px; margin: 0; }
.section-title .muted { color: var(--muted); font-size: 14px; }

.category-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
}
@media (max-width: 900px) { .category-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 520px) { .category-grid { grid-template-columns: 1fr; } }

.category-card {
  display: block;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  position: relative;
  overflow: hidden;
  transition: border-color .15s ease, transform .12s ease;
}
.category-card:hover { border-color: var(--teal); text-decoration: none; transform: translateY(-2px); }
.category-card .num {
  font-family: var(--font-head);
  color: var(--line);
  font-size: 28px;
  position: absolute;
  right: 14px;
  top: 8px;
}
.category-card h3 { font-size: 16px; margin: 0 0 6px; color: var(--text); }
.category-card .count { color: var(--muted); font-size: 13px; }

/* --- ワークフローカードグリッド --- */
.workflow-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 18px;
}
@media (max-width: 860px) { .workflow-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 560px) { .workflow-grid { grid-template-columns: 1fr; } }

.workflow-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--panel);
  display: flex;
  flex-direction: column;
  transition: border-color .15s ease;
}
.workflow-card:hover { border-color: var(--teal); }
.workflow-card .thumb {
  aspect-ratio: 4 / 3;
  background: var(--panel-2);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.workflow-card .thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.workflow-card .thumb .placeholder { color: var(--line); font-family: var(--font-head); font-size: 13px; }
.workflow-card .body { padding: 14px 16px 16px; flex: 1; display: flex; flex-direction: column; }
.workflow-card h3 { font-size: 15px; margin: 0 0 6px; }
.workflow-card h3 a { color: var(--text); }
.workflow-card .desc {
  color: var(--muted);
  font-size: 13px;
  margin: 0 0 10px;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.workflow-card .meta {
  margin-top: auto;
  font-size: 12px;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
}

/* --- ページネーション --- */
.pagination {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin: 36px 0;
  flex-wrap: wrap;
}
.pagination a, .pagination span {
  min-width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
}
.pagination a:hover { border-color: var(--teal); text-decoration: none; }
.pagination .current { background: var(--teal); color: #0c1210; border-color: var(--teal); font-weight: 600; }
.pagination .disabled { color: var(--line); border-color: var(--line); }

/* --- フォーム --- */
.form-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 28px;
  max-width: 720px;
}
.field { margin-bottom: 20px; }
.field label { display: block; font-size: 14px; margin-bottom: 6px; color: var(--text); }
.field .hint { color: var(--muted); font-size: 12px; margin-top: 6px; }
input[type=text], input[type=password], input[type=file], textarea, select {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14px;
}
textarea { resize: vertical; min-height: 110px; }
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--teal);
}
.category-radio-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}
.category-radio {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  cursor: pointer;
}
.category-radio:has(input:checked) { border-color: var(--teal); background: rgba(79,209,197,.06); }
.category-radio input { width: auto; }

.alert {
  padding: 12px 16px;
  border-radius: 8px;
  margin-bottom: 20px;
  font-size: 14px;
}
.alert-error { background: rgba(224,102,106,.1); border: 1px solid var(--danger); color: #ffb3b5; }
.alert-success { background: rgba(79,209,197,.1); border: 1px solid var(--teal); color: var(--teal); }

/* --- ギャラリー（ワークフロー詳細ページ） --- */
.gallery-main {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--panel-2);
  aspect-ratio: 16/10;
  display: flex;
  align-items: center;
  justify-content: center;
}
.gallery-main img { width: 100%; height: 100%; object-fit: contain; background: #0d0f12; }
.gallery-thumbs {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  flex-wrap: wrap;
}
.gallery-thumbs img {
  width: 72px;
  height: 54px;
  object-fit: cover;
  border-radius: 6px;
  border: 2px solid transparent;
  cursor: pointer;
}
.gallery-thumbs img.active { border-color: var(--teal); }

/* --- ワークフロービューア --- */
.wf-viewer-wrap {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #0d0f12;
  position: relative;
  overflow: hidden;
}
.wf-viewer-toolbar {
  display: flex;
  gap: 8px;
  padding: 10px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  align-items: center;
  font-size: 13px;
  color: var(--muted);
}
.wf-viewer-toolbar .spacer { flex: 1; }
.wf-canvas-host {
  display: block;                 /* 追加: canvasのinline-block由来の余白ズレを解消 */
  width: 100%;
  height: min(70vh, 640px);       /* 変更: 固定520px→画面の高さに応じて可変（上限640px） */
  min-height: 360px;              /* 追加: 極端に低くならないよう下限を確保 */
  cursor: grab;
  touch-action: none;
}
.wf-canvas-host:active { cursor: grabbing; }
.wf-viewer-toolbar {
  display: flex;
  gap: 8px;
  padding: 10px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  align-items: center;
  font-size: 13px;
  color: var(--muted);
}
.wf-viewer-toolbar .spacer { flex: 1; }
.wf-canvas-host { width: 100%; height: 520px; cursor: grab; touch-action: none; }
.wf-canvas-host:active { cursor: grabbing; }

/* --- 詳細ページのアクション行 --- */
.detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 18px 0 8px;
}
.share-x     { border-color: #1d9bf0; color: #1d9bf0; }
.share-facebook { border-color: #1877f2; color: #1877f2; }
.share-threads  { border-color: #e8e8e8; color: #e8e8e8; }

.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.6);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}
.modal-backdrop.open { display: flex; }
.modal-box {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  max-width: 640px;
  width: 100%;
}
.modal-box h3 { margin-top: 0; }
.modal-box textarea {
  font-family: 'Space Mono', monospace;
  font-size: 12.5px;
  min-height: 90px;
}
.modal-close { float: right; cursor: pointer; color: var(--muted); background:none; border:none; font-size: 20px; }

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 100px;
  border: 1px solid var(--line);
  font-size: 12px;
  color: var(--muted);
}

.meta-row { display:flex; gap: 14px; align-items:center; color: var(--muted); font-size: 13px; margin-bottom: 18px; flex-wrap: wrap; }

.thumb-manage-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  margin-top: 8px;
}
.thumb-manage-item { position: relative; }
.thumb-manage-item img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); }
.thumb-manage-item label {
  position: absolute; top: 4px; right: 4px;
  background: rgba(20,22,26,.85);
  border-radius: 4px;
  padding: 2px 4px;
  font-size: 11px;
  display: flex; gap: 4px; align-items: center;
}

.site-footer {
  border-top: 1px solid var(--line);
  margin-top: 60px;
  padding: 30px 0;
  color: var(--muted);
  font-size: 13px;
}

@media (max-width: 640px) {
  .hero h1 { font-size: 30px; }
  .form-panel { padding: 20px; }
  .category-radio-grid { grid-template-columns: 1fr; }
}
