:root {
  --bg: #0d1014;
  --bg-deep: #171b22;
  --ink: #f1ebe2;
  --muted: #a39a8f;
  --panel: #1b2028;
  --accent: #c73f2a;
  --accent-dark: #8f2a1b;
  --accent-soft: #f0a29a;
  --border: #2a303a;
  --shadow: rgba(6, 7, 10, 0.45);
  --nav-offset: 120px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Trebuchet MS", "Gill Sans", "Lucida Grande", sans-serif;
  color: var(--ink);
  background: linear-gradient(140deg, var(--bg) 0%, var(--bg-deep) 100%);
  min-height: 100vh;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background-image:
    radial-gradient(circle at 10% 10%, rgba(255, 255, 255, 0.08), transparent 45%),
    radial-gradient(circle at 85% 15%, rgba(199, 63, 42, 0.2), transparent 45%),
    repeating-linear-gradient(120deg, rgba(255, 255, 255, 0.04) 0, rgba(255, 255, 255, 0.04) 1px, transparent 1px, transparent 18px);
  pointer-events: none;
  z-index: -1;
}

h1,
h2 {
  font-family: "Palatino Linotype", "Book Antiqua", Palatino, serif;
  margin: 0;
}

p {
  margin: 0;
  line-height: 1.5;
}

.page {
  width: min(1500px, 96vw);
  margin: 0 auto;
  padding: 40px 0 80px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 22px;
  padding: 12px 16px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: rgba(20, 24, 31, 0.7);
  box-shadow: 0 18px 30px -24px var(--shadow);
  position: sticky;
  top: 12px;
  z-index: 20;
  backdrop-filter: blur(10px);
}

.topbar-left,
.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.search-wrap {
  position: relative;
}

.topbar-search {
  min-width: min(360px, 60vw);
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #0f1319;
  color: var(--ink);
  font-size: 14px;
}

.search-suggest {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  background: #141922;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 8px;
  box-shadow: 0 18px 32px -20px var(--shadow);
  display: none;
  z-index: 30;
}

.search-suggest.show {
  display: block;
}

.suggest-item {
  display: grid;
  grid-template-columns: 44px 1fr;
  gap: 10px;
  align-items: center;
  padding: 8px;
  border-radius: 12px;
  cursor: pointer;
}

.suggest-item:hover {
  background: rgba(199, 63, 42, 0.12);
}

.suggest-thumb {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background: #0f1319;
  display: grid;
  place-items: center;
  overflow: hidden;
}

.suggest-thumb img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.suggest-meta {
  display: grid;
  gap: 4px;
  font-size: 12px;
  color: var(--muted);
}

.suggest-meta strong {
  color: var(--ink);
  font-size: 13px;
}

.page-nav {
  display: flex;
  gap: 6px;
  flex-wrap: nowrap;
  overflow-x: auto;
  max-width: min(520px, 60vw);
  padding-bottom: 2px;
  scrollbar-width: none;
}

.page-nav::-webkit-scrollbar {
  display: none;
}

.page-link {
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(9, 11, 16, 0.6);
  color: var(--muted);
  font-size: 12px;
  text-decoration: none;
  cursor: pointer;
}

.page-link.is-draggable {
  cursor: grab;
}

.page-link.is-draggable:active {
  cursor: grabbing;
}

.page-link.is-dragging {
  opacity: 0.55;
}

.page-link.is-drop-target {
  border-color: rgba(164, 170, 180, 0.8);
  color: #f5ebe1;
  box-shadow: inset 0 0 0 2px rgba(164, 170, 180, 0.25);
}

.page-link:hover,
.page-link.active {
  color: #f5ebe1;
  border-color: rgba(199, 63, 42, 0.6);
}

.upload-card {
  padding: 26px;
  background: rgba(22, 26, 34, 0.85);
  border: 3px dotted rgba(180, 185, 195, 0.45);
  border-radius: 16px;
  display: grid;
  gap: 12px;
  place-items: center;
  text-align: center;
  margin-top: 32px;
  box-shadow: inset 0 0 0 8px rgba(255, 255, 255, 0.03);
}

.upload-label {
  font-weight: 700;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.upload-hint {
  font-size: 13px;
  color: var(--muted);
}

.upload-plus {
  width: 64px;
  height: 64px;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.06);
  color: rgba(255, 255, 255, 0.5);
  display: grid;
  place-items: center;
  font-size: 28px;
}

