:root {
  --bg: #1a0e2e;
  --panel: #271843;
  --panel-2: #2f1d50;
  --gold: #d4a437;
  --gold-soft: #f7d764;
  --magenta: #c1274d;
  --violet: #6c3c9c;
  --text: #ece6f5;
  --text-dim: #b09cc8;
  --border: #3e2867;
  --keep: #4caf50;
  --change: #f44336;
  --discuss: #ff9800;
  --recolor: #00bcd4;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "PingFang TC", "Microsoft JhengHei", sans-serif;
  font-size: 13px;
  line-height: 1.5;
}
header {
  position: sticky;
  top: 0;
  background: linear-gradient(135deg, var(--panel) 0%, var(--panel-2) 100%);
  border-bottom: 2px solid var(--gold);
  padding: 10px 16px;
  z-index: 100;
}
.title-row {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 8px;
}
.title-row h1 { flex: 0 0 auto; }
.title-row #stats { flex: 0 0 auto; margin-left: auto; }
.tabs {
  display: flex;
  gap: 2px;
  flex: 0 0 auto;
}
.tabs .tab {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 5px 14px;
  border-radius: 4px 4px 0 0;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  border-bottom: none;
  position: relative;
  bottom: -2px;
}
.tabs .tab:hover { color: var(--text); }
.tabs .tab.active {
  background: var(--panel);
  color: var(--gold-soft);
  border-color: var(--gold);
  border-bottom: 2px solid var(--panel);
}
.tabs .count {
  font-size: 11px;
  color: var(--text-dim);
  margin-left: 4px;
}
.tabs .tab.active .count { color: var(--gold); }
.grid.hidden { display: none; }
.col-anim-no   { width: 64px; }
.col-anim-atlas { width: 200px; }
.col-anim-cat  { width: 150px; }
.col-anim-name { width: 220px; }
.col-anim-kind { width: 100px; }
.col-anim-len  { width: 80px; text-align: right; }
.col-anim-preview { width: 220px; }
.col-anim-sugg { width: 360px; }

td.col-anim-no { font-family: ui-monospace, "SF Mono", monospace; color: var(--text-dim); }
td.col-anim-atlas { color: var(--gold-soft); font-weight: 500; }
td.col-anim-name { font-family: ui-monospace, "SF Mono", monospace; word-break: break-all; }
td.col-anim-kind { color: var(--text-dim); font-size: 11px; }
td.col-anim-len { font-variant-numeric: tabular-nums; color: var(--text-dim); }
td.col-anim-sugg { white-space: pre-wrap; word-break: break-word; background: rgba(0,0,0,0.18); border-left: 3px solid var(--gold); }

