:root {
  --bg: #121212;
  --surface: #212121;
  --surface-2: #2a2a2a;
  --surface-3: #424242;
  --line: rgba(255, 255, 255, 0.12);
  --text: #ffffff;
  --text-2: rgba(255, 255, 255, 0.7);
  --text-3: rgba(255, 255, 255, 0.5);
  --primary: #1976d2;
  --primary-soft: rgba(25, 118, 210, 0.16);
  --secondary: #dca001;
  --success: #00e676;
  --drawer: 256px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 Roboto, "Segoe UI", system-ui, -apple-system, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
svg { fill: currentColor; }
[hidden] { display: none !important; }

/* ---------------------------------------------------------------- layout */

.app { display: flex; min-height: 100%; }

.drawer {
  position: fixed; inset: 0 auto 0 0; width: var(--drawer); z-index: 30;
  background: var(--surface); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; overflow-y: auto;
  transition: transform .2s ease;
}
.drawer-brand { display: block; padding: 20px 20px 4px; }
.drawer-brand img { max-width: 160px; height: auto; display: block; }
.drawer-sub { padding: 0 20px 12px; color: var(--secondary); font-weight: 500; letter-spacing: .08em; text-transform: uppercase; font-size: 12px; }
.drawer-nav { padding: 4px 8px; flex: 1; }
.nav-group { padding: 16px 12px 6px; font-size: 12px; color: var(--text-3); font-weight: 500; letter-spacing: .04em; text-transform: uppercase; }
.nav-item {
  display: flex; align-items: center; gap: 16px; padding: 0 12px; height: 40px; margin: 2px 0;
  border-radius: 4px; text-decoration: none; color: var(--text-2); font-weight: 500;
}
.nav-item svg { width: 22px; height: 22px; flex: none; opacity: .85; }
.nav-item span { flex: 1; }
.nav-item em { font-style: normal; font-size: 12px; color: var(--text-3); }
.nav-item:hover { background: rgba(255, 255, 255, 0.06); color: var(--text); }
.nav-item.active { background: var(--primary-soft); color: #64b5f6; }
.nav-item.active em { color: #64b5f6; }
.drawer-foot { padding: 14px 20px; border-top: 1px solid var(--line); font-size: 12px; color: var(--text-3); }
.drawer-foot b { color: var(--success); font-weight: 500; }
.drawer-foot .warn { color: var(--secondary); }

.scrim { display: none; }

.main { flex: 1; margin-left: var(--drawer); min-width: 0; display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 20; height: 56px; display: none; align-items: center; gap: 8px;
  padding: 0 8px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.topbar-title { font-size: 18px; font-weight: 500; }
.topbar-title span { color: var(--secondary); }

.content { padding: 24px 28px 48px; max-width: 1680px; width: 100%; }

.icon-btn {
  width: 40px; height: 40px; border-radius: 50%; border: 0; background: transparent; color: var(--text);
  display: inline-flex; align-items: center; justify-content: center; cursor: pointer;
}
.icon-btn svg { width: 24px; height: 24px; }
.icon-btn:hover { background: rgba(255, 255, 255, 0.08); }

/* ---------------------------------------------------------------- header + filters */

.page-head h1 { margin: 0 0 4px; font-size: 30px; font-weight: 400; display: flex; align-items: center; gap: 12px; }
.chip {
  display: inline-flex; align-items: center; height: 26px; padding: 0 12px; border-radius: 13px;
  background: var(--surface-3); font-size: 13px; font-weight: 500; color: var(--text);
}
.page-desc { margin: 0 0 20px; color: var(--text-2); max-width: 820px; }

.filters { display: flex; flex-wrap: wrap; gap: 12px; align-items: stretch; margin-bottom: 16px; }
.field {
  position: relative; display: flex; align-items: center; min-height: 56px;
  background: rgba(255, 255, 255, 0.06); border-radius: 4px 4px 0 0; border-bottom: 1px solid rgba(255, 255, 255, 0.42);
  transition: background .15s;
}
.field:hover { background: rgba(255, 255, 255, 0.09); }
.field:focus-within { border-bottom: 2px solid var(--primary); }
.field-search { flex: 1 1 340px; padding: 0 12px; gap: 10px; }
.field-search svg { width: 22px; height: 22px; color: var(--text-2); flex: none; }
.field-search input {
  flex: 1; background: transparent; border: 0; outline: 0; color: var(--text); font: inherit; font-size: 16px; height: 54px; min-width: 0;
}
.field-select { flex: 0 1 220px; flex-direction: column; align-items: stretch; justify-content: center; padding: 0 12px; }
.field-select span { font-size: 12px; color: var(--text-2); line-height: 1; margin-top: 8px; }
.field-select select {
  appearance: none; background: transparent; border: 0; outline: 0; color: var(--text); font: inherit; font-size: 15px;
  padding: 4px 22px 8px 0; cursor: pointer; width: 100%;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-2) 50%), linear-gradient(135deg, var(--text-2) 50%, transparent 50%);
  background-position: calc(100% - 9px) 52%, calc(100% - 4px) 52%;
  background-size: 5px 5px; background-repeat: no-repeat;
}
.field-select select option { background: var(--surface); color: var(--text); }
.toggle { display: flex; align-items: center; gap: 8px; color: var(--text-2); cursor: pointer; user-select: none; padding: 0 6px; }
.toggle input { accent-color: var(--primary); width: 18px; height: 18px; }

.result-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; color: var(--text-2); }

.pager { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.pager-bottom { justify-content: center; margin-top: 24px; }
.pager button {
  min-width: 36px; height: 36px; padding: 0 10px; border: 0; border-radius: 4px; cursor: pointer;
  background: transparent; color: var(--text); font: inherit; font-weight: 500;
}
.pager button:hover:not(:disabled) { background: rgba(255, 255, 255, 0.08); }
.pager button.current { background: var(--primary); color: #fff; }
.pager button:disabled { color: var(--text-3); cursor: default; }
.pager .gap { color: var(--text-3); padding: 0 4px; }

/* ---------------------------------------------------------------- object grid */

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 16px; }
.card {
  position: relative; background: var(--surface); border-radius: 4px; overflow: hidden; cursor: pointer;
  box-shadow: 0 2px 1px -1px rgba(0,0,0,.2), 0 1px 1px 0 rgba(0,0,0,.14), 0 1px 3px 0 rgba(0,0,0,.12);
  transition: box-shadow .15s, transform .15s;
  display: flex; flex-direction: column; text-align: left; border: 0; color: inherit; font: inherit; padding: 0;
}
.card:hover { box-shadow: 0 5px 5px -3px rgba(0,0,0,.2), 0 8px 10px 1px rgba(0,0,0,.14), 0 3px 14px 2px rgba(0,0,0,.12); transform: translateY(-2px); }
.card:focus-visible { outline: 2px solid var(--primary); }
.thumb {
  position: relative; aspect-ratio: 1 / 1; background: radial-gradient(circle at 50% 40%, #3a3a3a, #1b1b1b 75%);
  display: flex; align-items: center; justify-content: center; overflow: hidden;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .noimg { width: 42%; height: 42%; color: rgba(255, 255, 255, 0.14); }
.thumb::after {
  content: ""; position: absolute; inset: auto 0 0 0; height: 40%;
  background: linear-gradient(to top right, rgba(18,18,18,.9), rgba(33,33,33,.1)); pointer-events: none;
}
.badge {
  position: absolute; top: 8px; left: 8px; z-index: 1; font-size: 11px; font-weight: 500; padding: 2px 8px; border-radius: 10px;
  background: rgba(0, 0, 0, 0.6); color: var(--secondary); max-width: calc(100% - 16px); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.badge.server { color: #64b5f6; }
.card-body { padding: 10px 12px 12px; display: flex; align-items: center; gap: 6px; min-width: 0; }
.card-text { flex: 1; min-width: 0; }
.card-name { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px; }
.card-hash { font-size: 12px; color: var(--text-3); font-family: ui-monospace, "Roboto Mono", Consolas, monospace; }
.copy-btn {
  flex: none; width: 32px; height: 32px; border-radius: 50%; border: 0; background: transparent; color: var(--text-2); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
}
.copy-btn svg { width: 18px; height: 18px; }
.copy-btn:hover { background: rgba(255, 255, 255, 0.1); color: var(--text); }

/* ---------------------------------------------------------------- animation list */

.anim-list { background: var(--surface); border-radius: 4px; overflow: hidden; box-shadow: 0 1px 3px rgba(0,0,0,.3); }
.anim-row { border-bottom: 1px solid var(--line); }
.anim-row:last-child { border-bottom: 0; }
.anim-head {
  display: flex; align-items: center; gap: 14px; width: 100%; padding: 12px 16px; background: transparent; border: 0;
  color: inherit; font: inherit; text-align: left; cursor: pointer;
}
.anim-head:hover { background: rgba(255, 255, 255, 0.04); }
.anim-icon { width: 40px; height: 40px; border-radius: 50%; background: var(--primary-soft); color: #64b5f6; display: flex; align-items: center; justify-content: center; flex: none; }
.anim-icon svg { width: 22px; height: 22px; }
.anim-main { flex: 1; min-width: 0; }
.anim-dict { font-family: ui-monospace, "Roboto Mono", Consolas, monospace; font-size: 14px; word-break: break-all; }
.anim-meta { font-size: 12px; color: var(--text-3); }
.anim-matches { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 16px 12px 70px; }
.clip-chip {
  font-family: ui-monospace, "Roboto Mono", Consolas, monospace; font-size: 12px; padding: 3px 10px; border-radius: 14px;
  background: var(--surface-3); color: var(--text); border: 0; cursor: pointer;
}
.clip-chip:hover { background: var(--primary); }
.clip-chip mark, .anim-dict mark, .card-name mark { background: transparent; color: var(--secondary); }

/* ---------------------------------------------------------------- dialog */

.dialog-wrap {
  position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, 0.6);
  display: flex; align-items: flex-start; justify-content: center; padding: 48px 16px; overflow-y: auto;
}
.dialog {
  position: relative; width: 100%; max-width: 900px; background: var(--surface); border-radius: 4px;
  box-shadow: 0 11px 15px -7px rgba(0,0,0,.2), 0 24px 38px 3px rgba(0,0,0,.14), 0 9px 46px 8px rgba(0,0,0,.12);
}
.dialog-close { position: absolute; top: 8px; right: 8px; z-index: 2; }
.detail { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.detail .thumb { aspect-ratio: 1 / 1; border-radius: 4px 0 0 4px; }
.detail .thumb::after { display: none; }
.detail-info { padding: 24px 24px 20px; min-width: 0; }
.detail-info h2 { margin: 0 40px 4px 0; font-size: 22px; font-weight: 500; word-break: break-all; }
.detail-sub { color: var(--text-2); margin-bottom: 18px; }
.kv { display: grid; grid-template-columns: 110px minmax(0, 1fr) auto; align-items: center; gap: 2px 8px; }
.kv dt { color: var(--text-3); font-size: 13px; }
.kv dd { margin: 0; font-family: ui-monospace, "Roboto Mono", Consolas, monospace; font-size: 13px; word-break: break-all; padding: 6px 0; }
.snippet-tabs { display: flex; gap: 2px; margin: 20px 0 0; border-bottom: 1px solid var(--line); }
.snippet-tabs button {
  background: transparent; border: 0; color: var(--text-2); font: inherit; font-weight: 500; padding: 10px 16px; cursor: pointer;
  border-bottom: 2px solid transparent; text-transform: uppercase; font-size: 13px; letter-spacing: .04em;
}
.snippet-tabs button.active { color: #64b5f6; border-bottom-color: var(--primary); }
.snippet { position: relative; }
.snippet pre {
  margin: 0; background: #181818; padding: 14px 44px 14px 14px; border-radius: 0 0 4px 4px; overflow-x: auto;
  font: 12.5px/1.55 ui-monospace, "Roboto Mono", Consolas, monospace; color: #e0e0e0;
}
.snippet .copy-btn { position: absolute; top: 6px; right: 6px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 18px; }
.btn {
  display: inline-flex; align-items: center; gap: 8px; height: 36px; padding: 0 16px; border-radius: 4px; border: 0; cursor: pointer;
  background: var(--primary); color: #fff; font: inherit; font-weight: 500; text-transform: uppercase; font-size: 13px; letter-spacing: .04em;
  text-decoration: none;
}
.btn svg { width: 18px; height: 18px; }
.btn.outlined { background: transparent; color: #64b5f6; box-shadow: inset 0 0 0 1px rgba(100, 181, 246, 0.5); }
.btn:hover { filter: brightness(1.12); }

.anim-detail { padding: 24px; }
.anim-detail h2 { margin: 0 40px 4px 0; font-size: 20px; font-weight: 500; font-family: ui-monospace, "Roboto Mono", Consolas, monospace; word-break: break-all; }
.clip-filter { margin: 16px 0 10px; }
.clip-filter .field { min-height: 44px; }
.clip-filter input { height: 42px !important; font-size: 14px !important; }
.clip-table { width: 100%; border-collapse: collapse; }
.clip-table td { padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.clip-table tr.sel td { background: var(--primary-soft); }
.clip-table td:first-child { font-family: ui-monospace, "Roboto Mono", Consolas, monospace; font-size: 13px; word-break: break-all; cursor: pointer; }
.clip-table td:last-child { width: 1%; white-space: nowrap; text-align: right; }
.clip-scroll { max-height: 340px; overflow-y: auto; border: 1px solid var(--line); border-radius: 4px; }

/* ---------------------------------------------------------------- misc */

.empty { padding: 48px 16px; text-align: center; color: var(--text-3); }
.loading { padding: 80px 16px; text-align: center; color: var(--text-2); }
.loading .bar { height: 4px; max-width: 320px; margin: 0 auto 14px; background: rgba(25, 118, 210, 0.25); position: relative; overflow: hidden; border-radius: 2px; }
.loading .bar::after { content: ""; position: absolute; inset: 0; width: 40%; background: var(--primary); animation: slide 1.1s infinite ease-in-out; }
@keyframes slide { from { transform: translateX(-100%); } to { transform: translateX(260%); } }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); z-index: 60; opacity: 0; pointer-events: none;
  background: #323232; color: #fff; padding: 12px 18px; border-radius: 4px; box-shadow: 0 3px 5px -1px rgba(0,0,0,.3); transition: all .2s;
  max-width: calc(100% - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------------------------------------------------------------- small screens */

@media (max-width: 1100px) {
  .drawer { transform: translateX(-100%); }
  body.drawer-open .drawer { transform: none; }
  body.drawer-open .scrim { display: block; position: fixed; inset: 0; z-index: 25; background: rgba(0, 0, 0, 0.5); }
  .main { margin-left: 0; }
  .topbar { display: flex; }
}
@media (max-width: 720px) {
  .content { padding: 16px 16px 40px; }
  .page-head h1 { font-size: 24px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
  .field-select { flex: 1 1 calc(50% - 6px); }
  .detail { grid-template-columns: 1fr; }
  .detail .thumb { border-radius: 4px 4px 0 0; }
  .dialog-wrap { padding: 16px 8px; }
  .kv { grid-template-columns: 90px minmax(0, 1fr) auto; }
  .anim-matches { padding-left: 16px; }
}
