@font-face {
  font-family: "ESBuild";
  src:
    url("../fonts/ESBuild-Regular.woff2") format("woff2"),
    url("../fonts/ESBuild-Regular.woff") format("woff");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

:root {
  --bg: #ffffff;
  --bg-2: #f6f5f2;
  --panel: #ffffff;
  --line: rgba(28, 25, 20, 0.12);
  --text: #1c1914;
  --muted: #6b6458;
  --accent: #a1544c;
  --accent-2: #b56a62;
  --danger: #b43d3d;
  --shadow: 0 12px 32px rgba(28, 25, 20, 0.1);
  font-family: "ESBuild", sans-serif;
  font-weight: 400;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "ESBuild", sans-serif;
  font-weight: 400;
}

body {
  min-height: 100vh;
}

.hidden { display: none !important; }

.app {
  display: grid;
  grid-template-rows: auto auto 1fr;
  min-height: 100vh;
  height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.4rem;
  border-bottom: 1px solid var(--line);
  background: #fff;
  position: sticky;
  top: 0;
  z-index: 5;
}

.brand h1 {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 400;
  letter-spacing: 0.02em;
}

.actions {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  border-radius: 999px;
  padding: 0.55rem 1rem;
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
}

.btn:hover { border-color: rgba(161, 84, 76, 0.55); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 400;
}
.btn-primary:hover { background: var(--accent-2); border-color: var(--accent-2); color: #fff; }
.btn-ghost { background: transparent; }
.btn-danger {
  color: var(--danger);
  border-color: rgba(180, 61, 61, 0.35);
}

.tabbar {
  display: flex;
  gap: 1.35rem;
  padding: 0 1.4rem;
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.tab {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.95rem;
  padding: 0.7rem 0 0.75rem;
  margin-bottom: -1px;
  border-bottom: 2px solid transparent;
  cursor: pointer;
}

.tab:hover { color: var(--text); }
.tab[aria-selected="true"] {
  color: var(--text);
  border-bottom-color: var(--accent);
}

.tab-panel {
  min-height: 0;
  height: 100%;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  min-height: 0;
  height: 100%;
}

.stage {
  position: relative;
  min-height: 0;
  height: 100%;
  padding: 1.5rem;
  display: grid;
  place-items: center;
}

.stage.is-loading .dropzone,
.stage.is-loading .canvas-frame {
  visibility: hidden;
  pointer-events: none;
}

.dropzone {
  width: min(720px, 100%);
  min-height: 360px;
  border: 1px dashed rgba(161, 84, 76, 0.5);
  border-radius: 18px;
  background: var(--bg-2);
  display: grid;
  place-items: center;
  text-align: center;
  padding: 2rem;
  cursor: pointer;
}

.dropzone.is-over {
  border-color: var(--accent);
  background: rgba(161, 84, 76, 0.12);
}

.dropzone h2 {
  margin: 0 0 0.4rem;
  font-weight: 400;
}

.dropzone p {
  margin: 0;
  color: var(--muted);
}

.canvas-frame {
  position: relative;
  display: block;
  line-height: 0;
}

.canvas-frame img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: 6px;
  box-shadow: var(--shadow);
  cursor: crosshair;
}

.overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  touch-action: none;
}

.crop-overlay {
  position: absolute;
  inset: 0;
  overflow: hidden;
  cursor: crosshair;
  touch-action: none;
}

.crop-window {
  position: absolute;
  box-sizing: border-box;
  box-shadow: 0 0 0 200vmax rgba(255, 255, 255, 0.58);
  pointer-events: none;
}

.crop-canvas {
  overflow: hidden;
  border-radius: 6px;
}

.crop-canvas img {
  cursor: crosshair;
}

.crop-meta {
  color: var(--text);
  font-size: 0.85rem;
  line-height: 1.45;
  margin: 0 0 1rem;
}

.crop-preview {
  margin-top: 0.85rem;
}

.crop-preview-label {
  margin: 0 0 0.5rem;
  color: var(--muted);
  font-size: 0.82rem;
}

.crop-preview-frame {
  --crop-w: 3;
  --crop-h: 4;
  position: relative;
  overflow: hidden;
  width: min(100%, calc(min(52vh, 26rem) * var(--crop-w) / var(--crop-h)));
  aspect-ratio: var(--crop-w) / var(--crop-h);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.crop-preview-frame img {
  position: absolute;
  display: block;
  max-width: none;
  max-height: none;
  pointer-events: none;
  user-select: none;
}

.pin {
  position: absolute;
  width: 24px;
  height: 24px;
  border: 0;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.28);
  transform: translate(-50%, -50%);
  pointer-events: auto;
  cursor: grab;
  color: #111;
  font-size: 16px;
  font-weight: 400;
  line-height: 1;
  display: grid;
  place-items: center;
  user-select: none;
  touch-action: none;
  z-index: 2;
  padding: 0;
  overflow: visible;
}

.pin::before {
  content: "+";
}

.pin:hover, .pin.is-selected {
  z-index: 3;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35), 0 0 0 3px rgba(0, 0, 0, 0.08);
}

.pin.is-dragging { cursor: grabbing; }

.pin-label {
  position: absolute;
  z-index: 3;
  transform: translate(-50%, -50%);
  max-width: min(280px, 90%);
  padding: 0.55rem 1.15rem;
  background: #fff;
  color: #111;
  border-radius: 999px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.16);
  pointer-events: none;
  font-size: 0.95rem;
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: 0;
  visibility: hidden;
}

