/* ── Tokens ──────────────────────────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600;700&display=swap');

@font-face {
  font-family: 'Monocraft';
  src: url('https://cdn.jsdelivr.net/gh/IdreesInc/Monocraft@main/dist/Monocraft-ttf/Monocraft.ttf') format('truetype');
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}

:root {
  --bg:          #0f1117;
  --surface:     #181c27;
  --surface2:    #1e2333;
  --border:      rgba(255,255,255,.07);
  --border2:     rgba(255,255,255,.12);
  --text:        #e8eaf0;
  --muted:       rgba(232,234,240,.45);
  --accent:      #4ade80;
  --accent-dim:  rgba(74,222,128,.15);
  --accent2:     #60a5fa;
  --accent3:     #f97316;
  --radius:      14px;
  --radius-sm:   9px;
  --shadow:      0 24px 60px rgba(0,0,0,.55);
  --shadow-sm:   0 4px 14px rgba(0,0,0,.35);
  --font-ui:     'DM Sans', system-ui, sans-serif;
  --font-mono:   'Monocraft', monospace;
}

/* ── Reset ───────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }

body {
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  /* Subtle grid texture */
  background-image:
    linear-gradient(rgba(74,222,128,.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(74,222,128,.03) 1px, transparent 1px);
  background-size: 32px 32px;
}

/* ── Topbar ───────────────────────────────────────────────────────────────── */
.topbar {
  max-width: 1280px;
  margin: 0 auto;
  padding: 12px 24px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-mark {
  width: 44px; height: 44px;
  background: var(--surface2);
  border: 1px solid var(--border2);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 0 4px rgba(74,222,128,.06);
}

.brand-name {
  display: block;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--accent);
  font-family: var(--font-mono);
}
.brand-tag {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-top: 1px;
}

.topbar-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}

.kofi-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 16px;
  background: #ff5e5b;
  color: #fff;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
  transition: opacity .15s, transform .08s;
  white-space: nowrap;
  box-shadow: 0 4px 14px rgba(255,94,91,.35);
}
.kofi-btn:hover { opacity: .88; }
.kofi-btn:active { transform: translateY(1px); }

.disclaimer {
  max-width: 440px;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.5;
  background: rgba(255,255,255,.03);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
}
.disclaimer strong { color: var(--text); }

/* ── Layout ───────────────────────────────────────────────────────────────── */
.layout {
  max-width: 1280px;
  margin: 0 auto;
  padding: 16px 24px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}

@media (min-width: 1000px) {
  .layout {
    grid-template-columns: 420px 1fr;
    align-items: start;
    /* Fill remaining viewport height after topbar */
    height: calc(100vh - 110px);
  }

  #card-crop,
  #card-output {
    height: 100%;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,.1) transparent;
  }
}

/* ── Cards ────────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}

.card-title {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.step {
  width: 22px; height: 22px;
  background: var(--accent-dim);
  color: var(--accent);
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  font-family: var(--font-mono);
  flex-shrink: 0;
}

/* ── Utilities ────────────────────────────────────────────────────────────── */
.row { display: flex; align-items: center; }
.gap-8 { gap: 8px; }
.flex-wrap { flex-wrap: wrap; }
.spacer { flex: 1; }

/* ── File button ─────────────────────────────────────────────────────────── */
.file-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 14px;
  background: var(--surface2);
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.file-btn:hover { border-color: var(--accent); background: rgba(74,222,128,.07); }
.file-btn input { display: none; }
.file-btn svg { color: var(--accent); flex-shrink: 0; }

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .12s, transform .08s, background .12s, border-color .12s;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .35; cursor: not-allowed; pointer-events: none; }

.btn.primary {
  background: var(--accent);
  color: #0a1a0e;
  box-shadow: 0 0 20px rgba(74,222,128,.25);
}
.btn.primary:hover { opacity: .9; }

.btn.secondary {
  background: var(--surface2);
  color: var(--text);
  border-color: var(--border2);
}
.btn.secondary:hover { border-color: var(--accent); color: var(--accent); }

.btn.icon { padding: 9px 13px; }
.btn.wide  { width: 100%; margin-top: 8px; }

/* ── Crop area ───────────────────────────────────────────────────────────── */
.crop-area {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  max-height: 280px;
  margin: 10px 0;
  border-radius: var(--radius);
  border: 1px solid var(--border2);
  background: var(--surface2);
  overflow: hidden;
}