.preview-thumb {
  display: inline-block;
  background:
    linear-gradient(45deg, #2d2244 25%, transparent 25%),
    linear-gradient(-45deg, #2d2244 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #2d2244 75%),
    linear-gradient(-45deg, transparent 75%, #2d2244 75%),
    var(--bg);
  background-size: 12px 12px;
  background-position: 0 0, 0 6px, 6px -6px, -6px 0px;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px;
  cursor: pointer;
  position: relative;
}
.preview-thumb img {
  display: block;
  max-width: 100px;
  max-height: 100px;
  object-fit: contain;
}
.preview-thumb:hover { box-shadow: 0 0 0 2px var(--gold); }
.preview-thumb .badge {
  position: absolute;
  top: 2px;
  right: 2px;
  background: rgba(0,0,0,0.7);
  color: var(--gold-soft);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 10px;
}
header h1 {
  margin: 0;
  font-size: 16px;
  color: var(--gold-soft);
}
header .tag {
  font-size: 11px;
  padding: 2px 6px;
  background: var(--magenta);
  color: white;
  border-radius: 3px;
  margin-left: 8px;
  vertical-align: middle;
}
#stats { color: var(--text-dim); font-size: 12px; }

.filters {
  display: flex;
  gap: 8px;
  align-items: center;
}
.filters input, .filters select, .filters button {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 5px 10px;
  border-radius: 4px;
  font-size: 13px;
}
.filters input { flex: 1; min-width: 200px; max-width: 400px; }
.filters button {
  background: var(--gold);
  color: var(--bg);
  border: none;
  cursor: pointer;
  font-weight: 600;
}
.filters button:hover { background: var(--gold-soft); }

main { padding: 0; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  table-layout: fixed;
}
thead {
  position: sticky;
  top: 78px;
  z-index: 50;
  background: var(--panel-2);
}
th, td {
  padding: 8px 10px;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--border);
}
th {
  font-weight: 600;
  color: var(--gold-soft);
  font-size: 12px;
  border-bottom: 2px solid var(--gold);
  white-space: nowrap;
}
th.sortable {
  cursor: pointer;
  user-select: none;
}
th.sortable::after {
  content: " ⇅";
  color: var(--text-dim);
  font-size: 10px;
  opacity: 0.5;
}
th.sortable:hover { color: white; }
th.sort-asc::after  { content: " ▲"; color: var(--gold); opacity: 1; }
th.sort-desc::after { content: " ▼"; color: var(--gold); opacity: 1; }
.col-no    { width: 64px; }
.col-cat   { width: 120px; }
.col-type  { width: 120px; }
.col-name  { width: 160px; }
.col-path  { width: 200px; }
.col-ext   { width: 60px; text-align: center; }
td.col-path {
  font-family: ui-monospace, "SF Mono", monospace;
  color: var(--text-dim);
  font-size: 11px;
  word-break: break-all;
  cursor: text;
  user-select: text;
}
td.col-path code {
  background: rgba(0,0,0,0.2);
  padding: 1px 4px;
  border-radius: 2px;
  display: inline-block;
}
.col-size  { width: 110px; }
.col-count { width: 60px; text-align: center; }
.col-thumb { width: 160px; }
.col-target { width: 160px; }
.col-note  { width: 200px; }
.col-sugg  { width: 360px; }
.col-mark  { width: 200px; }

td.col-no { font-family: ui-monospace, "SF Mono", monospace; color: var(--text-dim); }
.pair-badge {
  display: inline-block;
  margin-top: 4px;
  font-size: 10px;
  padding: 1px 5px;
  background: rgba(108, 60, 156, 0.3);
  border: 1px solid var(--violet);
  border-radius: 3px;
  color: var(--gold-soft);
  text-decoration: none;
  cursor: pointer;
}
.pair-badge:hover {
  background: var(--violet);
  color: white;
}
tr.flash { animation: flash 1.5s ease-out; }
@keyframes flash {
  0% { background: var(--gold); }
  100% { background: transparent; }
}
.lightbox-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.92);
  z-index: 10000;
  display: flex;
  flex-direction: column;
}
.lightbox-bar {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--gold);
  color: var(--text);
  font-size: 13px;
}
.lightbox-bar span { flex: 1; color: var(--gold-soft); }
.lightbox-bar button {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 4px 12px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
}
.lightbox-bar button:hover { border-color: var(--gold); }
.lightbox-content {
  flex: 1;
  overflow: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  align-items: center;
}
.lightbox-content figure {
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  max-width: 100%;
}
.lightbox-content img {
  display: block;
  background: repeating-conic-gradient(#222 0% 25%, #2a2a2a 0% 50%) 50% / 20px 20px;
}
.lightbox-content figcaption {
  font-size: 11px;
  color: var(--text-dim);
  font-family: ui-monospace, monospace;
}
td.col-name { font-weight: 600; color: var(--gold-soft); word-break: break-all; }
td.col-note, td.col-sugg { white-space: pre-wrap; word-break: break-word; }
td.col-sugg {
  background: rgba(0,0,0,0.18);
  border-left: 3px solid var(--gold);
}
.sugg-wrap { display: flex; flex-direction: column; gap: 4px; }
.sugg-display {
  white-space: pre-wrap;
  cursor: text;
  padding: 4px;
  border-radius: 3px;
  border: 1px solid transparent;
  font-size: 12px;
  line-height: 1.5;
  min-height: 22px;
}
.sugg-display:hover {
  background: rgba(212, 164, 55, 0.06);
  border-color: var(--border);
}
.sugg-display.edited {
  background: rgba(0, 188, 212, 0.06);
  border-left: 3px solid var(--recolor);
  padding-left: 8px;
}
.sugg-edit {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--gold);
  color: var(--text);
  padding: 6px 8px;
  border-radius: 3px;
  font-family: inherit;
  font-size: 12px;
  line-height: 1.5;
  resize: vertical;
  min-height: 100px;
}
.sugg-hint {
  font-size: 10px;
  color: var(--text-dim);
  font-style: italic;
}
.sugg-tagbar {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 10px;
}
.sugg-tag {
  color: var(--text-dim);
}
.sugg-display.edited + .sugg-tagbar .sugg-tag { color: var(--recolor); }
.sugg-reset {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 3px;
  cursor: pointer;
}
.sugg-reset:hover {
  border-color: var(--gold);
  color: var(--gold-soft);
}

