/* ------------------------------------------------------------------
   GridTone – global styles (dark, minimal, “app-like”)
   ------------------------------------------------------------------ */

/* ---------- Base / Reset ---------- */
*,
*::before,
*::after { box-sizing: border-box; }

:root {
  --bg: #0f0f10;
  --bg-elev: #131315;
  --text: #e9e9ea;
  --muted: #a5a6aa;
  --border: rgba(255,255,255,0.08);
  --border-soft: rgba(255,255,255,0.06);
  --accent: #5f8cff;
  --accent-2: #8b5cf6;
  --danger: #ef4444;
  --card-radius: 14px;
  --gap: 12px;
  color-scheme: dark;
}

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a { color: var(--text); text-decoration: underline; text-underline-offset: 2px; }
a:hover { color: #fff; }
img { display: block; max-width: 100%; height: auto; }

/* ---------- Header / Topbar ---------- */
.topbar {
  padding: 12px 16px;
  display: grid;
  gap: 8px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, #141416, #0f0f10);
}

.branding { display: flex; align-items: baseline; gap: 8px; }
.branding .logo { font-weight: 700; text-decoration: none; color: #fff; }
.branding .tagline { opacity: .7; font-size: .9rem; }

.controls { display: grid; gap: 8px; }
.controls .row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.check { display: inline-flex; align-items: center; gap: 6px; user-select: none; }
.range { display: inline-flex; align-items: center; gap: 6px; }

/* ---------- Buttons & Inputs ---------- */
.btn {
  background: #2b2f36;
  color: #e9eef5;
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 10px;
  padding: 8px 12px;
  font: inherit;
  cursor: pointer;
  transition: background .16s ease, transform .16s ease, border-color .16s ease;
}
.btn:hover { background: #343a43; }
.btn.primary { background: #2d7aff; color: #fff; border-color: #2d7aff; }
.btn.primary:hover { filter: brightness(1.05); }

/* ---------- Page / Footer ---------- */
#export-root { margin: 12px auto; max-width: 980px; }
.footer { padding: 16px; opacity: .7; text-align: center; }

/* ---------- Grid (3-across) ---------- */
.grid-wrap { width: 100%; display: grid; place-items: center; }

.grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  width: 100%;
  max-width: 980px;
  padding: 8px 12px 24px;
  touch-action: pan-y; /* allow vertical scroll when not dragging */
}

@media (max-width: 760px) {
  .grid { gap: 12px; padding: 8px 10px 20px; }
}

/* Empty state (dropzone) */
.grid-empty {
  width: 100%;
  max-width: 980px;
  height: 380px;
  border: 1px dashed rgba(255,255,255,.25);
  border-radius: 16px;
  display: grid;
  place-items: center;
  gap: 10px;
  color: #cfd3d7;
  background: rgba(255,255,255,.03);
}

/* ---------- Tiles ---------- */
.tile {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: 18px;
  overflow: hidden;
  background: #15161a;
  box-shadow:
    0 1px 2px rgba(0,0,0,.5),
    inset 0 0 0 1px rgba(255,255,255,.06);
  transition: box-shadow .15s ease, transform .15s ease;
}

.tile-imgWrap {
  position: relative;
  width: 100%;
  height: 100%;
  cursor: grab;
}
.tile, .tile * { user-select: none; }      /* prevent accidental selection while dragging */
.tile-img { width: 100%; height: 100%; object-fit: cover; display: block; -webkit-user-drag: none; }

/* Close button */
.tile-close {
  position: absolute;
  top: 8px; right: 8px;
  z-index: 10;
  width: 24px; height: 24px;
  border-radius: 9999px;
  border: 0;
  background: rgba(0,0,0,.55);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
  line-height: 1;
}
.tile-close:hover { background: rgba(0,0,0,.75); }

/* Overlay layers (rendered by Grid.jsx) */
.tile .overlay {
  position: absolute; inset: 0;
  pointer-events: none;
  z-index: 3; /* above image, below close button */
  border-radius: 18px;
}
.tile .overlay__block {
  position: absolute; left: 0; right: 0; bottom: 0;
  border-radius: 18px;
  overflow: hidden;
}

/* ---------- Modal (ImageViewerModal) ---------- */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.55);
  backdrop-filter: blur(2px);
  display: grid; place-items: center;
  z-index: 1000;
}

.modal {
  width: min(92vw, 900px);
  max-height: 88vh;
  overflow: hidden;
  background: linear-gradient(180deg, #1b1b1d, #131315);
  border: 1px solid var(--border);
  border-radius: var(--card-radius);
  box-shadow: 0 20px 60px rgba(0,0,0,.45);
  display: grid; grid-template-rows: auto auto 1fr;
}

.modal-header {
  display:flex; align-items:center; justify-content:space-between;
  padding: 12px 14px; border-bottom: 1px solid var(--border);
}
.modal-close {
  width:28px; height:28px; border-radius:999px; cursor:pointer;
  background:rgba(0,0,0,.5); color:#fff; border:1px solid rgba(255,255,255,.2);
}

.modal-controls {
  padding: 10px 14px;
  display:flex; gap:10px; align-items:center; flex-wrap: wrap;
  border-bottom: 1px solid var(--border);
}

.modal-body { padding: 12px; overflow:auto; background: var(--bg); }
.modal-body--viewer { background: #0a0a0b; }

.viewer-stage {
  position: relative;
  display: grid; place-items: center;
  width: 100%; height: 70vh;
  background: radial-gradient(1200px 600px at 50% 40%, rgba(255,255,255,0.04), transparent 60%);
}
.viewer-img {
  max-width: min(92vw, 860px);
  max-height: 66vh;
  width: auto; height: auto;
  border-radius: 12px;
  object-fit: contain;
  box-shadow: 0 10px 40px rgba(0,0,0,.35);
  border: 1px solid rgba(255,255,255,.07);
  background: #0d0d0f;
}

/* Viewer overlays */
.viewer-overlay {
  position: absolute; left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  width: min(92vw, 860px);
  height: min(66vh, 66vh);
  border-radius: 12px;
  z-index: 3;
}
.viewer-overlay--half { clip-path: inset(50% 0 0 0 round 12px); }

/* Dot bar in viewer */
.viewer-dotbar {
  position: absolute; left: 50%; bottom: 24px; transform: translateX(-50%);
  display: inline-flex; gap: 10px; align-items: center;
  padding: 8px 12px; border-radius: 999px;
  background: rgba(0,0,0,.4); backdrop-filter: blur(2px);
  border: 1px solid rgba(255,255,255,.12);
}
.viewer-dot { width: 20px; height: 20px; border-radius: 999px; border: 1px solid rgba(0,0,0,.25); }