.pin:hover + .pin-label,
.pin:focus + .pin-label,
.pin.is-dragging + .pin-label {
  opacity: 1;
  visibility: visible;
}

.pin:hover::before,
.pin:focus::before,
.pin.is-dragging::before {
  opacity: 0;
}

.tooltip-pill {
  position: absolute;
  z-index: 6;
  transform: translate(-50%, -50%);
  max-width: min(280px, 90%);
  padding: 0.55rem 1.15rem;
  background: #fff;
  color: #111;
  border-radius: 999px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.16);
  pointer-events: auto;
  cursor: grab;
  font-size: 0.95rem;
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar textarea,
.sidebar input {
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  border-radius: 8px;
  padding: 0.55rem 0.65rem;
  font: inherit;
  resize: vertical;
}

.editor-actions {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.65rem;
}

.sidebar {
  border-left: 1px solid var(--line);
  background: var(--bg-2);
  padding: 1.1rem 1rem 2rem;
  overflow: auto;
}

.sidebar h2 {
  margin: 0 0 0.35rem;
  font-size: 0.95rem;
  font-weight: 400;
}

.hint:empty { display: none; }

.tip-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.55rem;
}

.tip-item {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.7rem;
  background: var(--panel);
  cursor: pointer;
}

.tip-item.is-selected { border-color: var(--accent); }
.tip-item.is-editing { cursor: default; }

.tip-item header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
  margin-bottom: 0.35rem;
}

.num {
  width: 1.25rem;
  height: 1.25rem;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 0.7rem;
  font-weight: 400;
}

.tip-item p {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
  white-space: pre-wrap;
  word-break: break-word;
}

.tile-editor textarea {
  min-height: 72px;
  margin-top: 0.2rem;
}

.icon-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  padding: 0.15rem;
  font: inherit;
}

.icon-btn:hover { color: var(--danger); }

.status {
  position: fixed;
  left: 50%;
  bottom: 1.2rem;
  transform: translateX(-50%);
  background: #fff;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: var(--shadow);
  padding: 0.5rem 0.9rem;
  font-size: 0.85rem;
  z-index: 10;
}

.loader {
  position: absolute;
  inset: 0;
  z-index: 8;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 0.75rem;
  background: rgba(255, 255, 255, 0.92);
  color: var(--text);
  pointer-events: none;
}

.loader p {
  margin: 0;
  font-size: 0.9rem;
  color: var(--muted);
}

.loader-spinner {
  width: 2rem;
  height: 2rem;
  border: 3px solid rgba(161, 84, 76, 0.22);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.bulk-stage {
  position: relative;
  min-height: 0;
  height: 100%;
  padding: 1.5rem;
  overflow: auto;
  display: grid;
  place-items: center;
}

.bulk-stage.has-files {
  place-items: stretch;
  align-content: start;
}

.bulk-grid {
  list-style: none;
  margin: 0;
  padding: 0;
  width: 100%;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1rem;
  align-content: start;
}

.bulk-card {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  overflow: hidden;
  display: grid;
  grid-template-rows: 200px auto;
}

.bulk-card img {
  width: 100%;
  height: 200px;
  object-fit: cover;
  background: var(--bg-2);
  display: block;
}

.bulk-card-meta {
  padding: 0.65rem 0.75rem 0.75rem;
  min-width: 0;
}

.bulk-card-meta strong {
  display: block;
  font-weight: 400;
  font-size: 0.85rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bulk-card-meta p {
  margin: 0.15rem 0 0;
  color: var(--muted);
  font-size: 0.75rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bulk-file-remove {
  appearance: none;
  border: 0;
  position: absolute;
  top: 0.4rem;
  right: 0.4rem;
  z-index: 1;
  background: rgba(255, 255, 255, 0.9);
  color: var(--muted);
  width: 1.7rem;
  height: 1.7rem;
  padding: 0;
  display: grid;
  place-items: center;
  border-radius: 6px;
  cursor: pointer;
}

.bulk-file-remove:hover {
  color: var(--danger);
  background: #fff;
}

.bulk-import {
  width: min(720px, 100%);
  display: grid;
  gap: 1rem;
}

.bulk-stage.has-files .bulk-import {
  width: 100%;
  max-width: 720px;
  justify-self: start;
  order: 2;
}

.bulk-stage.has-files .bulk-grid {
  order: 1;
}

.bulk-stage.is-loading .bulk-import,
.bulk-stage.is-loading .bulk-grid {
  visibility: hidden;
  pointer-events: none;
}

.bulk-actions {
  display: grid;
  gap: 0.5rem;
}

.bulk-actions .btn {
  width: 100%;
  justify-content: center;
  text-align: center;
}

.bulk-url {
  width: 100%;
  display: grid;
  gap: 0.45rem;
}

.bulk-url label {
  font-size: 0.82rem;
}

.bulk-url-fields {
  display: flex;
  gap: 0.5rem;
}

.bulk-url-fields input {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  border-radius: 8px;
  padding: 0.55rem 0.65rem;
  font: inherit;
}

.bulk-url-fields .btn {
  flex: 0 0 auto;
  justify-content: center;
  text-align: center;
}


.bulk-author {
  margin-top: 1.15rem;
  display: grid;
  gap: 0.45rem;
}

.bulk-author label {
  font-size: 0.82rem;
}

.bulk-author .hint {
  margin: 0;
}

.bulk-author .btn {
  width: 100%;
  justify-content: center;
  text-align: center;
}


@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { border-left: 0; border-top: 1px solid var(--line); }
  .stage, .bulk-stage, .crop-stage { min-height: 50vh; }
}
