/* ── Reset & Variables ───────────────────────────────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #0d0f14;
  --bg-card: #161a23;
  --bg-row: #1a1f2c;
  --bg-hover: #1f2535;
  --border: #252d3d;
  --accent: #7b6cff;
  --accent2: #5bc8af;
  --text: #e8eaf0;
  --text-muted: #8891a8;
  --red: #ff6b6b;
  --green: #51cf66;
  --font: 'Segoe UI', 'Hiragino Sans', Meiryo, sans-serif;
  --radius: 10px;
}

html {
  font-size: 14px;
  scroll-behavior: smooth;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  min-height: 100vh;
}

.hidden {
  display: none !important;
}

/* ── Header ──────────────────────────────────────────────────────────────── */
header {
  background: linear-gradient(135deg, #0a0c12 0%, #151929 100%);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 60px;
}

h1 {
  font-size: 1.3rem;
  letter-spacing: 0.05em;
}

h1 span {
  color: var(--accent);
}

.site-logo {
  height: 1.3rem;
  width: auto;
  vertical-align: middle;
  margin-right: 8px;
  border-radius: 4px;
  object-fit: contain;
}

.status-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* ── Language Toggle ─────────────────────────────────────────────────────── */
.lang-toggle {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}

.lang-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  padding: 4px 10px;
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  transition: background 0.15s, color 0.15s;
}

.lang-btn:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.lang-btn.active {
  background: var(--accent);
  color: #fff;
}

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn-primary {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 6px 16px;
  cursor: pointer;
  font-size: 0.85rem;
  transition: background 0.15s, opacity 0.15s;
}

.btn-primary:hover {
  background: #6a5ce8;
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-link {
  background: none;
  border: 1px solid var(--border);
  color: var(--accent);
  border-radius: 6px;
  padding: 4px 12px;
  cursor: pointer;
  font-size: 0.8rem;
  transition: background 0.15s;
}

.btn-link:hover {
  background: var(--bg-hover);
}

.btn-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
  line-height: 1;
  transition: color 0.15s;
}

.btn-close:hover {
  color: var(--text);
}

/* ── Card ────────────────────────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

/* ── Main Layout ─────────────────────────────────────────────────────────── */
main {
  max-width: 1200px;
  margin: 24px auto;
  padding: 0 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ── Category Filter ─────────────────────────────────────────────────────── */
.category-filter {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px 0 2px;
}

.cat-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.sub-row {
  padding-left: 4px;
}

.cat-btn {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 20px;
  padding: 5px 14px;
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 500;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  white-space: nowrap;
}

.cat-btn:hover {
  background: var(--bg-hover);
  color: var(--text);
  border-color: var(--accent);
}

.cat-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.sub-btn {
  font-size: 0.78rem;
  padding: 3px 11px;
  border-color: color-mix(in srgb, var(--border) 60%, transparent);
}

.sub-btn.active {
  background: var(--accent2);
  border-color: var(--accent2);
  color: #fff;
}

/* ── Controls ────────────────────────────────────────────────────────────── */
.controls {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 16px;
  flex-wrap: wrap;
}

.search-wrap {
  flex: 1;
  min-width: 200px;
  position: relative;
  display: flex;
  align-items: center;
}

#search-input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 8px 34px 8px 12px;
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.15s;
}

#search-input:focus {
  border-color: var(--accent);
}

.search-clear {
  position: absolute;
  right: 8px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
  transition: color 0.15s, background 0.15s;
}

.search-clear:hover {
  color: var(--text);
  background: var(--bg-hover);
}

.sort-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-muted);
  font-size: 0.85rem;
}

#sort-select {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 6px 10px;
  cursor: pointer;
  font-size: 0.85rem;
}