.upload-card input[type="file"] {
  width: min(320px, 80%);
  text-align: center;
}

input[type="file"] {
  padding: 10px;
  background: #0f1319;
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 14px;
  color: var(--ink);
}

main {
  margin-top: 36px;
}

.empty {
  padding: 48px;
  text-align: center;
  border-radius: 18px;
  border: 1px dashed var(--border);
  color: var(--muted);
  background: rgba(18, 21, 28, 0.6);
}

.gallery {
  display: grid;
  gap: 32px;
}

.image-section {
  background: linear-gradient(160deg, rgba(28, 33, 42, 0.96), rgba(16, 19, 25, 0.98));
  border-radius: 18px;
  border: 1px solid var(--border);
  box-shadow: 0 16px 28px -24px var(--shadow);
  padding: 16px;
  scroll-margin-top: var(--nav-offset);
}

.image-header {
  margin-bottom: 10px;
}

.image-title {
  font-weight: 700;
  font-size: 14px;
  color: var(--ink);
  background: rgba(15, 19, 25, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.08);
  padding: 6px 10px;
  border-radius: 999px;
}

.image-delete {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 28px;
  height: 28px;
  border-radius: 999px;
  border: 1px solid rgba(199, 63, 42, 0.45);
  background: rgba(9, 11, 16, 0.7);
  color: var(--muted);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
  z-index: 2;
}

.image-delete i {
  pointer-events: none;
}

.image-delete:hover {
  color: #f5ebe1;
  border-color: var(--accent);
}

.edit-toggle {
  position: relative;
  width: 128px;
  height: 40px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: linear-gradient(180deg, #11151c 0%, #0a0d12 100%);
  color: var(--muted);
  font-weight: 700;
  letter-spacing: 0.01em;
  cursor: pointer;
  display: grid;
  grid-template-columns: 1fr 1fr;
  align-items: center;
  padding: 0;
  text-transform: uppercase;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.08),
    inset 0 -2px 4px rgba(0, 0, 0, 0.6);
  overflow: hidden;
}

.edit-toggle::before {
  content: "";
  position: absolute;
  top: 5px;
  bottom: 3px;
  left: 5px;
  width: calc(50% - 8px);
  border-radius: 10px;
  background: linear-gradient(180deg, var(--accent) 0%, var(--accent-dark) 100%);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.25),
    0 8px 14px -10px var(--accent-dark);
  transition: left 0.2s ease;
  z-index: 0;
}

