@import url("../assets/common.css");

.back-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  box-sizing: border-box;
  min-height: calc(env(safe-area-inset-top, 0px) + var(--back-bar-body));
  padding:
    calc(env(safe-area-inset-top, 0px) + 10px)
    max(16px, env(safe-area-inset-right))
    10px
    max(16px, env(safe-area-inset-left));
  background: rgba(15, 20, 25, 0.9);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--panel-border);
}

.back-bar .back-link {
  min-height: 36px;
  padding: 0 4px;
}

.back-bar .back-link:active {
  color: var(--accent);
}

.page-with-back-bar {
  padding-top: calc(env(safe-area-inset-top, 0px) + var(--back-bar-body) + var(--back-bar-gap));
}

.desktop-only {
  display: block;
}

.mobile-only {
  display: none;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin: 24px 0 18px;
}

.control {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 160px;
  color: var(--muted);
  font-size: 0.9rem;
}

.control select,
.order-btn {
  appearance: none;
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  background: var(--panel);
  color: var(--text);
  padding: 10px 14px;
  font: inherit;
  touch-action: manipulation;
}

.order-btn {
  align-self: flex-end;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.order-btn:hover,
.control select:hover {
  border-color: var(--accent);
}

.scroll-hint {
  display: none;
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 0.82rem;
}

.table-wrap {
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  background: rgba(26, 35, 50, 0.92);
  box-shadow: var(--shadow);
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 860px;
}

th,
td {
  padding: 14px 16px;
  text-align: left;
  white-space: nowrap;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #162033;
  color: var(--muted);
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  border-bottom: 1px solid var(--panel-border);
}

th:first-child,
td:first-child {
  position: sticky;
  left: 0;
  z-index: 2;
  background: #162033;
  box-shadow: 2px 0 8px rgba(0, 0, 0, 0.18);
}

td:first-child {
  background: rgba(26, 35, 50, 0.98);
  z-index: 1;
}

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

th.sorted {
  color: var(--accent);
  background: #18243a;
}

th.sorted::after {
  content: " " attr(data-order);
  font-size: 0.85rem;
}

tbody tr {
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

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

.name-cell {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
}

.rank {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.8rem;
  flex-shrink: 0;
}

.stone-name {
  color: var(--stone-color, var(--text));
}

.mobile-cards {
  gap: 12px;
}

.stat-card {
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  background: rgba(26, 35, 50, 0.92);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.stat-card-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  font-weight: 600;
}

.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
}

.stat-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 11px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

.stat-item:nth-child(odd) {
  border-right: 1px solid rgba(255, 255, 255, 0.04);
}

.stat-item:nth-last-child(-n + 2) {
  border-bottom: none;
}

.stat-label {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 500;
}

.stat-value {
  font-size: 0.92rem;
  font-weight: 600;
  text-align: right;
}

.stat-item.is-sorted {
  background: var(--accent-soft);
}

.stat-item.is-sorted .stat-label,
.stat-item.is-sorted .stat-value {
  color: var(--accent);
}

.footer {
  margin-top: 16px;
  color: var(--muted);
  font-size: 0.95rem;
}

.footer p {
  margin: 0;
  line-height: 1.55;
}

@media (max-width: 900px) and (min-width: 769px) {
  .scroll-hint {
    display: block;
  }
}

@media (max-width: 768px) {
  .back-bar .back-link {
    min-height: 44px;
  }

  .desktop-only {
    display: none;
  }

  .mobile-only.mobile-cards {
    display: grid;
  }

  .controls {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-top: 18px;
  }

  .control {
    min-width: 0;
  }

  .control select {
    width: 100%;
    min-height: 44px;
    font-size: 16px;
  }

  .order-btn {
    grid-column: 1 / -1;
    width: 100%;
    align-self: stretch;
    min-height: 44px;
  }

  .footer {
    font-size: 0.88rem;
  }

  .footer .disclaimer {
    font-size: 0.76rem;
  }
}

@media (max-width: 380px) {
  .stat-grid {
    grid-template-columns: 1fr;
  }

  .stat-item:nth-child(odd) {
    border-right: none;
  }

  .stat-item:not(:last-child) {
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  }
}