/* ── Loading ─────────────────────────────────────────────────────────────── */
.loading,
.no-data {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  gap: 16px;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ── Table ───────────────────────────────────────────────────────────────── */
.table-section {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

thead tr {
  background: #12151f;
}

th {
  padding: 12px 14px;
  text-align: right;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

th.col-name,
th.col-img {
  text-align: left;
}

th.sortable {
  cursor: pointer;
  user-select: none;
}

th.sortable:hover {
  color: var(--text);
}

tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
  cursor: pointer;
}

tbody tr:last-child {
  border-bottom: none;
}

tbody tr:hover {
  background: var(--bg-hover);
}

td {
  padding: 10px 14px;
  vertical-align: middle;
  text-align: right;
}

td.col-name {
  text-align: left;
  max-width: 320px;
}

td.col-img {
  text-align: left;
  width: 44px;
  padding: 6px 8px 6px 14px;
}

/* ── Grade colors ────────────────────────────────────────────────────────── */
.grade-none {
  --grade-color: #9e9e9e;
}

.grade-green {
  --grade-color: #51cf66;
}

.grade-blue {
  --grade-color: #4dabf7;
}

.grade-magenta {
  --grade-color: #cc5de8;
}

.grade-orange {
  --grade-color: #ff922b;
}

.grade-red {
  --grade-color: #ff6b6b;
}

.item-img-wrap {
  width: 36px;
  height: 36px;
  border: 2px solid var(--grade-color, var(--border));
  border-radius: 6px;
  flex-shrink: 0;
  background: color-mix(in srgb, var(--grade-color, #1a1f2c) 12%, #0d0f14);
  display: flex;
  align-items: center;
  justify-content: center;
}

.item-img {
  width: 30px;
  height: 30px;
  object-fit: contain;
  border-radius: 3px;
}

.item-name {
  font-size: 0.9rem;
}

.item-name .tag {
  display: inline-block;
  font-size: 0.65rem;
  padding: 1px 5px;
  border-radius: 3px;
  margin-left: 6px;
  vertical-align: middle;
}

.tag-crypto {
  background: #2a3a5e;
  color: #6badf7;
}

.price-jpy {
  font-weight: 600;
  color: var(--text);
}

.price-secondary {
  font-weight: 400;
  font-size: 0.85rem;
}

.price-usdt {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.count-badge {
  display: inline-block;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 2px 10px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.row-count {
  text-align: right;
  padding: 8px 14px;
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* ── Modal ───────────────────────────────────────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(2px);
}

.modal-box {
  position: relative;
  z-index: 1;
  width: min(760px, calc(100vw - 32px));
  max-height: calc(100vh - 64px);
  overflow-y: auto;
  padding: 24px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.modal-header h2 {
  font-size: 1.1rem;
}

.modal-title-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.modal-item-img {
  width: 44px;
  height: 44px;
  object-fit: contain;
  border-radius: 6px;
  flex-shrink: 0;
  border: 2px solid var(--grade-color, var(--border));
  background: color-mix(in srgb, var(--grade-color, #1a1f2c) 12%, #0d0f14);
}

/* ── Modal item info (grade + basic options) ─────────────────────────────── */
.modal-item-info {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.grade-badge {
  display: inline-block;
  padding: 3px 12px;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: #fff;
  background: var(--grade-color, #444);
  flex-shrink: 0;
}

.basic-options {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.basic-option {
  display: flex;
  align-items: center;
  gap: 5px;
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 3px 10px;
  font-size: 0.78rem;
}

.opt-name {
  color: var(--text-muted);
}

.opt-value {
  color: var(--text);
  font-weight: 600;
}

.modal-chart-wrap {
  position: relative;
  height: 260px;
  margin-bottom: 20px;
}

.modal-listings h3 {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.listings-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  table-layout: fixed;
}

.listings-table th {
  text-align: right;
  color: var(--text-muted);
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  font-weight: 500;
  width: 33.33%;
}

.listings-table th:first-child {
  text-align: left;
}

.listings-table td {
  text-align: right;
  padding: 7px 10px;
  border-bottom: 1px solid var(--border);
}

.listings-table tr:last-child td {
  border-bottom: none;
}

.listings-table td.listing-price {
  text-align: left;
  font-weight: 600;
  color: var(--text);
}

.listings-table td.listing-usdt {
  color: var(--text-muted);
  font-size: 0.8rem;
}

.listings-table td.listing-amount {
  font-variant-numeric: tabular-nums;
}

/* ── Item Hover Tooltip ──────────────────────────────────────────────────── */
.item-tooltip {
  position: fixed;
  z-index: 500;
  width: 230px;
  background: #12151f;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(255, 255, 255, 0.04);
  pointer-events: none;
  opacity: 0;
  transform: translateY(6px) scale(0.97);
  transition: opacity 0.15s ease, transform 0.15s ease;
}

.item-tooltip.visible {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.tooltip-header {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 9px;
}

.tooltip-img-wrap {
  width: 46px;
  height: 46px;
  flex-shrink: 0;
  border: 2px solid var(--grade-color, var(--border));
  border-radius: 7px;
  background: color-mix(in srgb, var(--grade-color, #1a1f2c) 14%, #0d0f14);
  display: flex;
  align-items: center;
  justify-content: center;
}

.tooltip-img {
  width: 38px;
  height: 38px;
  object-fit: contain;
  border-radius: 4px;
}

.tooltip-title-area {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
  align-items: flex-start;
}

.tooltip-name {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.3;
  word-break: break-all;
}

.tooltip-category {
  font-size: 0.74rem;
  color: var(--text-muted);
  margin-bottom: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.tooltip-options {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-height: 20px;
}

.tooltip-opt-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.79rem;
  gap: 8px;
}

.tooltip-opt-name {
  color: var(--text-muted);
  flex: 1;
}

.tooltip-opt-val {
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
}

.tooltip-no-opts {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-style: italic;
}

.tooltip-loading {
  font-size: 0.78rem;
  color: var(--text-muted);
}



/* タブレット */
@media (max-width: 768px) {
  .col-usdt {
    display: none;
  }
}

/* スマートフォン */
@media (max-width: 480px) {

  /* ヘッダー */
  header {
    padding: 0 12px;
  }

  .header-inner {
    height: auto;
    flex-wrap: wrap;
    gap: 6px;
    padding: 8px 0;
  }

  h1 {
    font-size: 1rem;
  }

  #status-text {
    font-size: 0.72rem;
  }

  /* メインコンテンツ */
  main {
    padding: 0 8px;
    margin: 12px auto;
    gap: 10px;
  }

  /* カテゴリフィルター */
  .cat-btn {
    font-size: 0.76rem;
    padding: 4px 10px;
  }

  .sub-btn {
    font-size: 0.72rem;
    padding: 2px 8px;
  }

  /* 検索・並び替え */
  .controls {
    padding: 8px 10px;
    gap: 8px;
  }

  #search-input {
    font-size: 0.85rem;
    padding: 7px 30px 7px 10px;
  }

  .sort-controls {
    font-size: 0.78rem;
  }

  #sort-select {
    font-size: 0.78rem;
    padding: 5px 6px;
  }

  /* テーブル: 平均値・最高値・USDt列を非表示 */
  .col-usdt {
    display: none;
  }

  th:nth-child(5),
  td:nth-child(5) {
    display: none;
  }

  /* 平均値 */
  th:nth-child(6),
  td:nth-child(6) {
    display: none;
  }

  /* 最高値 */

  /* テーブルのセル余白を縮小 */
  th {
    padding: 8px 8px;
    font-size: 0.72rem;
  }

  td {
    padding: 8px 8px;
  }

  td.col-img {
    padding: 5px 4px 5px 8px;
    width: 36px;
  }

  td.col-name {
    font-size: 0.82rem;
  }

  .item-img-wrap {
    width: 30px;
    height: 30px;
  }

  .item-img {
    width: 24px;
    height: 24px;
  }

  .count-badge {
    padding: 2px 7px;
    font-size: 0.72rem;
  }

  .price-jpy {
    font-size: 0.85rem;
  }

  /* モーダル */
  .modal-box {
    padding: 14px 12px;
  }

  .modal-header {
    margin-bottom: 12px;
  }

  .modal-header h2 {
    font-size: 0.95rem;
  }

  .modal-item-img {
    width: 36px;
    height: 36px;
  }

  .modal-chart-wrap {
    height: 200px;
    margin-bottom: 14px;
  }

  .modal-item-info {
    gap: 6px;
    margin-bottom: 10px;
  }

  .grade-badge {
    font-size: 0.7rem;
    padding: 2px 9px;
  }

  .basic-option {
    font-size: 0.72rem;
    padding: 2px 7px;
  }

  /* 出品一覧テーブル */
  .listings-table th,
  .listings-table td {
    padding: 5px 6px;
    font-size: 0.78rem;
  }
}