.edit-toggle span {
  position: relative;
  z-index: 1;
  font-size: 11px;
  text-align: center;
  justify-self: center;
  width: 100%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.edit-toggle.is-editing {
  color: #f5ebe1;
}

.edit-toggle.is-editing::before {
  left: calc(50% + 5px);
}

.edit-toggle.is-editing .toggle-edit {
  color: #f5ebe1;
}

.edit-toggle.is-editing .toggle-view {
  color: var(--muted);
}

.edit-toggle .toggle-view {
  color: #f5ebe1;
}

.image-frame {
  position: relative;
  width: auto;
  max-width: 100%;
  margin: 0 auto;
  aspect-ratio: 16 / 9;
  height: auto;
  overflow: hidden;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: #0a0c10;
  user-select: none;
}

.image-frame img {
  user-select: none;
  -webkit-user-drag: none;
}

.image-frame.is-editing {
  outline: 2px dashed var(--accent);
  outline-offset: 4px;
  cursor: crosshair;
}

.image-frame.is-link-drop {
  outline: 2px dashed rgba(164, 170, 180, 0.8);
  outline-offset: 6px;
}

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

.overlay-node {
  position: absolute;
  width: 0;
  height: 0;
}

.overlay-node.highlight .overlay-btn {
  box-shadow:
    0 0 0 3px rgba(199, 63, 42, 0.8),
    0 0 24px rgba(199, 63, 42, 0.6);
}

.overlay-layer {
  position: absolute;
  inset: 0;
}

.overlay-btn {
  position: absolute;
  width: 108px;
  height: 108px;
  border-radius: 50%;
  border: 2px solid #a4aab4;
  background: rgba(15, 19, 25, 0.55);
  color: #0a0c10;
  font-weight: 800;
  cursor: pointer;
  top: 0;
  left: 0;
  transform: translate(-50%, -50%);
  display: grid;
  place-items: center;
  box-shadow:
    0 0 6px rgba(196, 201, 210, 0.28),
    0 8px 18px -12px var(--shadow);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  background-size: cover;
  background-position: center;
  overflow: hidden;
}

.overlay-btn:hover {
  transform: translate(-50%, -50%) scale(1.18);
  box-shadow:
    0 0 8px rgba(196, 201, 210, 0.35),
    0 12px 20px -10px var(--shadow);
}

.overlay-btn::after {
  content: attr(data-tooltip);
  position: absolute;
  left: 50%;
  bottom: calc(100% + 12px);
  transform: translateX(-50%);
  background: #0d0f14;
  color: #f1ebe2;
  padding: 8px 12px;
  border-radius: 10px;
  font-size: 12px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.overlay-btn:hover::after {
  opacity: 1;
}

.overlay-btn.is-editing {
  background: rgba(199, 63, 42, 0.35);
}

.overlay-btn.has-item {
  color: #f9f1e6;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.7);
}

.overlay-btn.is-link {
  background: rgba(18, 22, 29, 0.78);
  color: #f5f3ee;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.4px;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.65);
}

.overlay-btn.is-link.is-editing {
  background: rgba(18, 22, 29, 0.78);
}

.thumb-grid {
  position: absolute;
  inset: 5px;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  grid-template-rows: repeat(2, 1fr);
  gap: 4px;
  z-index: 1;
  pointer-events: none;
}

.thumb-grid.count-2 {
  grid-template-columns: repeat(2, 1fr);
  grid-template-rows: 1fr;
  inset: 6px 4px;
  gap: 3px;
}

.thumb-cell {
  background: transparent;
  background-size: contain;
  background-position: center;
  background-repeat: no-repeat;
  border-radius: 4px;
}

.thumb-single {
  position: absolute;
  inset: 10px;
  display: grid;
  place-items: center;
  z-index: 1;
  pointer-events: none;
}

.thumb-single img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.overlay-btn.has-item {
  background: rgba(0, 0, 0, 0.45);
}

.overlay-card {
  position: absolute;
  top: 12px;
  left: 12px;
  width: 320px;
  background: #141922;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px;
  box-shadow: 0 18px 32px -20px var(--shadow);
  opacity: 0;
  pointer-events: none;
  transform: translateY(-8px) scale(0.98);
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 5;
}

.overlay-card .overlay-close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 26px;
  height: 26px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(9, 11, 16, 0.7);
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  line-height: 1;
  display: grid;
  place-items: center;
}

.overlay-card .overlay-close i {
  pointer-events: none;
}

.overlay-card .overlay-close:hover {
  color: #f5ebe1;
  border-color: rgba(199, 63, 42, 0.6);
}

.overlay-node.expanded {
  z-index: 6;
}

.overlay-node.expanded .overlay-card {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0) scale(1);
}

.overlay-card h4 {
  margin: 0 0 8px;
  font-size: 14px;
}

.overlay-card-list {
  display: grid;
  gap: 8px;
  max-height: 220px;
  overflow: auto;
}

