* { box-sizing: border-box; }

:root {
  --bg: #1c1b26;
  --text: #efeaf6;
  --panel: #26242f;
  --cell: #2b293a;
  --border: #3c3a4a;
  --muted: #9b94ad;
  --accent: #7c5cd6;
}

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: ui-rounded, "Segoe UI", system-ui, -apple-system, sans-serif;
}

body { padding: 20px 16px 48px; }

header {
  max-width: 640px;
  margin: 0 auto 8px;
}
h1 { font-size: 26px; letter-spacing: -0.5px; }

main { max-width: 640px; margin: 0 auto; }

.hint { color: #9b94ad; font-size: 14px; margin: 8px 0 16px; }
.hidden { display: none; }

.tile-list {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin: 16px 0;
  min-height: 40px;
}

.tile-card {
  width: 110px;
  background: #26242f;
  border: 1px solid #3c3a4a;
  border-radius: 12px;
  padding: 8px;
  position: relative;
}
.tile-card .thumb {
  width: 92px; height: 92px;
  border-radius: 9px;
  object-fit: cover;
  display: block;
  background: #2b293a;
}
.tile-card .tval {
  position: absolute;
  top: 6px; left: 6px;
  background: rgba(0,0,0,0.62);
  color: #fff;
  border-radius: 7px;
  padding: 2px 7px;
  font-size: 13px;
  font-weight: 700;
}
.tile-card .tname {
  font-size: 13px;
  text-align: center;
  margin-top: 6px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tile-card .tby {
  font-size: 11px;
  color: #9b94ad;
  text-align: center;
}
.tile-card .del {
  position: absolute;
  top: 4px; right: 4px;
  width: 24px; height: 24px;
  border-radius: 50%;
  border: none;
  background: rgba(0,0,0,0.65);
  color: #fff;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  display: none;
}
.tile-card.tile-new { animation: tileIn 380ms ease; }
.tile-card.tile-gone { opacity: 0; transform: scale(0.6); transition: opacity 300ms, transform 300ms; pointer-events: none; }

@keyframes tileIn {
  0% { transform: scale(0.3); opacity: 0; }
  70% { transform: scale(1.06); }
  100% { transform: scale(1); opacity: 1; }
}

#upload-form { display: flex; gap: 8px; flex-wrap: wrap; }

.file-picker {
  background: #26242f;
  border: 1px solid #3c3a4a;
  border-radius: 10px;
  padding: 12px 14px;
  cursor: pointer;
  font-size: 13px;
  color: #9b94ad;
  flex: 1 1 150px;
}
.file-picker input { display: none; }
#upload-form input[type="text"] {
  flex: 2 1 150px;
  background: #26242f;
  border: 1px solid #3c3a4a;
  border-radius: 10px;
  padding: 12px 14px;
  color: #efeaf6;
  font-size: 14px;
  min-width: 0;
}
#upload-form input[type="text"]:focus { outline: none; border-color: #7c5cd6; }
#upload-btn {
  background: #7c5cd6;
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 12px 20px;
  font-size: 14px;
  cursor: pointer;
  font-weight: 600;
}
#upload-btn:disabled { opacity: 0.5; cursor: default; }

.msg { font-size: 13px; margin: 12px 0 0; min-height: 18px; }
.msg.error { color: #ff7b89; }
.msg.ok { color: #7bd88f; }

section { margin-top: 28px; }
.section-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.section-head h2 { margin: 0; font-size: 18px; }
#new-pack-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 9px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.pack-list { display: flex; flex-direction: column; gap: 10px; min-height: 40px; }

.pack-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  position: relative;
  cursor: pointer;
}
.pack-header { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.pack-header .pname { font-size: 15px; font-weight: 700; }
.pack-header .pby { font-size: 12px; color: var(--muted); }
.pack-thumbs { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.pack-thumbs img { width: 44px; height: 44px; border-radius: 7px; object-fit: cover; background: var(--cell); }
.pack-more {
  width: 44px;
  height: 44px;
  border-radius: 7px;
  background: var(--cell);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
  color: var(--muted);
}
.pack-actions { position: absolute; top: 10px; right: 10px; display: flex; gap: 6px; }
.pack-actions button {
  background: var(--border);
  border: none;
  color: var(--text);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 12px;
  cursor: pointer;
}

/* modal editor */
.modal {
  position: fixed;
  inset: 0;
  z-index: 10;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 24px 16px;
  overflow-y: auto;
}
.modal.hidden { display: none; }
.modal-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 18px;
  width: 100%;
  max-width: 460px;
}
.modal-card h3 { margin: 0 0 10px; font-size: 18px; }
.modal-card input[type="text"] {
  width: 100%;
  background: var(--cell);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 12px;
  color: var(--text);
  font-size: 14px;
  margin-bottom: 10px;
}
.modal-card input[type="text"]:focus { outline: none; border-color: var(--accent); }

.order-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
  min-height: 20px;
}
.order-item {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--cell);
  border-radius: 9px;
  padding: 6px 8px;
}
.order-item img { width: 30px; height: 30px; border-radius: 6px; object-fit: cover; }
.order-item .oname { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 110px; }
.order-item button {
  background: var(--border);
  border: none;
  color: var(--text);
  border-radius: 6px;
  width: 24px;
  height: 24px;
  cursor: pointer;
  font-size: 12px;
}

.pool-list { display: flex; flex-wrap: wrap; gap: 8px; }
.pool-item {
  position: relative;
  width: 56px;
  height: 56px;
  border-radius: 9px;
  overflow: hidden;
  border: 2px solid var(--border);
  cursor: pointer;
  background: var(--cell);
}
.pool-item img { width: 100%; height: 100%; object-fit: cover; display: block; }
.pool-item.sel { border-color: var(--accent); }
.pool-item .pmark {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 22px;
  font-weight: 700;
  background: rgba(124,92,214,0.75);
  opacity: 0;
}
.pool-item.sel .pmark { opacity: 1; }

.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.modal-actions button {
  background: var(--border);
  border: none;
  color: var(--text);
  border-radius: 9px;
  padding: 9px 16px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.modal-actions button.primary { background: var(--accent); color: #fff; }

/* pack viewer */
.viewer-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.viewer-head h3 { margin: 0; font-size: 18px; }
.viewer-head .hint { margin: 2px 0 0; }
.x-close {
  background: var(--border);
  border: none;
  color: var(--text);
  border-radius: 50%;
  width: 30px;
  height: 30px;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  flex: none;
}
.vcount { font-size: 12px; color: var(--muted); margin: 10px 0 12px; }
.viewer-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  max-height: 60vh;
  overflow-y: auto;
}
.viewer-item {
  width: 92px;
  background: var(--cell);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px;
}
.viewer-item img { width: 78px; height: 78px; object-fit: cover; border-radius: 7px; display: block; background: #1f1e28; }
.viewer-item .vname { font-size: 12px; text-align: center; margin-top: 5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewer-item .vby { font-size: 10px; color: var(--muted); text-align: center; }