*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f0f0f;
  --bg2: #181818;
  --bg3: #222;
  --border: #2e2e2e;
  --border2: #3a3a3a;
  --text: #f0f0f0;
  --text2: #999;
  --text3: #555;
  --accent: #e8ff47;
  --accent2: #c8dc30;
  --accent-dim: rgba(232,255,71,0.08);
  --red: #ff5c5c;
  --blue: #4da6ff;
  --radius: 8px;
  --radius-lg: 12px;
}

body {
  font-family: 'SF Mono', 'Fira Code', monospace;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 13px;
}

/* ── Layout ── */
.app {
  display: grid;
  grid-template-columns: 320px 1fr;
  grid-template-rows: 52px 1fr;
  height: 100vh;
  overflow: hidden;
}

.topbar {
  grid-column: 1 / -1;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 16px;
}
.topbar-logo { font-size: 14px; font-weight: 700; letter-spacing: -0.5px; color: var(--accent); }
.topbar-logo span { color: var(--text2); font-weight: 400; }
.topbar-steps { display: flex; gap: 2px; margin-left: auto; }
.step-pill {
  padding: 4px 14px; border-radius: 20px; font-size: 11px; cursor: pointer;
  color: var(--text3); border: 1px solid transparent; transition: all 0.15s;
}
.step-pill.active { background: var(--accent-dim); color: var(--accent); border-color: var(--accent); }
.step-pill.done { color: var(--text2); }

.sidebar {
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.main { background: var(--bg); display: flex; flex-direction: column; overflow: hidden; }

/* ── Sidebar sections ── */
.sb-section { padding: 16px; border-bottom: 1px solid var(--border); }
.sb-label { font-size: 10px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--text3); margin-bottom: 10px; }

/* ── Drop zone ── */
#drop-zone {
  border: 1.5px dashed var(--border2);
  border-radius: var(--radius);
  padding: 24px 16px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  color: var(--text3);
}
#drop-zone:hover, #drop-zone.drag { border-color: var(--accent); color: var(--accent); background: var(--accent-dim); }
#drop-zone svg { display: block; margin: 0 auto 8px; opacity: 0.5; }
#drop-zone.drag svg { opacity: 1; }

/* ── Frame list ── */
#frame-list { flex: 1; overflow-y: auto; padding: 8px; display: flex; flex-direction: column; gap: 4px; }
.frame-item {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 8px; border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg3);
  cursor: grab;
  transition: border-color 0.15s, background 0.15s;
  user-select: none;
}
.frame-item:hover { border-color: var(--border2); }
.frame-item.active { border-color: var(--accent); background: var(--accent-dim); }
.frame-item.dragging { opacity: 0.4; }
.frame-item.drag-over { border-color: var(--blue); background: rgba(77,166,255,0.06); }
.frame-thumb { width: 52px; height: 32px; object-fit: cover; border-radius: 4px; flex-shrink: 0; }
.frame-info { flex: 1; min-width: 0; }
.frame-name { font-size: 11px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.frame-clicks { font-size: 10px; color: var(--text3); margin-top: 2px; }
.frame-order { font-size: 11px; color: var(--text3); min-width: 16px; text-align: right; }
.frame-del { background: none; border: none; color: var(--text3); cursor: pointer; padding: 2px 4px; border-radius: 4px; font-size: 12px; }
.frame-del:hover { color: var(--red); }

/* ── Settings ── */
.setting-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; gap: 8px; }
.setting-row label { font-size: 11px; color: var(--text2); white-space: nowrap; }
.setting-row input[type=range] { flex: 1; accent-color: var(--accent); }
.setting-row input[type=number], .setting-row select {
  background: var(--bg3); border: 1px solid var(--border2); color: var(--text);
  border-radius: 4px; padding: 3px 6px; font-size: 11px; width: 70px;
  font-family: inherit;
}
.setting-val { font-size: 11px; color: var(--accent); min-width: 28px; text-align: right; }

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px; border-radius: var(--radius); border: 1px solid var(--border2);
  background: var(--bg3); color: var(--text); font-size: 12px; cursor: pointer;
  font-family: inherit; transition: all 0.15s; white-space: nowrap;
}
.btn:hover { border-color: var(--border); background: #2a2a2a; }
.btn.primary { background: var(--accent); color: #000; border-color: var(--accent); font-weight: 700; }
.btn.primary:hover { background: var(--accent2); }
.btn.danger { color: var(--red); border-color: #3a2020; }
.btn.danger:hover { background: rgba(255,92,92,0.08); }
.btn:disabled { opacity: 0.35; cursor: not-allowed; }
.btn-row { display: flex; gap: 6px; flex-wrap: wrap; }

/* ── Canvas area ── */
.canvas-header {
  padding: 12px 20px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px;
  background: var(--bg2);
}
.canvas-header h2 { font-size: 13px; font-weight: 600; color: var(--text); }
.canvas-header .hint { font-size: 11px; color: var(--text3); }
.canvas-wrap-outer {
  flex: 1; overflow: auto; display: flex; align-items: center; justify-content: center;
  padding: 24px; background: #0a0a0a;
}
#canvas-wrap { position: relative; display: inline-block; cursor: crosshair; }
#main-canvas { display: block; border-radius: var(--radius); border: 1px solid var(--border); max-width: 100%; }
#overlay-canvas { position: absolute; top: 0; left: 0; pointer-events: none; border-radius: var(--radius); }
#pins-layer { position: absolute; top: 0; left: 0; pointer-events: none; }

/* ── Pin styles ── */
.pin { position: absolute; transform: translate(-50%, -50%); }
.pin-ring {
  width: 28px; height: 28px; border-radius: 50%;
  border: 2px solid currentColor; position: absolute;
  top: 50%; left: 50%; transform: translate(-50%,-50%);
  animation: ping 1.5s ease-out infinite;
  opacity: 0.4;
}
@keyframes ping { 0% { transform: translate(-50%,-50%) scale(0.8); opacity: 0.6; } 100% { transform: translate(-50%,-50%) scale(1.8); opacity: 0; } }
.pin-dot {
  width: 18px; height: 18px; border-radius: 50%;
  background: currentColor; border: 2px solid #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 9px; font-weight: 700; color: #000;
  position: relative; z-index: 1;
}
.pin-tooltip {
  position: absolute; left: 14px; top: -10px;
  background: rgba(0,0,0,0.85); color: #fff;
  font-size: 10px; padding: 3px 7px; border-radius: 4px;
  white-space: nowrap; border: 1px solid #333;
}

/* ── Click list ── */
#click-list { list-style: none; display: flex; flex-direction: column; gap: 4px; }
#click-list li {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg3); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 7px 10px; font-size: 11px;
}
#click-list .seq { width: 18px; height: 18px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 9px; font-weight: 700; color: #000; flex-shrink: 0; }
#click-list .lbl { flex: 1; background: transparent; border: none; border-bottom: 1px dashed var(--border2); color: var(--text); font-family: inherit; font-size: 11px; padding: 1px 3px; outline: none; }
#click-list .xy { color: var(--text3); font-size: 10px; white-space: nowrap; }
#click-list .del { background: none; border: none; color: var(--text3); cursor: pointer; font-size: 12px; }
#click-list .del:hover { color: var(--red); }

/* ── Preview ── */
#preview-wrap {
  flex: 1; overflow: auto; display: flex; align-items: center; justify-content: center;
  padding: 24px; background: #0a0a0a;
}
#preview-canvas { border-radius: var(--radius); border: 1px solid var(--border); }

/* ── Progress ── */
#progress-bar-wrap { display: none; padding: 0 20px 16px; }
#progress-track { height: 4px; background: var(--border); border-radius: 2px; }
#progress-fill { height: 4px; background: var(--accent); border-radius: 2px; width: 0%; transition: width 0.1s; }
#progress-label { font-size: 10px; color: var(--text3); margin-top: 4px; }

/* ── Empty state ── */
.empty-state { text-align: center; color: var(--text3); padding: 60px 20px; }
.empty-state svg { display: block; margin: 0 auto 12px; opacity: 0.2; }
.empty-state p { font-size: 12px; line-height: 1.7; }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 10px; }