.crop-hint {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 14px;
  pointer-events: none;
}

#sourceImg {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  opacity: 0;
}

/* ── Controls ────────────────────────────────────────────────────────────── */
.controls {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.field label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

select {
  appearance: none;
  background: var(--surface2) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23666' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E") no-repeat right 12px center;
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 13px;
  padding: 9px 34px 9px 12px;
  outline: none;
  transition: border-color .15s;
}
select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(74,222,128,.12); }
select option { background: var(--surface2); }

.toggles {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: rgba(232,234,240,.75);
  cursor: pointer;
  user-select: none;
}
.toggle input[type="checkbox"] {
  width: 16px; height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
}

/* ── Status bar ──────────────────────────────────────────────────────────── */
.status-bar {
  margin-top: 12px;
  padding: 10px 14px;
  background: rgba(0,0,0,.2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 11px;
  color: var(--muted);
  font-family: var(--font-mono);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.progress-wrap {
  height: 3px;
  background: rgba(255,255,255,.07);
  border-radius: 99px;
  overflow: hidden;
  transition: opacity .2s;
}
.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  border-radius: 99px;
  transition: width .1s linear;
}

/* ── Preview / zoom wrap ─────────────────────────────────────────────────── */
.preview-area {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.zoom-wrap {
  width: 100%;
  height: 340px;
  overflow: hidden;
  border-radius: var(--radius);
  border: 1px solid var(--border2);
  background: #111;
  cursor: grab;
  position: relative;
}
.zoom-wrap:active { cursor: grabbing; }

#outCanvas {
  display: block;
  image-rendering: pixelated;
  transform-origin: 0 0;
  /* canvas is positioned absolutely so transform scale doesn't push layout */
  position: absolute;
  top: 0;
  left: 0;
}

.counts-meta {
  font-size: 10px;
  color: var(--muted);
  font-family: var(--font-mono);
}

/* ── Divider ─────────────────────────────────────────────────────────────── */
.divider {
  height: 1px;
  background: var(--border);
  margin: 16px 0;
}

/* ── Counts table ────────────────────────────────────────────────────────── */
.counts-section { display: flex; flex-direction: column; gap: 10px; }

.counts-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.counts-table {
  max-height: 380px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: rgba(0,0,0,.15);
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,.1) transparent;
}

.count-row {
  display: grid;
  grid-template-columns: 36px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  transition: background .1s;
}
.count-row:last-child { border-bottom: none; }
.count-row:hover { background: rgba(255,255,255,.03); }

.count-thumb {
  width: 32px; height: 32px;
  border-radius: 6px;
  border: 1px solid rgba(255,255,255,.08);
  image-rendering: pixelated;
  background: var(--surface2);
}

