:root {
  --bg: #16130f;
  --panel: #211d17;
  --panel-2: #2b261e;
  --line: #3a332a;
  --text: #efe8dc;
  --muted: #a39a8a;
  --accent: #e0a13a;
  --danger: #d9634f;
  --radius: 10px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
}
a { color: inherit; text-decoration: none; }
h2 { font-size: 1.15rem; margin: 0 0 12px; }
h3 { font-size: .85rem; margin: 24px 0 8px; color: var(--muted); font-weight: 600; letter-spacing: .04em; }

header {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: rgba(22, 19, 15, .92); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; font-size: 1.1rem; letter-spacing: .05em; }
nav { display: flex; gap: 8px; }
main { max-width: 1100px; margin: 0 auto; padding: 16px 16px 80px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--panel-2); color: var(--text);
  font: inherit; font-size: .95rem; cursor: pointer; white-space: nowrap;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #1c1407; font-weight: 600; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); background: transparent; }
.btn.big { min-height: 56px; font-size: 1.05rem; width: 100%; }
.btn:disabled { opacity: .5; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row > .grow { flex: 1; min-width: 0; }
.stack { display: grid; gap: 10px; }
.muted { color: var(--muted); font-size: .9rem; }
.center { text-align: center; }

input, select, textarea {
  width: 100%; min-height: 42px; padding: 8px 12px;
  background: var(--panel); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--radius);
  font: inherit;
}
textarea { min-height: 84px; resize: vertical; }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label { display: grid; gap: 4px; font-size: .85rem; color: var(--muted); }
.form { display: grid; gap: 12px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form .wide { grid-column: 1 / -1; }

/* 列表 */
.toolbar { display: flex; gap: 8px; margin-bottom: 8px; }
.toolbar select { width: auto; flex: none; }
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); margin-top: 14px; }
.card { display: block; min-width: 0; }
.cover {
  aspect-ratio: 1; width: 100%; display: block; object-fit: cover;
  background: var(--panel); border-radius: 6px; border: 1px solid var(--line);
}
.cover.empty { display: grid; place-items: center; color: var(--line); font-size: 2.4rem; }
.card .t { margin-top: 6px; font-size: .9rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card .a { font-size: .8rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty-state { text-align: center; padding: 60px 16px; color: var(--muted); }

/* 入庫 */
.scanner { position: relative; background: #000; border-radius: var(--radius); overflow: hidden; aspect-ratio: 4 / 3; }
.scanner video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scanner::after {
  content: ""; position: absolute; left: 10%; right: 10%; top: 50%;
  height: 2px; background: var(--accent); box-shadow: 0 0 8px var(--accent);
}
.results { display: grid; gap: 8px; margin-top: 12px; }
.result {
  display: flex; gap: 12px; align-items: center; text-align: left; width: 100%;
  padding: 8px; background: var(--panel); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--radius); font: inherit; cursor: pointer;
}
.result img, .result .ph { width: 64px; height: 64px; flex: none; object-fit: cover; border-radius: 4px; background: var(--panel-2); }
.result .info { min-width: 0; flex: 1; }
.result .info b { display: block; overflow-wrap: anywhere; }
.result .info span { display: block; font-size: .82rem; color: var(--muted); overflow-wrap: anywhere; }
.badge { flex: none; font-size: .75rem; padding: 2px 8px; border-radius: 99px; background: var(--accent); color: #1c1407; font-weight: 600; }

/* 詳細頁 */
.detail { display: grid; gap: 24px; grid-template-columns: minmax(0, 320px) minmax(0, 1fr); align-items: start; }
.detail h1 { font-size: 1.4rem; margin: 0; line-height: 1.3; overflow-wrap: anywhere; }
.detail .sub { color: var(--muted); margin: 4px 0 0; overflow-wrap: anywhere; }
.photos { display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); }
.photo { position: relative; }
.photo img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 6px; display: block; border: 1px solid var(--line); }
.photo.is-cover img { border-color: var(--accent); }
.tracks { margin: 0; padding: 0; list-style: none; font-size: .92rem; }
.tracks li { display: flex; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.tracks .pos { color: var(--muted); width: 2.4em; flex: none; }
.tracks .ttl { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.tracks .dur { color: var(--muted); }

.viewer { position: fixed; inset: 0; z-index: 30; background: rgba(0,0,0,.94); display: flex; flex-direction: column; }
.viewer img { flex: 1; min-height: 0; width: 100%; object-fit: contain; }
.viewer .row { padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); justify-content: center; }

#toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  z-index: 40; max-width: calc(100vw - 32px);
  padding: 10px 16px; border-radius: var(--radius);
  background: var(--text); color: var(--bg); font-size: .92rem;
}

@media (max-width: 720px) {
  .detail { grid-template-columns: minmax(0, 1fr); }
  .detail .cover-wrap { max-width: 260px; margin: 0 auto; width: 100%; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 12px; }
}

/* 登入 */
body.locked header nav { display: none; }
.auth { max-width: 360px; margin: 12vh auto 0; }

/* 拉正裁切 */
.cropper { touch-action: none; user-select: none; -webkit-user-select: none; }
.crop-area { flex: 1; min-height: 0; display: grid; place-items: center; padding: 28px; }
.stage { position: relative; line-height: 0; }
.stage img { max-width: calc(100vw - 56px); max-height: calc(100vh - 220px); max-height: calc(100dvh - 220px); width: auto; height: auto; flex: none; }
.stage svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; }
.stage polygon { fill: rgba(224, 161, 58, .12); stroke: var(--accent); stroke-width: 2; vector-effect: non-scaling-stroke; }
.handle {
  position: absolute; width: 44px; height: 44px; margin: -22px 0 0 -22px;
  border-radius: 50%; border: 2px solid #fff; background: rgba(224, 161, 58, .25);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .6); touch-action: none; cursor: grab;
}
.handle::after { content: ""; position: absolute; left: 50%; top: 50%; width: 6px; height: 6px; margin: -3px 0 0 -3px; border-radius: 50%; background: #fff; }
.check { display: flex; align-items: center; gap: 6px; grid-auto-flow: column; color: var(--text); font-size: .9rem; }
.check input { width: 20px; min-height: 20px; height: 20px; padding: 0; }
.viewer .row { flex-wrap: wrap; }