.overlay-card-item {
  display: grid;
  grid-template-columns: 34px 1fr auto auto;
  gap: 10px;
  align-items: center;
  background: rgba(20, 24, 31, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 10px;
  padding: 6px 8px;
}

.overlay-card-item img {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  object-fit: cover;
}

.overlay-card-item span {
  font-size: 12px;
  color: var(--ink);
}

.max-input {
  width: 44px;
  padding: 4px 6px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(9, 11, 16, 0.6);
  color: var(--ink);
  font-size: 12px;
  text-align: center;
}

.max-input[readonly] {
  cursor: pointer;
  color: var(--muted);
}

.overlay-card-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.overlay-card-actions button,
.overlay-card-remove {
  border: none;
  border-radius: 999px;
  padding: 6px 10px;
  background: rgba(199, 63, 42, 0.2);
  color: var(--ink);
  font-size: 11px;
  cursor: pointer;
}

.overlay-card-remove {
  background: rgba(255, 255, 255, 0.08);
  color: var(--muted);
}

.conveyor-tools {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 10px 0 0;
}

.conveyor-icon {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(9, 11, 16, 0.7);
  display: grid;
  place-items: center;
  overflow: hidden;
}

.conveyor-icon img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.conveyor-select {
  flex: 1;
  min-width: 120px;
  padding: 4px 10px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(9, 11, 16, 0.7);
  color: var(--ink);
  font-size: 12px;
}

.conveyor-copy {
  width: 34px;
  height: 34px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(9, 11, 16, 0.7);
  color: var(--ink);
  cursor: pointer;
  display: grid;
  place-items: center;
}

.conveyor-copy i {
  font-size: 14px;
}

.conveyor-copy.copied {
  border-color: rgba(46, 204, 113, 0.6);
  color: #2ecc71;
}

.instructions {
  font-size: 13px;
  color: var(--muted);
  margin-top: 10px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: #0d0f14;
  color: #f5efe7;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.modal {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 10;
}

.modal.show {
  display: flex;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(5, 6, 8, 0.7);
}

.modal-card {
  position: relative;
  width: min(560px, 92vw);
  background: #151a21;
  border-radius: 18px;
  border: 1px solid var(--border);
  box-shadow: 0 24px 40px -20px var(--shadow);
  padding: 18px;
  display: grid;
  gap: 14px;
}

.confirm-card {
  width: min(420px, 92vw);
}

.confirm-message {
  color: var(--muted);
  margin: 0;
}

.confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.confirm-btn {
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(9, 11, 16, 0.7);
  color: var(--ink);
  padding: 8px 14px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 13px;
}

.confirm-btn.primary {
  border-color: rgba(199, 63, 42, 0.6);
  color: #f5ebe1;
  background: rgba(199, 63, 42, 0.2);
}

.confirm-btn.danger {
  border-color: rgba(199, 63, 42, 0.6);
  color: #f5ebe1;
  background: rgba(199, 63, 42, 0.2);
}

.auth-card {
  width: min(360px, 92vw);
}

.auth-message {
  color: var(--muted);
  font-size: 13px;
  margin: 0;
}

.sign-preview {
  display: none;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  position: relative;
}

.sign-preview.show {
  display: block;
}

.sign-canvas {
  width: 100%;
  height: auto;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #0f1319;
}

.sign-copy {
  position: absolute;
  top: 14px;
  right: 14px;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(9, 11, 16, 0.7);
  color: var(--ink);
  font-size: 11px;
  cursor: pointer;
  opacity: 0;
  transform: translateY(-4px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
}

.sign-copy i {
  font-size: 14px;
}

.sign-preview:hover .sign-copy {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.sign-copy.copied {
  border-color: rgba(46, 204, 113, 0.6);
  color: #2ecc71;
}

.sign-status:empty {
  display: none;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-close {
  border: none;
  background: transparent;
  color: var(--muted);
  font-weight: 600;
  cursor: pointer;
}

.modal-search {
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  font-size: 14px;
  background: #0f1319;
  color: var(--ink);
}

.modal-results {
  max-height: 320px;
  overflow: auto;
  display: grid;
  gap: 8px;
}

.item-result {
  display: grid;
  grid-template-columns: 48px 1fr;
  gap: 12px;
  align-items: center;
  border: 1px solid transparent;
  padding: 8px;
  border-radius: 12px;
  background: rgba(20, 24, 31, 0.85);
  cursor: pointer;
}

.item-result:hover {
  border-color: var(--accent);
  background: rgba(199, 63, 42, 0.12);
}

.item-result.is-selected {
  border-color: rgba(199, 63, 42, 0.8);
  background: rgba(199, 63, 42, 0.18);
}

.item-thumb {
  width: 48px;
  height: 48px;
  border-radius: 10px;
  background: #10141a;
  display: grid;
  place-items: center;
  overflow: hidden;
}

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

.item-meta {
  display: grid;
  gap: 4px;
}

.item-meta span {
  color: var(--muted);
  font-size: 12px;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(-6px);
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(18px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 900px) {
  .topbar {
    flex-direction: column;
    align-items: stretch;
  }

  .topbar-search {
    min-width: 100%;
  }
}

@media (max-width: 600px) {
  .page {
    width: min(94vw, 100%);
  }

  .upload-card {
    padding: 14px;
  }

  .overlay-btn {
    width: 88px;
    height: 88px;
  }
}