.count-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.count-name {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.count-sub {
  font-size: 9px;
  color: var(--muted);
  font-family: var(--font-mono);
}

.count-num {
  font-size: 10px;
  font-weight: 700;
  color: var(--accent);
  font-family: var(--font-mono);
  text-align: right;
}

.empty {
  padding: 16px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

/* ── Multi-map section ───────────────────────────────────────────────────── */
.multimap-wrap {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 24px 48px;
}

.multimap-card {
  border-top: 2px solid var(--accent);
}

.multimap-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.multimap-desc {
  font-size: 13px;
  color: var(--muted);
  margin-top: 4px;
  max-width: 500px;
  line-height: 1.5;
}

.kofi-nudge {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
  background: rgba(255,94,91,.08);
  border: 1px solid rgba(255,94,91,.2);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  white-space: nowrap;
  flex-wrap: wrap;
}
.kofi-nudge a {
  color: #ff5e5b;
  font-weight: 700;
  text-decoration: none;
}
.kofi-nudge a:hover { text-decoration: underline; }

.multimap-controls {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.grid-status-bar {
  padding: 10px 14px;
  background: rgba(0,0,0,.2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 12px;
  color: var(--muted);
  font-family: var(--font-mono);
  margin-bottom: 16px;
}

.grid-preview {
  display: grid;
  gap: 8px;
}

.grid-seg {
  position: relative;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border2);
  aspect-ratio: 1;
  background: #111;
}

.grid-seg canvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
}

.grid-seg-label {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(0,0,0,.65);
  color: var(--accent);
  font-size: 10px;
  font-family: var(--font-mono);
  font-weight: 700;
  text-align: center;
  padding: 3px 0;
  letter-spacing: 0.05em;
}
.cropper-view-box,
.cropper-face { border-radius: 0; }
.cropper-line  { background-color: var(--accent) !important; }
.cropper-point { background-color: var(--accent) !important; width: 8px !important; height: 8px !important; border-radius: 2px !important; }
.cropper-modal { background: rgba(0,0,0,.6); }

/* ── SEO content (visible to crawlers, hidden visually) ─────────────────── */
.seo-content {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

/* ── Schematic export button ─────────────────────────────────────────────── */
.schematic-btn {
  border-color: rgba(74,222,128,.3) !important;
  color: var(--accent) !important;
}
.schematic-btn:hover {
  background: rgba(74,222,128,.08) !important;
  border-color: var(--accent) !important;
}

/* ── Topbar actions ──────────────────────────────────────────────────────── */
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: flex-end;
}

.feedback-trigger {
  font-size: 12px;
  padding: 7px 12px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.disclaimer-link {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}
.disclaimer-link:hover { text-decoration: underline; }

/* ── Feedback modal ──────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.7);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
  padding: 20px;
}
.modal-overlay.active {
  opacity: 1;
  pointer-events: all;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  padding: 24px;
  width: 100%;
  max-width: 460px;
  box-shadow: var(--shadow);
  transform: translateY(8px);
  transition: transform .2s;
}
.modal-overlay.active .modal { transform: translateY(0); }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}
.modal-title {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.modal-close {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  display: flex;
  align-items: center;
}
.modal-close:hover { color: var(--text); background: rgba(255,255,255,.05); }

.modal .field {
  margin-bottom: 14px;
}
.modal .field label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 6px;
}
.optional {
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  font-size: 11px;
}

textarea {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 13px;
  padding: 10px 12px;
  resize: vertical;
  outline: none;
  transition: border-color .15s;
}
textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(74,222,128,.12); }

input[type="email"] {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 13px;
  padding: 9px 12px;
  outline: none;
  transition: border-color .15s;
}
input[type="email"]:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(74,222,128,.12); }

/* Star rating */
.star-row {
  display: flex;
  gap: 4px;
}
.star {
  background: none;
  border: none;
  font-size: 28px;
  color: var(--border2);
  cursor: pointer;
  padding: 0 2px;
  transition: color .1s, transform .1s;
  line-height: 1;
}
.star.active, .star.hover { color: #fbbf24; }
.star:hover { transform: scale(1.15); }

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 16px;
  flex-wrap: wrap;
}
.privacy-note {
  font-size: 11px;
  color: var(--muted);
  flex: 1;
}
.privacy-note a { color: var(--accent); }

/* Success state */
.feedback-success {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 32px 0;
  text-align: center;
}
.success-icon {
  width: 48px; height: 48px;
  background: var(--accent-dim);
  color: var(--accent);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  font-weight: 700;
}
.feedback-success h4 { font-size: 16px; font-weight: 700; }
.feedback-success p  { font-size: 13px; color: var(--muted); }

/* ── Footer ──────────────────────────────────────────────────────────────── */
.site-footer {
  max-width: 1280px;
  margin: 0 auto;
  padding: 16px 24px 32px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--muted);
}
.site-footer a { color: var(--muted); text-decoration: none; }
.site-footer a:hover { color: var(--accent); }
.footer-sep { opacity: .3; }
.footer-feedback-btn {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
  padding: 0;
  font-family: var(--font-ui);
}
.footer-feedback-btn:hover { color: var(--accent); }

/* ── Privacy page ────────────────────────────────────────────────────────── */
.privacy-body h2 {
  font-size: 15px;
  font-weight: 700;
  color: var(--accent);
  margin: 24px 0 8px;
}
.privacy-body p {
  font-size: 14px;
  color: rgba(232,234,240,.8);
  line-height: 1.7;
  margin-bottom: 10px;
}
.privacy-body ul {
  margin: 8px 0 10px 20px;
  font-size: 14px;
  color: rgba(232,234,240,.8);
  line-height: 1.7;
}
.privacy-body a { color: var(--accent); }
