:root {
  --bg: #f3f6f9;
  --surface: #ffffff;
  --surface-2: #f7f9fc;
  --border: #e3e8f0;
  --text: #1f2a37;
  --text-dim: #6b7689;
  --primary: #4f8cff;
  --primary-dark: #3b78ee;
  --secondary: #6c757d;
  --success: #2ea36b;
  --danger: #e2574c;
  --shadow: 0 4px 6px rgba(20, 30, 50, .07), 0 10px 20px rgba(20, 30, 50, .08);
  --radius: 14px;
  --radius-pill: 999px;
  --transition: 160ms ease;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.icon {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}

.container {
  max-width: 820px;
  margin: 40px auto;
  padding: 36px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

h1 {
  margin: 0 0 28px;
  text-align: center;
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
}

h2 {
  margin: 0 0 16px;
  font-size: 18px;
  font-weight: 600;
  text-align: center;
  color: var(--text);
}

.input-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 24px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field > span {
  font-size: 13px;
  color: var(--primary);
  font-weight: 500;
}

input, textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  font-size: 15px;
  font-family: inherit;
  color: var(--text);
  background: var(--surface-2);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}

input:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 140, 255, .15);
}

textarea {
  border-radius: var(--radius);
  min-height: 180px;
  resize: vertical;
  background: var(--surface);
  border: 1px solid var(--primary);
  padding: 16px;
  line-height: 1.55;
}

.button-row {
  display: flex;
  justify-content: center;
  gap: 14px;
  margin-bottom: 18px;
}

.token-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  margin-bottom: 28px;
  flex-wrap: wrap;
}

.token-field {
  flex: 1;
  min-width: 220px;
}

.token-row .btn { padding: 11px 16px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 24px;
  border: 1px solid transparent;
  border-radius: var(--radius-pill);
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: transform var(--transition), background-color var(--transition), border-color var(--transition);
}

.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: .6; cursor: not-allowed; transform: none; }

.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }

.btn-secondary { background: var(--secondary); color: #fff; border-color: var(--secondary); }

.btn-copy { background: var(--success); color: #fff; border-color: var(--success); width: 100%; margin-top: 16px; }

.output-section { margin-bottom: 28px; }

.output-container {
  background: var(--surface-2);
  padding: 16px;
  border-radius: var(--radius);
  margin-bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.output-container:empty::after {
  content: "Заполните поля выше и нажмите «Создать список»";
  display: block;
  text-align: center;
  color: var(--text-dim);
  font-size: 14px;
  padding: 24px 8px;
}

.line {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color var(--transition), box-shadow var(--transition);
}

.line.drag-over {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(79, 140, 255, .15);
}

.line-head {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.line-num {
  font-weight: 600;
  color: var(--primary);
  min-width: 28px;
  font-variant-numeric: tabular-nums;
}

.line-input {
  flex: 1;
  min-width: 160px;
  padding: 9px 12px;
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.line-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 140, 255, .15);
}

.line-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.line-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 7px 12px;
  border-radius: var(--radius-pill);
  border: none;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  transition: background-color var(--transition), color var(--transition), transform var(--transition);
}

.line-btn .icon { width: 14px; height: 14px; }

.line-btn:hover { transform: translateY(-1px); }
.line-btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }

.line-btn.pick { background: #e9ecef; color: var(--text); }
.line-btn.pick:hover { background: #dde2e8; }

.line-btn.upload { background: var(--primary); color: #fff; }
.line-btn.upload:hover { background: var(--primary-dark); }
.line-btn.upload.busy { background: #d1e8ff; color: var(--primary-dark); }
.line-btn.upload.done { background: var(--success); }
.line-btn.upload.fail { background: var(--danger); }

.thumbs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 0;
}

.thumbs:empty { display: none; }

.thumb {
  position: relative;
  width: 48px;
  height: 48px;
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface-2);
  border: 1px solid var(--border);
  flex-shrink: 0;
}

.thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.thumb-link {
  position: absolute;
  inset: 0;
  text-decoration: none;
  color: transparent;
}

.thumb-pending-dot {
  position: absolute;
  bottom: 3px;
  right: 3px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--primary);
  box-shadow: 0 0 0 2px var(--surface);
}

.thumb-remove {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: rgba(20, 30, 50, .7);
  color: #fff;
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  opacity: 0;
  transition: opacity var(--transition);
}

.thumb:hover .thumb-remove { opacity: 1; }

.thumb-remove .icon { width: 11px; height: 11px; }

.progress {
  width: 100%;
  height: 3px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
}

.progress[hidden] { display: none; }

.progress-bar {
  height: 100%;
  width: 0;
  background: var(--primary);
  transition: width 120ms linear;
}

.scroll-btn[hidden] { display: none; }

.help-btn, .scroll-btn {
  position: fixed;
  border: none;
  background: var(--primary);
  color: #fff;
  border-radius: 50%;
  width: 44px;
  height: 44px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow);
  opacity: .55;
  transition: opacity var(--transition), transform var(--transition);
}

.help-btn:hover, .scroll-btn:hover { opacity: 1; transform: scale(1.05); }

.help-btn { top: 20px; right: 20px; }
.scroll-btn { bottom: 20px; right: 20px; }

.help-btn .icon, .scroll-btn .icon { width: 20px; height: 20px; }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 22, 36, .5);
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal[hidden] { display: none; }

.modal-card {
  background: var(--surface);
  border-radius: var(--radius);
  max-width: 520px;
  width: 100%;
  padding: 28px;
  box-shadow: var(--shadow);
  position: relative;
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  border: none;
  background: var(--surface-2);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  color: var(--text-dim);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.modal-card h2 { margin: 0 0 14px; text-align: left; }

.help-list { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 8px; font-size: 14px; color: var(--text); }

.toast-container {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 80;
  pointer-events: none;
}

.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--primary);
  border-radius: 10px;
  padding: 12px 18px;
  font-size: 14px;
  box-shadow: var(--shadow);
  min-width: 220px;
  text-align: center;
  animation: toast-in 200ms ease;
}

.toast.success { border-left-color: var(--success); }
.toast.error   { border-left-color: var(--danger); }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: translateY(0); }
}

@media (max-width: 720px) {
  .container { margin: 12px; padding: 18px; border-radius: 12px; }
  h1 { font-size: 22px; margin-bottom: 18px; }
  .input-grid { grid-template-columns: 1fr; gap: 12px; }
  .button-row { flex-direction: column; gap: 10px; }
  .btn { width: 100%; }
  .token-row { flex-direction: column; align-items: stretch; }
  .line { padding: 10px; }
  .line-input { width: 100%; }
  .line-actions { width: 100%; justify-content: stretch; }
  .line-btn { flex: 1; justify-content: center; }
}
