:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #eef0f3;
  --text: #1b1f27;
  --muted: #677084;
  --border: #dde1e7;
  --accent: #f0612a;
  --accent-ink: #ffffff;
  --accent-soft: #fff0e9;
  --danger: #c6362b;
  --ok: #1f7a4d;
  --warn-bg: #fff6dc;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151b;
    --surface: #1b1f27;
    --surface-2: #242a35;
    --text: #e8ebf1;
    --muted: #949cad;
    --border: #2e3542;
    --accent: #ff7a45;
    --accent-ink: #1a0e08;
    --accent-soft: #3a2219;
    --danger: #ff6b5e;
    --ok: #5fd39a;
    --warn-bg: #3a3218;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.6rem; margin: 0 0 .4rem; line-height: 1.25; }
h2 { font-size: 1.05rem; margin: 0 0 .75rem; }
h3 { font-size: .85rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 1.5rem 0 .5rem; }
img { max-width: 100%; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
[hidden] { display: none !important; }

/* ---------- top bar */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
.topbar-inner { max-width: 1400px; margin: 0 auto; padding: .6rem 1rem; display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; }
.brand { display: flex; gap: .5rem; align-items: center; font-weight: 700; font-size: 1.15rem; color: var(--text); }
.brand:hover { text-decoration: none; }
.search { flex: 1 1 240px; }
.search input { width: 100%; }
.nav { display: flex; gap: .4rem; align-items: center; flex-wrap: wrap; }
.navlink { color: var(--text); padding: .4rem .6rem; border-radius: 8px; font-size: .95rem; }
.navlink:hover { background: var(--surface-2); text-decoration: none; }
.nav form { margin: 0; }

.wrap { max-width: 1400px; margin: 0 auto; padding: 1.25rem 1rem 3rem; }
.narrow { max-width: 680px; margin: 0 auto; }

/* ---------- controls */
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: .5rem .65rem; width: 100%; max-width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
input[type=file] { padding: .4rem; background: var(--surface-2); }
input[type=checkbox] { width: auto; }
input[type=color] { width: 2.2rem; height: 2.2rem; padding: 2px; flex: none; }
label { display: block; font-weight: 600; font-size: .92rem; }
label > input, label > select, label > textarea { margin-top: .3rem; font-weight: 400; }
label.check { display: flex; gap: .5rem; align-items: center; font-weight: 400; margin: .3rem 0; }
fieldset { border: 1px solid var(--border); border-radius: 10px; padding: .75rem 1rem; margin: 0; }
legend { font-weight: 600; padding: 0 .3rem; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: .35rem; font: inherit; font-weight: 600;
  font-size: .92rem; padding: .5rem .9rem; border-radius: 9px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.small { padding: .25rem .55rem; font-size: .82rem; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .6; cursor: progress; }
.danger-btn { background: var(--danger); border-color: var(--danger); color: #fff; }
.linkbtn { background: none; border: 0; padding: 0; font: inherit; color: var(--accent); cursor: pointer; }
.linkbtn:hover { text-decoration: underline; }
.danger, .linkbtn.danger { color: var(--danger); }
.inline { display: inline; margin: 0; }
.row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; margin-top: .75rem; }
.row input[type=file] { flex: 1 1 220px; width: auto; }
.stack { display: grid; gap: 1rem; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.pad { padding: 1.1rem 1.25rem; }
.card + .card, .model-side > * + * { margin-top: 1rem; }
.grid > .card { margin-top: 0; }

.flash { padding: .65rem .9rem; border-radius: 9px; margin-bottom: 1rem; background: var(--accent-soft); border: 1px solid var(--border); }
.flash.ok { border-left: 4px solid var(--ok); }
.flash.error { border-left: 4px solid var(--danger); }
.flash.warn { background: var(--warn-bg); font-size: .9rem; }
.hint { margin: 0; padding: .6rem .8rem; background: var(--accent-soft); border-radius: 9px; font-size: .9rem; }

.pill { font-size: .72rem; font-weight: 700; background: var(--accent-soft); color: var(--accent); padding: .1rem .45rem; border-radius: 99px; vertical-align: middle; }
.tags { display: flex; gap: .35rem; flex-wrap: wrap; }
.tag { font-size: .85rem; padding: .2rem .6rem; background: var(--surface-2); color: var(--text); border-radius: 99px; }
.tag small { color: var(--muted); }
.tag.on { background: var(--accent); color: var(--accent-ink); }
.tag:hover { text-decoration: none; filter: brightness(.97); }
.chips { display: flex; gap: .4rem; flex-wrap: wrap; margin: 0 0 1rem; }
.chip { background: var(--accent-soft); color: var(--accent); padding: .15rem .6rem; border-radius: 99px; font-size: .85rem; font-weight: 600; }

/* ---------- login */
.auth-card { max-width: 380px; margin: 8vh auto 0; padding: 2rem; text-align: center; }
.auth-card form { text-align: left; margin-top: 1.25rem; }

/* ---------- browse */
.browse { display: grid; grid-template-columns: 220px 1fr; gap: 1.5rem; align-items: start; }
.filters { position: sticky; top: 4.5rem; }
.section-head { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; flex-wrap: wrap; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 1rem; }
.model-card { overflow: hidden; color: var(--text); display: flex; flex-direction: column; transition: transform .12s, box-shadow .12s; }
.model-card:hover { text-decoration: none; transform: translateY(-2px); box-shadow: 0 6px 18px rgba(0,0,0,.12); }
.cover { aspect-ratio: 4 / 3; background: var(--surface-2); position: relative; display: grid; place-items: center; }
.cover img { width: 100%; height: 100%; object-fit: cover; }
.cover-empty { font-size: 2.5rem; color: var(--border); }
.badge { position: absolute; top: .5rem; right: .5rem; background: rgba(0,0,0,.65); color: #fff; font-size: .75rem; font-weight: 700; padding: .1rem .45rem; border-radius: 6px; }
.card-body { padding: .65rem .8rem .8rem; }
.card-title { font-weight: 600; line-height: 1.3; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.card-meta { display: flex; justify-content: space-between; align-items: center; gap: .5rem; color: var(--muted); font-size: .85rem; margin-top: .3rem; }
.swatches { display: flex; }
.swatches i { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--surface); margin-left: -4px; box-shadow: 0 0 0 1px var(--border); }
.pager { display: flex; gap: 1rem; justify-content: center; align-items: center; margin-top: 1.5rem; }
.empty { text-align: center; padding: 3rem 1rem; }

/* ---------- model page */
.model-head { display: flex; justify-content: space-between; gap: 1rem; align-items: flex-start; flex-wrap: wrap; margin-bottom: 1rem; }
.model-head p { margin: 0 0 .5rem; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.model-layout { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 1.25rem; align-items: start; }
.viewer { position: relative; aspect-ratio: 4 / 3; overflow: hidden; background: radial-gradient(circle at 50% 40%, var(--surface), var(--surface-2)); }
.viewer canvas { width: 100%; height: 100%; display: block; touch-action: none; }
.viewer-overlay { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; padding: 1rem; }
.viewer-hint { position: absolute; bottom: .5rem; left: .75rem; font-size: .75rem; pointer-events: none; }
.viewer-photo { width: 100%; height: 100%; object-fit: contain; }
.description { white-space: pre-wrap; overflow-wrap: anywhere; }
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .75rem; }
.photos figure { margin: 0; }
.photos img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 9px; display: block; }
.photos figcaption { font-size: .8rem; margin-top: .25rem; }

.changelog { white-space: pre-wrap; background: var(--surface-2); padding: .5rem .7rem; border-radius: 8px; font-size: .9rem; }
.files { list-style: none; padding: 0; margin: 0 0 1rem; }
.files li { display: flex; gap: .5rem; align-items: baseline; padding: .45rem 0; border-bottom: 1px solid var(--border); font-size: .92rem; }
.files .fname { flex: 1; overflow-wrap: anywhere; }
.filaments { list-style: none; padding: 0; margin: 0; display: grid; gap: .7rem; }
.filaments li { display: flex; gap: .7rem; align-items: center; }
.fil-title { font-weight: 600; }
.swatch { width: 30px; height: 30px; border-radius: 50%; flex: none; box-shadow: inset 0 0 0 1px rgba(0,0,0,.15); }
.swatch.none { background: repeating-linear-gradient(45deg, var(--surface-2), var(--surface-2) 4px, var(--border) 4px, var(--border) 8px); }
.add-filaments { display: block; border-style: dashed; color: var(--text); }
.history { list-style: none; padding: 0; margin: 0; }
.history li { padding: .45rem .6rem; border-radius: 8px; }
.history li.current { background: var(--accent-soft); }
.side-links { margin-top: 1rem; text-align: right; }

/* ---------- forms / tables */
.table-scroll { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: .4rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: .8rem; color: var(--muted); font-weight: 600; }
.fil-table input { min-width: 90px; }
.color-cell { display: flex; gap: .3rem; align-items: center; }
.color-cell .hex { width: 6.5rem; min-width: 0; }
.row-form { display: flex; gap: .75rem; align-items: flex-end; flex-wrap: wrap; margin-bottom: 1rem; }
.row-form h2 { width: 100%; margin: 0; }
.row-form label { flex: 1 1 160px; }
.row-form label.check { flex: 0 0 auto; }
.users tr.disabled td { opacity: .5; }
.user-actions { white-space: nowrap; }
.user-actions input { width: auto; padding: .25rem .45rem; font-size: .82rem; }
.progress { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.progress > div { height: 100%; width: 0; background: var(--accent); transition: width .2s; }

@media (max-width: 960px) {
  /* phones/tablets: viewer, then download + filaments, then description/photos */
  .model-layout { display: flex; flex-direction: column; gap: 1rem; }
  .model-main { display: contents; }
  .model-main > .card { margin-top: 0; order: 3; }
  .model-main > #viewer { order: 1; }
  .model-side { order: 2; }
}
@media (max-width: 720px) {
  .browse { grid-template-columns: 1fr; }
  .filters { position: static; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .7rem; }
  h1 { font-size: 1.35rem; }
}
