:root {
  --bg: #0f1117;
  --surface: #1a1d2e;
  --surface2: #252840;
  --border: #2d3155;
  --text: #e2e4f0;
  --text-muted: #8b8fa8;
  --accent: #5b7cf7;
  --accent-hover: #7b96ff;
  --blue: #3b82f6;
  --green: #22c55e;
  --red: #ef4444;
  --white-card: #c8cad4;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Hiragino Sans', 'Noto Sans JP', 'YuGothic', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

/* Header */
header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 20px;
  height: 56px;
  display: flex;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 100;
}
.header-inner { display: flex; align-items: baseline; gap: 12px; }
.logo { font-size: 20px; font-weight: 700; color: var(--accent); letter-spacing: 0.05em; }
.subtitle { font-size: 12px; color: var(--text-muted); }

/* Layout */
.layout { display: flex; min-height: calc(100vh - 56px); }

/* Sidebar */
.sidebar {
  width: 260px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 16px;
  position: sticky;
  top: 56px;
  height: calc(100vh - 56px);
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.sidebar-header h2 {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.btn-reset {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 3px 8px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 11px;
  transition: all 0.15s;
}
.btn-reset:hover { color: var(--text); border-color: var(--text-muted); }

/* Filter groups */
.filter-group { margin-bottom: 20px; }
.filter-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 7px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.filter-input {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 10px;
  color: var(--text);
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s;
}
.filter-input:focus { border-color: var(--accent); }
.filter-input::placeholder { color: var(--text-muted); }

/* Checkbox groups */
.check-group { display: flex; flex-wrap: wrap; gap: 5px; }
.check-label {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 4px 8px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  transition: all 0.15s;
  user-select: none;
  white-space: nowrap;
}
.check-label:hover { border-color: var(--accent); color: var(--accent-hover); }
.check-label input { display: none; }
.check-label.checked { background: var(--accent); border-color: var(--accent); color: white; }

/* Color dots */
.color-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex-shrink: 0; }
.color-青 { background: var(--blue); }
.color-緑 { background: var(--green); }
.color-赤 { background: var(--red); }
.color-白 { background: var(--white-card); }

/* Rarity badges */
.rarity {
  display: inline-block;
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 10px;
  font-weight: 700;
  white-space: nowrap;
}
.r-C   { background: #374151; color: #9ca3af; }
.r-U   { background: #1d4ed8; color: #bfdbfe; }
.r-R   { background: #7e22ce; color: #e9d5ff; }
.r-LR  { background: #a16207; color: #fef08a; }
.r-LRp { background: #c2410c; color: #fed7aa; }
.r-LRpp{ background: #991b1b; color: #fecaca; }
.r-P   { background: #be185d; color: #fbcfe8; }

/* Ranges */
.ranges { display: flex; flex-direction: column; gap: 6px; }
.range-row { display: flex; align-items: center; gap: 6px; }
.range-row > span:first-child { width: 38px; font-size: 11px; color: var(--text-muted); flex-shrink: 0; }
.range-row > span:last-child { color: var(--text-muted); font-size: 12px; }
.range-row input {
  width: 50px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px 6px;
  color: var(--text);
  font-size: 12px;
  text-align: center;
  outline: none;
}
.range-row input:focus { border-color: var(--accent); }

/* Main */
.main { flex: 1; padding: 16px; min-width: 0; }
.main-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.result-count { color: var(--text-muted); font-size: 13px; flex: 1; }
.btn-filter-toggle {
  display: none;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
}

/* Sort + view controls */
.controls-right { display: flex; align-items: center; gap: 8px; }
.sort-select {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 5px 8px;
  border-radius: 6px;
  font-size: 12px;
  outline: none;
  cursor: pointer;
}
.sort-select:focus { border-color: var(--accent); }
.view-toggle { display: flex; gap: 2px; }
.view-btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  width: 32px;
  height: 32px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  transition: all 0.15s;
}
.view-btn:hover { color: var(--text); border-color: var(--text-muted); }
.view-btn.active { background: var(--accent); border-color: var(--accent); color: white; }

/* Card grid */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
}
.card-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  transition: all 0.15s;
}
.card-item:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: 0 4px 20px rgba(91, 124, 247, 0.2);
}
.card-thumb {
  aspect-ratio: 215 / 300;
  background: var(--surface2);
  overflow: hidden;
  position: relative;
}
.card-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.2s;
}
.card-item:hover .card-thumb img { transform: scale(1.03); }
.no-image {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 11px;
}
.card-info { padding: 8px; }
.card-name {
  font-size: 12px;
  font-weight: 600;
  line-height: 1.3;
  margin-bottom: 5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card-meta { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.card-no { font-size: 10px; color: var(--text-muted); }

/* List view table */
.card-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.card-table th {
  background: var(--surface2);
  border-bottom: 2px solid var(--border);
  padding: 8px 10px;
  text-align: left;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
}
.card-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.card-table tr { cursor: pointer; transition: background 0.1s; }
.card-table tr:hover td { background: var(--surface2); }
.card-table .list-no { color: var(--text-muted); font-size: 11px; white-space: nowrap; }
.card-table .list-name { font-weight: 600; }
.card-table .list-stat { text-align: center; color: var(--text); font-weight: 600; }
.card-table .list-stat.empty { color: var(--text-muted); }
.card-table .list-colors { display: flex; gap: 3px; }

/* Copy URL button in modal */
.btn-copy-url {
  display: block;
  width: 100%;
  margin-top: 10px;
  padding: 6px;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 6px;
  font-size: 11px;
  cursor: pointer;
  text-align: center;
  transition: all 0.15s;
}
.btn-copy-url:hover { border-color: var(--accent); color: var(--accent); }
.btn-copy-url.copied { border-color: #22c55e; color: #22c55e; }

/* Loading / empty */
.loading {
  grid-column: 1 / -1;
  text-align: center;
  padding: 80px 20px;
  color: var(--text-muted);
  font-size: 15px;
}

/* Modal */
.modal-bg {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-bg.open { display: flex; }
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  max-width: 720px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 14px;
  z-index: 10;
  transition: all 0.15s;
}
.modal-close:hover { background: var(--border); }
.modal-body { display: flex; gap: 24px; padding: 24px; }

/* Modal image col */
.modal-image-col { flex-shrink: 0; width: 170px; }
.modal-image-col img { width: 100%; border-radius: 8px; display: block; }
.variant-tabs { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; }
.variant-btn {
  padding: 3px 8px;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 4px;
  font-size: 11px;
  cursor: pointer;
  transition: all 0.15s;
}
.variant-btn:hover { border-color: var(--accent); color: var(--accent); }
.variant-btn.active { border-color: var(--accent); color: var(--accent); background: rgba(91,124,247,0.1); }

/* Modal detail col */
.modal-detail-col { flex: 1; min-width: 0; }
.modal-card-name { font-size: 22px; font-weight: 700; margin-bottom: 4px; line-height: 1.3; }
.modal-card-no { font-size: 13px; color: var(--text-muted); margin-bottom: 16px; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 16px;
}
.stat-box {
  background: var(--surface2);
  border-radius: 6px;
  padding: 8px 4px;
  text-align: center;
}
.stat-label { font-size: 10px; color: var(--text-muted); display: block; margin-bottom: 2px; }
.stat-value { font-size: 20px; font-weight: 700; }

.detail-row { display: flex; gap: 8px; margin-bottom: 8px; font-size: 13px; align-items: flex-start; }
.detail-key { color: var(--text-muted); flex-shrink: 0; width: 90px; padding-top: 1px; }
.detail-val { flex: 1; }

.effect-box {
  background: var(--surface2);
  border-radius: 8px;
  padding: 14px;
  font-size: 13px;
  line-height: 1.8;
  margin-top: 12px;
  white-space: pre-wrap;
  word-break: break-all;
}

/* Mobile */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 150;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    padding-top: 64px;
    width: 280px;
    box-shadow: 4px 0 20px rgba(0,0,0,0.5);
  }
  .sidebar.open { transform: translateX(0); }
  .btn-filter-toggle { display: block; }
  .modal-body { flex-direction: column; padding: 16px; }
  .modal-image-col { width: 130px; margin: 0 auto; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .card-grid { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; }
  .card-table th:nth-child(n+5):nth-child(-n+8) { display: none; }
  .card-table td:nth-child(n+5):nth-child(-n+8) { display: none; }
}
