:root {
  --bg: #f6f3ee;
  --surface: #ffffff;
  --ink: #2b2620;
  --muted: #7a7065;
  --line: #e6e0d6;
  --accent: #9a6b3f;
  --accent-ink: #ffffff;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(43, 38, 32, .06), 0 6px 20px rgba(43, 38, 32, .06);
  font-family: "Be Vietnam Pro", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; }

/* ---------- Trang chủ ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: rgba(246, 243, 238, .9);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.topbar-inner, main.list {
  max-width: 1200px; margin: 0 auto;
  padding-inline: max(16px, env(safe-area-inset-left));
}
.topbar-inner { display: flex; align-items: center; gap: 12px; padding-block: 14px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: .02em; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center;
  background: var(--accent); color: var(--accent-ink); font-size: 15px; font-weight: 800;
}
.brand small { display: block; font-weight: 400; color: var(--muted); font-size: 12px; letter-spacing: 0; }
.search {
  margin-left: auto; flex: 0 1 280px; min-width: 0;
  padding: 9px 14px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface); font: inherit; font-size: 14px; outline: none;
}
.search:focus { border-color: var(--accent); }

main.list { padding-block: 24px 48px; }
.list-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.list-head h1 { font-size: clamp(20px, 3vw, 26px); margin: 0; }
.count { color: var(--muted); font-size: 14px; }

.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
@media (max-width: 480px) { .grid { grid-template-columns: repeat(2, 1fr); gap: 12px; } }

.card {
  background: var(--surface); border-radius: var(--radius); overflow: hidden;
  box-shadow: var(--shadow); display: flex; flex-direction: column;
  transition: transform .15s ease, box-shadow .15s ease;
}
.card:hover { transform: translateY(-2px); box-shadow: 0 2px 4px rgba(43,38,32,.08), 0 12px 28px rgba(43,38,32,.10); }
.thumb {
  aspect-ratio: 4 / 3; background: linear-gradient(160deg, #efe9df, #e2d9cb);
  display: grid; place-items: center; overflow: hidden;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb svg { width: 38%; height: auto; color: #b9a78f; }
.card-body { padding: 10px 12px 12px; }
.card-title { font-weight: 600; font-size: 15px; line-height: 1.3; overflow-wrap: anywhere; }
.card-meta { color: var(--muted); font-size: 12px; margin-top: 4px; display: flex; gap: 8px; }
.tag { text-transform: uppercase; font-weight: 600; letter-spacing: .04em; color: var(--accent); }

.state { text-align: center; color: var(--muted); padding: 64px 16px; }
.state code { background: #ece6dc; padding: 2px 6px; border-radius: 6px; font-size: 13px; }

footer.site { text-align: center; color: var(--muted); font-size: 12px; padding: 0 16px 32px; }

/* ---------- Trang xem 3D ---------- */
body.viewer { height: 100dvh; overflow: hidden; background: #ece7df; }
#stage { position: fixed; inset: 0; }
#stage canvas { display: block; width: 100%; height: 100%; touch-action: none; }

.vbar {
  position: fixed; left: 0; right: 0; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 10px;
  padding: calc(10px + env(safe-area-inset-top, 0px)) max(12px, env(safe-area-inset-right)) 10px max(12px, env(safe-area-inset-left));
  background: linear-gradient(rgba(236,231,223,.95), rgba(236,231,223,0));
  pointer-events: none;
}
.vbar > * { pointer-events: auto; }
.vtitle { font-weight: 600; font-size: 16px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-width: 42px; height: 42px; padding: 0 12px; border-radius: 12px;
  background: rgba(255,255,255,.92); border: 1px solid var(--line); cursor: pointer;
  box-shadow: 0 1px 3px rgba(0,0,0,.06); font-size: 14px; white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}
.btn svg { width: 20px; height: 20px; flex: none; }
.btn:hover { border-color: #cdbfac; }
.btn[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.tools {
  position: fixed; z-index: 5; left: 50%; transform: translateX(-50%);
  bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  display: flex; gap: 8px; padding: 6px; border-radius: 16px;
  background: rgba(255,255,255,.6); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  max-width: calc(100% - 24px); overflow-x: auto;
}
@media (max-width: 560px) { .tools .label { display: none; } .tools .btn { padding: 0; width: 44px; } }

.hint {
  position: fixed; z-index: 4; left: 0; right: 0; text-align: center;
  bottom: calc(76px + env(safe-area-inset-bottom, 0px));
  color: var(--muted); font-size: 12px; pointer-events: none;
  transition: opacity .6s;
}

.loader {
  position: fixed; inset: 0; z-index: 6; display: grid; place-items: center;
  background: #ece7df; transition: opacity .4s;
}
.loader.done { opacity: 0; pointer-events: none; }
.loader-box { width: min(260px, 70vw); text-align: center; color: var(--muted); font-size: 14px; }
.bar { height: 6px; border-radius: 99px; background: #ddd4c6; overflow: hidden; margin-top: 12px; }
.bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.loader.error .loader-box { color: #a0392b; }

/* nền tối */
body.viewer.dark { background: #1d1b19; }
body.viewer.dark .vbar { background: linear-gradient(rgba(29,27,25,.95), rgba(29,27,25,0)); color: #f1ece4; }
body.viewer.dark .btn:not([aria-pressed="true"]) { background: rgba(50,46,42,.92); border-color: #3d3833; color: #f1ece4; }
body.viewer.dark .tools { background: rgba(40,37,34,.6); }
body.viewer.dark .hint { color: #a59b8f; }
