:root {
  --bg: #0b0d14;
  --bg-2: #11141d;
  --panel: #151926;
  --panel-2: #1b2030;
  --line: #252b3d;
  --line-2: #2f374d;
  --txt: #e6e9f2;
  --txt-dim: #9aa3bb;
  --txt-mute: #6c7691;
  --acc: #5ef0a8;
  --acc-2: #7c5cff;
  --warn: #ffb347;
  --common: #9aa3bb;
  --rare: #4aa8ff;
  --epic: #b06bff;
  --legendary: #ffb347;
  --skill: #5ef0a8;
  --radius: 10px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--txt);
  font-family: "Nunito", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

button, input, select { font-family: inherit; }

#app {
  display: grid;
  grid-template-rows: auto 1fr;
  height: 100%;
}

/* ---------------- header ---------------- */
#topbar {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 18px;
  height: 58px;
  background: linear-gradient(180deg, #151a29 0%, #10131c 100%);
  border-bottom: 1px solid var(--line);
  z-index: 20;
}

#brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  letter-spacing: .3px;
  font-size: 15px;
  white-space: nowrap;
}

#brand .logo {
  width: 26px; height: 26px;
  border-radius: 7px;
  background: conic-gradient(from 140deg, var(--acc), var(--acc-2), var(--acc));
  box-shadow: 0 0 18px rgba(94, 240, 168, .35);
}

#brand small {
  display: block;
  font-size: 10px;
  font-weight: 600;
  color: var(--txt-mute);
  letter-spacing: .6px;
  text-transform: uppercase;
}

#tabs {
  display: flex;
  gap: 4px;
  margin-left: 8px;
  flex-wrap: wrap;
}

.tab {
  border: 1px solid transparent;
  background: transparent;
  color: var(--txt-dim);
  padding: 7px 13px;
  border-radius: 8px;
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
  transition: .15s;
  white-space: nowrap;
}
.tab:hover { background: var(--panel-2); color: var(--txt); }
.tab.active {
  background: rgba(94, 240, 168, .12);
  color: var(--acc);
  border-color: rgba(94, 240, 168, .3);
}

#stats {
  margin-left: auto;
  display: flex;
  gap: 14px;
  font-size: 11px;
  color: var(--txt-mute);
  font-variant-numeric: tabular-nums;
}
#stats b { color: var(--txt-dim); font-weight: 700; }

/* ---------------- layout ---------------- */
#main {
  display: grid;
  grid-template-columns: 264px 1fr 320px;
  min-height: 0;
}

#sidebar, #inspector {
  background: var(--bg-2);
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0;
}
#sidebar { border-right: 1px solid var(--line); }
#inspector { border-left: 1px solid var(--line); }

#sidebar::-webkit-scrollbar, #inspector::-webkit-scrollbar,
.panel-scroll::-webkit-scrollbar { width: 8px; }
#sidebar::-webkit-scrollbar-thumb, #inspector::-webkit-scrollbar-thumb,
.panel-scroll::-webkit-scrollbar-thumb {
  background: #2a3044; border-radius: 4px;
}

.sec {
  padding: 12px 14px 4px;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 1.1px;
  text-transform: uppercase;
  color: var(--txt-mute);
}

.asset-list { padding: 4px 8px 12px; display: flex; flex-direction: column; gap: 2px; }

.asset-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 9px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 12.5px;
  color: var(--txt-dim);
  border: 1px solid transparent;
  transition: .12s;
  text-align: left;
  background: none;
  width: 100%;
}
.asset-item:hover { background: var(--panel); color: var(--txt); }
.asset-item.active {
  background: linear-gradient(90deg, rgba(124, 92, 255, .22), rgba(94, 240, 168, .08));
  border-color: rgba(124, 92, 255, .4);
  color: #fff;
}
.asset-item .dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--acc-2); flex: 0 0 auto;
}
.asset-item.enemy .dot { background: #ff6b6b; }
.asset-item.player .dot { background: var(--acc); }
.asset-item.prop .dot { background: var(--warn); }
.asset-item .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.asset-item .badge {
  margin-left: auto;
  font-size: 9.5px;
  color: var(--txt-mute);
  font-variant-numeric: tabular-nums;
  flex: 0 0 auto;
}

/* ---------------- stage ---------------- */
#stage {
  position: relative;
  background: radial-gradient(circle at 50% 38%, #1a2033 0%, #0a0c12 72%);
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

#canvas-holder { position: absolute; inset: 0; }
#canvas-holder canvas { display: block; }

#stage-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 14px;
}

#stage-title {
  pointer-events: none;
  background: rgba(10, 12, 19, .68);
  backdrop-filter: blur(8px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 9px 13px;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  align-self: flex-start;
  font-size: 13px;
  font-weight: 700;
  max-width: 100%;
}
#stage-title .sub {
  font-size: 10.5px;
  font-weight: 600;
  color: var(--txt-mute);
  letter-spacing: .4px;
  text-transform: uppercase;
}

