:root {
  --bg: #181b1f;
  --page-bg: #1E2127;
  --surface: #272b33;
  --surface-2: #31363f;
  --text: #e8eaed;
  --muted: #9aa1ab;
  --line: #363b45;
  --accent: #3E90FF;
  --fav: #ff6b8b;
  --viewer-bg: #101219;
  --radius: 12px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--page-bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", sans-serif;
  line-height: 1.6;
}
a { color: inherit; }
button, input { font: inherit; color: inherit; }

.icon { display: inline-flex; width: 1.1em; height: 1.1em; }
.icon svg { width: 100%; height: 100%; fill: currentColor; }

.site-header { position: sticky; top: 0; z-index: 10; padding: 14px 24px; background: var(--bg); }
.logo { display: inline-flex; align-self: flex-start; align-items: center; gap: 10px; text-decoration: none; }
.logo-cube { width: 32px; height: 32px; flex: none; display: block; }
.logo-text {
  font-family: "Advent Pro", sans-serif; font-weight: 900; font-stretch: 125%;
  font-size: 1.7rem; line-height: 1; letter-spacing: .03em; white-space: nowrap;
  color: transparent; -webkit-text-stroke: 1.2px #3d68dc;
}

.profile img, .profile-banner { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; -webkit-user-drag: none; pointer-events: none; }
.profile-btn, .profile-card { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }
.profile { position: absolute; right: 24px; top: 13px; z-index: 30; }
.profile-btn { display: block; width: 34px; height: 34px; padding: 0; border: none; border-radius: 50%; overflow: hidden; cursor: pointer; background: #fff; box-shadow: 0 0 0 2px var(--surface); transition: box-shadow .12s ease; }
.profile-btn:hover, .profile-btn[aria-expanded="true"] { box-shadow: 0 0 0 2px #f4a7c3; }
.profile-btn img { width: 100%; height: 100%; display: block; object-fit: cover; }
.profile-card {
  position: absolute; right: 0; top: calc(100% + 10px); width: 300px; padding: 3px;
  border-radius: 14px; background: linear-gradient(180deg, #df6fa0, #d13deb);
  box-shadow: 0 10px 30px rgba(0, 0, 0, .5);
}
.profile-inner { position: relative; border-radius: 11px; overflow: hidden; background: linear-gradient(180deg, #f2c5da 0%, #edb1f7 100%); color: #3a2a3c; }
.profile-banner { height: 92px; background: url(../img/banner.webp) center / cover no-repeat, #f4a3cc; }
.profile-avatar {
  position: absolute; left: 14px; top: 48px; width: 86px; height: 86px; border-radius: 50%;
  border: 5px solid #f2c5da; background: #fff; object-fit: cover;
}
.profile-status {
  position: absolute; left: 108px; top: 100px; width: 40px; height: 40px; border-radius: 12px;
  display: grid; place-items: center; font-size: 1.25rem; background: rgba(255, 255, 255, .7);
  box-shadow: 0 2px 6px rgba(160, 80, 140, .2);
}
.profile-status img { width: 26px; height: 26px; display: block; }
.profile-status::before { content: ""; position: absolute; left: -9px; top: -2px; width: 9px; height: 9px; border-radius: 50%; background: rgba(255, 255, 255, .7); }
.profile-body { padding: 50px 16px 16px; }
.profile-name { font-size: 1.35rem; font-weight: 800; line-height: 1.3; color: #dc5d9f; }
.profile-user { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 2px; font-size: .85rem; color: #4a3550; }
.profile-add {
  display: flex; align-items: center; justify-content: center; margin-top: 14px; height: 36px;
  border-radius: 8px; background: #780345; color: #fff; font-size: .88rem; font-weight: 700; text-decoration: none;
}
.profile-add:hover { background: #941765; }
.profile-add:not([hidden]) + .profile-copy { margin-top: 8px; }
.profile-copy { margin-top: 14px; width: 100%; height: 36px; border: none; border-radius: 8px; background: #780345; color: #fff; font-size: .88rem; font-weight: 700; cursor: pointer; }
.profile-copy:hover { background: #941765; }
.wrap { max-width: 1200px; margin: 0 auto; padding: 24px; }

.site-header:has(.toolbar) { display: flex; align-items: center; min-height: 55px; }
.toolbar { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(420px, calc(100% - 2 * 190px)); display: flex; }
.search {
  flex: 1; min-width: 0; height: 34px; padding: 0 4px 0 10px;
  display: flex; align-items: center; gap: 8px;
  background: var(--surface); border-radius: 4px; cursor: text;
}
.search svg { flex: none; width: 16px; height: 16px; fill: var(--muted); }
.search input { flex: 1; min-width: 0; height: 100%; padding: 0; background: none; border: none; outline: none; }
.search input::-webkit-search-cancel-button {
  -webkit-appearance: none; appearance: none; width: 16px; height: 16px; margin: 0 4px 0 6px; cursor: pointer;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%239aa1ab' d='M18.3 5.7 12 12l6.3 6.3-1.4 1.4L10.6 13.4 4.3 19.7l-1.4-1.4L9.2 12 2.9 5.7l1.4-1.4 6.3 6.3 6.3-6.3z'/%3E%3C/svg%3E") center / contain no-repeat;
}
.search input::-webkit-search-cancel-button:hover { filter: brightness(1.4); }
.dropdown { position: relative; flex: none; }
.dropdown-btn {
  height: 26px; padding: 0 6px 0 12px;
  display: inline-flex; align-items: center; gap: 2px;
  background: #363b42; border: none; border-radius: 999px;
  font-size: .85rem; cursor: pointer;
}
.dropdown-btn:hover { filter: brightness(1.15); }
.dropdown-btn:focus-visible { outline: none; box-shadow: 0 0 0 1px var(--accent); }
.dropdown-btn svg { width: 18px; height: 18px; fill: currentColor; }
.dropdown-menu {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: 20;
  min-width: 150px; margin: 0; padding: 6px 0; list-style: none;
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .35);
}
.dropdown-menu li { position: relative; padding: 8px 16px 8px 34px; font-size: .9rem; cursor: pointer; white-space: nowrap; }
.dropdown-menu li:hover { background: var(--surface-2); }
.dropdown-menu li[aria-selected="true"]::before {
  content: ""; position: absolute; left: 13px; top: 50%; width: 5px; height: 10px;
  border: solid currentColor; border-width: 0 2px 2px 0;
  transform: translateY(-65%) rotate(45deg);
}

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px; }
.card { display: flex; flex-direction: column; text-decoration: none; }
.card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.thumb {
  aspect-ratio: 1; border-radius: var(--radius); overflow: hidden; background: var(--viewer-bg);
  display: grid; place-items: center; position: relative; transition: filter .15s ease;
}
.card:hover .thumb { filter: brightness(.65); }
.thumb img { width: 88%; height: 88%; object-fit: contain; }
.thumb img:not([src]) { visibility: hidden; }
.thumb.loading::after, .viewer.loading::after {
  content: ""; position: absolute; width: 28px; height: 28px;
  border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%;
  animation: spin .8s linear infinite;
}
.thumb.thumb-error::after, .viewer.error::after {
  content: "Failed to load"; position: absolute; color: var(--muted); font-size: .85rem;
}
@keyframes spin { to { transform: rotate(360deg); } }
.card-body { padding: 8px 2px 0; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.card-title { margin: 0; min-width: 0; font-size: .98rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-meta { flex: none; display: flex; gap: 10px; color: var(--muted); font-size: .72rem; }
.stat { display: inline-flex; align-items: center; gap: 4px; font-variant-numeric: tabular-nums; }
.status { color: var(--muted); text-align: center; }

.detail { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 24px; align-items: start; }
.viewer {
  position: relative; height: min(72vh, 720px); min-height: 320px;
  background: var(--viewer-bg); border-radius: var(--radius); overflow: hidden;
  display: grid; place-items: center; touch-action: none;
}
.viewer canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: grab; }
.viewer canvas:active { cursor: grabbing; }
.viewer-bar { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-top: 10px; padding: 0 4px; }
.model-head { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.title-row { display: flex; align-items: baseline; flex-wrap: wrap; column-gap: 20px; }
.model-title { margin: 0; min-width: 0; font-size: 1.25rem; font-weight: 700; line-height: 1.3; overflow-wrap: anywhere; }
.model-date { color: var(--muted); font-size: .85rem; font-variant-numeric: tabular-nums; }
.model-date:empty { display: none; }
.viewer-stats { display: flex; gap: 14px; color: var(--muted); font-size: .9rem; }
.fav-icon {
  flex: none; margin-top: 2px;
  display: grid; place-items: center; width: 36px; height: 36px; padding: 0;
  border: none; border-radius: 50%; cursor: pointer; background: transparent;
  color: var(--fav); font-size: 20px; transition: transform .12s ease;
}
.fav-icon:hover:not(:disabled) { transform: scale(1.12); }
.fav-icon:active:not(:disabled) { transform: scale(.92); }
.fav-icon:disabled { opacity: .5; cursor: default; }
.fav-icon:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.info { background: var(--surface); border-radius: var(--radius); padding: 20px; }
.side { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.terms-list { list-style: none; margin: 0 0 10px; padding: 0; display: flex; flex-direction: column; gap: 4px; font-size: .88rem; }
.terms-list li { position: relative; padding-left: 22px; }
.terms-list li::before {
  content: ""; position: absolute; left: 0; top: 50%; width: 14px; height: 14px; transform: translateY(-50%);
  background: currentColor; -webkit-mask: var(--icon) center / contain no-repeat; mask: var(--icon) center / contain no-repeat;
}
.terms-list .ok::before { color: #4cc38a; --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12.5l4.5 4.5L19 7.5'/%3E%3C/svg%3E"); }
.terms-list .ng::before { color: #ff6b6b; --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.5' stroke-linecap='round'%3E%3Cpath d='M6.5 6.5l11 11M17.5 6.5l-11 11'/%3E%3C/svg%3E"); }
.terms-list .ng { color: var(--muted); }
.terms-note { margin: 0; color: var(--muted); font-size: .8rem; overflow-wrap: anywhere; }
.terms-note a { color: var(--accent); }
.description { white-space: pre-wrap; margin: 0 0 4px; }
.description:empty { display: none; }
.sub { font-size: .95rem; margin: 0 0 8px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 42px; padding: 8px 14px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface-2);
  text-decoration: none; cursor: pointer; font-weight: 600;
}
.btn:hover { filter: brightness(1.05); }
.downloads { display: flex; flex-direction: column; gap: 14px; }
.dl-group { display: flex; flex-direction: column; gap: 6px; }
.dl-label { margin: 0; color: var(--muted); font-size: .8rem; }
.download { justify-content: flex-start; background: #33383f; border-color: #33383f; color: var(--text); transition: background-color .12s ease, border-color .12s ease; }
.download:hover { background: var(--accent); border-color: var(--accent); color: #fff; filter: none; }
.dl-name { flex: 1; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dl-size { font-weight: 400; opacity: .85; font-size: .85rem; }

.empty { text-align: center; padding: 60px 0; grid-column: 1 / -1; }

@media (max-width: 860px) {
  .wrap { padding: 16px; }
  .site-header { padding: 12px 16px; }
  .profile { right: 16px; top: 11px; }
  .site-header:has(.toolbar) { flex-direction: column; align-items: stretch; gap: 8px; }
  .toolbar { position: static; transform: none; width: auto; }
  .detail { grid-template-columns: 1fr; }
  .viewer { height: 60vh; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
}