/* ── Tab nav inside main ── */
.tab-nav { display: flex; border-bottom: 1px solid var(--border); background: var(--bg2); }
.tab-btn { padding: 10px 20px; font-size: 12px; cursor: pointer; background: none; border: none; color: var(--text3); border-bottom: 2px solid transparent; font-family: inherit; transition: all 0.15s; }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-content { display: none; flex-direction: column; flex: 1; overflow: hidden; }
.tab-content.active { display: flex; }

.export-panel { padding: 20px; display: flex; flex-direction: column; gap: 16px; flex: 1; overflow-y: auto; }
.export-card {
  background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 16px;
}
.export-card h3 { font-size: 12px; color: var(--text); margin-bottom: 12px; font-weight: 600; }

.export-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.format-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 4px;
}

#toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--accent); color: #000; font-weight: 700; font-size: 12px;
  padding: 8px 20px; border-radius: 20px; opacity: 0; transition: opacity 0.3s;
  pointer-events: none; z-index: 999;
}

/* ════════════════════════════════════════
   MOBILE RESPONSIVE  (≤ 700px)
════════════════════════════════════════ */
@media (max-width: 700px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto 1fr;
    height: auto;
    min-height: 100vh;
    overflow: auto;
  }

  .topbar {
    flex-wrap: wrap;
    height: auto;
    padding: 10px 12px;
    gap: 8px;
  }

  .topbar-steps {
    margin-left: 0;
    flex-wrap: wrap;
    width: 100%;
    gap: 4px;
  }

  .step-pill {
    font-size: 10px;
    padding: 4px 10px;
  }

  .sidebar {
    border-right: none;
    border-bottom: 1px solid var(--border);
    max-height: 55vh;
    overflow-y: auto;
    display: block;          /* drop flex column so children can stack naturally */
  }

  /* On mobile, let the frame list show its full height inside the scrollable sidebar
     instead of being a flex child that collapses to 0px. */
  #frame-list {
    flex: none;
    overflow: visible;
    max-height: none;
  }

  .main {
    min-height: 60vh;
    overflow: hidden;
  }

  .canvas-wrap-outer,
  #preview-wrap {
    padding: 12px;
  }

  .canvas-header {
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 12px;
  }

  .canvas-header .canvas-header-actions {
    margin-left: 0;
    width: 100%;
    justify-content: flex-end;
  }

  .export-grid,
  .format-grid {
    grid-template-columns: 1fr;
  }

  .tab-btn {
    padding: 10px 14px;
    font-size: 11px;
  }

  #click-section {
    max-height: 140px;
  }

  .empty-state {
    padding: 32px 16px;
  }
}