#toolbar {
  pointer-events: auto;
  align-self: center;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: center;
  background: rgba(10, 12, 19, .72);
  backdrop-filter: blur(10px);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 7px;
  max-width: calc(100% - 20px);
}

.tool {
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--txt-dim);
  padding: 6px 11px;
  border-radius: 7px;
  font-size: 11.5px;
  font-weight: 700;
  cursor: pointer;
  transition: .13s;
  white-space: nowrap;
}
.tool:hover { border-color: var(--line-2); color: var(--txt); }
.tool.on {
  background: rgba(94, 240, 168, .16);
  border-color: rgba(94, 240, 168, .45);
  color: var(--acc);
}

#clipbar {
  pointer-events: auto;
  align-self: center;
  display: flex;
  gap: 6px;
  margin-top: 8px;
  flex-wrap: wrap;
  justify-content: center;
}
.clip {
  background: rgba(124, 92, 255, .14);
  border: 1px solid rgba(124, 92, 255, .38);
  color: #cfc4ff;
  padding: 5px 11px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
}
.clip.on { background: var(--acc-2); color: #fff; border-color: var(--acc-2); }

#hint {
  position: absolute;
  right: 14px;
  bottom: 14px;
  font-size: 10.5px;
  color: var(--txt-mute);
  text-align: right;
  line-height: 1.6;
  pointer-events: none;
}

#loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 12px;
  background: rgba(11, 13, 20, .82);
  z-index: 5;
  font-size: 12.5px;
  color: var(--txt-dim);
  letter-spacing: .4px;
}
#loading.hidden { display: none; }
.spin {
  width: 30px; height: 30px;
  border: 2.5px solid rgba(94, 240, 168, .18);
  border-top-color: var(--acc);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------- inspector ---------------- */
.insp-head {
  padding: 14px;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  background: var(--bg-2);
  z-index: 2;
}
.insp-head h2 {
  margin: 0 0 4px;
  font-size: 14px;
  font-weight: 800;
  letter-spacing: .2px;
}
.insp-head .tagline {
  font-size: 10.5px;
  color: var(--txt-mute);
  text-transform: uppercase;
  letter-spacing: .8px;
  font-weight: 700;
}

.insp-body { padding: 12px 14px 60px; }

.kv {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 0;
  border-bottom: 1px dashed rgba(47, 55, 77, .7);
  font-size: 12px;
}
.kv:last-child { border-bottom: none; }
.kv .k { color: var(--txt-mute); font-weight: 600; }
.kv .v {
  color: var(--txt);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.card-block {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 11px 12px;
  margin-bottom: 10px;
}
.card-block h3 {
  margin: 0 0 8px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--txt-mute);
  font-weight: 800;
}
.card-block p {
  margin: 0 0 8px;
  font-size: 11.5px;
  line-height: 1.65;
  color: var(--txt-dim);
}
.card-block p:last-child { margin-bottom: 0; }
.card-block code {
  background: #0a0c12;
  border: 1px solid var(--line);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 10.5px;
  color: var(--acc);
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
}

/* ---------------- grids for other tabs ---------------- */
.panel-scroll {
  grid-column: 1 / -1;
  overflow-y: auto;
  padding: 20px 22px 60px;
  min-height: 0;
}
.panel-scroll::-webkit-scrollbar { width: 10px; }

.panel-title {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0 0 4px;
  font-size: 19px;
  font-weight: 800;
}
.panel-desc {
  margin: 0 0 20px;
  font-size: 12.5px;
  color: var(--txt-mute);
  max-width: 820px;
  line-height: 1.7;
}

.tex-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(118px, 1fr));
  gap: 11px;
}
.tex-cell {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 9px;
  overflow: hidden;
  cursor: pointer;
  transition: .14s;
  position: relative;
}
.tex-cell:hover { border-color: var(--acc-2); transform: translateY(-2px); }
.tex-cell .thumb {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    linear-gradient(45deg, #171b28 25%, transparent 25%),
    linear-gradient(-45deg, #171b28 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #171b28 75%),
    linear-gradient(-45deg, transparent 75%, #171b28 75%);
  background-size: 14px 14px;
  background-position: 0 0, 0 7px, 7px -7px, -7px 0;
  padding: 5px;
}
.tex-cell img {
  max-width: 100%;
  max-height: 100%;
  display: block;
  image-rendering: auto;
}
.tex-cell .cap {
  font-size: 10px;
  padding: 5px 7px;
  color: var(--txt-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border-top: 1px solid var(--line);
  background: var(--panel-2);
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(196px, 1fr));
  gap: 12px;
  margin-top: 6px;
}
.gamecard {
  border-radius: 12px;
  border: 1px solid var(--line-2);
  background: var(--panel);
  overflow: hidden;
  position: relative;
  min-height: 132px;
  display: flex;
  flex-direction: column;
}
.gamecard .art {
  height: 74px;
  background-size: cover;
  background-position: center;
  position: relative;
}
.gamecard .art::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(10, 12, 19, .05), rgba(21, 25, 38, .96));
}
.gamecard .body { padding: 9px 11px 11px; position: relative; margin-top: -22px; }
.gamecard .rar {
  font-size: 9px;
  font-weight: 900;
  letter-spacing: 1.1px;
  text-transform: uppercase;
  margin-bottom: 4px;
}
.gamecard .nm {
  font-size: 12.5px;
  font-weight: 800;
  line-height: 1.35;
  margin-bottom: 5px;
}
.gamecard .ds { font-size: 10.5px; color: var(--txt-mute); line-height: 1.5; }

.r-common .rar { color: var(--common); }
.r-rare .rar { color: var(--rare); }
.r-epic .rar { color: var(--epic); }
.r-legendary .rar { color: var(--legendary); }
.r-skill .rar { color: var(--skill); }
.r-common { border-color: rgba(154, 163, 187, .35); }
.r-rare { border-color: rgba(74, 168, 255, .35); }
.r-epic { border-color: rgba(176, 107, 255, .38); }
.r-legendary { border-color: rgba(255, 179, 71, .4); }
.r-skill { border-color: rgba(94, 240, 168, .4); }

table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 11.5px;
  margin-top: 6px;
}
table.data th {
  text-align: left;
  padding: 7px 9px;
  background: var(--panel-2);
  color: var(--txt-mute);
  font-size: 9.5px;
  text-transform: uppercase;
  letter-spacing: .8px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
table.data td {
  padding: 7px 9px;
  border-bottom: 1px solid rgba(37, 43, 61, .65);
  color: var(--txt-dim);
  font-variant-numeric: tabular-nums;
}
table.data tr:hover td { background: rgba(124, 92, 255, .07); color: var(--txt); }
table.data td.num { text-align: right; }

pre.code {
  background: #08090e;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 12px 14px;
  font-size: 11px;
  line-height: 1.65;
  color: #b9c2d8;
  overflow: auto;
  max-height: 460px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  margin: 0;
}
pre.code .c { color: #55607a; }
pre.code .k { color: #c792ea; }
pre.code .s { color: #a5e8a0; }
pre.code .n { color: #ffb347; }

.audio-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 9px 12px;
  margin-bottom: 7px;
}
.audio-row .name { font-size: 12px; font-weight: 700; flex: 1; }
.audio-row .sz { font-size: 10.5px; color: var(--txt-mute); font-variant-numeric: tabular-nums; }
.audio-row audio { height: 30px; max-width: 260px; }

.chip-row { display: flex; gap: 6px; flex-wrap: wrap; margin: 10px 0 16px; }
.chip {
  padding: 5px 11px;
  border-radius: 20px;
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--txt-dim);
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
}
.chip.on { background: rgba(94, 240, 168, .14); border-color: rgba(94, 240, 168, .42); color: var(--acc); }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
@media (max-width: 1100px) { .two-col { grid-template-columns: 1fr; } }

.formula {
  background: #08090e;
  border-left: 3px solid var(--acc-2);
  border-radius: 0 8px 8px 0;
  padding: 10px 13px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 11.5px;
  color: var(--acc);
  margin: 8px 0;
  overflow-x: auto;
  white-space: pre;
}

/* lightbox */
#lightbox {
  position: fixed;
  inset: 0;
  background: rgba(5, 6, 10, .93);
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 14px;
  padding: 30px;
  cursor: zoom-out;
}
#lightbox.on { display: flex; }
#lightbox img {
  max-width: 88vw;
  max-height: 78vh;
  object-fit: contain;
  border-radius: 10px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, .8);
  background: #14182 a;
}
#lightbox .cap {
  font-size: 12px;
  color: var(--txt-dim);
  font-weight: 700;
  letter-spacing: .4px;
}

@media (max-width: 980px) {
  #main { grid-template-columns: 200px 1fr 0; }
  #inspector { display: none; }
}
@media (max-width: 680px) {
  #main { grid-template-columns: 0 1fr 0; }
  #sidebar { display: none; }
  #stats { display: none; }
}