.thumb-wrap {
  background:
    linear-gradient(45deg, #2d2244 25%, transparent 25%),
    linear-gradient(-45deg, #2d2244 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #2d2244 75%),
    linear-gradient(-45deg, transparent 75%, #2d2244 75%),
    var(--bg);
  background-size: 12px 12px;
  background-position: 0 0, 0 6px, 6px -6px, -6px 0px;
  border: 1px solid var(--border);
  border-radius: 4px;
  display: inline-block;
  cursor: pointer;
  position: relative;
  max-width: 150px;
  max-height: 150px;
  overflow: hidden;
}
.thumb-wrap img {
  display: block;
  max-width: 150px;
  max-height: 150px;
  object-fit: contain;
}
.thumb-wrap .play-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  background: rgba(0,0,0,0.7);
  color: var(--gold-soft);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 10px;
}
.thumb-wrap:hover { box-shadow: 0 0 0 2px var(--gold); }

.target-wrap {
  background:
    linear-gradient(45deg, #2d2244 25%, transparent 25%),
    linear-gradient(-45deg, #2d2244 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #2d2244 75%),
    linear-gradient(-45deg, transparent 75%, #2d2244 75%),
    var(--bg);
  background-size: 12px 12px;
  background-position: 0 0, 0 6px, 6px -6px, -6px 0px;
  border: 1px solid var(--violet);
  border-radius: 4px;
  display: inline-block;
  cursor: pointer;
  position: relative;
  max-width: 150px;
  max-height: 150px;
  overflow: hidden;
}
.target-wrap img {
  display: block;
  max-width: 150px;
  max-height: 150px;
  object-fit: contain;
}
.target-wrap::before {
  content: "🎯";
  position: absolute;
  top: 2px;
  right: 2px;
  background: rgba(0,0,0,0.7);
  color: var(--gold-soft);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 11px;
  z-index: 1;
}
.target-wrap:hover { box-shadow: 0 0 0 2px var(--violet); }

tr.row.keep td:first-child { box-shadow: inset 4px 0 0 var(--keep); }
tr.row.change td:first-child { box-shadow: inset 4px 0 0 var(--change); }
tr.row.discuss td:first-child { box-shadow: inset 4px 0 0 var(--discuss); }
tr.row.recolor td:first-child { box-shadow: inset 4px 0 0 var(--recolor); }
tr.row:hover td { background: rgba(255,255,255,0.03); }

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
}
.actions button {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 3px 6px;
  border-radius: 3px;
  cursor: pointer;
  font-size: 11px;
  white-space: nowrap;
}
.actions button.active.keep { background: var(--keep); color: white; border-color: var(--keep); }
.actions button.active.change { background: var(--change); color: white; border-color: var(--change); }
.actions button.active.discuss { background: var(--discuss); color: white; border-color: var(--discuss); }
.actions button.active.recolor { background: var(--recolor); color: var(--bg); border-color: var(--recolor); }

/* expanded preview row */
tr.preview-row > td {
  padding: 0;
  background: var(--panel);
  border-left: 4px solid var(--gold);
}

.summary-preview {
  display: grid;
  grid-template-columns: minmax(420px, 1fr) minmax(360px, 1.2fr);
  gap: 12px;
  padding: 12px 16px;
  max-height: 600px;
}
.summary-preview .stage-side { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.summary-preview .stage {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  height: 360px;
  position: relative;
  overflow: hidden;
}
.summary-preview .stage-info {
  font-size: 12px;
  color: var(--text-dim);
}
.summary-preview .stage-info b { color: var(--gold-soft); }
.summary-preview .anim-list {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow-y: auto;
  max-height: 580px;
}
.anim-list-header {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--gold-soft);
  font-size: 12px;
  font-weight: 500;
  position: sticky;
  top: 0;
  z-index: 1;
}
.anim-item {
  border-bottom: 1px solid var(--border);
  padding: 8px 12px;
  font-size: 12px;
}
.anim-item.active {
  background: rgba(212, 164, 55, 0.08);
  border-left: 3px solid var(--gold);
}
.anim-item.keep { border-left: 3px solid var(--keep); }
.anim-item.change { border-left: 3px solid var(--change); }
.anim-item.discuss { border-left: 3px solid var(--discuss); }
.anim-item.recolor { border-left: 3px solid var(--recolor); }
.anim-row1 {
  display: flex;
  gap: 8px;
  align-items: center;
  cursor: pointer;
  padding: 2px 0;
}
.anim-row1:hover { color: var(--gold-soft); }
.anim-row1 .anim-play {
  color: var(--gold);
  font-size: 13px;
}
.anim-row1 .anim-name {
  flex: 1;
  font-family: ui-monospace, monospace;
  word-break: break-all;
}
.anim-row1 .anim-len {
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  font-size: 11px;
}
.anim-marks { margin: 6px 0 4px; }
.anim-sugg { margin-top: 4px; }
.anim-sugg .sugg-display { font-size: 11px; }

/* plist frames grid (no stage) */
.frames-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 8px;
  padding: 12px 16px;
  max-height: 500px;
  overflow-y: auto;
}
.frame-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 6px;
  font-size: 11px;
}
.frame-card.keep { border-left: 3px solid var(--keep); }
.frame-card.change { border-left: 3px solid var(--change); }
.frame-card.discuss { border-left: 3px solid var(--discuss); }
.frame-card.recolor { border-left: 3px solid var(--recolor); }
.frame-thumb {
  background:
    linear-gradient(45deg, #2d2244 25%, transparent 25%),
    linear-gradient(-45deg, #2d2244 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #2d2244 75%),
    linear-gradient(-45deg, transparent 75%, #2d2244 75%),
    var(--bg);
  background-size: 12px 12px;
  background-position: 0 0, 0 6px, 6px -6px, -6px 0px;
  border: 1px solid var(--border);
  border-radius: 3px;
  height: 90px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  margin-bottom: 4px;
  overflow: hidden;
}
.frame-thumb img { max-width: 100%; max-height: 100%; object-fit: contain; }
.frame-thumb:hover { box-shadow: 0 0 0 2px var(--gold); }
.frame-name {
  font-family: ui-monospace, monospace;
  word-break: break-all;
  color: var(--text);
  margin-bottom: 2px;
}
.frame-size { color: var(--text-dim); font-size: 10px; margin-bottom: 4px; }
.frame-card .actions button { font-size: 10px; padding: 2px 4px; }
.frame-card .sugg-display { font-size: 11px; padding: 2px; min-height: 16px; }
.frame-card .sugg-display:empty::before { content: "✎ 點此寫說明"; color: var(--text-dim); font-style: italic; font-size: 10px; }
.preview-pane {
  display: grid;
  grid-template-columns: 480px 1fr;
  gap: 16px;
  padding: 14px 16px;
}
.preview-pane .stage {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  height: 360px;
  position: relative;
  overflow: hidden;
}
.preview-pane .stage img {
  max-width: 100%;
  max-height: 100%;
  display: block;
  margin: auto;
  position: absolute;
  inset: 0;
  object-fit: contain;
}
.preview-pane .info {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 13px;
}
.preview-pane .info b { color: var(--gold-soft); }
.preview-pane .info code {
  background: var(--bg);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 12px;
  color: var(--text-dim);
}
.preview-pane .err {
  color: var(--change);
  font-style: italic;
  padding: 12px;
}

.spine-player {
  width: 100%;
  height: 100%;
  background: var(--bg) !important;
}

footer {
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-dim);
}
.legend { font-style: italic; }
