:root {
  --ink: #131313;
  --sub: #8b8b8f;
  --line: #ededee;
  --chip: #f4f4f5;
  --bg: #ffffff;
  --radius: 3px;
  --content: 1180px;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button { font-family: inherit; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(255, 255, 255, .92);
  backdrop-filter: saturate(160%) blur(14px);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
}

.topbar-inner {
  max-width: var(--content);
  margin: 0 auto;
  height: 56px;
  padding: 0 12px;
  display: grid;
  grid-template-columns: 88px 1fr 88px;
  align-items: center;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 2px;
}

.topbar-title {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: .3px;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.icon-btn {
  width: 38px;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  background: transparent;
  color: var(--ink);
  border-radius: 50%;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.icon-btn:hover { background: #f3f3f4; }
.icon-btn:active { background: #eaeaec; }
.icon-btn svg { width: 22px; height: 22px; }

.main {
  max-width: var(--content);
  margin: 0 auto;
  padding: 2px 18px 56px;
}

/* ---------- search ---------- */
.searchbar {
  position: relative;
  display: flex;
  align-items: center;
  gap: 9px;
  height: 44px;
  margin: 8px 0 0;
  padding: 0 12px;
  background: var(--chip);
  border-radius: 9px;
}

.searchbar svg {
  width: 18px;
  height: 18px;
  color: #9a9a9e;
  flex: none;
}

.searchbar input {
  flex: 1;
  min-width: 0;
  height: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  font-size: 15px;
  color: var(--ink);
}

.searchbar input::placeholder { color: #a5a5a9; }

.search-clear {
  flex: none;
  width: 22px;
  height: 22px;
  border: 0;
  border-radius: 50%;
  background: #dcdcdf;
  color: #fff;
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.searchbar.has-value .search-clear { display: inline-flex; }

/* ---------- list view ---------- */
.material-title {
  margin: 26px 0 0;
  font-size: 24px;
  font-weight: 600;
  letter-spacing: .5px;
  text-align: center;
}

.material-meta {
  margin-top: 7px;
  font-size: 12.5px;
  color: var(--sub);
  text-align: center;
  letter-spacing: .2px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 24px 14px;
  margin-top: 22px;
}

.material-card {
  cursor: pointer;
  outline: none;
  animation: rise .32s ease both;
}

.material-card .img-wrap {
  position: relative;
  aspect-ratio: 570 / 397;
  background: #0c0c0c;
  border-radius: var(--radius);
  overflow: hidden;
}

.material-card img,
.piece-card img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform .38s ease, opacity .2s ease;
}

.material-card:hover img { transform: scale(1.025); }
.material-card:focus-visible .img-wrap { outline: 2px solid #111; outline-offset: 2px; }

.card-meta { padding-top: 8px; }

.card-title {
  font-size: 14px;
  font-weight: 500;
  letter-spacing: .1px;
}

.card-sub {
  margin-top: 3px;
  font-size: 12px;
  color: var(--sub);
}

/* ---------- detail view ---------- */
.detail-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  margin-top: 18px;
}

.detail-head h2 {
  margin: 0;
  min-width: 0;
  font-size: 19px;
  font-weight: 600;
  letter-spacing: .2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.detail-area {
  flex: none;
  font-size: 13.5px;
  color: #6f6f74;
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 12px;
}

.chip {
  display: inline-flex;
  align-items: center;
  height: 24px;
  padding: 0 8px;
  border-radius: 4px;
  background: var(--chip);
  color: #3c3c40;
  font-size: 12px;
  letter-spacing: .2px;
}

.tabs {
  display: flex;
  gap: 34px;
  margin-top: 14px;
  overflow-x: auto;
  scrollbar-width: none;
  border-bottom: 1px solid var(--line);
}

.tabs::-webkit-scrollbar { display: none; }

.tab {
  position: relative;
  flex: none;
  padding: 11px 1px 10px;
  border: 0;
  background: transparent;
  color: #6c6c71;
  font-size: 16px;
  letter-spacing: .3px;
  cursor: pointer;
}

.tab:hover { color: var(--ink); }

.tab.active {
  color: var(--ink);
  font-weight: 500;
}

.tab.active::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  height: 2px;
  background: var(--ink);
  border-radius: 2px;
}

.pieces-grid {
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 22px 14px;
  margin-top: 18px;
}

.piece-card {
  animation: rise .3s ease both;
}

.piece-card .img-wrap {
  position: relative;
  aspect-ratio: 570 / 397;
  background: #0c0c0c;
  border-radius: var(--radius);
  overflow: hidden;
}

.img-open {
  display: block;
  width: 100%;
  height: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: zoom-in;
}

.img-open:focus-visible { outline: 2px solid #fff; outline-offset: -3px; }

.piece-card .img-wrap:hover img { opacity: .94; }

.dl-fab {
  position: absolute;
  right: 9px;
  bottom: 9px;
  width: 31px;
  height: 31px;
  border: 0;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, .94);
  color: #111;
  box-shadow: 0 1px 5px rgba(0, 0, 0, .28);
  cursor: pointer;
  opacity: 0;
  transform: translateY(3px);
  transition: opacity .2s ease, transform .2s ease, background .2s ease;
}

.dl-fab svg { width: 16px; height: 16px; }
.dl-fab:hover { background: #fff; }
.piece-card:hover .dl-fab,
.dl-fab:focus-visible { opacity: 1; transform: translateY(0); }

/* ---------- code sheet ---------- */
.codesheet {
  margin: 36px 0 26px;
}

.codesheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.codesheet-head h3 {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: .3px;
}

.sheet-dl {
  border: 0;
  background: transparent;
  color: #2f7ed8;
  font-size: 13.5px;
  letter-spacing: .2px;
  cursor: pointer;
  padding: 4px 0;
}

.sheet-dl:hover { text-decoration: underline; }

.sheet-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.sheet-table {
  width: 100%;
  border-collapse: collapse;
  border: 1px solid #292929;
  table-layout: fixed;
}

.sheet-table th,
.sheet-table td {
  border: 1px solid #cfcfd2;
  padding: 10px 4px;
  text-align: center;
  font-size: 13px;
  font-weight: 400;
  line-height: 1.35;
  font-variant-numeric: tabular-nums;
}

.sheet-table th {
  background: #f3f3f4;
  font-weight: 600;
}

.sheet-table th span {
  display: block;
  font-size: 12px;
  font-weight: 400;
  color: #555;
}

.sheet-table .sheet-total td {
  font-weight: 600;
  background: #fafafa;
}

/* ---------- empty ---------- */
.empty {
  padding: 72px 0 40px;
  text-align: center;
  color: var(--sub);
}

.empty svg { width: 46px; height: 46px; color: #d4d4d7; }
.empty p { margin: 12px 0 0; font-size: 14px; }

/* ---------- lightbox ---------- */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  background: rgba(10, 10, 10, .96);
  color: #fff;
  animation: fade .18s ease both;
}

.lightbox[hidden] { display: none; }

.lb-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px 4px;
  flex: none;
}

.lb-counter {
  font-size: 13px;
  color: rgba(255, 255, 255, .68);
  letter-spacing: .6px;
}

.lb-btn {
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, .08);
  color: #fff;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.lb-btn:hover { background: rgba(255, 255, 255, .16); }
.lb-btn svg { width: 20px; height: 20px; }

.lb-stage {
  flex: 1;
  min-height: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 0 64px;
}

.lb-stage img {
  max-width: 100%;
  max-height: calc(100vh - 190px);
  object-fit: contain;
  border-radius: 2px;
  box-shadow: 0 10px 60px rgba(0, 0, 0, .5);
}

.lb-caption {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  width: min(100%, 860px);
  padding-bottom: 10px;
}

.lb-info {
  font-size: 13px;
  color: rgba(255, 255, 255, .78);
  letter-spacing: .3px;
}

.lb-actions { flex: none; }

.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 38px;
  padding: 0 16px;
  border: 0;
  border-radius: 19px;
  background: #fff;
  color: #111;
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
}

.btn-primary:hover { background: #ececec; }
.btn-primary svg { width: 17px; height: 17px; }

.lb-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, .08);
  color: #fff;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.lb-nav:hover { background: rgba(255, 255, 255, .16); }
.lb-nav svg { width: 22px; height: 22px; }
.lb-nav.prev { left: 14px; }
.lb-nav.next { right: 14px; }
.lb-nav[disabled] { opacity: .25; pointer-events: none; }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 34px;
  transform: translateX(-50%);
  z-index: 120;
  padding: 9px 16px;
  border-radius: 8px;
  background: rgba(17, 17, 17, .9);
  color: #fff;
  font-size: 13px;
  letter-spacing: .3px;
  animation: fade .18s ease both;
  pointer-events: none;
}

.toast[hidden] { display: none; }

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

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

@media (max-width: 640px) {
  .main { padding: 2px 14px 48px; }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px 12px; }
  .pieces-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px 12px; }
  .material-title { font-size: 21px; margin-top: 22px; }
  .detail-head h2 { font-size: 16.5px; }
  .tabs { gap: 26px; }
  .tab { font-size: 15px; }
  .lb-stage { padding: 0 10px; }
  .lb-nav { display: none; }
  .lb-caption { flex-direction: column; align-items: flex-start; gap: 10px; }
  .lb-stage img { max-height: calc(100vh - 230px); }
  .sheet-table th, .sheet-table td { padding: 8px 2px; font-size: 12px; }
  .sheet-table th span { font-size: 11px; }
  .codesheet { margin-top: 30px; }
}

@media (hover: none) {
  .dl-fab { opacity: 1; transform: none; }
}
